From b09f88e15770092ad4654123472774e77d25c838 Mon Sep 17 00:00:00 2001 From: Aria Date: Sat, 2 Nov 2019 19:23:31 +0100 Subject: [PATCH] !Added debug commands for dev./bug tracking --- .../mmocore/command/MMOCoreCommand.java | 2 + .../mmocore/command/rpg/debug/Debug.java | 7 +++ .../command/rpg/debug/DebugCommandMap.java | 18 ++++++++ .../rpg/debug/StatValueCommandMap.java | 44 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 src/main/java/net/Indyuce/mmocore/command/rpg/debug/Debug.java create mode 100644 src/main/java/net/Indyuce/mmocore/command/rpg/debug/DebugCommandMap.java create mode 100644 src/main/java/net/Indyuce/mmocore/command/rpg/debug/StatValueCommandMap.java diff --git a/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java b/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java index 25201187..c4864cda 100644 --- a/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java +++ b/src/main/java/net/Indyuce/mmocore/command/MMOCoreCommand.java @@ -15,6 +15,7 @@ import net.Indyuce.mmocore.command.rpg.NoteCommandMap; import net.Indyuce.mmocore.command.rpg.ReloadCommandMap; import net.Indyuce.mmocore.command.rpg.admin.AdminCommandMap; import net.Indyuce.mmocore.command.rpg.booster.BoosterCommandMap; +import net.Indyuce.mmocore.command.rpg.debug.DebugCommandMap; import net.Indyuce.mmocore.command.rpg.waypoint.WaypointsCommandMap; public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabCompleter { @@ -25,6 +26,7 @@ public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabC addFloor(new CoinsCommandMap(this)); addFloor(new NoteCommandMap(this)); addFloor(new AdminCommandMap(this)); + addFloor(new DebugCommandMap(this)); addFloor(new BoosterCommandMap(this)); addFloor(new WaypointsCommandMap(this)); } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/debug/Debug.java b/src/main/java/net/Indyuce/mmocore/command/rpg/debug/Debug.java new file mode 100644 index 00000000..b42fbc95 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/debug/Debug.java @@ -0,0 +1,7 @@ +package net.Indyuce.mmocore.command.rpg.debug; + +import org.bukkit.ChatColor; + +public class Debug { + public static final String cmdPrefix = ChatColor.YELLOW + "[" + ChatColor.RED + "DEBUG" + ChatColor.GOLD + "] " + ChatColor.RESET; +} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/debug/DebugCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/debug/DebugCommandMap.java new file mode 100644 index 00000000..9eea93df --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/debug/DebugCommandMap.java @@ -0,0 +1,18 @@ +package net.Indyuce.mmocore.command.rpg.debug; + +import org.bukkit.command.CommandSender; + +import net.Indyuce.mmocore.command.api.CommandMap; + +public class DebugCommandMap extends CommandMap { + public DebugCommandMap(CommandMap parent) { + super(parent, "debug"); + + addFloor(new StatValueCommandMap(this)); + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + return CommandResult.THROW_USAGE; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/debug/StatValueCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/debug/StatValueCommandMap.java new file mode 100644 index 00000000..921b613b --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/debug/StatValueCommandMap.java @@ -0,0 +1,44 @@ +package net.Indyuce.mmocore.command.rpg.debug; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.stats.StatType; +import net.Indyuce.mmocore.command.api.CommandEnd; +import net.Indyuce.mmocore.command.api.CommandMap; +import net.Indyuce.mmocore.command.api.Parameter; + +public class StatValueCommandMap extends CommandEnd { + public StatValueCommandMap(CommandMap parent) { + super(parent, "statvalue"); + + addParameter(new Parameter("", list -> { for(StatType stat : StatType.values()) list.add(stat.name()); })); + addParameter(new Parameter("(formatted)", list -> { list.add("true"); })); + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + if (args.length < 3 ) + return CommandResult.THROW_USAGE; + + if(!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command can only be used by a player."); + return CommandResult.FAILURE; + } + PlayerData data = PlayerData.get((Player) sender); + + StatType stat = StatType.valueOf(args[2]); + if (stat == null) { + sender.sendMessage(ChatColor.RED + "Could not find stat: " + args[2] + "."); + return CommandResult.FAILURE; + } + + if(args.length > 3 && args[3].equals("true")) + sender.sendMessage(Debug.cmdPrefix + "Stat Value (" + ChatColor.BLUE + stat.name() + ChatColor.WHITE + "): " + ChatColor.GREEN + stat.format(data.getStats().getStat(stat)) + ChatColor.WHITE + " *"); + else sender.sendMessage(Debug.cmdPrefix + "Stat Value (" + ChatColor.BLUE + stat.name() + ChatColor.WHITE + "): " + ChatColor.GREEN + data.getStats().getStat(stat)); + + return CommandResult.SUCCESS; + } +}