Implement gamerule reset

This commit is contained in:
Ben Woo 2023-09-25 12:29:29 +08:00
parent 7c6d7d5883
commit 8d508358f7
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
3 changed files with 75 additions and 22 deletions

View File

@ -1,6 +1,10 @@
package org.mvplugins.multiverse.core.commands;
import co.aikar.commands.BukkitCommandIssuer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.InvalidCommandArgument;
import co.aikar.commands.MessageType;
@ -34,9 +38,6 @@ import org.mvplugins.multiverse.core.display.parsers.MapContentProvider;
import org.mvplugins.multiverse.core.utils.MVCorei18n;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import java.util.HashMap;
import java.util.Map;
@Service
@CommandAlias("mv")
@Subcommand("gamerule|rule|gamerules|rules")
@ -76,8 +77,8 @@ class GameruleCommand extends MultiverseCommand {
@CommandCompletion("@gamerules true|false|@range:1-10 @mvworlds:multiple|*")
@Syntax("<Gamerule> <Gamerule value> [World or *]")
@Description("{@@mv-core.gamerule.set.description}")
void onGameruleCommand(
BukkitCommandIssuer issuer,
void onGameruleSetCommand(
MVCommandIssuer issuer,
@Syntax("<Gamerule>")
@Description("{@@mv-core.gamerule.set.gamerule.description}")
@ -90,8 +91,7 @@ class GameruleCommand extends MultiverseCommand {
@Flags("resolve=issuerAware")
@Syntax("[World or *]")
@Description("{@@mv-core.gamerule.set.world.description}")
LoadedMultiverseWorld[] worlds)
{
LoadedMultiverseWorld[] worlds) {
Object value = gameRuleValue.getValue();
boolean success = true;
for (LoadedMultiverseWorld world : worlds) {
@ -122,13 +122,53 @@ class GameruleCommand extends MultiverseCommand {
}
}
@Subcommand("reset")
@CommandPermission("multiverse.core.gamerule.set")
@CommandCompletion("@gamerules @mvworlds:multiple|*")
@Syntax("<Gamerule> [World or *]")
@Description("{@@mv-core.gamerule.reset.description}")
void onGameruleSetCommand(
MVCommandIssuer issuer,
@Syntax("<Gamerule>")
@Description("{@@mv-core.gamerule.reset.gamerule.description}")
GameRule gamerule,
@Flags("resolve=issuerAware")
@Syntax("[World or *]")
@Description("{@@mv-core.gamerule.reset.world.description}")
LoadedMultiverseWorld[] worlds) {
AtomicBoolean success = new AtomicBoolean(true);
Arrays.stream(worlds).forEach(world -> world.getBukkitWorld().peek(bukkitWorld -> {
bukkitWorld.setGameRule(gamerule, bukkitWorld.getGameRuleDefault(gamerule));
}).onEmpty(() -> {
success.set(false);
issuer.sendError(MVCorei18n.GAMERULE_RESET_FAILED,
"{gamerule}", gamerule.getName(),
"{world}", world.getName());
}));
// Tell user if it was successful
if (success.get()) {
if (worlds.length == 1) {
issuer.sendInfo(MVCorei18n.GAMERULE_RESET_SUCCESS_SINGLE,
"{gamerule}", gamerule.getName(),
"{world}", worlds[0].getName());
} else if (worlds.length > 1) {
issuer.sendInfo(MVCorei18n.GAMERULE_RESET_SUCCESS_MULTIPLE,
"{gamerule}", gamerule.getName(),
"{count}", String.valueOf(worlds.length));
}
}
}
@Subcommand("list")
@CommandPermission("multiverse.core.gamerule.list")
@CommandCompletion("@mvworlds|@flags:groupName=mvgamerulescommand @flags:groupName=mvgamerulescommand")
@CommandCompletion("@mvworlds|@flags:groupName=mvgamerulecommand @flags:groupName=mvgamerulecommand")
@Syntax("[world] [--page <page>] [--filter <filter>]")
@Description("{@@mv-core.gamerule.list.description}")
void onGamerulesCommand(
@NotNull MVCommandIssuer issuer,
void onGameruleListCommand(
MVCommandIssuer issuer,
@Flags("resolve=issuerAware")
@Syntax("<world>")

View File

@ -49,12 +49,17 @@ public enum MVCorei18n implements MessageKeyProvider {
DUMPS_DESCRIPTION,
DUMPS_URL_LIST,
// gamerule command
// gamerule set command
GAMERULE_SET_FAILED,
GAMERULE_SET_SUCCESS_SINGLE,
GAMERULE_SET_SUCCESS_MULTIPLE,
// Gamerules command
// gamerule reset command
GAMERULE_RESET_FAILED,
GAMERULE_RESET_SUCCESS_SINGLE,
GAMERULE_RESET_SUCCESS_MULTIPLE,
// gamerule list command
GAMERULE_LIST_DESCRIPTION,
GAMERULE_LIST_DESCRIPTION_PAGE,
GAMERULE_LIST_DESCRIPTION_WORLD,

View File

@ -60,19 +60,27 @@ mv-core.delete.success=&aWorld '{world}' deleted!
mv-core.dumps.description=Dumps version info to the console or paste services
mv-core.dumps.url.list={service} : {link}
# /mv gamerule
mv-core.gamerule.set.description=Changes a gamerule in one or more worlds
mv-core.gamerule.set.gamerule.description=Gamerule to set
mv-core.gamerule.set.value.description=Value of gamerule
mv-core.gamerule.set.world.description=World to apply gamerule to, current world by default
# /mv gamerule set
mv-core.gamerule.set.description=Changes a gamerule in one or more worlds.
mv-core.gamerule.set.gamerule.description=Gamerule to set.
mv-core.gamerule.set.value.description=Value of gamerule.
mv-core.gamerule.set.world.description=World to apply gamerule to, current player's world by default.
mv-core.gamerule.set.failed=Failed to set gamerule {gamerule} to {value} in {world}. &fIt should be a {type}.
mv-core.gamerule.set.success.single=&aSuccessfully set {gamerule} to {value} in {world}.
mv-core.gamerule.set.success.multiple=&aSuccessfully set {gamerule} to {value} in {count} worlds.
# /mv gamerules
mv-core.gamerule.list.description=Lists gamerules for the specified world
mv-core.gamerule.list.description.page=The page to view
mv-core.gamerule.list.description.world=The world to list gamerules in
# /mv gamerule reset
mv-core.gamerule.reset.description=Resets a gamerule in one or more worlds to it's default value.
mv-core.gamerule.reset.gamerule.description=Gamerule to reset.
mv-core.gamerule.reset.world.description=World to reset gamerule of, current player's world by default.
mv-core.gamerule.reset.failed=Failed to reset gamerule {gamerule} in {world}.
mv-core.gamerule.reset.success.single=&aSuccessfully reset {gamerule} in {world}.
mv-core.gamerule.reset.success.multiple=&aSuccessfully reset {gamerule} in {count} worlds.
# /mv gamerule list
mv-core.gamerule.list.description=Lists gamerules for the specified world.
mv-core.gamerule.list.description.page=The page to view.
mv-core.gamerule.list.description.world=The world to list gamerules in.
mv-core.gamerule.list.title= --- Gamerules for {world} ---
# /mv import