Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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("<size>")
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("<damage>")
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("<distance>")
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("<size>")
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("<distance>")
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("<time>")
int time,

@Flags("resolve=issuerAware")
@Syntax("[world]")
LoadedMultiverseWorld world
) {
worldBorderAction(issuer, world, worldBorder -> {
if (worldBorder.getWarningTime() == time) {
issuer.sendMessage(MVCorei18n.WORLDBORDER_WARNINGTIME_NOTHINGCHANGED,
Replace.WORLD.with(world.getAliasOrName()));
return;
}
worldBorder.setWarningTime(time);
issuer.sendMessage(MVCorei18n.WORLDBORDER_WARNINGTIME_SUCCESS,
replace("{time}").with(worldBorder.getWarningTime()),
Replace.WORLD.with(world.getAliasOrName()));
});
}

private void worldBorderAction(MVCommandIssuer issuer, LoadedMultiverseWorld world, Consumer<WorldBorder> worldBorderAction) {
Try.run(() -> world.getWorldBorder().peek(worldBorderAction))
.onFailure(error -> issuer.sendError(error.getLocalizedMessage()));
}
}
33 changes: 28 additions & 5 deletions src/main/java/org/mvplugins/multiverse/core/locale/MVCorei18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ public enum MVCorei18n implements MessageKeyProvider {
// /mv usage
USAGE_DESCRIPTION,

// /mv version
VERSION_DESCRIPTION,
VERSION_MV,
VERSION_AUTHORS,
VERSION_SECRETCODE,

// /mv who
// /mv whoall
WHO_DESCRIPTION,
Expand All @@ -214,11 +220,28 @@ public enum MVCorei18n implements MessageKeyProvider {
WHO_EMPTY,
WHO_HEADER,

// /mv version
VERSION_DESCRIPTION,
VERSION_MV,
VERSION_AUTHORS,
VERSION_SECRETCODE,
// /mv worldborder
WORLDBORDER_CENTER_NOTHINGCHANGED,
WORLDBORDER_CENTER_SUCCESS,

WORLDBORDER_DAMAGEAMOUNT_NOTHINGCHANGED,
WORLDBORDER_DAMAGEAMOUNT_SUCCESS,

WORLDBORDER_DAMAGEBUFFER_NOTHINGCHANGED,
WORLDBORDER_DAMAGEBUFFER_SUCCESS,

WORLDBORDER_GET_SIZE,

WORLDBORDER_SET_NOTHINGCHANGED,
WORLDBORDER_SET_IMMEDIATE,
WORLDBORDER_SET_SHRINKING,
WORLDBORDER_SET_GROWING,

WORLDBORDER_WARNINGDISTANCE_NOTHINGCHANGED,
WORLDBORDER_WARNINGDISTANCE_SUCCESS,

WORLDBORDER_WARNINGTIME_NOTHINGCHANGED,
WORLDBORDER_WARNINGTIME_SUCCESS,

// commands error
COMMANDS_ERROR_PLAYERSONLY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -159,6 +160,15 @@ public Option<List<Player>> getPlayers() {
return getBukkitWorld().map(World::getPlayers);
}

/**
* Get the world border configuration for this world.
*
* @return World border configuration
*/
public Option<WorldBorder> getWorldBorder() {
return getBukkitWorld().map(World::getWorldBorder);
}

/**
* {@inheritDoc}
*/
Expand Down
33 changes: 28 additions & 5 deletions src/main/resources/multiverse-core_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ mv-core.unload.success=&aWorld '{world}' unloaded!
# /mv usage
mv-core.usage.description=Show Multiverse-Core command usage.

# /mv version
mv-core.version.description=Displays version and authors
mv-core.version.mv=Multiverse Core Version &fv{version}
mv-core.version.authors=Multiverse Core Authors &f{authors}
mv-core.version.secretcode=Special Code: &fFRN002

# /mv who
# /mv whoall
mv-core.who.description=Lists the players in the world specified
Expand All @@ -197,11 +203,28 @@ mv-core.who.flags.description=Filter - only shows entries matching this. Page -
mv-core.who.empty=&7&oempty
mv-core.who.header=&b====[ Multiverse World Players List ]====

# /mv version
mv-core.version.description=Displays version and authors
mv-core.version.mv=Multiverse Core Version &fv{version}
mv-core.version.authors=Multiverse Core Authors &f{authors}
mv-core.version.secretcode=Special Code: &fFRN002
# /mv worldborder
mv-core.worldborder.center.nothingchanged=&cNothing changed. The world border is already centered there for world '&6{world}&c'.
mv-core.worldborder.center.success=&rSet the center of the world border to &6{x}&r, &6{z}&r for world '&6{world}&r'.

mv-core.worldborder.damageamount.nothingchanged=&cNothing changed. The world border damage is already that amount for world '&6{world}&c'.
mv-core.worldborder.damageamount.success=&rSet the world border damage to {amount} per block each second for world '&6{world}&r'.

mv-core.worldborder.damagebuffer.nothingchanged=&cNothing changed. The world border damage buffer is already that distance for world '&6{world}&c'.
mv-core.worldborder.damagebuffer.success=&rSet the world border damage buffer to {distance} block(s) for world '&6{world}&r'.

mv-core.worldborder.get.size=&rThe world border is currently {size} block(s) wide for world '&6{world}&r'.

mv-core.worldborder.set.nothingchanged=&cNothing changed. The world border is already that size for world '&6{world}&c'.
mv-core.worldborder.set.immediate=&rSet the world border to {size} block(s) wide for world '&6{world}&r'.
mv-core.worldborder.set.shrinking=&rShrinking the world border to {size} block(s) wide over {time} second(s) for world '&6{world}&r'.
mv-core.worldborder.set.growing=&rGrowing the world border to {size} block(s) wide over {time} second(s) for world '&6{world}&r'.

mv-core.worldborder.warningdistance.nothingchanged=&cNothing changed. The world border warning is already that distance for world '&6{world}&c'.
mv-core.worldborder.warningdistance.success=&rSet the world border warning distance to {distance} block(s) for world '&6{world}&r'.

mv-core.worldborder.warningtime.nothingchanged=&cNothing changed. The world border warning is already that amount of time for world '&6{world}&c'.
mv-core.worldborder.warningtime.success=&rSet the world border warning time to {time} second(s) for world '&6{world}&r'.

# commands error
mv-core.commands.error.playersonly=&cThis command can only be used by players
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class InjectionTest : TestWithMockBukkit() {
@Test
fun `Commands are available as services`() {
val commands = serviceLocator.getAllActiveServices(CoreCommand::class.java)
assertEquals(56, commands.size)
assertEquals(57, commands.size)
}

@Test
Expand Down