mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-25 01:31:24 +01:00
Switch to ContentDisplay API
This commit is contained in:
parent
1ac54b7e1d
commit
48ff8d8bd1
@ -6,9 +6,9 @@ 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;
|
||||||
|
import co.aikar.commands.annotation.Default;
|
||||||
import co.aikar.commands.annotation.Description;
|
import co.aikar.commands.annotation.Description;
|
||||||
import co.aikar.commands.annotation.Flags;
|
import co.aikar.commands.annotation.Optional;
|
||||||
import co.aikar.commands.annotation.Single;
|
|
||||||
import co.aikar.commands.annotation.Subcommand;
|
import co.aikar.commands.annotation.Subcommand;
|
||||||
import co.aikar.commands.annotation.Syntax;
|
import co.aikar.commands.annotation.Syntax;
|
||||||
import com.dumptruckman.minecraft.util.Logging;
|
import com.dumptruckman.minecraft.util.Logging;
|
||||||
@ -16,11 +16,14 @@ 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.display.ContentDisplay;
|
||||||
|
import com.onarandombox.MultiverseCore.display.handlers.PagedSendHandler;
|
||||||
|
import com.onarandombox.MultiverseCore.display.parsers.MapContentProvider;
|
||||||
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
|
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jvnet.hk2.annotations.Service;
|
import org.jvnet.hk2.annotations.Service;
|
||||||
|
|
||||||
@ -43,35 +46,42 @@ public class GamerulesCommand extends MultiverseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subcommand("gamerules|rules")
|
@Subcommand("gamerules|rules")
|
||||||
@CommandPermission("multiverse.core.gamerules.list")
|
@CommandPermission("multiverse.core.gamerule.list")
|
||||||
@CommandCompletion("@mvworlds")
|
@CommandCompletion("@mvworlds @range:1-6")
|
||||||
@Syntax("[World]")
|
@Syntax("[world] [page]")
|
||||||
@Description("{@@mv-core.gamerules.description}")
|
@Description("{@@mv-core.gamerules.description}")
|
||||||
public void onGamerulesCommand(@NotNull BukkitCommandIssuer issuer,
|
public void onGamerulesCommand(@NotNull BukkitCommandIssuer issuer,
|
||||||
|
|
||||||
@Single
|
@Optional
|
||||||
@Syntax("<world>")
|
@Syntax("<world>")
|
||||||
@Description("{@@mv-core.gamerules.description.world}")
|
@Description("{@@mv-core.gamerules.description.world}")
|
||||||
MVWorld world
|
MVWorld world,
|
||||||
|
|
||||||
|
@Optional
|
||||||
|
@Default("1")
|
||||||
|
@Syntax("<page>")
|
||||||
|
@Description("{@@mv-core.gamerules.description.page}")
|
||||||
|
int page
|
||||||
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
if (!issuer.isPlayer() && world == null) {
|
Logging.finer("Page is: " + page);
|
||||||
issuer.sendInfo(MVCorei18n.GAMERULES_ERROR_SPECIFYWORLD);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the players world if none is specified
|
|
||||||
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");
|
|
||||||
world = worldManager.getMVWorld(player.getWorld());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, send the list
|
|
||||||
issuer.sendInfo(MVCorei18n.GAMERULES_TITLE, "{world}", world.getName());
|
|
||||||
issuer.sendMessage("\n" + encodeMap(issuer, getGameRuleMap(world.getCBWorld())));
|
|
||||||
|
|
||||||
|
|
||||||
|
ContentDisplay.create()
|
||||||
|
.addContent(
|
||||||
|
new MapContentProvider<>(getGameRuleMap(world.getCBWorld()))
|
||||||
|
.withKeyColor(ChatColor.AQUA)
|
||||||
|
.withValueColor(ChatColor.WHITE)
|
||||||
|
)
|
||||||
|
.withSendHandler(
|
||||||
|
new PagedSendHandler()
|
||||||
|
.withHeader(this.getTitle(issuer, world.getCBWorld()))
|
||||||
|
.doPagination(true)
|
||||||
|
.withLinesPerPage(8)
|
||||||
|
.withTargetPage(page)
|
||||||
|
)
|
||||||
|
|
||||||
|
.send(issuer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,18 +103,11 @@ public class GamerulesCommand extends MultiverseCommand {
|
|||||||
return gameRuleMap;
|
return gameRuleMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String encodeMap(CommandIssuer issuer, Map<String, String> inMap) {
|
private String getTitle(CommandIssuer issuer, World world) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
return this.commandManager.formatMessage(
|
||||||
for (String key : inMap.keySet()) {
|
issuer,
|
||||||
String value = inMap.get(key);
|
MessageType.INFO,
|
||||||
|
MVCorei18n.GAMERULES_TITLE,
|
||||||
stringBuilder.append(this.commandManager.formatMessage(
|
"{world}", world.getName());
|
||||||
issuer,
|
|
||||||
MessageType.INFO,
|
|
||||||
MVCorei18n.GAMERULES_RULE,
|
|
||||||
"{gamerule}", key, "{value}", value))
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public class PagedSendHandler extends BaseSendHandler<PagedSendHandler> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether display output should be paginated if is for console output.
|
* Sets whether display output should be paginated if is for console output.
|
||||||
* This option will be useless of {@link PagedSendHandler#paginate} is set to false.
|
* This option will be useless if {@link PagedSendHandler#paginate} is set to false.
|
||||||
*
|
*
|
||||||
* @param paginateInConsole State of doing pagination in console.
|
* @param paginateInConsole State of doing pagination in console.
|
||||||
* @return Same {@link PagedSendHandler} for method chaining.
|
* @return Same {@link PagedSendHandler} for method chaining.
|
||||||
|
@ -44,10 +44,9 @@ public enum MVCorei18n implements MessageKeyProvider {
|
|||||||
|
|
||||||
// Gamerules command
|
// Gamerules command
|
||||||
GAMERULES_DESCRIPTION,
|
GAMERULES_DESCRIPTION,
|
||||||
|
GAMERULES_DESCRIPTION_PAGE,
|
||||||
GAMERULES_DESCRIPTION_WORLD,
|
GAMERULES_DESCRIPTION_WORLD,
|
||||||
GAMERULES_ERROR_SPECIFYWORLD,
|
|
||||||
GAMERULES_TITLE,
|
GAMERULES_TITLE,
|
||||||
GAMERULES_RULE,
|
|
||||||
|
|
||||||
// import command
|
// import command
|
||||||
IMPORT_IMPORTING,
|
IMPORT_IMPORTING,
|
||||||
|
@ -61,10 +61,9 @@ mv-core.gamerule.success.multiple=&aSuccessfully set {gamerule} to {value} in {c
|
|||||||
|
|
||||||
# /mv gamerules
|
# /mv gamerules
|
||||||
mv-core.gamerules.description=Lists gamerules for the specified world
|
mv-core.gamerules.description=Lists gamerules for the specified world
|
||||||
|
mv-core.gamerules.description.page=The page to view
|
||||||
mv-core.gamerules.description.world=The world to list gamerules in
|
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.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.
|
||||||
|
Loading…
Reference in New Issue
Block a user