Skip to content

Commit

Permalink
Use world.getName() for world placeholders
Browse files Browse the repository at this point in the history
Updated various command classes to use `world.getName()` instead of `world.key().asString()` for world placeholders. This improves code readability and ensures consistency across the methods dealing with world data representation in the `Placeholder` objects.
  • Loading branch information
NonSwag committed Nov 30, 2024
1 parent 8a066b5 commit 70ef403
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private int prune(CommandContext<CommandSourceStack> context, @Nullable World wo
@SneakyThrows
private void prune(CommandContext<CommandSourceStack> context, List<OfflinePlayer> players, @Nullable World world) {
var sender = context.getSource().getSender();
var placeholder = Placeholder.parsed("world", world != null ? world.key().asString() : "null");
var placeholder = Placeholder.parsed("world", world != null ? world.getName() : "null");
deleteAccounts(players.stream().map(OfflinePlayer::getUniqueId).toList(), world).thenAccept(success -> {
var message = players.isEmpty()
? (world != null ? "account.prune.none.world" : "account.prune.none")
Expand All @@ -163,14 +163,14 @@ private int create(CommandContext<CommandSourceStack> context, Collection<? exte
: (player.equals(sender) ? "account.created.self" : "account.created.other");
plugin.bundle().sendMessage(sender, message,
Placeholder.parsed("player", player.getName() != null ? player.getName() : player.getUniqueId().toString()),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));
}).exceptionally(throwable -> {
var message = world != null
? (player.equals(sender) ? "account.exists.world.self" : "account.exists.world.other")
: (player.equals(sender) ? "account.exists.self" : "account.exists.other");
plugin.bundle().sendMessage(sender, message,
Placeholder.parsed("player", player.getName() != null ? player.getName() : player.getUniqueId().toString()),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));
return null;
}));
return Command.SINGLE_SUCCESS;
Expand All @@ -188,7 +188,7 @@ private int delete(CommandContext<CommandSourceStack> context, Collection<? exte
: (player.equals(sender) ? "account.not-found.self" : "account.not-found.other"));
plugin.bundle().sendMessage(sender, message,
Placeholder.parsed("player", player.getName() != null ? player.getName() : player.getUniqueId().toString()),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));
}).exceptionally(throwable -> {
plugin.getComponentLogger().error("Failed to delete account for {}", player.getName(), throwable);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ private int balance(CommandContext<CommandSourceStack> context, OfflinePlayer pl
? controller.getCurrencyNameSingular(locale)
: controller.getCurrencyNamePlural(locale)),
Placeholder.parsed("symbol", controller.getCurrencySymbol()),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));

}, () -> plugin.bundle().sendMessage(sender, world != null
? (player.equals(sender) ? "account.not-found.world.self" : "account.not-found.world.other")
: (player.equals(sender) ? "account.not-found.self" : "account.not-found.other"),
Placeholder.parsed("player", String.valueOf(player.getName())),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"))));
Placeholder.parsed("world", world != null ? world.getName() : "null"))));

return Command.SINGLE_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ private void top(CommandSender sender, List<Account> accounts, int index, @Nulla
var totalBalance = plugin.dataController().getTotalBalance(world).doubleValue();

plugin.bundle().sendMessage(sender, world != null ? "balance.top-list.header.world" : "balance.top-list.header",
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));
plugin.bundle().sendMessage(sender, world != null ? "balance.top-list.total.world" : "balance.top-list.total",
Placeholder.parsed("symbol", plugin.economyController().getCurrencySymbol()),
Placeholder.parsed("total", plugin.economyController().format(totalBalance, locale)),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));

for (int i = 0; i < accounts.size(); i++) {
var account = accounts.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private int execute(CommandContext<CommandSourceStack> context, String successMe
.thenAccept(optional -> optional.ifPresentOrElse(account -> {
var balance = function.apply(account, amount);
plugin.bundle().sendMessage(sender, successMessage,
Placeholder.parsed("world", world != null ? world.key().asString() : "null"),
Placeholder.parsed("world", world != null ? world.getName() : "null"),
Placeholder.parsed("player", String.valueOf(player.getName())),
Placeholder.parsed("balance", plugin.economyController().format(balance, locale)),
Placeholder.parsed("amount", plugin.economyController().format(amount, locale)),
Expand All @@ -124,7 +124,7 @@ private int execute(CommandContext<CommandSourceStack> context, String successMe
? (sender.equals(player) ? "account.not-found.world.self" : "account.not-found.world.other")
: (sender.equals(player) ? "account.not-found.self" : "account.not-found.other"),
Placeholder.parsed("player", String.valueOf(player.getName())),
Placeholder.parsed("world", world != null ? world.key().asString() : "null")))));
Placeholder.parsed("world", world != null ? world.getName() : "null")))));
else plugin.bundle().sendMessage(sender, "player.define");
return Command.SINGLE_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ private void missingAccount(@Nullable World world, Player sender, OfflinePlayer
? (player.equals(sender) ? "account.not-found.world.self" : "account.not-found.world.other")
: (player.equals(sender) ? "account.not-found.self" : "account.not-found.other"),
Placeholder.parsed("player", player.getName() != null ? player.getName() : player.getUniqueId().toString()),
Placeholder.parsed("world", world != null ? world.key().asString() : "null"));
Placeholder.parsed("world", world != null ? world.getName() : "null"));
}
}

0 comments on commit 70ef403

Please sign in to comment.