diff --git a/build.gradle.kts b/build.gradle.kts index b64e879..9255497 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,7 +66,7 @@ dependencies { compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.4.4") { isTransitive = false } compileOnly("com.bergerkiller.bukkit:LightCleaner:1.15.2-v1") compileOnly("com.bergerkiller.bukkit:BKCommonLib:1.15.2-v2") - compileOnly("dev.jorel.CommandAPI:commandapi-core:8.7.0") + compileOnly("dev.jorel:commandapi-bukkit-core:9.4.1") compileOnly("com.google.code.gson:gson:2.8.5") compileOnly("com.playmonumenta:scripted-quests:7.0") diff --git a/src/main/java/com/playmonumenta/structures/commands/ActivateSpecialStructure.java b/src/main/java/com/playmonumenta/structures/commands/ActivateSpecialStructure.java index 2aba237..a442427 100644 --- a/src/main/java/com/playmonumenta/structures/commands/ActivateSpecialStructure.java +++ b/src/main/java/com/playmonumenta/structures/commands/ActivateSpecialStructure.java @@ -5,9 +5,12 @@ import com.playmonumenta.structures.utils.MessagingUtils; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.arguments.TextArgument; import javax.annotation.Nullable; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; @@ -17,38 +20,27 @@ public static void register(Plugin plugin) { final String command = "activatespecialstructure"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .executes((sender, args) -> { - activate(sender, plugin, (String)args[0], null); - }) - .register(); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + TextArgument pathArg = new TextArgument("special_structure_path"); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .withArguments(new TextArgument("special_structure_path")) + .withArguments(labelArg) + .withArguments(pathArg) .executes((sender, args) -> { - activate(sender, plugin, (String)args[0], (String)args[1]); + activate(sender, plugin, args.getByArgument(labelArg), args.getByArgument(pathArg)); }) .register(); } - private static void activate(CommandSender sender, Plugin plugin, String label, @Nullable String path) { + private static void activate(CommandSender sender, Plugin plugin, String label, String path) { try { CommandUtils.getAndValidateSchematicPath(plugin, path, true); RespawnManager.getInstance().activateSpecialStructure(label, path); + sender.sendMessage("Successfully activated special structure"); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to activate special structure: " + e.getMessage()); + sender.sendMessage(Component.text("Got error while attempting to activate special structure: " + e.getMessage(), NamedTextColor.RED)); MessagingUtils.sendStackTrace(sender, e); - return; - } - - if (path != null) { - sender.sendMessage("Successfully activated special structure"); - } else { - sender.sendMessage("Successfully deactivated special structure"); } } } diff --git a/src/main/java/com/playmonumenta/structures/commands/AddRespawningStructure.java b/src/main/java/com/playmonumenta/structures/commands/AddRespawningStructure.java index 475f5e8..43cad3b 100644 --- a/src/main/java/com/playmonumenta/structures/commands/AddRespawningStructure.java +++ b/src/main/java/com/playmonumenta/structures/commands/AddRespawningStructure.java @@ -9,6 +9,8 @@ import dev.jorel.commandapi.arguments.LocationArgument; import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.arguments.TextArgument; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -19,16 +21,23 @@ public static void register(Plugin plugin) { final String command = "addrespawningstructure"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); + StringArgument labelArg = new StringArgument("label"); + TextArgument pathArg = new TextArgument("path"); // TODO: Path arguments autocomplete? + LocationArgument locationArg = new LocationArgument("location"); + IntegerArgument radiusArg = new IntegerArgument("extraRadius", 0); + IntegerArgument respawnTimeArg = new IntegerArgument("respawnTime", 20); + TextArgument nameArg = new TextArgument("name"); + new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label")) - .withArguments(new TextArgument("path")) // TODO: Path arguments autocomplete? - .withArguments(new LocationArgument("location")) - .withArguments(new IntegerArgument("extraRadius", 0)) - .withArguments(new IntegerArgument("respawnTime", 20)) - .withArguments(new TextArgument("name")) + .withArguments(labelArg) + .withArguments(pathArg) + .withArguments(locationArg) + .withArguments(radiusArg) + .withArguments(respawnTimeArg) + .withArguments(nameArg) .executes((sender, args) -> { - add(sender, plugin, (String)args[0], (String)args[1], (Location)args[2], (Integer)args[3], (Integer)args[4], (String)args[5]); + add(sender, plugin, args.getByArgument(labelArg), args.getByArgument(pathArg), args.getByArgument(locationArg), args.getByArgument(radiusArg), args.getByArgument(respawnTimeArg), args.getByArgument(nameArg)); }) .register(); } @@ -44,7 +53,7 @@ public static void add(CommandSender sender, Plugin plugin, String label, String RespawnManager.getInstance().addStructure(extraRadius, label, name, path, loc.toVector(), respawnTime).whenComplete((unused, ex) -> { if (ex != null) { - sender.sendMessage(ChatColor.RED + "Failed to add structure: " + ex.getMessage()); + sender.sendMessage(Component.text("Failed to add structure: " + ex.getMessage(), NamedTextColor.RED)); } else { sender.sendMessage("Structure added successfully"); } diff --git a/src/main/java/com/playmonumenta/structures/commands/CompassRespawn.java b/src/main/java/com/playmonumenta/structures/commands/CompassRespawn.java index fcf8df6..3845544 100644 --- a/src/main/java/com/playmonumenta/structures/commands/CompassRespawn.java +++ b/src/main/java/com/playmonumenta/structures/commands/CompassRespawn.java @@ -3,7 +3,10 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.StringArgument; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,23 +16,24 @@ public static void register() { final String command = "compassrespawn"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures.compassrespawn"); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) + .withArguments(labelArg) .executes((sender, args) -> { - if (sender instanceof Player) { - forceRespawn(sender, (String)args[0]); + if (sender instanceof Player player) { + forceRespawn(player, args.getByArgument(labelArg)); } }) .register(); } - private static void forceRespawn(CommandSender sender, String label) { + private static void forceRespawn(Player player, String label) { try { - Player player = (Player) sender; RespawnManager.getInstance().compassRespawn(player, label); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to force respawn on structure: " + e.getMessage()); + player.sendMessage(Component.text("Got error while attempting to force respawn on structure: " + e.getMessage(), NamedTextColor.RED)); } } } diff --git a/src/main/java/com/playmonumenta/structures/commands/ForceConquerRespawn.java b/src/main/java/com/playmonumenta/structures/commands/ForceConquerRespawn.java index 2abb9e6..c47006b 100644 --- a/src/main/java/com/playmonumenta/structures/commands/ForceConquerRespawn.java +++ b/src/main/java/com/playmonumenta/structures/commands/ForceConquerRespawn.java @@ -3,7 +3,8 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.StringArgument; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -13,20 +14,23 @@ public static void register() { final String command = "forceconquerrespawn"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures.forceconquerrespawn"); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + EntitySelectorArgument.OnePlayer playerArg = new EntitySelectorArgument.OnePlayer("player"); + new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) + .withArguments(labelArg) .executesPlayer((sender, args) -> { - forceRespawn(sender, (String)args[0]); + forceRespawn(sender, args.getByArgument(labelArg)); }) .register(); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .withArguments(new PlayerArgument("player")) + .withArguments(labelArg) + .withArguments(playerArg) .executes((sender, args) -> { - forceRespawn((Player) args[1], (String)args[0]); + forceRespawn(args.getByArgument(playerArg), args.getByArgument(labelArg)); }) .register(); } diff --git a/src/main/java/com/playmonumenta/structures/commands/ForceloadLazy.java b/src/main/java/com/playmonumenta/structures/commands/ForceloadLazy.java index ea8f8ac..8da4345 100644 --- a/src/main/java/com/playmonumenta/structures/commands/ForceloadLazy.java +++ b/src/main/java/com/playmonumenta/structures/commands/ForceloadLazy.java @@ -21,26 +21,31 @@ public class ForceloadLazy { public static void register() { + Location2DArgument fromArg = new Location2DArgument("from", LocationType.BLOCK_POSITION); + Location2DArgument toArg = new Location2DArgument("to", LocationType.BLOCK_POSITION); + FunctionArgument callbackArg = new FunctionArgument("callback"); + new CommandTree("forceload") .then(new LiteralArgument("addlazy") .withPermission(CommandPermission.fromString("monumenta.structures.forceloadlazy")) // forceload addlazy from - .then(new Location2DArgument("from", LocationType.BLOCK_POSITION) + .then(fromArg .executes((sender, args) -> { - load(sender, (Location2D) args[0], (Location2D) args[0], null); // Intentionally both the same argument + Location2D from = args.getByArgument(fromArg); + load(sender, from, from, null); // Intentionally both the same argument }) // forceload addlazy from to - .then(new Location2DArgument("to", LocationType.BLOCK_POSITION) + .then(toArg .executes((sender, args) -> { - load(sender, (Location2D) args[0], (Location2D) args[1], null); + load(sender, args.getByArgument(fromArg), args.getByArgument(toArg), null); }) // forceload addlazy from to callback - .then(new FunctionArgument("callback") + .then(callbackArg .executes((sender, args) -> { - load(sender, (Location2D) args[0], (Location2D) args[1], (FunctionWrapper[]) args[2]); + load(sender, args.getByArgument(fromArg), args.getByArgument(toArg), args.getByArgument(callbackArg)); }))))) .register(); } diff --git a/src/main/java/com/playmonumenta/structures/commands/ListRespawningStructures.java b/src/main/java/com/playmonumenta/structures/commands/ListRespawningStructures.java index 62d4fc9..fdb0717 100644 --- a/src/main/java/com/playmonumenta/structures/commands/ListRespawningStructures.java +++ b/src/main/java/com/playmonumenta/structures/commands/ListRespawningStructures.java @@ -3,8 +3,11 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.StringArgument; import javax.annotation.Nullable; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -13,18 +16,13 @@ public static void register() { final String command = "listrespawningstructures"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); - new CommandAPICommand(command) - .withPermission(perms) - .executes((sender, args) -> { - list(sender, null); - }) - .register(); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) + .withOptionalArguments(labelArg) .executes((sender, args) -> { - list(sender, (String)args[0]); + list(sender, args.getByArgument(labelArg)); }) .register(); } @@ -36,7 +34,7 @@ private static void list(CommandSender sender, @Nullable String label) { try { RespawnManager.getInstance().structureInfo(sender, label); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to get structure info: " + e.getMessage()); + sender.sendMessage(Component.text("Got error while attempting to get structure info: " + e.getMessage(), NamedTextColor.RED)); } } } diff --git a/src/main/java/com/playmonumenta/structures/commands/LoadStructure.java b/src/main/java/com/playmonumenta/structures/commands/LoadStructure.java index 4479246..cc787cb 100644 --- a/src/main/java/com/playmonumenta/structures/commands/LoadStructure.java +++ b/src/main/java/com/playmonumenta/structures/commands/LoadStructure.java @@ -10,7 +10,8 @@ import dev.jorel.commandapi.arguments.TextArgument; import dev.jorel.commandapi.wrappers.FunctionWrapper; import javax.annotation.Nullable; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Location; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; @@ -21,56 +22,33 @@ public static void register() { final String command = "loadstructure"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new TextArgument("path")) - .withArguments(new LocationArgument("position")) - .executes((sender, args) -> { - load(sender, (String)args[0], (Location)args[1], false, false, null); - }) - .register(); - - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new TextArgument("path")) - .withArguments(new LocationArgument("position")) - .withArguments(new BooleanArgument("includeEntities")) - .executes((sender, args) -> { - load(sender, (String)args[0], (Location)args[1], (Boolean)args[2], false, null); - }) - .register(); - - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new TextArgument("path")) - .withArguments(new LocationArgument("position")) - .withArguments(new BooleanArgument("includeEntities")) - .withArguments(new BooleanArgument("includeBiomes")) - .executes((sender, args) -> { - load(sender, (String)args[0], (Location)args[1], (Boolean)args[2], (Boolean)args[3], null); - }) - .register(); + TextArgument pathArg = new TextArgument("path"); + LocationArgument positionArg = new LocationArgument("position"); + BooleanArgument includeEntitiesArg = new BooleanArgument("includeEntities"); + BooleanArgument includeBiomesArg = new BooleanArgument("includeBiomes"); + FunctionArgument functionArg = new FunctionArgument("postLoadFunction"); + // Skips biomeArg new CommandAPICommand(command) .withPermission(perms) - .withArguments(new TextArgument("path")) - .withArguments(new LocationArgument("position")) - .withArguments(new BooleanArgument("includeEntities")) - .withArguments(new FunctionArgument("postLoadFunction")) + .withArguments(pathArg) + .withArguments(positionArg) + .withArguments(includeEntitiesArg) + .withArguments(functionArg) .executes((sender, args) -> { - load(sender, (String)args[0], (Location)args[1], (Boolean)args[2], false, (FunctionWrapper[])args[3]); + load(sender, args.getByArgument(pathArg), args.getByArgument(positionArg), args.getByArgumentOrDefault(includeEntitiesArg, false), false, args.getByArgument(functionArg)); }) .register(); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new TextArgument("path")) - .withArguments(new LocationArgument("position")) - .withArguments(new BooleanArgument("includeEntities")) - .withArguments(new BooleanArgument("includeBiomes")) - .withArguments(new FunctionArgument("postLoadFunction")) + .withArguments(pathArg) + .withArguments(positionArg) + .withOptionalArguments(includeEntitiesArg) + .withOptionalArguments(includeBiomesArg) + .withOptionalArguments(functionArg) .executes((sender, args) -> { - load(sender, (String)args[0], (Location)args[1], (Boolean)args[2], (Boolean)args[3], (FunctionWrapper[])args[4]); + load(sender, args.getByArgument(pathArg), args.getByArgument(positionArg), args.getByArgumentOrDefault(includeEntitiesArg, false), args.getByArgumentOrDefault(includeBiomesArg, false), args.getByArgument(functionArg)); }) .register(); } @@ -89,7 +67,7 @@ private static void load(CommandSender sender, String path, Location loadLoc, bo senderLoaded = true; } if (senderLoaded) { - sender.sendMessage(ChatColor.RED + "Failed to load structure: " + ex.getMessage()); + sender.sendMessage(Component.text("Failed to load structure: " + ex.getMessage(), NamedTextColor.RED)); ex.printStackTrace(); MessagingUtils.sendStackTrace(sender, ex); } diff --git a/src/main/java/com/playmonumenta/structures/commands/ReloadStructures.java b/src/main/java/com/playmonumenta/structures/commands/ReloadStructures.java index 4a6bc76..6c0b4d3 100644 --- a/src/main/java/com/playmonumenta/structures/commands/ReloadStructures.java +++ b/src/main/java/com/playmonumenta/structures/commands/ReloadStructures.java @@ -3,6 +3,8 @@ import com.playmonumenta.structures.StructuresPlugin; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; public class ReloadStructures { @@ -11,7 +13,7 @@ public static void register(StructuresPlugin plugin) { .withPermission(CommandPermission.fromString("monumenta.structures")) .executes((sender, args) -> { plugin.reloadConfig(); - sender.sendMessage(ChatColor.GREEN + "Structures reloaded"); + sender.sendMessage(Component.text("Structures reloaded", NamedTextColor.GREEN)); }) .register(); } diff --git a/src/main/java/com/playmonumenta/structures/commands/RemoveRespawningStructure.java b/src/main/java/com/playmonumenta/structures/commands/RemoveRespawningStructure.java index 8578fc3..39a9b85 100644 --- a/src/main/java/com/playmonumenta/structures/commands/RemoveRespawningStructure.java +++ b/src/main/java/com/playmonumenta/structures/commands/RemoveRespawningStructure.java @@ -3,17 +3,22 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.StringArgument; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; public class RemoveRespawningStructure { public static void register() { + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + new CommandAPICommand("removerespawningstructure") .withPermission(CommandPermission.fromString("monumenta.structures")) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) + .withArguments(labelArg) .executes((sender, args) -> { - remove(sender, (String)args[0]); + remove(sender, args.getByArgument(labelArg)); }) .register(); } @@ -22,7 +27,7 @@ private static void remove(CommandSender sender, String label) { try { RespawnManager.getInstance().removeStructure(label); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Failed to remove structure: " + e.getMessage()); + sender.sendMessage(Component.text("Failed to remove structure: " + e.getMessage(), NamedTextColor.RED)); return; } diff --git a/src/main/java/com/playmonumenta/structures/commands/RespawnStructure.java b/src/main/java/com/playmonumenta/structures/commands/RespawnStructure.java index ce5a7f3..d172749 100644 --- a/src/main/java/com/playmonumenta/structures/commands/RespawnStructure.java +++ b/src/main/java/com/playmonumenta/structures/commands/RespawnStructure.java @@ -3,9 +3,11 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.StringArgument; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; public class RespawnStructure { @@ -13,20 +15,15 @@ public static void register() { final String command = "respawnstructure"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .executes((sender, args) -> { - respawn(sender, (String)args[0], 600); // Default 30s - }) - .register(); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + IntegerArgument ticksUntilRespawnArg = new IntegerArgument("ticks_until_respawn", 0); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .withArguments(new IntegerArgument("ticks_until_respawn", 0)) + .withArguments(labelArg) + .withOptionalArguments(ticksUntilRespawnArg) .executes((sender, args) -> { - respawn(sender, (String)args[0], (Integer)args[1]); + respawn(sender, args.getByArgument(labelArg), args.getByArgumentOrDefault(ticksUntilRespawnArg, 600)); }) .register(); } @@ -35,7 +32,7 @@ private static void respawn(CommandSender sender, String label, Integer ticksUnt try { RespawnManager.getInstance().setTimer(label, ticksUntilRespawn); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to respawn structure: " + e.getMessage()); + sender.sendMessage(Component.text("Got error while attempting to respawn structure: " + e.getMessage(), NamedTextColor.RED)); } } } diff --git a/src/main/java/com/playmonumenta/structures/commands/SaveStructure.java b/src/main/java/com/playmonumenta/structures/commands/SaveStructure.java index 8d7bbf2..1f234cc 100644 --- a/src/main/java/com/playmonumenta/structures/commands/SaveStructure.java +++ b/src/main/java/com/playmonumenta/structures/commands/SaveStructure.java @@ -13,13 +13,17 @@ public class SaveStructure { public static void register() { + TextArgument pathArg = new TextArgument("path"); + LocationArgument pos1Arg = new LocationArgument("pos1"); + LocationArgument pos2Arg = new LocationArgument("pos2"); + new CommandAPICommand("savestructure") .withPermission(CommandPermission.fromString("monumenta.structures")) - .withArguments(new TextArgument("path")) - .withArguments(new LocationArgument("pos1")) - .withArguments(new LocationArgument("pos2")) + .withArguments(pathArg) + .withArguments(pos1Arg) + .withArguments(pos2Arg) .executes((sender, args) -> { - save(sender, (Location)args[1], (Location)args[2], (String)args[0]); + save(sender, args.getByArgument(pos1Arg), args.getByArgument(pos2Arg), args.getByArgument(pathArg)); }) .register(); } diff --git a/src/main/java/com/playmonumenta/structures/commands/SetPostRespawnCommand.java b/src/main/java/com/playmonumenta/structures/commands/SetPostRespawnCommand.java index fab82d3..058c65e 100644 --- a/src/main/java/com/playmonumenta/structures/commands/SetPostRespawnCommand.java +++ b/src/main/java/com/playmonumenta/structures/commands/SetPostRespawnCommand.java @@ -3,10 +3,12 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.arguments.TextArgument; import javax.annotation.Nullable; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; public class SetPostRespawnCommand { @@ -14,20 +16,15 @@ public static void register() { final String command = "setpostrespawncommand"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .executes((sender, args) -> { - setCommand(sender, (String)args[0], null); - }) - .register(); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + TextArgument commandArg = new TextArgument("command"); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .withArguments(new TextArgument("command")) + .withArguments(labelArg) + .withOptionalArguments(commandArg) .executes((sender, args) -> { - setCommand(sender, (String)args[0], (String)args[1]); + setCommand(sender, args.getByArgument(labelArg), args.getByArgument(commandArg)); }) .register(); } @@ -40,7 +37,7 @@ private static void setCommand(CommandSender sender, String label, @Nullable Str try { RespawnManager.getInstance().setPostRespawnCommand(label, command); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to set post respawn command: " + e.getMessage()); + sender.sendMessage(Component.text("Got error while attempting to set post respawn command: " + e.getMessage(), NamedTextColor.RED)); return; } diff --git a/src/main/java/com/playmonumenta/structures/commands/SetRespawnTimer.java b/src/main/java/com/playmonumenta/structures/commands/SetRespawnTimer.java index fa9018f..337913a 100644 --- a/src/main/java/com/playmonumenta/structures/commands/SetRespawnTimer.java +++ b/src/main/java/com/playmonumenta/structures/commands/SetRespawnTimer.java @@ -3,19 +3,25 @@ import com.playmonumenta.structures.managers.RespawnManager; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.StringArgument; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; public class SetRespawnTimer { public static void register() { + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + IntegerArgument ticksArg = new IntegerArgument("ticks", 0); + new CommandAPICommand("setrespawntimer") .withPermission(CommandPermission.fromString("monumenta.structures")) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .withArguments(new IntegerArgument("ticks", 0)) + .withArguments(labelArg) + .withArguments(ticksArg) .executes((sender, args) -> { - setTimer(sender, (String)args[0], (Integer)args[1]); + setTimer(sender, args.getByArgument(labelArg), args.getByArgument(ticksArg)); }) .register(); } @@ -24,7 +30,7 @@ private static void setTimer(CommandSender sender, String label, int ticks) { try { RespawnManager.getInstance().setTimerPeriod(label, ticks); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to set post respawn command: " + e.getMessage()); + sender.sendMessage(Component.text("Got error while attempting to set post respawn command: " + e.getMessage(), NamedTextColor.RED)); return; } diff --git a/src/main/java/com/playmonumenta/structures/commands/SetSpawnerBreakTrigger.java b/src/main/java/com/playmonumenta/structures/commands/SetSpawnerBreakTrigger.java index 0772458..3f8fb0c 100644 --- a/src/main/java/com/playmonumenta/structures/commands/SetSpawnerBreakTrigger.java +++ b/src/main/java/com/playmonumenta/structures/commands/SetSpawnerBreakTrigger.java @@ -4,11 +4,13 @@ import com.playmonumenta.structures.managers.SpawnerBreakTrigger; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.StringArgument; import javax.annotation.Nullable; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; public class SetSpawnerBreakTrigger { @@ -16,21 +18,17 @@ public static void register() { final String command = "setspawnerbreaktrigger"; final CommandPermission perms = CommandPermission.fromString("monumenta.structures"); - new CommandAPICommand(command) - .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .executes((sender, args) -> { - setTrigger(sender, (String)args[0], 0, null); - }) - .register(); + Argument labelArg = new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES); + IntegerArgument spawnerCountArg = new IntegerArgument("spawner_count", 0); + GreedyStringArgument questComponentArg = new GreedyStringArgument("quest_component"); new CommandAPICommand(command) .withPermission(perms) - .withArguments(new StringArgument("label").replaceSuggestions(RespawnManager.SUGGESTIONS_STRUCTURES)) - .withArguments(new IntegerArgument("spawner_count", 0)) - .withArguments(new GreedyStringArgument("quest_component")) + .withArguments(labelArg) + .withOptionalArguments(spawnerCountArg) + .withOptionalArguments(questComponentArg) .executes((sender, args) -> { - setTrigger(sender, (String)args[0], (Integer)args[1], (String)args[2]); + setTrigger(sender, args.getByArgument(labelArg), args.getByArgumentOrDefault(spawnerCountArg, 0), args.getByArgument(questComponentArg)); }) .register(); } @@ -43,7 +41,7 @@ private static void setTrigger(CommandSender sender, String label, int spawnerCo } RespawnManager.getInstance().setSpawnerBreakTrigger(label, trigger); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Got error while attempting to set spawner break trigger: " + e.getMessage()); + sender.sendMessage(Component.text("Got error while attempting to set spawner break trigger: " + e.getMessage(), NamedTextColor.RED)); return; } diff --git a/src/main/java/com/playmonumenta/structures/managers/RespawnManager.java b/src/main/java/com/playmonumenta/structures/managers/RespawnManager.java index 3e700a2..1897903 100644 --- a/src/main/java/com/playmonumenta/structures/managers/RespawnManager.java +++ b/src/main/java/com/playmonumenta/structures/managers/RespawnManager.java @@ -34,7 +34,7 @@ public class RespawnManager { public static final String ZONE_NAMESPACE_INSIDE = "Respawning Structures Inside"; public static final String ZONE_NAMESPACE_NEARBY = "Respawning Structures Nearby"; private static @Nullable RespawnManager INSTANCE = null; - public static ArgumentSuggestions SUGGESTIONS_STRUCTURES = ArgumentSuggestions.strings((info) -> { + public static ArgumentSuggestions SUGGESTIONS_STRUCTURES = ArgumentSuggestions.strings((info) -> { if (INSTANCE == null) { return new String[]{}; }