Remap CraftBukkit to Mojang+Yarn Mappings
By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
@@ -14,13 +14,13 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import net.minecraft.commands.CommandListenerWrapper;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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<CommandSourceStack>, Predicate<CommandSourceStack>, SuggestionProvider<CommandSourceStack> {
|
||||
|
||||
private final CraftServer server;
|
||||
private final Command command;
|
||||
@@ -30,34 +30,34 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public LiteralCommandNode<CommandListenerWrapper> register(CommandDispatcher<CommandListenerWrapper> dispatcher, String label) {
|
||||
public LiteralCommandNode<CommandSourceStack> register(CommandDispatcher<CommandSourceStack> 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))
|
||||
LiteralArgumentBuilder.<CommandSourceStack>literal(label).requires(this).executes(this)
|
||||
.then(RequiredArgumentBuilder.<CommandSourceStack, String>argument("args", StringArgumentType.greedyString()).suggests(this).executes(this))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CommandListenerWrapper wrapper) {
|
||||
return command.testPermissionSilent(wrapper.getBukkitSender());
|
||||
public boolean test(CommandSourceStack wrapper) {
|
||||
return this.command.testPermissionSilent(wrapper.getBukkitSender());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int run(CommandContext<CommandListenerWrapper> context) throws CommandSyntaxException {
|
||||
public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
CommandSender sender = context.getSource().getBukkitSender();
|
||||
|
||||
try {
|
||||
return server.dispatchCommand(sender, context.getInput()) ? 1 : 0;
|
||||
return this.server.dispatchCommand(sender, context.getInput()) ? 1 : 0;
|
||||
} catch (CommandException ex) {
|
||||
sender.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
|
||||
server.getLogger().log(Level.SEVERE, null, ex);
|
||||
this.server.getLogger().log(Level.SEVERE, null, ex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandListenerWrapper> context, SuggestionsBuilder builder) throws CommandSyntaxException {
|
||||
List<String> results = server.tabComplete(context.getSource().getBukkitSender(), builder.getInput(), context.getSource().getLevel(), context.getSource().getPosition(), true);
|
||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) throws CommandSyntaxException {
|
||||
List<String> results = this.server.tabComplete(context.getSource().getBukkitSender(), builder.getInput(), context.getSource().getLevel(), context.getSource().getPosition(), true);
|
||||
|
||||
// Defaults to sub nodes, but we have just one giant args node, so offset accordingly
|
||||
builder = builder.createOffset(builder.getInput().lastIndexOf(' ') + 1);
|
||||
|
||||
@@ -19,47 +19,47 @@ public class ColouredConsoleSender extends CraftConsoleCommandSender {
|
||||
private final ChatColor[] colors = ChatColor.values();
|
||||
private final boolean jansiPassthrough;
|
||||
private static final char ANSI_ESC_CHAR = '\u001B';
|
||||
private static final String RGB_STRING = String.valueOf(ANSI_ESC_CHAR) + "[38;2;%d;%d;%dm";
|
||||
private static final String RGB_STRING = String.valueOf(ColouredConsoleSender.ANSI_ESC_CHAR) + "[38;2;%d;%d;%dm";
|
||||
private static final Pattern RBG_TRANSLATE = Pattern.compile(String.valueOf(ChatColor.COLOR_CHAR) + "x(" + String.valueOf(ChatColor.COLOR_CHAR) + "[A-F0-9]){6}", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
protected ColouredConsoleSender() {
|
||||
super();
|
||||
this.terminal = ((CraftServer) getServer()).getReader().getTerminal();
|
||||
this.terminal = ((CraftServer) this.getServer()).getReader().getTerminal();
|
||||
this.jansiPassthrough = Boolean.getBoolean("jansi.passthrough");
|
||||
|
||||
replacements.put(ChatColor.BLACK, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
|
||||
replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
|
||||
replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
|
||||
replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
|
||||
replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
|
||||
replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
|
||||
replacements.put(ChatColor.GOLD, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
|
||||
replacements.put(ChatColor.GRAY, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
|
||||
replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
|
||||
replacements.put(ChatColor.BLUE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
|
||||
replacements.put(ChatColor.GREEN, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
|
||||
replacements.put(ChatColor.AQUA, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
|
||||
replacements.put(ChatColor.RED, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
|
||||
replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
|
||||
replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
|
||||
replacements.put(ChatColor.WHITE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
|
||||
replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Attribute.BLINK_SLOW).toString());
|
||||
replacements.put(ChatColor.BOLD, Ansi.ansi().a(Attribute.UNDERLINE_DOUBLE).toString());
|
||||
replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Attribute.STRIKETHROUGH_ON).toString());
|
||||
replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Attribute.UNDERLINE).toString());
|
||||
replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Attribute.ITALIC).toString());
|
||||
replacements.put(ChatColor.RESET, Ansi.ansi().a(Attribute.RESET).toString());
|
||||
this.replacements.put(ChatColor.BLACK, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
|
||||
this.replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
|
||||
this.replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
|
||||
this.replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
|
||||
this.replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
|
||||
this.replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
|
||||
this.replacements.put(ChatColor.GOLD, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
|
||||
this.replacements.put(ChatColor.GRAY, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
|
||||
this.replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
|
||||
this.replacements.put(ChatColor.BLUE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
|
||||
this.replacements.put(ChatColor.GREEN, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
|
||||
this.replacements.put(ChatColor.AQUA, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
|
||||
this.replacements.put(ChatColor.RED, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
|
||||
this.replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
|
||||
this.replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
|
||||
this.replacements.put(ChatColor.WHITE, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
|
||||
this.replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Attribute.BLINK_SLOW).toString());
|
||||
this.replacements.put(ChatColor.BOLD, Ansi.ansi().a(Attribute.UNDERLINE_DOUBLE).toString());
|
||||
this.replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Attribute.STRIKETHROUGH_ON).toString());
|
||||
this.replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Attribute.UNDERLINE).toString());
|
||||
this.replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Attribute.ITALIC).toString());
|
||||
this.replacements.put(ChatColor.RESET, Ansi.ansi().a(Attribute.RESET).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
// support jansi passthrough VM option when jansi doesn't detect an ANSI supported terminal
|
||||
if (jansiPassthrough || terminal.isAnsiSupported()) {
|
||||
if (!conversationTracker.isConversingModaly()) {
|
||||
String result = convertRGBColors(message);
|
||||
for (ChatColor color : colors) {
|
||||
if (replacements.containsKey(color)) {
|
||||
result = result.replaceAll("(?i)" + color.toString(), replacements.get(color));
|
||||
if (this.jansiPassthrough || this.terminal.isAnsiSupported()) {
|
||||
if (!this.conversationTracker.isConversingModaly()) {
|
||||
String result = ColouredConsoleSender.convertRGBColors(message);
|
||||
for (ChatColor color : this.colors) {
|
||||
if (this.replacements.containsKey(color)) {
|
||||
result = result.replaceAll("(?i)" + color.toString(), this.replacements.get(color));
|
||||
} else {
|
||||
result = result.replaceAll("(?i)" + color.toString(), "");
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class ColouredConsoleSender extends CraftConsoleCommandSender {
|
||||
}
|
||||
|
||||
private static String convertRGBColors(String input) {
|
||||
Matcher matcher = RBG_TRANSLATE.matcher(input);
|
||||
Matcher matcher = ColouredConsoleSender.RBG_TRANSLATE.matcher(input);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String s = matcher.group().replace("§", "").replace('x', '#');
|
||||
@@ -80,7 +80,7 @@ public class ColouredConsoleSender extends CraftConsoleCommandSender {
|
||||
int red = color.getRed();
|
||||
int blue = color.getBlue();
|
||||
int green = color.getGreen();
|
||||
String replacement = String.format(RGB_STRING, red, green, blue);
|
||||
String replacement = String.format(ColouredConsoleSender.RGB_STRING, red, green, blue);
|
||||
matcher.appendReplacement(buffer, replacement);
|
||||
}
|
||||
matcher.appendTail(buffer);
|
||||
|
||||
@@ -21,10 +21,10 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
||||
@Override
|
||||
protected List<String> evaluate() {
|
||||
List<String> offers = server.getCommandMap().tabComplete(server.getConsoleSender(), buffer);
|
||||
List<String> offers = ConsoleCommandCompleter.this.server.getCommandMap().tabComplete(ConsoleCommandCompleter.this.server.getConsoleSender(), buffer);
|
||||
|
||||
TabCompleteEvent tabEvent = new TabCompleteEvent(server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers);
|
||||
server.getPluginManager().callEvent(tabEvent);
|
||||
TabCompleteEvent tabEvent = new TabCompleteEvent(ConsoleCommandCompleter.this.server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers);
|
||||
ConsoleCommandCompleter.this.server.getPluginManager().callEvent(tabEvent);
|
||||
|
||||
return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.bukkit.craftbukkit.command;
|
||||
|
||||
import net.minecraft.commands.CommandListenerWrapper;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
@@ -28,50 +28,50 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
|
||||
throw new UnsupportedOperationException("Cannot change operator status of a block");
|
||||
}
|
||||
});
|
||||
private final CommandListenerWrapper block;
|
||||
private final TileEntity tile;
|
||||
private final CommandSourceStack block;
|
||||
private final BlockEntity tile;
|
||||
|
||||
public CraftBlockCommandSender(CommandListenerWrapper commandBlockListenerAbstract, TileEntity tile) {
|
||||
super(SHARED_PERM);
|
||||
public CraftBlockCommandSender(CommandSourceStack commandBlockListenerAbstract, BlockEntity tile) {
|
||||
super(CraftBlockCommandSender.SHARED_PERM);
|
||||
this.block = commandBlockListenerAbstract;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock() {
|
||||
return CraftBlock.at(tile.getLevel(), tile.getBlockPos());
|
||||
return CraftBlock.at(this.tile.getLevel(), this.tile.getBlockPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
for (IChatBaseComponent component : CraftChatMessage.fromString(message)) {
|
||||
block.source.sendSystemMessage(component);
|
||||
for (Component component : CraftChatMessage.fromString(message)) {
|
||||
this.block.source.sendSystemMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String... messages) {
|
||||
for (String message : messages) {
|
||||
sendMessage(message);
|
||||
this.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return block.getTextName();
|
||||
return this.block.getTextName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return SHARED_PERM.isOp();
|
||||
return CraftBlockCommandSender.SHARED_PERM.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
SHARED_PERM.setOp(value);
|
||||
CraftBlockCommandSender.SHARED_PERM.setOp(value);
|
||||
}
|
||||
|
||||
public CommandListenerWrapper getWrapper() {
|
||||
return block;
|
||||
public CommandSourceStack getWrapper() {
|
||||
return this.block;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ public class CraftCommandMap extends SimpleCommandMap {
|
||||
}
|
||||
|
||||
public Map<String, Command> getKnownCommands() {
|
||||
return knownCommands;
|
||||
return this.knownCommands;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sendRawMessage(message);
|
||||
this.sendRawMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,7 +37,7 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
@Override
|
||||
public void sendMessage(String... messages) {
|
||||
for (String message : messages) {
|
||||
sendMessage(message);
|
||||
this.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,26 +58,26 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
|
||||
@Override
|
||||
public boolean beginConversation(Conversation conversation) {
|
||||
return conversationTracker.beginConversation(conversation);
|
||||
return this.conversationTracker.beginConversation(conversation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abandonConversation(Conversation conversation) {
|
||||
conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||
this.conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
|
||||
conversationTracker.abandonConversation(conversation, details);
|
||||
this.conversationTracker.abandonConversation(conversation, details);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptConversationInput(String input) {
|
||||
conversationTracker.acceptConversationInput(input);
|
||||
this.conversationTracker.acceptConversationInput(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConversing() {
|
||||
return conversationTracker.isConversing();
|
||||
return this.conversationTracker.isConversing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
package org.bukkit.craftbukkit.command;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.server.rcon.RemoteControlCommandListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.rcon.RconConsoleSource;
|
||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
||||
|
||||
public class CraftRemoteConsoleCommandSender extends ServerCommandSender implements RemoteConsoleCommandSender {
|
||||
|
||||
private final RemoteControlCommandListener listener;
|
||||
private final RconConsoleSource listener;
|
||||
|
||||
public CraftRemoteConsoleCommandSender(RemoteControlCommandListener listener) {
|
||||
public CraftRemoteConsoleCommandSender(RconConsoleSource listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public RemoteControlCommandListener getListener() {
|
||||
return listener;
|
||||
public RconConsoleSource getListener() {
|
||||
return this.listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getAddress() {
|
||||
return listener.socketAddress;
|
||||
return this.listener.socketAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
listener.sendSystemMessage(IChatBaseComponent.literal(message + "\n")); // Send a newline after each message, to preserve formatting.
|
||||
this.listener.sendSystemMessage(Component.literal(message + "\n")); // Send a newline after each message, to preserve formatting.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String... messages) {
|
||||
for (String message : messages) {
|
||||
sendMessage(message);
|
||||
this.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.command;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.commands.CommandListenerWrapper;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ProxiedCommandSender;
|
||||
@@ -13,123 +13,123 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ProxiedNativeCommandSender implements ProxiedCommandSender {
|
||||
|
||||
private final CommandListenerWrapper orig;
|
||||
private final CommandSourceStack orig;
|
||||
private final CommandSender caller;
|
||||
private final CommandSender callee;
|
||||
|
||||
public ProxiedNativeCommandSender(CommandListenerWrapper orig, CommandSender caller, CommandSender callee) {
|
||||
public ProxiedNativeCommandSender(CommandSourceStack orig, CommandSender caller, CommandSender callee) {
|
||||
this.orig = orig;
|
||||
this.caller = caller;
|
||||
this.callee = callee;
|
||||
}
|
||||
|
||||
public CommandListenerWrapper getHandle() {
|
||||
return orig;
|
||||
public CommandSourceStack getHandle() {
|
||||
return this.orig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSender getCaller() {
|
||||
return caller;
|
||||
return this.caller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSender getCallee() {
|
||||
return callee;
|
||||
return this.callee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
getCaller().sendMessage(message);
|
||||
this.getCaller().sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String... messages) {
|
||||
getCaller().sendMessage(messages);
|
||||
this.getCaller().sendMessage(messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(UUID sender, String message) {
|
||||
getCaller().sendMessage(sender, message);
|
||||
this.getCaller().sendMessage(sender, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(UUID sender, String... messages) {
|
||||
getCaller().sendMessage(sender, messages);
|
||||
this.getCaller().sendMessage(sender, messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return getCallee().getServer();
|
||||
return this.getCallee().getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getCallee().getName();
|
||||
return this.getCallee().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return getCaller().isPermissionSet(name);
|
||||
return this.getCaller().isPermissionSet(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(Permission perm) {
|
||||
return getCaller().isPermissionSet(perm);
|
||||
return this.getCaller().isPermissionSet(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
return getCaller().hasPermission(name);
|
||||
return this.getCaller().hasPermission(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Permission perm) {
|
||||
return getCaller().hasPermission(perm);
|
||||
return this.getCaller().hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return getCaller().addAttachment(plugin, name, value);
|
||||
return this.getCaller().addAttachment(plugin, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return getCaller().addAttachment(plugin);
|
||||
return this.getCaller().addAttachment(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
return getCaller().addAttachment(plugin, name, value, ticks);
|
||||
return this.getCaller().addAttachment(plugin, name, value, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
return getCaller().addAttachment(plugin, ticks);
|
||||
return this.getCaller().addAttachment(plugin, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
getCaller().removeAttachment(attachment);
|
||||
this.getCaller().removeAttachment(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
getCaller().recalculatePermissions();
|
||||
this.getCaller().recalculatePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return getCaller().getEffectivePermissions();
|
||||
return this.getCaller().getEffectivePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return getCaller().isOp();
|
||||
return this.getCaller().isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
getCaller().setOp(value);
|
||||
this.getCaller().setOp(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class ServerCommandSender implements CommandSender {
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return perm.isPermissionSet(name);
|
||||
return this.perm.isPermissionSet(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,7 +34,7 @@ public abstract class ServerCommandSender implements CommandSender {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
return perm.hasPermission(name);
|
||||
return this.perm.hasPermission(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,37 +44,37 @@ public abstract class ServerCommandSender implements CommandSender {
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return perm.addAttachment(plugin, name, value);
|
||||
return this.perm.addAttachment(plugin, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return perm.addAttachment(plugin);
|
||||
return this.perm.addAttachment(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
return perm.addAttachment(plugin, name, value, ticks);
|
||||
return this.perm.addAttachment(plugin, name, value, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
return perm.addAttachment(plugin, ticks);
|
||||
return this.perm.addAttachment(plugin, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
perm.removeAttachment(attachment);
|
||||
this.perm.removeAttachment(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
perm.recalculatePermissions();
|
||||
this.perm.recalculatePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return perm.getEffectivePermissions();
|
||||
return this.perm.getEffectivePermissions();
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
|
||||
@@ -7,10 +7,10 @@ import com.mojang.brigadier.tree.CommandNode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.minecraft.commands.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandListenerWrapper;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.vehicle.EntityMinecartCommandBlock;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.vehicle.MinecartCommandBlock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -26,22 +26,22 @@ import org.bukkit.entity.minecart.CommandMinecart;
|
||||
|
||||
public final class VanillaCommandWrapper extends BukkitCommand {
|
||||
|
||||
private final CommandDispatcher dispatcher;
|
||||
public final CommandNode<CommandListenerWrapper> vanillaCommand;
|
||||
private final Commands dispatcher;
|
||||
public final CommandNode<CommandSourceStack> vanillaCommand;
|
||||
|
||||
public VanillaCommandWrapper(CommandDispatcher dispatcher, CommandNode<CommandListenerWrapper> vanillaCommand) {
|
||||
public VanillaCommandWrapper(Commands dispatcher, CommandNode<CommandSourceStack> vanillaCommand) {
|
||||
super(vanillaCommand.getName(), "A Mojang provided command.", vanillaCommand.getUsageText(), Collections.EMPTY_LIST);
|
||||
this.dispatcher = dispatcher;
|
||||
this.vanillaCommand = vanillaCommand;
|
||||
this.setPermission(getPermission(vanillaCommand));
|
||||
this.setPermission(VanillaCommandWrapper.getPermission(vanillaCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
if (!this.testPermission(sender)) return true;
|
||||
|
||||
CommandListenerWrapper icommandlistener = getListener(sender);
|
||||
dispatcher.performPrefixedCommand(icommandlistener, toDispatcher(args, getName()), toDispatcher(args, commandLabel));
|
||||
CommandSourceStack icommandlistener = VanillaCommandWrapper.getListener(sender);
|
||||
this.dispatcher.performPrefixedCommand(icommandlistener, this.toDispatcher(args, this.getName()), this.toDispatcher(args, commandLabel));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,28 +51,28 @@ public final class VanillaCommandWrapper extends BukkitCommand {
|
||||
Preconditions.checkArgument(args != null, "Arguments cannot be null");
|
||||
Preconditions.checkArgument(alias != null, "Alias cannot be null");
|
||||
|
||||
CommandListenerWrapper icommandlistener = getListener(sender);
|
||||
ParseResults<CommandListenerWrapper> parsed = dispatcher.getDispatcher().parse(toDispatcher(args, getName()), icommandlistener);
|
||||
CommandSourceStack icommandlistener = VanillaCommandWrapper.getListener(sender);
|
||||
ParseResults<CommandSourceStack> parsed = this.dispatcher.getDispatcher().parse(this.toDispatcher(args, this.getName()), icommandlistener);
|
||||
|
||||
List<String> results = new ArrayList<>();
|
||||
dispatcher.getDispatcher().getCompletionSuggestions(parsed).thenAccept((suggestions) -> {
|
||||
this.dispatcher.getDispatcher().getCompletionSuggestions(parsed).thenAccept((suggestions) -> {
|
||||
suggestions.getList().forEach((s) -> results.add(s.getText()));
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public static CommandListenerWrapper getListener(CommandSender sender) {
|
||||
public static CommandSourceStack getListener(CommandSender sender) {
|
||||
if (sender instanceof CraftEntity entity) {
|
||||
if (sender instanceof CommandMinecart) {
|
||||
return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock().createCommandSourceStack();
|
||||
return ((MinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock().createCommandSourceStack();
|
||||
}
|
||||
|
||||
if (sender instanceof CraftPlayer player) {
|
||||
return player.getHandle().createCommandSourceStack();
|
||||
}
|
||||
|
||||
return entity.getHandle().createCommandSourceStackForNameResolution((WorldServer) entity.getHandle().level());
|
||||
return entity.getHandle().createCommandSourceStackForNameResolution((ServerLevel) entity.getHandle().level());
|
||||
}
|
||||
if (sender instanceof BlockCommandSender) {
|
||||
return ((CraftBlockCommandSender) sender).getWrapper();
|
||||
@@ -90,7 +90,7 @@ public final class VanillaCommandWrapper extends BukkitCommand {
|
||||
throw new IllegalArgumentException("Cannot make " + sender + " a vanilla command listener");
|
||||
}
|
||||
|
||||
public static String getPermission(CommandNode<CommandListenerWrapper> vanillaCommand) {
|
||||
public static String getPermission(CommandNode<CommandSourceStack> vanillaCommand) {
|
||||
return "minecraft.command." + ((vanillaCommand.getRedirect() == null) ? vanillaCommand.getName() : vanillaCommand.getRedirect().getName());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user