mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-23 01:17:44 +01:00
Squash these tab complete patches
This commit is contained in:
parent
f2da19f9e0
commit
43876bb104
@ -1,4 +1,4 @@
|
||||
From fe0db51a7d21aa243baeaca88edb3b1e8b7ac981 Mon Sep 17 00:00:00 2001
|
||||
From 2e148b75463f007fbfd5c9d19bb2c0dbf5658aa3 Mon Sep 17 00:00:00 2001
|
||||
From: DemonWav <demonwav@gmail.com>
|
||||
Date: Sat, 30 Jan 2016 18:58:09 -0600
|
||||
Subject: [PATCH] Add Location support to tab completers (vanilla feature
|
||||
@ -6,7 +6,7 @@ Subject: [PATCH] Add Location support to tab completers (vanilla feature
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
|
||||
index 548d570..c126a1e 100644
|
||||
index 548d570..c5b2e34 100644
|
||||
--- a/src/main/java/org/bukkit/command/Command.java
|
||||
+++ b/src/main/java/org/bukkit/command/Command.java
|
||||
@@ -8,6 +8,7 @@ import java.util.Set;
|
||||
@ -17,10 +17,22 @@ index 548d570..c126a1e 100644
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.CommandMinecart;
|
||||
@@ -109,6 +110,30 @@ public abstract class Command {
|
||||
return matchedPlayers;
|
||||
}
|
||||
|
||||
@@ -85,6 +86,42 @@ 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 {
|
||||
+ // 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 548d570..c126a1e 100644
|
||||
+ */
|
||||
+ 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");
|
||||
@@ -108,6 +145,7 @@ 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 3bfa31f..e3f8295 100644
|
||||
--- a/src/main/java/org/bukkit/command/PluginCommand.java
|
||||
@ -169,5 +189,5 @@ index 6d61e3a..2cb971c 100644
|
||||
+ // PaperSpigot end
|
||||
}
|
||||
--
|
||||
1.9.1
|
||||
2.7.0
|
||||
|
||||
|
@ -1,93 +0,0 @@
|
||||
From 3217d06837310e286c73e39f4d73ef7b19716274 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 c126a1e..f0860a9 100644
|
||||
--- a/src/main/java/org/bukkit/command/Command.java
|
||||
+++ b/src/main/java/org/bukkit/command/Command.java
|
||||
@@ -86,28 +86,16 @@ 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
|
||||
@@ -130,7 +118,32 @@ 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
|
||||
|
||||
@@ -447,4 +460,4 @@ public abstract class Command {
|
||||
public String toString() {
|
||||
return getClass().getName() + '(' + name + ')';
|
||||
}
|
||||
-}
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
1.9.1
|
||||
|
@ -1,4 +1,4 @@
|
||||
From 89f0cb0fb82ec84a13ddb088b944ac1d4167bb0f Mon Sep 17 00:00:00 2001
|
||||
From 440a040fc1c9673186be49157299f67dfbb9167a 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
|
||||
@ -19,7 +19,7 @@ index 4a421ba..ff8770b 100644
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index a54b3e8..e130052 100644
|
||||
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;
|
||||
@ -78,7 +78,7 @@ index a54b3e8..e130052 100644
|
||||
- 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,6 +133,21 @@ index de788d6..db46eb0 100644
|
||||
|
||||
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 ecb9519..008b79c 100644
|
||||
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
@@ -396,4 +396,10 @@ 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.9.1
|
||||
2.7.0
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
From bcfd15f836f3331070c285e6f4a8221cf6a69760 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 e130052..642880e 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1639,7 +1639,7 @@ 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 ecb9519..008b79c 100644
|
||||
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
||||
@@ -396,4 +396,10 @@ 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.9.1
|
||||
|
Loading…
Reference in New Issue
Block a user