9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-23 00:49:31 +00:00

Optimize leaves protocol manager & Fix diff

This commit is contained in:
Dreeam
2025-06-15 00:46:13 +08:00
parent ebd0c5d3ac
commit 03c04f0dcc
3 changed files with 45 additions and 29 deletions

View File

@@ -99,6 +99,18 @@ public class LeavesProtocolManager {
return;
}
// Leaf start - optimize leaves protocol manager
boolean active = true;
try {
Method isActiveMethod = clazz.getDeclaredMethod("isActive");
isActiveMethod.setAccessible(true);
active = (Boolean) isActiveMethod.invoke(protocol);
} catch (Throwable e) {
LOGGER.warning("Failed to check isActive for " + clazz.getName() + ": " + e);
continue;
}
// Leaf end - optimize leaves protocol manager
for (final Method method : clazz.getDeclaredMethods()) {
if (method.isBridge() || method.isSynthetic()) {
continue;
@@ -116,6 +128,22 @@ public class LeavesProtocolManager {
continue;
}
if (!active) continue; // Leaf - optimize leaves protocol manager
// Leaf start - optimize leaves protocol manager - move up
final ProtocolHandler.ReloadServer reloadServer = method.getAnnotation(ProtocolHandler.ReloadServer.class);
if (reloadServer != null) {
RELOAD_SERVER.add(new EmptyInvokerHolder<>(protocol, method, reloadServer));
continue;
}
final ProtocolHandler.ReloadDataPack reloadDataPack = method.getAnnotation(ProtocolHandler.ReloadDataPack.class);
if (reloadDataPack != null) {
RELOAD_DATAPACK.add(new EmptyInvokerHolder<>(protocol, method, reloadDataPack));
continue;
}
// Leaf end - optimize leaves protocol manager - move up
final ProtocolHandler.PayloadReceiver payloadReceiver = method.getAnnotation(ProtocolHandler.PayloadReceiver.class);
if (payloadReceiver != null) {
PAYLOAD_RECEIVERS.put(payloadReceiver.payload(), new PayloadReceiverInvokerHolder(protocol, method, payloadReceiver));
@@ -160,18 +188,6 @@ public class LeavesProtocolManager {
continue;
}
final ProtocolHandler.ReloadServer reloadServer = method.getAnnotation(ProtocolHandler.ReloadServer.class);
if (reloadServer != null) {
RELOAD_SERVER.add(new EmptyInvokerHolder<>(protocol, method, reloadServer));
continue;
}
final ProtocolHandler.ReloadDataPack reloadDataPack = method.getAnnotation(ProtocolHandler.ReloadDataPack.class);
if (reloadDataPack != null) {
RELOAD_DATAPACK.add(new EmptyInvokerHolder<>(protocol, method, reloadDataPack));
continue;
}
final ProtocolHandler.MinecraftRegister minecraftRegister = method.getAnnotation(ProtocolHandler.MinecraftRegister.class);
if (minecraftRegister != null) {
String key = minecraftRegister.key();
@@ -300,16 +316,11 @@ public class LeavesProtocolManager {
private static void sendKnownId(ServerPlayer player) {
Set<String> set = new HashSet<>();
PAYLOAD_RECEIVERS.forEach((clazz, holder) -> {
if (holder.owner().isActive()) {
set.add(IDS.get(clazz).toString());
}
});
STRICT_BYTEBUF_RECEIVERS.forEach((key, holder) -> {
if (holder.owner().isActive()) {
set.add(key);
}
});
// Leaf start - optimize leaves protocol manager
PAYLOAD_RECEIVERS.forEach((clazz, holder) -> set.add(IDS.get(clazz).toString()));
STRICT_BYTEBUF_RECEIVERS.forEach((key, holder) -> set.add(key));
if (set.isEmpty()) return;
// Leaf end - optimize leaves protocol manager
ProtocolUtils.sendBytebufPacket(player, ResourceLocation.fromNamespaceAndPath("minecraft", "register"), buf -> {
ResourceLocation channel;
for (Iterator<String> var3 = set.iterator(); var3.hasNext(); buf.writeBytes(channel.toString().getBytes(StandardCharsets.US_ASCII))) {
@@ -394,4 +405,4 @@ public class LeavesProtocolManager {
}
}
}
}
}