fix subcommand completing issues

This commit is contained in:
2021-09-01 17:49:23 +02:00
parent 1bb2c7ea6a
commit ad599092de
8 changed files with 20 additions and 20 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.0</version> <version>2.1</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -48,9 +48,9 @@ public class CommandWhitelistBukkit extends JavaPlugin {
// Use paper's async tab completions if possible // Use paper's async tab completions if possible
Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent"); Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent");
getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this); getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException ignored) {
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
} }
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
PluginCommand command = getCommand("commandwhitelist"); PluginCommand command = getCommand("commandwhitelist");
if (command != null) { if (command != null) {
@@ -9,21 +9,17 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public class AsyncTabCompleteBlockerListener implements Listener { public class AsyncTabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.HIGHEST)
public void onCommandTabComplete(AsyncTabCompleteEvent event) { public void onCommandTabComplete(AsyncTabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return; if (!(event.getSender() instanceof Player)) return;
Player player = (Player) event.getSender(); Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
event.setCompletions( String buffer = event.getBuffer();
CommandUtil.filterSuggestions( if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true);
event.getBuffer(), event.setCompletions(CommandUtil.filterSuggestions(buffer, event.getCompletions(), CommandWhitelistBukkit.getSuggestions(player)));
event.getCompletions(),
CommandWhitelistBukkit.getSuggestions(player)
)
);
event.setHandled(true);
} }
} }
@@ -7,18 +7,22 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.server.TabCompleteEvent;
public class TabCompleteBlockerListener implements Listener { public class TabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) { public void onCommandTabComplete(TabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return; if (!(event.getSender() instanceof Player)) return;
Player player = (Player) event.getSender(); Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer();
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true);
event.setCompletions( event.setCompletions(
CommandUtil.filterSuggestions( CommandUtil.filterSuggestions(
event.getBuffer(), buffer,
event.getCompletions(), event.getCompletions(),
CommandWhitelistBukkit.getSuggestions(player) CommandWhitelistBukkit.getSuggestions(player)
) )
); );
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.0</version> <version>2.1</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.0</version> <version>2.1</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.0</version> <version>2.1</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <artifactId>Waterfall</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.0</version> <version>2.1</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>