Fix commands from signs not firing command events

This patch changes sign command logic so that `run_command` click events:
  - are logged to the console
  - fire PlayerCommandPreprocessEvent
  - work with double-slash commands like `//wand`
  - sends failure messages to the player who clicked the sign
This commit is contained in:
Jake Potrebic
2021-07-09 13:50:48 -07:00
parent 9ce3172c9f
commit 39716421ea
3 changed files with 75 additions and 8 deletions

View File

@@ -0,0 +1,42 @@
package io.papermc.paper.commands;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import org.bukkit.command.CommandSender;
import java.util.UUID;
public class DelegatingCommandSource implements CommandSource {
private final CommandSource delegate;
public DelegatingCommandSource(CommandSource delegate) {
this.delegate = delegate;
}
@Override
public void sendSystemMessage(Component message) {
delegate.sendSystemMessage(message);
}
@Override
public boolean acceptsSuccess() {
return delegate.acceptsSuccess();
}
@Override
public boolean acceptsFailure() {
return delegate.acceptsFailure();
}
@Override
public boolean shouldInformAdmins() {
return delegate.shouldInformAdmins();
}
@Override
public CommandSender getBukkitSender(CommandSourceStack wrapper) {
return delegate.getBukkitSender(wrapper);
}
}

View File

@@ -61,7 +61,7 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
CommandSender sender = context.getSource().getBukkitSender();
try {
return this.server.dispatchCommand(sender, context.getInput()) ? 1 : 0;
return this.server.dispatchCommand(sender, context.getRange().get(context.getInput())) ? 1 : 0; // Paper - Fix commands from signs not firing command events; actually use the StringRange from context
} catch (CommandException ex) {
sender.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
this.server.getLogger().log(Level.SEVERE, null, ex);