Skip to content

Commit 235e301

Browse files
authored
Merge pull request #668 from Multiverse/feat/complete-locales
Refactor all remaining issuer raw string messages to use localized strings
2 parents 2045275 + bc0d1a2 commit 235e301

23 files changed

Lines changed: 431 additions & 95 deletions

src/main/java/org/mvplugins/multiverse/inventories/commands/CacheCommand.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
1313
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
1414
import org.mvplugins.multiverse.inventories.profile.ProfileCacheManager;
15+
import org.mvplugins.multiverse.inventories.util.MVInvi18n;
1516

1617
import java.util.Map;
1718

19+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
20+
1821
@Service
1922
final class CacheCommand extends InventoriesCommand {
2023

@@ -30,15 +33,17 @@ final class CacheCommand extends InventoriesCommand {
3033
void onCacheStatsCommand(MVCommandIssuer issuer) {
3134
Map<String, CacheStats> stats = this.ProfileCacheManager.getCacheStats();
3235
for (Map.Entry<String, CacheStats> entry : stats.entrySet()) {
33-
issuer.sendMessage("Cache: " + entry.getKey());
34-
issuer.sendMessage(" hits count: " + entry.getValue().hitCount());
35-
issuer.sendMessage(" misses count: " + entry.getValue().missCount());
36-
issuer.sendMessage(" loads count: " + entry.getValue().loadCount());
37-
issuer.sendMessage(" evictions: " + entry.getValue().evictionCount());
38-
issuer.sendMessage(" hit rate: " + entry.getValue().hitRate() * 100 + "%");
39-
issuer.sendMessage(" miss rate: " + entry.getValue().missRate() * 100 + "%");
40-
issuer.sendMessage(" avg load penalty: " + entry.getValue().averageLoadPenalty() / 1000000 + "ms");
41-
issuer.sendMessage("--------");
36+
CacheStats cacheStats = entry.getValue();
37+
issuer.sendMessage(MVInvi18n.CACHE_ENTRY, replace("{cache}").with(entry.getKey()));
38+
issuer.sendMessage(MVInvi18n.CACHE_HITSCOUNT, replace("{count}").with(cacheStats.hitCount()));
39+
issuer.sendMessage(MVInvi18n.CACHE_MISSESCOUNT, replace("{count}").with(cacheStats.missCount()));
40+
issuer.sendMessage(MVInvi18n.CACHE_LOADSCOUNT, replace("{count}").with(cacheStats.loadCount()));
41+
issuer.sendMessage(MVInvi18n.CACHE_EVICTIONS, replace("{count}").with(cacheStats.evictionCount()));
42+
issuer.sendMessage(MVInvi18n.CACHE_HITRATE, replace("{rate}").with(cacheStats.hitRate() * 100));
43+
issuer.sendMessage(MVInvi18n.CACHE_MISSRATE, replace("{rate}").with(cacheStats.missRate() * 100));
44+
issuer.sendMessage(MVInvi18n.CACHE_AVGLOADPENALTY,
45+
replace("{milliseconds}").with(cacheStats.averageLoadPenalty() / 1000000));
46+
issuer.sendMessage(MVInvi18n.CACHE_SEPARATOR);
4247
}
4348
}
4449

src/main/java/org/mvplugins/multiverse/inventories/commands/ConfigCommand.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.jvnet.hk2.annotations.Service;
55
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
6-
import org.mvplugins.multiverse.core.command.MVCommandManager;
7-
import org.mvplugins.multiverse.core.exceptions.MultiverseException;
8-
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias;
96
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion;
107
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission;
118
import org.mvplugins.multiverse.external.acf.commands.annotation.Description;
129
import org.mvplugins.multiverse.external.acf.commands.annotation.Optional;
1310
import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand;
1411
import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax;
1512
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
16-
import org.mvplugins.multiverse.external.vavr.control.Option;
1713
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
14+
import org.mvplugins.multiverse.inventories.util.MVInvi18n;
15+
16+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
1817

1918
@Service
2019
final class ConfigCommand extends InventoriesCommand {
@@ -51,18 +50,23 @@ void onConfigCommand(
5150

5251
private void showConfigValue(MVCommandIssuer issuer, String name) {
5352
config.getStringPropertyHandle().getProperty(name)
54-
.onSuccess(value -> issuer.sendMessage(name + "is currently set to " + value))
55-
.onFailure(e -> issuer.sendMessage(e.getMessage()));
53+
.onSuccess(value -> issuer.sendMessage(MVInvi18n.CONFIG_CURRENTVALUE,
54+
replace("{name}").with(name),
55+
replace("{value}").with(value)))
56+
.onFailure(e -> issuer.sendError(MVInvi18n.CONFIG_SHOWFAILED, replace("{error}").with(e)));
5657
}
5758

5859
private void updateConfigValue(MVCommandIssuer issuer, String name, String value) {
59-
// TODO: Update with localization
6060
config.getStringPropertyHandle().setPropertyString(name, value)
6161
.onSuccess(ignore -> {
6262
config.save();
63-
issuer.sendMessage("Successfully set " + name + " to " + value);
63+
issuer.sendMessage(MVInvi18n.CONFIG_SET,
64+
replace("{name}").with(name),
65+
replace("{value}").with(value));
6466
})
65-
.onFailure(ignore -> issuer.sendMessage("Unable to set " + name + " to " + value + "."))
66-
.onFailure(MultiverseException.class, e -> Option.of(e.getLocalizableMessage()).peek(issuer::sendError));
67+
.onFailure(e -> issuer.sendError(MVInvi18n.CONFIG_SETFAILED,
68+
replace("{name}").with(name),
69+
replace("{value}").with(value),
70+
replace("{error}").with(e)));
6771
}
6872
}

src/main/java/org/mvplugins/multiverse/inventories/commands/GiveCommand.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
import org.mvplugins.multiverse.inventories.profile.key.ProfileType;
2828
import org.mvplugins.multiverse.inventories.profile.key.ProfileTypes;
2929
import org.mvplugins.multiverse.inventories.share.Sharables;
30+
import org.mvplugins.multiverse.inventories.util.MVInvi18n;
3031
import org.mvplugins.multiverse.inventories.util.PlayerStats;
3132

3233
import java.util.concurrent.CompletableFuture;
3334
import java.util.concurrent.atomic.AtomicBoolean;
3435

36+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
37+
3538
@Service
3639
final class GiveCommand extends InventoriesCommand {
3740

@@ -85,16 +88,19 @@ void onGiveCommand(
8588
&& world.getName().equals(onlinePlayer.getWorld().getName())
8689
&& ProfileTypes.forPlayer(onlinePlayer).equals(profileType)) {
8790
onlinePlayer.getInventory().addItem(itemStack);
88-
issuer.sendInfo("Gave player %s %s %s in world %s."
89-
.formatted(player.getName(), itemStack.getAmount(), itemStack, world.getName()));
91+
issuer.sendInfo(MVInvi18n.GIVE_SUCCESS,
92+
replace("{player}").with(player.getName()),
93+
replace("{amount}").with(itemStack.getAmount()),
94+
replace("{item}").with(itemStack),
95+
replace("{world}").with(world.getName()));
9096
return;
9197
}
9298

9399
SingleShareReader.of(inventories, player, world.getName(), profileType, Sharables.INVENTORY)
94100
.read()
95101
.thenCompose(inventory -> updatePlayerInventory(issuer, player, world, profileType, inventory, itemStack))
96102
.exceptionally(throwable -> {
97-
issuer.sendError(throwable.getMessage());
103+
issuer.sendError(MVInvi18n.GIVE_FAILED, replace("{error}").with(throwable));
98104
return null;
99105
});
100106
}
@@ -111,11 +117,11 @@ void onGiveCommand(
111117
.getOrElse(1);
112118
}
113119
if (amount < 1) {
114-
issuer.sendError("You have to give at least 1 item.");
120+
issuer.sendError(MVInvi18n.GIVE_INVALIDAMOUNT);
115121
return null;
116122
}
117123
if (amount > 6400) {
118-
issuer.sendError("Cannot give more than 6400 items at once.");
124+
issuer.sendError(MVInvi18n.GIVE_AMOUNTTOOLARGE, replace("{amount}").with(6400));
119125
return null;
120126
}
121127
// Remove amount string from item
@@ -128,7 +134,7 @@ void onGiveCommand(
128134
String itemName = split[0];
129135
Material material = Material.matchMaterial(itemName);
130136
if (material == null) {
131-
issuer.sendError("Invalid Material: " + split[0]);
137+
issuer.sendError(MVInvi18n.GIVE_INVALIDMATERIAL, replace("{material}").with(split[0]));
132138
return null;
133139
}
134140

@@ -139,7 +145,7 @@ void onGiveCommand(
139145
}
140146
String additionalData = split[1];
141147
return Try.of(() -> Bukkit.getUnsafe().modifyItemStack(itemStack, itemStack.getType().getKey() + "[" + additionalData))
142-
.onFailure(throwable -> issuer.sendError(throwable.getMessage()))
148+
.onFailure(throwable -> issuer.sendError(MVInvi18n.GIVE_FAILED, replace("{error}").with(throwable)))
143149
.getOrNull();
144150
}
145151

@@ -157,8 +163,11 @@ private CompletableFuture<Void> updatePlayerInventory(
157163
.thenCompose(ignore -> player.isOnline()
158164
? CompletableFuture.completedFuture(null)
159165
: profileDataSource.modifyGlobalProfile(GlobalProfileKey.of(player), profile -> profile.setLoadOnLogin(true)))
160-
.thenRun(() -> issuer.sendInfo("Gave player %s %s %s in world %s."
161-
.formatted(player.getName(), itemStack.getAmount(), itemStack.getI18NDisplayName(), world.getName())));
166+
.thenRun(() -> issuer.sendInfo(MVInvi18n.GIVE_SUCCESS,
167+
replace("{player}").with(player.getName()),
168+
replace("{amount}").with(itemStack.getAmount()),
169+
replace("{item}").with(itemStack.getI18NDisplayName()),
170+
replace("{world}").with(world.getName())));
162171
}
163172

164173
private void putItemInInventory(@Nullable ItemStack[] inventory, @NotNull ItemStack itemStack) {

src/main/java/org/mvplugins/multiverse/inventories/commands/InventoryModifyCommand.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.dumptruckman.minecraft.util.Logging;
44
import org.bukkit.Bukkit;
5-
import org.bukkit.ChatColor;
65
import org.bukkit.OfflinePlayer;
76
import org.bukkit.entity.Player;
87
import org.bukkit.inventory.Inventory;
98
import org.jvnet.hk2.annotations.Service;
109
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
10+
import org.mvplugins.multiverse.core.locale.message.Message;
1111
import org.mvplugins.multiverse.core.world.MultiverseWorld;
1212
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion;
1313
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission;
@@ -20,8 +20,12 @@
2020
import org.mvplugins.multiverse.inventories.MultiverseInventories;
2121
import org.mvplugins.multiverse.inventories.view.InventoryDataProvider;
2222
import org.mvplugins.multiverse.inventories.view.InventoryGUIHelper;
23+
import org.mvplugins.multiverse.inventories.view.InventoryStatus;
2324
import org.mvplugins.multiverse.inventories.view.ModifiableInventoryHolder;
2425
import org.mvplugins.multiverse.inventories.view.PlayerInventoryData;
26+
import org.mvplugins.multiverse.inventories.util.MVInvi18n;
27+
28+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
2529

2630
@Service
2731
final class InventoryModifyCommand extends InventoriesCommand {
@@ -63,7 +67,7 @@ void onInventoryModifyCommand(
6367
MultiverseWorld world
6468
) {
6569
String worldName = world.getName();
66-
issuer.sendInfo(ChatColor.YELLOW + "Loading inventory data for " + targetPlayer.getName() + "...");
70+
issuer.sendInfo(MVInvi18n.INVENTORY_LOADING, replace("{player}").with(targetPlayer.getName()));
6771
handleInventoryLoadAndDisplay(issuer, player, targetPlayer, worldName);
6872
}
6973

@@ -89,7 +93,7 @@ private void handleInventoryLoadAndDisplay(
8993
// If the player tries to modify their own live inventory, stop
9094
if (player.getUniqueId().equals(targetPlayer.getUniqueId())
9195
&& player.getWorld().getName().equalsIgnoreCase(worldName)) {
92-
issuer.sendError(ChatColor.RED + "You cannot modify your own live inventory using this command. Use your regular inventory.");
96+
issuer.sendError(MVInvi18n.INVENTORY_MODIFYLIVESELF);
9397
return; // Stop here if it's a live self-inventory
9498
}
9599
createAndOpenGUI(issuer, player, targetPlayer, worldName, playerInventoryData);
@@ -99,11 +103,13 @@ private void handleInventoryLoadAndDisplay(
99103

100104
.exceptionally(throwable -> {
101105
// This block runs if an exception occurs during data loading
102-
String errorMessage = throwable.getMessage();
106+
String errorMessage = throwable.getLocalizedMessage();
103107
if (errorMessage == null || errorMessage.isEmpty()) {
104-
errorMessage = "An unknown error occurred while loading inventory data.";
108+
issuer.sendError(MVInvi18n.INVENTORY_LOADFAILED,
109+
replace("{error}").with(Message.of(MVInvi18n.INVENTORY_UNKNOWNLOADERROR)));
110+
} else {
111+
issuer.sendError(MVInvi18n.INVENTORY_LOADFAILED, replace("{error}").with(throwable));
105112
}
106-
issuer.sendError(ChatColor.RED + errorMessage);
107113
Logging.fine("Error loading inventory for " + targetPlayer.getName() + ": " + throwable.getMessage());
108114
throwable.printStackTrace();
109115
return null;
@@ -141,6 +147,18 @@ private void createAndOpenGUI(
141147
// Call the helper method to populate the GUI
142148
inventoryGUIHelper.populateInventoryGUI(inv, playerInventoryData, true);
143149
player.openInventory(inv);
144-
issuer.sendInfo(ChatColor.GREEN + playerInventoryData.status.getFormattedMessage(targetPlayer.getName(), worldName) + ". Changes will save on close.");
150+
issuer.sendInfo(MVInvi18n.INVENTORY_OPENED,
151+
replace("{status}").with(getStatusMessage(playerInventoryData.status, targetPlayer.getName(), worldName)));
152+
}
153+
154+
private Message getStatusMessage(InventoryStatus status, String playerName, String worldName) {
155+
MVInvi18n messageKey = switch (status) {
156+
case LIVE_INVENTORY -> MVInvi18n.INVENTORY_LIVEINVENTORY;
157+
case STORED_INVENTORY -> MVInvi18n.INVENTORY_STOREDINVENTORY;
158+
case NO_DATA_FOUND -> MVInvi18n.INVENTORY_NODATAFOUND;
159+
};
160+
return Message.of(messageKey,
161+
replace("{player}").with(playerName),
162+
replace("{world}").with(worldName));
145163
}
146164
}

src/main/java/org/mvplugins/multiverse/inventories/commands/InventoryViewCommand.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.dumptruckman.minecraft.util.Logging;
44
import org.bukkit.Bukkit;
5-
import org.bukkit.ChatColor;
65
import org.bukkit.OfflinePlayer;
76
import org.bukkit.entity.Player;
87
import org.bukkit.inventory.Inventory;
98
import org.jvnet.hk2.annotations.Service;
109
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
10+
import org.mvplugins.multiverse.core.locale.message.Message;
1111
import org.mvplugins.multiverse.core.world.MultiverseWorld;
1212
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion;
1313
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission;
@@ -22,6 +22,10 @@
2222
import org.mvplugins.multiverse.inventories.view.PlayerInventoryData;
2323
import org.mvplugins.multiverse.inventories.view.ReadOnlyInventoryHolder;
2424
import org.mvplugins.multiverse.inventories.view.InventoryDataProvider;
25+
import org.mvplugins.multiverse.inventories.view.InventoryStatus;
26+
import org.mvplugins.multiverse.inventories.util.MVInvi18n;
27+
28+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
2529

2630
@Service
2731
final class InventoryViewCommand extends InventoriesCommand {
@@ -64,7 +68,7 @@ void onInventoryViewCommand(
6468
String worldName = world.getName();
6569

6670
// Asynchronously load data using InventoryDataProvider
67-
issuer.sendInfo(ChatColor.YELLOW + "Loading inventory data for " + targetPlayer.getName() + "...");
71+
issuer.sendInfo(MVInvi18n.INVENTORY_LOADING, replace("{player}").with(targetPlayer.getName()));
6872
handleInventoryLoadAndDisplay(issuer, player, targetPlayer, worldName);
6973
}
7074

@@ -90,7 +94,7 @@ private void handleInventoryLoadAndDisplay(
9094
})
9195
.exceptionally(throwable -> {
9296
// This block runs if an exception occurs during data loading
93-
issuer.sendError(ChatColor.RED + "Failed to load inventory data: " + throwable.getMessage());
97+
issuer.sendError(MVInvi18n.INVENTORY_LOADFAILED, replace("{error}").with(throwable));
9498
Logging.severe("Error loading inventory for " + targetPlayer.getName() + ": " + throwable.getMessage());
9599
throwable.printStackTrace();
96100
return null; // Must return null for CompletableFuture<Void> in exceptionally
@@ -123,6 +127,18 @@ private void createAndOpenGUI(
123127
// Call the helper method to populate the GUI
124128
inventoryGUIHelper.populateInventoryGUI(inv, playerInventoryData, false);
125129
player.openInventory(inv);
126-
issuer.sendInfo(ChatColor.GREEN + playerInventoryData.status.getFormattedMessage(targetPlayer.getName(), worldName) + ". Changes will save on close.");
130+
issuer.sendInfo(MVInvi18n.INVENTORY_OPENED,
131+
replace("{status}").with(getStatusMessage(playerInventoryData.status, targetPlayer.getName(), worldName)));
132+
}
133+
134+
private Message getStatusMessage(InventoryStatus status, String playerName, String worldName) {
135+
MVInvi18n messageKey = switch (status) {
136+
case LIVE_INVENTORY -> MVInvi18n.INVENTORY_LIVEINVENTORY;
137+
case STORED_INVENTORY -> MVInvi18n.INVENTORY_STOREDINVENTORY;
138+
case NO_DATA_FOUND -> MVInvi18n.INVENTORY_NODATAFOUND;
139+
};
140+
return Message.of(messageKey,
141+
replace("{player}").with(playerName),
142+
replace("{world}").with(worldName));
127143
}
128144
}

src/main/java/org/mvplugins/multiverse/inventories/commands/MigrateCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
@Service
2424
final class MigrateCommand extends InventoriesCommand {
2525

26+
private static final String IMPORTER_DOWNLOAD_URL = "https://modrinth.com/project/multiverse-inventoriesimporter/";
27+
private static final String IMPORTER_LEARN_MORE_URL = "https://mvplugins.org/inventories/how-to/import-playerdata/";
28+
2629
private final DataImportManager dataImportManager;
2730
private final CommandQueueManager commandQueueManager;
2831

@@ -48,9 +51,9 @@ void onMigrateCommand(
4851
String pluginName) {
4952

5053
if (dataImportManager.getEnabledImporterNames().isEmpty()) {
51-
issuer.sendError("Please install Multiverse-InventoriesImporter plugin to use this command.");
52-
issuer.sendInfo("Download Link: https://modrinth.com/project/multiverse-inventoriesimporter/");
53-
issuer.sendInfo("Learn More: https://mvplugins.org/inventories/how-to/import-playerdata/");
54+
issuer.sendError(MVInvi18n.MIGRATE_IMPORTERNOTINSTALLED);
55+
issuer.sendInfo(MVInvi18n.MIGRATE_DOWNLOADLINK, replace("{url}").with(IMPORTER_DOWNLOAD_URL));
56+
issuer.sendInfo(MVInvi18n.MIGRATE_LEARNMORE, replace("{url}").with(IMPORTER_LEARN_MORE_URL));
5457
return;
5558
}
5659

0 commit comments

Comments
 (0)