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 @@ -3,10 +3,8 @@
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.mvplugins.multiverse.core.MultiverseCoreApi;
import org.mvplugins.multiverse.core.config.CoreConfig;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.inject.PluginServiceLocatorFactory;
import org.mvplugins.multiverse.core.module.MultiverseModule;
import org.mvplugins.multiverse.core.utils.StringFormatter;
import org.mvplugins.multiverse.inventories.command.MVInvCommandConditions;
Expand All @@ -21,6 +19,7 @@
import org.mvplugins.multiverse.inventories.handleshare.SingleShareWriter;
import org.mvplugins.multiverse.inventories.handleshare.SpawnChangeListener;
import org.mvplugins.multiverse.inventories.handleshare.WriteOnlyShareHandler;
import org.mvplugins.multiverse.inventories.profile.PlayerNamesMapper;
import org.mvplugins.multiverse.inventories.profile.ProfileCacheManager;
import org.mvplugins.multiverse.inventories.profile.ProfileDataSource;
import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey;
Expand All @@ -31,8 +30,6 @@
import org.mvplugins.multiverse.inventories.util.ItemStackConverter;
import org.mvplugins.multiverse.inventories.util.Perm;
import org.bukkit.Bukkit;
import org.mvplugins.multiverse.core.command.MVCommandManager;
import org.mvplugins.multiverse.core.inject.PluginServiceLocator;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jakarta.inject.Provider;
import org.jvnet.hk2.annotations.Service;
Expand Down Expand Up @@ -61,6 +58,8 @@ public class MultiverseInventories extends MultiverseModule {
@Inject
private Provider<WorldGroupManager> worldGroupManager;
@Inject
private Provider<PlayerNamesMapper> playerNamesMapperProvider;
@Inject
private Provider<ProfileDataSource> profileDataSource;
@Inject
private Provider<ProfileCacheManager> profileCacheManager;
Expand Down Expand Up @@ -119,6 +118,7 @@ public final void onEnable() {
// Init other extensions
this.hookLuckPerms();
this.dupingPatch = InventoriesDupingPatch.enableDupingPatch(this);
this.playerNamesMapperProvider.get().loadMap();

Logging.config("Version %s (API v%s) Enabled - By %s",
this.getDescription().getVersion(), getVersionAsNumber(), StringFormatter.joinAnd(this.getDescription().getAuthors()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
import org.mvplugins.multiverse.core.command.MVCommandCompletions;
import org.mvplugins.multiverse.core.command.MVCommandManager;
import org.mvplugins.multiverse.core.config.handle.PropertyModifyAction;
import org.mvplugins.multiverse.core.utils.StringFormatter;
import org.mvplugins.multiverse.external.acf.commands.BukkitCommandCompletionContext;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.vavr.control.Try;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
import org.mvplugins.multiverse.inventories.dataimport.DataImportManager;
import org.mvplugins.multiverse.inventories.profile.PlayerNamesMapper;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroup;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroupManager;
import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey;
import org.mvplugins.multiverse.inventories.share.Sharables;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -28,21 +33,26 @@ public final class MVInvCommandCompletion {
private final InventoriesConfig inventoriesConfig;
private final WorldGroupManager worldGroupManager;
private final DataImportManager dataImportManager;
private final PlayerNamesMapper playerNamesMapper;

@Inject
private MVInvCommandCompletion(
@NotNull InventoriesConfig inventoriesConfig,
@NotNull WorldGroupManager worldGroupManager,
@NotNull DataImportManager dataImportManager,
@NotNull MVCommandManager mvCommandManager) {
@NotNull MVCommandManager mvCommandManager,
@NotNull PlayerNamesMapper playerNamesMapper
) {
this.inventoriesConfig = inventoriesConfig;
this.worldGroupManager = worldGroupManager;
this.dataImportManager = dataImportManager;
this.playerNamesMapper = playerNamesMapper;

MVCommandCompletions commandCompletions = mvCommandManager.getCommandCompletions();
commandCompletions.registerAsyncCompletion("dataimporters", this::suggestDataImporters);
commandCompletions.registerStaticCompletion("mvinvconfigs", inventoriesConfig.getStringPropertyHandle().getAllPropertyNames());
commandCompletions.registerAsyncCompletion("mvinvconfigvalues", this::suggestConfigValues);
commandCompletions.registerAsyncCompletion("mvinvplayernames", this::suggestPlayerNames);
commandCompletions.registerAsyncCompletion("sharables", this::suggestSharables);
commandCompletions.registerAsyncCompletion("shares", this::suggestShares);
commandCompletions.registerAsyncCompletion("worldGroups", this::suggestWorldGroups);
Expand All @@ -60,6 +70,25 @@ private Collection<String> suggestConfigValues(BukkitCommandCompletionContext co
.getOrElse(Collections.emptyList());
}

private Collection<String> suggestPlayerNames(BukkitCommandCompletionContext context) {
if (Objects.equals(context.getInput(), "@all")) {
return Collections.emptyList();
}
List<String> playerNames = getPlayerNames();
if (context.getInput().indexOf(',') == -1) {
playerNames.add("@all");
return playerNames;
}
return StringFormatter.addonToCommaSeperated(context.getInput(), playerNames);
}

private List<String> getPlayerNames() {
return playerNamesMapper.getKeys()
.stream()
.map(GlobalProfileKey::getPlayerName)
.collect(Collectors.toList());
}

private Collection<String> suggestSharables(BukkitCommandCompletionContext context) {
String scope = context.getConfig("scope", "enabled");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import org.bukkit.Bukkit;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.command.MVCommandManager;
import org.mvplugins.multiverse.core.utils.REPatterns;
import org.mvplugins.multiverse.external.acf.commands.BukkitCommandExecutionContext;
import org.mvplugins.multiverse.external.acf.commands.CommandContexts;
import org.mvplugins.multiverse.external.acf.commands.InvalidCommandArgument;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.vavr.control.Option;
import org.mvplugins.multiverse.inventories.profile.PlayerNamesMapper;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroup;
import org.mvplugins.multiverse.inventories.profile.group.WorldGroupManager;
import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey;
Expand All @@ -25,10 +27,16 @@
public final class MVInvCommandContexts {

private final WorldGroupManager worldGroupManager;
private final PlayerNamesMapper playerNamesMapper;

@Inject
private MVInvCommandContexts(@NotNull MVCommandManager commandManager, @NotNull WorldGroupManager worldGroupManager) {
private MVInvCommandContexts(
@NotNull MVCommandManager commandManager,
@NotNull WorldGroupManager worldGroupManager,
@NotNull PlayerNamesMapper playerNamesMapper
) {
this.worldGroupManager = worldGroupManager;
this.playerNamesMapper = playerNamesMapper;

CommandContexts<BukkitCommandExecutionContext> commandContexts = commandManager.getCommandContexts();
commandContexts.registerContext(GlobalProfileKey[].class, this::parseGlobalProfileKeys);
Expand All @@ -40,15 +48,14 @@ private MVInvCommandContexts(@NotNull MVCommandManager commandManager, @NotNull
private GlobalProfileKey[] parseGlobalProfileKeys(BukkitCommandExecutionContext context) {
String profileStrings = context.popFirstArg();
if (profileStrings.equals("@all")) {
return Arrays.stream(Bukkit.getOfflinePlayers())
.map(GlobalProfileKey::create)
.toArray(GlobalProfileKey[]::new);
return playerNamesMapper.getKeys().toArray(GlobalProfileKey[]::new);
}

String[] profileNames = profileStrings.split(",");
String[] profileNames = REPatterns.COMMA.split(profileStrings);
return Arrays.stream(profileNames)
.map(Bukkit::getOfflinePlayer)
.map(GlobalProfileKey::create)
.map(playerNamesMapper::getKey)
.filter(Option::isDefined)
.map(Option::get)
.toArray(GlobalProfileKey[]::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ final class ClearCommand extends InventoriesCommand {

@Subcommand("bulkedit globalprofile clear")
@CommandPermission("multiverse.inventories.bulkedit")
@CommandCompletion("@players @flags:groupName=" + Flags.NAME)
@Syntax("<players>")
@CommandCompletion("@mvinvplayernames @flags:groupName=" + Flags.NAME)
@Syntax("<players> [--clear-all-playerprofiles]")
void onCommand(
MVCommandIssuer issuer,

@Syntax("<players>")
GlobalProfileKey[] globalProfileKeys,

@Syntax("[--clear-all-playerprofiles]")
String[] flagArray
) {
ParsedCommandFlags parsedFlags = flags.parse(flagArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.mvplugins.multiverse.core.command.queue.CommandQueuePayload;
import org.mvplugins.multiverse.core.config.handle.PropertyModifyAction;
import org.mvplugins.multiverse.core.locale.message.Message;
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.Subcommand;
import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax;
Expand All @@ -32,6 +33,7 @@ final class ModifyCommand extends InventoriesCommand {

@Subcommand("bulkedit globalprofile modify")
@CommandPermission("multiverse.inventories.bulkedit")
@CommandCompletion("load-on-login|last-world @empty @mvinvplayernames")
@Syntax("<property> <value> <players>")
void onCommand(
MVCommandIssuer issuer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ final class FlatFileProfileDataSource implements ProfileDataSource {
private final AsyncFileIO asyncFileIO;
private final ProfileFilesLocator profileFilesLocator;
private final ProfileCacheManager profileCacheManager;
private final PlayerNamesMapper playerNamesMapper;

@Inject
FlatFileProfileDataSource(
@NotNull AsyncFileIO asyncFileIO,
@NotNull ProfileFilesLocator profileFilesLocator,
@NotNull ProfileCacheManager profileCacheManager
@NotNull ProfileCacheManager profileCacheManager,
@NotNull PlayerNamesMapper playerNamesMapper
) {
this.asyncFileIO = asyncFileIO;
this.profileFilesLocator = profileFilesLocator;
this.profileCacheManager = profileCacheManager;
this.playerNamesMapper = playerNamesMapper;
}

private FileConfiguration loadFileToJsonConfiguration(File file) {
Expand Down Expand Up @@ -263,7 +266,7 @@ public CompletableFuture<GlobalProfile> getGlobalProfile(GlobalProfileKey key) {
globalProfile.setLastKnownName(key.getPlayerName());
return CompletableFuture.completedFuture(globalProfile);
}
return asyncFileIO.queueFileCallable(globalFile, () -> getGlobalProfileFromDisk(key.getPlayerUUID(), key.getPlayerName(), globalFile));
return asyncFileIO.queueFileCallable(globalFile, () -> getGlobalProfileFromDisk(key.getPlayerUUID(), globalFile));
});
}

Expand All @@ -289,10 +292,8 @@ private void migrateGlobalProfileToUUID(UUID playerUUID, String playerName) {
}
}

private GlobalProfile getGlobalProfileFromDisk(UUID playerUUID, String playerName, File globalFile) {
GlobalProfile globalProfile = new GlobalProfile(playerUUID, globalFile.toPath());
globalProfile.setLastKnownName(playerName);
return globalProfile;
private GlobalProfile getGlobalProfileFromDisk(UUID playerUUID, File globalFile) {
return new GlobalProfile(playerUUID, globalFile.toPath());
}

/**
Expand All @@ -314,7 +315,11 @@ private CompletableFuture<Void> modifyGlobalProfile(GlobalProfile globalProfile,
@Override
public CompletableFuture<Void> updateGlobalProfile(GlobalProfile globalProfile) {
File globalFile = profileFilesLocator.getGlobalFile(globalProfile.getPlayerUUID().toString());
return asyncFileIO.queueFileAction(globalFile, () -> processGlobalProfileWrite(globalProfile));
boolean didPlayerNameChange = playerNamesMapper.setPlayerName(globalProfile.getPlayerUUID(), globalProfile.getLastKnownName());
return asyncFileIO.queueFileAction(globalFile, () -> processGlobalProfileWrite(globalProfile))
.thenCompose(ignore -> didPlayerNameChange
? asyncFileIO.queueFileAction(playerNamesMapper.getFile(), playerNamesMapper::savePlayerNames)
: CompletableFuture.completedFuture(null));
}

private void processGlobalProfileWrite(GlobalProfile globalProfile) {
Expand Down
Loading