From 1f97a8960a79b3a12aed7a40428b561eaa1322a3 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 6 May 2025 14:56:05 +0800 Subject: [PATCH] Implement `/mv worldborder` commands --- .../core/commands/WorldBorderCommand.java | 225 ++++++++++++++++++ .../multiverse/core/locale/MVCorei18n.java | 33 ++- .../core/world/LoadedMultiverseWorld.java | 10 + .../resources/multiverse-core_en.properties | 33 ++- .../multiverse/core/inject/InjectionTest.kt | 2 +- 5 files changed, 292 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/mvplugins/multiverse/core/commands/WorldBorderCommand.java diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/WorldBorderCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/WorldBorderCommand.java new file mode 100644 index 000000000..19d9b89bb --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/commands/WorldBorderCommand.java @@ -0,0 +1,225 @@ +package org.mvplugins.multiverse.core.commands; + +import co.aikar.commands.annotation.Default; +import co.aikar.commands.annotation.Flags; +import co.aikar.commands.annotation.Optional; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import io.vavr.control.Try; +import org.bukkit.WorldBorder; +import org.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.core.command.MVCommandIssuer; +import org.mvplugins.multiverse.core.locale.MVCorei18n; +import org.mvplugins.multiverse.core.locale.message.MessageReplacement.Replace; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; + +import java.util.function.Consumer; + +import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace; + +@Service +@Subcommand("worldborder") +final class WorldBorderCommand extends CoreCommand { + + @Subcommand("add") + void onWorldBorderAdd( + MVCommandIssuer issuer, + + @Syntax("") + double size, + + @Optional + @Default("0") + @Syntax("[time]") + int time, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + onWorldBorderSet(issuer, worldBorder.getSize() + size, time, world); + }); + } + + @Subcommand("center") + void onWorldBorderCenter( + MVCommandIssuer issuer, + + @Syntax("[x]") + double x, + + @Syntax("[z]") + double z, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + if (worldBorder.getCenter().getX() == x && worldBorder.getCenter().getZ() == z) { + issuer.sendMessage(MVCorei18n.WORLDBORDER_CENTER_NOTHINGCHANGED, + Replace.WORLD.with(world.getAliasOrName())); + return; + } + worldBorder.setCenter(x, z); + issuer.sendMessage(MVCorei18n.WORLDBORDER_CENTER_SUCCESS, + replace("{x}").with(worldBorder.getCenter().getX()), + replace("{z}").with(worldBorder.getCenter().getZ()), + Replace.WORLD.with(world.getAliasOrName())); + }); + } + + @Subcommand("damage amount") + void onWorldBorderDamageAmount( + MVCommandIssuer issuer, + + @Syntax("") + double damage, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + if (worldBorder.getDamageAmount() == damage) { + issuer.sendMessage(MVCorei18n.WORLDBORDER_DAMAGEAMOUNT_NOTHINGCHANGED, + Replace.WORLD.with(world.getAliasOrName())); + return; + } + worldBorder.setDamageAmount(damage); + issuer.sendMessage(MVCorei18n.WORLDBORDER_DAMAGEAMOUNT_SUCCESS, + replace("{amount}").with(worldBorder.getDamageAmount()), + Replace.WORLD.with(world.getAliasOrName())); + }); + } + + @Subcommand("damage buffer") + void onWorldBorderDamageBuffer( + MVCommandIssuer issuer, + + @Syntax("") + double distance, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + if (worldBorder.getDamageBuffer() == distance) { + issuer.sendMessage(MVCorei18n.WORLDBORDER_DAMAGEBUFFER_NOTHINGCHANGED, + Replace.WORLD.with(world.getAliasOrName())); + return; + } + worldBorder.setDamageBuffer(distance); + issuer.sendMessage(MVCorei18n.WORLDBORDER_DAMAGEBUFFER_SUCCESS, + replace("{distance}").with(worldBorder.getDamageBuffer()), + Replace.WORLD.with(world.getAliasOrName())); + }); + } + + @Subcommand("get") + void onWorldBorderGet( + MVCommandIssuer issuer, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + issuer.sendMessage(MVCorei18n.WORLDBORDER_GET_SIZE, + replace("{size}").with(worldBorder.getSize()), + Replace.WORLD.with(world.getAliasOrName())); + }); + } + + @Subcommand("set") + void onWorldBorderSet( + MVCommandIssuer issuer, + + @Syntax("") + double size, + + @Optional + @Default("0") + @Syntax("[time]") + int time, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + double previousSize = worldBorder.getSize(); + if (previousSize == size) { + issuer.sendMessage(MVCorei18n.WORLDBORDER_SET_NOTHINGCHANGED, + Replace.WORLD.with(world.getAliasOrName())); + return; + } + worldBorder.setSize(size, time); + if (time <= 0) { + issuer.sendMessage(MVCorei18n.WORLDBORDER_SET_IMMEDIATE, + replace("{size}").with(worldBorder.getSize()), + Replace.WORLD.with(world.getAliasOrName())); + } else { + issuer.sendMessage(previousSize > size ? MVCorei18n.WORLDBORDER_SET_GROWING : MVCorei18n.WORLDBORDER_SET_SHRINKING, + replace("{size}").with(size), + replace("{time}").with(time), + Replace.WORLD.with(world.getAliasOrName())); + } + }); + } + + @Subcommand("warning distance") + void onWorldBorderWarningDistance( + MVCommandIssuer issuer, + + @Syntax("") + int distance, + + @Flags("resolve=issuerAware") + @Syntax("[world]") + LoadedMultiverseWorld world + ) { + worldBorderAction(issuer, world, worldBorder -> { + if (worldBorder.getWarningDistance() == distance) { + issuer.sendMessage(MVCorei18n.WORLDBORDER_WARNINGDISTANCE_NOTHINGCHANGED, + Replace.WORLD.with(world.getAliasOrName())); + return; + } + worldBorder.setWarningDistance(distance); + issuer.sendMessage(MVCorei18n.WORLDBORDER_WARNINGDISTANCE_SUCCESS, + replace("{distance}").with(worldBorder.getWarningDistance()), + Replace.WORLD.with(world.getAliasOrName())); + }); + } + + @Subcommand("warning time") + void onWorldBorderWarningTime( + MVCommandIssuer issuer, + + @Syntax("