Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 19:10:09 +01:00
614a664bd3
Mark chunks that are blocking main thread for world generation as urgent Implements a general priority system so that chunks that are sorted in the generator queues can prioritize certain chunks over another. Urgent chunks will jump to the front of the line, ensuring that a sync chunk load on an ungenerated chunk does not lag the server for a long period of time if the servers generator queues are filled with lots of chunks already. This massively reduces the lag spikes from sync chunk gens. Then we further prioritize loading order so nearby chunks have higher priority than distant chunks, reducing the pressure a high no tick view distance holds on you. Chunks in front of the player have higher priority, to help with fast traveling players keep up with their movement. This commit also improves single core cpu scenarios in that we will now automatically disable Async Chunks as well as Minecrafts thread pool. It is never recommended to use async chunks on a single CPU as context switching will be slower than just running it all on main. This also bumps the number of server worker threads by default too. Mojang does not utilize the workers in an effecient manner, resulting in them using barely any sustained CPU. So give it more workers so more chunks can be processed concurrently This change also improves urgent chunk loading, so players flying into unloaded chunks will hurt a little bit less (but still hurt) Ping #3395 #3363 (Not marking as closed, we need to make prevent moving work)
140 Zeilen
9.0 KiB
Diff
140 Zeilen
9.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sun, 19 Apr 2020 18:15:29 -0400
|
|
Subject: [PATCH] Implement Brigadier Mojang API
|
|
|
|
Adds AsyncPlayerSendCommandsEvent
|
|
- Allows modifying on a per command basis what command data they see.
|
|
|
|
Adds CommandRegisteredEvent
|
|
- Allows manipulating the CommandNode to add more children/metadata for the client
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/CommandDispatcher.java b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
|
index 2414b0a552e5d6fb449bca163add7a9bac39e943..2d512aa4f9ab74dfadff748ba6dd72631eda9fe5 100644
|
|
--- a/src/main/java/net/minecraft/server/CommandDispatcher.java
|
|
+++ b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
|
@@ -267,6 +267,7 @@ public class CommandDispatcher {
|
|
bukkit.add(node.getName());
|
|
}
|
|
// Paper start - Async command map building
|
|
+ new com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent<CommandListenerWrapper>(entityplayer.getBukkitEntity(), (RootCommandNode) rootcommandnode, false).callEvent(); // Paper
|
|
MinecraftServer.getServer().execute(() -> {
|
|
runSync(entityplayer, bukkit, rootcommandnode);
|
|
});
|
|
@@ -274,6 +275,7 @@ public class CommandDispatcher {
|
|
|
|
private void runSync(EntityPlayer entityplayer, Collection<String> bukkit, RootCommandNode<ICompletionProvider> rootcommandnode) {
|
|
// Paper end - Async command map building
|
|
+ new com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent<CommandListenerWrapper>(entityplayer.getBukkitEntity(), (RootCommandNode) rootcommandnode, false).callEvent(); // Paper
|
|
PlayerCommandSendEvent event = new PlayerCommandSendEvent(entityplayer.getBukkitEntity(), new LinkedHashSet<>(bukkit));
|
|
event.getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/CommandListenerWrapper.java b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
index 0b23a0548d52a30c064d624e39a896a9791aab3b..c988c929f1063b417d10d84b0c13127738f63e20 100644
|
|
--- a/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
+++ b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
|
|
@@ -15,7 +15,7 @@ import java.util.function.BinaryOperator;
|
|
import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
|
|
-public class CommandListenerWrapper implements ICompletionProvider {
|
|
+public class CommandListenerWrapper implements ICompletionProvider, com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource { // Paper
|
|
|
|
public static final SimpleCommandExceptionType a = new SimpleCommandExceptionType(new ChatMessage("permissions.requires.player", new Object[0]));
|
|
public static final SimpleCommandExceptionType b = new SimpleCommandExceptionType(new ChatMessage("permissions.requires.entity", new Object[0]));
|
|
@@ -120,6 +120,25 @@ public class CommandListenerWrapper implements ICompletionProvider {
|
|
return this.g;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public org.bukkit.entity.Entity getBukkitEntity() {
|
|
+ return getEntity() != null ? getEntity().getBukkitEntity() : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.World getBukkitWorld() {
|
|
+ return getWorld() != null ? getWorld().getWorld() : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.Location getBukkitLocation() {
|
|
+ Vec3D pos = getPosition();
|
|
+ org.bukkit.World world = getBukkitWorld();
|
|
+ return world != null && pos != null ? new org.bukkit.Location(world, pos.x, pos.y, pos.z) : null;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public boolean hasPermission(int i) {
|
|
// CraftBukkit start
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index 148cd6a850ef87095558d008fbaf0038d537b78a..63cbdc3531712b9b63f75789c3481a74a44a0fa7 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -581,8 +581,12 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
ParseResults<CommandListenerWrapper> parseresults = this.minecraftServer.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener());
|
|
|
|
this.minecraftServer.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
|
|
- if (((Suggestions) suggestions).isEmpty()) return; // CraftBukkit - don't send through empty suggestions - prevents [<args>] from showing for plugins with nothing more to offer
|
|
- this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), (Suggestions) suggestions)); // CraftBukkit - decompile error
|
|
+ // Paper start
|
|
+ com.destroystokyo.paper.event.brigadier.AsyncPlayerSendSuggestionsEvent suggestEvent = new com.destroystokyo.paper.event.brigadier.AsyncPlayerSendSuggestionsEvent(this.getPlayer(), suggestions, buffer);
|
|
+ suggestEvent.setCancelled(suggestions.isEmpty());
|
|
+ if (!suggestEvent.callEvent()) return;
|
|
+ this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), (Suggestions) suggestEvent.getSuggestions())); // CraftBukkit - decompile error // Paper
|
|
+ // Paper end
|
|
});
|
|
}); // Paper - This needs to be on main
|
|
}
|
|
@@ -592,7 +596,11 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
|
|
builder = builder.createOffset(builder.getInput().lastIndexOf(' ') + 1);
|
|
completions.forEach(builder::suggest);
|
|
- player.playerConnection.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), builder.buildFuture().join()));
|
|
+ Suggestions suggestions = builder.buildFuture().join();
|
|
+ com.destroystokyo.paper.event.brigadier.AsyncPlayerSendSuggestionsEvent suggestEvent = new com.destroystokyo.paper.event.brigadier.AsyncPlayerSendSuggestionsEvent(this.getPlayer(), suggestions, buffer);
|
|
+ suggestEvent.setCancelled(suggestions.isEmpty());
|
|
+ if (!suggestEvent.callEvent()) return;
|
|
+ this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestEvent.getSuggestions()));
|
|
}
|
|
// Paper end - async tab completion
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
|
index 5f33c9e52ac51486d4b22a6dcbfac7f46e0412bb..e16ecdea7d27424053b3f21378af054b2f808eca 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
|
@@ -17,7 +17,7 @@ import net.minecraft.server.CommandListenerWrapper;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
-public class BukkitCommandWrapper implements com.mojang.brigadier.Command<CommandListenerWrapper>, Predicate<CommandListenerWrapper>, SuggestionProvider<CommandListenerWrapper> {
|
|
+public class BukkitCommandWrapper implements com.mojang.brigadier.Command<CommandListenerWrapper>, Predicate<CommandListenerWrapper>, SuggestionProvider<CommandListenerWrapper>, com.destroystokyo.paper.brigadier.BukkitBrigadierCommand<CommandListenerWrapper> { // Paper
|
|
|
|
private final CraftServer server;
|
|
private final Command command;
|
|
@@ -28,10 +28,19 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
|
|
}
|
|
|
|
public LiteralCommandNode<CommandListenerWrapper> register(CommandDispatcher<CommandListenerWrapper> dispatcher, String label) {
|
|
- return dispatcher.register(
|
|
- LiteralArgumentBuilder.<CommandListenerWrapper>literal(label).requires(this).executes(this)
|
|
- .then(RequiredArgumentBuilder.<CommandListenerWrapper, String>argument("args", StringArgumentType.greedyString()).suggests(this).executes(this))
|
|
- );
|
|
+ // Paper start - Expose Brigadier to Paper-MojangAPI
|
|
+ com.mojang.brigadier.tree.RootCommandNode<CommandListenerWrapper> root = dispatcher.getRoot();
|
|
+ LiteralCommandNode<CommandListenerWrapper> literal = LiteralArgumentBuilder.<CommandListenerWrapper>literal(label).requires(this).executes(this).build();
|
|
+ com.mojang.brigadier.tree.ArgumentCommandNode<CommandListenerWrapper, String> defaultArgs = RequiredArgumentBuilder.<CommandListenerWrapper, String>argument("args", StringArgumentType.greedyString()).suggests(this).executes(this).build();
|
|
+ literal.addChild(defaultArgs);
|
|
+ com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent<CommandListenerWrapper> event = new com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent<>(label, this, this.command, root, literal, defaultArgs);
|
|
+ if (!event.callEvent()) {
|
|
+ return null;
|
|
+ }
|
|
+ literal = event.getLiteral();
|
|
+ root.addChild(literal);
|
|
+ return literal;
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|