Skip to content

Commit

Permalink
Improve tag parser handling, move hunks out of chunk system patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Feb 5, 2024
1 parent c5d168c commit 9e171ef
Show file tree
Hide file tree
Showing 53 changed files with 351 additions and 244 deletions.
77 changes: 35 additions & 42 deletions patches/server/0162-AsyncTabCompleteEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Also adds isCommand and getLocation to the sync TabCompleteEvent
Co-authored-by: Aikar <aikar@aikar.co>

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index ba2628f22907b386fe5638220e5f10e39bc1f80b..2d633b9921e04dac21d705ffdf0f5a92b41c2e30 100644
index a30eb2a9e201face352be5c6f74e690d8e5c0478..0497393afd8f60ac17148dde2a394b4b6795c7d8 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -688,27 +688,58 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -688,21 +688,58 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

}

Expand All @@ -33,61 +33,54 @@ index ba2628f22907b386fe5638220e5f10e39bc1f80b..2d633b9921e04dac21d705ffdf0f5a92
+ // PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - AsyncTabCompleteEvent; run this async
// CraftBukkit start
if (this.chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
- this.disconnect(Component.translatable("disconnect.spam"));
+ server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam"))); // Paper - AsyncTabCompleteEvent
this.disconnect(Component.translatable("disconnect.spam"));
return;
}
// CraftBukkit end
+ // Paper start - AsyncTabCompleteEvent
+ TAB_COMPLETE_EXECUTOR.execute(() -> {
+ TAB_COMPLETE_EXECUTOR.execute(() -> this.handleCustomCommandSuggestions0(packet));
+ }
+
+ private void handleCustomCommandSuggestions0(final ServerboundCommandSuggestionPacket packet) {
StringReader stringreader = new StringReader(packet.getCommand());

if (stringreader.canRead() && stringreader.peek() == '/') {
stringreader.skip();
}
-
- ParseResults<CommandSourceStack> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
-
- this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
- if (suggestions.isEmpty()) return; // CraftBukkit - don't send through empty suggestions - prevents [<args>] from showing for plugins with nothing more to offer
- this.send(new ClientboundCommandSuggestionsPacket(packet.getId(), suggestions));
+ final String command = packet.getCommand();
+ final com.destroystokyo.paper.event.server.AsyncTabCompleteEvent event = new com.destroystokyo.paper.event.server.AsyncTabCompleteEvent(this.getCraftPlayer(), command, true, null);
+ event.callEvent();
+ final java.util.List<com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion> completions = event.isCancelled() ? com.google.common.collect.ImmutableList.of() : event.completions();
+ // If the event isn't handled, we can assume that we have no completions, and so we'll ask the server
+ if (!event.isHandled()) {
+ if (!event.isCancelled()) {
+
+ this.server.scheduleOnMain(() -> { // This needs to be on main
+ ParseResults<CommandSourceStack> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());

+ final com.destroystokyo.paper.event.server.AsyncTabCompleteEvent event = new com.destroystokyo.paper.event.server.AsyncTabCompleteEvent(this.getCraftPlayer(), packet.getCommand(), true, null);
+ event.callEvent();
+ final List<com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion> completions = event.isCancelled() ? com.google.common.collect.ImmutableList.of() : event.completions();
+ // If the event isn't handled, we can assume that we have no completions, and so we'll ask the server
+ if (!event.isHandled()) {
+ if (event.isCancelled()) {
+ return;
+ }
+
+ this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
+ if (suggestions.isEmpty()) return; // CraftBukkit - don't send through empty suggestions - prevents [<args>] from showing for plugins with nothing more to offer
+ this.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), suggestions));
+ });
+ });
+ // This needs to be on main
+ this.server.scheduleOnMain(() -> this.sendServerSuggestions(packet, stringreader));
+ } else if (!completions.isEmpty()) {
+ final com.mojang.brigadier.suggestion.SuggestionsBuilder builder0 = new com.mojang.brigadier.suggestion.SuggestionsBuilder(packet.getCommand(), stringreader.getTotalLength());
+ final com.mojang.brigadier.suggestion.SuggestionsBuilder builder = builder0.createOffset(builder0.getInput().lastIndexOf(' ') + 1);
+ for (final com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion completion : completions) {
+ final Integer intSuggestion = com.google.common.primitives.Ints.tryParse(completion.suggestion());
+ if (intSuggestion != null) {
+ builder.suggest(intSuggestion, PaperAdventure.asVanilla(completion.tooltip()));
+ } else {
+ builder.suggest(completion.suggestion(), PaperAdventure.asVanilla(completion.tooltip()));
+ }
+ } else if (!completions.isEmpty()) {
+ final com.mojang.brigadier.suggestion.SuggestionsBuilder builder0 = new com.mojang.brigadier.suggestion.SuggestionsBuilder(command, stringreader.getTotalLength());
+ final com.mojang.brigadier.suggestion.SuggestionsBuilder builder = builder0.createOffset(builder0.getInput().lastIndexOf(' ') + 1);
+ completions.forEach(completion -> {
+ final Integer intSuggestion = com.google.common.primitives.Ints.tryParse(completion.suggestion());
+ if (intSuggestion != null) {
+ builder.suggest(intSuggestion, PaperAdventure.asVanilla(completion.tooltip()));
+ } else {
+ builder.suggest(completion.suggestion(), PaperAdventure.asVanilla(completion.tooltip()));
+ }
+ });
+ player.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), builder.buildFuture().join()));
+ }
});
+ this.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), builder.buildFuture().join()));
+ }
+ }
+
+ private void sendServerSuggestions(final ServerboundCommandSuggestionPacket packet, final StringReader stringreader) {
+ // Paper end - AsyncTabCompleteEvent
}
ParseResults<CommandSourceStack> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());

@Override
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 59776663cee396f29f05988d8e22dd5c23b118b5..fb26379f600cc3e7e286d246f25e2bf718611e9d 100644
index 46acd80641b2ecafd9f364d7ad9b477b6b2f0289..22e61d492c935688b6d1d63d13ba8313abd9e1b4 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2227,7 +2227,7 @@ public final class CraftServer implements Server {
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0177-Player.setPlayerProfile-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ This can be useful for changing name or skins after a player has logged in.
public-f net.minecraft.world.entity.player.Player gameProfile

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 35c8c18fac425a60300718e80fd5304d2e41b53a..e37dc60167b8a6c3c321b5931ed90d13d4520236 100644
index 0497393afd8f60ac17148dde2a394b4b6795c7d8..1da44846ad1ed2768fd7ebca4017c4bbc399ba68 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1461,7 +1461,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -1467,7 +1467,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
this.internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet());
}

Expand Down
4 changes: 2 additions & 2 deletions patches/server/0209-InventoryCloseEvent-Reason-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ index d51244c634d0209efb98be965ce7318480220b96..33108a55c1cc305d44238d0862755af8
this.doCloseContainer();
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index e37dc60167b8a6c3c321b5931ed90d13d4520236..ddc9361f80bf28252852f9169b0f5d2f7a8320ba 100644
index 1da44846ad1ed2768fd7ebca4017c4bbc399ba68..6bd81598a45fd0b428740f7be674adfe0c26aa05 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2520,10 +2520,15 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -2526,10 +2526,15 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

@Override
public void handleContainerClose(ServerboundContainerClosePacket packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Refresh the player inventory when PlayerInteractEntityEvent is
cancelled to avoid this problem.

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index ddc9361f80bf28252852f9169b0f5d2f7a8320ba..2e2bf7ba0a2511128cac1ff47b9a38a67b61522c 100644
index 6bd81598a45fd0b428740f7be674adfe0c26aa05..60443fecfc6956e9863d8cf3cf74be447d48ba34 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2411,6 +2411,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -2417,6 +2417,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}

if (event.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ to take the burden of this into their own hand without having to rely on
plugins doing unsafe things.

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 2e2bf7ba0a2511128cac1ff47b9a38a67b61522c..14dc58263afbdafb576bd10f7b98403466093834 100644
index 60443fecfc6956e9863d8cf3cf74be447d48ba34..4787d49964ddb93558faa271ad27f5bbc17742f2 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -256,6 +256,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
Expand All @@ -47,6 +47,6 @@ index 2e2bf7ba0a2511128cac1ff47b9a38a67b61522c..14dc58263afbdafb576bd10f7b984034
// CraftBukkit start
- if (this.chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
+ if (this.chatSpamTickCount.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper - configurable tab spam limits
server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam"))); // Paper - AsyncTabCompleteEvent
this.disconnect(Component.translatable("disconnect.spam"));
return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Subject: [PATCH] Add option to prevent players from moving into unloaded


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 14dc58263afbdafb576bd10f7b98403466093834..5f68a0cd7e2484933dfa09cb54a0f2f18fa2241c 100644
index 4787d49964ddb93558faa271ad27f5bbc17742f2..0c5ddfc6c12aaab10369ff96fcac1152965befcf 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -474,9 +474,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
Expand Down Expand Up @@ -39,7 +39,7 @@ index 14dc58263afbdafb576bd10f7b98403466093834..5f68a0cd7e2484933dfa09cb54a0f2f1
if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
// CraftBukkit end
ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
@@ -1172,9 +1182,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -1178,9 +1188,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

} else {
this.awaitingTeleportTime = this.tickCount;
Expand All @@ -52,7 +52,7 @@ index 14dc58263afbdafb576bd10f7b98403466093834..5f68a0cd7e2484933dfa09cb54a0f2f1
float f = Mth.wrapDegrees(packet.getYRot(this.player.getYRot()));
float f1 = Mth.wrapDegrees(packet.getXRot(this.player.getXRot()));

@@ -1230,6 +1240,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -1236,6 +1246,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
} else {
speed = this.player.getAbilities().walkingSpeed * 10f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ index a8d33286832786031ac57e6ce27d5181e1a3d9b1..e8b12b27e5ec74afb940f575e5ce78e5

this.level.destroyBlockProgress(this.player.getId(), pos, -1);
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 5f68a0cd7e2484933dfa09cb54a0f2f18fa2241c..7c9e4673ef06c08f04691137cbef5ed3fc5d0b4b 100644
index 0c5ddfc6c12aaab10369ff96fcac1152965befcf..7a63be0cfda49395c19d563bd298bf48888fd84c 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1584,6 +1584,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -1590,6 +1590,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
case START_DESTROY_BLOCK:
case ABORT_DESTROY_BLOCK:
case STOP_DESTROY_BLOCK:
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0277-Book-Size-Limits.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Book Size Limits
Puts some limits on the size of books.

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 7c9e4673ef06c08f04691137cbef5ed3fc5d0b4b..06120b7da7f830f4bb36e5c1ec71201e344a1182 100644
index 7a63be0cfda49395c19d563bd298bf48888fd84c..2a49c02ad4baccc1fe3b0b69da0e584b7efec3ee 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1018,6 +1018,45 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@@ -1024,6 +1024,45 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

@Override
public void handleEditBook(ServerboundEditBookPacket packet) {
Expand Down
Loading

0 comments on commit 9e171ef

Please sign in to comment.