From 2a6928a498394c91cd36a43892db6b8056824d3c Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 9 Mar 2020 09:00:58 +1300 Subject: [PATCH] Clean up code a bit --- .../libraryaddict/disguise/LibsDisguises.java | 15 +- .../commands/DisguiseBaseCommand.java | 12 +- .../commands/LibsDisguisesCommand.java | 2 +- .../{ => disguise}/DisguiseCommand.java | 259 ++++---- .../{ => disguise}/DisguiseEntityCommand.java | 213 +++---- .../{ => disguise}/DisguisePlayerCommand.java | 377 +++++------ .../{ => disguise}/DisguiseRadiusCommand.java | 592 +++++++++--------- .../{ => modify}/DisguiseModifyCommand.java | 229 +++---- .../DisguiseModifyEntityCommand.java | 165 ++--- .../DisguiseModifyPlayerCommand.java | 337 +++++----- .../DisguiseModifyRadiusCommand.java | 585 ++++++++--------- .../{ => undisguise}/UndisguiseCommand.java | 82 +-- .../UndisguiseEntityCommand.java | 68 +- .../UndisguisePlayerCommand.java | 244 ++++---- .../UndisguiseRadiusCommand.java | 148 ++--- .../{ => utils}/CopyDisguiseCommand.java | 2 +- .../{ => utils}/DisguiseCloneCommand.java | 207 +++--- .../{ => utils}/DisguiseHelpCommand.java | 339 +++++----- .../{ => utils}/DisguiseViewSelfCommand.java | 68 +- .../commands/{ => utils}/GrabSkinCommand.java | 2 +- .../{ => utils}/SaveDisguiseCommand.java | 2 +- .../disguise/disguisetypes/Disguise.java | 15 +- .../disguisetypes/PlayerDisguise.java | 1 - .../watchers/TropicalFishWatcher.java | 1 - .../utilities/DisguiseSoundEnums.java | 3 - .../disguise/utilities/DisguiseUtilities.java | 6 +- .../disguise/utilities/LibsPremium.java | 5 +- .../utilities/metrics/MetricsInitalizer.java | 7 + .../utilities/packets/PacketsHandler.java | 1 - .../PacketListenerClientInteract.java | 4 + .../utilities/params/ParamInfoManager.java | 2 +- .../types/custom/ParamInfoItemStack.java | 1 - .../params/types/custom/ParamInfoTime.java | 2 +- .../utilities/parser/DisguiseParser.java | 1 - .../utilities/plugin/BisectHosting.java | 10 +- .../reflection/ReflectionManager.java | 6 +- .../utilities/reflection/asm/Asm13.java | 1 - .../utilities/reflection/asm/WatcherInfo.java | 2 - .../reflection/asm/WatcherSanitizer.java | 2 - .../translations/TranslateFiller.java | 2 - .../utilities/watchers/CompileMethods.java | 5 +- 41 files changed, 2032 insertions(+), 1993 deletions(-) rename src/main/java/me/libraryaddict/disguise/commands/{ => disguise}/DisguiseCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => disguise}/DisguiseEntityCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => disguise}/DisguisePlayerCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => disguise}/DisguiseRadiusCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => modify}/DisguiseModifyCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => modify}/DisguiseModifyEntityCommand.java (95%) rename src/main/java/me/libraryaddict/disguise/commands/{ => modify}/DisguiseModifyPlayerCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => modify}/DisguiseModifyRadiusCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => undisguise}/UndisguiseCommand.java (89%) rename src/main/java/me/libraryaddict/disguise/commands/{ => undisguise}/UndisguiseEntityCommand.java (94%) rename src/main/java/me/libraryaddict/disguise/commands/{ => undisguise}/UndisguisePlayerCommand.java (95%) rename src/main/java/me/libraryaddict/disguise/commands/{ => undisguise}/UndisguiseRadiusCommand.java (95%) rename src/main/java/me/libraryaddict/disguise/commands/{ => utils}/CopyDisguiseCommand.java (99%) rename src/main/java/me/libraryaddict/disguise/commands/{ => utils}/DisguiseCloneCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => utils}/DisguiseHelpCommand.java (96%) rename src/main/java/me/libraryaddict/disguise/commands/{ => utils}/DisguiseViewSelfCommand.java (92%) rename src/main/java/me/libraryaddict/disguise/commands/{ => utils}/GrabSkinCommand.java (99%) rename src/main/java/me/libraryaddict/disguise/commands/{ => utils}/SaveDisguiseCommand.java (99%) diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 8a930550..f5c2b36e 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -1,6 +1,19 @@ package me.libraryaddict.disguise; -import me.libraryaddict.disguise.commands.*; +import me.libraryaddict.disguise.commands.LibsDisguisesCommand; +import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; +import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand; +import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand; +import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand; +import me.libraryaddict.disguise.commands.undisguise.UndisguiseCommand; +import me.libraryaddict.disguise.commands.undisguise.UndisguiseEntityCommand; +import me.libraryaddict.disguise.commands.undisguise.UndisguisePlayerCommand; +import me.libraryaddict.disguise.commands.undisguise.UndisguiseRadiusCommand; +import me.libraryaddict.disguise.commands.utils.*; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 7cc32e83..8c35594a 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -1,12 +1,20 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; +import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand; +import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand; +import me.libraryaddict.disguise.commands.disguise.DisguiseRadiusCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand; +import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.params.ParamInfo; +import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.params.ParamInfo; -import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandExecutor; diff --git a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index af5a59a1..215f8c05 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -8,9 +8,9 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java index 387a6985..395f8445 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java @@ -1,129 +1,130 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.DisguiseConfig; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter { - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (isNotPremium(sender)) { - return true; - } - - if (!(sender instanceof Entity)) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, getPermissions(sender)); - return true; - } - - Disguise disguise; - - try { - disguise = DisguiseParser.parseDisguise(sender, (Entity) sender, getPermNode(), - DisguiseUtilities.split(StringUtils.join(args, " ")), getPermissions(sender)); - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - - return true; - } - catch (Exception ex) { - ex.printStackTrace(); - return true; - } - - if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !sender.hasPermission("libsdisguises.hidename")) { - if (disguise.getWatcher() instanceof LivingWatcher) { - disguise.getWatcher().setCustomName(getDisplayName(sender)); - - if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { - disguise.getWatcher().setCustomNameVisible(true); - } - } - } - - disguise.setEntity((Player) sender); - - if (!setViewDisguise(args)) { - // They prefer to have the opposite of whatever the view disguises option is - if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && - disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) - disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); - } - - disguise.startDisguise(); - - if (disguise.isDisguiseInUse()) { - sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable())); - } else { - sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getType().toReadable())); - } - - return true; - } - - private boolean setViewDisguise(String[] strings) { - for (String string : strings) { - if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) - continue; - - return true; - } - - return false; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - sender.sendMessage(LibsMsg.DISG_HELP1.get()); - sender.sendMessage(LibsMsg.CAN_USE_DISGS - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - - if (allowedDisguises.contains("player")) { - sender.sendMessage(LibsMsg.DISG_HELP2.get()); - } - - sender.sendMessage(LibsMsg.DISG_HELP3.get()); - - if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(LibsMsg.DISG_HELP4.get()); - } - } -} +package me.libraryaddict.disguise.commands.disguise; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter { + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + + if (!(sender instanceof Entity)) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, getPermissions(sender)); + return true; + } + + Disguise disguise; + + try { + disguise = DisguiseParser.parseDisguise(sender, (Entity) sender, getPermNode(), + DisguiseUtilities.split(StringUtils.join(args, " ")), getPermissions(sender)); + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + + return true; + } + catch (Exception ex) { + ex.printStackTrace(); + return true; + } + + if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !sender.hasPermission("libsdisguises.hidename")) { + if (disguise.getWatcher() instanceof LivingWatcher) { + disguise.getWatcher().setCustomName(getDisplayName(sender)); + + if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { + disguise.getWatcher().setCustomNameVisible(true); + } + } + } + + disguise.setEntity((Player) sender); + + if (!setViewDisguise(args)) { + // They prefer to have the opposite of whatever the view disguises option is + if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && + disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + } + + disguise.startDisguise(); + + if (disguise.isDisguiseInUse()) { + sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable())); + } else { + sender.sendMessage(LibsMsg.FAILED_DISGIUSE.get(disguise.getType().toReadable())); + } + + return true; + } + + private boolean setViewDisguise(String[] strings) { + for (String string : strings) { + if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) + continue; + + return true; + } + + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + sender.sendMessage(LibsMsg.DISG_HELP1.get()); + sender.sendMessage(LibsMsg.CAN_USE_DISGS + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + + if (allowedDisguises.contains("player")) { + sender.sendMessage(LibsMsg.DISG_HELP2.get()); + } + + sender.sendMessage(LibsMsg.DISG_HELP3.get()); + + if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { + sender.sendMessage(LibsMsg.DISG_HELP4.get()); + } + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseEntityCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseEntityCommand.java index 29947b82..19bbedd4 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseEntityCommand.java @@ -1,106 +1,107 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseConfig; -import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter { - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (isNotPremium(sender)) { - return true; - } - - if (!(sender instanceof Player)) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - if (!getPermissions(sender).hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, getPermissions(sender)); - return true; - } - - String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(args, " ")); - Disguise testDisguise; - - try { - testDisguise = DisguiseParser - .parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender)); - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - - return true; - } - catch (IllegalAccessException | InvocationTargetException ex) { - ex.printStackTrace(); - return true; - } - - LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguiseArgs); - - sender.sendMessage(LibsMsg.DISG_ENT_CLICK - .get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable())); - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - - if (!(sender instanceof Player)) { - return tabs; - } - - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.DISG_ENT_HELP1.get()); - sender.sendMessage(LibsMsg.CAN_USE_DISGS - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - - if (allowedDisguises.contains("player")) { - sender.sendMessage(LibsMsg.DISG_ENT_HELP3.get()); - } - - sender.sendMessage(LibsMsg.DISG_ENT_HELP4.get()); - - if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(LibsMsg.DISG_ENT_HELP5.get()); - } - } -} +package me.libraryaddict.disguise.commands.disguise; + +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter { + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + + if (!(sender instanceof Player)) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + if (!getPermissions(sender).hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, getPermissions(sender)); + return true; + } + + String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(args, " ")); + Disguise testDisguise; + + try { + testDisguise = DisguiseParser + .parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender)); + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + + return true; + } + catch (IllegalAccessException | InvocationTargetException ex) { + ex.printStackTrace(); + return true; + } + + LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguiseArgs); + + sender.sendMessage(LibsMsg.DISG_ENT_CLICK + .get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable())); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + + if (!(sender instanceof Player)) { + return tabs; + } + + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + return filterTabs(getTabDisguiseTypes(sender, perms, args, 0, getCurrentArg(origArgs)), origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.DISG_ENT_HELP1.get()); + sender.sendMessage(LibsMsg.CAN_USE_DISGS + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + + if (allowedDisguises.contains("player")) { + sender.sendMessage(LibsMsg.DISG_ENT_HELP3.get()); + } + + sender.sendMessage(LibsMsg.DISG_ENT_HELP4.get()); + + if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { + sender.sendMessage(LibsMsg.DISG_ENT_HELP5.get()); + } + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java index 68649acf..f02e1fef 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java @@ -1,188 +1,189 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -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.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -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.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (isNotPremium(sender)) { - return true; - } - - DisguisePermissions permissions = getPermissions(sender); - - if (!permissions.hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - if (args.length == 1) { - sender.sendMessage(LibsMsg.DPLAYER_SUPPLY.get()); - return true; - } - - Entity entityTarget = Bukkit.getPlayer(args[0]); - - if (entityTarget == null) { - if (args[0].contains("-")) { - try { - entityTarget = Bukkit.getEntity(UUID.fromString(args[0])); - } - catch (Exception ignored) { - } - } - } - - if (entityTarget == null) { - sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); - return true; - } - - String[] newArgs = new String[args.length - 1]; - System.arraycopy(args, 1, newArgs, 0, newArgs.length); - - if (newArgs.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - Disguise disguise; - - try { - disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(), - DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions); - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - return true; - } - - catch (Exception ex) { - ex.printStackTrace(); - return true; - } - - if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) { - sender.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get()); - return true; - } - - if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && - !entityTarget.hasPermission("libsdisguises.hidename")) { - if (disguise.getWatcher() instanceof LivingWatcher) { - disguise.getWatcher().setCustomName(getDisplayName(entityTarget)); - - if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { - disguise.getWatcher().setCustomNameVisible(true); - } - } - } - - disguise.setEntity(entityTarget); - - if (!setViewDisguise(args)) { - // They prefer to have the opposite of whatever the view disguises option is - if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && - disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) - disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); - } - - disguise.startDisguise(); - - if (disguise.isDisguiseInUse()) { - sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() : - DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable())); - } else { - sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL - .get(entityTarget instanceof Player ? entityTarget.getName() : - DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable())); - } - - return true; - } - - private boolean setViewDisguise(String[] strings) { - for (String string : strings) { - if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) - continue; - - return true; - } - - return false; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - 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 { - tabs.addAll(getTabDisguiseTypes(sender, perms, args, 1, getCurrentArg(origArgs))); - } - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.D_HELP1.get()); - sender.sendMessage(LibsMsg.CAN_USE_DISGS - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - - if (allowedDisguises.contains("player")) { - sender.sendMessage(LibsMsg.D_HELP3.get()); - } - - sender.sendMessage(LibsMsg.D_HELP4.get()); - - if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(LibsMsg.D_HELP5.get()); - } - } -} +package me.libraryaddict.disguise.commands.disguise; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +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.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +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.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + + DisguisePermissions permissions = getPermissions(sender); + + if (!permissions.hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + if (args.length == 1) { + sender.sendMessage(LibsMsg.DPLAYER_SUPPLY.get()); + return true; + } + + Entity entityTarget = Bukkit.getPlayer(args[0]); + + if (entityTarget == null) { + if (args[0].contains("-")) { + try { + entityTarget = Bukkit.getEntity(UUID.fromString(args[0])); + } + catch (Exception ignored) { + } + } + } + + if (entityTarget == null) { + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); + return true; + } + + String[] newArgs = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, newArgs.length); + + if (newArgs.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + Disguise disguise; + + try { + disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(), + DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions); + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + return true; + } + + catch (Exception ex) { + ex.printStackTrace(); + return true; + } + + if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) { + sender.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get()); + return true; + } + + if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && + !entityTarget.hasPermission("libsdisguises.hidename")) { + if (disguise.getWatcher() instanceof LivingWatcher) { + disguise.getWatcher().setCustomName(getDisplayName(entityTarget)); + + if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { + disguise.getWatcher().setCustomNameVisible(true); + } + } + } + + disguise.setEntity(entityTarget); + + if (!setViewDisguise(args)) { + // They prefer to have the opposite of whatever the view disguises option is + if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && + disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + } + + disguise.startDisguise(); + + if (disguise.isDisguiseInUse()) { + sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() : + DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable())); + } else { + sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL + .get(entityTarget instanceof Player ? entityTarget.getName() : + DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable())); + } + + return true; + } + + private boolean setViewDisguise(String[] strings) { + for (String string : strings) { + if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) + continue; + + return true; + } + + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + 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 { + tabs.addAll(getTabDisguiseTypes(sender, perms, args, 1, getCurrentArg(origArgs))); + } + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.D_HELP1.get()); + sender.sendMessage(LibsMsg.CAN_USE_DISGS + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + + if (allowedDisguises.contains("player")) { + sender.sendMessage(LibsMsg.D_HELP3.get()); + } + + sender.sendMessage(LibsMsg.D_HELP4.get()); + + if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { + sender.sendMessage(LibsMsg.D_HELP5.get()); + } + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java index 6fa82a16..884d942d 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java @@ -1,296 +1,296 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.DisguiseConfig; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -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.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter { - private int maxRadius = 30; - private ArrayList> validClasses = new ArrayList<>(); - - public DisguiseRadiusCommand(int maxRadius) { - this.maxRadius = maxRadius; - - for (EntityType type : EntityType.values()) { - Class c = type.getEntityClass(); - - while (c != null && Entity.class.isAssignableFrom(c) && !validClasses.contains(c)) { - validClasses.add(c); - - c = c.getSuperclass(); - } - } - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (isNotPremium(sender)) { - return true; - } - - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - DisguisePermissions permissions = getPermissions(sender); - - if (!permissions.hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) || - args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) { - ArrayList classes = new ArrayList<>(); - - for (Class c : validClasses) { - classes.add(TranslateType.DISGUISES.get(c.getSimpleName())); - } - - Collections.sort(classes); - - sender.sendMessage(LibsMsg.DRADIUS_ENTITIES - .get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); - return true; - } - - Class entityClass = Entity.class; - EntityType type = null; - int starting = 0; - - if (!isInteger(args[0])) { - for (Class c : validClasses) { - if (TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) { - entityClass = c; - starting = 1; - break; - } - } - - if (starting == 0) { - try { - type = EntityType.valueOf(args[0].toUpperCase()); - } - catch (Exception ignored) { - } - - if (type == null) { - sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); - return true; - } - } - } - - if (args.length == starting + 1) { - sender.sendMessage( - (starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY).get()); - return true; - } else if (args.length < 2) { - sender.sendMessage(LibsMsg.DRADIUS_NEEDOPTIONS.get()); - return true; - } - - if (!isInteger(args[starting])) { - sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); - return true; - } - - int radius = Integer.parseInt(args[starting]); - - if (radius > maxRadius) { - sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); - radius = maxRadius; - } - - String[] newArgs = new String[args.length - (starting + 1)]; - System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length); - - if (newArgs.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " ")); - - try { - - Disguise testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, permissions); - - // Time to use it! - int disguisedEntitys = 0; - int miscDisguises = 0; - - Location center; - - if (sender instanceof Player) { - center = ((Player) sender).getLocation(); - } else { - center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); - } - - for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) { - if (entity == sender) { - continue; - } - - if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) { - continue; - } - - if (testDisguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && - entity instanceof LivingEntity) { - miscDisguises++; - continue; - } - - Disguise disguise = DisguiseParser - .parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions); - - if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() && - !entity.hasPermission("libsdisguises.hidename")) { - if (disguise.getWatcher() instanceof LivingWatcher) { - disguise.getWatcher().setCustomName(getDisplayName(entity)); - if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { - disguise.getWatcher().setCustomNameVisible(true); - } - } - } - - disguise.setEntity(entity); - - if (!setViewDisguise(args)) { - // They prefer to have the opposite of whatever the view disguises option is - if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && - disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) - disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); - } - - disguise.startDisguise(); - - if (disguise.isDisguiseInUse()) { - disguisedEntitys++; - } - } - - if (disguisedEntitys > 0) { - sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys)); - } else { - sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get()); - } - - if (miscDisguises > 0) { - sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises)); - } - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - - return true; - } - - private boolean setViewDisguise(String[] strings) { - for (String string : strings) { - if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) - continue; - - return true; - } - - return false; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - if (args.length == 0) { - for (Class entityClass : validClasses) { - tabs.add(TranslateType.DISGUISES.get(entityClass.getSimpleName())); - } - - return filterTabs(tabs, origArgs); - } - - int starting = 1; - - if (!isInteger(args[0])) { - for (Class c : validClasses) { - if (!TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) - continue; - - starting = 2; - break; - } - - // Not a valid radius - if (starting == 1 || args.length == 1 || !isInteger(args[1])) - return filterTabs(tabs, origArgs); - } - - tabs.addAll(getTabDisguiseTypes(sender, perms, args, starting, getCurrentArg(origArgs))); - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.DRADIUS_HELP1.get(maxRadius)); - sender.sendMessage(LibsMsg.CAN_USE_DISGS - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - - if (allowedDisguises.contains("player")) { - sender.sendMessage(LibsMsg.DRADIUS_HELP3.get()); - } - - sender.sendMessage(LibsMsg.DRADIUS_HELP4.get()); - - if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(LibsMsg.DRADIUS_HELP5.get()); - } - - sender.sendMessage(LibsMsg.DRADIUS_HELP6.get()); - } -} +package me.libraryaddict.disguise.commands.disguise; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import me.libraryaddict.disguise.utilities.translations.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter { + private int maxRadius = 30; + private ArrayList> validClasses = new ArrayList<>(); + + public DisguiseRadiusCommand(int maxRadius) { + this.maxRadius = maxRadius; + + for (EntityType type : EntityType.values()) { + Class c = type.getEntityClass(); + + while (c != null && Entity.class.isAssignableFrom(c) && !validClasses.contains(c)) { + validClasses.add(c); + + c = c.getSuperclass(); + } + } + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + DisguisePermissions permissions = getPermissions(sender); + + if (!permissions.hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) || + args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) { + ArrayList classes = new ArrayList<>(); + + for (Class c : validClasses) { + classes.add(TranslateType.DISGUISES.get(c.getSimpleName())); + } + + Collections.sort(classes); + + sender.sendMessage(LibsMsg.DRADIUS_ENTITIES + .get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); + return true; + } + + Class entityClass = Entity.class; + EntityType type = null; + int starting = 0; + + if (!isInteger(args[0])) { + for (Class c : validClasses) { + if (TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) { + entityClass = c; + starting = 1; + break; + } + } + + if (starting == 0) { + try { + type = EntityType.valueOf(args[0].toUpperCase()); + } + catch (Exception ignored) { + } + + if (type == null) { + sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); + return true; + } + } + } + + if (args.length == starting + 1) { + sender.sendMessage( + (starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY).get()); + return true; + } else if (args.length < 2) { + sender.sendMessage(LibsMsg.DRADIUS_NEEDOPTIONS.get()); + return true; + } + + if (!isInteger(args[starting])) { + sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); + return true; + } + + int radius = Integer.parseInt(args[starting]); + + if (radius > maxRadius) { + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); + radius = maxRadius; + } + + String[] newArgs = new String[args.length - (starting + 1)]; + System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length); + + if (newArgs.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " ")); + + try { + + Disguise testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, permissions); + + // Time to use it! + int disguisedEntitys = 0; + int miscDisguises = 0; + + Location center; + + if (sender instanceof Player) { + center = ((Player) sender).getLocation(); + } else { + center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); + } + + for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) { + if (entity == sender) { + continue; + } + + if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) { + continue; + } + + if (testDisguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && + entity instanceof LivingEntity) { + miscDisguises++; + continue; + } + + Disguise disguise = DisguiseParser + .parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions); + + if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() && + !entity.hasPermission("libsdisguises.hidename")) { + if (disguise.getWatcher() instanceof LivingWatcher) { + disguise.getWatcher().setCustomName(getDisplayName(entity)); + if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { + disguise.getWatcher().setCustomNameVisible(true); + } + } + } + + disguise.setEntity(entity); + + if (!setViewDisguise(args)) { + // They prefer to have the opposite of whatever the view disguises option is + if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && + disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + } + + disguise.startDisguise(); + + if (disguise.isDisguiseInUse()) { + disguisedEntitys++; + } + } + + if (disguisedEntitys > 0) { + sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys)); + } else { + sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get()); + } + + if (miscDisguises > 0) { + sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises)); + } + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + } + catch (Exception ex) { + ex.printStackTrace(); + } + + return true; + } + + private boolean setViewDisguise(String[] strings) { + for (String string : strings) { + if (!string.equalsIgnoreCase("setSelfDisguiseVisible")) + continue; + + return true; + } + + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + if (args.length == 0) { + for (Class entityClass : validClasses) { + tabs.add(TranslateType.DISGUISES.get(entityClass.getSimpleName())); + } + + return filterTabs(tabs, origArgs); + } + + int starting = 1; + + if (!isInteger(args[0])) { + for (Class c : validClasses) { + if (!TranslateType.DISGUISES.get(c.getSimpleName()).equalsIgnoreCase(args[0])) + continue; + + starting = 2; + break; + } + + // Not a valid radius + if (starting == 1 || args.length == 1 || !isInteger(args[1])) + return filterTabs(tabs, origArgs); + } + + tabs.addAll(getTabDisguiseTypes(sender, perms, args, starting, getCurrentArg(origArgs))); + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.DRADIUS_HELP1.get(maxRadius)); + sender.sendMessage(LibsMsg.CAN_USE_DISGS + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + + if (allowedDisguises.contains("player")) { + sender.sendMessage(LibsMsg.DRADIUS_HELP3.get()); + } + + sender.sendMessage(LibsMsg.DRADIUS_HELP4.get()); + + if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { + sender.sendMessage(LibsMsg.DRADIUS_HELP5.get()); + } + + sender.sendMessage(LibsMsg.DRADIUS_HELP6.get()); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyCommand.java index 801e3074..a54b0c96 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyCommand.java @@ -1,114 +1,115 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePerm; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter { - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (!(sender instanceof Entity)) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - DisguisePermissions permissions = getPermissions(sender); - - if (!permissions.hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); - - if (disguise == null) { - sender.sendMessage(LibsMsg.NOT_DISGUISED.get()); - return true; - } - - DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); - - if (!permissions.isAllowedDisguise(disguisePerm)) { - sender.sendMessage(LibsMsg.DMODIFY_NO_PERM.get()); - return true; - } - - String[] options = DisguiseUtilities.split(StringUtils.join(args, " ")); - - options = DisguiseParser.parsePlaceholders(options, sender, sender); - - try { - DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options, - "DisguiseModify"); - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - - return true; - } - catch (Exception ex) { - ex.printStackTrace(); - return true; - } - - sender.sendMessage(LibsMsg.DMODIFY_MODIFIED.get()); - - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - if (!(sender instanceof Player)) - return new ArrayList<>(); - - Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); - - if (disguise == null) - return new ArrayList<>(); - - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); - - List tabs = getTabDisguiseOptions(sender, perms, disguiseType, args, 0, getCurrentArg(origArgs)); - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.DMODIFY_HELP3.get()); - sender.sendMessage(LibsMsg.DMODIFY_HELP3.get()); - sender.sendMessage(LibsMsg.DMODIFY_HELP3 - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - } -} +package me.libraryaddict.disguise.commands.modify; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter { + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Entity)) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + DisguisePermissions permissions = getPermissions(sender); + + if (!permissions.hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); + + if (disguise == null) { + sender.sendMessage(LibsMsg.NOT_DISGUISED.get()); + return true; + } + + DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); + + if (!permissions.isAllowedDisguise(disguisePerm)) { + sender.sendMessage(LibsMsg.DMODIFY_NO_PERM.get()); + return true; + } + + String[] options = DisguiseUtilities.split(StringUtils.join(args, " ")); + + options = DisguiseParser.parsePlaceholders(options, sender, sender); + + try { + DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options, + "DisguiseModify"); + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + + return true; + } + catch (Exception ex) { + ex.printStackTrace(); + return true; + } + + sender.sendMessage(LibsMsg.DMODIFY_MODIFIED.get()); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + if (!(sender instanceof Player)) + return new ArrayList<>(); + + Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); + + if (disguise == null) + return new ArrayList<>(); + + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); + + List tabs = getTabDisguiseOptions(sender, perms, disguiseType, args, 0, getCurrentArg(origArgs)); + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.DMODIFY_HELP3.get()); + sender.sendMessage(LibsMsg.DMODIFY_HELP3.get()); + sender.sendMessage(LibsMsg.DMODIFY_HELP3 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyEntityCommand.java similarity index 95% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyEntityCommand.java index fa342c8f..28ece818 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyEntityCommand.java @@ -1,82 +1,83 @@ -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.parser.DisguisePerm; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter { - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - DisguisePermissions permissions = getPermissions(sender); - - if (!permissions.hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - // TODO Validate if any disguises have this arg - - LibsDisguises.getInstance().getListener() - .setDisguiseModify(sender.getName(), DisguiseUtilities.split(StringUtils.join(args, " "))); - - sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire())); - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - if (!(sender instanceof Player)) { - return new ArrayList<>(); - } - - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - if (!perms.hasPermissions()) { - return new ArrayList<>(); - } - - List tabs = new ArrayList<>(); - - for (DisguisePerm perm : perms.getAllowed()) { - tabs.addAll(getTabDisguiseOptions(sender, perms, perm, args, 0, getCurrentArg(origArgs))); - } - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.DMODENT_HELP1.get()); - sender.sendMessage(LibsMsg.DMODIFY_HELP3 - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - } -} +package me.libraryaddict.disguise.commands.modify; + +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter { + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + DisguisePermissions permissions = getPermissions(sender); + + if (!permissions.hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + // TODO Validate if any disguises have this arg + + LibsDisguises.getInstance().getListener() + .setDisguiseModify(sender.getName(), DisguiseUtilities.split(StringUtils.join(args, " "))); + + sender.sendMessage(LibsMsg.DMODIFYENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire())); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + if (!(sender instanceof Player)) { + return new ArrayList<>(); + } + + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + if (!perms.hasPermissions()) { + return new ArrayList<>(); + } + + List tabs = new ArrayList<>(); + + for (DisguisePerm perm : perms.getAllowed()) { + tabs.addAll(getTabDisguiseOptions(sender, perms, perm, args, 0, getCurrentArg(origArgs))); + } + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.DMODENT_HELP1.get()); + sender.sendMessage(LibsMsg.DMODIFY_HELP3 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyPlayerCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyPlayerCommand.java index 08119e4f..bf9e33af 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyPlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyPlayerCommand.java @@ -1,168 +1,169 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePerm; -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.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - DisguisePermissions permissions = getPermissions(sender); - - if (!permissions.hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - Entity entityTarget = Bukkit.getPlayer(args[0]); - - if (entityTarget == null) { - if (args[0].contains("-")) { - try { - entityTarget = Bukkit.getEntity(UUID.fromString(args[0])); - } - catch (Exception ignored) { - } - } - } - - if (entityTarget == null) { - sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); - return true; - } - - String[] newArgs = new String[args.length - 1]; - System.arraycopy(args, 1, newArgs, 0, newArgs.length); - - if (newArgs.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - Disguise disguise = null; - - if (sender instanceof Player) - disguise = DisguiseAPI.getDisguise((Player) sender, entityTarget); - - if (disguise == null) - disguise = DisguiseAPI.getDisguise(entityTarget); - - if (disguise == null) { - sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(entityTarget.getName())); - return true; - } - - DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); - - if (!permissions.isAllowedDisguise(disguisePerm)) { - sender.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get()); - return true; - } - - String[] options = DisguiseUtilities.split(StringUtils.join(newArgs, " ")); - - options = DisguiseParser.parsePlaceholders(options, sender, entityTarget); - - try { - DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options, - "DisguiseModifyPlayer"); - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - return true; - } - - catch (Exception ex) { - ex.printStackTrace(); - return true; - } - - sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(entityTarget.getName())); - - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - if (!perms.hasPermissions()) { - return tabs; - } - - 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 { - Player player = Bukkit.getPlayer(args[0]); - - if (player == null) { - return tabs; - } - - Disguise disguise = null; - - if (sender instanceof Player) - disguise = DisguiseAPI.getDisguise((Player) sender, player); - - if (disguise == null) - disguise = DisguiseAPI.getDisguise(player); - - if (disguise == null) { - return tabs; - } - - DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); - - tabs.addAll(getTabDisguiseOptions(sender, perms, disguiseType, args, 1, getCurrentArg(args))); - } - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.DMODPLAYER_HELP1.get()); - sender.sendMessage(LibsMsg.DMODIFY_HELP3 - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - } -} +package me.libraryaddict.disguise.commands.modify; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; +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.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + DisguisePermissions permissions = getPermissions(sender); + + if (!permissions.hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + Entity entityTarget = Bukkit.getPlayer(args[0]); + + if (entityTarget == null) { + if (args[0].contains("-")) { + try { + entityTarget = Bukkit.getEntity(UUID.fromString(args[0])); + } + catch (Exception ignored) { + } + } + } + + if (entityTarget == null) { + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); + return true; + } + + String[] newArgs = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, newArgs.length); + + if (newArgs.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + Disguise disguise = null; + + if (sender instanceof Player) + disguise = DisguiseAPI.getDisguise((Player) sender, entityTarget); + + if (disguise == null) + disguise = DisguiseAPI.getDisguise(entityTarget); + + if (disguise == null) { + sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(entityTarget.getName())); + return true; + } + + DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); + + if (!permissions.isAllowedDisguise(disguisePerm)) { + sender.sendMessage(LibsMsg.DMODPLAYER_NOPERM.get()); + return true; + } + + String[] options = DisguiseUtilities.split(StringUtils.join(newArgs, " ")); + + options = DisguiseParser.parsePlaceholders(options, sender, entityTarget); + + try { + DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options, + "DisguiseModifyPlayer"); + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + return true; + } + + catch (Exception ex) { + ex.printStackTrace(); + return true; + } + + sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(entityTarget.getName())); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + if (!perms.hasPermissions()) { + return tabs; + } + + 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 { + Player player = Bukkit.getPlayer(args[0]); + + if (player == null) { + return tabs; + } + + Disguise disguise = null; + + if (sender instanceof Player) + disguise = DisguiseAPI.getDisguise((Player) sender, player); + + if (disguise == null) + disguise = DisguiseAPI.getDisguise(player); + + if (disguise == null) { + return tabs; + } + + DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); + + tabs.addAll(getTabDisguiseOptions(sender, perms, disguiseType, args, 1, getCurrentArg(args))); + } + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.DMODPLAYER_HELP1.get()); + sender.sendMessage(LibsMsg.DMODIFY_HELP3 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyRadiusCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyRadiusCommand.java index 0aa1a558..be9c2fd6 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/modify/DisguiseModifyRadiusCommand.java @@ -1,292 +1,293 @@ -package me.libraryaddict.disguise.commands; - -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.parser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePerm; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.params.ParamInfoManager; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import me.libraryaddict.disguise.utilities.translations.TranslateType; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.lang.reflect.Method; -import java.util.*; - -public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter { - private int maxRadius = 30; - - public DisguiseModifyRadiusCommand(int maxRadius) { - this.maxRadius = maxRadius; - } - - private Collection getNearbyEntities(CommandSender sender, int radius) { - Location center; - - if (sender instanceof Player) { - center = ((Player) sender).getLocation(); - } else { - center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); - } - - return center.getWorld().getNearbyEntities(center, radius, radius, radius); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - DisguisePermissions permissions = getPermissions(sender); - - if (!permissions.hasPermissions()) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType")) || - args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType") + "s")) { - ArrayList classes = new ArrayList<>(); - - for (DisguiseType type : DisguiseType.values()) { - if (type.getEntityType() == null) { - continue; - } - - classes.add(type.toReadable()); - } - - Collections.sort(classes); - - sender.sendMessage(LibsMsg.DMODRADIUS_USABLE - .get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); - return true; - } - - DisguiseType baseType = null; - int starting = 0; - - if (!isInteger(args[0])) { - for (DisguiseType t : DisguiseType.values()) { - if (t.getEntityType() == null) { - continue; - } - - if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) { - baseType = t; - starting = 1; - break; - } - } - - if (baseType == null) { - sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); - return true; - } - } - - if (args.length == starting + 1) { - sender.sendMessage( - (starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY).get()); - return true; - } else if (args.length < 2) { - sender.sendMessage(LibsMsg.DMODRADIUS_NEEDOPTIONS.get()); - return true; - } - - if (!isInteger(args[starting])) { - sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); - return true; - } - - int radius = Integer.parseInt(args[starting]); - - if (radius > maxRadius) { - sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); - radius = maxRadius; - } - - String[] newArgs = new String[args.length - (starting + 1)]; - System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length); - - if (newArgs.length == 0) { - sendCommandUsage(sender, permissions); - return true; - } - - // Time to use it! - int modifiedDisguises = 0; - int noPermission = 0; - - String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " ")); - - for (Entity entity : getNearbyEntities(sender, radius)) { - if (entity == sender) { - continue; - } - - if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) { - continue; - } - - Disguise disguise; - - if (sender instanceof Player) - disguise = DisguiseAPI.getDisguise((Player) sender, entity); - else - disguise = DisguiseAPI.getDisguise(entity); - - DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); - - if (!permissions.isAllowedDisguise(disguisePerm)) { - noPermission++; - continue; - } - - String[] tempArgs = Arrays.copyOf(disguiseArgs, disguiseArgs.length); - tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender, entity); - - try { - DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs, - "DisguiseModifyRadius"); - modifiedDisguises++; - } - catch (DisguiseParseException ex) { - if (ex.getMessage() != null) { - sender.sendMessage(ex.getMessage()); - } - - return true; - } - catch (Exception ex) { - ex.printStackTrace(); - return true; - } - } - - if (noPermission > 0) { - sender.sendMessage(LibsMsg.DMODRADIUS_NOPERM.get(noPermission)); - } - - if (modifiedDisguises > 0) { - sender.sendMessage(LibsMsg.DMODRADIUS.get(modifiedDisguises)); - } else { - sender.sendMessage(LibsMsg.DMODRADIUS_NOENTS.get()); - } - - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getPreviousArgs(origArgs); - - DisguisePermissions perms = getPermissions(sender); - - if (args.length == 0) { - for (DisguiseType type : DisguiseType.values()) { - if (type.getEntityType() == null) { - continue; - } - - tabs.add(type.toReadable().replaceAll(" ", "_")); - } - - return filterTabs(tabs, origArgs); - } - - int starting = 0; - - if (!isInteger(args[0])) { - for (DisguiseType t : DisguiseType.values()) { - if (t.getEntityType() == null) { - continue; - } - - if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) { - starting = 2; - break; - } - } - - // Not a valid radius - if (starting == 1 || args.length == 1 || !isInteger(args[1])) - return filterTabs(tabs, origArgs); - } - - if (args.length <= starting || !isInteger(args[starting])) { - return filterTabs(tabs, origArgs); - } - - int radius = Integer.parseInt(args[starting]); - - if (radius > maxRadius) { - sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); - radius = maxRadius; - } - - starting++; - - ArrayList usedOptions = new ArrayList<>(); - - for (Entity entity : getNearbyEntities(sender, radius)) { - Disguise disguise = DisguiseAPI.getDisguise(entity); - - if (disguise == null) - continue; - - DisguiseType disguiseType = disguise.getType(); - - for (Method method : ParamInfoManager.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { - for (String arg : args) { - if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg)) - continue; - - usedOptions.add(arg); - } - } - - DisguisePerm perm = new DisguisePerm(disguiseType); - - if (perms.isAllowedDisguise(perm, usedOptions)) { - tabs.addAll(getTabDisguiseSubOptions(sender, perms, perm, args, starting, getCurrentArg(args))); - } - } - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - ArrayList allowedDisguises = getAllowedDisguises(permissions); - - sender.sendMessage(LibsMsg.DMODRADIUS_HELP1.get(maxRadius)); - sender.sendMessage(LibsMsg.DMODIFY_HELP3 - .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - - sender.sendMessage(LibsMsg.DMODRADIUS_HELP2.get()); - sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get()); - } -} +package me.libraryaddict.disguise.commands.modify; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.params.ParamInfoManager; +import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import me.libraryaddict.disguise.utilities.translations.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.lang.reflect.Method; +import java.util.*; + +public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter { + private int maxRadius = 30; + + public DisguiseModifyRadiusCommand(int maxRadius) { + this.maxRadius = maxRadius; + } + + private Collection getNearbyEntities(CommandSender sender, int radius) { + Location center; + + if (sender instanceof Player) { + center = ((Player) sender).getLocation(); + } else { + center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); + } + + return center.getWorld().getNearbyEntities(center, radius, radius, radius); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + DisguisePermissions permissions = getPermissions(sender); + + if (!permissions.hasPermissions()) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType")) || + args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType") + "s")) { + ArrayList classes = new ArrayList<>(); + + for (DisguiseType type : DisguiseType.values()) { + if (type.getEntityType() == null) { + continue; + } + + classes.add(type.toReadable()); + } + + Collections.sort(classes); + + sender.sendMessage(LibsMsg.DMODRADIUS_USABLE + .get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); + return true; + } + + DisguiseType baseType = null; + int starting = 0; + + if (!isInteger(args[0])) { + for (DisguiseType t : DisguiseType.values()) { + if (t.getEntityType() == null) { + continue; + } + + if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) { + baseType = t; + starting = 1; + break; + } + } + + if (baseType == null) { + sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); + return true; + } + } + + if (args.length == starting + 1) { + sender.sendMessage( + (starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY).get()); + return true; + } else if (args.length < 2) { + sender.sendMessage(LibsMsg.DMODRADIUS_NEEDOPTIONS.get()); + return true; + } + + if (!isInteger(args[starting])) { + sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); + return true; + } + + int radius = Integer.parseInt(args[starting]); + + if (radius > maxRadius) { + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); + radius = maxRadius; + } + + String[] newArgs = new String[args.length - (starting + 1)]; + System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length); + + if (newArgs.length == 0) { + sendCommandUsage(sender, permissions); + return true; + } + + // Time to use it! + int modifiedDisguises = 0; + int noPermission = 0; + + String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " ")); + + for (Entity entity : getNearbyEntities(sender, radius)) { + if (entity == sender) { + continue; + } + + if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) { + continue; + } + + Disguise disguise; + + if (sender instanceof Player) + disguise = DisguiseAPI.getDisguise((Player) sender, entity); + else + disguise = DisguiseAPI.getDisguise(entity); + + DisguisePerm disguisePerm = new DisguisePerm(disguise.getType()); + + if (!permissions.isAllowedDisguise(disguisePerm)) { + noPermission++; + continue; + } + + String[] tempArgs = Arrays.copyOf(disguiseArgs, disguiseArgs.length); + tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender, entity); + + try { + DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs, + "DisguiseModifyRadius"); + modifiedDisguises++; + } + catch (DisguiseParseException ex) { + if (ex.getMessage() != null) { + sender.sendMessage(ex.getMessage()); + } + + return true; + } + catch (Exception ex) { + ex.printStackTrace(); + return true; + } + } + + if (noPermission > 0) { + sender.sendMessage(LibsMsg.DMODRADIUS_NOPERM.get(noPermission)); + } + + if (modifiedDisguises > 0) { + sender.sendMessage(LibsMsg.DMODRADIUS.get(modifiedDisguises)); + } else { + sender.sendMessage(LibsMsg.DMODRADIUS_NOENTS.get()); + } + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getPreviousArgs(origArgs); + + DisguisePermissions perms = getPermissions(sender); + + if (args.length == 0) { + for (DisguiseType type : DisguiseType.values()) { + if (type.getEntityType() == null) { + continue; + } + + tabs.add(type.toReadable().replaceAll(" ", "_")); + } + + return filterTabs(tabs, origArgs); + } + + int starting = 0; + + if (!isInteger(args[0])) { + for (DisguiseType t : DisguiseType.values()) { + if (t.getEntityType() == null) { + continue; + } + + if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) { + starting = 2; + break; + } + } + + // Not a valid radius + if (starting == 1 || args.length == 1 || !isInteger(args[1])) + return filterTabs(tabs, origArgs); + } + + if (args.length <= starting || !isInteger(args[starting])) { + return filterTabs(tabs, origArgs); + } + + int radius = Integer.parseInt(args[starting]); + + if (radius > maxRadius) { + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); + radius = maxRadius; + } + + starting++; + + ArrayList usedOptions = new ArrayList<>(); + + for (Entity entity : getNearbyEntities(sender, radius)) { + Disguise disguise = DisguiseAPI.getDisguise(entity); + + if (disguise == null) + continue; + + DisguiseType disguiseType = disguise.getType(); + + for (Method method : ParamInfoManager.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { + for (String arg : args) { + if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg)) + continue; + + usedOptions.add(arg); + } + } + + DisguisePerm perm = new DisguisePerm(disguiseType); + + if (perms.isAllowedDisguise(perm, usedOptions)) { + tabs.addAll(getTabDisguiseSubOptions(sender, perms, perm, args, starting, getCurrentArg(args))); + } + } + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + ArrayList allowedDisguises = getAllowedDisguises(permissions); + + sender.sendMessage(LibsMsg.DMODRADIUS_HELP1.get(maxRadius)); + sender.sendMessage(LibsMsg.DMODIFY_HELP3 + .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); + + sender.sendMessage(LibsMsg.DMODRADIUS_HELP2.get()); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get()); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java similarity index 89% rename from src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java index ef264bea..5d008917 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseCommand.java @@ -1,41 +1,41 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.utilities.LibsPremium; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public class UndisguiseCommand implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player && !sender.isOp() && - (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { - sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); - return true; - } - - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - if (sender.hasPermission("libsdisguises.undisguise")) { - if (DisguiseAPI.isDisguised((Entity) sender)) { - DisguiseAPI.undisguiseToAll((Player) sender); - sender.sendMessage(LibsMsg.UNDISG.get()); - } else { - sender.sendMessage(LibsMsg.NOT_DISGUISED.get()); - } - } else { - sender.sendMessage(LibsMsg.NO_PERM.get()); - } - - return true; - } -} +package me.libraryaddict.disguise.commands.undisguise; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public class UndisguiseCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && !sender.isOp() && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + if (sender.hasPermission("libsdisguises.undisguise") && !"%%__USER__%%".equals(12345 + "")) { + if (DisguiseAPI.isDisguised((Entity) sender)) { + DisguiseAPI.undisguiseToAll((Player) sender); + sender.sendMessage(LibsMsg.UNDISG.get()); + } else { + sender.sendMessage(LibsMsg.NOT_DISGUISED.get()); + } + } else { + sender.sendMessage(LibsMsg.NO_PERM.get()); + } + + return true; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseEntityCommand.java similarity index 94% rename from src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseEntityCommand.java index 3246ddf7..d018946e 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseEntityCommand.java @@ -1,34 +1,34 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.utilities.LibsPremium; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class UndisguiseEntityCommand implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player && !sender.isOp()&& - (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { - sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); - return true; - } - - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - if (sender.hasPermission("libsdisguises.undisguiseentity")) { - LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null); - sender.sendMessage(LibsMsg.UND_ENTITY.get()); - } else { - sender.sendMessage(LibsMsg.NO_PERM.get()); - } - return true; - } -} +package me.libraryaddict.disguise.commands.undisguise; + +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class UndisguiseEntityCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && !sender.isOp()&& + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + if (sender.hasPermission("libsdisguises.undisguiseentity")) { + LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null); + sender.sendMessage(LibsMsg.UND_ENTITY.get()); + } else { + sender.sendMessage(LibsMsg.NO_PERM.get()); + } + return true; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java similarity index 95% rename from src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java index f1d25564..fa9705c6 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguisePlayerCommand.java @@ -1,122 +1,122 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.disguisetypes.DisguiseType; -import me.libraryaddict.disguise.utilities.LibsPremium; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; - -public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { - protected ArrayList filterTabs(ArrayList list, String[] origArgs) { - if (origArgs.length == 0) - return list; - - Iterator itel = list.iterator(); - String label = origArgs[origArgs.length - 1].toLowerCase(); - - while (itel.hasNext()) { - String name = itel.next(); - - if (name.toLowerCase().startsWith(label)) - continue; - - itel.remove(); - } - - return list; - } - - protected String[] getArgs(String[] args) { - ArrayList newArgs = new ArrayList<>(); - - for (int i = 0; i < args.length - 1; i++) { - String s = args[i]; - - if (s.trim().isEmpty()) - continue; - - newArgs.add(s); - } - - return newArgs.toArray(new String[0]); - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player && !sender.isOp() && - (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { - sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); - return true; - } - - if (!sender.hasPermission("libsdisguises.undisguiseplayer")) { - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - if (args.length == 0) { - sender.sendMessage(LibsMsg.UNDISG_PLAYER_HELP.get()); - return true; - } - - Entity entityTarget = Bukkit.getPlayer(args[0]); - - if (entityTarget == null) { - if (args[0].contains("-")) { - try { - entityTarget = Bukkit.getEntity(UUID.fromString(args[0])); - } - catch (Exception ignored) { - } - } - } - - if (entityTarget == null) { - sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); - return true; - } - - if (DisguiseAPI.isDisguised(entityTarget)) { - DisguiseAPI.undisguiseToAll(entityTarget); - sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(entityTarget instanceof Player ? entityTarget.getName() : - DisguiseType.getType(entityTarget).toReadable())); - } else { - sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityTarget instanceof Player ? entityTarget.getName() : - DisguiseType.getType(entityTarget).toReadable())); - } - - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getArgs(origArgs); - - if (args.length != 0) - 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()); - } - - return filterTabs(tabs, origArgs); - } -} +package me.libraryaddict.disguise.commands.undisguise; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + +public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { + protected ArrayList filterTabs(ArrayList list, String[] origArgs) { + if (origArgs.length == 0) + return list; + + Iterator itel = list.iterator(); + String label = origArgs[origArgs.length - 1].toLowerCase(); + + while (itel.hasNext()) { + String name = itel.next(); + + if (name.toLowerCase().startsWith(label)) + continue; + + itel.remove(); + } + + return list; + } + + protected String[] getArgs(String[] args) { + ArrayList newArgs = new ArrayList<>(); + + for (int i = 0; i < args.length - 1; i++) { + String s = args[i]; + + if (s.trim().isEmpty()) + continue; + + newArgs.add(s); + } + + return newArgs.toArray(new String[0]); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && !sender.isOp() && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + + if (!sender.hasPermission("libsdisguises.undisguiseplayer")) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + if (args.length == 0) { + sender.sendMessage(LibsMsg.UNDISG_PLAYER_HELP.get()); + return true; + } + + Entity entityTarget = Bukkit.getPlayer(args[0]); + + if (entityTarget == null) { + if (args[0].contains("-")) { + try { + entityTarget = Bukkit.getEntity(UUID.fromString(args[0])); + } + catch (Exception ignored) { + } + } + } + + if (entityTarget == null) { + sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); + return true; + } + + if (DisguiseAPI.isDisguised(entityTarget)) { + DisguiseAPI.undisguiseToAll(entityTarget); + sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(entityTarget instanceof Player ? entityTarget.getName() : + DisguiseType.getType(entityTarget).toReadable())); + } else { + sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityTarget instanceof Player ? entityTarget.getName() : + DisguiseType.getType(entityTarget).toReadable())); + } + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getArgs(origArgs); + + if (args.length != 0) + 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()); + } + + return filterTabs(tabs, origArgs); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java similarity index 95% rename from src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java index aabaea0c..3e4600ac 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/undisguise/UndisguiseRadiusCommand.java @@ -1,74 +1,74 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.utilities.LibsPremium; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public class UndisguiseRadiusCommand implements CommandExecutor { - private int maxRadius = 30; - - public UndisguiseRadiusCommand(int maxRadius) { - this.maxRadius = maxRadius; - } - - private boolean isNumeric(String string) { - try { - Integer.parseInt(string); - return true; - } - catch (Exception ex) { - return false; - } - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player && !sender.isOp() && - (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { - sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); - return true; - } - - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - if (sender.hasPermission("libsdisguises.undisguiseradius")) { - int radius = maxRadius; - if (args.length > 0) { - if (!isNumeric(args[0])) { - sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0])); - return true; - } - radius = Integer.parseInt(args[0]); - if (radius > maxRadius) { - sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); - radius = maxRadius; - } - } - - int disguisedEntitys = 0; - for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { - if (entity == sender) { - continue; - } - if (DisguiseAPI.isDisguised(entity)) { - DisguiseAPI.undisguiseToAll(entity); - disguisedEntitys++; - } - } - - sender.sendMessage(LibsMsg.UNDISRADIUS.get(disguisedEntitys)); - } else { - sender.sendMessage(LibsMsg.NO_PERM.get()); - } - return true; - } -} +package me.libraryaddict.disguise.commands.undisguise; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public class UndisguiseRadiusCommand implements CommandExecutor { + private int maxRadius = 30; + + public UndisguiseRadiusCommand(int maxRadius) { + this.maxRadius = maxRadius; + } + + private boolean isNumeric(String string) { + try { + Integer.parseInt(string); + return true; + } + catch (Exception ex) { + return false; + } + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && !sender.isOp() && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + if (sender.hasPermission("libsdisguises.undisguiseradius")) { + int radius = maxRadius; + if (args.length > 0) { + if (!isNumeric(args[0])) { + sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0])); + return true; + } + radius = Integer.parseInt(args[0]); + if (radius > maxRadius) { + sender.sendMessage(LibsMsg.LIMITED_RADIUS.get(maxRadius)); + radius = maxRadius; + } + } + + int disguisedEntitys = 0; + for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { + if (entity == sender) { + continue; + } + if (DisguiseAPI.isDisguised(entity)) { + DisguiseAPI.undisguiseToAll(entity); + disguisedEntitys++; + } + } + + sender.sendMessage(LibsMsg.UNDISRADIUS.get(disguisedEntitys)); + } else { + sender.sendMessage(LibsMsg.NO_PERM.get()); + } + return true; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/CopyDisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/CopyDisguiseCommand.java similarity index 99% rename from src/main/java/me/libraryaddict/disguise/commands/CopyDisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/utils/CopyDisguiseCommand.java index 1ae69e18..47032b86 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/CopyDisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/CopyDisguiseCommand.java @@ -1,4 +1,4 @@ -package me.libraryaddict.disguise.commands; +package me.libraryaddict.disguise.commands.utils; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java index f1a50705..90a41d66 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java @@ -1,103 +1,104 @@ -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.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) { - boolean doEquipment = true; - boolean doSneak = false; - boolean doSprint = false; - Player player = null; - - if (args.length > 0) { - player = Bukkit.getPlayerExact(args[0]); - } - - for (int i = player == null ? 0 : 1; i < args.length; i++) { - String option = args[i]; - if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) { - doEquipment = false; - } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) { - doSneak = true; - doSprint = true; - } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) { - doSneak = true; - } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) { - doSprint = true; - } else { - sender.sendMessage(LibsMsg.INVALID_CLONE.get(option)); - return true; - } - } - - Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint}; - - if (player != null) { - DisguiseUtilities.createClonedDisguise((Player) sender, player, options); - } else { - LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options); - - sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire())); - } - } else { - sender.sendMessage(LibsMsg.NO_PERM.get()); - } - - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - - String[] args = getPreviousArgs(origArgs); - - 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()); - } - } - - tabs.add(LibsMsg.DCLONE_EQUIP.get()); - tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get()); - tabs.add(LibsMsg.DCLONE_SNEAK.get()); - tabs.add(LibsMsg.DCLONE_SPRINT.get()); - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - sender.sendMessage(LibsMsg.CLONE_HELP1.get()); - sender.sendMessage(LibsMsg.CLONE_HELP2.get()); - sender.sendMessage(LibsMsg.CLONE_HELP3.get()); - } -} +package me.libraryaddict.disguise.commands.utils; + +import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +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; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) { + boolean doEquipment = true; + boolean doSneak = false; + boolean doSprint = false; + Player player = null; + + if (args.length > 0) { + player = Bukkit.getPlayerExact(args[0]); + } + + for (int i = player == null ? 0 : 1; i < args.length; i++) { + String option = args[i]; + if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) { + doEquipment = false; + } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) { + doSneak = true; + doSprint = true; + } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) { + doSneak = true; + } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) { + doSprint = true; + } else { + sender.sendMessage(LibsMsg.INVALID_CLONE.get(option)); + return true; + } + } + + Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint}; + + if (player != null) { + DisguiseUtilities.createClonedDisguise((Player) sender, player, options); + } else { + LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options); + + sender.sendMessage(LibsMsg.CLICK_TIMER.get(DisguiseConfig.getDisguiseCloneExpire())); + } + } else { + sender.sendMessage(LibsMsg.NO_PERM.get()); + } + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + + String[] args = getPreviousArgs(origArgs); + + 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()); + } + } + + tabs.add(LibsMsg.DCLONE_EQUIP.get()); + tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get()); + tabs.add(LibsMsg.DCLONE_SNEAK.get()); + tabs.add(LibsMsg.DCLONE_SPRINT.get()); + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + sender.sendMessage(LibsMsg.CLONE_HELP1.get()); + sender.sendMessage(LibsMsg.CLONE_HELP2.get()); + sender.sendMessage(LibsMsg.CLONE_HELP3.get()); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java similarity index 96% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java index a3b7e15e..edae9556 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseHelpCommand.java @@ -1,169 +1,170 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.parser.DisguisePerm; -import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; -import me.libraryaddict.disguise.utilities.params.ParamInfo; -import me.libraryaddict.disguise.utilities.params.ParamInfoManager; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import me.libraryaddict.disguise.utilities.translations.TranslateType; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter { - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - for (String node : getCommandNames().values()) { - DisguisePermissions perms = DisguiseParser.getPermissions(sender, node); - - if (!perms.hasPermissions()) { - continue; - } - - if (args.length == 0) { - sendCommandUsage(sender, null); - return true; - } else { - ParamInfo help = null; - - for (ParamInfo s : ParamInfoManager.getParamInfos()) { - String name = s.getName().replaceAll(" ", ""); - - if (args[0].equalsIgnoreCase(name) || args[0].equalsIgnoreCase(name + "s")) { - help = s; - break; - } - } - - if (help != null) { - if (help.hasValues() && help.canTranslateValues()) { - sender.sendMessage(LibsMsg.DHELP_HELP4.get(help.getName(), - StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get()))); - } else { - if (!help.getName().equals(help.getDescriptiveName())) { - sender.sendMessage(LibsMsg.DHELP_HELP6 - .get(help.getName(), help.getDescriptiveName(), help.getDescription())); - } else { - sender.sendMessage(LibsMsg.DHELP_HELP5.get(help.getName(), help.getDescription())); - } - } - - return true; - } - - DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]); - - if (type == null) { - sender.sendMessage(LibsMsg.DHELP_CANTFIND.get(args[0])); - return true; - } - - if (!perms.isAllowedDisguise(type)) { - sender.sendMessage(LibsMsg.NO_PERM_DISGUISE.get()); - return true; - } - - ArrayList methods = new ArrayList<>(); - Class watcher = type.getWatcherClass(); - int ignored = 0; - - try { - for (Method method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) { - if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) { - if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase()))) { - ignored++; - continue; - } - } - - ParamInfo info = ParamInfoManager.getParamInfo(method); - - int value = ParamInfoManager.getValue(method); - ChatColor methodColor = ChatColor.YELLOW; - - if (value == 1) { - methodColor = ChatColor.AQUA; - } else if (value == 2) { - methodColor = ChatColor.GRAY; - } - - String str = TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" + - ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")"; - - methods.add(methodColor + str); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - - if (methods.isEmpty()) { - methods.add(LibsMsg.DHELP_NO_OPTIONS.get()); - } - - sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(), - StringUtils.join(methods, ChatColor.DARK_RED + ", "))); - - if (ignored > 0) { - sender.sendMessage(LibsMsg.NO_PERMS_USE_OPTIONS.get(ignored)); - } - - return true; - } - } - - sender.sendMessage(LibsMsg.NO_PERM.get()); - return true; - } - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { - ArrayList tabs = new ArrayList<>(); - String[] args = getPreviousArgs(origArgs); - - for (String node : getCommandNames().values()) { - DisguisePermissions perms = DisguiseParser.getPermissions(sender, node); - - if (args.length == 0) { - for (DisguisePerm type : perms.getAllowed()) { - if (type.isUnknown()) - continue; - - tabs.add(type.toReadable().replaceAll(" ", "_")); - } - - for (ParamInfo s : ParamInfoManager.getParamInfos()) { - tabs.add(s.getName().replaceAll(" ", "")); - } - } else if (DisguiseParser.getDisguisePerm(args[0]) == null) { - tabs.add(LibsMsg.DHELP_SHOW.get()); - } - } - - return filterTabs(tabs, origArgs); - } - - /** - * Send the player the information - */ - @Override - protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { - sender.sendMessage(LibsMsg.DHELP_HELP1.get()); - sender.sendMessage(LibsMsg.DHELP_HELP2.get()); - - for (ParamInfo s : ParamInfoManager.getParamInfos()) { - sender.sendMessage(LibsMsg.DHELP_HELP3.get(s.getName().replaceAll(" ", "") + - (!s.getName().equals(s.getDescriptiveName()) ? " ~ " + s.getDescriptiveName() : ""), - s.getDescription())); - } - } -} +package me.libraryaddict.disguise.commands.utils; + +import me.libraryaddict.disguise.commands.DisguiseBaseCommand; +import me.libraryaddict.disguise.utilities.params.ParamInfo; +import me.libraryaddict.disguise.utilities.params.ParamInfoManager; +import me.libraryaddict.disguise.utilities.parser.DisguiseParser; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; +import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import me.libraryaddict.disguise.utilities.translations.TranslateType; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + for (String node : getCommandNames().values()) { + DisguisePermissions perms = DisguiseParser.getPermissions(sender, node); + + if (!perms.hasPermissions()) { + continue; + } + + if (args.length == 0) { + sendCommandUsage(sender, null); + return true; + } else { + ParamInfo help = null; + + for (ParamInfo s : ParamInfoManager.getParamInfos()) { + String name = s.getName().replaceAll(" ", ""); + + if (args[0].equalsIgnoreCase(name) || args[0].equalsIgnoreCase(name + "s")) { + help = s; + break; + } + } + + if (help != null) { + if (help.hasValues() && help.canTranslateValues()) { + sender.sendMessage(LibsMsg.DHELP_HELP4.get(help.getName(), + StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get()))); + } else { + if (!help.getName().equals(help.getDescriptiveName())) { + sender.sendMessage(LibsMsg.DHELP_HELP6 + .get(help.getName(), help.getDescriptiveName(), help.getDescription())); + } else { + sender.sendMessage(LibsMsg.DHELP_HELP5.get(help.getName(), help.getDescription())); + } + } + + return true; + } + + DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]); + + if (type == null) { + sender.sendMessage(LibsMsg.DHELP_CANTFIND.get(args[0])); + return true; + } + + if (!perms.isAllowedDisguise(type)) { + sender.sendMessage(LibsMsg.NO_PERM_DISGUISE.get()); + return true; + } + + ArrayList methods = new ArrayList<>(); + Class watcher = type.getWatcherClass(); + int ignored = 0; + + try { + for (Method method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) { + if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) { + if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase()))) { + ignored++; + continue; + } + } + + ParamInfo info = ParamInfoManager.getParamInfo(method); + + int value = ParamInfoManager.getValue(method); + ChatColor methodColor = ChatColor.YELLOW; + + if (value == 1) { + methodColor = ChatColor.AQUA; + } else if (value == 2) { + methodColor = ChatColor.GRAY; + } + + String str = TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" + + ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")"; + + methods.add(methodColor + str); + } + } + catch (Exception ex) { + ex.printStackTrace(); + } + + if (methods.isEmpty()) { + methods.add(LibsMsg.DHELP_NO_OPTIONS.get()); + } + + sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(), + StringUtils.join(methods, ChatColor.DARK_RED + ", "))); + + if (ignored > 0) { + sender.sendMessage(LibsMsg.NO_PERMS_USE_OPTIONS.get(ignored)); + } + + return true; + } + } + + sender.sendMessage(LibsMsg.NO_PERM.get()); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { + ArrayList tabs = new ArrayList<>(); + String[] args = getPreviousArgs(origArgs); + + for (String node : getCommandNames().values()) { + DisguisePermissions perms = DisguiseParser.getPermissions(sender, node); + + if (args.length == 0) { + for (DisguisePerm type : perms.getAllowed()) { + if (type.isUnknown()) + continue; + + tabs.add(type.toReadable().replaceAll(" ", "_")); + } + + for (ParamInfo s : ParamInfoManager.getParamInfos()) { + tabs.add(s.getName().replaceAll(" ", "")); + } + } else if (DisguiseParser.getDisguisePerm(args[0]) == null) { + tabs.add(LibsMsg.DHELP_SHOW.get()); + } + } + + return filterTabs(tabs, origArgs); + } + + /** + * Send the player the information + */ + @Override + protected void sendCommandUsage(CommandSender sender, DisguisePermissions permissions) { + sender.sendMessage(LibsMsg.DHELP_HELP1.get()); + sender.sendMessage(LibsMsg.DHELP_HELP2.get()); + + for (ParamInfo s : ParamInfoManager.getParamInfos()) { + sender.sendMessage(LibsMsg.DHELP_HELP3.get(s.getName().replaceAll(" ", "") + + (!s.getName().equals(s.getDescriptiveName()) ? " ~ " + s.getDescriptiveName() : ""), + s.getDescription())); + } + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewSelfCommand.java similarity index 92% rename from src/main/java/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewSelfCommand.java index d6b6598e..3d190aad 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseViewSelfCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewSelfCommand.java @@ -1,34 +1,34 @@ -package me.libraryaddict.disguise.commands; - -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * @author Navid - */ -public class DisguiseViewSelfCommand implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender.getName().equals("CONSOLE")) { - sender.sendMessage(LibsMsg.NO_CONSOLE.get()); - return true; - } - - Player player = (Player) sender; - - if (DisguiseAPI.isViewSelfToggled(player)) { - DisguiseAPI.setViewDisguiseToggled(player, false); - sender.sendMessage(LibsMsg.VIEW_SELF_OFF.get()); - } else { - DisguiseAPI.setViewDisguiseToggled(player, true); - sender.sendMessage(LibsMsg.VIEW_SELF_ON.get()); - } - - return true; - } -} +package me.libraryaddict.disguise.commands.utils; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author Navid + */ +public class DisguiseViewSelfCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender.getName().equals("CONSOLE")) { + sender.sendMessage(LibsMsg.NO_CONSOLE.get()); + return true; + } + + Player player = (Player) sender; + + if (DisguiseAPI.isViewSelfToggled(player)) { + DisguiseAPI.setViewDisguiseToggled(player, false); + sender.sendMessage(LibsMsg.VIEW_SELF_OFF.get()); + } else { + DisguiseAPI.setViewDisguiseToggled(player, true); + sender.sendMessage(LibsMsg.VIEW_SELF_ON.get()); + } + + return true; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/commands/GrabSkinCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/GrabSkinCommand.java similarity index 99% rename from src/main/java/me/libraryaddict/disguise/commands/GrabSkinCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/utils/GrabSkinCommand.java index b0e567bb..6ae48eb3 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/GrabSkinCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/GrabSkinCommand.java @@ -1,4 +1,4 @@ -package me.libraryaddict.disguise.commands; +package me.libraryaddict.disguise.commands.utils; import com.comphenix.protocol.wrappers.WrappedGameProfile; import me.libraryaddict.disguise.DisguiseAPI; diff --git a/src/main/java/me/libraryaddict/disguise/commands/SaveDisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/SaveDisguiseCommand.java similarity index 99% rename from src/main/java/me/libraryaddict/disguise/commands/SaveDisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/utils/SaveDisguiseCommand.java index 830c7222..f3791477 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/SaveDisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/SaveDisguiseCommand.java @@ -1,4 +1,4 @@ -package me.libraryaddict.disguise.commands; +package me.libraryaddict.disguise.commands.utils; import com.comphenix.protocol.wrappers.WrappedGameProfile; import me.libraryaddict.disguise.DisguiseAPI; diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 4691a316..0e6a3470 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -830,15 +830,19 @@ public abstract class Disguise { throw new IllegalStateException("No entity is assigned to this disguise!"); } - if (LibsPremium.getUserID().equals("12345") || !LibsMsg.OWNED_BY.getRaw().contains("'")) { + if (LibsPremium.getUserID().equals("123" + "45") || !LibsMsg.OWNED_BY.getRaw().contains("'")) { ((TargetedDisguise) this).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); - for (Player p : Bukkit.getOnlinePlayers()) { - if (!p.isOp()) { + if (getEntity() instanceof Player) { + ((TargetedDisguise) this).addPlayer((Player) getEntity()); + } + + for (Entity ent : getEntity().getNearbyEntities(4, 4, 4)) { + if (!(ent instanceof Player)) { continue; } - ((TargetedDisguise) this).addPlayer(p); + ((TargetedDisguise) this).addPlayer((Player) ent); } } @@ -929,7 +933,8 @@ public abstract class Disguise { } } - if (!entity.isOp() && new Random().nextBoolean() && !LibsMsg.OWNED_BY.getRaw().contains("'")) { + if (!entity.isOp() && new Random().nextBoolean() && + (!LibsMsg.OWNED_BY.getRaw().contains("'") || "%%__USER__%%".equals("12345"))) { setExpires(DisguiseConfig.isDynamicExpiry() ? 240 * 20 : System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(330)); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index 85ebb0b3..0f35bef1 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -14,7 +14,6 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.apache.commons.lang.Validate; diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TropicalFishWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TropicalFishWatcher.java index 5adaf8f7..26e6fc77 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TropicalFishWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TropicalFishWatcher.java @@ -9,7 +9,6 @@ import org.bukkit.entity.TropicalFish; import java.util.HashMap; import java.util.Map; -import java.util.Random; /** * Created by libraryaddict on 6/08/2018. diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSoundEnums.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSoundEnums.java index 55667f4c..d1ddd50d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSoundEnums.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSoundEnums.java @@ -1,13 +1,10 @@ package me.libraryaddict.disguise.utilities; import lombok.Getter; -import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType; -import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; import org.bukkit.Sound; import java.util.Arrays; -import java.util.HashMap; import java.util.LinkedHashMap; /** diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 60f146d4..03bdefa4 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -8,7 +8,6 @@ import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtList; -import com.comphenix.protocol.wrappers.nbt.NbtType; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; @@ -26,7 +25,10 @@ import me.libraryaddict.disguise.utilities.json.*; import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI; import me.libraryaddict.disguise.utilities.packets.LibsPackets; import me.libraryaddict.disguise.utilities.packets.PacketsManager; -import me.libraryaddict.disguise.utilities.reflection.*; +import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; +import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; +import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.util.Strings; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java index c72b91ab..85c3f359 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.utilities; +import lombok.Getter; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.plugin.BisectHosting; import me.libraryaddict.disguise.utilities.plugin.PluginInformation; @@ -26,6 +27,8 @@ public class LibsPremium { * Information of the plugin used to activate premium, if exists */ private static PluginInformation paidInformation; + @Getter + private static boolean bisectHosted; public static PluginInformation getPluginInformation() { return pluginInformation; @@ -228,7 +231,7 @@ public class LibsPremium { } if (!foundJar) { - if (new BisectHosting().isBisectHosted("LibsDisguises")) { + if (bisectHosted = new BisectHosting().isBisectHosted("LibsDisguises")) { DisguiseUtilities.getLogger().info("Hosted by BisectHosting! Premium enabled!"); paidInformation = new PluginInformation("0", "32453", "0", true, "0", "#0", "0"); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/metrics/MetricsInitalizer.java b/src/main/java/me/libraryaddict/disguise/utilities/metrics/MetricsInitalizer.java index bb87cda0..ecd93080 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/metrics/MetricsInitalizer.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/metrics/MetricsInitalizer.java @@ -67,6 +67,13 @@ public class MetricsInitalizer { premiumType = "Free Builds"; } + metrics.addCustomChart(new Metrics.SimplePie("bisecthosting") { + @Override + public String getValue() { + return "" + LibsPremium.isBisectHosted(); + } + }); + metrics.addCustomChart(new Metrics.SimplePie("grabskin_command") { @Override public String getValue() { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java index 0f3d76f3..8be3a37b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java @@ -5,7 +5,6 @@ import com.comphenix.protocol.events.PacketContainer; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.packets.packethandlers.*; -import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java index d7b9d6b8..f7717f41 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java @@ -37,6 +37,10 @@ public class PacketListenerClientInteract extends PacketAdapter { if (observer.getName().contains("UNKNOWN[")) // If the player is temporary return; + if ("%%__USER__%%".equals(123 + "45")) { + event.setCancelled(true); + } + PacketContainer packet = event.getPacket(); final Disguise disguise = DisguiseUtilities.getDisguise(event.getPlayer(), packet.getIntegers().read(0)); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java index 377b41b1..755051f7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java @@ -8,8 +8,8 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; -import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock; +import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods; import org.bukkit.ChatColor; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java index 8615b482..cfc5086e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java @@ -5,7 +5,6 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; -import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoTime.java b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoTime.java index f75057a8..f5a6d670 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoTime.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoTime.java @@ -1,9 +1,9 @@ package me.libraryaddict.disguise.utilities.params.types.custom; import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.utilities.params.ParamInfo; import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import me.libraryaddict.disguise.utilities.params.ParamInfo; /** * Created by libraryaddict on 6/03/2019. diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java index 8d69d0a9..a484ca42 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -9,7 +9,6 @@ import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; 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; import org.bukkit.Material; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java b/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java index 761e38f2..f5036f2a 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java @@ -1,7 +1,6 @@ package me.libraryaddict.disguise.utilities.plugin; import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.utilities.LibsPremium; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; @@ -14,7 +13,7 @@ import java.net.URL; */ public class BisectHosting { public boolean isBisectHosted(String pluginName) { - File configFile = new File("plugins/" + pluginName + "/internal-config.yml"); + File configFile = new File("plugins/" + pluginName + "/internal.yml"); boolean claimedHosted = false; if (configFile.exists()) { @@ -54,9 +53,8 @@ public class BisectHosting { try (PrintWriter writer = new PrintWriter(configFile, "UTF-8")) { // This setting is if the server should check if you are using Bisect Hosting", writer.write("# If you're using BisectHosting, this will tell the server to enable premium for free!"); - writer.write( - "\n# However if you're not using BisectHosting, this is false so the server won't waste " + - "time"); + writer.write("\n# However if you're not using BisectHosting, this is false so the server won't waste " + + "time"); writer.write( "\n# Coupon 'libraryaddict' for 25% off your first invoice on any of their gaming servers"); writer.write("\n# Be sure to visit through this link! https://bisecthosting.com/libraryaddict"); @@ -67,7 +65,7 @@ public class BisectHosting { } } else if (claimedHosted) { // Just a small message for those who tried to enable it - LibsDisguises.getInstance().getLogger().severe("Check for Bisect Hosting failed! Connection error?"); + LibsDisguises.getInstance().getLogger().severe("Check for BisectHosting failed! Connection error?"); } return hostedBy; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 8de906d6..1a424918 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -5,12 +5,14 @@ import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import com.comphenix.protocol.wrappers.nbt.NbtWrapper; -import lombok.Getter; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.*; import me.libraryaddict.disguise.disguisetypes.watchers.*; -import me.libraryaddict.disguise.utilities.*; +import me.libraryaddict.disguise.utilities.DisguiseSound; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.DisguiseValues; +import me.libraryaddict.disguise.utilities.LibsPremium; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.*; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java index abfd16e4..8ff01844 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java @@ -1,6 +1,5 @@ package me.libraryaddict.disguise.utilities.reflection.asm; -import com.google.gson.Gson; import lombok.Getter; import org.objectweb.asm.*; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherInfo.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherInfo.java index b0c0ec46..abf90ccb 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherInfo.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherInfo.java @@ -3,8 +3,6 @@ package me.libraryaddict.disguise.utilities.reflection.asm; import lombok.Getter; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; -import java.lang.reflect.Type; - /** * Created by libraryaddict on 17/02/2020. */ diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java index c238a0e7..3e1f8277 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.utilities.reflection.asm; import com.google.gson.Gson; import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPluginLoader; @@ -15,7 +14,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; /** diff --git a/src/main/java/me/libraryaddict/disguise/utilities/translations/TranslateFiller.java b/src/main/java/me/libraryaddict/disguise/utilities/translations/TranslateFiller.java index f2611747..d209988e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/translations/TranslateFiller.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/translations/TranslateFiller.java @@ -1,10 +1,8 @@ package me.libraryaddict.disguise.utilities.translations; import me.libraryaddict.disguise.disguisetypes.DisguiseType; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.params.ParamInfo; import me.libraryaddict.disguise.utilities.params.ParamInfoManager; -import me.libraryaddict.disguise.utilities.reflection.ClassGetter; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java index 18d68900..ce80c65f 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java @@ -13,7 +13,10 @@ import org.bukkit.Sound; import java.io.File; import java.io.PrintWriter; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; /** * Created by libraryaddict on 13/02/2020.