diff --git a/Paper-MojangAPI/pom.xml b/Paper-MojangAPI/pom.xml new file mode 100644 index 000000000..55482a6a9 --- /dev/null +++ b/Paper-MojangAPI/pom.xml @@ -0,0 +1,204 @@ + + + 4.0.0 + + com.destroystokyo.paper + paper-parent + dev-SNAPSHOT + + + com.destroystokyo.paper + paper-mojangapi + 1.15.2-R0.1-SNAPSHOT + jar + + Paper-MojangAPI + https://github.com/PaperMC/Paper + API additions that utilize Mojang Specific API's + + + + 1.8 + 1.8 + UTF-8 + + + + + spigotmc-public + https://hub.spigotmc.org/nexus/content/groups/public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + minecraft-libraries + Minecraft Libraries + https://libraries.minecraft.net + + + + + + spigotmc-public + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + com.destroystokyo.paper + paper-api + ${project.version} + provided + + + + com.mojang + brigadier + 1.0.17 + provided + + + + it.unimi.dsi + fastutil + 8.2.2 + provided + + + + org.jetbrains + annotations + 18.0.0 + provided + + + + junit + junit + 4.13 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + + + org.ow2.asm + asm-tree + 7.3.1 + test + + + + + clean install + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + org.codehaus.plexus + plexus-compiler-eclipse + 2.8.5-spigotmc + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + org.bukkit + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + ${project.build.directory}/dependency-reduced-pom.xml + + true + + + + + + + + development + + false + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + + process-classes + + check + + + + + checkstyle.xml + true + + + + com.puppycrawl.tools + checkstyle + 8.29 + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.18 + + + process-classes + + check + + + + + + org.codehaus.mojo.signature + java18 + 1.0 + + + + + + + + diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java new file mode 100644 index 000000000..3848933b6 --- /dev/null +++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java @@ -0,0 +1,9 @@ +package com.destroystokyo.paper.brigadier; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.suggestion.SuggestionProvider; + +import java.util.function.Predicate; + +public interface BukkitBrigadierCommand extends Command, Predicate, SuggestionProvider { +} diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java new file mode 100644 index 000000000..7a0e81658 --- /dev/null +++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java @@ -0,0 +1,21 @@ +package com.destroystokyo.paper.brigadier; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.Nullable; + +public interface BukkitBrigadierCommandSource { + + @Nullable + Entity getBukkitEntity(); + + @Nullable + World getBukkitWorld(); + + @Nullable + Location getBukkitLocation(); + + CommandSender getBukkitSender(); +} diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java new file mode 100644 index 000000000..a275a85ad --- /dev/null +++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java @@ -0,0 +1,65 @@ +package com.destroystokyo.paper.event.brigadier; + +import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; +import com.mojang.brigadier.tree.RootCommandNode; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.jetbrains.annotations.NotNull; + +/** + * Fired any time a Brigadier RootCommandNode is generated for a player to inform the client of commands. + * You may manipulate this CommandNode to change what the client sees. + * + * This event may fire on login, world change, and permission rebuilds, by plugin request, and potentially future means. + * + * This event will fire before {@link org.bukkit.event.player.PlayerCommandSendEvent}, so no filtering has been done by + * other plugins yet. + * + * WARNING: This event will potentially (and most likely) fire twice! Once for Async, and once again for Sync. + * It is important that you check event.isAsynchronous() and event.hasFiredAsync() to ensure you only act once. + * If for some reason we are unable to send this asynchronously in the future, only the sync method will fire. + * + * Your logic should look like this: + * if (event.isAsynchronous() || !event.hasFiredAsync()) { do stuff } + * + * If your logic is not safe to run asynchronously, only react to the synchronous version. + * @deprecated Draft API - Subject to change until confirmed solves desired use cases + */ +public class AsyncPlayerSendCommandsEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + private final RootCommandNode node; + private final boolean hasFiredAsync; + + public AsyncPlayerSendCommandsEvent(Player player, RootCommandNode node, boolean hasFiredAsync) { + super(player, !Bukkit.isPrimaryThread()); + this.node = node; + this.hasFiredAsync = hasFiredAsync; + } + + /** + * @return The full Root Command Node being sent to the client, which is mutable. + */ + public RootCommandNode getCommandNode() { + return node; + } + + /** + * @return If this event has already fired asynchronously. + */ + public boolean hasFiredAsync() { + return hasFiredAsync; + } + + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java new file mode 100644 index 000000000..92924622b --- /dev/null +++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java @@ -0,0 +1,122 @@ +package com.destroystokyo.paper.event.brigadier; + +import com.destroystokyo.paper.brigadier.BukkitBrigadierCommand; +import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; +import com.mojang.brigadier.tree.ArgumentCommandNode; +import com.mojang.brigadier.tree.LiteralCommandNode; +import com.mojang.brigadier.tree.RootCommandNode; +import org.bukkit.command.Command; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.server.ServerEvent; +import org.jetbrains.annotations.NotNull; + +/** + * Fired anytime the server synchronizes Bukkit CommandMap to Brigadier. + * + * Allows a plugin to control the Literal and Argument nodes for this command to be + * sent to the client. + * This is done at Plugin Enable time after commands have been registered, but some + * plugins may use reflection to retrigger this rebuild during runtime. + * + * @deprecated Draft API - Subject to change until confirmed solves desired use cases + */ +public class CommandRegisteredEvent extends ServerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private final String commandLabel; + private final Command command; + private final BukkitBrigadierCommand brigadierCommand; + private final RootCommandNode root; + private final ArgumentCommandNode defaultArgs; + private LiteralCommandNode literal; + private boolean cancelled = false; + + public CommandRegisteredEvent(String commandLabel, BukkitBrigadierCommand brigadierCommand, Command command, RootCommandNode root, LiteralCommandNode literal, ArgumentCommandNode defaultArgs) { + this.commandLabel = commandLabel; + this.brigadierCommand = brigadierCommand; + this.command = command; + this.root = root; + this.literal = literal; + this.defaultArgs = defaultArgs; + } + + /** + * @return The command name being registered + */ + public String getCommandLabel() { + return commandLabel; + } + + /** + * @return The Bukkit API Brigadier Wrapped Command Object to handle executions and suggestions + */ + public BukkitBrigadierCommand getBrigadierCommand() { + return brigadierCommand; + } + + public Command getCommand() { + return command; + } + + /** + * @return Gets the root command node being used to register a command to. + */ + public RootCommandNode getRoot() { + return root; + } + + /** + * Returns the Bukkit API's default handling of Arguments, if you wish to reuse it. + * @return + */ + public ArgumentCommandNode getDefaultArgs() { + return defaultArgs; + } + + /** + * Returns the Bukkit API's default literal for this command, including the {@link #getDefaultArgs()} as a child already. + * @return + */ + public LiteralCommandNode getLiteral() { + return literal; + } + + /** + * Changes the literal used to register this command. The previous literable is mutable, so this is primarily if + * you want to completely replace the object. + * @param literal + */ + public void setLiteral(LiteralCommandNode literal) { + this.literal = literal; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isCancelled() { + return this.cancelled; + } + + /** + * Cancels registering this command to Brigadier, but will remain in Bukkit Command Map. Can be used to hide a + * command from all players. + * + * {@inheritDoc} + */ + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/Spigot-API-Patches/0001-POM-changes.patch b/Spigot-API-Patches/0001-POM-changes.patch index 4d9703d31..2d3d875c8 100644 --- a/Spigot-API-Patches/0001-POM-changes.patch +++ b/Spigot-API-Patches/0001-POM-changes.patch @@ -1,11 +1,11 @@ -From 755a3e8943286365b0f518c5423687872c8181ae Mon Sep 17 00:00:00 2001 +From 72e2e4af618fca06282903aa0100a779f2945168 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 1 Mar 2016 00:16:08 +0100 Subject: [PATCH] POM changes diff --git a/pom.xml b/pom.xml -index 8964b9e33..ce09baeab 100644 +index 8964b9e3..ce09baea 100644 --- a/pom.xml +++ b/pom.xml @@ -2,34 +2,28 @@ @@ -110,6 +110,19 @@ index 8964b9e33..ce09baeab 100644 true +diff --git a/src/main/java/org/bukkit/event/player/PlayerEvent.java b/src/main/java/org/bukkit/event/player/PlayerEvent.java +index 793b661b..b7c8f2c3 100644 +--- a/src/main/java/org/bukkit/event/player/PlayerEvent.java ++++ b/src/main/java/org/bukkit/event/player/PlayerEvent.java +@@ -14,7 +14,7 @@ public abstract class PlayerEvent extends Event { + player = who; + } + +- PlayerEvent(@NotNull final Player who, boolean async) { ++ public PlayerEvent(@NotNull final Player who, boolean async) { // Paper - wtf? + super(async); + player = who; + -- -2.25.1 +2.26.2 diff --git a/Spigot-Server-Patches/0001-POM-Changes.patch b/Spigot-Server-Patches/0001-POM-Changes.patch index 2e91d6905..6e84e2209 100644 --- a/Spigot-Server-Patches/0001-POM-Changes.patch +++ b/Spigot-Server-Patches/0001-POM-Changes.patch @@ -1,11 +1,11 @@ -From c9716ffd01bb1c07e57fdb1e3f5da315ce435605 Mon Sep 17 00:00:00 2001 +From e5972e429a6ce140fcdca52e906abf72e8c20243 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Mon, 29 Feb 2016 20:40:33 -0600 Subject: [PATCH] POM Changes diff --git a/pom.xml b/pom.xml -index def28b3bec..3dc6c2a3f5 100644 +index def28b3bec..23f33d0477 100644 --- a/pom.xml +++ b/pom.xml @@ -1,15 +1,14 @@ @@ -28,7 +28,7 @@ index def28b3bec..3dc6c2a3f5 100644 UTF-8 unknown 1.15.2 -@@ -22,16 +21,16 @@ +@@ -22,16 +21,22 @@ @@ -46,10 +46,16 @@ index def28b3bec..3dc6c2a3f5 100644 - spigot-api + com.destroystokyo.paper + paper-api ++ ${project.version} ++ compile ++ ++ ++ com.destroystokyo.paper ++ paper-mojangapi ${project.version} compile -@@ -109,34 +108,22 @@ +@@ -109,34 +114,22 @@ @@ -95,7 +101,7 @@ index def28b3bec..3dc6c2a3f5 100644 -@@ -146,11 +133,13 @@ +@@ -146,11 +139,13 @@ maven-jar-plugin 2.4 @@ -110,7 +116,7 @@ index def28b3bec..3dc6c2a3f5 100644 ${maven.build.timestamp} Bukkit ${api.version} -@@ -190,6 +179,7 @@ +@@ -190,6 +185,7 @@ shade @@ -118,7 +124,7 @@ index def28b3bec..3dc6c2a3f5 100644 ${shadeSourcesJar} -@@ -203,10 +193,11 @@ +@@ -203,10 +199,11 @@ jline org.bukkit.craftbukkit.libs.jline @@ -134,7 +140,7 @@ index def28b3bec..3dc6c2a3f5 100644 org.apache.commons.codec org.bukkit.craftbukkit.libs.org.apache.commons.codec -@@ -248,10 +239,6 @@ +@@ -248,10 +245,6 @@ org.apache.maven.plugins maven-compiler-plugin 3.8.1 @@ -159,5 +165,5 @@ index 93046379d0..674096cab1 100644 if (stream != null) { -- -2.25.1 +2.26.2 diff --git a/Spigot-Server-Patches/0149-Use-TerminalConsoleAppender-for-console-improvements.patch b/Spigot-Server-Patches/0149-Use-TerminalConsoleAppender-for-console-improvements.patch index 6774aab95..78979fe45 100644 --- a/Spigot-Server-Patches/0149-Use-TerminalConsoleAppender-for-console-improvements.patch +++ b/Spigot-Server-Patches/0149-Use-TerminalConsoleAppender-for-console-improvements.patch @@ -1,4 +1,4 @@ -From bd039fe4f27ea8f45a60714fb121a7e639eb0b94 Mon Sep 17 00:00:00 2001 +From 1c57cf609900d050035f40a897d442f171803efa Mon Sep 17 00:00:00 2001 From: Minecrell Date: Fri, 9 Jun 2017 19:03:43 +0200 Subject: [PATCH] Use TerminalConsoleAppender for console improvements @@ -19,10 +19,10 @@ Other changes: configuration diff --git a/pom.xml b/pom.xml -index 3dc6c2a3f5..b1f008738b 100644 +index 23f33d0477..dea7bc2619 100644 --- a/pom.xml +++ b/pom.xml -@@ -41,10 +41,27 @@ +@@ -47,10 +47,27 @@ compile @@ -54,7 +54,7 @@ index 3dc6c2a3f5..b1f008738b 100644 org.ow2.asm -@@ -230,10 +247,18 @@ +@@ -236,10 +253,18 @@ META-INF/services/java.sql.Driver diff --git a/Spigot-Server-Patches/0170-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch b/Spigot-Server-Patches/0170-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch index 108893d05..f22a2ba71 100644 --- a/Spigot-Server-Patches/0170-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch +++ b/Spigot-Server-Patches/0170-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch @@ -1,4 +1,4 @@ -From cc7eb34ab0d7d3ed2ac9c1133b0867d3f46c0227 Mon Sep 17 00:00:00 2001 +From 5f12e07474ebfc007a3a8fddca90e4e076127efa Mon Sep 17 00:00:00 2001 From: Minecrell Date: Mon, 18 Sep 2017 12:00:03 +0200 Subject: [PATCH] Use Log4j IOStreams to redirect System.out/err to logger @@ -12,10 +12,10 @@ results in a separate line, even though it should not result in a line break. Log4j's implementation handles it correctly. diff --git a/pom.xml b/pom.xml -index b1f00873..14c4ec25 100644 +index dea7bc2619..24cdeb6ff4 100644 --- a/pom.xml +++ b/pom.xml -@@ -63,6 +63,11 @@ +@@ -69,6 +69,11 @@ 2.8.1 runtime @@ -28,7 +28,7 @@ index b1f00873..14c4ec25 100644 org.ow2.asm asm diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java -index d34f772f..ec257ba3 100644 +index d34f772fae..ec257ba31f 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -155,8 +155,10 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer @@ -45,5 +45,5 @@ index d34f772f..ec257ba3 100644 thread.setDaemon(true); -- -2.25.1.windows.1 +2.26.2 diff --git a/Spigot-Server-Patches/0171-Handle-plugin-prefixes-using-Log4J-configuration.patch b/Spigot-Server-Patches/0171-Handle-plugin-prefixes-using-Log4J-configuration.patch index f91152739..1489aa922 100644 --- a/Spigot-Server-Patches/0171-Handle-plugin-prefixes-using-Log4J-configuration.patch +++ b/Spigot-Server-Patches/0171-Handle-plugin-prefixes-using-Log4J-configuration.patch @@ -1,4 +1,4 @@ -From d1c079b07d209c70bf52c519ce4b2cfc5a2a9fe0 Mon Sep 17 00:00:00 2001 +From c564d96c0c02a902a986e9a512da7dc5a2b25628 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Thu, 21 Sep 2017 16:14:55 +0200 Subject: [PATCH] Handle plugin prefixes using Log4J configuration @@ -15,10 +15,10 @@ This may cause additional prefixes to be disabled for plugins bypassing the plugin logger. diff --git a/pom.xml b/pom.xml -index 14c4ec25..5a230592 100644 +index 24cdeb6ff4..ab8c61ab53 100644 --- a/pom.xml +++ b/pom.xml -@@ -61,7 +61,7 @@ +@@ -67,7 +67,7 @@ org.apache.logging.log4j log4j-core 2.8.1 @@ -28,7 +28,7 @@ index 14c4ec25..5a230592 100644 org.apache.logging.log4j diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java -index fdca3434..6d77bbc5 100644 +index fdca34346a..6d77bbc5aa 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/src/main/java/org/spigotmc/SpigotConfig.java @@ -286,7 +286,7 @@ public class SpigotConfig @@ -41,7 +41,7 @@ index fdca3434..6d77bbc5 100644 public static int playerShuffle; diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml -index 620b9490..a8bdaaea 100644 +index 620b9490e5..a8bdaaeaa1 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -5,10 +5,22 @@ @@ -70,5 +70,5 @@ index 620b9490..a8bdaaea 100644 -- -2.25.1.windows.1 +2.26.2 diff --git a/Spigot-Server-Patches/0172-Include-Log4J2-SLF4J-implementation.patch b/Spigot-Server-Patches/0172-Include-Log4J2-SLF4J-implementation.patch index a03554a39..5a6028042 100644 --- a/Spigot-Server-Patches/0172-Include-Log4J2-SLF4J-implementation.patch +++ b/Spigot-Server-Patches/0172-Include-Log4J2-SLF4J-implementation.patch @@ -1,14 +1,14 @@ -From a40b48933c0e67d7f6146cf6a40d377a33b54857 Mon Sep 17 00:00:00 2001 +From 9e21ba071cd08c5232b4352237d05eec746746f8 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Thu, 21 Sep 2017 16:33:35 +0200 Subject: [PATCH] Include Log4J2 SLF4J implementation diff --git a/pom.xml b/pom.xml -index 5a230592..6f2fe9c2 100644 +index ab8c61ab53..76ce7f4486 100644 --- a/pom.xml +++ b/pom.xml -@@ -63,6 +63,12 @@ +@@ -69,6 +69,12 @@ 2.8.1 compile @@ -22,5 +22,5 @@ index 5a230592..6f2fe9c2 100644 org.apache.logging.log4j log4j-iostreams -- -2.25.1.windows.1 +2.26.2 diff --git a/Spigot-Server-Patches/0247-Use-asynchronous-Log4j-2-loggers.patch b/Spigot-Server-Patches/0247-Use-asynchronous-Log4j-2-loggers.patch index 11bae125e..a16a0f8e4 100644 --- a/Spigot-Server-Patches/0247-Use-asynchronous-Log4j-2-loggers.patch +++ b/Spigot-Server-Patches/0247-Use-asynchronous-Log4j-2-loggers.patch @@ -1,14 +1,14 @@ -From 3d7f218a63941724b6e4fd12852b8e8a1f12df98 Mon Sep 17 00:00:00 2001 +From f52e7ce0fdce36da196c298d84ac8b5d778c4cb6 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Tue, 17 Jul 2018 16:42:17 +0200 Subject: [PATCH] Use asynchronous Log4j 2 loggers diff --git a/pom.xml b/pom.xml -index 6f2fe9c2..55679af9 100644 +index 76ce7f4486..28ff064c19 100644 --- a/pom.xml +++ b/pom.xml -@@ -74,6 +74,13 @@ +@@ -80,6 +80,13 @@ log4j-iostreams 2.8.1 @@ -24,7 +24,7 @@ index 6f2fe9c2..55679af9 100644 asm diff --git a/src/main/java/com/destroystokyo/paper/log/LogFullPolicy.java b/src/main/java/com/destroystokyo/paper/log/LogFullPolicy.java new file mode 100644 -index 00000000..db652a1f +index 0000000000..db652a1f7a --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/log/LogFullPolicy.java @@ -0,0 +1,17 @@ @@ -46,7 +46,7 @@ index 00000000..db652a1f + } +} diff --git a/src/main/resources/log4j2.component.properties b/src/main/resources/log4j2.component.properties -index 0694b214..30efeb5f 100644 +index 0694b21465..30efeb5faf 100644 --- a/src/main/resources/log4j2.component.properties +++ b/src/main/resources/log4j2.component.properties @@ -1 +1,3 @@ @@ -54,5 +54,5 @@ index 0694b214..30efeb5f 100644 +log4j2.AsyncQueueFullPolicy="com.destroystokyo.paper.log.LogFullPolicy" log4j.skipJansi=true -- -2.25.1.windows.1 +2.26.2 diff --git a/Spigot-Server-Patches/0494-Implement-Brigadier-Mojang-API.patch b/Spigot-Server-Patches/0494-Implement-Brigadier-Mojang-API.patch new file mode 100644 index 000000000..3d6b7e4ca --- /dev/null +++ b/Spigot-Server-Patches/0494-Implement-Brigadier-Mojang-API.patch @@ -0,0 +1,110 @@ +From bdb2c31298c1b905485d70aa0e4a09841fd38023 Mon Sep 17 00:00:00 2001 +From: Aikar +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 2414b0a552..2d512aa4f9 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(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 bukkit, RootCommandNode rootcommandnode) { + // Paper end - Async command map building ++ new com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent(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 0b23a0548d..c988c929f1 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/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java +index 5f33c9e52a..e16ecdea7d 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, Predicate, SuggestionProvider { ++public class BukkitCommandWrapper implements com.mojang.brigadier.Command, Predicate, SuggestionProvider, com.destroystokyo.paper.brigadier.BukkitBrigadierCommand { // Paper + + private final CraftServer server; + private final Command command; +@@ -28,10 +28,19 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command register(CommandDispatcher dispatcher, String label) { +- return dispatcher.register( +- LiteralArgumentBuilder.literal(label).requires(this).executes(this) +- .then(RequiredArgumentBuilder.argument("args", StringArgumentType.greedyString()).suggests(this).executes(this)) +- ); ++ // Paper start - Expose Brigadier to Paper-MojangAPI ++ com.mojang.brigadier.tree.RootCommandNode root = dispatcher.getRoot(); ++ LiteralCommandNode literal = LiteralArgumentBuilder.literal(label).requires(this).executes(this).build(); ++ com.mojang.brigadier.tree.ArgumentCommandNode defaultArgs = RequiredArgumentBuilder.argument("args", StringArgumentType.greedyString()).suggests(this).executes(this).build(); ++ literal.addChild(defaultArgs); ++ com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent 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 +-- +2.26.2 + diff --git a/pom.xml b/pom.xml index 3541b9580..4ddd1eb64 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,9 @@ https://github.com/PaperMC/Paper - Paper-Server Paper-API + Paper-MojangAPI + Paper-Server