diff --git a/src/main/java/com/dfsek/terra/command/ReloadCommand.java b/src/main/java/com/dfsek/terra/command/ReloadCommand.java index 8093ff0ef..42ba71ef5 100644 --- a/src/main/java/com/dfsek/terra/command/ReloadCommand.java +++ b/src/main/java/com/dfsek/terra/command/ReloadCommand.java @@ -2,6 +2,7 @@ package com.dfsek.terra.command; import com.dfsek.terra.Terra; import com.dfsek.terra.command.type.Command; +import com.dfsek.terra.command.type.DebugCommand; import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.command.CommandSender; @@ -10,7 +11,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; -public class ReloadCommand extends Command { +public class ReloadCommand extends Command implements DebugCommand { @Override public String getName() { return "reload"; diff --git a/src/main/java/com/dfsek/terra/command/geometry/GeometryCommand.java b/src/main/java/com/dfsek/terra/command/geometry/GeometryCommand.java index edebf1689..4674cb10b 100644 --- a/src/main/java/com/dfsek/terra/command/geometry/GeometryCommand.java +++ b/src/main/java/com/dfsek/terra/command/geometry/GeometryCommand.java @@ -1,5 +1,6 @@ package com.dfsek.terra.command.geometry; +import com.dfsek.terra.command.type.DebugCommand; import com.dfsek.terra.command.type.PlayerCommand; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.command.Command; @@ -11,7 +12,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -public class GeometryCommand extends PlayerCommand { +public class GeometryCommand extends PlayerCommand implements DebugCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { LangUtil.send("command.geometry.main-menu", sender); diff --git a/src/main/java/com/dfsek/terra/command/image/gui/GUICommand.java b/src/main/java/com/dfsek/terra/command/image/gui/GUICommand.java index cf8e38c80..dcf7a6deb 100644 --- a/src/main/java/com/dfsek/terra/command/image/gui/GUICommand.java +++ b/src/main/java/com/dfsek/terra/command/image/gui/GUICommand.java @@ -1,5 +1,6 @@ package com.dfsek.terra.command.image.gui; +import com.dfsek.terra.command.type.DebugCommand; import com.dfsek.terra.command.type.WorldCommand; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.World; @@ -12,7 +13,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -public class GUICommand extends WorldCommand { +public class GUICommand extends WorldCommand implements DebugCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { LangUtil.send("command.image.gui.main-menu", sender); diff --git a/src/main/java/com/dfsek/terra/command/structure/LoadCommand.java b/src/main/java/com/dfsek/terra/command/structure/LoadCommand.java index 1a62cc59f..080352496 100644 --- a/src/main/java/com/dfsek/terra/command/structure/LoadCommand.java +++ b/src/main/java/com/dfsek/terra/command/structure/LoadCommand.java @@ -1,6 +1,7 @@ package com.dfsek.terra.command.structure; import com.dfsek.terra.Terra; +import com.dfsek.terra.command.type.DebugCommand; import com.dfsek.terra.command.type.PlayerCommand; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.structure.GaeaStructure; @@ -14,7 +15,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -public class LoadCommand extends PlayerCommand { +public class LoadCommand extends PlayerCommand implements DebugCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { try { diff --git a/src/main/java/com/dfsek/terra/command/type/Command.java b/src/main/java/com/dfsek/terra/command/type/Command.java index 299a2ea23..055de3139 100644 --- a/src/main/java/com/dfsek/terra/command/type/Command.java +++ b/src/main/java/com/dfsek/terra/command/type/Command.java @@ -1,6 +1,7 @@ package com.dfsek.terra.command.type; import com.dfsek.terra.Debug; +import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -63,9 +64,15 @@ public abstract class Command implements CommandExecutor, TabCompleter { */ @Override public final boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) { + if(this instanceof DebugCommand && ! ConfigUtil.debug) { + LangUtil.send("command.debug-only", sender); + return true; + } if(args.length > 0) { for(Command c : getSubCommands()) { - if(c.getName().equals(args[0])) return c.onCommand(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new)); + if(c.getName().equals(args[0])) { + return c.onCommand(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new)); + } } if(args.length != arguments()) { LangUtil.send("command.invalid", sender, String.valueOf(arguments()), String.valueOf(args.length)); diff --git a/src/main/java/com/dfsek/terra/command/type/DebugCommand.java b/src/main/java/com/dfsek/terra/command/type/DebugCommand.java new file mode 100644 index 000000000..e4d1c0f38 --- /dev/null +++ b/src/main/java/com/dfsek/terra/command/type/DebugCommand.java @@ -0,0 +1,8 @@ +package com.dfsek.terra.command.type; + +/** + * Implementing this interface marks a command as debug-only. + * If a parent command implements this interface, all child commands will be considered debug commands, regardless of whether they implement DebugCommand as well. + */ +public interface DebugCommand { +} diff --git a/src/main/resources/lang/en_us.yml b/src/main/resources/lang/en_us.yml index 45e5ba876..33269e3ee 100644 --- a/src/main/resources/lang/en_us.yml +++ b/src/main/resources/lang/en_us.yml @@ -5,6 +5,7 @@ enable: disable: - "Thank you for using Terra!" command: + debug-only: "This command must be used with debug mode enabled!" player-only: "This command is for players only!" terra-world: "This command must be executed in a Terra world!" invalid: "Invalid command. (Expected %1$s arguments, found %2$s)."