Brigadier based command API

== AT ==
public net.minecraft.commands.arguments.blocks.BlockInput tag
public net.minecraft.commands.arguments.DimensionArgument ERROR_INVALID_VALUE
public net.minecraft.server.ReloadableServerResources registryLookup
public net.minecraft.server.ReloadableServerResources

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Marc Baloup <marc.baloup@laposte.net>
This commit is contained in:
Owen1212055
2022-08-01 22:50:34 -04:00
parent aabe9f5264
commit 977543c545
37 changed files with 2324 additions and 304 deletions

View File

@@ -1558,12 +1558,10 @@
}
return optional;
@@ -1564,8 +2394,129 @@
}
@@ -1566,6 +2396,117 @@
return false;
+ }
+
}
+ // CraftBukkit start - add method
+ public void chat(String s, PlayerChatMessage original, boolean async) {
+ if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) {
@@ -1656,39 +1654,29 @@
+ this.server.console.sendMessage(s);
+ }
+ }
}
+ private void handleCommand(String s) {
+ org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + s); // Paper - Add async catcher
+ if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
+ this.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + s);
+ }
+
+ CraftPlayer player = this.getCraftPlayer();
+
+ PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s, new LazyPlayerSet(this.server));
+ this.cserver.getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ try {
+ if (this.cserver.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
+ return;
+ }
+ } catch (org.bukkit.command.CommandException ex) {
+ player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
+ java.util.logging.Logger.getLogger(ServerGamePacketListenerImpl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ return;
+ } finally {
+ @Deprecated // Paper
+ public void handleCommand(String s) { // Paper - private -> public
+ // Paper start - Remove all this old duplicated logic
+ if (s.startsWith("/")) {
+ s = s.substring(1);
+ }
+ /*
+ It should be noted that this represents the "legacy" command execution path.
+ Api can call commands even if there is no additional context provided.
+ This method should ONLY be used if you need to execute a command WITHOUT
+ an actual player's input.
+ */
+ this.performUnsignedChatCommand(s);
+ // Paper end
+ }
+ // CraftBukkit end
+
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
@@ -1573,15 +2524,44 @@
@@ -1573,15 +2514,44 @@
}
private void broadcastChatMessage(PlayerChatMessage message) {
@@ -1739,7 +1727,7 @@
}
@@ -1592,7 +2572,7 @@
@@ -1592,7 +2562,7 @@
synchronized (this.lastSeenMessages) {
if (!this.lastSeenMessages.applyOffset(packet.offset())) {
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
@@ -1748,7 +1736,7 @@
}
}
@@ -1601,7 +2581,40 @@
@@ -1601,7 +2571,40 @@
@Override
public void handleAnimate(ServerboundSwingPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1789,7 +1777,7 @@
this.player.swing(packet.getHand());
}
@@ -1609,6 +2622,29 @@
@@ -1609,6 +2612,29 @@
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasClientLoaded()) {
@@ -1819,7 +1807,7 @@
this.player.resetLastActionTime();
Entity entity;
PlayerRideableJumping ijumpable;
@@ -1616,6 +2652,11 @@
@@ -1616,6 +2642,11 @@
switch (packet.getAction()) {
case PRESS_SHIFT_KEY:
this.player.setShiftKeyDown(true);
@@ -1831,7 +1819,7 @@
break;
case RELEASE_SHIFT_KEY:
this.player.setShiftKeyDown(false);
@@ -1684,13 +2725,19 @@
@@ -1684,13 +2715,19 @@
}
if (i > 4096) {
@@ -1852,7 +1840,7 @@
this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params));
this.addPendingMessage(message);
}
@@ -1701,7 +2748,19 @@
@@ -1701,7 +2738,19 @@
public SocketAddress getRemoteAddress() {
return this.connection.getRemoteAddress();
@@ -1872,7 +1860,7 @@
public void switchToConfig() {
this.waitingForSwitchToConfig = true;
@@ -1718,9 +2777,17 @@
@@ -1718,9 +2767,17 @@
@Override
public void handleInteract(ServerboundInteractPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1890,7 +1878,7 @@
this.player.resetLastActionTime();
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
@@ -1733,20 +2800,59 @@
@@ -1733,20 +2790,59 @@
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packet.dispatch(new ServerboundInteractPacket.Handler() {
@@ -1954,7 +1942,7 @@
}
}
@@ -1755,19 +2861,20 @@
@@ -1755,19 +2851,20 @@
@Override
public void onInteraction(InteractionHand hand) {
@@ -1978,7 +1966,7 @@
label23:
{
if (entity instanceof AbstractArrow) {
@@ -1785,17 +2892,41 @@
@@ -1785,17 +2882,41 @@
}
ServerGamePacketListenerImpl.this.player.attack(entity);
@@ -2021,7 +2009,7 @@
}
}
@@ -1809,7 +2940,7 @@
@@ -1809,7 +2930,7 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
@@ -2030,7 +2018,7 @@
this.resetPosition();
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
} else {
@@ -1817,11 +2948,11 @@
@@ -1817,11 +2938,11 @@
return;
}
@@ -2045,7 +2033,7 @@
}
}
break;
@@ -1833,16 +2964,27 @@
@@ -1833,16 +2954,27 @@
@Override
public void handleContainerClose(ServerboundContainerClosePacket packet) {
@@ -2075,7 +2063,7 @@
this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) {
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
@@ -1855,7 +2997,303 @@
@@ -1855,7 +2987,303 @@
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@@ -2380,7 +2368,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1879,6 +3317,14 @@
@@ -1879,6 +3307,14 @@
@Override
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
@@ -2395,7 +2383,7 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
this.player.resetLastActionTime();
if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) {
@@ -1900,8 +3346,42 @@
@@ -1900,8 +3336,42 @@
ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location());
return;
}
@@ -2439,7 +2427,7 @@
if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) {
this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
@@ -1917,6 +3397,7 @@
@@ -1917,6 +3387,7 @@
@Override
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -2447,7 +2435,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1945,7 +3426,44 @@
@@ -1945,7 +3416,44 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@@ -2492,7 +2480,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
@@ -1964,7 +3482,19 @@
@@ -1964,7 +3472,19 @@
@Override
public void handleSignUpdate(ServerboundSignUpdatePacket packet) {
@@ -2513,7 +2501,7 @@
this.filterTextPacket(list).thenAcceptAsync((list1) -> {
this.updateSignText(packet, list1);
@@ -1972,6 +3502,7 @@
@@ -1972,6 +3492,7 @@
}
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
@@ -2521,7 +2509,7 @@
this.player.resetLastActionTime();
ServerLevel worldserver = this.player.serverLevel();
BlockPos blockposition = packet.getPos();
@@ -1993,15 +3524,33 @@
@@ -1993,15 +3514,33 @@
@Override
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -2556,7 +2544,7 @@
if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) {
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
}
@@ -2012,7 +3561,7 @@
@@ -2012,7 +3551,7 @@
public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) {
@@ -2565,7 +2553,7 @@
}
}
@@ -2033,7 +3582,7 @@
@@ -2033,7 +3572,7 @@
if (!Objects.equals(profilepublickey_a, profilepublickey_a1)) {
if (profilepublickey_a != null && profilepublickey_a1.expiresAt().isBefore(profilepublickey_a.expiresAt())) {
@@ -2574,7 +2562,7 @@
} else {
try {
SignatureValidator signaturevalidator = this.server.getProfileKeySignatureValidator();
@@ -2045,8 +3594,8 @@
@@ -2045,8 +3584,8 @@
this.resetPlayerChatState(remotechatsession_a.validate(this.player.getGameProfile(), signaturevalidator));
} catch (ProfilePublicKey.ValidationException profilepublickey_b) {
@@ -2585,7 +2573,7 @@
}
}
@@ -2058,7 +3607,7 @@
@@ -2058,7 +3597,7 @@
if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested");
} else {
@@ -2594,7 +2582,7 @@
}
}
@@ -2076,15 +3625,18 @@
@@ -2076,15 +3615,18 @@
private void resetPlayerChatState(RemoteChatSession session) {
this.chatSession = session;
@@ -2616,7 +2604,7 @@
@Override
public void handleClientTickEnd(ServerboundClientTickEndPacket packet) {
@@ -2115,4 +3667,17 @@
@@ -2115,4 +3657,17 @@
InteractionResult run(ServerPlayer player, Entity entity, InteractionHand hand);
}