From 294c944b122c7038ecf235d7e48c0a8fa8d2298a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 3 Feb 2019 13:45:42 +1300 Subject: [PATCH] Don't tab-complete hidden players, fixes #339 --- .../disguise/commands/DisguiseCloneCommand.java | 7 ++++++- .../disguise/commands/DisguiseCommand.java | 12 +++++++++++- .../commands/DisguiseEntityCommand.java | 12 +++++++++++- .../commands/DisguiseModifyCommand.java | 7 ++++++- .../commands/DisguiseModifyEntityCommand.java | 7 ++++++- .../commands/DisguiseModifyPlayerCommand.java | 10 ++++++++++ .../commands/DisguiseModifyRadiusCommand.java | 9 +++++++-- .../commands/DisguisePlayerCommand.java | 17 ++++++++++++++++- .../commands/DisguiseRadiusCommand.java | 16 +++++++++++++--- .../commands/UndisguisePlayerCommand.java | 5 +++++ 10 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java index 4a57346a..50501a94 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java @@ -3,8 +3,8 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -74,6 +74,11 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp if (args.length == 0) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java index ccc13b0b..1e52f782 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -6,9 +6,9 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.parser.*; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -113,6 +113,11 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter if (args.length == 1 && disguiseType.getType() == DisguiseType.PLAYER) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } else { @@ -146,6 +151,11 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index 728d8d6d..3b3618d2 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -5,9 +5,9 @@ import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.parser.*; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -89,6 +89,11 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom if (args.length == 1 && disguiseType.getType() == DisguiseType.PLAYER) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } else { @@ -122,6 +127,11 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java index 22fcc605..32b45adb 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java @@ -4,9 +4,9 @@ import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.parser.*; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -123,6 +123,11 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java index 0e56ef06..6516e356 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java @@ -3,11 +3,11 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; import me.libraryaddict.disguise.utilities.parser.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -82,6 +82,11 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java index abede4a3..54e310b4 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java @@ -103,6 +103,11 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements if (args.length == 0) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } else { @@ -158,6 +163,11 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player p : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(p)) { + continue; + } + tabs.add(p.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java index f913c4d1..6c65b552 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java @@ -4,10 +4,10 @@ import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import me.libraryaddict.disguise.utilities.translations.TranslateType; import me.libraryaddict.disguise.utilities.parser.*; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -261,6 +261,11 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index c14730ea..a7e3f8d0 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -6,9 +6,9 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.parser.*; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -146,6 +146,11 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom if (args.length == 0) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } else if (args.length == 1) { @@ -158,6 +163,11 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom if (args.length == 2 && disguiseType.getType() == DisguiseType.PLAYER) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } else { @@ -191,6 +201,11 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 5c2244b6..95705c09 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -5,12 +5,12 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.utilities.reflection.ClassGetter; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import me.libraryaddict.disguise.utilities.translations.TranslateType; import me.libraryaddict.disguise.utilities.parser.*; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; +import me.libraryaddict.disguise.utilities.reflection.ClassGetter; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -269,6 +269,11 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom if (args.length == 1 + starting && disguiseType.getType() == DisguiseType.PLAYER) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } else { @@ -303,6 +308,11 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom tabs.addAll(info.getEnums(origArgs[origArgs.length - 1])); } else if (info.isParam(String.class)) { for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); } } diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java index bbdcc817..136ecab5 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java @@ -99,6 +99,11 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { return filterTabs(tabs, origArgs); for (Player player : Bukkit.getOnlinePlayers()) { + // If command user cannot see player online, don't tab-complete name + if (sender instanceof Player && !((Player) sender).canSee(player)) { + continue; + } + tabs.add(player.getName()); }