From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Wed, 7 Feb 2024 09:00:10 +0000 Subject: [PATCH] Leaves Fix Bladeren Protocol diff --git a/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocol.java index 64a1d25973b032e8cab64bbffa6824a131676773..57a563b3f2d01719d490578907411d25ea07a658 100644 --- a/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocol.java +++ b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocol.java @@ -8,9 +8,7 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface LeavesProtocol { - - String namespace() default "minecraft"; - - String[] namespaces() default {}; + + String[] namespace(); } diff --git a/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java index 055f044ce6cef4377f6f577efdbfad0ec9a2d57b..18fc0e2c890020bf587f5b1d2e097126d3e19999 100644 --- a/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java +++ b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java @@ -56,7 +56,7 @@ public class LeavesProtocolManager { return; } - Map> map = new HashMap<>(); + Map> map = KNOWN_TYPES.getOrDefault(protocol, new HashMap<>()); for (final Method method : methods) { if (method.isBridge() || method.isSynthetic() || !Modifier.isStatic(method.getModifiers())) { continue; @@ -131,13 +131,13 @@ public class LeavesProtocolManager { public static CustomPacketPayload getPayload(ResourceLocation id, FriendlyByteBuf buf) { for (LeavesProtocol protocol : KNOWN_TYPES.keySet()) { - if (!protocol.namespace().equals(id.getNamespace()) && !ArrayUtils.contains(protocol.namespaces(), id.getNamespace())) { + if (!ArrayUtils.contains(protocol.namespace(), id.getNamespace())) { continue; } Map> map = KNOWN_TYPES.get(protocol); for (ProtocolHandler.PayloadReceiver receiver : map.keySet()) { - if (receiver.ignoreId() || receiver.payloadId().equals(id.getPath()) || ArrayUtils.contains(receiver.payloadIds(), id.getPath())) { + if (receiver.ignoreId() || ArrayUtils.contains(receiver.payloadId(), id.getPath())) { try { return map.get(receiver).newInstance(id, buf); } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { @@ -151,15 +151,14 @@ public class LeavesProtocolManager { public static void handlePayload(ServerPlayer player, CustomPacketPayload payload) { for (LeavesProtocol protocol : KNOW_RECEIVERS.keySet()) { - if (!protocol.namespace().equals(payload.id().getNamespace()) && !ArrayUtils.contains(protocol.namespaces(), payload.id().getNamespace())) { + if (!ArrayUtils.contains(protocol.namespace(), payload.id().getNamespace())) { continue; } Map map = KNOW_RECEIVERS.get(protocol); for (ProtocolHandler.PayloadReceiver receiver : map.keySet()) { if (payload.getClass() == receiver.payload()) { - if (receiver.ignoreId() || receiver.payloadId().equals(payload.id().getPath()) || - ArrayUtils.contains(receiver.payloadIds(), payload.id().getPath())) { + if (receiver.ignoreId() || ArrayUtils.contains(receiver.payloadId(), payload.id().getPath())) { try { map.get(receiver).invoke(null, player, payload); } catch (InvocationTargetException | IllegalAccessException e) { @@ -222,7 +221,7 @@ public class LeavesProtocolManager { public static void handleMinecraftRegister(String channelId, ServerPlayer player) { for (LeavesProtocol protocol : MINECRAFT_REGISTER.keySet()) { String[] channel = channelId.split(":"); - if (!protocol.namespace().equals(channel[0]) && !ArrayUtils.contains(protocol.namespaces(), channel[0])) { + if (!ArrayUtils.contains(protocol.namespace(), channel[0])) { continue; } diff --git a/src/main/java/top/leavesmc/leaves/protocol/core/ProtocolHandler.java b/src/main/java/top/leavesmc/leaves/protocol/core/ProtocolHandler.java index d696f001d2576d1b61cc732c81f22eb52205072b..92ad6e9b1c0d9640b80c1ebe739c613d989eec21 100644 --- a/src/main/java/top/leavesmc/leaves/protocol/core/ProtocolHandler.java +++ b/src/main/java/top/leavesmc/leaves/protocol/core/ProtocolHandler.java @@ -21,9 +21,7 @@ public class ProtocolHandler { Class payload(); - String[] payloadIds() default {}; - - String payloadId() default ""; + String[] payloadId(); boolean ignoreId() default false; }