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

Warn instead of blowing up everything

Dieser Commit ist enthalten in:
creeper123123321 2019-02-11 16:48:26 -02:00
Ursprung 4eb4b2c37f
Commit 7856716a3a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1

Datei anzeigen

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
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.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;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -14,6 +15,7 @@ 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.logging.Level;
public abstract class Protocol { public abstract class Protocol {
private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>(); private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
@ -104,7 +106,10 @@ 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); Pair<State, Integer> pair = new Pair<>(state, newPacketID);
if (!override && incoming.containsKey(pair)) throw new IllegalArgumentException(pair + " already registered"); if (!override && incoming.containsKey(pair)) {
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
" If this override is intentional, set override to true. Stacktrace: ", new Exception());
};
incoming.put(pair, protocolPacket); incoming.put(pair, protocolPacket);
} }
@ -134,7 +139,10 @@ 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); Pair<State, Integer> pair = new Pair<>(state, oldPacketID);
if (!override && outgoing.containsKey(pair)) throw new IllegalArgumentException(pair + " already registered"); if (!override && outgoing.containsKey(pair)) {
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
" If override is intentional, set override to true. Stacktrace: ", new Exception());
}
outgoing.put(pair, protocolPacket); outgoing.put(pair, protocolPacket);
} }