mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-09-06 11:48:05 +02:00
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing BungeeCord Changes: f0908b66 Add optional 1.17 (21w19a) snapshot protocol support 5fa596fe #3084: (Regrettably) add a full SLF4J wrapper
366 lines
18 KiB
Diff
366 lines
18 KiB
Diff
From 5933064944a64327398feb3d07ccadbdcb41b629 Mon Sep 17 00:00:00 2001
|
|
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
|
|
Date: Wed, 17 Apr 2019 09:24:38 +0300
|
|
Subject: [PATCH] Speed up packet construction
|
|
|
|
|
|
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
index c856f365..d2a11a82 100644
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
@@ -57,6 +57,7 @@ public enum Protocol
|
|
{
|
|
TO_SERVER.registerPacket(
|
|
Handshake.class,
|
|
+ Handshake::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
|
|
);
|
|
}
|
|
@@ -68,6 +69,7 @@ public enum Protocol
|
|
{
|
|
TO_CLIENT.registerPacket(
|
|
KeepAlive.class,
|
|
+ KeepAlive::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x1F ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x21 ),
|
|
@@ -79,6 +81,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Login.class,
|
|
+ Login::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x23 ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x25 ),
|
|
@@ -89,6 +92,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Chat.class,
|
|
+ Chat::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x02 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x0F ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x0E ),
|
|
@@ -98,6 +102,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Respawn.class,
|
|
+ Respawn::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x07 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x33 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x34 ),
|
|
@@ -111,6 +116,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
BossBar.class,
|
|
+ BossBar::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x0C ),
|
|
map( ProtocolConstants.MINECRAFT_1_15, 0x0D ),
|
|
map( ProtocolConstants.MINECRAFT_1_16, 0x0C ),
|
|
@@ -119,17 +125,20 @@ public enum Protocol
|
|
// Waterfall start
|
|
TO_CLIENT.registerPacket(
|
|
EntityEffect.class,
|
|
+ EntityEffect::new, // Waterfall - speed up packet construction
|
|
map(ProtocolConstants.MINECRAFT_1_8, 0x1D),
|
|
map(ProtocolConstants.MINECRAFT_1_9, Integer.MIN_VALUE)
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
EntityRemoveEffect.class,
|
|
+ EntityRemoveEffect::new, // Waterfall - speed up packet construction
|
|
map(ProtocolConstants.MINECRAFT_1_8, 0x1E),
|
|
map(ProtocolConstants.MINECRAFT_1_9, Integer.MIN_VALUE)
|
|
);
|
|
// Waterfall end
|
|
TO_CLIENT.registerPacket(
|
|
PlayerListItem.class, // PlayerInfo
|
|
+ PlayerListItem::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x38 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x2D ),
|
|
map( ProtocolConstants.MINECRAFT_1_12_1, 0x2E ),
|
|
@@ -142,6 +151,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
TabCompleteResponse.class,
|
|
+ TabCompleteResponse::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x3A ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x0E ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x10 ),
|
|
@@ -152,6 +162,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
ScoreboardObjective.class,
|
|
+ ScoreboardObjective::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x3B ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x3F ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x41 ),
|
|
@@ -163,6 +174,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
ScoreboardScore.class,
|
|
+ ScoreboardScore::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x3C ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x42 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x44 ),
|
|
@@ -174,6 +186,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
ScoreboardDisplay.class,
|
|
+ ScoreboardDisplay::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x3D ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x38 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x3A ),
|
|
@@ -185,6 +198,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Team.class,
|
|
+ Team::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x3E ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x41 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x43 ),
|
|
@@ -196,6 +210,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
PluginMessage.class,
|
|
+ PluginMessage::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x3F ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x18 ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x19 ),
|
|
@@ -207,6 +222,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Kick.class,
|
|
+ Kick::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x40 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x1A ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x1B ),
|
|
@@ -218,6 +234,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Title.class,
|
|
+ Title::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x45 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x47 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12_1, 0x48 ),
|
|
@@ -239,6 +256,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
PlayerListHeaderFooter.class,
|
|
+ PlayerListHeaderFooter::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x47 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x48 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9_4, 0x47 ),
|
|
@@ -252,6 +270,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
EntityStatus.class,
|
|
+ EntityStatus::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x1A ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x1B ),
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x1C ),
|
|
@@ -263,6 +282,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
Commands.class,
|
|
+ Commands::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x11 ),
|
|
map( ProtocolConstants.MINECRAFT_1_15, 0x12 ),
|
|
map( ProtocolConstants.MINECRAFT_1_16, 0x11 ),
|
|
@@ -271,6 +291,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
GameState.class,
|
|
+ GameState::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_15, 0x1F ),
|
|
map( ProtocolConstants.MINECRAFT_1_16, 0x1E ),
|
|
map( ProtocolConstants.MINECRAFT_1_16_2, 0x1D ),
|
|
@@ -278,6 +299,7 @@ public enum Protocol
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
ViewDistance.class,
|
|
+ ViewDistance::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_14, 0x41 ),
|
|
map( ProtocolConstants.MINECRAFT_1_15, 0x42 ),
|
|
map( ProtocolConstants.MINECRAFT_1_16, 0x41 ),
|
|
@@ -286,6 +308,7 @@ public enum Protocol
|
|
|
|
TO_SERVER.registerPacket(
|
|
KeepAlive.class,
|
|
+ KeepAlive::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x0B ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x0C ),
|
|
@@ -297,6 +320,7 @@ public enum Protocol
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
Chat.class,
|
|
+ Chat::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x02 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x03 ),
|
|
@@ -305,6 +329,7 @@ public enum Protocol
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
TabCompleteRequest.class,
|
|
+ TabCompleteRequest::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x14 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x01 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x02 ),
|
|
@@ -314,6 +339,7 @@ public enum Protocol
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
ClientSettings.class,
|
|
+ ClientSettings::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x15 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x04 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x05 ),
|
|
@@ -322,6 +348,7 @@ public enum Protocol
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
PluginMessage.class,
|
|
+ PluginMessage::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x17 ),
|
|
map( ProtocolConstants.MINECRAFT_1_9, 0x09 ),
|
|
map( ProtocolConstants.MINECRAFT_1_12, 0x0A ),
|
|
@@ -339,19 +366,23 @@ public enum Protocol
|
|
{
|
|
TO_CLIENT.registerPacket(
|
|
StatusResponse.class,
|
|
+ StatusResponse::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
PingPacket.class,
|
|
+ PingPacket::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
|
|
);
|
|
|
|
TO_SERVER.registerPacket(
|
|
StatusRequest.class,
|
|
+ StatusRequest::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
PingPacket.class,
|
|
+ PingPacket::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
|
|
);
|
|
}
|
|
@@ -363,35 +394,43 @@ public enum Protocol
|
|
{
|
|
TO_CLIENT.registerPacket(
|
|
Kick.class,
|
|
+ Kick::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
EncryptionRequest.class,
|
|
+ EncryptionRequest::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
LoginSuccess.class,
|
|
+ LoginSuccess::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x02 )
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
SetCompression.class,
|
|
+ SetCompression::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x03 )
|
|
);
|
|
TO_CLIENT.registerPacket(
|
|
LoginPayloadRequest.class,
|
|
+ LoginPayloadRequest::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x04 )
|
|
);
|
|
|
|
TO_SERVER.registerPacket(
|
|
LoginRequest.class,
|
|
+ LoginRequest::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
EncryptionResponse.class,
|
|
+ EncryptionResponse::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
|
|
);
|
|
TO_SERVER.registerPacket(
|
|
LoginPayloadResponse.class,
|
|
+ LoginPayloadResponse::new, // Waterfall - speed up packet construction
|
|
map( ProtocolConstants.MINECRAFT_1_13, 0x02 )
|
|
);
|
|
}
|
|
@@ -442,7 +481,7 @@ public enum Protocol
|
|
|
|
private final int protocolVersion;
|
|
private final TObjectIntMap<Class<? extends DefinedPacket>> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID );
|
|
- private final Constructor<? extends DefinedPacket>[] packetConstructors = new Constructor[ MAX_PACKET_ID ];
|
|
+ private final java.util.function.Supplier<? extends DefinedPacket>[] packetConstructors = new java.util.function.Supplier[ MAX_PACKET_ID ]; // Waterfall - speed up packet construction
|
|
}
|
|
|
|
@Data
|
|
@@ -510,21 +549,24 @@ public enum Protocol
|
|
throw new BadPacketException( "Packet with id " + id + " outside of range " );
|
|
}
|
|
|
|
- Constructor<? extends DefinedPacket> constructor = protocolData.packetConstructors[id];
|
|
+ java.util.function.Supplier<? extends DefinedPacket> constructor = protocolData.packetConstructors[id]; // Waterfall - speed up packet construction
|
|
try
|
|
{
|
|
- return ( constructor == null ) ? null : constructor.newInstance();
|
|
- } catch ( ReflectiveOperationException ex )
|
|
+ return ( constructor == null ) ? null : constructor.get(); // Waterfall - speed up packet construction
|
|
+ } catch ( Exception ex ) // Waterfall - speed up packet construction
|
|
{
|
|
throw new BadPacketException( "Could not construct packet with id " + id, ex );
|
|
}
|
|
}
|
|
|
|
- private void registerPacket(Class<? extends DefinedPacket> packetClass, ProtocolMapping... mappings)
|
|
+ private <P extends DefinedPacket> void registerPacket(Class<P> packetClass, java.util.function.Supplier<P> constructor, ProtocolMapping... mappings) // Waterfall - speed up packet construction
|
|
{
|
|
+ // Waterfall start - speed up packet construction
|
|
+ /*
|
|
try
|
|
{
|
|
Constructor<? extends DefinedPacket> constructor = packetClass.getDeclaredConstructor();
|
|
+ */ // Waterfall end
|
|
|
|
int mappingIndex = 0;
|
|
ProtocolMapping mapping = mappings[mappingIndex];
|
|
@@ -555,11 +597,32 @@ public enum Protocol
|
|
data.packetConstructors[mapping.packetID] = constructor;
|
|
} // Waterfall
|
|
}
|
|
+ // Waterfall start - speed up packet construction
|
|
+ /*
|
|
} catch ( NoSuchMethodException ex )
|
|
{
|
|
throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass );
|
|
}
|
|
+ */ // Waterfall end
|
|
}
|
|
+ // Waterfall start - speed up packet construction (backwards compat)
|
|
+ private <P extends DefinedPacket> void registerPacket(Class<P> packetClass, ProtocolMapping... mappings) {
|
|
+ java.util.function.Supplier<P> packetSupplier;
|
|
+ try {
|
|
+ Constructor<? extends DefinedPacket> constructor = packetClass.getDeclaredConstructor();
|
|
+ packetSupplier = () -> {
|
|
+ try {
|
|
+ return (P) constructor.newInstance();
|
|
+ } catch (Exception e) {
|
|
+ throw new RuntimeException(e);
|
|
+ }
|
|
+ };
|
|
+ } catch (ReflectiveOperationException e) {
|
|
+ throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass );
|
|
+ }
|
|
+ registerPacket(packetClass, packetSupplier, mappings);
|
|
+ }
|
|
+ // Waterfall end
|
|
|
|
final int getId(Class<? extends DefinedPacket> packet, int version)
|
|
{
|
|
--
|
|
2.31.1
|
|
|