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
19 changes: 0 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ group = 'org.mvplugins.multiverse.inventories'
description = 'Multiverse-Inventories'

repositories {
maven {
name = 'codemc'
url = uri('https://repo.codemc.org/repository/maven-releases')
}

maven {
name = "helpchatRepoReleases"
url = uri("https://repo.helpch.at/releases/")
Expand Down Expand Up @@ -59,24 +54,10 @@ dependencies {
// Luckperms for group context
compileOnly 'net.luckperms:api:5.4'

// Other plugins for import
compileOnly('uk.co:MultiInv:3.0.6') {
exclude group: '*', module: '*'
}
compileOnly('me.drayshak:WorldInventories:1.0.2') {
exclude group: '*', module: '*'
}
// perworldinventory is weird and has snakeyaml included in the jar, so we can only use compileOnly for build to work properly
compileOnly('me.ebonjaeger:perworldinventory-kt:2.3.2') {
exclude group: '*', module: '*'
}

// hk2 for annotation processing only
compileOnly('org.glassfish.hk2:hk2-api:3.1.1') {
exclude group: '*', module: '*'
}
annotationProcessor 'org.glassfish.hk2:hk2-metadata-generator:3.1.1'
testAnnotationProcessor 'org.glassfish.hk2:hk2-metadata-generator:3.1.1'
}

shadowJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public class MultiverseInventories extends MultiverseModule {
@Inject
private Provider<ProfileContainerStoreProvider> profileContainerStoreProvider;
@Inject
private Provider<DataImportManager> dataImportManager;
@Inject
private Provider<MVInvCommandCompletion> mvInvCommandCompletion;
@Inject
private Provider<MVInvCommandContexts> mvInvCommandContexts;
Expand Down Expand Up @@ -112,9 +110,6 @@ public final void onEnable() {
this.registerCommands();
this.registerDestinations();

// Hook plugins that can be imported from
this.hookImportables();

// Init other extensions
this.hookLuckPerms();
this.loadPlaceholderApiIntegration();
Expand Down Expand Up @@ -171,12 +166,6 @@ private void registerDestinations() {
destinationsProvider.get().registerDestination(serviceLocator.getService(LastLocationDestination.class));
}

private void hookImportables() {
serviceLocator.getAllServices(DataImporter.class).forEach(dataImporter -> {
dataImportManager.get().register(dataImporter);
});
}

private void hookLuckPerms() {
Try.run(() -> Class.forName("net.luckperms.api.LuckPerms"))
.onFailure(e -> Logging.fine("Luckperms is not installed!"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mvplugins.multiverse.inventories.commands;

import com.dumptruckman.minecraft.util.Logging;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
Expand Down Expand Up @@ -46,6 +47,13 @@ void onMigrateCommand(
@Syntax("<MultiInv|WorldInventories|PerWorldInventory>")
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/");
return;
}

dataImportManager.getImporter(pluginName)
.onEmpty(() -> issuer.sendError(MVInvi18n.MIGRATE_UNSUPPORTEDPLUGIN, replace("{plugin}").with(pluginName)))
.peek(dataImporter -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mvplugins.multiverse.inventories.commands;

import com.google.common.io.Files;
import org.bukkit.World;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.command.MVCommandIssuer;
Expand All @@ -9,72 +8,18 @@
import org.mvplugins.multiverse.external.acf.commands.annotation.Description;
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.Try;
import org.mvplugins.multiverse.inventories.profile.ProfileDataSource;
import org.mvplugins.multiverse.inventories.profile.data.ProfileData;
import org.mvplugins.multiverse.inventories.profile.key.ContainerType;
import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey;
import org.mvplugins.multiverse.inventories.profile.key.ProfileKey;
import org.mvplugins.multiverse.inventories.profile.key.ProfileTypes;
import org.mvplugins.multiverse.inventories.profile.nbt.PlayerDataExtractor;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

@Service
final class PlayerDataImportCommand extends InventoriesCommand {

private final PlayerDataExtractor playerDataExtractor;
private final ProfileDataSource profileDataSource;

@Inject
PlayerDataImportCommand(PlayerDataExtractor playerDataExtractor, ProfileDataSource profileDataSource) {
this.playerDataExtractor = playerDataExtractor;
this.profileDataSource = profileDataSource;
}

@Subcommand("playerdata import")
@Syntax("<world>")
@CommandPermission("multiverse.inventories.importplayerdata")
@CommandCompletion("@worldwithplayerdata")
@Description("Import player data from the world's playerdata folder.")
void onCommand(MVCommandIssuer issuer, World world) {
Path worldPath = world.getWorldFolder().toPath();
File playerDataPath = worldPath.resolve("playerdata").toFile();
if (!playerDataPath.isDirectory()) {
issuer.sendMessage("World's playerdata folder does not exist: " + world.getName());
return;
}

List<CompletableFuture<Void>> playerDataFutures = new ArrayList<>();
File[] files = playerDataPath.listFiles();
if (files == null) {
issuer.sendMessage("No player data files found in the world's playerdata folder: " + world.getName());
return;
}

for (File playerDataFile : files) {
if (!Files.getFileExtension(playerDataFile.getName()).equals("dat")) {
continue;
}
UUID playerUUID = UUID.fromString(Files.getNameWithoutExtension(playerDataFile.getName()));
playerDataExtractor.extract(playerDataFile.toPath())
.onSuccess(profileData -> playerDataFutures.add(profileDataSource
.getGlobalProfile(GlobalProfileKey.of(playerUUID))
.thenCompose(profileDataSource::updateGlobalProfile)
.thenCompose(ignore -> profileDataSource.getPlayerProfile(
ProfileKey.of(ContainerType.WORLD, world.getName(), ProfileTypes.getDefault(), playerUUID)))
.thenCompose(playerProfile -> {
playerProfile.update(profileData);
return profileDataSource.updatePlayerProfile(playerProfile);
})));
}
CompletableFuture.allOf(playerDataFutures.toArray(new CompletableFuture[0]))
.thenRun(() -> issuer.sendMessage("Successfully imported all player data from " + world.getName() + "."));
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/");
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading