Make some commands debug only, update Mesa biome

This commit is contained in:
dfsek 2020-10-08 03:03:20 -07:00
parent fd82d645a1
commit 3ca1c5980c
7 changed files with 25 additions and 5 deletions

View File

@ -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";

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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));

View File

@ -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 {
}

View File

@ -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)."