1.21.5
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: MiniDigger | Martin <admin@minidigger.dev> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com> Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
This commit is contained in:
@@ -32,7 +32,6 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
|
||||
}
|
||||
|
||||
public LiteralCommandNode<CommandSourceStack> register(CommandDispatcher<CommandSourceStack> dispatcher, String label) {
|
||||
// Paper start - Expose Brigadier to Paper-MojangAPI
|
||||
com.mojang.brigadier.tree.RootCommandNode<CommandSourceStack> root = dispatcher.getRoot();
|
||||
LiteralCommandNode<CommandSourceStack> literal = LiteralArgumentBuilder.<CommandSourceStack>literal(label).requires(this).executes(this).build();
|
||||
LiteralCommandNode<CommandSourceStack> defaultNode = literal;
|
||||
@@ -49,7 +48,6 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
|
||||
}
|
||||
root.addChild(literal);
|
||||
return literal;
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package org.bukkit.craftbukkit.command;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
//import jline.Terminal;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
public class ColouredConsoleSender /*extends CraftConsoleCommandSender */{/* // Paper - disable
|
||||
private final Terminal terminal;
|
||||
private final Map<ChatColor, String> replacements = new EnumMap<ChatColor, String>(ChatColor.class);
|
||||
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(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) this.getServer()).getReader().getTerminal();
|
||||
this.jansiPassthrough = Boolean.getBoolean("jansi.passthrough");
|
||||
|
||||
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 (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(), "");
|
||||
}
|
||||
}
|
||||
System.out.println(result + Ansi.ansi().reset().toString());
|
||||
}
|
||||
} else {
|
||||
super.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static String convertRGBColors(String input) {
|
||||
Matcher matcher = ColouredConsoleSender.RBG_TRANSLATE.matcher(input);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String s = matcher.group().replace("§", "").replace('x', '#');
|
||||
Color color = Color.decode(s);
|
||||
int red = color.getRed();
|
||||
int blue = color.getBlue();
|
||||
int green = color.getGreen();
|
||||
String replacement = String.format(ColouredConsoleSender.RGB_STRING, red, green, blue);
|
||||
matcher.appendReplacement(buffer, replacement);
|
||||
}
|
||||
matcher.appendTail(buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static ConsoleCommandSender getInstance() {
|
||||
if (Bukkit.getConsoleSender() != null) {
|
||||
return Bukkit.getConsoleSender();
|
||||
} else {
|
||||
return new ColouredConsoleSender();
|
||||
}
|
||||
}*/ // Paper
|
||||
}
|
||||
@@ -8,12 +8,10 @@ import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
|
||||
// Paper start - JLine update
|
||||
import org.jline.reader.Candidate;
|
||||
import org.jline.reader.Completer;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jline.reader.ParsedLine;
|
||||
// Paper end
|
||||
import org.bukkit.event.server.TabCompleteEvent;
|
||||
|
||||
public class ConsoleCommandCompleter implements Completer {
|
||||
@@ -40,7 +38,7 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
// Still fire sync event with the provided completions, if someone is listening
|
||||
if (!event.isCancelled() && TabCompleteEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
List<com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion> finalCompletions = new java.util.ArrayList<>(completions);
|
||||
Waitable<List<String>> syncCompletions = new Waitable<List<String>>() {
|
||||
Waitable<List<String>> syncCompletions = new Waitable<>() {
|
||||
@Override
|
||||
protected List<String> evaluate() {
|
||||
org.bukkit.event.server.TabCompleteEvent syncEvent = new org.bukkit.event.server.TabCompleteEvent(server.getConsoleSender(), buffer,
|
||||
@@ -66,36 +64,20 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
}
|
||||
}
|
||||
|
||||
if (false && !completions.isEmpty()) {
|
||||
for (final com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion completion : completions) {
|
||||
if (completion.suggestion().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
candidates.add(new Candidate(
|
||||
completion.suggestion(),
|
||||
completion.suggestion(),
|
||||
null,
|
||||
io.papermc.paper.adventure.PaperAdventure.PLAIN.serializeOr(completion.tooltip(), null),
|
||||
null,
|
||||
null,
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
||||
this.addCompletions(reader, line, candidates, completions);
|
||||
return;
|
||||
}
|
||||
|
||||
// Paper end
|
||||
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
||||
Waitable<List<String>> waitable = new Waitable<>() {
|
||||
@Override
|
||||
protected List<String> evaluate() {
|
||||
List<String> offers = server.getCommandMap().tabComplete(server.getConsoleSender(), buffer); // Paper - Remove "this."
|
||||
|
||||
TabCompleteEvent tabEvent = new TabCompleteEvent(server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers); // Paper - Remove "this."
|
||||
TabCompleteEvent tabEvent = new TabCompleteEvent(server.getConsoleSender(), buffer, (offers == null) ? Collections.emptyList() : offers); // Paper - Remove "this."
|
||||
server.getPluginManager().callEvent(tabEvent); // Paper - Remove "this."
|
||||
|
||||
return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
|
||||
return tabEvent.isCancelled() ? Collections.emptyList() : tabEvent.getCompletions();
|
||||
}
|
||||
};
|
||||
server.getServer().processQueue.add(waitable); // Paper - Remove "this."
|
||||
@@ -106,29 +88,7 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
return; // Paper - Method returns void
|
||||
}
|
||||
|
||||
// Paper start - JLine update
|
||||
/*
|
||||
for (String completion : offers) {
|
||||
if (completion.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
candidates.add(new Candidate(completion));
|
||||
}
|
||||
*/
|
||||
this.addCompletions(reader, line, candidates, offers.stream().map(com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion::completion).collect(java.util.stream.Collectors.toList()));
|
||||
// Paper end
|
||||
|
||||
// Paper start - JLine handles cursor now
|
||||
/*
|
||||
final int lastSpace = buffer.lastIndexOf(' ');
|
||||
if (lastSpace == -1) {
|
||||
return cursor - buffer.length();
|
||||
} else {
|
||||
return cursor - (buffer.length() - lastSpace - 1);
|
||||
}
|
||||
*/
|
||||
// Paper end
|
||||
} catch (ExecutionException e) {
|
||||
server.getLogger().log(Level.WARNING, "Unhandled exception when tab completing", e); // Paper - Remove "this."
|
||||
} catch (InterruptedException e) {
|
||||
@@ -136,7 +96,6 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
}
|
||||
}
|
||||
|
||||
// Paper start
|
||||
private boolean notNewSuggestion(final List<com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion> completions, final String completion) {
|
||||
for (final com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion it : completions) {
|
||||
if (it.suggestion().equals(completion)) {
|
||||
@@ -149,5 +108,4 @@ public class ConsoleCommandCompleter implements Completer {
|
||||
private void addCompletions(final LineReader reader, final ParsedLine line, final List<Candidate> candidates, final List<com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion> existing) {
|
||||
this.brigadierCompleter.complete(reader, line, candidates, existing);
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
|
||||
}
|
||||
});
|
||||
private final CommandSourceStack block;
|
||||
private final BlockEntity tile;
|
||||
private final BlockEntity blockEntity;
|
||||
|
||||
public CraftBlockCommandSender(CommandSourceStack commandBlockListenerAbstract, BlockEntity tile) {
|
||||
public CraftBlockCommandSender(CommandSourceStack commandBlockListenerAbstract, BlockEntity blockEntity) {
|
||||
super(CraftBlockCommandSender.SHARED_PERM);
|
||||
this.block = commandBlockListenerAbstract;
|
||||
this.tile = tile;
|
||||
this.blockEntity = blockEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock() {
|
||||
return CraftBlock.at(this.tile.getLevel(), this.tile.getBlockPos());
|
||||
return CraftBlock.at(this.blockEntity.getLevel(), this.blockEntity.getBlockPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,17 +61,15 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
|
||||
return this.block.getTextName();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void sendMessage(net.kyori.adventure.identity.Identity identity, net.kyori.adventure.text.Component message, net.kyori.adventure.audience.MessageType type) {
|
||||
block.source.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message));
|
||||
this.block.source.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.block.getDisplayName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
|
||||
@@ -46,12 +46,10 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return net.kyori.adventure.text.Component.text(this.getName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
@@ -88,7 +86,6 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
return this.conversationTracker.isConversing();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
|
||||
this.sendRawMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(message));
|
||||
@@ -103,5 +100,4 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
public boolean hasPermission(org.bukkit.permissions.Permission perm) {
|
||||
return io.papermc.paper.configuration.GlobalConfiguration.get().console.hasAllPermissions || super.hasPermission(perm);
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -39,12 +39,10 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
|
||||
return "Rcon";
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return net.kyori.adventure.text.Component.text(this.getName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
@@ -56,7 +54,6 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
|
||||
throw new UnsupportedOperationException("Cannot change operator status of remote controller.");
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
return io.papermc.paper.configuration.GlobalConfiguration.get().console.hasAllPermissions || super.hasPermission(name);
|
||||
@@ -66,5 +63,4 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
|
||||
public boolean hasPermission(org.bukkit.permissions.Permission perm) {
|
||||
return io.papermc.paper.configuration.GlobalConfiguration.get().console.hasAllPermissions || super.hasPermission(perm);
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -67,12 +67,10 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender {
|
||||
return this.getCallee().getName();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return this.getCallee().name();
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
@@ -139,11 +137,8 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender {
|
||||
this.getCaller().setOp(value);
|
||||
}
|
||||
|
||||
// Spigot start
|
||||
@Override
|
||||
public org.bukkit.command.CommandSender.Spigot spigot()
|
||||
{
|
||||
return this.getCaller().spigot();
|
||||
public org.bukkit.command.CommandSender.Spigot spigot() {
|
||||
return this.getCaller().spigot();
|
||||
}
|
||||
// Spigot end
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class ServerCommandSender implements CommandSender {
|
||||
public final PermissibleBase perm; // Paper
|
||||
private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
|
||||
public final PermissibleBase perm;
|
||||
private net.kyori.adventure.pointer.Pointers adventure$pointers;
|
||||
|
||||
protected ServerCommandSender() {
|
||||
this.perm = new PermissibleBase(this);
|
||||
@@ -97,42 +97,33 @@ public abstract class ServerCommandSender implements CommandSender {
|
||||
this.sendMessage(messages); // ServerCommandSenders have no use for senders
|
||||
}
|
||||
|
||||
// Spigot start
|
||||
private final org.bukkit.command.CommandSender.Spigot spigot = new org.bukkit.command.CommandSender.Spigot()
|
||||
{
|
||||
private final org.bukkit.command.CommandSender.Spigot spigot = new org.bukkit.command.CommandSender.Spigot() {
|
||||
@Override
|
||||
public void sendMessage(net.md_5.bungee.api.chat.BaseComponent component)
|
||||
{
|
||||
public void sendMessage(net.md_5.bungee.api.chat.BaseComponent component) {
|
||||
ServerCommandSender.this.sendMessage(net.md_5.bungee.api.chat.TextComponent.toLegacyText(component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.md_5.bungee.api.chat.BaseComponent... components)
|
||||
{
|
||||
public void sendMessage(net.md_5.bungee.api.chat.BaseComponent... components) {
|
||||
ServerCommandSender.this.sendMessage(net.md_5.bungee.api.chat.TextComponent.toLegacyText(components));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(UUID sender, net.md_5.bungee.api.chat.BaseComponent... components)
|
||||
{
|
||||
public void sendMessage(UUID sender, net.md_5.bungee.api.chat.BaseComponent... components) {
|
||||
this.sendMessage(components);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(UUID sender, net.md_5.bungee.api.chat.BaseComponent component)
|
||||
{
|
||||
public void sendMessage(UUID sender, net.md_5.bungee.api.chat.BaseComponent component) {
|
||||
this.sendMessage(component);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public org.bukkit.command.CommandSender.Spigot spigot()
|
||||
{
|
||||
public org.bukkit.command.CommandSender.Spigot spigot() {
|
||||
return this.spigot;
|
||||
}
|
||||
// Spigot end
|
||||
|
||||
// Paper start - implement pointers
|
||||
@Override
|
||||
public net.kyori.adventure.pointer.Pointers pointers() {
|
||||
if (this.adventure$pointers == null) {
|
||||
@@ -144,5 +135,4 @@ public abstract class ServerCommandSender implements CommandSender {
|
||||
|
||||
return this.adventure$pointers;
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.List;
|
||||
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,13 +25,10 @@ import org.bukkit.entity.minecart.CommandMinecart;
|
||||
|
||||
public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
|
||||
//private final Commands dispatcher; // Paper
|
||||
public final CommandNode<CommandSourceStack> vanillaCommand;
|
||||
|
||||
// Paper start
|
||||
public VanillaCommandWrapper(String name, String description, String usageMessage, List<String> aliases, CommandNode<CommandSourceStack> vanillaCommand) {
|
||||
super(name, description, usageMessage, aliases);
|
||||
//this.dispatcher = dispatcher; // Paper
|
||||
this.vanillaCommand = vanillaCommand;
|
||||
}
|
||||
|
||||
@@ -40,10 +36,8 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
return net.minecraft.server.MinecraftServer.getServer().getCommands();
|
||||
}
|
||||
|
||||
// Paper end
|
||||
public VanillaCommandWrapper(Commands dispatcher, CommandNode<CommandSourceStack> vanillaCommand) {
|
||||
super(vanillaCommand.getName(), "A Mojang provided command.", vanillaCommand.getUsageText(), Collections.EMPTY_LIST);
|
||||
// this.dispatcher = dispatcher; // Paper
|
||||
public VanillaCommandWrapper(CommandNode<CommandSourceStack> vanillaCommand) {
|
||||
super(vanillaCommand.getName(), "A Mojang provided command.", vanillaCommand.getUsageText(), Collections.emptyList());
|
||||
this.vanillaCommand = vanillaCommand;
|
||||
this.setPermission(VanillaCommandWrapper.getPermission(vanillaCommand));
|
||||
}
|
||||
@@ -52,8 +46,8 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!this.testPermission(sender)) return true;
|
||||
|
||||
CommandSourceStack icommandlistener = VanillaCommandWrapper.getListener(sender);
|
||||
this.commands().performPrefixedCommand(icommandlistener, this.toDispatcher(args, this.getName()), this.toDispatcher(args, commandLabel)); // Paper
|
||||
CommandSourceStack source = VanillaCommandWrapper.getListener(sender);
|
||||
this.commands().performPrefixedCommand(source, this.toDispatcher(args, this.getName()), this.toDispatcher(args, commandLabel)); // Paper
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -63,8 +57,8 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
Preconditions.checkArgument(args != null, "Arguments cannot be null");
|
||||
Preconditions.checkArgument(alias != null, "Alias cannot be null");
|
||||
|
||||
CommandSourceStack icommandlistener = VanillaCommandWrapper.getListener(sender);
|
||||
ParseResults<CommandSourceStack> parsed = this.commands().getDispatcher().parse(this.toDispatcher(args, this.getName()), icommandlistener); // Paper
|
||||
CommandSourceStack source = VanillaCommandWrapper.getListener(sender);
|
||||
ParseResults<CommandSourceStack> parsed = this.commands().getDispatcher().parse(this.toDispatcher(args, this.getName()), source); // Paper
|
||||
|
||||
List<String> results = new ArrayList<>();
|
||||
this.commands().getDispatcher().getCompletionSuggestions(parsed).thenAccept((suggestions) -> { // Paper
|
||||
@@ -77,7 +71,7 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
public static CommandSourceStack getListener(CommandSender sender) {
|
||||
if (sender instanceof CraftEntity entity) {
|
||||
if (sender instanceof CommandMinecart) {
|
||||
return ((MinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock().createCommandSourceStack();
|
||||
return ((CraftMinecartCommand) sender).getHandle().getCommandBlock().createCommandSourceStack();
|
||||
}
|
||||
|
||||
if (sender instanceof CraftPlayer player) {
|
||||
@@ -98,11 +92,9 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
if (sender instanceof ProxiedCommandSender) {
|
||||
return ((ProxiedNativeCommandSender) sender).getHandle();
|
||||
}
|
||||
// Paper start
|
||||
if (sender instanceof io.papermc.paper.commands.FeedbackForwardingSender feedback) {
|
||||
return feedback.asVanilla();
|
||||
}
|
||||
// Paper end
|
||||
|
||||
throw new IllegalArgumentException("Cannot make " + sender + " a vanilla command listener");
|
||||
}
|
||||
@@ -128,7 +120,7 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
private String toDispatcher(String[] args, String name) {
|
||||
return name + ((args.length > 0) ? " " + Joiner.on(' ').join(args) : "");
|
||||
}
|
||||
// Paper start
|
||||
|
||||
@Override
|
||||
public boolean canBeOverriden() {
|
||||
return true;
|
||||
@@ -138,5 +130,4 @@ public class VanillaCommandWrapper extends BukkitCommand { // Paper
|
||||
public boolean isRegistered() {
|
||||
return true;
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user