diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java index bfa5bda4..d286f021 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java @@ -36,7 +36,23 @@ public class ProtocolAPI { public static final TinyProtocol tinyProtocol = TinyProtocol.instance; - public static void setOutgoingHandler(Class packetClass, BiFunction handler) { + static { + TinyProtocol.instance.setOutFilter((receiver, channel, packet) -> { + BiFunction handler = outgoingHandler.get(packet.getClass()); + if (handler == null) + return packet; + return handler.apply(receiver, packet); + }); + TinyProtocol.instance.setInFilter((sender, channel, packet) -> { + BiFunction handler = incomingHandler.get(packet.getClass()); + if (handler == null) + return packet; + return handler.apply(sender, packet); + }); + } + + public static void setOutgoingHandler + (Class packetClass, BiFunction handler) { outgoingHandler.put(packetClass, handler); } @@ -44,7 +60,8 @@ public class ProtocolAPI { outgoingHandler.remove(packetClass); } - public static void setIncomingHandler(Class packetClass, BiFunction handler) { + public static void setIncomingHandler + (Class packetClass, BiFunction handler) { incomingHandler.put(packetClass, handler); }