mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-25 09:41:23 +01:00
Add i18n and tell user when a world is empty when using /mv who
This commit is contained in:
parent
a6f4f2d2d5
commit
c640a251b6
@ -8,10 +8,12 @@ import co.aikar.commands.annotation.Description;
|
|||||||
import co.aikar.commands.annotation.Optional;
|
import co.aikar.commands.annotation.Optional;
|
||||||
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 jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jvnet.hk2.annotations.Service;
|
import org.jvnet.hk2.annotations.Service;
|
||||||
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
|
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
|
||||||
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
|
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
|
||||||
@ -79,12 +81,17 @@ public class WhoCommand extends MultiverseCommand {
|
|||||||
|
|
||||||
@Optional
|
@Optional
|
||||||
@Syntax("[--page <page>] [--filter <filter>]")
|
@Syntax("[--page <page>] [--filter <filter>]")
|
||||||
@Description("{@@mv-core.who.flags}")
|
@Description("{@@mv-core.who.flags.description}")
|
||||||
String[] flags) {
|
String[] flags) {
|
||||||
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
||||||
|
|
||||||
// Send the display
|
// Send the display
|
||||||
getListDisplay(worldManager.getLoadedWorlds(), parsedFlags.flagValue(PAGE_FLAG, 1), parsedFlags.flagValue(FILTER_FLAG, DefaultContentFilter.get())).send(issuer);
|
getListDisplay(
|
||||||
|
worldManager.getLoadedWorlds(),
|
||||||
|
parsedFlags.flagValue(PAGE_FLAG, 1),
|
||||||
|
parsedFlags.flagValue(FILTER_FLAG, DefaultContentFilter.get()),
|
||||||
|
true
|
||||||
|
).send(issuer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,35 +109,45 @@ public class WhoCommand extends MultiverseCommand {
|
|||||||
|
|
||||||
@Optional
|
@Optional
|
||||||
@Syntax("[--page <page>] [--filter <filter>]")
|
@Syntax("[--page <page>] [--filter <filter>]")
|
||||||
@Description("{@@mv-core.who.flags}")
|
@Description("{@@mv-core.who.flags.description}")
|
||||||
String[] flags) {
|
String[] flags) {
|
||||||
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
||||||
|
|
||||||
// Send the display
|
// Send the display
|
||||||
getListDisplay(inputtedWorld, parsedFlags.flagValue(PAGE_FLAG, 1), parsedFlags.flagValue(FILTER_FLAG, DefaultContentFilter.get())).send(issuer);
|
getListDisplay(
|
||||||
|
inputtedWorld,
|
||||||
|
parsedFlags.flagValue(PAGE_FLAG, 1),
|
||||||
|
parsedFlags.flagValue(FILTER_FLAG, DefaultContentFilter.get()),
|
||||||
|
false
|
||||||
|
).send(issuer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String phrasePlayerList(List<Player> players) {
|
private String phrasePlayerList(List<Player> players) {
|
||||||
return players.stream().map(Player::getName).collect(Collectors.joining(", "));
|
return players.stream().map(Player::getName).collect(Collectors.joining(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContentDisplay getListDisplay(LoadedMultiverseWorld world, int page, ContentFilter filter) {
|
private ContentDisplay getListDisplay(LoadedMultiverseWorld world, int page, ContentFilter filter, boolean ignoreEmptyWorlds) {
|
||||||
Collection<LoadedMultiverseWorld> listingWorlds = new ArrayList<>();
|
Collection<LoadedMultiverseWorld> listingWorlds = new ArrayList<>();
|
||||||
listingWorlds.add(world);
|
listingWorlds.add(world);
|
||||||
return getListDisplay(listingWorlds, page, filter);
|
return getListDisplay(listingWorlds, page, filter, ignoreEmptyWorlds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContentDisplay getListDisplay(Collection<LoadedMultiverseWorld> worlds, int page, ContentFilter filter) {
|
private ContentDisplay getListDisplay(Collection<LoadedMultiverseWorld> worlds, int page, ContentFilter filter, boolean ignoreEmptyWorlds) {
|
||||||
HashMap<String, String> outMap = new HashMap<>();
|
HashMap<String, String> outMap = new HashMap<>();
|
||||||
|
|
||||||
// Add all the worlds to our hashmap
|
// Add all the worlds to our hashmap
|
||||||
for (LoadedMultiverseWorld world : worlds) {
|
for (LoadedMultiverseWorld world : worlds) {
|
||||||
List<Player> players = world.getPlayers().getOrNull();
|
@Nullable List<Player> players = world.getPlayers().getOrNull();
|
||||||
|
|
||||||
// If the world has 0 players in it, ignore it
|
// If the world has 0 players in it, say that it is empty
|
||||||
if (players.isEmpty()) {
|
if ((players == null || players.isEmpty()) && !ignoreEmptyWorlds) {
|
||||||
|
outMap.put(world.getAlias(), ChatColor.RED + "Empty");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (players == null || players.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
outMap.put(world.getAlias(), phrasePlayerList(players));
|
outMap.put(world.getAlias(), phrasePlayerList(players));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,14 @@ public enum MVCorei18n implements MessageKeyProvider {
|
|||||||
UNLOAD_UNLOADING,
|
UNLOAD_UNLOADING,
|
||||||
UNLOAD_SUCCESS,
|
UNLOAD_SUCCESS,
|
||||||
|
|
||||||
|
// who command
|
||||||
|
WHO_DESCRIPTION,
|
||||||
|
WHO_ALL_DESCRIPTION,
|
||||||
|
WHO_WORLD_DESCRIPTION,
|
||||||
|
WHO_FLAGS_DESCRIPTION,
|
||||||
|
WHO_EMPTY,
|
||||||
|
|
||||||
|
|
||||||
// debug command
|
// debug command
|
||||||
DEBUG_INFO_OFF,
|
DEBUG_INFO_OFF,
|
||||||
DEBUG_INFO_ON,
|
DEBUG_INFO_ON,
|
||||||
|
@ -139,6 +139,14 @@ mv-core.unload.success=&aWorld '{world}' unloaded!
|
|||||||
# /mv usage
|
# /mv usage
|
||||||
mv-core.usage.description=Show Multiverse-Core command usage.
|
mv-core.usage.description=Show Multiverse-Core command usage.
|
||||||
|
|
||||||
|
# /mv who
|
||||||
|
# /mv whoall
|
||||||
|
mv-core.who.description=Lists the players in the world specified
|
||||||
|
mv-core.who.all.description=Lists the players in all worlds
|
||||||
|
mv-core.who.world.description=Name of the world you want to list players in
|
||||||
|
mv-core.who.flags.description=Filter - only shows entries matching this. Page - the page to show
|
||||||
|
mv-core.who.empty=&rEmpty
|
||||||
|
|
||||||
# commands error
|
# commands error
|
||||||
mv-core.commands.error.playersonly=&cThis command can only be used by players
|
mv-core.commands.error.playersonly=&cThis command can only be used by players
|
||||||
mv-core.commands.error.multiverseworldonly=&cThis can only be used in multiverse worlds
|
mv-core.commands.error.multiverseworldonly=&cThis can only be used in multiverse worlds
|
||||||
|
Loading…
Reference in New Issue
Block a user