Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.inventories.profile.ProfileCacheManager;
import org.mvplugins.multiverse.inventories.util.MVInvi18n;

import java.util.Map;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

@Service
final class CacheCommand extends InventoriesCommand {

Expand All @@ -30,15 +33,17 @@ final class CacheCommand extends InventoriesCommand {
void onCacheStatsCommand(MVCommandIssuer issuer) {
Map<String, CacheStats> stats = this.ProfileCacheManager.getCacheStats();
for (Map.Entry<String, CacheStats> entry : stats.entrySet()) {
issuer.sendMessage("Cache: " + entry.getKey());
issuer.sendMessage(" hits count: " + entry.getValue().hitCount());
issuer.sendMessage(" misses count: " + entry.getValue().missCount());
issuer.sendMessage(" loads count: " + entry.getValue().loadCount());
issuer.sendMessage(" evictions: " + entry.getValue().evictionCount());
issuer.sendMessage(" hit rate: " + entry.getValue().hitRate() * 100 + "%");
issuer.sendMessage(" miss rate: " + entry.getValue().missRate() * 100 + "%");
issuer.sendMessage(" avg load penalty: " + entry.getValue().averageLoadPenalty() / 1000000 + "ms");
issuer.sendMessage("--------");
CacheStats cacheStats = entry.getValue();
issuer.sendMessage(MVInvi18n.CACHE_ENTRY, replace("{cache}").with(entry.getKey()));
issuer.sendMessage(MVInvi18n.CACHE_HITSCOUNT, replace("{count}").with(cacheStats.hitCount()));
issuer.sendMessage(MVInvi18n.CACHE_MISSESCOUNT, replace("{count}").with(cacheStats.missCount()));
issuer.sendMessage(MVInvi18n.CACHE_LOADSCOUNT, replace("{count}").with(cacheStats.loadCount()));
issuer.sendMessage(MVInvi18n.CACHE_EVICTIONS, replace("{count}").with(cacheStats.evictionCount()));
issuer.sendMessage(MVInvi18n.CACHE_HITRATE, replace("{rate}").with(cacheStats.hitRate() * 100));
issuer.sendMessage(MVInvi18n.CACHE_MISSRATE, replace("{rate}").with(cacheStats.missRate() * 100));
issuer.sendMessage(MVInvi18n.CACHE_AVGLOADPENALTY,
replace("{milliseconds}").with(cacheStats.averageLoadPenalty() / 1000000));
issuer.sendMessage(MVInvi18n.CACHE_SEPARATOR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
import org.mvplugins.multiverse.core.command.MVCommandManager;
import org.mvplugins.multiverse.core.exceptions.MultiverseException;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission;
import org.mvplugins.multiverse.external.acf.commands.annotation.Description;
import org.mvplugins.multiverse.external.acf.commands.annotation.Optional;
import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand;
import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.vavr.control.Option;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
import org.mvplugins.multiverse.inventories.util.MVInvi18n;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

@Service
final class ConfigCommand extends InventoriesCommand {
Expand Down Expand Up @@ -51,18 +50,23 @@ void onConfigCommand(

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

private void updateConfigValue(MVCommandIssuer issuer, String name, String value) {
// TODO: Update with localization
config.getStringPropertyHandle().setPropertyString(name, value)
.onSuccess(ignore -> {
config.save();
issuer.sendMessage("Successfully set " + name + " to " + value);
issuer.sendMessage(MVInvi18n.CONFIG_SET,
replace("{name}").with(name),
replace("{value}").with(value));
})
.onFailure(ignore -> issuer.sendMessage("Unable to set " + name + " to " + value + "."))
.onFailure(MultiverseException.class, e -> Option.of(e.getLocalizableMessage()).peek(issuer::sendError));
.onFailure(e -> issuer.sendError(MVInvi18n.CONFIG_SETFAILED,
replace("{name}").with(name),
replace("{value}").with(value),
replace("{error}").with(e)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
import org.mvplugins.multiverse.inventories.profile.key.ProfileType;
import org.mvplugins.multiverse.inventories.profile.key.ProfileTypes;
import org.mvplugins.multiverse.inventories.share.Sharables;
import org.mvplugins.multiverse.inventories.util.MVInvi18n;
import org.mvplugins.multiverse.inventories.util.PlayerStats;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

@Service
final class GiveCommand extends InventoriesCommand {

Expand Down Expand Up @@ -85,16 +88,19 @@ void onGiveCommand(
&& world.getName().equals(onlinePlayer.getWorld().getName())
&& ProfileTypes.forPlayer(onlinePlayer).equals(profileType)) {
onlinePlayer.getInventory().addItem(itemStack);
issuer.sendInfo("Gave player %s %s %s in world %s."
.formatted(player.getName(), itemStack.getAmount(), itemStack, world.getName()));
issuer.sendInfo(MVInvi18n.GIVE_SUCCESS,
replace("{player}").with(player.getName()),
replace("{amount}").with(itemStack.getAmount()),
replace("{item}").with(itemStack),
replace("{world}").with(world.getName()));
return;
}

SingleShareReader.of(inventories, player, world.getName(), profileType, Sharables.INVENTORY)
.read()
.thenCompose(inventory -> updatePlayerInventory(issuer, player, world, profileType, inventory, itemStack))
.exceptionally(throwable -> {
issuer.sendError(throwable.getMessage());
issuer.sendError(MVInvi18n.GIVE_FAILED, replace("{error}").with(throwable));
return null;
});
}
Expand All @@ -111,11 +117,11 @@ void onGiveCommand(
.getOrElse(1);
}
if (amount < 1) {
issuer.sendError("You have to give at least 1 item.");
issuer.sendError(MVInvi18n.GIVE_INVALIDAMOUNT);
return null;
}
if (amount > 6400) {
issuer.sendError("Cannot give more than 6400 items at once.");
issuer.sendError(MVInvi18n.GIVE_AMOUNTTOOLARGE, replace("{amount}").with(6400));
return null;
}
// Remove amount string from item
Expand All @@ -128,7 +134,7 @@ void onGiveCommand(
String itemName = split[0];
Material material = Material.matchMaterial(itemName);
if (material == null) {
issuer.sendError("Invalid Material: " + split[0]);
issuer.sendError(MVInvi18n.GIVE_INVALIDMATERIAL, replace("{material}").with(split[0]));
return null;
}

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

Expand All @@ -157,8 +163,11 @@ private CompletableFuture<Void> updatePlayerInventory(
.thenCompose(ignore -> player.isOnline()
? CompletableFuture.completedFuture(null)
: profileDataSource.modifyGlobalProfile(GlobalProfileKey.of(player), profile -> profile.setLoadOnLogin(true)))
.thenRun(() -> issuer.sendInfo("Gave player %s %s %s in world %s."
.formatted(player.getName(), itemStack.getAmount(), itemStack.getI18NDisplayName(), world.getName())));
.thenRun(() -> issuer.sendInfo(MVInvi18n.GIVE_SUCCESS,
replace("{player}").with(player.getName()),
replace("{amount}").with(itemStack.getAmount()),
replace("{item}").with(itemStack.getI18NDisplayName()),
replace("{world}").with(world.getName())));
}

private void putItemInInventory(@Nullable ItemStack[] inventory, @NotNull ItemStack itemStack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.world.MultiverseWorld;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission;
Expand All @@ -20,8 +20,12 @@
import org.mvplugins.multiverse.inventories.MultiverseInventories;
import org.mvplugins.multiverse.inventories.view.InventoryDataProvider;
import org.mvplugins.multiverse.inventories.view.InventoryGUIHelper;
import org.mvplugins.multiverse.inventories.view.InventoryStatus;
import org.mvplugins.multiverse.inventories.view.ModifiableInventoryHolder;
import org.mvplugins.multiverse.inventories.view.PlayerInventoryData;
import org.mvplugins.multiverse.inventories.util.MVInvi18n;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

@Service
final class InventoryModifyCommand extends InventoriesCommand {
Expand Down Expand Up @@ -63,7 +67,7 @@ void onInventoryModifyCommand(
MultiverseWorld world
) {
String worldName = world.getName();
issuer.sendInfo(ChatColor.YELLOW + "Loading inventory data for " + targetPlayer.getName() + "...");
issuer.sendInfo(MVInvi18n.INVENTORY_LOADING, replace("{player}").with(targetPlayer.getName()));
handleInventoryLoadAndDisplay(issuer, player, targetPlayer, worldName);
}

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

.exceptionally(throwable -> {
// This block runs if an exception occurs during data loading
String errorMessage = throwable.getMessage();
String errorMessage = throwable.getLocalizedMessage();
if (errorMessage == null || errorMessage.isEmpty()) {
errorMessage = "An unknown error occurred while loading inventory data.";
issuer.sendError(MVInvi18n.INVENTORY_LOADFAILED,
replace("{error}").with(Message.of(MVInvi18n.INVENTORY_UNKNOWNLOADERROR)));
} else {
issuer.sendError(MVInvi18n.INVENTORY_LOADFAILED, replace("{error}").with(throwable));
}
issuer.sendError(ChatColor.RED + errorMessage);
Logging.fine("Error loading inventory for " + targetPlayer.getName() + ": " + throwable.getMessage());
throwable.printStackTrace();
return null;
Expand Down Expand Up @@ -141,6 +147,18 @@ private void createAndOpenGUI(
// Call the helper method to populate the GUI
inventoryGUIHelper.populateInventoryGUI(inv, playerInventoryData, true);
player.openInventory(inv);
issuer.sendInfo(ChatColor.GREEN + playerInventoryData.status.getFormattedMessage(targetPlayer.getName(), worldName) + ". Changes will save on close.");
issuer.sendInfo(MVInvi18n.INVENTORY_OPENED,
replace("{status}").with(getStatusMessage(playerInventoryData.status, targetPlayer.getName(), worldName)));
}

private Message getStatusMessage(InventoryStatus status, String playerName, String worldName) {
MVInvi18n messageKey = switch (status) {
case LIVE_INVENTORY -> MVInvi18n.INVENTORY_LIVEINVENTORY;
case STORED_INVENTORY -> MVInvi18n.INVENTORY_STOREDINVENTORY;
case NO_DATA_FOUND -> MVInvi18n.INVENTORY_NODATAFOUND;
};
return Message.of(messageKey,
replace("{player}").with(playerName),
replace("{world}").with(worldName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.world.MultiverseWorld;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion;
import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission;
Expand All @@ -22,6 +22,10 @@
import org.mvplugins.multiverse.inventories.view.PlayerInventoryData;
import org.mvplugins.multiverse.inventories.view.ReadOnlyInventoryHolder;
import org.mvplugins.multiverse.inventories.view.InventoryDataProvider;
import org.mvplugins.multiverse.inventories.view.InventoryStatus;
import org.mvplugins.multiverse.inventories.util.MVInvi18n;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;

@Service
final class InventoryViewCommand extends InventoriesCommand {
Expand Down Expand Up @@ -64,7 +68,7 @@ void onInventoryViewCommand(
String worldName = world.getName();

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

Expand All @@ -90,7 +94,7 @@ private void handleInventoryLoadAndDisplay(
})
.exceptionally(throwable -> {
// This block runs if an exception occurs during data loading
issuer.sendError(ChatColor.RED + "Failed to load inventory data: " + throwable.getMessage());
issuer.sendError(MVInvi18n.INVENTORY_LOADFAILED, replace("{error}").with(throwable));
Logging.severe("Error loading inventory for " + targetPlayer.getName() + ": " + throwable.getMessage());
throwable.printStackTrace();
return null; // Must return null for CompletableFuture<Void> in exceptionally
Expand Down Expand Up @@ -123,6 +127,18 @@ private void createAndOpenGUI(
// Call the helper method to populate the GUI
inventoryGUIHelper.populateInventoryGUI(inv, playerInventoryData, false);
player.openInventory(inv);
issuer.sendInfo(ChatColor.GREEN + playerInventoryData.status.getFormattedMessage(targetPlayer.getName(), worldName) + ". Changes will save on close.");
issuer.sendInfo(MVInvi18n.INVENTORY_OPENED,
replace("{status}").with(getStatusMessage(playerInventoryData.status, targetPlayer.getName(), worldName)));
}

private Message getStatusMessage(InventoryStatus status, String playerName, String worldName) {
MVInvi18n messageKey = switch (status) {
case LIVE_INVENTORY -> MVInvi18n.INVENTORY_LIVEINVENTORY;
case STORED_INVENTORY -> MVInvi18n.INVENTORY_STOREDINVENTORY;
case NO_DATA_FOUND -> MVInvi18n.INVENTORY_NODATAFOUND;
};
return Message.of(messageKey,
replace("{player}").with(playerName),
replace("{world}").with(worldName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
@Service
final class MigrateCommand extends InventoriesCommand {

private static final String IMPORTER_DOWNLOAD_URL = "https://modrinth.com/project/multiverse-inventoriesimporter/";
private static final String IMPORTER_LEARN_MORE_URL = "https://mvplugins.org/inventories/how-to/import-playerdata/";

private final DataImportManager dataImportManager;
private final CommandQueueManager commandQueueManager;

Expand All @@ -48,9 +51,9 @@ void onMigrateCommand(
String pluginName) {

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

Expand Down
Loading
Loading