Paper/Spigot-Server-Patches/0085-Add-Location-support-to-tab-completers-vanilla-featu.patch

154 lines
7.6 KiB
Diff
Raw Normal View History

2016-02-24 05:35:34 +01:00
From 80b20092e304d27660bf79623f9187c93cf28984 Mon Sep 17 00:00:00 2001
From: DemonWav <demonwav@gmail.com>
Date: Sat, 30 Jan 2016 19:17:19 -0600
Subject: [PATCH] Add Location support to tab completers (vanilla feature
missing in CraftBukkit)
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2016-02-24 05:35:34 +01:00
index ee09922..b400ce0 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2016-02-24 05:35:34 +01:00
@@ -1153,7 +1153,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
return arraylist;
}
*/
- return server.tabComplete(icommandlistener, s);
+ return server.tabComplete(icommandlistener, s, blockposition); // PaperSpigot - add Location argument
// CraftBukkit end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2016-02-01 00:00:30 +01:00
index a54b3e8..642880e 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -29,6 +29,7 @@ import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
+import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.UnsafeValues;
@@ -1597,21 +1598,38 @@ public final class CraftServer implements Server {
}
public List<String> tabComplete(net.minecraft.server.ICommandListener sender, String message) {
+ return tabComplete(sender, message, null); // PaperSpigot - location tab-completes. Original code here moved below
+ }
+
+ // PaperSpigot 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<String> 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);
}
}
+ // PaperSpigot end
public List<String> tabCompleteCommand(Player player, String message) {
+ return tabCompleteCommand(player, message, null); // PaperSpigot - location tab-completes. Original code here moved below
+ }
+
+ // PaperSpigot start - add BlockPosition support
+ /*
+ this code is copied, except for the noted change, from the original tabCompleteCommand(Player player, String message) method
+ */
+ public List<String> 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();
}
@@ -1619,7 +1637,13 @@ public final class CraftServer implements Server {
List<String> completions = null;
try {
- completions = getCommandMap().tabComplete(player, message.substring(1));
+ // send location info if present
+ // completions = getCommandMap().tabComplete(player, message.substring(1));
2016-02-01 00:00:30 +01:00
+ if (blockPosition == null || !((CraftWorld) player.getWorld()).getHandle().paperSpigotConfig.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()));
+ }
} 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);
@@ -1627,6 +1651,7 @@ public final class CraftServer implements Server {
return completions == null ? ImmutableList.<String>of() : completions;
}
+ // PaperSpigot end
public List<String> tabCompleteChat(Player player, String message) {
List<String> completions = new ArrayList<String>();
diff --git a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java
index de788d6..db46eb0 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java
@@ -7,6 +7,7 @@ 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;
@@ -46,11 +47,25 @@ public final class VanillaCommandWrapper extends VanillaCommand {
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
+ return tabComplete(sender, alias, args, null); // PaperSpigot - location tab-completes. Original code moved below
+ }
+
+ // PaperSpigot 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<String> 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<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(0, 0, 0));
+ if (location == null) { // PaperSpigot use location information if available
+ return (List<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(0, 0, 0));
+ } else {
+ return (List<String>) vanillaCommand.tabComplete(getListener(sender), args, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
+ }
}
+ // PaperSpigot end
public static CommandSender lastSender = null; // Nasty :(
2016-02-01 00:00:30 +01:00
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
2016-02-05 11:12:16 +01:00
index 00057a1..c3c374d 100644
2016-02-01 00:00:30 +01:00
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
2016-02-05 11:12:16 +01:00
@@ -390,4 +390,10 @@ public class PaperSpigotWorldConfig
2016-02-01 00:00:30 +01:00
{
allChunksAreSlimeChunks = getBoolean( "all-chunks-are-slime-chunks", false );
}
+
+ public boolean allowBlockLocationTabCompletion;
+ private void allowBlockLocationTabCompletion()
+ {
+ allowBlockLocationTabCompletion = getBoolean( "allow-block-location-tab-completion", true );
+ }
}
--
2016-02-24 05:35:34 +01:00
2.7.1