Skip to content

Commit

Permalink
Add i18n and tell user when a world is empty when using /mv who
Browse files Browse the repository at this point in the history
  • Loading branch information
zax71 committed Feb 24, 2024
1 parent a6f4f2d commit c640a25
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.dumptruckman.minecraft.util.Logging;

Check warning on line 11 in src/main/java/org/mvplugins/multiverse/core/commands/WhoCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Unused import - com.dumptruckman.minecraft.util.Logging. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/WhoCommand.java:11:8: warning: Unused import - com.dumptruckman.minecraft.util.Logging. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import jakarta.inject.Inject;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;

Check warning on line 18 in src/main/java/org/mvplugins/multiverse/core/commands/WhoCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'org.mvplugins.multiverse.core.commandtools.MultiverseCommand' should be separated from previous imports. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/WhoCommand.java:18:1: warning: 'org.mvplugins.multiverse.core.commandtools.MultiverseCommand' should be separated from previous imports. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;

Check warning on line 19 in src/main/java/org/mvplugins/multiverse/core/commands/WhoCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Wrong order for 'org.mvplugins.multiverse.core.commandtools.MVCommandIssuer' import. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/WhoCommand.java:19:1: warning: Wrong order for 'org.mvplugins.multiverse.core.commandtools.MVCommandIssuer' import. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
Expand Down Expand Up @@ -79,12 +81,17 @@ void onWhoAllCommand(

@Optional
@Syntax("[--page <page>] [--filter <filter>]")
@Description("{@@mv-core.who.flags}")
@Description("{@@mv-core.who.flags.description}")
String[] flags) {
ParsedCommandFlags parsedFlags = parseFlags(flags);

// 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);

}

Expand All @@ -102,35 +109,45 @@ void onWhoCommand(

@Optional
@Syntax("[--page <page>] [--filter <filter>]")
@Description("{@@mv-core.who.flags}")
@Description("{@@mv-core.who.flags.description}")
String[] flags) {
ParsedCommandFlags parsedFlags = parseFlags(flags);

// 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) {
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<>();
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<>();

// Add all the worlds to our hashmap
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 (players.isEmpty()) {
// If the world has 0 players in it, say that it is empty
if ((players == null || players.isEmpty()) && !ignoreEmptyWorlds) {
outMap.put(world.getAlias(), ChatColor.RED + "Empty");
continue;
}
if (players == null || players.isEmpty()) {
continue;
}

outMap.put(world.getAlias(), phrasePlayerList(players));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public enum MVCorei18n implements MessageKeyProvider {
UNLOAD_UNLOADING,
UNLOAD_SUCCESS,

// who command
WHO_DESCRIPTION,
WHO_ALL_DESCRIPTION,
WHO_WORLD_DESCRIPTION,
WHO_FLAGS_DESCRIPTION,
WHO_EMPTY,


// debug command
DEBUG_INFO_OFF,
DEBUG_INFO_ON,
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/multiverse-core_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ mv-core.unload.success=&aWorld '{world}' unloaded!
# /mv 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

Check warning on line 145 in src/main/resources/multiverse-core_en.properties

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Property key 'mv-core.who.all.description' is not in the right order with previous property 'mv-core.who.description'. Raw Output: /github/workspace/./src/main/resources/multiverse-core_en.properties:145:0: warning: Property key 'mv-core.who.all.description' is not in the right order with previous property 'mv-core.who.description'. (com.puppycrawl.tools.checkstyle.checks.OrderedPropertiesCheck)
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

Check warning on line 147 in src/main/resources/multiverse-core_en.properties

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Property key 'mv-core.who.flags.description' is not in the right order with previous property 'mv-core.who.world.description'. Raw Output: /github/workspace/./src/main/resources/multiverse-core_en.properties:147:0: warning: Property key 'mv-core.who.flags.description' is not in the right order with previous property 'mv-core.who.world.description'. (com.puppycrawl.tools.checkstyle.checks.OrderedPropertiesCheck)
mv-core.who.empty=&rEmpty

Check warning on line 148 in src/main/resources/multiverse-core_en.properties

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Property key 'mv-core.who.empty' is not in the right order with previous property 'mv-core.who.flags.description'. Raw Output: /github/workspace/./src/main/resources/multiverse-core_en.properties:148:0: warning: Property key 'mv-core.who.empty' is not in the right order with previous property 'mv-core.who.flags.description'. (com.puppycrawl.tools.checkstyle.checks.OrderedPropertiesCheck)

# commands error
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
Expand Down

0 comments on commit c640a25

Please sign in to comment.