From 25c330e4ef4328a86208e84dd9c09aa4b1041d65 Mon Sep 17 00:00:00 2001 From: Minenash Date: Thu, 3 Jan 2019 22:48:03 -0500 Subject: Fixed and improved BPM's messages and commands --- .../modules/blockplacemods/BlockPlaceMods.cmd | 25 +- .../modules/blockplacemods/BlockPlaceMods.java | 254 ++++++++------------- .../redstoner/modules/blockplacemods/ModType.java | 20 +- 3 files changed, 131 insertions(+), 168 deletions(-) (limited to 'src') diff --git a/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.cmd b/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.cmd index f025d26..5e1206c 100644 --- a/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.cmd +++ b/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.cmd @@ -1,25 +1,40 @@ command bpm { alias set; alias toggle; + alias mod; perm blockplacemods.use; - type player; - [empty] { + [empty] { + help Lists the block place mods and their statuses.; + run list_mods; + } + + list [empty] { help Lists the block place mods and their statuses.; run list_mods; } reset [string:mod] { - Help Resets the specified mod's settings to the default value.; + help Resets the specified mod's settings to the default value.; run reset_mod mod; } - - [string:mod] { + + toggle [string:mod] { help Toggles a block place mod.; run toggle_mod mod; } + + set [string:mod] [string:value] { + help Sets the specified mod's state to the specified value. Only works for mods that have a state.; + run set_mod_value mod value; + } + + [string:mod] { + help Toggles a block place mod.; + run toggle_mod_no_prefix mod; + } [string:mod] [string:value] { help Sets the specified mod's state to the specified value. Only works for mods that have a state.; diff --git a/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java b/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java index 4343d8f..1306235 100644 --- a/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java +++ b/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java @@ -4,6 +4,7 @@ import com.nemez.cmdmgr.Command; import com.redstoner.annotations.AutoRegisterListener; import com.redstoner.annotations.Commands; import com.redstoner.annotations.Version; +import com.redstoner.coremods.moduleLoader.ModuleLoader; import com.redstoner.misc.CommandHolderType; import com.redstoner.misc.Main; import com.redstoner.modules.Module; @@ -13,7 +14,6 @@ import com.redstoner.modules.blockplacemods.mods.ModSlab; import com.redstoner.modules.datamanager.DataManager; import net.nemez.chatapi.click.Message; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -52,7 +52,7 @@ public class BlockPlaceMods implements Module, Listener { enabledMods.add(mod); Bukkit.getPluginManager().registerEvents(mod, Main.plugin); } else { - getLogger().warn("Block place mod failed to enable, see any errors above!"); + getLogger().warn("Failed to enable the mod, &e" + mod.name + "&7!"); } } @@ -69,8 +69,7 @@ public class BlockPlaceMods implements Module, Listener { enabledMods.clear(); mods.clear(); } - - @SuppressWarnings("incomplete-switch") + @Command (async = Command.AsyncType.ALWAYS, hook = "list_mods") public void listMods(CommandSender sender) { Player player = (Player) sender; @@ -78,198 +77,137 @@ public class BlockPlaceMods implements Module, Listener { Message msg = new Message(sender, sender); - msg.appendText(ChatColor.DARK_GREEN + "--==[BlockPlaceMods]==--\n"); - msg.appendText(ChatColor.GRAY + "TIP: Hover over the following messages to see a description :)\n\n"); + msg.appendText(getLogger().getHeader() + "\n"); + int curMod = 1; for (BlockPlaceMod mod : modsToRegister) { - - msg.appendTextHover( - ChatColor.DARK_PURPLE + "[" - + ChatColor.DARK_BLUE + mod.name - + ChatColor.DARK_PURPLE + "]", - - ChatColor.GREEN + mod.description - ); - - msg.appendText(" "); - + boolean enabled = (boolean) DataManager.getOrDefault(uuid, "BlockPlaceMods", mod.name, mod.enabledByDefault); - - msg.appendTextHover( - enabledMods.contains(mod) ? ChatColor.GREEN + "Loaded" : ChatColor.DARK_RED + "Not loaded", - ChatColor.GRAY + (enabledMods.contains(mod) ? "The mod is working fine." : "Something is wrong!") - ); - - msg.appendText(ChatColor.RESET + ", "); - msg.appendTextHover( - enabled ? ChatColor.GREEN + "Enabled" : ChatColor.DARK_RED + "Disabled", - ChatColor.GRAY + (enabled ? "You have this mod enabled." : "You have disabled this mod!") - ); - + boolean loaded = enabledMods.contains(mod); + + String text = (enabled? "&a" : "&c") + (loaded? "" : "&m") + mod.name; + String hover = (enabled? "&aEnabled" : "&cDisabled") + (loaded? "" : "\n&c&oThis mod is not loaded, report to staff!"); + if (mod.type != ModType.STATELESS) { Object state = DataManager.getOrDefault(uuid, "BlockPlaceMods", mod.name + "_state", null); - - if (state != null) { - msg.appendText(ChatColor.AQUA + " -> "); - - switch (mod.type) { - case STRING: - msg.appendTextHover(ChatColor.GOLD + state.toString(), "String value - " + mod.typeDescription); - break; - case INTEGER: - case UNSIGNED_INTEGER: - msg.appendTextHover(ChatColor.DARK_GREEN + state.toString(), "Integer value - " + mod.typeDescription); - break; - case REDSTONE_LEVEL: - msg.appendTextHover(ChatColor.RED + state.toString(), "Redstone level - " + mod.typeDescription); - } - - msg.appendTextHover( - enabled ? ChatColor.GREEN + "Enabled" : ChatColor.DARK_RED + "Disabled", - ChatColor.GRAY + (enabled ? "You have this mod enabled." : "You have disabled this mod!") - ); - } + if (state != null) + hover += ("\n\n&7Value: &e" + state.toString() + "\n&7Type: &e" + mod.type.asString() + " \n&7Meaning: " + mod.typeDescription); } + + hover += "\n\n&7" + mod.description + "\n&e&oClick to " + (enabled? "&c&oDisable" : "&a&oEnable"); + msg.appendSendChatHover(text, "/bpm " + mod.name, hover); + + if (curMod != modsToRegister.length) + msg.appendText("&7, "); + curMod++; } - - msg.send(); + msg.appendText("\n\n&2Hover over a mod for details.") + .send(); } @Command (async = Command.AsyncType.ALWAYS, hook = "reset_mod") public void resetMod(CommandSender sender, String mod) { BlockPlaceMod bpm = mods.get(mod.toLowerCase()); - Message msg = new Message(sender, sender); - - msg.appendText(ChatColor.DARK_GREEN + "[BlockPlaceMods] "); if (bpm == null) { - msg.appendText(ChatColor.DARK_RED + "That mod does not exist!"); - } else { - Player player = (Player) sender; - DataManager.removeData(player.getUniqueId().toString(), "BlockPlaceMods", bpm.name); - DataManager.removeData(player.getUniqueId().toString(), "BlockPlaceMods", bpm.name + "_state"); - - msg.appendText(ChatColor.GREEN + "Successfully reset the settings for: " + ChatColor.DARK_PURPLE + bpm.name); + getLogger().message(sender, true, "The mod, &e" + mod + "&7, does not exist!"); + return; } + + Player player = (Player) sender; + DataManager.removeData(player.getUniqueId().toString(), "BlockPlaceMods", bpm.name); + DataManager.removeData(player.getUniqueId().toString(), "BlockPlaceMods", bpm.name + "_state"); - msg.send(); + getLogger().message(sender, "The &3" + bpm.name + "&7 mod has been reset back to it's original settings."); } - + + @Command (async = Command.AsyncType.ALWAYS, hook = "toggle_mod_no_prefix") + public void toggleModNoPrefix(CommandSender sender, String mod) { + if (mod.equals("help")) + try { + Bukkit.getScheduler().callSyncMethod(ModuleLoader.getPlugin(), () -> Bukkit.dispatchCommand(sender, "bpm help 1")).get(); + } catch (Exception e) { + getLogger().message(sender, true, "&4An error accorded trying to show you the help! Please inform a staff member!"); + e.printStackTrace(); + } + else + toggleMod(sender, mod); + } + @Command (async = Command.AsyncType.ALWAYS, hook = "toggle_mod") public void toggleMod(CommandSender sender, String mod) { BlockPlaceMod bpm = mods.get(mod.toLowerCase()); - Message msg = new Message(sender, sender); - - msg.appendText(ChatColor.DARK_GREEN + "[BlockPlaceMods] "); if (bpm == null) { - msg.appendText(ChatColor.DARK_RED + "That mod does not exist!"); - } else { - Player player = (Player) sender; - String uuid = player.getUniqueId().toString(); - - boolean current = (boolean) DataManager.getOrDefault(uuid, "BlockPlaceMods", bpm.name, bpm.enabledByDefault); - DataManager.setData(uuid, "BlockPlaceMods", bpm.name, !current); - - msg.appendText( - ChatColor.GREEN + "The " + ChatColor.DARK_PURPLE + bpm.name - + ChatColor.GREEN + " mod has been " - + (current ? ChatColor.RED + "Disabled!" : ChatColor.GREEN + "Enabled!") - ); + getLogger().message(sender, true, "The mod, &e" + mod + "&7, does not exist!"); + return; } + + Player player = (Player) sender; + String uuid = player.getUniqueId().toString(); + + boolean current = (boolean) DataManager.getOrDefault(uuid, "BlockPlaceMods", bpm.name, bpm.enabledByDefault); + DataManager.setData(uuid, "BlockPlaceMods", bpm.name, !current); - msg.send(); + getLogger().message(sender, "The &3" + bpm.name + "&7 mod has been " + (current ? "&cDisabled&7!" : "&aEnabled&7!")); } @Command (async = Command.AsyncType.ALWAYS, hook = "set_mod_value") public void setModValue(CommandSender sender, String mod, String value) { BlockPlaceMod bpm = mods.get(mod.toLowerCase()); - Message msg = new Message(sender, sender); - - msg.appendText(ChatColor.DARK_GREEN + "[BlockPlaceMods] "); if (bpm == null) { - msg.appendText(ChatColor.DARK_RED + "That mod does not exist!"); - } else { - Player player = (Player) sender; - String uuid = player.getUniqueId().toString(); - - switch (bpm.type) { - case STATELESS: - msg.appendText(ChatColor.DARK_RED + "You cannot change the value of a stateless mod!"); - break; - case STRING: - DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", value); - - msg.appendText( - ChatColor.GREEN + "Changed the value of " - + ChatColor.DARK_PURPLE + bpm.name + ChatColor.GREEN - + " to: " + ChatColor.GRAY + value - ); - - break; - case INTEGER: - try { - DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", Integer.parseInt(value)); - } catch (NumberFormatException e) { - msg.appendText(ChatColor.RED + "The specified value must be an integer!"); - break; - } - - msg.appendText( - ChatColor.GREEN + "Changed the value of " - + ChatColor.DARK_PURPLE + bpm.name + ChatColor.GREEN - + " to: " + ChatColor.GRAY + value - ); - - break; - case UNSIGNED_INTEGER: - try { - int val = Integer.parseInt(value); + getLogger().message(sender, true, "The mod, &e" + mod + "&7, does not exist!"); + return; + } + + Player player = (Player) sender; + String uuid = player.getUniqueId().toString(); - if (val < 0) { - msg.appendText(ChatColor.RED + "The specified value must be a positive integer!"); - break; - } + switch (bpm.type) { + case STATELESS: + getLogger().message(sender, true, "You cannot change the value of a stateless mod!"); + break; + case STRING: + DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", value); + getLogger().message(sender, "Changed the value of &3" + bpm.name + "&7 to &e" + value); + break; + case INTEGER: + try { + DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", Integer.parseInt(value)); + getLogger().message(sender, "Changed the value of &3" + bpm.name + "&7 to &e" + value); + } catch (NumberFormatException e) { + getLogger().message(sender, true, "The specified value must be an integer!"); + } + break; + case UNSIGNED_INTEGER: + try { + int val = Integer.parseInt(value); - DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", val); - } catch (NumberFormatException e) { - msg.appendText(ChatColor.RED + "The specified value must be a positive integer!"); + if (val < 0) { + getLogger().message(sender, true, "The specified value must be zero or a positive integer!"); break; } + DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", val); + getLogger().message(sender, "Changed the value of &3" + bpm.name + "&7 to &e" + value); + } catch (NumberFormatException e) { + getLogger().message(sender, true, "The specified value must be zero or a positive integer!"); + } + break; + case REDSTONE_LEVEL: + try { + int val = Integer.parseInt(value); - msg.appendText( - ChatColor.GREEN + "Changed the value of " - + ChatColor.DARK_PURPLE + bpm.name + ChatColor.GREEN - + " to: " + ChatColor.GRAY + value - ); - - break; - case REDSTONE_LEVEL: - try { - int val = Integer.parseInt(value); - - if (val < 1 || val > 15) { - msg.appendText(ChatColor.RED + "The specified value must be an integer between 0 (exclusive) and 15 (inclusive)!"); - break; - } - - DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", val); - } catch (NumberFormatException e) { - msg.appendText(ChatColor.RED + "The specified value must be an integer between 0 (exclusive) and 15 (inclusive)!"); + if (val < 1 || val > 15) { + getLogger().message(sender, true, "The specified value must be an integer between 1 and 15!"); break; } - - msg.appendText( - ChatColor.GREEN + "Changed the value of " - + ChatColor.DARK_PURPLE + bpm.name + ChatColor.GREEN - + " to: " + ChatColor.GRAY + value - ); - - break; - } + DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", val); + getLogger().message(sender, "Changed the value of &3" + bpm.name + "&7 to &e" + value); + } catch (NumberFormatException e) { + getLogger().message(sender, true, "The specified value must be an integer between 1 and 15!"); + } + break; } - - msg.send(); } } diff --git a/src/main/java/com/redstoner/modules/blockplacemods/ModType.java b/src/main/java/com/redstoner/modules/blockplacemods/ModType.java index 6ef4634..d7511d2 100644 --- a/src/main/java/com/redstoner/modules/blockplacemods/ModType.java +++ b/src/main/java/com/redstoner/modules/blockplacemods/ModType.java @@ -1,9 +1,19 @@ package com.redstoner.modules.blockplacemods; public enum ModType { - STATELESS, - INTEGER, - UNSIGNED_INTEGER, - STRING, - REDSTONE_LEVEL + STATELESS("Stateless"), + INTEGER("Integer"), + UNSIGNED_INTEGER("Positive Integer"), + STRING("String"), + REDSTONE_LEVEL("Redstone Level"); + + private String asString; + + private ModType(String asString) { + this.asString = asString; + } + + public String asString() { + return asString; + } } -- cgit v1.2.3