3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Add generic types on base protocols

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-01-27 13:45:40 +01:00
Ursprung 8000561ae9
Commit c8d339ab30
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
12 geänderte Dateien mit 166 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -51,24 +51,25 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/ */
public interface Protocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> { public interface Protocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> {
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) { default void registerClientbound(State state, ClientboundPacketType packetType, @Nullable PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
}
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
default void registerClientbound(State state, ClientboundPacketType packetType, PacketHandler handler) {
Preconditions.checkArgument(packetType.state() == state); Preconditions.checkArgument(packetType.state() == state);
registerClientbound(state, packetType.getId(), packetType.getId(), handler, false); registerClientbound(state, packetType.getId(), packetType.getId(), handler, false);
} }
default void registerServerbound(State state, ServerboundPacketType packetType, PacketHandler handler) { default void registerServerbound(State state, ServerboundPacketType packetType, @Nullable PacketHandler handler) {
Preconditions.checkArgument(packetType.state() == state); Preconditions.checkArgument(packetType.state() == state);
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false); registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
} }
@Deprecated/*(forRemoval = true)*/
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) {
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
}
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
}
/** /**
* Registers a serverbound packet, with id transformation and remapper. * Registers a serverbound packet, with id transformation and remapper.
* *
@ -79,15 +80,16 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param override whether an existing mapper should be overridden * @param override whether an existing mapper should be overridden
* @see #registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketHandler, boolean) * @see #registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketHandler, boolean)
*/ */
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override); void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
void cancelServerbound(State state, int mappedPacketId); void cancelServerbound(State state, int mappedPacketId);
@Deprecated/*(forRemoval = true)*/
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId) { default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId) {
registerClientbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null); registerClientbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
} }
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler) { default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false); registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
} }
@ -103,7 +105,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @param override whether an existing mapper should be overridden * @param override whether an existing mapper should be overridden
* @see #registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketHandler, boolean) * @see #registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketHandler, boolean)
*/ */
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override); void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override);
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------

Datei anzeigen

@ -27,18 +27,26 @@ import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionProvider; import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
import com.viaversion.viaversion.protocols.base.packet.BasePacketTypesProvider;
import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class BaseProtocol extends AbstractProtocol { public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> {
private static final int STATUS_INTENT = 1; private static final int STATUS_INTENT = 1;
private static final int LOGIN_INTENT = 2; private static final int LOGIN_INTENT = 2;
private static final int TRANSFER_INTENT = 3; private static final int TRANSFER_INTENT = 3;
public BaseProtocol() {
super(BaseClientboundPacket.class, BaseClientboundPacket.class, BaseServerboundPacket.class, BaseServerboundPacket.class);
}
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Handshake Packet // Handshake Packet
@ -127,4 +135,9 @@ public class BaseProtocol extends AbstractProtocol {
} }
} }
} }
@Override
protected PacketTypesProvider<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> createPacketTypesProvider() {
return BasePacketTypesProvider.INSTANCE;
}
} }

Datei anzeigen

@ -27,12 +27,16 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry; import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionProvider; import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocol.ProtocolManagerImpl; import com.viaversion.viaversion.protocol.ProtocolManagerImpl;
import com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton; import com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton;
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
import com.viaversion.viaversion.protocols.base.packet.BasePacketTypesProvider;
import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.util.ChatColorUtil; import com.viaversion.viaversion.util.ChatColorUtil;
import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.GsonUtil;
@ -41,11 +45,15 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class BaseProtocol1_7 extends AbstractProtocol { public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> {
public BaseProtocol1_7() {
super(BaseClientboundPacket.class, BaseClientboundPacket.class, BaseServerboundPacket.class, BaseServerboundPacket.class);
}
@Override @Override
protected void registerPackets() { protected void registerPackets() {
registerClientbound(ClientboundStatusPackets.STATUS_RESPONSE, new PacketHandlers() { // Status Response Packet registerClientbound(ClientboundStatusPackets.STATUS_RESPONSE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); map(Type.STRING);
@ -191,4 +199,9 @@ public class BaseProtocol1_7 extends AbstractProtocol {
} }
return UUID.fromString(uuidString); return UUID.fromString(uuidString);
} }
@Override
protected PacketTypesProvider<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> createPacketTypesProvider() {
return BasePacketTypesProvider.INSTANCE;
}
} }

Datei anzeigen

@ -17,10 +17,10 @@
*/ */
package com.viaversion.viaversion.protocols.base; package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
public enum ClientboundLoginPackets implements ClientboundPacketType { public enum ClientboundLoginPackets implements BaseClientboundPacket {
LOGIN_DISCONNECT, // 0x00 LOGIN_DISCONNECT, // 0x00
HELLO, // 0x01 HELLO, // 0x01
GAME_PROFILE, // 0x02 GAME_PROFILE, // 0x02

Datei anzeigen

@ -17,10 +17,10 @@
*/ */
package com.viaversion.viaversion.protocols.base; package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
public enum ClientboundStatusPackets implements ClientboundPacketType { public enum ClientboundStatusPackets implements BaseClientboundPacket {
STATUS_RESPONSE, // 0x00 STATUS_RESPONSE, // 0x00
PONG_RESPONSE; // 0x01 PONG_RESPONSE; // 0x01

Datei anzeigen

@ -17,10 +17,10 @@
*/ */
package com.viaversion.viaversion.protocols.base; package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
public enum ServerboundHandshakePackets implements ServerboundPacketType { public enum ServerboundHandshakePackets implements BaseServerboundPacket {
CLIENT_INTENTION; // 0x00 CLIENT_INTENTION; // 0x00
@Override @Override

Datei anzeigen

@ -17,10 +17,10 @@
*/ */
package com.viaversion.viaversion.protocols.base; package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
public enum ServerboundLoginPackets implements ServerboundPacketType { public enum ServerboundLoginPackets implements BaseServerboundPacket {
HELLO, // 0x00 HELLO, // 0x00
ENCRYPTION_KEY, // 0x01 ENCRYPTION_KEY, // 0x01
CUSTOM_QUERY_ANSWER, // 0x02 CUSTOM_QUERY_ANSWER, // 0x02

Datei anzeigen

@ -17,10 +17,10 @@
*/ */
package com.viaversion.viaversion.protocols.base; package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
public enum ServerboundStatusPackets implements ServerboundPacketType { public enum ServerboundStatusPackets implements BaseServerboundPacket {
STATUS_REQUEST, // 0x00 STATUS_REQUEST, // 0x00
PING_REQUEST; // 0x01 PING_REQUEST; // 0x01

Datei anzeigen

@ -0,0 +1,23 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.base.packet;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
public interface BaseClientboundPacket extends ClientboundPacketType {
}

Datei anzeigen

@ -0,0 +1,64 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.base.packet;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypeMap;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ClientboundStatusPackets;
import com.viaversion.viaversion.protocols.base.ServerboundHandshakePackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundStatusPackets;
import java.util.EnumMap;
import java.util.Map;
public final class BasePacketTypesProvider implements PacketTypesProvider<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> {
public static final PacketTypesProvider<BaseClientboundPacket, BaseClientboundPacket, BaseServerboundPacket, BaseServerboundPacket> INSTANCE = new BasePacketTypesProvider();
private final Map<State, PacketTypeMap<BaseClientboundPacket>> clientboundPacketTypes = new EnumMap<>(State.class);
private final Map<State, PacketTypeMap<BaseServerboundPacket>> serverboundPacketTypes = new EnumMap<>(State.class);
private BasePacketTypesProvider() {
clientboundPacketTypes.put(State.STATUS, PacketTypeMap.of(ClientboundStatusPackets.class));
clientboundPacketTypes.put(State.LOGIN, PacketTypeMap.of(ClientboundLoginPackets.class));
serverboundPacketTypes.put(State.STATUS, PacketTypeMap.of(ServerboundStatusPackets.class));
serverboundPacketTypes.put(State.HANDSHAKE, PacketTypeMap.of(ServerboundHandshakePackets.class));
serverboundPacketTypes.put(State.LOGIN, PacketTypeMap.of(ServerboundLoginPackets.class));
}
@Override
public Map<State, PacketTypeMap<BaseClientboundPacket>> unmappedClientboundPacketTypes() {
return clientboundPacketTypes;
}
@Override
public Map<State, PacketTypeMap<BaseServerboundPacket>> unmappedServerboundPacketTypes() {
return serverboundPacketTypes;
}
@Override
public Map<State, PacketTypeMap<BaseClientboundPacket>> mappedClientboundPacketTypes() {
return unmappedClientboundPacketTypes();
}
@Override
public Map<State, PacketTypeMap<BaseServerboundPacket>> mappedServerboundPacketTypes() {
return unmappedServerboundPacketTypes();
}
}

Datei anzeigen

@ -0,0 +1,23 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.base.packet;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
public interface BaseServerboundPacket extends ServerboundPacketType {
}

Datei anzeigen

@ -39,6 +39,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
@ -551,7 +552,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
// Incoming packets // Incoming packets
// New packet 0x02 - Login Plugin Message // New packet 0x02 - Login Plugin Message
cancelServerbound(State.LOGIN, 0x02); cancelServerbound(State.LOGIN, ServerboundLoginPackets.CUSTOM_QUERY_ANSWER.getId());
// New 0x01 - Query Block NBT // New 0x01 - Query Block NBT
cancelServerbound(ServerboundPackets1_13.QUERY_BLOCK_NBT); cancelServerbound(ServerboundPackets1_13.QUERY_BLOCK_NBT);