Fixed and improved BPM's messages and commands
This commit is contained in:
@@ -1,25 +1,40 @@
|
|||||||
command bpm {
|
command bpm {
|
||||||
alias set;
|
alias set;
|
||||||
alias toggle;
|
alias toggle;
|
||||||
|
alias mod;
|
||||||
|
|
||||||
perm blockplacemods.use;
|
perm blockplacemods.use;
|
||||||
|
|
||||||
type player;
|
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.;
|
help Lists the block place mods and their statuses.;
|
||||||
run list_mods;
|
run list_mods;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset [string:mod] {
|
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;
|
run reset_mod mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
[string:mod] {
|
toggle [string:mod] {
|
||||||
help Toggles a block place mod.;
|
help Toggles a block place mod.;
|
||||||
run toggle_mod 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] {
|
[string:mod] [string:value] {
|
||||||
help Sets the specified mod's state to the specified value. Only works for mods that have a state.;
|
help Sets the specified mod's state to the specified value. Only works for mods that have a state.;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.nemez.cmdmgr.Command;
|
|||||||
import com.redstoner.annotations.AutoRegisterListener;
|
import com.redstoner.annotations.AutoRegisterListener;
|
||||||
import com.redstoner.annotations.Commands;
|
import com.redstoner.annotations.Commands;
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
|
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||||
import com.redstoner.misc.CommandHolderType;
|
import com.redstoner.misc.CommandHolderType;
|
||||||
import com.redstoner.misc.Main;
|
import com.redstoner.misc.Main;
|
||||||
import com.redstoner.modules.Module;
|
import com.redstoner.modules.Module;
|
||||||
@@ -13,7 +14,6 @@ import com.redstoner.modules.blockplacemods.mods.ModSlab;
|
|||||||
import com.redstoner.modules.datamanager.DataManager;
|
import com.redstoner.modules.datamanager.DataManager;
|
||||||
import net.nemez.chatapi.click.Message;
|
import net.nemez.chatapi.click.Message;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -52,7 +52,7 @@ public class BlockPlaceMods implements Module, Listener {
|
|||||||
enabledMods.add(mod);
|
enabledMods.add(mod);
|
||||||
Bukkit.getPluginManager().registerEvents(mod, Main.plugin);
|
Bukkit.getPluginManager().registerEvents(mod, Main.plugin);
|
||||||
} else {
|
} 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();
|
enabledMods.clear();
|
||||||
mods.clear();
|
mods.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("incomplete-switch")
|
|
||||||
@Command (async = Command.AsyncType.ALWAYS, hook = "list_mods")
|
@Command (async = Command.AsyncType.ALWAYS, hook = "list_mods")
|
||||||
public void listMods(CommandSender sender) {
|
public void listMods(CommandSender sender) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
@@ -78,198 +77,137 @@ public class BlockPlaceMods implements Module, Listener {
|
|||||||
|
|
||||||
Message msg = new Message(sender, sender);
|
Message msg = new Message(sender, sender);
|
||||||
|
|
||||||
msg.appendText(ChatColor.DARK_GREEN + "--==[BlockPlaceMods]==--\n");
|
msg.appendText(getLogger().getHeader() + "\n");
|
||||||
msg.appendText(ChatColor.GRAY + "TIP: Hover over the following messages to see a description :)\n\n");
|
|
||||||
|
|
||||||
|
int curMod = 1;
|
||||||
for (BlockPlaceMod mod : modsToRegister) {
|
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);
|
boolean enabled = (boolean) DataManager.getOrDefault(uuid, "BlockPlaceMods", mod.name, mod.enabledByDefault);
|
||||||
|
boolean loaded = enabledMods.contains(mod);
|
||||||
msg.appendTextHover(
|
|
||||||
enabledMods.contains(mod) ? ChatColor.GREEN + "Loaded" : ChatColor.DARK_RED + "Not loaded",
|
String text = (enabled? "&a" : "&c") + (loaded? "" : "&m") + mod.name;
|
||||||
ChatColor.GRAY + (enabledMods.contains(mod) ? "The mod is working fine." : "Something is wrong!")
|
String hover = (enabled? "&aEnabled" : "&cDisabled") + (loaded? "" : "\n&c&oThis mod is not loaded, report to staff!");
|
||||||
);
|
|
||||||
|
|
||||||
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!")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (mod.type != ModType.STATELESS) {
|
if (mod.type != ModType.STATELESS) {
|
||||||
Object state = DataManager.getOrDefault(uuid, "BlockPlaceMods", mod.name + "_state", null);
|
Object state = DataManager.getOrDefault(uuid, "BlockPlaceMods", mod.name + "_state", null);
|
||||||
|
if (state != null)
|
||||||
if (state != null) {
|
hover += ("\n\n&7Value: &e" + state.toString() + "\n&7Type: &e" + mod.type.asString() + " \n&7Meaning: " + mod.typeDescription);
|
||||||
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!")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.appendText("\n\n&2Hover over a mod for details.")
|
||||||
msg.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command (async = Command.AsyncType.ALWAYS, hook = "reset_mod")
|
@Command (async = Command.AsyncType.ALWAYS, hook = "reset_mod")
|
||||||
public void resetMod(CommandSender sender, String mod) {
|
public void resetMod(CommandSender sender, String mod) {
|
||||||
BlockPlaceMod bpm = mods.get(mod.toLowerCase());
|
BlockPlaceMod bpm = mods.get(mod.toLowerCase());
|
||||||
Message msg = new Message(sender, sender);
|
|
||||||
|
|
||||||
msg.appendText(ChatColor.DARK_GREEN + "[BlockPlaceMods] ");
|
|
||||||
|
|
||||||
if (bpm == null) {
|
if (bpm == null) {
|
||||||
msg.appendText(ChatColor.DARK_RED + "That mod does not exist!");
|
getLogger().message(sender, true, "The mod, &e" + mod + "&7, does not exist!");
|
||||||
} else {
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
@Command (async = Command.AsyncType.ALWAYS, hook = "toggle_mod")
|
||||||
public void toggleMod(CommandSender sender, String mod) {
|
public void toggleMod(CommandSender sender, String mod) {
|
||||||
BlockPlaceMod bpm = mods.get(mod.toLowerCase());
|
BlockPlaceMod bpm = mods.get(mod.toLowerCase());
|
||||||
Message msg = new Message(sender, sender);
|
|
||||||
|
|
||||||
msg.appendText(ChatColor.DARK_GREEN + "[BlockPlaceMods] ");
|
|
||||||
|
|
||||||
if (bpm == null) {
|
if (bpm == null) {
|
||||||
msg.appendText(ChatColor.DARK_RED + "That mod does not exist!");
|
getLogger().message(sender, true, "The mod, &e" + mod + "&7, does not exist!");
|
||||||
} else {
|
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.appendText(
|
|
||||||
ChatColor.GREEN + "The " + ChatColor.DARK_PURPLE + bpm.name
|
|
||||||
+ ChatColor.GREEN + " mod has been "
|
|
||||||
+ (current ? ChatColor.RED + "Disabled!" : ChatColor.GREEN + "Enabled!")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String uuid = player.getUniqueId().toString();
|
||||||
|
|
||||||
msg.send();
|
boolean current = (boolean) DataManager.getOrDefault(uuid, "BlockPlaceMods", bpm.name, bpm.enabledByDefault);
|
||||||
|
DataManager.setData(uuid, "BlockPlaceMods", bpm.name, !current);
|
||||||
|
|
||||||
|
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")
|
@Command (async = Command.AsyncType.ALWAYS, hook = "set_mod_value")
|
||||||
public void setModValue(CommandSender sender, String mod, String value) {
|
public void setModValue(CommandSender sender, String mod, String value) {
|
||||||
BlockPlaceMod bpm = mods.get(mod.toLowerCase());
|
BlockPlaceMod bpm = mods.get(mod.toLowerCase());
|
||||||
Message msg = new Message(sender, sender);
|
|
||||||
|
|
||||||
msg.appendText(ChatColor.DARK_GREEN + "[BlockPlaceMods] ");
|
|
||||||
|
|
||||||
if (bpm == null) {
|
if (bpm == null) {
|
||||||
msg.appendText(ChatColor.DARK_RED + "That mod does not exist!");
|
getLogger().message(sender, true, "The mod, &e" + mod + "&7, does not exist!");
|
||||||
} else {
|
return;
|
||||||
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);
|
|
||||||
|
|
||||||
if (val < 0) {
|
|
||||||
msg.appendText(ChatColor.RED + "The specified value must be a positive integer!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataManager.setData(uuid, "BlockPlaceMods", bpm.name + "_state", val);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
msg.appendText(ChatColor.RED + "The specified value must be a positive integer!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.appendText(
|
|
||||||
ChatColor.GREEN + "Changed the value of "
|
|
||||||
+ ChatColor.DARK_PURPLE + bpm.name + ChatColor.GREEN
|
|
||||||
+ " to: " + ChatColor.GRAY + value
|
|
||||||
);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String uuid = player.getUniqueId().toString();
|
||||||
|
|
||||||
msg.send();
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (val < 1 || val > 15) {
|
||||||
|
getLogger().message(sender, true, "The specified value must be an integer between 1 and 15!");
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
package com.redstoner.modules.blockplacemods;
|
package com.redstoner.modules.blockplacemods;
|
||||||
|
|
||||||
public enum ModType {
|
public enum ModType {
|
||||||
STATELESS,
|
STATELESS("Stateless"),
|
||||||
INTEGER,
|
INTEGER("Integer"),
|
||||||
UNSIGNED_INTEGER,
|
UNSIGNED_INTEGER("Positive Integer"),
|
||||||
STRING,
|
STRING("String"),
|
||||||
REDSTONE_LEVEL
|
REDSTONE_LEVEL("Redstone Level");
|
||||||
|
|
||||||
|
private String asString;
|
||||||
|
|
||||||
|
private ModType(String asString) {
|
||||||
|
this.asString = asString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asString() {
|
||||||
|
return asString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user