Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Minor protocol cleanup
Removed unneeded integer boxing and empty method implementations of the user init
Dieser Commit ist enthalten in:
Ursprung
95db675de5
Commit
b5e5118450
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.api.protocol;
|
package us.myles.ViaVersion.api.protocol;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||||
@ -13,14 +12,12 @@ import us.myles.ViaVersion.packets.State;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public abstract class Protocol {
|
public abstract class Protocol {
|
||||||
private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
|
private final Map<Packet, ProtocolPacket> incoming = new HashMap<>();
|
||||||
private final Map<Pair<State, Integer>, ProtocolPacket> outgoing = new HashMap<>();
|
private final Map<Packet, ProtocolPacket> outgoing = new HashMap<>();
|
||||||
|
private final Map<Class, Object> storedObjects = new HashMap<>(); // currently only used for MetadataRewriters
|
||||||
private final Map<Class, Object> storedObjects = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public Protocol() {
|
public Protocol() {
|
||||||
registerPackets();
|
registerPackets();
|
||||||
@ -50,26 +47,30 @@ public abstract class Protocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle protocol registration phase, use this to register providers / tasks.
|
* Register the packets for this protocol.
|
||||||
*
|
|
||||||
* @param providers The current providers
|
|
||||||
*/
|
|
||||||
protected void register(ViaProviders providers) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the packets for this protocol
|
|
||||||
*/
|
*/
|
||||||
protected abstract void registerPackets();
|
protected abstract void registerPackets();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle protocol registration phase, use this to register providers / tasks.
|
||||||
|
* <p>
|
||||||
|
* To be overridden if needed.
|
||||||
|
*
|
||||||
|
* @param providers The current providers
|
||||||
|
*/
|
||||||
|
protected void register(ViaProviders providers) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise a user for this protocol setting up objects.
|
* Initialise a user for this protocol setting up objects.
|
||||||
* /!\ WARNING - May be called more than once in a single {@link UserConnection}
|
* /!\ WARNING - May be called more than once in a single {@link UserConnection}
|
||||||
|
* <p>
|
||||||
|
* To be overridden if needed.
|
||||||
*
|
*
|
||||||
* @param userConnection The user to initialise
|
* @param userConnection The user to initialise
|
||||||
*/
|
*/
|
||||||
public abstract void init(UserConnection userConnection);
|
public void init(UserConnection userConnection) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register an incoming packet, with simple id transformation.
|
* Register an incoming packet, with simple id transformation.
|
||||||
@ -96,12 +97,12 @@ public abstract class Protocol {
|
|||||||
|
|
||||||
public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||||
Pair<State, Integer> pair = new Pair<>(state, newPacketID);
|
Packet packet = new Packet(state, newPacketID);
|
||||||
if (!override && incoming.containsKey(pair)) {
|
if (!override && incoming.containsKey(packet)) {
|
||||||
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
|
Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" +
|
||||||
" If this override is intentional, set override to true. Stacktrace: ", new Exception());
|
" If this override is intentional, set override to true. Stacktrace: ", new Exception());
|
||||||
}
|
}
|
||||||
incoming.put(pair, protocolPacket);
|
incoming.put(packet, protocolPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
|
public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
|
||||||
@ -142,12 +143,12 @@ public abstract class Protocol {
|
|||||||
|
|
||||||
public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||||
Pair<State, Integer> pair = new Pair<>(state, oldPacketID);
|
Packet packet = new Packet(state, oldPacketID);
|
||||||
if (!override && outgoing.containsKey(pair)) {
|
if (!override && outgoing.containsKey(packet)) {
|
||||||
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
|
Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" +
|
||||||
" If override is intentional, set override to true. Stacktrace: ", new Exception());
|
" If override is intentional, set override to true. Stacktrace: ", new Exception());
|
||||||
}
|
}
|
||||||
outgoing.put(pair, protocolPacket);
|
outgoing.put(packet, protocolPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
|
public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
|
||||||
@ -172,12 +173,13 @@ public abstract class Protocol {
|
|||||||
* @throws Exception Throws exception if it fails to transform
|
* @throws Exception Throws exception if it fails to transform
|
||||||
*/
|
*/
|
||||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||||
Pair<State, Integer> statePacket = new Pair<>(state, packetWrapper.getId());
|
Packet statePacket = new Packet(state, packetWrapper.getId());
|
||||||
Map<Pair<State, Integer>, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming);
|
Map<Packet, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming);
|
||||||
ProtocolPacket protocolPacket = packetMap.get(statePacket);
|
ProtocolPacket protocolPacket = packetMap.get(statePacket);
|
||||||
if (protocolPacket == null) {
|
if (protocolPacket == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write packet id
|
// write packet id
|
||||||
int newID = direction == Direction.OUTGOING ? protocolPacket.getNewID() : protocolPacket.getOldID();
|
int newID = direction == Direction.OUTGOING ? protocolPacket.getNewID() : protocolPacket.getOldID();
|
||||||
packetWrapper.setId(newID);
|
packetWrapper.setId(newID);
|
||||||
@ -203,6 +205,44 @@ public abstract class Protocol {
|
|||||||
return "Protocol:" + getClass().getSimpleName();
|
return "Protocol:" + getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Packet {
|
||||||
|
private final State state;
|
||||||
|
private final int packetId;
|
||||||
|
|
||||||
|
public Packet(State state, int packetId) {
|
||||||
|
this.state = state;
|
||||||
|
this.packetId = packetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public State getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPacketId() {
|
||||||
|
return packetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Packet{" + "state=" + state + ", packetId=" + packetId + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Packet that = (Packet) o;
|
||||||
|
return packetId == that.packetId && state == that.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = state != null ? state.hashCode() : 0;
|
||||||
|
result = 31 * result + packetId;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class ProtocolPacket {
|
public static class ProtocolPacket {
|
||||||
private final State state;
|
private final State state;
|
||||||
private final int oldID;
|
private final int oldID;
|
||||||
|
@ -9,7 +9,6 @@ import net.md_5.bungee.api.ChatColor;
|
|||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
@ -190,11 +189,6 @@ public class BaseProtocol1_7 extends Protocol {
|
|||||||
registerIncoming(State.LOGIN, 0x02, 0x02); // Plugin Response (1.13)
|
registerIncoming(State.LOGIN, 0x02, 0x02); // Plugin Response (1.13)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String addDashes(String trimmedUUID) {
|
public static String addDashes(String trimmedUUID) {
|
||||||
StringBuilder idBuff = new StringBuilder(trimmedUUID);
|
StringBuilder idBuff = new StringBuilder(trimmedUUID);
|
||||||
idBuff.insert(20, '-');
|
idBuff.insert(20, '-');
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_11_1to1_11;
|
package us.myles.ViaVersion.protocols.protocol1_11_1to1_11;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
|
||||||
public class Protocol1_11_1To1_11 extends Protocol {
|
public class Protocol1_11_1To1_11 extends Protocol {
|
||||||
@ -8,9 +7,4 @@ public class Protocol1_11_1To1_11 extends Protocol {
|
|||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
// Only had metadata changes, see wiki.vg for full info.
|
// Only had metadata changes, see wiki.vg for full info.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_12_1to1_12;
|
package us.myles.ViaVersion.protocols.protocol1_12_1to1_12;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -87,9 +86,4 @@ public class Protocol1_12_1To1_12 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1;
|
package us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
@ -26,9 +25,4 @@ public class Protocol1_12_2To1_12_1 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1;
|
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
@ -71,9 +70,4 @@ public class Protocol1_13_2To1_13_1 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_14_3to1_14_2;
|
package us.myles.ViaVersion.protocols.protocol1_14_3to1_14_2;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -43,8 +42,4 @@ public class Protocol1_14_3To1_14_2 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_14_4to1_14_3;
|
package us.myles.ViaVersion.protocols.protocol1_14_4to1_14_3;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -40,8 +39,4 @@ public class Protocol1_14_4To1_14_3 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_15_1to1_15;
|
package us.myles.ViaVersion.protocols.protocol1_15_1to1_15;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
|
||||||
public class Protocol1_15_1To1_15 extends Protocol {
|
public class Protocol1_15_1To1_15 extends Protocol {
|
||||||
@ -8,8 +7,4 @@ public class Protocol1_15_1To1_15 extends Protocol {
|
|||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection user) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_15_2to1_15_1;
|
package us.myles.ViaVersion.protocols.protocol1_15_2to1_15_1;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
|
||||||
public class Protocol1_15_2To1_15_1 extends Protocol {
|
public class Protocol1_15_2To1_15_1 extends Protocol {
|
||||||
@ -8,8 +7,4 @@ public class Protocol1_15_2To1_15_1 extends Protocol {
|
|||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection user) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9_1to1_9;
|
package us.myles.ViaVersion.protocols.protocol1_9_1to1_9;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -45,9 +44,4 @@ public class Protocol1_9_1To1_9 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_9_1;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_9_1;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -47,9 +46,4 @@ public class Protocol1_9To1_9_1 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren