This commit is contained in:
zax71 2023-09-04 13:08:39 +01:00
parent b42b77b0bf
commit 1ac54b7e1d
3 changed files with 31 additions and 16 deletions

View File

@ -1,6 +1,8 @@
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import co.aikar.commands.BukkitCommandIssuer; import co.aikar.commands.BukkitCommandIssuer;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.MessageType;
import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.CommandPermission;
@ -14,6 +16,7 @@ import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.World; import org.bukkit.World;
@ -43,31 +46,29 @@ public class GamerulesCommand extends MultiverseCommand {
@CommandPermission("multiverse.core.gamerules.list") @CommandPermission("multiverse.core.gamerules.list")
@CommandCompletion("@mvworlds") @CommandCompletion("@mvworlds")
@Syntax("[World]") @Syntax("[World]")
@Description("{@@mv-core.gamerules.description}") //TODO i18n @Description("{@@mv-core.gamerules.description}")
public void onGamerulesCommand(@NotNull BukkitCommandIssuer issuer, public void onGamerulesCommand(@NotNull BukkitCommandIssuer issuer,
@Flags("resolve=issuerOnly")
Player player,
@Single @Single
@Syntax("<world>") @Syntax("<world>")
@Description("{@@mv-core.gamerules.world.description}") //TODO i18n @Description("{@@mv-core.gamerules.description.world}")
MVWorld world MVWorld world
) { ) {
if (!issuer.isPlayer()) { if (!issuer.isPlayer() && world == null) {
if (world == null) { issuer.sendInfo(MVCorei18n.GAMERULES_ERROR_SPECIFYWORLD);
issuer.sendMessage("You must specify a world from the command line");
return; return;
} }
}
// Get the players world if none is specified // Get the players world if none is specified
if (world == null) { if (world == null) {
Player player = issuer.getPlayer(); // Need to do it here so the command can be run from console
Logging.finer("Getting the player's current world to list gamerules for"); Logging.finer("Getting the player's current world to list gamerules for");
world = worldManager.getMVWorld(player.getWorld()); world = worldManager.getMVWorld(player.getWorld());
} }
issuer.sendMessage("--- Gamerules for " + world.getName() + " ---\n" + encodeMap(getGameRuleMap(world.getCBWorld()))); // Finally, send the list
issuer.sendInfo(MVCorei18n.GAMERULES_TITLE, "{world}", world.getName());
issuer.sendMessage("\n" + encodeMap(issuer, getGameRuleMap(world.getCBWorld())));
@ -92,16 +93,16 @@ public class GamerulesCommand extends MultiverseCommand {
return gameRuleMap; return gameRuleMap;
} }
private String encodeMap(Map<String, String> inMap) { //TODO i18n private String encodeMap(CommandIssuer issuer, Map<String, String> inMap) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (String key : inMap.keySet()) { for (String key : inMap.keySet()) {
String value = inMap.get(key); String value = inMap.get(key);
stringBuilder stringBuilder.append(this.commandManager.formatMessage(
.append("&l") issuer,
.append(key) MessageType.INFO,
.append("&f : &6") MVCorei18n.GAMERULES_RULE,
.append(value) "{gamerule}", key, "{value}", value))
.append("\n"); .append("\n");
} }
return stringBuilder.toString(); return stringBuilder.toString();

View File

@ -42,6 +42,13 @@ public enum MVCorei18n implements MessageKeyProvider {
GAMERULE_SUCCESS_SINGLE, GAMERULE_SUCCESS_SINGLE,
GAMERULE_SUCCESS_MULTIPLE, GAMERULE_SUCCESS_MULTIPLE,
// Gamerules command
GAMERULES_DESCRIPTION,
GAMERULES_DESCRIPTION_WORLD,
GAMERULES_ERROR_SPECIFYWORLD,
GAMERULES_TITLE,
GAMERULES_RULE,
// import command // import command
IMPORT_IMPORTING, IMPORT_IMPORTING,
IMPORT_FAILED, IMPORT_FAILED,

View File

@ -59,6 +59,13 @@ mv-core.gamerule.failed=Failed to set gamerule {gamerule} to {value} in {world}.
mv-core.gamerule.success.single=&aSuccessfully set {gamerule} to {value} in {world}. mv-core.gamerule.success.single=&aSuccessfully set {gamerule} to {value} in {world}.
mv-core.gamerule.success.multiple=&aSuccessfully set {gamerule} to {value} in {count} worlds. mv-core.gamerule.success.multiple=&aSuccessfully set {gamerule} to {value} in {count} worlds.
# /mv gamerules
mv-core.gamerules.description=Lists gamerules for the specified world
mv-core.gamerules.description.world=The world to list gamerules in
mv-core.gamerules.error.specifyworld=You must specify a world from the command line
mv-core.gamerules.title= --- Gamerules for {world} ---
mv-core.gamerules.rule=&l{gamerule}&f : &6{value}
# /mv import # /mv import
mv-core.import.description=Imports an existing world folder. mv-core.import.description=Imports an existing world folder.
mv-core.import.name.description=Name of the world folder. mv-core.import.name.description=Name of the world folder.