mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 23:07:40 +01:00
Squash these tab complete patches
This commit is contained in:
parent
4a57c8b43d
commit
9d79cc6b99
@ -18,9 +18,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.CommandMinecart;
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
return matchedPlayers;
|
||||
}
|
||||
|
||||
* @throws IllegalArgumentException if sender, alias, or args is null
|
||||
*/
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
+ // PaperSpigot - location tab-completes
|
||||
+ /*
|
||||
+ To prevent infinite recursion, this implementation has been moved down to
|
||||
+ tabCompleteImpl(CommandSender sender, String alias, String[] args). The infinite recursion happens when
|
||||
+ a subclass calls super.tabComplete(CommandSender sender, String alias, String[] args, Location location),
|
||||
+ which would end up calling tabComplete(CommandSender sender, String alias, String[] args), but rather than
|
||||
+ this method, it would call the overridden method, which would call super.tabComplete again, etc. To prevent
|
||||
+ this we move the actual main logic to a separate private method.
|
||||
+ */
|
||||
+ return tabCompleteImpl(sender, alias, args);
|
||||
+ }
|
||||
+
|
||||
+ // PaperSpigot start - location tab-completes
|
||||
+ /**
|
||||
+ * Executed on tab completion for this command, returning a list of options the player can tab through. This method
|
||||
@ -41,13 +53,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ */
|
||||
+ public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
|
||||
+ // Simply default to the standard tab-complete, subclasses can override this if needed
|
||||
+ return tabComplete(sender, alias, args);
|
||||
+ return tabCompleteImpl(sender, alias, args);
|
||||
+ }
|
||||
+ // PaperSpigot end
|
||||
+
|
||||
+ private List<String> tabCompleteImpl(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
Validate.notNull(sender, "Sender cannot be null");
|
||||
Validate.notNull(args, "Arguments cannot be null");
|
||||
Validate.notNull(alias, "Alias cannot be null");
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
|
||||
return matchedPlayers;
|
||||
}
|
||||
+ // PaperSpigot end
|
||||
|
||||
/**
|
||||
* Returns the name of this command
|
||||
*
|
||||
diff --git a/src/main/java/org/bukkit/command/PluginCommand.java b/src/main/java/org/bukkit/command/PluginCommand.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/command/PluginCommand.java
|
||||
|
@ -1,91 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: DemonWav <demonwav@gmail.com>
|
||||
Date: Sun, 31 Jan 2016 01:20:21 -0600
|
||||
Subject: [PATCH] Fix infinite recursion with plugin tab completers
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/command/Command.java
|
||||
+++ b/src/main/java/org/bukkit/command/Command.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
* @throws IllegalArgumentException if sender, alias, or args is null
|
||||
*/
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
- Validate.notNull(sender, "Sender cannot be null");
|
||||
- Validate.notNull(args, "Arguments cannot be null");
|
||||
- Validate.notNull(alias, "Alias cannot be null");
|
||||
-
|
||||
- if (args.length == 0) {
|
||||
- return ImmutableList.of();
|
||||
- }
|
||||
-
|
||||
- String lastWord = args[args.length - 1];
|
||||
-
|
||||
- Player senderPlayer = sender instanceof Player ? (Player) sender : null;
|
||||
-
|
||||
- ArrayList<String> matchedPlayers = new ArrayList<String>();
|
||||
- for (Player player : sender.getServer().getOnlinePlayers()) {
|
||||
- String name = player.getName();
|
||||
- if ((senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
|
||||
- matchedPlayers.add(name);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
|
||||
- return matchedPlayers;
|
||||
+ // PaperSpigot - location tab-completes
|
||||
+ /*
|
||||
+ To prevent infinite recursion, this implementation has been moved down to
|
||||
+ tabCompleteImpl(CommandSender sender, String alias, String[] args). The infinite recursion happens when
|
||||
+ a subclass calls super.tabComplete(CommandSender sender, String alias, String[] args, Location location),
|
||||
+ which would end up calling tabComplete(CommandSender sender, String alias, String[] args), but rather than
|
||||
+ this method, it would call the overridden method, which would call super.tabComplete again, etc. To prevent
|
||||
+ this we move the actual main logic to a separate private method.
|
||||
+ */
|
||||
+ return tabCompleteImpl(sender, alias, args);
|
||||
}
|
||||
|
||||
// PaperSpigot start - location tab-completes
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
*/
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
|
||||
// Simply default to the standard tab-complete, subclasses can override this if needed
|
||||
- return tabComplete(sender, alias, args);
|
||||
+ return tabCompleteImpl(sender, alias, args);
|
||||
+ }
|
||||
+
|
||||
+ private List<String> tabCompleteImpl(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
+ Validate.notNull(sender, "Sender cannot be null");
|
||||
+ Validate.notNull(args, "Arguments cannot be null");
|
||||
+ Validate.notNull(alias, "Alias cannot be null");
|
||||
+
|
||||
+ if (args.length == 0) {
|
||||
+ return ImmutableList.of();
|
||||
+ }
|
||||
+
|
||||
+ String lastWord = args[args.length - 1];
|
||||
+
|
||||
+ Player senderPlayer = sender instanceof Player ? (Player) sender : null;
|
||||
+
|
||||
+ ArrayList<String> matchedPlayers = new ArrayList<String>();
|
||||
+ for (Player player : sender.getServer().getOnlinePlayers()) {
|
||||
+ String name = player.getName();
|
||||
+ if ((senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
|
||||
+ matchedPlayers.add(name);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
|
||||
+ return matchedPlayers;
|
||||
}
|
||||
// PaperSpigot end
|
||||
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
public String toString() {
|
||||
return getClass().getName() + '(' + name + ')';
|
||||
}
|
||||
-}
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
@ -78,7 +78,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
- completions = getCommandMap().tabComplete(player, message.substring(1));
|
||||
+ // send location info if present
|
||||
+ // completions = getCommandMap().tabComplete(player, message.substring(1));
|
||||
+ if (blockPosition == null) {
|
||||
+ 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()));
|
||||
@ -133,4 +133,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
public static CommandSender lastSender = null; // Nasty :(
|
||||
|
||||
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
@@ -0,0 +0,0 @@ public class PaperSpigotWorldConfig
|
||||
{
|
||||
allChunksAreSlimeChunks = getBoolean( "all-chunks-are-slime-chunks", false );
|
||||
}
|
||||
+
|
||||
+ public boolean allowBlockLocationTabCompletion;
|
||||
+ private void allowBlockLocationTabCompletion()
|
||||
+ {
|
||||
+ allowBlockLocationTabCompletion = getBoolean( "allow-block-location-tab-completion", true );
|
||||
+ }
|
||||
}
|
||||
--
|
@ -1,36 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: DemonWav <demonwav@gmail.com>
|
||||
Date: Sun, 31 Jan 2016 01:21:03 -0600
|
||||
Subject: [PATCH] Make block location tab completion be a per-world
|
||||
configurable value
|
||||
|
||||
|
||||
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 @@ public final class CraftServer implements Server {
|
||||
try {
|
||||
// send location info if present
|
||||
// completions = getCommandMap().tabComplete(player, message.substring(1));
|
||||
- if (blockPosition == null) {
|
||||
+ 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()));
|
||||
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
@@ -0,0 +0,0 @@ public class PaperSpigotWorldConfig
|
||||
{
|
||||
allChunksAreSlimeChunks = getBoolean( "all-chunks-are-slime-chunks", false );
|
||||
}
|
||||
+
|
||||
+ public boolean allowBlockLocationTabCompletion;
|
||||
+ private void allowBlockLocationTabCompletion()
|
||||
+ {
|
||||
+ allowBlockLocationTabCompletion = getBoolean( "allow-block-location-tab-completion", true );
|
||||
+ }
|
||||
}
|
||||
--
|
Loading…
Reference in New Issue
Block a user