Skip to content

Commit

Permalink
BREAKING: Update CommandAPI version to 9.4.1 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nobody314159 authored May 12, 2024
1 parent eddba96 commit bedb9b8
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 147 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,23 +16,24 @@ public static void register() {
final String command = "compassrespawn";
final CommandPermission perms = CommandPermission.fromString("monumenta.structures.compassrespawn");

Argument<String> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,20 +14,23 @@ public static void register() {
final String command = "forceconquerrespawn";
final CommandPermission perms = CommandPermission.fromString("monumenta.structures.forceconquerrespawn");

Argument<String> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> 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();
}
Expand All @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit bedb9b8

Please sign in to comment.