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; 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.CommandIssuer;
import co.aikar.commands.InvalidCommandArgument; import co.aikar.commands.InvalidCommandArgument;
import co.aikar.commands.MessageType; 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.utils.MVCorei18n;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import java.util.HashMap;
import java.util.Map;
@Service @Service
@CommandAlias("mv") @CommandAlias("mv")
@Subcommand("gamerule|rule|gamerules|rules") @Subcommand("gamerule|rule|gamerules|rules")
@ -76,8 +77,8 @@ class GameruleCommand extends MultiverseCommand {
@CommandCompletion("@gamerules true|false|@range:1-10 @mvworlds:multiple|*") @CommandCompletion("@gamerules true|false|@range:1-10 @mvworlds:multiple|*")
@Syntax("<Gamerule> <Gamerule value> [World or *]") @Syntax("<Gamerule> <Gamerule value> [World or *]")
@Description("{@@mv-core.gamerule.set.description}") @Description("{@@mv-core.gamerule.set.description}")
void onGameruleCommand( void onGameruleSetCommand(
BukkitCommandIssuer issuer, MVCommandIssuer issuer,
@Syntax("<Gamerule>") @Syntax("<Gamerule>")
@Description("{@@mv-core.gamerule.set.gamerule.description}") @Description("{@@mv-core.gamerule.set.gamerule.description}")
@ -90,8 +91,7 @@ class GameruleCommand extends MultiverseCommand {
@Flags("resolve=issuerAware") @Flags("resolve=issuerAware")
@Syntax("[World or *]") @Syntax("[World or *]")
@Description("{@@mv-core.gamerule.set.world.description}") @Description("{@@mv-core.gamerule.set.world.description}")
LoadedMultiverseWorld[] worlds) LoadedMultiverseWorld[] worlds) {
{
Object value = gameRuleValue.getValue(); Object value = gameRuleValue.getValue();
boolean success = true; boolean success = true;
for (LoadedMultiverseWorld world : worlds) { 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") @Subcommand("list")
@CommandPermission("multiverse.core.gamerule.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>]") @Syntax("[world] [--page <page>] [--filter <filter>]")
@Description("{@@mv-core.gamerule.list.description}") @Description("{@@mv-core.gamerule.list.description}")
void onGamerulesCommand( void onGameruleListCommand(
@NotNull MVCommandIssuer issuer, MVCommandIssuer issuer,
@Flags("resolve=issuerAware") @Flags("resolve=issuerAware")
@Syntax("<world>") @Syntax("<world>")

View File

@ -49,12 +49,17 @@ public enum MVCorei18n implements MessageKeyProvider {
DUMPS_DESCRIPTION, DUMPS_DESCRIPTION,
DUMPS_URL_LIST, DUMPS_URL_LIST,
// gamerule command // gamerule set command
GAMERULE_SET_FAILED, GAMERULE_SET_FAILED,
GAMERULE_SET_SUCCESS_SINGLE, GAMERULE_SET_SUCCESS_SINGLE,
GAMERULE_SET_SUCCESS_MULTIPLE, 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,
GAMERULE_LIST_DESCRIPTION_PAGE, GAMERULE_LIST_DESCRIPTION_PAGE,
GAMERULE_LIST_DESCRIPTION_WORLD, 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.description=Dumps version info to the console or paste services
mv-core.dumps.url.list={service} : {link} mv-core.dumps.url.list={service} : {link}
# /mv gamerule # /mv gamerule set
mv-core.gamerule.set.description=Changes a gamerule in one or more worlds 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.gamerule.description=Gamerule to set.
mv-core.gamerule.set.value.description=Value of gamerule 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-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.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.single=&aSuccessfully set {gamerule} to {value} in {world}.
mv-core.gamerule.set.success.multiple=&aSuccessfully set {gamerule} to {value} in {count} worlds. mv-core.gamerule.set.success.multiple=&aSuccessfully set {gamerule} to {value} in {count} worlds.
# /mv gamerules # /mv gamerule reset
mv-core.gamerule.list.description=Lists gamerules for the specified world mv-core.gamerule.reset.description=Resets a gamerule in one or more worlds to it's default value.
mv-core.gamerule.list.description.page=The page to view mv-core.gamerule.reset.gamerule.description=Gamerule to reset.
mv-core.gamerule.list.description.world=The world to list gamerules in 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-core.gamerule.list.title= --- Gamerules for {world} ---
# /mv import # /mv import