From 05f2763311af4af6b6570a97b205ed600d3aee9e Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 27 Oct 2020 11:03:47 -0700 Subject: [PATCH] You can now silence mmoedit, addlevels, and addxp with -s --- Changelog.txt | 12 +++--- .../commands/experience/AddlevelsCommand.java | 10 ++++- .../commands/experience/AddxpCommand.java | 10 ++++- .../experience/ExperienceCommand.java | 40 ++++++++++++------- .../commands/experience/MmoeditCommand.java | 10 ++++- .../commands/CommandRegistrationManager.java | 6 +-- .../resources/locale/locale_en_US.properties | 1 + 7 files changed, 61 insertions(+), 28 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index a0f452ad9..1baf71fe8 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -4,11 +4,13 @@ Version 2.1.150 The style and look of admin/party chat is now determined by locale file instead of options in config.yml Improved messages players recieve when they toggle on or off admin or party chat All locale files have had [[]] color codes replaced by & color codes, you can still use [[GOLD]] and stuff if you want - Added new locale string 'Chat.Identity.Console' - Added new locale string 'Chat.Style.Admin' - Added new locale string 'Chat.Style.Party' - Added new locale string 'Chat.Channel.On' - Added new locale string 'Chat.Channel.Off' + You can now add "-s" at the end of mmoedit, addlevels, or addxp to silence the command. Which will prevent the target of the command from being informed that the command was executed. + Added new locale entry 'Commands.Usage.3.XP' + Added new locale entry 'Chat.Identity.Console' + Added new locale entry 'Chat.Style.Admin' + Added new locale entry 'Chat.Style.Party' + Added new locale entry 'Chat.Channel.On' + Added new locale entry 'Chat.Channel.Off' Fixed an ArrayIndexOutOfBounds exception when using /skillreset (API) ChatAPI::getPartyChatManager() has been removed (API) ChatAPI::sendPartyChat has been removed (similar functionality can be found in the new ChatManager class) diff --git a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java index e4edefd74..6c736fd2c 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java @@ -34,12 +34,18 @@ public class AddlevelsCommand extends ExperienceCommand { } @Override - protected void handlePlayerMessageAll(Player player, int value) { + protected void handlePlayerMessageAll(Player player, int value, boolean isSilent) { + if(isSilent) + return; + player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", value)); } @Override - protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill) { + protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent) { + if(isSilent) + return; + player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, skill.getName())); } } diff --git a/src/main/java/com/gmail/nossr50/commands/experience/AddxpCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/AddxpCommand.java index f2f3a5370..03ad449bb 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/AddxpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/AddxpCommand.java @@ -37,12 +37,18 @@ public class AddxpCommand extends ExperienceCommand { } @Override - protected void handlePlayerMessageAll(Player player, int value) { + protected void handlePlayerMessageAll(Player player, int value, boolean isSilent) { + if(isSilent) + return; + player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", value)); } @Override - protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill) { + protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent) { + if(isSilent) + return; + player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, skill.getName())); } } diff --git a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java index e4886ae0f..2443e6d62 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java @@ -25,8 +25,10 @@ public abstract class ExperienceCommand implements TabExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { PrimarySkillType skill; - switch (args.length) { - case 2: + if(args.length < 2) { + return false; + } else { + if(args.length == 2 && !isSilent(args) || args.length == 3 && isSilent(args)) { if (CommandUtils.noConsoleUsage(sender)) { return true; } @@ -62,10 +64,10 @@ public abstract class ExperienceCommand implements TabExecutor { } - editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill, Integer.parseInt(args[1])); + editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill, Integer.parseInt(args[1]), isSilent(args)); return true; - - case 3: + } else if((args.length == 3 && !isSilent(args)) + || (args.length == 4 && isSilent(args))) { if (!permissionsCheckOthers(sender)) { sender.sendMessage(command.getPermissionMessage()); return true; @@ -105,20 +107,30 @@ public abstract class ExperienceCommand implements TabExecutor { return true; } - editValues(null, profile, skill, value); + editValues(null, profile, skill, value, isSilent(args)); } else { - editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill, value); + editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill, value, isSilent(args)); } handleSenderMessage(sender, playerName, skill); return true; - - default: + } else { return false; + } } } + private boolean isSilent(String[] args) { + int length = args.length; + + if(length == 0) + return false; + + return args[length-1].equalsIgnoreCase("-s"); + } + + @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { switch (args.length) { @@ -135,8 +147,8 @@ public abstract class ExperienceCommand implements TabExecutor { protected abstract boolean permissionsCheckSelf(CommandSender sender); protected abstract boolean permissionsCheckOthers(CommandSender sender); protected abstract void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill, int value); - protected abstract void handlePlayerMessageAll(Player player, int value); - protected abstract void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill); + protected abstract void handlePlayerMessageAll(Player player, int value, boolean isSilent); + protected abstract void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent); private boolean validateArguments(CommandSender sender, String skillName, String value) { return !(CommandUtils.isInvalidInteger(sender, value) || (!skillName.equalsIgnoreCase("all") && CommandUtils.isInvalidSkill(sender, skillName))); @@ -151,21 +163,21 @@ public abstract class ExperienceCommand implements TabExecutor { } } - protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill, int value) { + protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill, int value, boolean isSilent) { if (skill == null) { for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) { handleCommand(player, profile, primarySkillType, value); } if (player != null) { - handlePlayerMessageAll(player, value); + handlePlayerMessageAll(player, value, isSilent); } } else { handleCommand(player, profile, skill, value); if (player != null) { - handlePlayerMessageSkill(player, value, skill); + handlePlayerMessageSkill(player, value, skill, isSilent); } } } diff --git a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java index 4e483dc6a..9aa02b164 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java @@ -40,12 +40,18 @@ public class MmoeditCommand extends ExperienceCommand { } @Override - protected void handlePlayerMessageAll(Player player, int value) { + protected void handlePlayerMessageAll(Player player, int value, boolean isSilent) { + if(isSilent) + return; + player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", value)); } @Override - protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill) { + protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent) { + if(isSilent) + return; + player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", skill.getName(), value)); } } diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java b/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java index c5056f02f..b01e34e4a 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java @@ -120,7 +120,7 @@ public final class CommandRegistrationManager { command.setDescription(LocaleLoader.getString("Commands.Description.addlevels")); command.setPermission("mcmmo.commands.addlevels;mcmmo.commands.addlevels.others"); command.setPermissionMessage(permissionsMessage); - command.setUsage(LocaleLoader.getString("Commands.Usage.3", "addlevels", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">")); + command.setUsage(LocaleLoader.getString("Commands.Usage.3.XP", "addlevels", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">")); command.setExecutor(new AddlevelsCommand()); } @@ -129,7 +129,7 @@ public final class CommandRegistrationManager { command.setDescription(LocaleLoader.getString("Commands.Description.addxp")); command.setPermission("mcmmo.commands.addxp;mcmmo.commands.addxp.others"); command.setPermissionMessage(permissionsMessage); - command.setUsage(LocaleLoader.getString("Commands.Usage.3", "addxp", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.XP") + ">")); + command.setUsage(LocaleLoader.getString("Commands.Usage.3.XP", "addxp", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.XP") + ">")); command.setExecutor(new AddxpCommand()); } @@ -183,7 +183,7 @@ public final class CommandRegistrationManager { command.setDescription(LocaleLoader.getString("Commands.Description.mmoedit")); command.setPermission("mcmmo.commands.mmoedit;mcmmo.commands.mmoedit.others"); command.setPermissionMessage(permissionsMessage); - command.setUsage(LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">")); + command.setUsage(LocaleLoader.getString("Commands.Usage.3.XP", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">")); command.setExecutor(new MmoeditCommand()); } diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index dcb7e95e3..a6387bc57 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -711,6 +711,7 @@ Commands.Usage.0=&cProper usage is /{0} Commands.Usage.1=&cProper usage is /{0} {1} Commands.Usage.2=&cProper usage is /{0} {1} {2} Commands.Usage.3=&cProper usage is /{0} {1} {2} {3} +Commands.Usage.3.XP=&cProper usage is /{0} {1} {2} {3}&7 (You can include -s at the end to execute the command without informing the player, effectively silencing it) Commands.Usage.FullClassName=classname Commands.Usage.Level=level Commands.Usage.Message=message