From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: DemonWav Date: Thu, 3 Mar 2016 01:44:39 -0600 Subject: [PATCH] Add Location support to tab completers (vanilla feature missing in CraftBukkit) diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -0,0 +0,0 @@ public class PaperWorldConfig { private void allChunksAreSlimeChunks() { allChunksAreSlimeChunks = getBoolean("all-chunks-are-slime-chunks", false); } + + public boolean allowBlockLocationTabCompletion; + private void allowBlockLocationTabCompletion() { + allowBlockLocationTabCompletion = getBoolean("allow-block-location-tab-completion", true); + } } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -0,0 +0,0 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs return arraylist; } */ - return server.tabComplete(icommandlistener, s); // PAIL : todo args + return server.tabComplete(icommandlistener, s, blockposition); // PAIL : todo args // Paper - add Location arg // CraftBukkit end } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -0,0 +0,0 @@ import javax.imageio.ImageIO; import net.minecraft.server.*; -import org.bukkit.BanList; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.OfflinePlayer; -import org.bukkit.Server; -import org.bukkit.UnsafeValues; +import net.minecraft.server.WorldType; +import org.bukkit.*; import org.bukkit.Warning.WarningState; import org.bukkit.World; import org.bukkit.World.Environment; -import org.bukkit.WorldCreator; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; import org.bukkit.boss.BarStyle; @@ -0,0 +0,0 @@ public final class CraftServer implements Server { } public List tabComplete(net.minecraft.server.ICommandListener sender, String message) { + return tabComplete(sender, message, null); // Paper - location tab-completes. Original code here moved below + } + + // Paper start - add BlockPosition support + /* + this code is copied, except for the noted change, from the original tabComplete(net.minecraft.server.ICommandListener sender, String message) method + */ + public List tabComplete(net.minecraft.server.ICommandListener sender, String message, BlockPosition blockPosition) { if (!(sender instanceof EntityPlayer)) { return ImmutableList.of(); } Player player = ((EntityPlayer) sender).getBukkitEntity(); if (message.startsWith("/")) { - return tabCompleteCommand(player, message); + return tabCompleteCommand(player, message, blockPosition); } else { return tabCompleteChat(player, message); } + // Paper end } public List tabCompleteCommand(Player player, String message) { + return tabCompleteCommand(player, message, null); // Paper - location tab-completes. Original code here moved below + } + + // Paper start - add BlockPosition support + /* + this code is copied, except for the noted change, from the original tabComplete(net.minecraft.server.ICommandListener sender, String message) method + */ + public List tabCompleteCommand(Player player, String message, BlockPosition blockPosition) { // Spigot Start - if ( (org.spigotmc.SpigotConfig.tabComplete < 0 || message.length() <= org.spigotmc.SpigotConfig.tabComplete) && !message.contains( " " ) ) + if ( (org.spigotmc.SpigotConfig.tabComplete < 0 || message.length() <= org.spigotmc.SpigotConfig.tabComplete) && !message.contains( " " ) ) { return ImmutableList.of(); } @@ -0,0 +0,0 @@ public final class CraftServer implements Server { List completions = null; try { - completions = getCommandMap().tabComplete(player, message.substring(1)); + // send location info if presen + // completions = getCommandMap().tabComplete(player, message.substring(1)); + if (blockPosition == null || !((CraftWorld) player.getWorld()).getHandle().paperConfig.allowBlockLocationTabCompletion) { + completions = getCommandMap().tabComplete(player, message.substring(1)); + } else { + completions = getCommandMap().tabComplete(player, message.substring(1), new Location(player.getWorld(), blockPosition.getX(), blockPosition.getY(), blockPosition.getZ())); + } + // Paper end } catch (CommandException ex) { player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command"); getLogger().log(Level.SEVERE, "Exception when " + player.getName() + " attempted to tab complete " + message, ex); diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java +++ b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java @@ -0,0 +0,0 @@ import net.minecraft.server.*; import org.apache.commons.lang.Validate; import org.apache.logging.log4j.Level; +import org.bukkit.Location; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -0,0 +0,0 @@ public final class VanillaCommandWrapper extends VanillaCommand { @Override public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { + return tabComplete(sender, alias, args, null); // Paper - location tab-completes. Original code moved below + } + + // Paper start - location tab-completes + /* + this code is copied, except for the noted change, from the original tabComplete(CommandSender sender, String alias, String[] args) method + */ + @Override + public List tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException { Validate.notNull(sender, "Sender cannot be null"); Validate.notNull(args, "Arguments cannot be null"); Validate.notNull(alias, "Alias cannot be null"); - return (List) vanillaCommand.tabComplete(MinecraftServer.getServer(), getListener(sender), args, new BlockPosition(0, 0, 0)); + if (location == null) { // PaperSpigot use location information if available + return (List) vanillaCommand.tabComplete(MinecraftServer.getServer(), getListener(sender), args, new BlockPosition(0, 0, 0)); + } else { + return (List) vanillaCommand.tabComplete(MinecraftServer.getServer(), getListener(sender), args, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ())); + } } public static CommandSender lastSender = null; // Nasty :( --