diff --git a/.github/workflows/pr.test.yml b/.github/workflows/pr.test.yml index b21190d5..6fa231e5 100644 --- a/.github/workflows/pr.test.yml +++ b/.github/workflows/pr.test.yml @@ -6,6 +6,6 @@ on: jobs: test: - uses: Multiverse/Multiverse-Core/.github/workflows/generic.test.yml@main + uses: Multiverse/Multiverse-Core/.github/workflows/generic.test.yml@MV5 # todo: Change back to main before release with: plugin_name: multiverse-inventories diff --git a/build.gradle b/build.gradle index 2f24bf24..4994209a 100644 --- a/build.gradle +++ b/build.gradle @@ -2,14 +2,22 @@ plugins { id 'java-library' id 'maven-publish' id 'checkstyle' - id 'com.github.johnrengelman.shadow' version '7.1.2' + id 'com.gradleup.shadow' version '8.3.5' } version = System.getenv('GITHUB_VERSION') ?: 'local' -group = 'com.onarandombox.multiverseinventories' +group = 'org.mvplugins.multiverse.inventories' description = 'Multiverse-Inventories' -java.sourceCompatibility = JavaVersion.VERSION_11 +compileJava { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +// todo: Enable test when convert them to use mockbukkit like mv-core +compileTestJava { + enabled = false +} repositories { mavenLocal() @@ -29,6 +37,11 @@ repositories { name = 'jitpack.io' url = uri('https://jitpack.io/') } + + maven { + name = 'benwoo1110' + url = uri('https://repo.c0ding.party/multiverse-beta') + } } dependencies { @@ -38,9 +51,8 @@ dependencies { } // Core - implementation('com.onarandombox.multiversecore:Multiverse-Core:4.2.2') { - exclude group: 'me.main__.util', module: 'SerializationConfig' - } + // TODO update to correct version once we have it published + implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT' // Config api 'com.dumptruckman.minecraft:JsonConfiguration:1.1' @@ -62,11 +74,6 @@ dependencies { exclude group: '*', module: '*' } - // Legacy Multiverse-Adventure - implementation('com.onarandombox.multiverseadventure:Multiverse-Adventure:2.5.0-SNAPSHOT') { - exclude group: '*', module: '*' - } - // Tests testImplementation 'com.github.MilkBowl:VaultAPI:1.7.1' testImplementation 'junit:junit:4.13.2' @@ -144,16 +151,28 @@ javadoc { project.configurations.api.canBeResolved = true shadowJar { - relocate 'com.dumptruckman.minecraft.util.Logging', 'com.onarandombox.multiverseinventories.utils.InvLogging' - relocate 'com.dumptruckman.minecraft.util.DebugLog', 'com.onarandombox.multiverseinventories.utils.DebugFileLogger' - relocate 'com.dumptruckman.bukkit.configuration', 'com.onarandombox.multiverseinventories.utils.configuration' - relocate 'io.papermc.lib', 'com.onarandombox.multiverseinventories.utils.paperlib' - relocate 'net.minidev.json', 'com.onarandombox.multiverseinventories.utils.json' + relocate 'com.dumptruckman.minecraft.util.Logging', 'org.mvplugins.multiverse.inventories.utils.InvLogging' + relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.inventories.utils.DebugFileLogger' + relocate 'com.dumptruckman.bukkit.configuration', 'org.mvplugins.multiverse.inventories.utils.configuration' + relocate 'io.papermc.lib', 'org.mvplugins.multiverse.inventories.utils.paperlib' + relocate 'net.minidev.json', 'org.mvplugins.multiverse.inventories.utils.json' configurations = [project.configurations.api] - archiveFileName = "$baseName-$version.$extension" + archiveClassifier.set('') } build.dependsOn shadowJar jar.enabled = false + + +tasks.register('runHabitatGenerator', JavaExec) { + classpath = configurations["compileClasspath"] + mainClass.set('org.mvplugins.multiverse.external.jvnet.hk2.generator.HabitatGenerator') + + args = [ + '--file', "build/libs/multiverse-inventories-$version" + ".jar", + '--locator', 'Multiverse-Inventories', + ] +} +tasks.named("build") { finalizedBy("runHabitatGenerator") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33c..5c40527d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/onarandombox/multiverseinventories/AdventureListener.java b/src/main/java/com/onarandombox/multiverseinventories/AdventureListener.java deleted file mode 100644 index c17b4524..00000000 --- a/src/main/java/com/onarandombox/multiverseinventories/AdventureListener.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.onarandombox.multiverseinventories; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseAdventure.event.MVAResetFinishedEvent; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import org.bukkit.OfflinePlayer; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -/** - * Listener for Multiverse-Adventure events. - */ -public class AdventureListener implements Listener { - - private MultiverseInventories inventories; - - public AdventureListener(MultiverseInventories inventories) { - this.inventories = inventories; - } - - /** - * @param event The Multiverse-Adventure event to handle when a world has finished resetting. - */ - @EventHandler - public void worldReset(MVAResetFinishedEvent event) { - ProfileContainer container = inventories.getWorldProfileContainerStore().getContainer(event.getWorld()); - for (OfflinePlayer player : inventories.getServer().getOfflinePlayers()) { - container.removeAllPlayerData(player); - } - Logging.info("Removed all inventories for Multiverse-Adventure world."); - } -} - diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/package-info.java b/src/main/java/com/onarandombox/multiverseinventories/command/package-info.java deleted file mode 100644 index 988881fa..00000000 --- a/src/main/java/com/onarandombox/multiverseinventories/command/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This package contains all Commands. - */ -package com.onarandombox.multiverseinventories.command; - diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/package-info.java b/src/main/java/com/onarandombox/multiverseinventories/share/package-info.java deleted file mode 100644 index 6f538d65..00000000 --- a/src/main/java/com/onarandombox/multiverseinventories/share/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Contains all external API classes for {@link com.onarandombox.multiverseinventories.share.Sharable}s and handling the sharing of those between worlds. - */ -package com.onarandombox.multiverseinventories.share; - diff --git a/src/main/java/com/onarandombox/multiverseinventories/util/package-info.java b/src/main/java/com/onarandombox/multiverseinventories/util/package-info.java deleted file mode 100644 index 0826b3ff..00000000 --- a/src/main/java/com/onarandombox/multiverseinventories/util/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * This package contains utility classes. - */ -package com.onarandombox.multiverseinventories.util; - diff --git a/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java b/src/main/java/org/mvplugins/multiverse/inventories/AbstractWorldGroupManager.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java rename to src/main/java/org/mvplugins/multiverse/inventories/AbstractWorldGroupManager.java index 59ee14f5..545d011e 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/AbstractWorldGroupManager.java @@ -1,14 +1,15 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.profile.WorldGroupManager; -import com.onarandombox.multiverseinventories.profile.GroupingConflict; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.share.Shares; -import com.onarandombox.multiverseinventories.locale.Message; +import org.mvplugins.multiverse.inventories.profile.WorldGroupManager; +import org.mvplugins.multiverse.inventories.profile.GroupingConflict; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.mvplugins.multiverse.inventories.locale.Message; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; +import org.mvplugins.multiverse.core.world.WorldManager; import java.util.ArrayList; import java.util.Collections; @@ -25,9 +26,11 @@ abstract class AbstractWorldGroupManager implements WorldGroupManager { static final String DEFAULT_GROUP_NAME = "default"; protected final Map groupNamesMap = new LinkedHashMap<>(); protected final MultiverseInventories plugin; + protected final WorldManager worldManager; public AbstractWorldGroupManager(final MultiverseInventories plugin) { this.plugin = plugin; + this.worldManager = plugin.getServiceLocator().getService(WorldManager.class); } /** @@ -60,7 +63,7 @@ public List getGroupsForWorld(String worldName) { } // Only use the default group for worlds managed by MV-Core if (worldGroups.isEmpty() && plugin.getMVIConfig().isDefaultingUngroupedWorlds() && - plugin.getCore().getMVWorldManager().isMVWorld(worldName)) { + this.worldManager.isWorld(worldName)) { Logging.finer("Returning default group for world: " + worldName); worldGroups.add(getDefaultGroup()); } diff --git a/src/main/java/com/onarandombox/multiverseinventories/CoreDebugListener.java b/src/main/java/org/mvplugins/multiverse/inventories/CoreDebugListener.java similarity index 80% rename from src/main/java/com/onarandombox/multiverseinventories/CoreDebugListener.java rename to src/main/java/org/mvplugins/multiverse/inventories/CoreDebugListener.java index cd9685d8..9735c2b8 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/CoreDebugListener.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/CoreDebugListener.java @@ -1,7 +1,7 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.event.MVDebugModeEvent; +import org.mvplugins.multiverse.core.event.MVDebugModeEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/com/onarandombox/multiverseinventories/DataStrings.java b/src/main/java/org/mvplugins/multiverse/inventories/DataStrings.java similarity index 99% rename from src/main/java/com/onarandombox/multiverseinventories/DataStrings.java rename to src/main/java/org/mvplugins/multiverse/inventories/DataStrings.java index baf6bfad..0c5bfb5f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/DataStrings.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/DataStrings.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; import net.minidev.json.JSONArray; diff --git a/src/main/java/com/onarandombox/multiverseinventories/DefaultMessageProvider.java b/src/main/java/org/mvplugins/multiverse/inventories/DefaultMessageProvider.java similarity index 93% rename from src/main/java/com/onarandombox/multiverseinventories/DefaultMessageProvider.java rename to src/main/java/org/mvplugins/multiverse/inventories/DefaultMessageProvider.java index 71e6b397..b34e5036 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/DefaultMessageProvider.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/DefaultMessageProvider.java @@ -1,10 +1,10 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.locale.LazyLocaleMessageProvider; -import com.onarandombox.multiverseinventories.locale.LocalizationLoadingException; -import com.onarandombox.multiverseinventories.locale.Message; -import com.onarandombox.multiverseinventories.locale.NoSuchLocalizationException; -import com.onarandombox.multiverseinventories.util.Font; +import org.mvplugins.multiverse.inventories.locale.LazyLocaleMessageProvider; +import org.mvplugins.multiverse.inventories.locale.LocalizationLoadingException; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.mvplugins.multiverse.inventories.locale.NoSuchLocalizationException; +import org.mvplugins.multiverse.inventories.util.Font; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; @@ -50,7 +50,7 @@ public DefaultMessageProvider(JavaPlugin plugin) { * Tries to load the locale. * * @param locale Locale to try to load. - * @throws com.onarandombox.multiverseinventories.locale.LocalizationLoadingException if the Locale could not be loaded. + * @throws LocalizationLoadingException if the Locale could not be loaded. */ public void maybeLoadLocale(Locale locale) throws LocalizationLoadingException { if (!isLocaleLoaded(locale)) { diff --git a/src/main/java/com/onarandombox/multiverseinventories/DefaultMessager.java b/src/main/java/org/mvplugins/multiverse/inventories/DefaultMessager.java similarity index 86% rename from src/main/java/com/onarandombox/multiverseinventories/DefaultMessager.java rename to src/main/java/org/mvplugins/multiverse/inventories/DefaultMessager.java index 57008559..35afe289 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/DefaultMessager.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/DefaultMessager.java @@ -1,11 +1,12 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.locale.MessageProvider; -import com.onarandombox.multiverseinventories.locale.Messager; -import com.onarandombox.multiverseinventories.locale.Message; +import org.mvplugins.multiverse.inventories.locale.MessageProvider; +import org.mvplugins.multiverse.inventories.locale.Messager; +import org.mvplugins.multiverse.inventories.locale.Message; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; +import org.mvplugins.multiverse.inventories.util.Font; import java.util.List; @@ -71,7 +72,7 @@ public void help(Message message, CommandSender sender, Object... args) { */ @Override public void sendMessage(CommandSender player, String message) { - List messages = com.onarandombox.multiverseinventories.util.Font.splitString(message); + List messages = Font.splitString(message); sendMessages(player, messages); } diff --git a/src/main/java/com/onarandombox/multiverseinventories/DefaultPersistingProfile.java b/src/main/java/org/mvplugins/multiverse/inventories/DefaultPersistingProfile.java similarity index 70% rename from src/main/java/com/onarandombox/multiverseinventories/DefaultPersistingProfile.java rename to src/main/java/org/mvplugins/multiverse/inventories/DefaultPersistingProfile.java index 186b5916..9ee01ab6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/DefaultPersistingProfile.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/DefaultPersistingProfile.java @@ -1,8 +1,8 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.share.PersistingProfile; -import com.onarandombox.multiverseinventories.share.Shares; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.share.PersistingProfile; +import org.mvplugins.multiverse.inventories.share.Shares; /** * Simple implementation of PersistingProfile. diff --git a/src/main/java/com/onarandombox/multiverseinventories/FlatFileProfileDataSource.java b/src/main/java/org/mvplugins/multiverse/inventories/FlatFileProfileDataSource.java similarity index 94% rename from src/main/java/com/onarandombox/multiverseinventories/FlatFileProfileDataSource.java rename to src/main/java/org/mvplugins/multiverse/inventories/FlatFileProfileDataSource.java index 040d31f6..2902a076 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/FlatFileProfileDataSource.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/FlatFileProfileDataSource.java @@ -1,598 +1,598 @@ -package com.onarandombox.multiverseinventories; - -import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; -import com.dumptruckman.minecraft.util.Logging; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.onarandombox.multiverseinventories.profile.ProfileDataSource; -import com.onarandombox.multiverseinventories.profile.ProfileKey; -import com.onarandombox.multiverseinventories.profile.ProfileTypes; -import com.onarandombox.multiverseinventories.share.ProfileEntry; -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.SharableEntry; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.profile.GlobalProfile; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.profile.ProfileType; -import net.minidev.json.JSONObject; -import org.bukkit.Bukkit; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.json.simple.parser.JSONParser; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; - -class FlatFileProfileDataSource implements ProfileDataSource { - - private static final String JSON = ".json"; - - private final JSONParser JSON_PARSER = new JSONParser(); - - private final ExecutorService fileIOExecutorService = Executors.newSingleThreadExecutor(); - - // TODO these probably need configurable max sizes - private final Cache profileCache = CacheBuilder.newBuilder() - .expireAfterAccess(10, TimeUnit.MINUTES) - .maximumSize(1000) - .build(); - private final Cache globalProfileCache = CacheBuilder.newBuilder() - .expireAfterAccess(10, TimeUnit.MINUTES) - .maximumSize(500) - .build(); - - private final File worldFolder; - private final File groupFolder; - private final File playerFolder; - - FlatFileProfileDataSource(MultiverseInventories plugin) throws IOException { - // Make the data folders - plugin.getDataFolder().mkdirs(); - - // Check if the data file exists. If not, create it. - this.worldFolder = new File(plugin.getDataFolder(), "worlds"); - if (!this.worldFolder.exists()) { - if (!this.worldFolder.mkdirs()) { - throw new IOException("Could not create world folder!"); - } - } - this.groupFolder = new File(plugin.getDataFolder(), "groups"); - if (!this.groupFolder.exists()) { - if (!this.groupFolder.mkdirs()) { - throw new IOException("Could not create group folder!"); - } - } - this.playerFolder = new File(plugin.getDataFolder(), "players"); - if (!this.playerFolder.exists()) { - if (!this.playerFolder.mkdirs()) { - throw new IOException("Could not create player folder!"); - } - } - } - - private FileConfiguration waitForConfigHandle(File file) { - Future future = fileIOExecutorService.submit(new ConfigLoader(file)); - while (true) { - try { - return future.get(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - } - } - - private static FileConfiguration getConfigHandleNow(File file) { - return JsonConfiguration.loadConfiguration(file); - } - - private static class ConfigLoader implements Callable { - private final File file; - - private ConfigLoader(File file) { - this.file = file; - } - - @Override - public FileConfiguration call() throws Exception { - return getConfigHandleNow(file); - } - } - - private File getFolder(ContainerType type, String folderName) { - File folder; - switch (type) { - case GROUP: - folder = new File(this.groupFolder, folderName); - break; - case WORLD: - folder = new File(this.worldFolder, folderName); - break; - default: - folder = new File(this.worldFolder, folderName); - break; - } - - if (!folder.exists()) { - folder.mkdirs(); - } - return folder; - } - - /** - * Retrieves the data file for a player based on a given world/group name, creating it if necessary. - * - * @param type Indicates whether data is for group or world. - * @param dataName The name of the group or world. - * @param playerName The name of the player. - * @return The data file for a player. - * @throws IOException if there was a problem creating the file. - */ - File getPlayerFile(ContainerType type, String dataName, String playerName) throws IOException { - File jsonPlayerFile = new File(this.getFolder(type, dataName), playerName + JSON); - if (!jsonPlayerFile.exists()) { - try { - jsonPlayerFile.createNewFile(); - } catch (IOException e) { - throw new IOException("Could not create necessary player data file: " + jsonPlayerFile.getPath() - + ". Data for " + playerName + " in " + type.name().toLowerCase() + " " + dataName - + " may not be saved.", e); - } - } - Logging.finer("got data file: %s. Type: %s, DataName: %s, PlayerName: %s", - jsonPlayerFile.getPath(), type, dataName, playerName); - return jsonPlayerFile; - } - - /** - * Retrieves the data file for a player for their global data, creating it if necessary. - * - * @param fileName The name of the file (player name or UUID) without extension. - * @param createIfMissing If true, the file will be created it it does not exist. - * @return The data file for a player. - * @throws IOException if there was a problem creating the file. - */ - File getGlobalFile(String fileName, boolean createIfMissing) throws IOException { - File jsonPlayerFile = new File(playerFolder, fileName + JSON); - if (createIfMissing && !jsonPlayerFile.exists()) { - try { - jsonPlayerFile.createNewFile(); - } catch (IOException e) { - throw new IOException("Could not create necessary player file: " + jsonPlayerFile.getPath() + ". " - + "There may be issues with " + fileName + "'s metadata", e); - } - } - return jsonPlayerFile; - } - - private void queueWrite(PlayerProfile profile) { - fileIOExecutorService.submit(new FileWriter(profile.clone())); - } - - private class FileWriter implements Callable { - private final PlayerProfile profile; - - private FileWriter(PlayerProfile profile) { - this.profile = profile; - } - - @Override - public Void call() throws Exception { - processProfileWrite(profile); - return null; - } - } - - private void processProfileWrite(PlayerProfile playerProfile) { - try { - File playerFile = this.getPlayerFile(playerProfile.getContainerType(), - playerProfile.getContainerName(), playerProfile.getPlayer().getName()); - FileConfiguration playerData = getConfigHandleNow(playerFile); - playerData.createSection(playerProfile.getProfileType().getName(), serializePlayerProfile(playerProfile)); - try { - playerData.save(playerFile); - } catch (IOException e) { - Logging.severe("Could not save data for player: " + playerProfile.getPlayer().getName() - + " for " + playerProfile.getContainerType().toString() + ": " + playerProfile.getContainerName()); - Logging.severe(e.getMessage()); - } - } catch (final Exception e) { - Logging.getLogger().log(Level.WARNING, "Error while attempting to write profile data.", e); - } - } - - private Map serializePlayerProfile(PlayerProfile playerProfile) { - Map playerData = new LinkedHashMap(); - JSONObject jsonStats = new JSONObject(); - for (SharableEntry entry : playerProfile) { - if (entry.getValue() != null) { - if (entry.getSharable().getSerializer() == null) { - continue; - } - Sharable sharable = entry.getSharable(); - if (sharable.getProfileEntry().isStat()) { - jsonStats.put(sharable.getProfileEntry().getFileTag(), - sharable.getSerializer().serialize(entry.getValue())); - } else { - playerData.put(sharable.getProfileEntry().getFileTag(), - sharable.getSerializer().serialize(entry.getValue())); - } - } - } - if (!jsonStats.isEmpty()) { - playerData.put(DataStrings.PLAYER_STATS, jsonStats); - } - return playerData; - } - - /** - * {@inheritDoc} - */ - @Override - public void updatePlayerData(PlayerProfile playerProfile) { - queueWrite(playerProfile); - } - - private PlayerProfile getPlayerData(ProfileKey key) { - PlayerProfile cached = profileCache.getIfPresent(key); - if (cached != null) { - return cached; - } - File playerFile = null; - try { - playerFile = getPlayerFile(key.getContainerType(), key.getDataName(), key.getPlayerName()); - } catch (IOException e) { - e.printStackTrace(); - // Return an empty profile - return PlayerProfile.createPlayerProfile(key.getContainerType(), key.getDataName(), key.getProfileType(), - Bukkit.getOfflinePlayer(key.getPlayerUUID())); - } - FileConfiguration playerData = this.waitForConfigHandle(playerFile); - if (convertConfig(playerData)) { - try { - playerData.save(playerFile); - } catch (IOException e) { - Logging.severe("Could not save data for player: " + key.getPlayerName() - + " for " + key.getContainerType().toString() + ": " + key.getDataName() + " after conversion."); - Logging.severe(e.getMessage()); - } - } - ConfigurationSection section = playerData.getConfigurationSection(key.getProfileType().getName()); - if (section == null) { - section = playerData.createSection(key.getProfileType().getName()); - } - PlayerProfile result = deserializePlayerProfile(key, convertSection(section)); - profileCache.put(key, result); - return result; - } - - @Override - public PlayerProfile getPlayerData(ContainerType containerType, String dataName, ProfileType profileType, UUID playerUUID) { - return getPlayerData(ProfileKey.createProfileKey(containerType, dataName, profileType, playerUUID)); - } - - private PlayerProfile deserializePlayerProfile(ProfileKey pKey, Map playerData) { - PlayerProfile profile = PlayerProfile.createPlayerProfile(pKey.getContainerType(), pKey.getDataName(), - pKey.getProfileType(), Bukkit.getOfflinePlayer(pKey.getPlayerUUID())); - for (Object keyObj : playerData.keySet()) { - String key = keyObj.toString(); - if (key.equalsIgnoreCase(DataStrings.PLAYER_STATS)) { - final Object statsObject = playerData.get(key); - if (statsObject instanceof String) { - parseJsonPlayerStatsIntoProfile(statsObject.toString(), profile); - } else { - if (statsObject instanceof Map) { - parsePlayerStatsIntoProfile((Map) statsObject, profile); - } else { - Logging.warning("Could not parse stats for " + pKey.getPlayerName()); - } - } - } else { - if (playerData.get(key) == null) { - Logging.fine("Player data '" + key + "' is null for: " + pKey.getPlayerName()); - continue; - } - try { - Sharable sharable = ProfileEntry.lookup(false, key); - if (sharable == null) { - Logging.fine("Player fileTag '" + key + "' is unrecognized!"); - continue; - } - profile.set(sharable, sharable.getSerializer().deserialize(playerData.get(key))); - } catch (Exception e) { - Logging.fine("Could not parse fileTag: '" + key + "' with value '" + playerData.get(key) + "'"); - Logging.getLogger().log(Level.FINE, "Exception: ", e); - e.printStackTrace(); - } - } - } - Logging.finer("Created player profile from map for '" + pKey.getPlayerName() + "'."); - return profile; - } - - private void parsePlayerStatsIntoProfile(Map stats, PlayerProfile profile) { - for (Object key : stats.keySet()) { - Sharable sharable = ProfileEntry.lookup(true, key.toString()); - if (sharable != null) { - profile.set(sharable, sharable.getSerializer().deserialize(stats.get(key).toString())); - } else { - Logging.warning("Could not parse stat: '" + key + "' for player '" - + profile.getPlayer().getName() + "' for " + profile.getContainerType() + " '" - + profile.getContainerName() + "'"); - } - } - } - - private void parseJsonPlayerStatsIntoProfile(String stats, PlayerProfile profile) { - if (stats.isEmpty()) { - return; - } - org.json.simple.JSONObject jsonStats = null; - try { - jsonStats = (org.json.simple.JSONObject) JSON_PARSER.parse(stats); - } catch (org.json.simple.parser.ParseException e) { - Logging.warning("Could not parse stats for player'" + profile.getPlayer().getName() + "' for " + - profile.getContainerType() + " '" + profile.getContainerName() + "': " + e.getMessage()); - } catch (ClassCastException e) { - Logging.warning("Could not parse stats for player'" + profile.getPlayer().getName() + "' for " + - profile.getContainerType() + " '" + profile.getContainerName() + "': " + e.getMessage()); - } - if (jsonStats == null) { - Logging.warning("Could not parse stats for player'" + profile.getPlayer().getName() + "' for " + - profile.getContainerType() + " '" + profile.getContainerName() + "'"); - return; - } - parsePlayerStatsIntoProfile(jsonStats, profile); - } - - // TODO Remove this conversion - private boolean convertConfig(FileConfiguration config) { - ConfigurationSection section = config.getConfigurationSection("playerData"); - if (section != null) { - config.set(ProfileTypes.SURVIVAL.getName(), section); - config.set(ProfileTypes.CREATIVE.getName(), section); - config.set(ProfileTypes.ADVENTURE.getName(), section); - config.set("playerData", null); - Logging.finer("Migrated old player data to new multi-profile format"); - return true; - } - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean removePlayerData(ContainerType containerType, String dataName, ProfileType profileType, String playerName) { - if (profileType == null) { - try { - File playerFile = getPlayerFile(containerType, dataName, playerName); - return playerFile.delete(); - } catch (IOException ignore) { - Logging.warning("Attempted to delete file that did not exist for player " + playerName - + " in " + containerType.name().toLowerCase() + " " + dataName); - return false; - } - } else { - File playerFile; - try { - playerFile = getPlayerFile(containerType, dataName, playerName); - } catch (IOException e) { - Logging.warning("Attempted to delete " + playerName + "'s data for " - + profileType.getName().toLowerCase() + " mode in " + containerType.name().toLowerCase() - + " " + dataName + " but the file did not exist."); - return false; - } - FileConfiguration playerData = this.waitForConfigHandle(playerFile); - playerData.set(profileType.getName(), null); - try { - playerData.save(playerFile); - } catch (IOException e) { - Logging.severe("Could not delete data for player: " + playerName - + " for " + containerType.toString() + ": " + dataName); - Logging.severe(e.getMessage()); - return false; - } - return true; - } - } - - private Map convertSection(ConfigurationSection section) { - Map resultMap = new HashMap(); - for (String key : section.getKeys(false)) { - Object obj = section.get(key); - if (obj instanceof ConfigurationSection) { - resultMap.put(key, convertSection((ConfigurationSection) obj)); - } else { - resultMap.put(key, obj); - } - } - return resultMap; - } - - @Override - @Deprecated - public GlobalProfile getGlobalProfile(String playerName) { - return getGlobalProfile(playerName, Bukkit.getOfflinePlayer(playerName).getUniqueId()); - } - - @Override - public GlobalProfile getGlobalProfile(String playerName, UUID playerUUID) { - GlobalProfile cached = globalProfileCache.getIfPresent(playerUUID); - if (cached != null) { - return cached; - } - File playerFile; - - // Migrate old data if necessary - try { - playerFile = getGlobalFile(playerName, false); - } catch (IOException e) { - // This won't ever happen - e.printStackTrace(); - return GlobalProfile.createGlobalProfile(playerName); - } - if (playerFile.exists()) { - GlobalProfile profile = loadGlobalProfile(playerFile, playerName, playerUUID); - if (!migrateGlobalProfileToUUID(profile, playerFile)) { - Logging.warning("Could not properly migrate player global data file for " + playerName); - } - globalProfileCache.put(playerUUID, profile); - return profile; - } - - // Load current format - try { - playerFile = getGlobalFile(playerUUID.toString(), true); - } catch (IOException e) { - e.printStackTrace(); - return GlobalProfile.createGlobalProfile(playerName, playerUUID); - } - GlobalProfile profile = loadGlobalProfile(playerFile, playerName, playerUUID); - globalProfileCache.put(playerUUID, profile); - return profile; - } - - private boolean migrateGlobalProfileToUUID(GlobalProfile profile, File playerFile) { - updateGlobalProfile(profile); - return playerFile.delete(); - } - - private GlobalProfile loadGlobalProfile(File playerFile, String playerName, UUID playerUUID) { - FileConfiguration playerData = this.waitForConfigHandle(playerFile); - ConfigurationSection section = playerData.getConfigurationSection("playerData"); - if (section == null) { - section = playerData.createSection("playerData"); - } - return deserializeGlobalProfile(playerName, playerUUID, convertSection(section)); - } - - private GlobalProfile deserializeGlobalProfile(String playerName, UUID playerUUID, - Map playerData) { - GlobalProfile globalProfile = GlobalProfile.createGlobalProfile(playerName, playerUUID); - for (String key : playerData.keySet()) { - if (key.equalsIgnoreCase(DataStrings.PLAYER_LAST_WORLD)) { - globalProfile.setLastWorld(playerData.get(key).toString()); - } else if (key.equalsIgnoreCase(DataStrings.PLAYER_SHOULD_LOAD)) { - globalProfile.setLoadOnLogin(Boolean.valueOf(playerData.get(key).toString())); - } else if (key.equalsIgnoreCase(DataStrings.PLAYER_LAST_KNOWN_NAME)) { - globalProfile.setLastKnownName(playerData.get(key).toString()); - } - } - return globalProfile; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean updateGlobalProfile(GlobalProfile globalProfile) { - File playerFile = null; - try { - playerFile = this.getGlobalFile(globalProfile.getPlayerUUID().toString(), true); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - FileConfiguration playerData = this.waitForConfigHandle(playerFile); - playerData.createSection("playerData", serializeGlobalProfile(globalProfile)); - try { - playerData.save(playerFile); - } catch (IOException e) { - Logging.severe("Could not save global data for player: " + globalProfile); - Logging.severe(e.getMessage()); - return false; - } - return true; - } - - private Map serializeGlobalProfile(GlobalProfile profile) { - Map result = new HashMap(2); - if (profile.getLastWorld() != null) { - result.put(DataStrings.PLAYER_LAST_WORLD, profile.getLastWorld()); - } - result.put(DataStrings.PLAYER_SHOULD_LOAD, profile.shouldLoadOnLogin()); - result.put(DataStrings.PLAYER_LAST_KNOWN_NAME, profile.getLastKnownName()); - return result; - } - - @Override - @Deprecated - // TODO replace for UUID - public void updateLastWorld(String playerName, String worldName) { - GlobalProfile globalProfile = getGlobalProfile(playerName); - globalProfile.setLastWorld(worldName); - updateGlobalProfile(globalProfile); - } - - @Override - @Deprecated - // TODO replace for UUID - public void setLoadOnLogin(final String playerName, final boolean loadOnLogin) { - final GlobalProfile globalProfile = getGlobalProfile(playerName); - globalProfile.setLoadOnLogin(loadOnLogin); - updateGlobalProfile(globalProfile); - } - - @Override - public void migratePlayerData(String oldName, String newName, UUID uuid, boolean removeOldData) throws IOException { - File[] worldFolders = worldFolder.listFiles(File::isDirectory); - if (worldFolders == null) { - throw new IOException("Could not enumerate world folders"); - } - File[] groupFolders = groupFolder.listFiles(File::isDirectory); - if (groupFolders == null) { - throw new IOException("Could not enumerate group folders"); - } - - for (File worldFolder : worldFolders) { - ProfileKey key = ProfileKey.createProfileKey(ContainerType.WORLD, worldFolder.getName(), - ProfileTypes.ADVENTURE, uuid, oldName); - updatePlayerData(getPlayerData(key)); - updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.CREATIVE))); - updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.SURVIVAL))); - } - - for (File groupFolder : groupFolders) { - ProfileKey key = ProfileKey.createProfileKey(ContainerType.GROUP, groupFolder.getName(), - ProfileTypes.ADVENTURE, uuid, oldName); - updatePlayerData(getPlayerData(key)); - updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.CREATIVE))); - updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.SURVIVAL))); - } - - if (removeOldData) { - for (File worldFolder : worldFolders) { - removePlayerData(ContainerType.WORLD, worldFolder.getName(), ProfileTypes.ADVENTURE, oldName); - removePlayerData(ContainerType.WORLD, worldFolder.getName(), ProfileTypes.CREATIVE, oldName); - removePlayerData(ContainerType.WORLD, worldFolder.getName(), ProfileTypes.SURVIVAL, oldName); - } - for (File groupFolder : groupFolders) { - removePlayerData(ContainerType.GROUP, groupFolder.getName(), ProfileTypes.ADVENTURE, oldName); - removePlayerData(ContainerType.GROUP, groupFolder.getName(), ProfileTypes.CREATIVE, oldName); - removePlayerData(ContainerType.GROUP, groupFolder.getName(), ProfileTypes.SURVIVAL, oldName); - } - } - } - - @Override - public void clearProfileCache(ProfileKey key) { - profileCache.invalidate(key); - } - - void clearCache() { - globalProfileCache.invalidateAll(); - profileCache.invalidateAll(); - } -} - +package org.mvplugins.multiverse.inventories; + +import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; +import com.dumptruckman.minecraft.util.Logging; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; +import org.mvplugins.multiverse.inventories.profile.ProfileKey; +import org.mvplugins.multiverse.inventories.profile.ProfileTypes; +import org.mvplugins.multiverse.inventories.share.ProfileEntry; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.SharableEntry; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.profile.GlobalProfile; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.ProfileType; +import net.minidev.json.JSONObject; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.json.simple.parser.JSONParser; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; + +class FlatFileProfileDataSource implements ProfileDataSource { + + private static final String JSON = ".json"; + + private final JSONParser JSON_PARSER = new JSONParser(); + + private final ExecutorService fileIOExecutorService = Executors.newSingleThreadExecutor(); + + // TODO these probably need configurable max sizes + private final Cache profileCache = CacheBuilder.newBuilder() + .expireAfterAccess(10, TimeUnit.MINUTES) + .maximumSize(1000) + .build(); + private final Cache globalProfileCache = CacheBuilder.newBuilder() + .expireAfterAccess(10, TimeUnit.MINUTES) + .maximumSize(500) + .build(); + + private final File worldFolder; + private final File groupFolder; + private final File playerFolder; + + FlatFileProfileDataSource(MultiverseInventories plugin) throws IOException { + // Make the data folders + plugin.getDataFolder().mkdirs(); + + // Check if the data file exists. If not, create it. + this.worldFolder = new File(plugin.getDataFolder(), "worlds"); + if (!this.worldFolder.exists()) { + if (!this.worldFolder.mkdirs()) { + throw new IOException("Could not create world folder!"); + } + } + this.groupFolder = new File(plugin.getDataFolder(), "groups"); + if (!this.groupFolder.exists()) { + if (!this.groupFolder.mkdirs()) { + throw new IOException("Could not create group folder!"); + } + } + this.playerFolder = new File(plugin.getDataFolder(), "players"); + if (!this.playerFolder.exists()) { + if (!this.playerFolder.mkdirs()) { + throw new IOException("Could not create player folder!"); + } + } + } + + private FileConfiguration waitForConfigHandle(File file) { + Future future = fileIOExecutorService.submit(new ConfigLoader(file)); + while (true) { + try { + return future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + } + + private static FileConfiguration getConfigHandleNow(File file) { + return JsonConfiguration.loadConfiguration(file); + } + + private static class ConfigLoader implements Callable { + private final File file; + + private ConfigLoader(File file) { + this.file = file; + } + + @Override + public FileConfiguration call() throws Exception { + return getConfigHandleNow(file); + } + } + + private File getFolder(ContainerType type, String folderName) { + File folder; + switch (type) { + case GROUP: + folder = new File(this.groupFolder, folderName); + break; + case WORLD: + folder = new File(this.worldFolder, folderName); + break; + default: + folder = new File(this.worldFolder, folderName); + break; + } + + if (!folder.exists()) { + folder.mkdirs(); + } + return folder; + } + + /** + * Retrieves the data file for a player based on a given world/group name, creating it if necessary. + * + * @param type Indicates whether data is for group or world. + * @param dataName The name of the group or world. + * @param playerName The name of the player. + * @return The data file for a player. + * @throws IOException if there was a problem creating the file. + */ + File getPlayerFile(ContainerType type, String dataName, String playerName) throws IOException { + File jsonPlayerFile = new File(this.getFolder(type, dataName), playerName + JSON); + if (!jsonPlayerFile.exists()) { + try { + jsonPlayerFile.createNewFile(); + } catch (IOException e) { + throw new IOException("Could not create necessary player data file: " + jsonPlayerFile.getPath() + + ". Data for " + playerName + " in " + type.name().toLowerCase() + " " + dataName + + " may not be saved.", e); + } + } + Logging.finer("got data file: %s. Type: %s, DataName: %s, PlayerName: %s", + jsonPlayerFile.getPath(), type, dataName, playerName); + return jsonPlayerFile; + } + + /** + * Retrieves the data file for a player for their global data, creating it if necessary. + * + * @param fileName The name of the file (player name or UUID) without extension. + * @param createIfMissing If true, the file will be created it it does not exist. + * @return The data file for a player. + * @throws IOException if there was a problem creating the file. + */ + File getGlobalFile(String fileName, boolean createIfMissing) throws IOException { + File jsonPlayerFile = new File(playerFolder, fileName + JSON); + if (createIfMissing && !jsonPlayerFile.exists()) { + try { + jsonPlayerFile.createNewFile(); + } catch (IOException e) { + throw new IOException("Could not create necessary player file: " + jsonPlayerFile.getPath() + ". " + + "There may be issues with " + fileName + "'s metadata", e); + } + } + return jsonPlayerFile; + } + + private void queueWrite(PlayerProfile profile) { + fileIOExecutorService.submit(new FileWriter(profile.clone())); + } + + private class FileWriter implements Callable { + private final PlayerProfile profile; + + private FileWriter(PlayerProfile profile) { + this.profile = profile; + } + + @Override + public Void call() throws Exception { + processProfileWrite(profile); + return null; + } + } + + private void processProfileWrite(PlayerProfile playerProfile) { + try { + File playerFile = this.getPlayerFile(playerProfile.getContainerType(), + playerProfile.getContainerName(), playerProfile.getPlayer().getName()); + FileConfiguration playerData = getConfigHandleNow(playerFile); + playerData.createSection(playerProfile.getProfileType().getName(), serializePlayerProfile(playerProfile)); + try { + playerData.save(playerFile); + } catch (IOException e) { + Logging.severe("Could not save data for player: " + playerProfile.getPlayer().getName() + + " for " + playerProfile.getContainerType().toString() + ": " + playerProfile.getContainerName()); + Logging.severe(e.getMessage()); + } + } catch (final Exception e) { + Logging.getLogger().log(Level.WARNING, "Error while attempting to write profile data.", e); + } + } + + private Map serializePlayerProfile(PlayerProfile playerProfile) { + Map playerData = new LinkedHashMap(); + JSONObject jsonStats = new JSONObject(); + for (SharableEntry entry : playerProfile) { + if (entry.getValue() != null) { + if (entry.getSharable().getSerializer() == null) { + continue; + } + Sharable sharable = entry.getSharable(); + if (sharable.getProfileEntry().isStat()) { + jsonStats.put(sharable.getProfileEntry().getFileTag(), + sharable.getSerializer().serialize(entry.getValue())); + } else { + playerData.put(sharable.getProfileEntry().getFileTag(), + sharable.getSerializer().serialize(entry.getValue())); + } + } + } + if (!jsonStats.isEmpty()) { + playerData.put(DataStrings.PLAYER_STATS, jsonStats); + } + return playerData; + } + + /** + * {@inheritDoc} + */ + @Override + public void updatePlayerData(PlayerProfile playerProfile) { + queueWrite(playerProfile); + } + + private PlayerProfile getPlayerData(ProfileKey key) { + PlayerProfile cached = profileCache.getIfPresent(key); + if (cached != null) { + return cached; + } + File playerFile = null; + try { + playerFile = getPlayerFile(key.getContainerType(), key.getDataName(), key.getPlayerName()); + } catch (IOException e) { + e.printStackTrace(); + // Return an empty profile + return PlayerProfile.createPlayerProfile(key.getContainerType(), key.getDataName(), key.getProfileType(), + Bukkit.getOfflinePlayer(key.getPlayerUUID())); + } + FileConfiguration playerData = this.waitForConfigHandle(playerFile); + if (convertConfig(playerData)) { + try { + playerData.save(playerFile); + } catch (IOException e) { + Logging.severe("Could not save data for player: " + key.getPlayerName() + + " for " + key.getContainerType().toString() + ": " + key.getDataName() + " after conversion."); + Logging.severe(e.getMessage()); + } + } + ConfigurationSection section = playerData.getConfigurationSection(key.getProfileType().getName()); + if (section == null) { + section = playerData.createSection(key.getProfileType().getName()); + } + PlayerProfile result = deserializePlayerProfile(key, convertSection(section)); + profileCache.put(key, result); + return result; + } + + @Override + public PlayerProfile getPlayerData(ContainerType containerType, String dataName, ProfileType profileType, UUID playerUUID) { + return getPlayerData(ProfileKey.createProfileKey(containerType, dataName, profileType, playerUUID)); + } + + private PlayerProfile deserializePlayerProfile(ProfileKey pKey, Map playerData) { + PlayerProfile profile = PlayerProfile.createPlayerProfile(pKey.getContainerType(), pKey.getDataName(), + pKey.getProfileType(), Bukkit.getOfflinePlayer(pKey.getPlayerUUID())); + for (Object keyObj : playerData.keySet()) { + String key = keyObj.toString(); + if (key.equalsIgnoreCase(DataStrings.PLAYER_STATS)) { + final Object statsObject = playerData.get(key); + if (statsObject instanceof String) { + parseJsonPlayerStatsIntoProfile(statsObject.toString(), profile); + } else { + if (statsObject instanceof Map) { + parsePlayerStatsIntoProfile((Map) statsObject, profile); + } else { + Logging.warning("Could not parse stats for " + pKey.getPlayerName()); + } + } + } else { + if (playerData.get(key) == null) { + Logging.fine("Player data '" + key + "' is null for: " + pKey.getPlayerName()); + continue; + } + try { + Sharable sharable = ProfileEntry.lookup(false, key); + if (sharable == null) { + Logging.fine("Player fileTag '" + key + "' is unrecognized!"); + continue; + } + profile.set(sharable, sharable.getSerializer().deserialize(playerData.get(key))); + } catch (Exception e) { + Logging.fine("Could not parse fileTag: '" + key + "' with value '" + playerData.get(key) + "'"); + Logging.getLogger().log(Level.FINE, "Exception: ", e); + e.printStackTrace(); + } + } + } + Logging.finer("Created player profile from map for '" + pKey.getPlayerName() + "'."); + return profile; + } + + private void parsePlayerStatsIntoProfile(Map stats, PlayerProfile profile) { + for (Object key : stats.keySet()) { + Sharable sharable = ProfileEntry.lookup(true, key.toString()); + if (sharable != null) { + profile.set(sharable, sharable.getSerializer().deserialize(stats.get(key).toString())); + } else { + Logging.warning("Could not parse stat: '" + key + "' for player '" + + profile.getPlayer().getName() + "' for " + profile.getContainerType() + " '" + + profile.getContainerName() + "'"); + } + } + } + + private void parseJsonPlayerStatsIntoProfile(String stats, PlayerProfile profile) { + if (stats.isEmpty()) { + return; + } + org.json.simple.JSONObject jsonStats = null; + try { + jsonStats = (org.json.simple.JSONObject) JSON_PARSER.parse(stats); + } catch (org.json.simple.parser.ParseException e) { + Logging.warning("Could not parse stats for player'" + profile.getPlayer().getName() + "' for " + + profile.getContainerType() + " '" + profile.getContainerName() + "': " + e.getMessage()); + } catch (ClassCastException e) { + Logging.warning("Could not parse stats for player'" + profile.getPlayer().getName() + "' for " + + profile.getContainerType() + " '" + profile.getContainerName() + "': " + e.getMessage()); + } + if (jsonStats == null) { + Logging.warning("Could not parse stats for player'" + profile.getPlayer().getName() + "' for " + + profile.getContainerType() + " '" + profile.getContainerName() + "'"); + return; + } + parsePlayerStatsIntoProfile(jsonStats, profile); + } + + // TODO Remove this conversion + private boolean convertConfig(FileConfiguration config) { + ConfigurationSection section = config.getConfigurationSection("playerData"); + if (section != null) { + config.set(ProfileTypes.SURVIVAL.getName(), section); + config.set(ProfileTypes.CREATIVE.getName(), section); + config.set(ProfileTypes.ADVENTURE.getName(), section); + config.set("playerData", null); + Logging.finer("Migrated old player data to new multi-profile format"); + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean removePlayerData(ContainerType containerType, String dataName, ProfileType profileType, String playerName) { + if (profileType == null) { + try { + File playerFile = getPlayerFile(containerType, dataName, playerName); + return playerFile.delete(); + } catch (IOException ignore) { + Logging.warning("Attempted to delete file that did not exist for player " + playerName + + " in " + containerType.name().toLowerCase() + " " + dataName); + return false; + } + } else { + File playerFile; + try { + playerFile = getPlayerFile(containerType, dataName, playerName); + } catch (IOException e) { + Logging.warning("Attempted to delete " + playerName + "'s data for " + + profileType.getName().toLowerCase() + " mode in " + containerType.name().toLowerCase() + + " " + dataName + " but the file did not exist."); + return false; + } + FileConfiguration playerData = this.waitForConfigHandle(playerFile); + playerData.set(profileType.getName(), null); + try { + playerData.save(playerFile); + } catch (IOException e) { + Logging.severe("Could not delete data for player: " + playerName + + " for " + containerType.toString() + ": " + dataName); + Logging.severe(e.getMessage()); + return false; + } + return true; + } + } + + private Map convertSection(ConfigurationSection section) { + Map resultMap = new HashMap(); + for (String key : section.getKeys(false)) { + Object obj = section.get(key); + if (obj instanceof ConfigurationSection) { + resultMap.put(key, convertSection((ConfigurationSection) obj)); + } else { + resultMap.put(key, obj); + } + } + return resultMap; + } + + @Override + @Deprecated + public GlobalProfile getGlobalProfile(String playerName) { + return getGlobalProfile(playerName, Bukkit.getOfflinePlayer(playerName).getUniqueId()); + } + + @Override + public GlobalProfile getGlobalProfile(String playerName, UUID playerUUID) { + GlobalProfile cached = globalProfileCache.getIfPresent(playerUUID); + if (cached != null) { + return cached; + } + File playerFile; + + // Migrate old data if necessary + try { + playerFile = getGlobalFile(playerName, false); + } catch (IOException e) { + // This won't ever happen + e.printStackTrace(); + return GlobalProfile.createGlobalProfile(playerName); + } + if (playerFile.exists()) { + GlobalProfile profile = loadGlobalProfile(playerFile, playerName, playerUUID); + if (!migrateGlobalProfileToUUID(profile, playerFile)) { + Logging.warning("Could not properly migrate player global data file for " + playerName); + } + globalProfileCache.put(playerUUID, profile); + return profile; + } + + // Load current format + try { + playerFile = getGlobalFile(playerUUID.toString(), true); + } catch (IOException e) { + e.printStackTrace(); + return GlobalProfile.createGlobalProfile(playerName, playerUUID); + } + GlobalProfile profile = loadGlobalProfile(playerFile, playerName, playerUUID); + globalProfileCache.put(playerUUID, profile); + return profile; + } + + private boolean migrateGlobalProfileToUUID(GlobalProfile profile, File playerFile) { + updateGlobalProfile(profile); + return playerFile.delete(); + } + + private GlobalProfile loadGlobalProfile(File playerFile, String playerName, UUID playerUUID) { + FileConfiguration playerData = this.waitForConfigHandle(playerFile); + ConfigurationSection section = playerData.getConfigurationSection("playerData"); + if (section == null) { + section = playerData.createSection("playerData"); + } + return deserializeGlobalProfile(playerName, playerUUID, convertSection(section)); + } + + private GlobalProfile deserializeGlobalProfile(String playerName, UUID playerUUID, + Map playerData) { + GlobalProfile globalProfile = GlobalProfile.createGlobalProfile(playerName, playerUUID); + for (String key : playerData.keySet()) { + if (key.equalsIgnoreCase(DataStrings.PLAYER_LAST_WORLD)) { + globalProfile.setLastWorld(playerData.get(key).toString()); + } else if (key.equalsIgnoreCase(DataStrings.PLAYER_SHOULD_LOAD)) { + globalProfile.setLoadOnLogin(Boolean.valueOf(playerData.get(key).toString())); + } else if (key.equalsIgnoreCase(DataStrings.PLAYER_LAST_KNOWN_NAME)) { + globalProfile.setLastKnownName(playerData.get(key).toString()); + } + } + return globalProfile; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean updateGlobalProfile(GlobalProfile globalProfile) { + File playerFile = null; + try { + playerFile = this.getGlobalFile(globalProfile.getPlayerUUID().toString(), true); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + FileConfiguration playerData = this.waitForConfigHandle(playerFile); + playerData.createSection("playerData", serializeGlobalProfile(globalProfile)); + try { + playerData.save(playerFile); + } catch (IOException e) { + Logging.severe("Could not save global data for player: " + globalProfile); + Logging.severe(e.getMessage()); + return false; + } + return true; + } + + private Map serializeGlobalProfile(GlobalProfile profile) { + Map result = new HashMap(2); + if (profile.getLastWorld() != null) { + result.put(DataStrings.PLAYER_LAST_WORLD, profile.getLastWorld()); + } + result.put(DataStrings.PLAYER_SHOULD_LOAD, profile.shouldLoadOnLogin()); + result.put(DataStrings.PLAYER_LAST_KNOWN_NAME, profile.getLastKnownName()); + return result; + } + + @Override + @Deprecated + // TODO replace for UUID + public void updateLastWorld(String playerName, String worldName) { + GlobalProfile globalProfile = getGlobalProfile(playerName); + globalProfile.setLastWorld(worldName); + updateGlobalProfile(globalProfile); + } + + @Override + @Deprecated + // TODO replace for UUID + public void setLoadOnLogin(final String playerName, final boolean loadOnLogin) { + final GlobalProfile globalProfile = getGlobalProfile(playerName); + globalProfile.setLoadOnLogin(loadOnLogin); + updateGlobalProfile(globalProfile); + } + + @Override + public void migratePlayerData(String oldName, String newName, UUID uuid, boolean removeOldData) throws IOException { + File[] worldFolders = worldFolder.listFiles(File::isDirectory); + if (worldFolders == null) { + throw new IOException("Could not enumerate world folders"); + } + File[] groupFolders = groupFolder.listFiles(File::isDirectory); + if (groupFolders == null) { + throw new IOException("Could not enumerate group folders"); + } + + for (File worldFolder : worldFolders) { + ProfileKey key = ProfileKey.createProfileKey(ContainerType.WORLD, worldFolder.getName(), + ProfileTypes.ADVENTURE, uuid, oldName); + updatePlayerData(getPlayerData(key)); + updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.CREATIVE))); + updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.SURVIVAL))); + } + + for (File groupFolder : groupFolders) { + ProfileKey key = ProfileKey.createProfileKey(ContainerType.GROUP, groupFolder.getName(), + ProfileTypes.ADVENTURE, uuid, oldName); + updatePlayerData(getPlayerData(key)); + updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.CREATIVE))); + updatePlayerData(getPlayerData(ProfileKey.createProfileKey(key, ProfileTypes.SURVIVAL))); + } + + if (removeOldData) { + for (File worldFolder : worldFolders) { + removePlayerData(ContainerType.WORLD, worldFolder.getName(), ProfileTypes.ADVENTURE, oldName); + removePlayerData(ContainerType.WORLD, worldFolder.getName(), ProfileTypes.CREATIVE, oldName); + removePlayerData(ContainerType.WORLD, worldFolder.getName(), ProfileTypes.SURVIVAL, oldName); + } + for (File groupFolder : groupFolders) { + removePlayerData(ContainerType.GROUP, groupFolder.getName(), ProfileTypes.ADVENTURE, oldName); + removePlayerData(ContainerType.GROUP, groupFolder.getName(), ProfileTypes.CREATIVE, oldName); + removePlayerData(ContainerType.GROUP, groupFolder.getName(), ProfileTypes.SURVIVAL, oldName); + } + } + } + + @Override + public void clearProfileCache(ProfileKey key) { + profileCache.invalidate(key); + } + + void clearCache() { + globalProfileCache.invalidateAll(); + profileCache.invalidateAll(); + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/GameModeShareHandler.java b/src/main/java/org/mvplugins/multiverse/inventories/GameModeShareHandler.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/GameModeShareHandler.java rename to src/main/java/org/mvplugins/multiverse/inventories/GameModeShareHandler.java index 55434da2..c8864648 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/GameModeShareHandler.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/GameModeShareHandler.java @@ -1,95 +1,95 @@ -package com.onarandombox.multiverseinventories; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.event.GameModeChangeShareHandlingEvent; -import com.onarandombox.multiverseinventories.event.ShareHandlingEvent; -import com.onarandombox.multiverseinventories.profile.ProfileType; -import com.onarandombox.multiverseinventories.profile.ProfileTypes; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.util.Perm; -import org.bukkit.GameMode; -import org.bukkit.entity.Player; - -import java.util.List; - -/** - * GameMode change implementation of ShareHandler. - */ -final class GameModeShareHandler extends ShareHandler { - - private final GameMode fromGameMode; - private final GameMode toGameMode; - private final ProfileType fromType; - private final ProfileType toType; - private final String world; - private final ProfileContainer worldProfileContainer; - private final List worldGroups; - - GameModeShareHandler(MultiverseInventories inventories, Player player, - GameMode fromGameMode, GameMode toGameMode) { - super(inventories, player); - this.fromGameMode = fromGameMode; - this.toGameMode = toGameMode; - this.fromType = ProfileTypes.forGameMode(fromGameMode); - this.toType = ProfileTypes.forGameMode(toGameMode); - this.world = player.getWorld().getName(); - this.worldProfileContainer = inventories.getWorldProfileContainerStore().getContainer(world); - this.worldGroups = getAffectedWorldGroups(); - - prepareProfiles(); - } - - private List getAffectedWorldGroups() { - return this.inventories.getGroupManager().getGroupsForWorld(world); - } - - @Override - protected ShareHandlingEvent createEvent() { - return new GameModeChangeShareHandlingEvent(player, affectedProfiles, fromGameMode, toGameMode); - } - - private void prepareProfiles() { - Logging.finer("=== " + player.getName() + " changing game mode from: " + fromType - + " to: " + toType + " for world: " + world + " ==="); - - setAlwaysWriteProfile(worldProfileContainer.getPlayerData(fromType, player)); - - if (isPlayerAffectedByChange()) { - addProfiles(); - } - } - - private boolean isPlayerAffectedByChange() { - if (isPlayerBypassingChange()) { - logBypass(); - return false; - } - return true; - } - - private boolean isPlayerBypassingChange() { - return Perm.BYPASS_WORLD.hasBypass(player, world) - || Perm.BYPASS_GAME_MODE.hasBypass(player, toGameMode.name().toLowerCase()); - } - - private void addProfiles() { - if (hasWorldGroups()) { - worldGroups.forEach(this::addProfilesForWorldGroup); - } else { - Logging.finer("No groups for world."); - addReadProfile(worldProfileContainer.getPlayerData(toType, player), Sharables.allOf()); - } - } - - private boolean hasWorldGroups() { - return !worldGroups.isEmpty(); - } - - private void addProfilesForWorldGroup(WorldGroup worldGroup) { - ProfileContainer container = worldGroup.getGroupProfileContainer(); - addWriteProfile(container.getPlayerData(fromType, player), Sharables.allOf()); - addReadProfile(container.getPlayerData(toType, player), Sharables.allOf()); - } -} - +package org.mvplugins.multiverse.inventories; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.event.GameModeChangeShareHandlingEvent; +import org.mvplugins.multiverse.inventories.event.ShareHandlingEvent; +import org.mvplugins.multiverse.inventories.profile.ProfileType; +import org.mvplugins.multiverse.inventories.profile.ProfileTypes; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.util.Perm; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * GameMode change implementation of ShareHandler. + */ +final class GameModeShareHandler extends ShareHandler { + + private final GameMode fromGameMode; + private final GameMode toGameMode; + private final ProfileType fromType; + private final ProfileType toType; + private final String world; + private final ProfileContainer worldProfileContainer; + private final List worldGroups; + + GameModeShareHandler(MultiverseInventories inventories, Player player, + GameMode fromGameMode, GameMode toGameMode) { + super(inventories, player); + this.fromGameMode = fromGameMode; + this.toGameMode = toGameMode; + this.fromType = ProfileTypes.forGameMode(fromGameMode); + this.toType = ProfileTypes.forGameMode(toGameMode); + this.world = player.getWorld().getName(); + this.worldProfileContainer = inventories.getWorldProfileContainerStore().getContainer(world); + this.worldGroups = getAffectedWorldGroups(); + + prepareProfiles(); + } + + private List getAffectedWorldGroups() { + return this.inventories.getGroupManager().getGroupsForWorld(world); + } + + @Override + protected ShareHandlingEvent createEvent() { + return new GameModeChangeShareHandlingEvent(player, affectedProfiles, fromGameMode, toGameMode); + } + + private void prepareProfiles() { + Logging.finer("=== " + player.getName() + " changing game mode from: " + fromType + + " to: " + toType + " for world: " + world + " ==="); + + setAlwaysWriteProfile(worldProfileContainer.getPlayerData(fromType, player)); + + if (isPlayerAffectedByChange()) { + addProfiles(); + } + } + + private boolean isPlayerAffectedByChange() { + if (isPlayerBypassingChange()) { + logBypass(); + return false; + } + return true; + } + + private boolean isPlayerBypassingChange() { + return Perm.BYPASS_WORLD.hasBypass(player, world) + || Perm.BYPASS_GAME_MODE.hasBypass(player, toGameMode.name().toLowerCase()); + } + + private void addProfiles() { + if (hasWorldGroups()) { + worldGroups.forEach(this::addProfilesForWorldGroup); + } else { + Logging.finer("No groups for world."); + addReadProfile(worldProfileContainer.getPlayerData(toType, player), Sharables.allOf()); + } + } + + private boolean hasWorldGroups() { + return !worldGroups.isEmpty(); + } + + private void addProfilesForWorldGroup(WorldGroup worldGroup) { + ProfileContainer container = worldGroup.getGroupProfileContainer(); + addWriteProfile(container.getPlayerData(fromType, player), Sharables.allOf()); + addReadProfile(container.getPlayerData(toType, player), Sharables.allOf()); + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java b/src/main/java/org/mvplugins/multiverse/inventories/InventoriesConfig.java similarity index 91% rename from src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java rename to src/main/java/org/mvplugins/multiverse/inventories/InventoriesConfig.java index 867e1a97..2db1a360 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/InventoriesConfig.java @@ -1,332 +1,336 @@ -package com.onarandombox.multiverseinventories; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.share.Shares; -import com.onarandombox.multiverseinventories.util.CommentedYamlConfiguration; -import io.papermc.lib.PaperLib; -import org.bukkit.configuration.file.FileConfiguration; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Provides methods for interacting with the configuration of Multiverse-Inventories. - */ -public final class InventoriesConfig { - - /** - * Enum for easily keeping track of config paths, defaults and comments. - */ - public enum Path { - /** - * Locale name config path, default and comments. - */ - LANGUAGE_FILE_NAME("settings.locale", "en", "# This is the locale you wish to use."), - /** - * First Run flag config path, default and comments. - */ - FIRST_RUN("settings.first_run", true, "# If this is true it will generate world groups for you based on MV worlds."), - /** - * First Run flag config path, default and comments. - */ - USE_BYPASS("settings.use_bypass", false, "# If this is set to true, it will enable bypass permissions (Check the wiki for more info.)"), - - /** - * Whether or not to make ungrouped worlds use the default group. - */ - DEFAULT_UNGROUPED_WORLDS("settings.default_ungrouped_worlds", false, "# If set to true, any world not listed in a group will automatically use the settings for the default group!"), - - /** - * Whether or not to save/load player data on log out/in. - */ - LOGGING_SAVE_LOAD("settings.save_load_on_log_in_out", false, - "# The default and suggested setting for this is FALSE.", - "# False means Multiverse-Inventories will not attempt to load or save any player data when they log in and out.", - "# That means that MINECRAFT will handle that exact thing JUST LIKE IT DOES NORMALLY.", - "# Changing this to TRUE will have Multiverse-Inventories save player data when they log out and load it when they log in.", - "# The biggest potential drawback here is that if your server crashes, player stats/inventories may be lost/rolled back!"), - - USE_OPTIONALS_UNGROUPED("shares.optionals_for_ungrouped_worlds", true, - "# When set to true, optional shares WILL be utilized in cases where a group does not cover their uses for a world.", - "# An example of this in action would be an ungrouped world using last_location. When this is true, players will return to their last location in that world.", - "# When set to false, optional shares WILL NOt be utilized in these cases, effectively disabling it for ungrouped worlds."), - /** - * First Run flag config path, default and comments. - */ - OPTIONAL_SHARES("shares.use_optionals", new ArrayList(), - "# You must specify optional shares you wish to use here or they will be ignored.", - "# The only built in optional shares are \"economy\" and \"last_location\"."), - /** - * Whether or not to split data based on game modes. - */ - USE_GAME_MODE_PROFILES("settings.use_game_mode_profiles", false, - "# If this is set to true, players will have different inventories/stats for each game mode.", - "# Please note that old data migrated to the version that has this feature will have their data copied for both game modes."); - - private String path; - private Object def; - private List comments; - - Path(String path, Object def, String... comments) { - this.path = path; - this.def = def; - this.comments = Arrays.asList(comments); - } - - /** - * Retrieves the path for a config option. - * - * @return The path for a config option. - */ - private String getPath() { - return this.path; - } - - /** - * Retrieves the default value for a config path. - * - * @return The default value for a config path. - */ - private Object getDefault() { - return this.def; - } - - /** - * Retrieves the comment for a config path. - * - * @return The comments for a config path. - */ - private List getComments() { - return this.comments; - } - } - - private final CommentedYamlConfiguration config; - private final MultiverseInventories plugin; - - InventoriesConfig(MultiverseInventories plugin) throws IOException { - this.plugin = plugin; - // Make the data folders - if (plugin.getDataFolder().mkdirs()) { - Logging.fine("Created data folder."); - } - - // Check if the config file exists. If not, create it. - File configFile = new File(plugin.getDataFolder(), "config.yml"); - boolean configFileExists = configFile.exists(); - if (!configFileExists) { - Logging.fine("Created config file."); - configFile.createNewFile(); - } - - // Load the configuration file into memory - boolean supportsCommentsNatively = PaperLib.getMinecraftVersion() > 17; - config = new CommentedYamlConfiguration(configFile, !configFileExists || !supportsCommentsNatively); - - // Sets defaults config values - this.setDefaults(); - - config.getConfig().options().header("Multiverse-Inventories Settings"); - - // Saves the configuration from memory to file - config.save(); - - Logging.setDebugLevel(this.getGlobalDebug()); - } - - - /** - * Loads default settings for any missing config values. - */ - private void setDefaults() { - for (InventoriesConfig.Path path : InventoriesConfig.Path.values()) { - config.addComment(path.getPath(), path.getComments()); - if (this.getConfig().get(path.getPath()) == null) { - if (path.getDefault() != null) { - Logging.fine("Config: Defaulting '" + path.getPath() + "' to " + path.getDefault()); - this.getConfig().set(path.getPath(), path.getDefault()); - } else { - this.getConfig().createSection(path.getPath()); - } - } - } - - } - - private Boolean getBoolean(Path path) { - return this.getConfig().getBoolean(path.getPath(), (Boolean) path.getDefault()); - } - - private Integer getInt(Path path) { - return this.getConfig().getInt(path.getPath(), (Integer) path.getDefault()); - } - - private String getString(Path path) { - return this.getConfig().getString(path.getPath(), (String) path.getDefault()); - } - - FileConfiguration getConfig() { - return this.config.getConfig(); - } - - /** - * Sets globalDebug level. - * - * @param globalDebug The new value. 0 = off. - */ - public void setGlobalDebug(int globalDebug) { - plugin.getCore().getMVConfig().setGlobalDebug(globalDebug); - } - - /** - * Gets globalDebug level. - * - * @return globalDebug. - */ - public int getGlobalDebug() { - return plugin.getCore().getMVConfig().getGlobalDebug(); - } - - /** - * Retrieves the locale string from the config. - * - * @return The locale string. - */ - public String getLocale() { - return this.getString(Path.LANGUAGE_FILE_NAME); - } - - /** - * Tells whether this is the first time the plugin has run as set by a config flag. - * - * @return True if first_run is set to true in config. - */ - public boolean isFirstRun() { - return this.getBoolean(Path.FIRST_RUN); - } - - /** - * Sets the first_run flag in the config so that the plugin no longer thinks it is the first run. - * - * @param firstRun What to set the flag to in the config. - */ - void setFirstRun(boolean firstRun) { - this.getConfig().set(Path.FIRST_RUN.getPath(), firstRun); - } - - /** - * @return True if we should check for bypass permissions. - */ - public boolean isUsingBypass() { - return this.getBoolean(Path.USE_BYPASS); - } - - /** - * @param useBypass Whether or not to check for bypass permissions. - */ - public void setUsingBypass(boolean useBypass) { - this.getConfig().set(Path.USE_BYPASS.getPath(), useBypass); - } - - /** - * Tells whether Multiverse-Inventories should save on player logout and load on player login. - * - * @return True if should save and load on player log out and in. - */ - public boolean usingLoggingSaveLoad() { - return this.getBoolean(Path.LOGGING_SAVE_LOAD); - } - - /** - * Sets whether Multiverse-Inventories should save on player logout and load on player login. - * - * @param useLoggingSaveLoad true if should save and load on player log out and in. - */ - public void setUsingLoggingSaveLoad(boolean useLoggingSaveLoad) { - this.getConfig().set(Path.LOGGING_SAVE_LOAD.getPath(), useLoggingSaveLoad); - } - - private Shares optionalSharables = null; - - /** - * @return A list of optional {@link com.onarandombox.multiverseinventories.share.Sharable}s to be treated as - * regular {@link com.onarandombox.multiverseinventories.share.Sharable}s throughout the code. - * A {@link com.onarandombox.multiverseinventories.share.Sharable} marked as optional is ignored if it is not - * contained in this list. - */ - public Shares getOptionalShares() { - if (this.optionalSharables == null) { - List list = this.getConfig().getList(Path.OPTIONAL_SHARES.getPath()); - if (list != null) { - this.optionalSharables = Sharables.fromList(list); - } else { - Logging.warning("'" + Path.OPTIONAL_SHARES.getPath() + "' is setup incorrectly!"); - this.optionalSharables = Sharables.noneOf(); - } - } - return this.optionalSharables; - } - - /** - * @return true if worlds with no group should be considered part of the default group. - */ - public boolean isDefaultingUngroupedWorlds() { - return this.getBoolean(Path.DEFAULT_UNGROUPED_WORLDS); - } - - /** - * @param useDefaultGroup Set this to true to use the default group for ungrouped worlds. - */ - public void setDefaultingUngroupedWorlds(boolean useDefaultGroup) { - this.getConfig().set(Path.FIRST_RUN.getPath(), useDefaultGroup); - } - - /** - * @return True if using separate data for game modes. - */ - public boolean isUsingGameModeProfiles() { - return this.getBoolean(Path.USE_GAME_MODE_PROFILES); - } - - /** - * @param useGameModeProfile whether to use separate data for game modes. - */ - public void setUsingGameModeProfiles(boolean useGameModeProfile) { - this.getConfig().set(Path.USE_GAME_MODE_PROFILES.getPath(), useGameModeProfile); - } - - /** - * Whether Multiverse-Inventories will utilize optional shares in worlds that are not grouped. - * - * @return true if should utilize optional shares in worlds that are not grouped. - */ - public boolean usingOptionalsForUngrouped() { - return this.getBoolean(Path.USE_OPTIONALS_UNGROUPED); - } - - /** - * Sets whether Multiverse-Inventories will utilize optional shares in worlds that are not grouped. - * - * @param usingOptionalsForUngrouped true if should utilize optional shares in worlds that are not grouped. - */ - public void setUsingOptionalsForUngrouped(final boolean usingOptionalsForUngrouped) { - this.getConfig().set(Path.USE_OPTIONALS_UNGROUPED.getPath(), usingOptionalsForUngrouped); - } - - /** - * Saves the configuration file to disk. - */ - // TODO remove need for this method. - // TODO Figure out what I meant by the above todo message... - public void save() { - if (this.optionalSharables != null) { - this.getConfig().set(Path.OPTIONAL_SHARES.getPath(), this.optionalSharables.toStringList()); - } - this.config.save(); - } -} - +package org.mvplugins.multiverse.inventories; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.mvplugins.multiverse.inventories.util.CommentedYamlConfiguration; +import io.papermc.lib.PaperLib; +import org.bukkit.configuration.file.FileConfiguration; +import org.mvplugins.multiverse.core.config.MVCoreConfig; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Provides methods for interacting with the configuration of Multiverse-Inventories. + */ +public final class InventoriesConfig { + + /** + * Enum for easily keeping track of config paths, defaults and comments. + */ + public enum Path { + /** + * Locale name config path, default and comments. + */ + LANGUAGE_FILE_NAME("settings.locale", "en", "# This is the locale you wish to use."), + /** + * First Run flag config path, default and comments. + */ + FIRST_RUN("settings.first_run", true, "# If this is true it will generate world groups for you based on MV worlds."), + /** + * First Run flag config path, default and comments. + */ + USE_BYPASS("settings.use_bypass", false, "# If this is set to true, it will enable bypass permissions (Check the wiki for more info.)"), + + /** + * Whether or not to make ungrouped worlds use the default group. + */ + DEFAULT_UNGROUPED_WORLDS("settings.default_ungrouped_worlds", false, "# If set to true, any world not listed in a group will automatically use the settings for the default group!"), + + /** + * Whether or not to save/load player data on log out/in. + */ + LOGGING_SAVE_LOAD("settings.save_load_on_log_in_out", false, + "# The default and suggested setting for this is FALSE.", + "# False means Multiverse-Inventories will not attempt to load or save any player data when they log in and out.", + "# That means that MINECRAFT will handle that exact thing JUST LIKE IT DOES NORMALLY.", + "# Changing this to TRUE will have Multiverse-Inventories save player data when they log out and load it when they log in.", + "# The biggest potential drawback here is that if your server crashes, player stats/inventories may be lost/rolled back!"), + + USE_OPTIONALS_UNGROUPED("shares.optionals_for_ungrouped_worlds", true, + "# When set to true, optional shares WILL be utilized in cases where a group does not cover their uses for a world.", + "# An example of this in action would be an ungrouped world using last_location. When this is true, players will return to their last location in that world.", + "# When set to false, optional shares WILL NOt be utilized in these cases, effectively disabling it for ungrouped worlds."), + /** + * First Run flag config path, default and comments. + */ + OPTIONAL_SHARES("shares.use_optionals", new ArrayList(), + "# You must specify optional shares you wish to use here or they will be ignored.", + "# The only built in optional shares are \"economy\" and \"last_location\"."), + /** + * Whether or not to split data based on game modes. + */ + USE_GAME_MODE_PROFILES("settings.use_game_mode_profiles", false, + "# If this is set to true, players will have different inventories/stats for each game mode.", + "# Please note that old data migrated to the version that has this feature will have their data copied for both game modes."); + + private String path; + private Object def; + private List comments; + + Path(String path, Object def, String... comments) { + this.path = path; + this.def = def; + this.comments = Arrays.asList(comments); + } + + /** + * Retrieves the path for a config option. + * + * @return The path for a config option. + */ + private String getPath() { + return this.path; + } + + /** + * Retrieves the default value for a config path. + * + * @return The default value for a config path. + */ + private Object getDefault() { + return this.def; + } + + /** + * Retrieves the comment for a config path. + * + * @return The comments for a config path. + */ + private List getComments() { + return this.comments; + } + } + + private final CommentedYamlConfiguration config; + private final MultiverseInventories plugin; + private final MVCoreConfig mvCoreConfig; + + InventoriesConfig(MultiverseInventories plugin, MVCoreConfig mvCoreConfig) throws IOException { + this.plugin = plugin; + this.mvCoreConfig = mvCoreConfig; + // Make the data folders + if (plugin.getDataFolder().mkdirs()) { + Logging.fine("Created data folder."); + } + + // Check if the config file exists. If not, create it. + File configFile = new File(plugin.getDataFolder(), "config.yml"); + boolean configFileExists = configFile.exists(); + if (!configFileExists) { + Logging.fine("Created config file."); + configFile.createNewFile(); + } + + // Load the configuration file into memory + boolean supportsCommentsNatively = PaperLib.getMinecraftVersion() > 17; + config = new CommentedYamlConfiguration(configFile, !configFileExists || !supportsCommentsNatively); + + // Sets defaults config values + this.setDefaults(); + + config.getConfig().options().header("Multiverse-Inventories Settings"); + + // Saves the configuration from memory to file + config.save(); + + Logging.setDebugLevel(this.getGlobalDebug()); + } + + + /** + * Loads default settings for any missing config values. + */ + private void setDefaults() { + for (InventoriesConfig.Path path : InventoriesConfig.Path.values()) { + config.addComment(path.getPath(), path.getComments()); + if (this.getConfig().get(path.getPath()) == null) { + if (path.getDefault() != null) { + Logging.fine("Config: Defaulting '" + path.getPath() + "' to " + path.getDefault()); + this.getConfig().set(path.getPath(), path.getDefault()); + } else { + this.getConfig().createSection(path.getPath()); + } + } + } + + } + + private Boolean getBoolean(Path path) { + return this.getConfig().getBoolean(path.getPath(), (Boolean) path.getDefault()); + } + + private Integer getInt(Path path) { + return this.getConfig().getInt(path.getPath(), (Integer) path.getDefault()); + } + + private String getString(Path path) { + return this.getConfig().getString(path.getPath(), (String) path.getDefault()); + } + + FileConfiguration getConfig() { + return this.config.getConfig(); + } + + /** + * Sets globalDebug level. + * + * @param globalDebug The new value. 0 = off. + */ + public void setGlobalDebug(int globalDebug) { + mvCoreConfig.setGlobalDebug(globalDebug); + } + + /** + * Gets globalDebug level. + * + * @return globalDebug. + */ + public int getGlobalDebug() { + return mvCoreConfig.getGlobalDebug(); + } + + /** + * Retrieves the locale string from the config. + * + * @return The locale string. + */ + public String getLocale() { + return this.getString(Path.LANGUAGE_FILE_NAME); + } + + /** + * Tells whether this is the first time the plugin has run as set by a config flag. + * + * @return True if first_run is set to true in config. + */ + public boolean isFirstRun() { + return this.getBoolean(Path.FIRST_RUN); + } + + /** + * Sets the first_run flag in the config so that the plugin no longer thinks it is the first run. + * + * @param firstRun What to set the flag to in the config. + */ + void setFirstRun(boolean firstRun) { + this.getConfig().set(Path.FIRST_RUN.getPath(), firstRun); + } + + /** + * @return True if we should check for bypass permissions. + */ + public boolean isUsingBypass() { + return this.getBoolean(Path.USE_BYPASS); + } + + /** + * @param useBypass Whether or not to check for bypass permissions. + */ + public void setUsingBypass(boolean useBypass) { + this.getConfig().set(Path.USE_BYPASS.getPath(), useBypass); + } + + /** + * Tells whether Multiverse-Inventories should save on player logout and load on player login. + * + * @return True if should save and load on player log out and in. + */ + public boolean usingLoggingSaveLoad() { + return this.getBoolean(Path.LOGGING_SAVE_LOAD); + } + + /** + * Sets whether Multiverse-Inventories should save on player logout and load on player login. + * + * @param useLoggingSaveLoad true if should save and load on player log out and in. + */ + public void setUsingLoggingSaveLoad(boolean useLoggingSaveLoad) { + this.getConfig().set(Path.LOGGING_SAVE_LOAD.getPath(), useLoggingSaveLoad); + } + + private Shares optionalSharables = null; + + /** + * @return A list of optional {@link Sharable}s to be treated as + * regular {@link Sharable}s throughout the code. + * A {@link Sharable} marked as optional is ignored if it is not + * contained in this list. + */ + public Shares getOptionalShares() { + if (this.optionalSharables == null) { + List list = this.getConfig().getList(Path.OPTIONAL_SHARES.getPath()); + if (list != null) { + this.optionalSharables = Sharables.fromList(list); + } else { + Logging.warning("'" + Path.OPTIONAL_SHARES.getPath() + "' is setup incorrectly!"); + this.optionalSharables = Sharables.noneOf(); + } + } + return this.optionalSharables; + } + + /** + * @return true if worlds with no group should be considered part of the default group. + */ + public boolean isDefaultingUngroupedWorlds() { + return this.getBoolean(Path.DEFAULT_UNGROUPED_WORLDS); + } + + /** + * @param useDefaultGroup Set this to true to use the default group for ungrouped worlds. + */ + public void setDefaultingUngroupedWorlds(boolean useDefaultGroup) { + this.getConfig().set(Path.FIRST_RUN.getPath(), useDefaultGroup); + } + + /** + * @return True if using separate data for game modes. + */ + public boolean isUsingGameModeProfiles() { + return this.getBoolean(Path.USE_GAME_MODE_PROFILES); + } + + /** + * @param useGameModeProfile whether to use separate data for game modes. + */ + public void setUsingGameModeProfiles(boolean useGameModeProfile) { + this.getConfig().set(Path.USE_GAME_MODE_PROFILES.getPath(), useGameModeProfile); + } + + /** + * Whether Multiverse-Inventories will utilize optional shares in worlds that are not grouped. + * + * @return true if should utilize optional shares in worlds that are not grouped. + */ + public boolean usingOptionalsForUngrouped() { + return this.getBoolean(Path.USE_OPTIONALS_UNGROUPED); + } + + /** + * Sets whether Multiverse-Inventories will utilize optional shares in worlds that are not grouped. + * + * @param usingOptionalsForUngrouped true if should utilize optional shares in worlds that are not grouped. + */ + public void setUsingOptionalsForUngrouped(final boolean usingOptionalsForUngrouped) { + this.getConfig().set(Path.USE_OPTIONALS_UNGROUPED.getPath(), usingOptionalsForUngrouped); + } + + /** + * Saves the configuration file to disk. + */ + // TODO remove need for this method. + // TODO Figure out what I meant by the above todo message... + public void save() { + if (this.optionalSharables != null) { + this.getConfig().set(Path.OPTIONAL_SHARES.getPath(), this.optionalSharables.toStringList()); + } + this.config.save(); + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/InventoriesDupingPatch.java b/src/main/java/org/mvplugins/multiverse/inventories/InventoriesDupingPatch.java similarity index 98% rename from src/main/java/com/onarandombox/multiverseinventories/InventoriesDupingPatch.java rename to src/main/java/org/mvplugins/multiverse/inventories/InventoriesDupingPatch.java index 13fcbeae..c1473552 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/InventoriesDupingPatch.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/InventoriesDupingPatch.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import java.util.HashMap; import java.util.Iterator; diff --git a/src/main/java/com/onarandombox/multiverseinventories/InventoriesListener.java b/src/main/java/org/mvplugins/multiverse/inventories/InventoriesListener.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/InventoriesListener.java rename to src/main/java/org/mvplugins/multiverse/inventories/InventoriesListener.java index 992df2a3..c318e8c6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/InventoriesListener.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/InventoriesListener.java @@ -1,13 +1,12 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVWorld; -import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; -import com.onarandombox.MultiverseCore.event.MVVersionEvent; -import com.onarandombox.multiverseinventories.profile.GlobalProfile; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import com.onarandombox.multiverseinventories.share.Sharables; +import org.mvplugins.multiverse.core.event.MVConfigReloadEvent; +import org.mvplugins.multiverse.core.event.MVDumpsDebugInfoEvent; +import org.mvplugins.multiverse.inventories.profile.GlobalProfile; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.mvplugins.multiverse.inventories.share.Sharables; import me.drayshak.WorldInventories.WorldInventories; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -32,6 +31,11 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.inventory.InventoryHolder; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import uk.co.tggl.pluckerpluck.multiinv.MultiInv; import java.io.File; @@ -42,14 +46,19 @@ /** * PlayerListener for MultiverseInventories. */ +@Service public class InventoriesListener implements Listener { - private MultiverseInventories inventories; + private final MultiverseInventories inventories; + private final WorldManager worldManager; + private List currentGroups; private Location spawnLoc = null; - public InventoriesListener(MultiverseInventories inventories) { + @Inject + InventoriesListener(@NotNull MultiverseInventories inventories, @NotNull WorldManager worldManager) { this.inventories = inventories; + this.worldManager = worldManager; } /** @@ -58,12 +67,12 @@ public InventoriesListener(MultiverseInventories inventories) { * @param event The MVVersionEvent that this plugin will listen for. */ @EventHandler - public void versionRequest(MVVersionEvent event) { - event.appendVersionInfo(this.inventories.getVersionInfo()); + public void dumpsDebugInfoRequest(MVDumpsDebugInfoEvent event) { + event.appendDebugInfo(this.inventories.getVersionInfo()); File configFile = new File(this.inventories.getDataFolder(), "config.yml"); File groupsFile = new File(this.inventories.getDataFolder(), "groups.yml"); - event.putDetailedVersionInfo("multiverse-inventories/config.yml", configFile); - event.putDetailedVersionInfo("multiverse-inventories/groups.yml", groupsFile); + event.putDetailedDebugInfo("multiverse-inventories/config.yml", configFile); + event.putDetailedDebugInfo("multiverse-inventories/groups.yml", groupsFile); } /** @@ -219,8 +228,7 @@ public void playerChangedWorld(PlayerChangedWorldEvent event) { return; } // Warn if not managed by Multiverse-Core - if (this.inventories.getCore().getMVWorldManager().getMVWorld(toWorld) == null - || this.inventories.getCore().getMVWorldManager().getMVWorld(fromWorld) == null) { + if (!this.worldManager.isLoadedWorld(toWorld) || !this.worldManager.isLoadedWorld(fromWorld)) { Logging.fine("The from or to world is not managed by Multiverse-Core!"); } @@ -389,8 +397,7 @@ private void handleRespawn(PlayerRespawnEvent event, EventPriority priority) { if (group.getSpawnPriority().equals(priority)) { String spawnWorldName = group.getSpawnWorld(); if (spawnWorldName != null) { - MVWorld mvWorld = this.inventories.getCore() - .getMVWorldManager().getMVWorld(spawnWorldName); + LoadedMultiverseWorld mvWorld = this.worldManager.getLoadedWorld(spawnWorldName).getOrNull(); if (mvWorld != null) { this.spawnLoc = mvWorld.getSpawnLocation(); event.setRespawnLocation(this.spawnLoc); diff --git a/src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java b/src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventories.java similarity index 81% rename from src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java rename to src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventories.java index 9e860235..2049b264 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/MultiverseInventories.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventories.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import java.io.File; import java.io.IOException; @@ -6,18 +6,19 @@ import java.util.Locale; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVCore; -import com.onarandombox.MultiverseCore.api.MVPlugin; -import com.onarandombox.multiverseinventories.locale.Message; -import com.onarandombox.multiverseinventories.locale.Messager; -import com.onarandombox.multiverseinventories.locale.Messaging; -import com.onarandombox.multiverseinventories.migration.ImportManager; -import com.onarandombox.multiverseinventories.profile.ProfileDataSource; -import com.onarandombox.multiverseinventories.profile.WorldGroupManager; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainerStore; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.util.Perm; +import org.mvplugins.multiverse.inventories.commands.InventoriesCommand; +import org.mvplugins.multiverse.core.api.MVCore; +import org.mvplugins.multiverse.core.api.MVPlugin; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.mvplugins.multiverse.inventories.locale.Messager; +import org.mvplugins.multiverse.inventories.locale.Messaging; +import org.mvplugins.multiverse.inventories.migration.ImportManager; +import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; +import org.mvplugins.multiverse.inventories.profile.WorldGroupManager; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainerStore; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.util.Perm; import me.drayshak.WorldInventories.WorldInventories; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -26,11 +27,19 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPluginLoader; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.config.MVCoreConfig; +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.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.external.vavr.control.Try; import uk.co.tggl.pluckerpluck.multiinv.MultiInv; /** * Multiverse-Inventories plugin main class. */ +@Service public class MultiverseInventories extends JavaPlugin implements MVPlugin, Messaging { private static final int PROTOCOL = 50; @@ -41,8 +50,14 @@ public static MultiverseInventories getPlugin() { return inventoriesPlugin; } - private final InventoriesListener inventoriesListener = new InventoriesListener(this); - private final AdventureListener adventureListener = new AdventureListener(this); + private PluginServiceLocator serviceLocator; + + @Inject + private Provider commandManager; + @Inject + private Provider mvCoreConfig; + @Inject + private Provider inventoriesListener; private Messager messager = new DefaultMessager(this); private WorldGroupManager worldGroupManager = null; @@ -110,12 +125,26 @@ public final void onEnable() { this.getServer().getPluginManager().disablePlugin(this); return; } - Logging.setDebugLevel(core.getMVConfig().getGlobalDebug()); + + initializeDependencyInjection(); + + Logging.setDebugLevel(mvCoreConfig.get().getGlobalDebug()); this.core.incrementPluginCount(); this.onMVPluginEnable(); Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), getProtocolVersion(), getAuthors()); } + private void initializeDependencyInjection() { + serviceLocator = core.getServiceLocatorFactory() + .registerPlugin(new MultiverseInventoriesPluginBinder(this), core.getServiceLocator()) + .flatMap(PluginServiceLocator::enable) + .getOrElseThrow(exception -> { + Logging.severe("Failed to initialize dependency injection!"); + getServer().getPluginManager().disablePlugin(this); + return new RuntimeException(exception); + }); + } + private void onMVPluginEnable() { Perm.register(this); @@ -133,10 +162,7 @@ private void onMVPluginEnable() { //this.getWorldProfileContainerStore().setWorldProfiles(this.getData().getWorldProfiles()); // Register Events - Bukkit.getPluginManager().registerEvents(inventoriesListener, this); - if (Bukkit.getPluginManager().getPlugin("Multiverse-Adventure") != null) { - Bukkit.getPluginManager().registerEvents(adventureListener, this); - } + Bukkit.getPluginManager().registerEvents(inventoriesListener.get(), this); if (getCore().getProtocolVersion() >= 24) { new CoreDebugListener(this); @@ -175,7 +201,13 @@ public void onDisable() { } private void registerCommands() { - + Try.of(() -> commandManager.get()) + .andThenTry(commandManager -> serviceLocator.getAllServices(InventoriesCommand.class) + .forEach(commandManager::registerCommand)) + .onFailure(e -> { + Logging.severe("Failed to register commands"); + e.printStackTrace(); + }); } private void hookImportables() { @@ -237,6 +269,11 @@ public String getAuthors() { return authors.toString(); } + @Override + public PluginServiceLocator getServiceLocator() { + return serviceLocator; + } + /** * Builds a String containing Multiverse-Inventories' version info. * @@ -280,7 +317,7 @@ public InventoriesConfig getMVIConfig() { @Override public void reloadConfig() { try { - this.config = new InventoriesConfig(this); + this.config = new InventoriesConfig(this, mvCoreConfig.get()); this.worldGroupManager = new YamlWorldGroupManager(this, this.config.getConfig()); this.worldProfileContainerStore = new WeakProfileContainerStore(this, ContainerType.WORLD); this.groupProfileContainerStore = new WeakProfileContainerStore(this, ContainerType.GROUP); diff --git a/src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventoriesPluginBinder.java b/src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventoriesPluginBinder.java new file mode 100644 index 00000000..1fc4dbaf --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventoriesPluginBinder.java @@ -0,0 +1,19 @@ +package org.mvplugins.multiverse.inventories; + +import org.mvplugins.multiverse.core.api.MVPlugin; +import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder; +import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; + +public class MultiverseInventoriesPluginBinder extends JavaPluginBinder { + + protected MultiverseInventoriesPluginBinder(@NotNull MultiverseInventories plugin) { + super(plugin); + } + + @Override + protected ScopedBindingBuilder bindPluginClass + (ScopedBindingBuilder bindingBuilder) { + return super.bindPluginClass(bindingBuilder).to(MVPlugin.class).to(MultiverseInventories.class); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/PlayerStats.java b/src/main/java/org/mvplugins/multiverse/inventories/PlayerStats.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/PlayerStats.java rename to src/main/java/org/mvplugins/multiverse/inventories/PlayerStats.java index 8c546a53..f5bcb332 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/PlayerStats.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/PlayerStats.java @@ -1,69 +1,69 @@ -package com.onarandombox.multiverseinventories; - -/** - * A collection of values relating to a Minecraft player. - */ -public class PlayerStats { - - /** - * Number of slots in Minecraft player inventory. - */ - public static final int INVENTORY_SIZE = 36; - /** - * Number of slots for armor for player. - */ - public static final int ARMOR_SIZE = 4; - /** - * Number of slots in an ender chest. - */ - public static final int ENDER_CHEST_SIZE = 27; - /** - * Default health value. - */ - public static final int HEALTH = 20; - /** - * Default experience value. - */ - public static final float EXPERIENCE = 0F; - /** - * Default total experience value. - */ - public static final int TOTAL_EXPERIENCE = 0; - /** - * Default level value. - */ - public static final int LEVEL = 0; - /** - * Default food level value. - */ - public static final int FOOD_LEVEL = 20; - /** - * Default exhaustion value. - */ - public static final float EXHAUSTION = 0F; - /** - * Default saturation value. - */ - public static final float SATURATION = 5F; - /** - * Default fall distance value. - */ - public static final float FALL_DISTANCE = 0F; - /** - * Default fire ticks value. - */ - public static final int FIRE_TICKS = 0; - /** - * Default remaining air value. - */ - public static final int REMAINING_AIR = 300; - /** - * Default maximum air value. - */ - public static final int MAXIMUM_AIR = 300; - - private PlayerStats() { - throw new AssertionError(); - } -} - +package org.mvplugins.multiverse.inventories; + +/** + * A collection of values relating to a Minecraft player. + */ +public class PlayerStats { + + /** + * Number of slots in Minecraft player inventory. + */ + public static final int INVENTORY_SIZE = 36; + /** + * Number of slots for armor for player. + */ + public static final int ARMOR_SIZE = 4; + /** + * Number of slots in an ender chest. + */ + public static final int ENDER_CHEST_SIZE = 27; + /** + * Default health value. + */ + public static final int HEALTH = 20; + /** + * Default experience value. + */ + public static final float EXPERIENCE = 0F; + /** + * Default total experience value. + */ + public static final int TOTAL_EXPERIENCE = 0; + /** + * Default level value. + */ + public static final int LEVEL = 0; + /** + * Default food level value. + */ + public static final int FOOD_LEVEL = 20; + /** + * Default exhaustion value. + */ + public static final float EXHAUSTION = 0F; + /** + * Default saturation value. + */ + public static final float SATURATION = 5F; + /** + * Default fall distance value. + */ + public static final float FALL_DISTANCE = 0F; + /** + * Default fire ticks value. + */ + public static final int FIRE_TICKS = 0; + /** + * Default remaining air value. + */ + public static final int REMAINING_AIR = 300; + /** + * Default maximum air value. + */ + public static final int MAXIMUM_AIR = 300; + + private PlayerStats() { + throw new AssertionError(); + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/ShareHandler.java b/src/main/java/org/mvplugins/multiverse/inventories/ShareHandler.java similarity index 93% rename from src/main/java/com/onarandombox/multiverseinventories/ShareHandler.java rename to src/main/java/org/mvplugins/multiverse/inventories/ShareHandler.java index 25008ab6..c07028a1 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/ShareHandler.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/ShareHandler.java @@ -1,17 +1,17 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.event.ShareHandlingEvent; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.share.PersistingProfile; -import com.onarandombox.multiverseinventories.share.Shares; +import org.mvplugins.multiverse.inventories.event.ShareHandlingEvent; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.share.PersistingProfile; +import org.mvplugins.multiverse.inventories.share.Shares; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.LinkedList; import java.util.List; -import static com.onarandombox.multiverseinventories.share.Sharables.allOf; +import static org.mvplugins.multiverse.inventories.share.Sharables.allOf; /** * Abstract class for handling sharing of data between worlds and game modes. diff --git a/src/main/java/com/onarandombox/multiverseinventories/ShareHandlingUpdater.java b/src/main/java/org/mvplugins/multiverse/inventories/ShareHandlingUpdater.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/ShareHandlingUpdater.java rename to src/main/java/org/mvplugins/multiverse/inventories/ShareHandlingUpdater.java index 5409a059..128c9016 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/ShareHandlingUpdater.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/ShareHandlingUpdater.java @@ -1,10 +1,10 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.share.PersistingProfile; -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.Sharables; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.share.PersistingProfile; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.Sharables; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/multiverseinventories/WeakProfileContainer.java b/src/main/java/org/mvplugins/multiverse/inventories/WeakProfileContainer.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/WeakProfileContainer.java rename to src/main/java/org/mvplugins/multiverse/inventories/WeakProfileContainer.java index eb34c970..a62aed92 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/WeakProfileContainer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/WeakProfileContainer.java @@ -1,123 +1,123 @@ -package com.onarandombox.multiverseinventories; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.profile.ProfileDataSource; -import com.onarandombox.multiverseinventories.profile.ProfileKey; -import com.onarandombox.multiverseinventories.profile.WorldGroupManager; -import com.onarandombox.multiverseinventories.profile.ProfileTypes; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import com.onarandombox.multiverseinventories.profile.ProfileType; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainerStore; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; -import java.util.WeakHashMap; - -/** - * Implementation of ProfileContainer using WeakHashMaps to keep memory usage to a minimum. - */ -final class WeakProfileContainer implements ProfileContainer { - - private Map> playerData = new WeakHashMap<>(); - private final MultiverseInventories inventories; - private final String name; - private final ContainerType type; - - WeakProfileContainer(MultiverseInventories inventories, String name, ContainerType type) { - this.inventories = inventories; - this.name = name; - this.type = type; - } - - /** - * Gets the stored profiles for this player, mapped by ProfileType. - * - * @param name The name of player to get profile map for. - * @return The profile map for the given player. - */ - protected Map getPlayerData(String name) { - return this.playerData.computeIfAbsent(name, k -> new HashMap<>()); - } - - protected ProfileDataSource getDataSource() { - return this.getInventories().getData(); - } - - protected WorldGroupManager getGroupManager() { - return this.getInventories().getGroupManager(); - } - - protected ProfileContainerStore getProfileManager() { - return this.getInventories().getWorldProfileContainerStore(); - } - - protected MultiverseInventories getInventories() { - return this.inventories; - } - - @Override - public PlayerProfile getPlayerData(Player player) { - ProfileType type; - if (inventories.getMVIConfig().isUsingGameModeProfiles()) { - type = ProfileTypes.forGameMode(player.getGameMode()); - } else { - type = ProfileTypes.SURVIVAL; - } - return getPlayerData(type, player); - } - - @Override - public PlayerProfile getPlayerData(ProfileType profileType, OfflinePlayer player) { - Map profileMap = this.getPlayerData(player.getName()); - PlayerProfile playerProfile = profileMap.get(profileType); - if (playerProfile == null) { - playerProfile = getDataSource().getPlayerData(getContainerType(), - getContainerName(), profileType, player.getUniqueId()); - Logging.finer("[%s - %s - %s - %s] not cached, loading from disk...", - profileType, getContainerType(), playerProfile.getContainerName(), player.getName()); - profileMap.put(profileType, playerProfile); - } - return playerProfile; - } - - @Override - public void addPlayerData(PlayerProfile playerProfile) { - this.getPlayerData(playerProfile.getPlayer().getName()).put(playerProfile.getProfileType(), playerProfile); - } - - @Override - public void removeAllPlayerData(OfflinePlayer player) { - this.getPlayerData(player.getName()).clear(); - this.getDataSource().removePlayerData(getContainerType(), getContainerName(), null, player.getName()); - } - - @Override - public void removePlayerData(ProfileType profileType, OfflinePlayer player) { - this.getPlayerData(player.getName()).remove(profileType); - this.getDataSource().removePlayerData(getContainerType(), getContainerName(), profileType, player.getName()); - } - - @Override - public String getContainerName() { - return name; - } - - @Override - public ContainerType getContainerType() { - return type; - } - - @Override - public void clearContainer() { - for (Map profiles : playerData.values()) { - for (PlayerProfile profile : profiles.values()) { - this.getDataSource().clearProfileCache(ProfileKey.createProfileKey(profile)); - } - } - this.playerData.clear(); - } -} +package org.mvplugins.multiverse.inventories; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; +import org.mvplugins.multiverse.inventories.profile.ProfileKey; +import org.mvplugins.multiverse.inventories.profile.WorldGroupManager; +import org.mvplugins.multiverse.inventories.profile.ProfileTypes; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.mvplugins.multiverse.inventories.profile.ProfileType; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainerStore; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * Implementation of ProfileContainer using WeakHashMaps to keep memory usage to a minimum. + */ +final class WeakProfileContainer implements ProfileContainer { + + private Map> playerData = new WeakHashMap<>(); + private final MultiverseInventories inventories; + private final String name; + private final ContainerType type; + + WeakProfileContainer(MultiverseInventories inventories, String name, ContainerType type) { + this.inventories = inventories; + this.name = name; + this.type = type; + } + + /** + * Gets the stored profiles for this player, mapped by ProfileType. + * + * @param name The name of player to get profile map for. + * @return The profile map for the given player. + */ + protected Map getPlayerData(String name) { + return this.playerData.computeIfAbsent(name, k -> new HashMap<>()); + } + + protected ProfileDataSource getDataSource() { + return this.getInventories().getData(); + } + + protected WorldGroupManager getGroupManager() { + return this.getInventories().getGroupManager(); + } + + protected ProfileContainerStore getProfileManager() { + return this.getInventories().getWorldProfileContainerStore(); + } + + protected MultiverseInventories getInventories() { + return this.inventories; + } + + @Override + public PlayerProfile getPlayerData(Player player) { + ProfileType type; + if (inventories.getMVIConfig().isUsingGameModeProfiles()) { + type = ProfileTypes.forGameMode(player.getGameMode()); + } else { + type = ProfileTypes.SURVIVAL; + } + return getPlayerData(type, player); + } + + @Override + public PlayerProfile getPlayerData(ProfileType profileType, OfflinePlayer player) { + Map profileMap = this.getPlayerData(player.getName()); + PlayerProfile playerProfile = profileMap.get(profileType); + if (playerProfile == null) { + playerProfile = getDataSource().getPlayerData(getContainerType(), + getContainerName(), profileType, player.getUniqueId()); + Logging.finer("[%s - %s - %s - %s] not cached, loading from disk...", + profileType, getContainerType(), playerProfile.getContainerName(), player.getName()); + profileMap.put(profileType, playerProfile); + } + return playerProfile; + } + + @Override + public void addPlayerData(PlayerProfile playerProfile) { + this.getPlayerData(playerProfile.getPlayer().getName()).put(playerProfile.getProfileType(), playerProfile); + } + + @Override + public void removeAllPlayerData(OfflinePlayer player) { + this.getPlayerData(player.getName()).clear(); + this.getDataSource().removePlayerData(getContainerType(), getContainerName(), null, player.getName()); + } + + @Override + public void removePlayerData(ProfileType profileType, OfflinePlayer player) { + this.getPlayerData(player.getName()).remove(profileType); + this.getDataSource().removePlayerData(getContainerType(), getContainerName(), profileType, player.getName()); + } + + @Override + public String getContainerName() { + return name; + } + + @Override + public ContainerType getContainerType() { + return type; + } + + @Override + public void clearContainer() { + for (Map profiles : playerData.values()) { + for (PlayerProfile profile : profiles.values()) { + this.getDataSource().clearProfileCache(ProfileKey.createProfileKey(profile)); + } + } + this.playerData.clear(); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/WeakProfileContainerStore.java b/src/main/java/org/mvplugins/multiverse/inventories/WeakProfileContainerStore.java similarity index 77% rename from src/main/java/com/onarandombox/multiverseinventories/WeakProfileContainerStore.java rename to src/main/java/org/mvplugins/multiverse/inventories/WeakProfileContainerStore.java index ad853c80..e693b63e 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/WeakProfileContainerStore.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/WeakProfileContainerStore.java @@ -1,41 +1,41 @@ -package com.onarandombox.multiverseinventories; - -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainerStore; - -import java.util.Map; -import java.util.WeakHashMap; - -final class WeakProfileContainerStore implements ProfileContainerStore { - - private final Map containers = new WeakHashMap<>(); - - private final MultiverseInventories inventories; - private final ContainerType containerType; - - WeakProfileContainerStore(MultiverseInventories inventories, ContainerType containerType) { - this.inventories = inventories; - this.containerType = containerType; - } - - private MultiverseInventories getInventories() { - return this.inventories; - } - - @Override - public void addContainer(ProfileContainer container) { - this.containers.put(container.getContainerName().toLowerCase(), container); - } - - @Override - public ProfileContainer getContainer(String containerName) { - ProfileContainer container = this.containers.get(containerName.toLowerCase()); - if (container == null) { - container = new WeakProfileContainer(this.getInventories(), containerName, containerType); - addContainer(container); - } - return container; - } -} - +package org.mvplugins.multiverse.inventories; + +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainerStore; + +import java.util.Map; +import java.util.WeakHashMap; + +final class WeakProfileContainerStore implements ProfileContainerStore { + + private final Map containers = new WeakHashMap<>(); + + private final MultiverseInventories inventories; + private final ContainerType containerType; + + WeakProfileContainerStore(MultiverseInventories inventories, ContainerType containerType) { + this.inventories = inventories; + this.containerType = containerType; + } + + private MultiverseInventories getInventories() { + return this.inventories; + } + + @Override + public void addContainer(ProfileContainer container) { + this.containers.put(container.getContainerName().toLowerCase(), container); + } + + @Override + public ProfileContainer getContainer(String containerName) { + ProfileContainer container = this.containers.get(containerName.toLowerCase()); + if (container == null) { + container = new WeakProfileContainer(this.getInventories(), containerName, containerType); + addContainer(container); + } + return container; + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/WorldChangeShareHandler.java b/src/main/java/org/mvplugins/multiverse/inventories/WorldChangeShareHandler.java similarity index 90% rename from src/main/java/com/onarandombox/multiverseinventories/WorldChangeShareHandler.java rename to src/main/java/org/mvplugins/multiverse/inventories/WorldChangeShareHandler.java index 33662872..e2e1ea75 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/WorldChangeShareHandler.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/WorldChangeShareHandler.java @@ -1,231 +1,231 @@ -package com.onarandombox.multiverseinventories; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.event.ShareHandlingEvent; -import com.onarandombox.multiverseinventories.event.WorldChangeShareHandlingEvent; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.share.Shares; -import com.onarandombox.multiverseinventories.util.Perm; -import org.bukkit.entity.Player; - -import java.util.List; - -/** - * WorldChange implementation of ShareHandler. - */ -final class WorldChangeShareHandler extends ShareHandler { - - private final String fromWorld; - private final String toWorld; - private final List fromWorldGroups; - private final List toWorldGroups; - - WorldChangeShareHandler(MultiverseInventories inventories, Player player, String fromWorld, String toWorld) { - super(inventories, player); - this.fromWorld = fromWorld; - this.toWorld = toWorld; - - // Get any groups we may need to save stuff to. - this.fromWorldGroups = getAffectedWorldGroups(fromWorld); - // Get any groups we may need to load stuff from. - this.toWorldGroups = getAffectedWorldGroups(toWorld); - - prepareProfiles(); - } - - private List getAffectedWorldGroups(String world) { - return this.inventories.getGroupManager().getGroupsForWorld(world); - } - - @Override - protected ShareHandlingEvent createEvent() { - return new WorldChangeShareHandlingEvent(player, affectedProfiles, fromWorld, toWorld); - } - - private void prepareProfiles() { - Logging.finer("=== %s traveling from world: %s to world: %s ===", player.getName(), fromWorld, toWorld); - - setAlwaysWriteWorldProfile(); - - if (isPlayerAffectedByChange()) { - addProfiles(); - } - } - - private void setAlwaysWriteWorldProfile() { - // We will always save everything to the world they come from. - PlayerProfile fromWorldProfile = getWorldPlayerProfile(fromWorld, player); - setAlwaysWriteProfile(fromWorldProfile); - } - - private PlayerProfile getWorldPlayerProfile(String world, Player player) { - return getWorldProfile(world).getPlayerData(player); - } - - private ProfileContainer getWorldProfile(String world) { - return inventories.getWorldProfileContainerStore().getContainer(world); - } - - private boolean isPlayerAffectedByChange() { - if (isPlayerBypassingChange()) { - logBypass(); - return false; - } - return true; - } - - private boolean isPlayerBypassingChange() { - return Perm.BYPASS_WORLD.hasBypass(player, fromWorld); - } - - private void addProfiles() { - addWriteProfiles(); - new ReadProfilesAggregator().addReadProfiles(); - } - - private void addWriteProfiles() { - if (hasFromWorldGroups()) { - fromWorldGroups.forEach(wg -> new WorldGroupWrapper(wg).conditionallyAddWriteProfiles()); - } else { - Logging.finer("No groups for fromWorld."); - } - } - - private boolean hasFromWorldGroups() { - return !fromWorldGroups.isEmpty(); - } - - private class ReadProfilesAggregator { - - private Shares sharesToRead; - - private void addReadProfiles() { - sharesToRead = Sharables.noneOf(); - addReadProfilesFromToWorldGroups(); - useToWorldForMissingShares(); - } - - private void addReadProfilesFromToWorldGroups() { - if (hasToWorldGroups()) { - toWorldGroups.forEach(this::conditionallyAddReadProfileForWorldGroup); - } else { - Logging.finer("No groups for toWorld."); - } - } - - private boolean hasToWorldGroups() { - return !toWorldGroups.isEmpty(); - } - - private void conditionallyAddReadProfileForWorldGroup(WorldGroup worldGroup) { - if (isPlayerAffectedByChange(worldGroup)) { - if (isFromWorldNotInToWorldGroup(worldGroup)) { - addReadProfileForWorldGroup(worldGroup); - } else { - sharesToRead.addAll(worldGroup.getShares()); - } - } - } - - private boolean isPlayerAffectedByChange(WorldGroup worldGroup) { - if (isPlayerBypassingChange(worldGroup)) { - logBypass(); - return false; - } - return true; - } - - private boolean isPlayerBypassingChange(WorldGroup worldGroup) { - return Perm.BYPASS_GROUP.hasBypass(player, worldGroup.getName()); - } - - private boolean isFromWorldNotInToWorldGroup(WorldGroup worldGroup) { - return !worldGroup.containsWorld(fromWorld); - } - - private void addReadProfileForWorldGroup(WorldGroup worldGroup) { - PlayerProfile playerProfile = getWorldGroupPlayerData(worldGroup); - Shares sharesToAdd = getWorldGroupShares(worldGroup); - - addReadProfile(playerProfile, sharesToAdd); - sharesToRead.addAll(sharesToAdd); - } - - private PlayerProfile getWorldGroupPlayerData(WorldGroup worldGroup) { - return getWorldGroupProfileContainer(worldGroup).getPlayerData(player); - } - - private ProfileContainer getWorldGroupProfileContainer(WorldGroup worldGroup) { - return worldGroup.getGroupProfileContainer(); - } - - private Shares getWorldGroupShares(WorldGroup worldGroup) { - return Sharables.fromShares(worldGroup.getShares()); - } - - private void useToWorldForMissingShares() { - // We need to fill in any sharables that are not going to be transferred with what's saved in the world file. - if (hasUnhandledShares()) { - addUnhandledSharesFromToWorld(); - } - } - - private boolean hasUnhandledShares() { - return !sharesToRead.isSharing(Sharables.all()); - } - - private void addUnhandledSharesFromToWorld() { - Shares unhandledShares = Sharables.complimentOf(sharesToRead); - - Logging.finer("%s are left unhandled, defaulting to toWorld", unhandledShares); - - addReadProfile(getToWorldPlayerData(), unhandledShares); - } - - private PlayerProfile getToWorldPlayerData() { - return getToWorldProfileContainer().getPlayerData(player); - } - - private ProfileContainer getToWorldProfileContainer() { - return inventories.getWorldProfileContainerStore().getContainer(toWorld); - } - } - - private class WorldGroupWrapper { - private final WorldGroup worldGroup; - - public WorldGroupWrapper(WorldGroup worldGroup) { - this.worldGroup = worldGroup; - } - - private void conditionallyAddWriteProfiles() { - if (isEligibleForWrite()) { - addWriteProfiles(); - } - } - - boolean isEligibleForWrite() { - return groupDoesNotContainWorld(toWorld) || isNotSharingAll(); - } - - private boolean groupDoesNotContainWorld(String world) { - return !worldGroup.containsWorld(world); - } - - private boolean isNotSharingAll() { - return !worldGroup.getShares().isSharing(Sharables.all()); - } - - void addWriteProfiles() { - ProfileContainer container = worldGroup.getGroupProfileContainer(); - affectedProfiles.addWriteProfile(container.getPlayerData(player), getWorldGroupShares()); - } - - private Shares getWorldGroupShares() { - return Sharables.fromShares(worldGroup.getShares()); - } - } - -} +package org.mvplugins.multiverse.inventories; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.event.ShareHandlingEvent; +import org.mvplugins.multiverse.inventories.event.WorldChangeShareHandlingEvent; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.mvplugins.multiverse.inventories.util.Perm; +import org.bukkit.entity.Player; + +import java.util.List; + +/** + * WorldChange implementation of ShareHandler. + */ +final class WorldChangeShareHandler extends ShareHandler { + + private final String fromWorld; + private final String toWorld; + private final List fromWorldGroups; + private final List toWorldGroups; + + WorldChangeShareHandler(MultiverseInventories inventories, Player player, String fromWorld, String toWorld) { + super(inventories, player); + this.fromWorld = fromWorld; + this.toWorld = toWorld; + + // Get any groups we may need to save stuff to. + this.fromWorldGroups = getAffectedWorldGroups(fromWorld); + // Get any groups we may need to load stuff from. + this.toWorldGroups = getAffectedWorldGroups(toWorld); + + prepareProfiles(); + } + + private List getAffectedWorldGroups(String world) { + return this.inventories.getGroupManager().getGroupsForWorld(world); + } + + @Override + protected ShareHandlingEvent createEvent() { + return new WorldChangeShareHandlingEvent(player, affectedProfiles, fromWorld, toWorld); + } + + private void prepareProfiles() { + Logging.finer("=== %s traveling from world: %s to world: %s ===", player.getName(), fromWorld, toWorld); + + setAlwaysWriteWorldProfile(); + + if (isPlayerAffectedByChange()) { + addProfiles(); + } + } + + private void setAlwaysWriteWorldProfile() { + // We will always save everything to the world they come from. + PlayerProfile fromWorldProfile = getWorldPlayerProfile(fromWorld, player); + setAlwaysWriteProfile(fromWorldProfile); + } + + private PlayerProfile getWorldPlayerProfile(String world, Player player) { + return getWorldProfile(world).getPlayerData(player); + } + + private ProfileContainer getWorldProfile(String world) { + return inventories.getWorldProfileContainerStore().getContainer(world); + } + + private boolean isPlayerAffectedByChange() { + if (isPlayerBypassingChange()) { + logBypass(); + return false; + } + return true; + } + + private boolean isPlayerBypassingChange() { + return Perm.BYPASS_WORLD.hasBypass(player, fromWorld); + } + + private void addProfiles() { + addWriteProfiles(); + new ReadProfilesAggregator().addReadProfiles(); + } + + private void addWriteProfiles() { + if (hasFromWorldGroups()) { + fromWorldGroups.forEach(wg -> new WorldGroupWrapper(wg).conditionallyAddWriteProfiles()); + } else { + Logging.finer("No groups for fromWorld."); + } + } + + private boolean hasFromWorldGroups() { + return !fromWorldGroups.isEmpty(); + } + + private class ReadProfilesAggregator { + + private Shares sharesToRead; + + private void addReadProfiles() { + sharesToRead = Sharables.noneOf(); + addReadProfilesFromToWorldGroups(); + useToWorldForMissingShares(); + } + + private void addReadProfilesFromToWorldGroups() { + if (hasToWorldGroups()) { + toWorldGroups.forEach(this::conditionallyAddReadProfileForWorldGroup); + } else { + Logging.finer("No groups for toWorld."); + } + } + + private boolean hasToWorldGroups() { + return !toWorldGroups.isEmpty(); + } + + private void conditionallyAddReadProfileForWorldGroup(WorldGroup worldGroup) { + if (isPlayerAffectedByChange(worldGroup)) { + if (isFromWorldNotInToWorldGroup(worldGroup)) { + addReadProfileForWorldGroup(worldGroup); + } else { + sharesToRead.addAll(worldGroup.getShares()); + } + } + } + + private boolean isPlayerAffectedByChange(WorldGroup worldGroup) { + if (isPlayerBypassingChange(worldGroup)) { + logBypass(); + return false; + } + return true; + } + + private boolean isPlayerBypassingChange(WorldGroup worldGroup) { + return Perm.BYPASS_GROUP.hasBypass(player, worldGroup.getName()); + } + + private boolean isFromWorldNotInToWorldGroup(WorldGroup worldGroup) { + return !worldGroup.containsWorld(fromWorld); + } + + private void addReadProfileForWorldGroup(WorldGroup worldGroup) { + PlayerProfile playerProfile = getWorldGroupPlayerData(worldGroup); + Shares sharesToAdd = getWorldGroupShares(worldGroup); + + addReadProfile(playerProfile, sharesToAdd); + sharesToRead.addAll(sharesToAdd); + } + + private PlayerProfile getWorldGroupPlayerData(WorldGroup worldGroup) { + return getWorldGroupProfileContainer(worldGroup).getPlayerData(player); + } + + private ProfileContainer getWorldGroupProfileContainer(WorldGroup worldGroup) { + return worldGroup.getGroupProfileContainer(); + } + + private Shares getWorldGroupShares(WorldGroup worldGroup) { + return Sharables.fromShares(worldGroup.getShares()); + } + + private void useToWorldForMissingShares() { + // We need to fill in any sharables that are not going to be transferred with what's saved in the world file. + if (hasUnhandledShares()) { + addUnhandledSharesFromToWorld(); + } + } + + private boolean hasUnhandledShares() { + return !sharesToRead.isSharing(Sharables.all()); + } + + private void addUnhandledSharesFromToWorld() { + Shares unhandledShares = Sharables.complimentOf(sharesToRead); + + Logging.finer("%s are left unhandled, defaulting to toWorld", unhandledShares); + + addReadProfile(getToWorldPlayerData(), unhandledShares); + } + + private PlayerProfile getToWorldPlayerData() { + return getToWorldProfileContainer().getPlayerData(player); + } + + private ProfileContainer getToWorldProfileContainer() { + return inventories.getWorldProfileContainerStore().getContainer(toWorld); + } + } + + private class WorldGroupWrapper { + private final WorldGroup worldGroup; + + public WorldGroupWrapper(WorldGroup worldGroup) { + this.worldGroup = worldGroup; + } + + private void conditionallyAddWriteProfiles() { + if (isEligibleForWrite()) { + addWriteProfiles(); + } + } + + boolean isEligibleForWrite() { + return groupDoesNotContainWorld(toWorld) || isNotSharingAll(); + } + + private boolean groupDoesNotContainWorld(String world) { + return !worldGroup.containsWorld(world); + } + + private boolean isNotSharingAll() { + return !worldGroup.getShares().isSharing(Sharables.all()); + } + + void addWriteProfiles() { + ProfileContainer container = worldGroup.getGroupProfileContainer(); + affectedProfiles.addWriteProfile(container.getPlayerData(player), getWorldGroupShares()); + } + + private Shares getWorldGroupShares() { + return Sharables.fromShares(worldGroup.getShares()); + } + } + +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java b/src/main/java/org/mvplugins/multiverse/inventories/WorldGroup.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java rename to src/main/java/org/mvplugins/multiverse/inventories/WorldGroup.java index ef42ac42..a0e6cdd6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/WorldGroup.java @@ -1,247 +1,247 @@ -package com.onarandombox.multiverseinventories; - -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.share.Shares; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import org.bukkit.World; -import org.bukkit.event.EventPriority; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -public final class WorldGroup { - - private final MultiverseInventories plugin; - private final String name; - private final HashSet worlds = new HashSet<>(); - private final Shares shares = Sharables.noneOf(); - - private String spawnWorld = null; - private EventPriority spawnPriority = EventPriority.NORMAL; - - WorldGroup(final MultiverseInventories inventories, final String name) { - this.plugin = inventories; - this.name = name; - } - - /** - * Get the name of this World Group. - * - * @return Name of this World Group. - */ - public String getName() { - return this.name; - } - - /** - * Adds a world to this world group and updates it in the Config. - * - * @param worldName The name of the world to add. - */ - public void addWorld(String worldName) { - this.addWorld(worldName, true); - } - - /** - * Adds a world to this world group and optionally updates it in the Config. - * - * @param worldName The name of the world to add. - * @param updateConfig True to update this group in the config. - */ - public void addWorld(String worldName, boolean updateConfig) { - this.getWorlds().add(worldName.toLowerCase()); - if (updateConfig) { - plugin.getGroupManager().updateGroup(this); - } - } - - /** - * Convenience method to add a {@link org.bukkit.World} to this World Group. - * - * @param world The world to add. - */ - public void addWorld(World world) { - this.addWorld(world.getName()); - } - - /** - * Convenience method to add multiple worlds to this World Group and updates it in the Config. - * - * @param worlds A collections of worlds to add. - */ - public void addWorlds(Collection worlds) { - this.addWorlds(worlds, true); - } - - /** - * Convenience method to add multiple worlds to this World Group. - * - * @param worlds A collections of worlds to add. - * @param updateConfig True to update this group in the config. - */ - public void addWorlds(Collection worlds, boolean updateConfig) { - worlds.forEach(worldName -> this.addWorld(worldName, false)); - if (updateConfig) { - this.plugin.getGroupManager().updateGroup(this); - } - } - - /** - * Removes a world from this world group and updates the group in the Config. - * - * @param worldName The name of the world to remove. - */ - public void removeWorld(String worldName) { - this.removeWorld(worldName, true); - } - - /** - * Removes a world from this world group and optionally updates it in the Config. - * - * @param worldName The name of the world to remove. - * @param updateConfig True to update this group in the config. - */ - public void removeWorld(String worldName, boolean updateConfig) { - this.getWorlds().remove(worldName.toLowerCase()); - if (updateConfig) { - plugin.getGroupManager().updateGroup(this); - } - } - - /** - * Convenience method to remove a {@link org.bukkit.World} from this World Group. - * - * @param world The world to remove. - */ - public void removeWorld(World world) { - this.removeWorld(world.getName()); - } - - /** - * Remove all the worlds in this World Group. - */ - public void removeAllWorlds() { - this.removeAllWorlds(true); - } - - /** - * Remove all the worlds in this World Group. - * - * @param updateConfig True to update this group in the config. - */ - public void removeAllWorlds(boolean updateConfig) { - this.worlds.clear(); - if (updateConfig) { - this.plugin.getGroupManager().updateGroup(this); - } - } - - /** - * Retrieves all of the worlds in this World Group. - * - * @return The worlds of this World Group. - */ - public Set getWorlds() { - return this.worlds; - } - - /** - * Checks if this group is sharing sharable. This will check both shares and negative shares of the group. - * This is the preferred method for checking if a group shares something as shares may contain ALL shares while - * ones indicated in negative shares means those aren't actually shared. - * - * @param sharable Sharable to check if sharing. - * @return true is the sharable is shared for this group. - */ - public boolean isSharing(Sharable sharable) { - return getShares().isSharing(sharable); - } - - /** - * Retrieves the shares for this World Group. Any changes to this group must be subsequently saved to the data - * source for the changes to be permanent. - * - * @return The shares for this World Group. - */ - public Shares getShares() { - return this.shares; - } - - /** - * @param worldName Name of world to check for. - * @return True if specified world is part of this group. - */ - public boolean containsWorld(String worldName) { - return this.getWorlds().contains(worldName.toLowerCase()); - } - - /** - * @return The name of the world that will be used as the spawn for this group. - * Or null if no world was specified as the group spawn world. - */ - public String getSpawnWorld() { - return this.spawnWorld; - } - - /** - * @param worldName The name of the world to set this groups spawn to. - */ - public void setSpawnWorld(String worldName) { - this.spawnWorld = worldName.toLowerCase(); - } - - /** - * @return The priority for the respawn event that this spawn will act on. - */ - public EventPriority getSpawnPriority() { - return this.spawnPriority; - } - - /** - * @param priority The priority that will be used for respawning the player at - * this group's spawn location if there is one set. - */ - public void setSpawnPriority(EventPriority priority) { - this.spawnPriority = priority; - } - - /** - * Is this a default group. - * - * @return true if this is the default group. - */ - public boolean isDefault() { - return AbstractWorldGroupManager.DEFAULT_GROUP_NAME.equals(getName()); - } - - /** - * Returns the profile container for this group. - * - * @return the profile container for this group. - */ - public ProfileContainer getGroupProfileContainer() { - return plugin.getGroupProfileContainerStore().getContainer(getName()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(this.getName()).append(": {Worlds: ["); - String[] worldsString = this.getWorlds().toArray(new String[this.getWorlds().size()]); - for (int i = 0; i < worldsString.length; i++) { - if (i != 0) { - builder.append(", "); - } - builder.append(worldsString[i]); - } - builder.append("], Shares: [").append(this.getShares().toString()).append("]"); - if (this.getSpawnWorld() != null) { - builder.append(", Spawn World: ").append(this.getSpawnWorld()); - builder.append(", Spawn Priority: ").append(this.getSpawnPriority().toString()); - } - builder.append("}"); - return builder.toString(); - } -} +package org.mvplugins.multiverse.inventories; + +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.bukkit.World; +import org.bukkit.event.EventPriority; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public final class WorldGroup { + + private final MultiverseInventories plugin; + private final String name; + private final HashSet worlds = new HashSet<>(); + private final Shares shares = Sharables.noneOf(); + + private String spawnWorld = null; + private EventPriority spawnPriority = EventPriority.NORMAL; + + WorldGroup(final MultiverseInventories inventories, final String name) { + this.plugin = inventories; + this.name = name; + } + + /** + * Get the name of this World Group. + * + * @return Name of this World Group. + */ + public String getName() { + return this.name; + } + + /** + * Adds a world to this world group and updates it in the Config. + * + * @param worldName The name of the world to add. + */ + public void addWorld(String worldName) { + this.addWorld(worldName, true); + } + + /** + * Adds a world to this world group and optionally updates it in the Config. + * + * @param worldName The name of the world to add. + * @param updateConfig True to update this group in the config. + */ + public void addWorld(String worldName, boolean updateConfig) { + this.getWorlds().add(worldName.toLowerCase()); + if (updateConfig) { + plugin.getGroupManager().updateGroup(this); + } + } + + /** + * Convenience method to add a {@link org.bukkit.World} to this World Group. + * + * @param world The world to add. + */ + public void addWorld(World world) { + this.addWorld(world.getName()); + } + + /** + * Convenience method to add multiple worlds to this World Group and updates it in the Config. + * + * @param worlds A collections of worlds to add. + */ + public void addWorlds(Collection worlds) { + this.addWorlds(worlds, true); + } + + /** + * Convenience method to add multiple worlds to this World Group. + * + * @param worlds A collections of worlds to add. + * @param updateConfig True to update this group in the config. + */ + public void addWorlds(Collection worlds, boolean updateConfig) { + worlds.forEach(worldName -> this.addWorld(worldName, false)); + if (updateConfig) { + this.plugin.getGroupManager().updateGroup(this); + } + } + + /** + * Removes a world from this world group and updates the group in the Config. + * + * @param worldName The name of the world to remove. + */ + public void removeWorld(String worldName) { + this.removeWorld(worldName, true); + } + + /** + * Removes a world from this world group and optionally updates it in the Config. + * + * @param worldName The name of the world to remove. + * @param updateConfig True to update this group in the config. + */ + public void removeWorld(String worldName, boolean updateConfig) { + this.getWorlds().remove(worldName.toLowerCase()); + if (updateConfig) { + plugin.getGroupManager().updateGroup(this); + } + } + + /** + * Convenience method to remove a {@link org.bukkit.World} from this World Group. + * + * @param world The world to remove. + */ + public void removeWorld(World world) { + this.removeWorld(world.getName()); + } + + /** + * Remove all the worlds in this World Group. + */ + public void removeAllWorlds() { + this.removeAllWorlds(true); + } + + /** + * Remove all the worlds in this World Group. + * + * @param updateConfig True to update this group in the config. + */ + public void removeAllWorlds(boolean updateConfig) { + this.worlds.clear(); + if (updateConfig) { + this.plugin.getGroupManager().updateGroup(this); + } + } + + /** + * Retrieves all of the worlds in this World Group. + * + * @return The worlds of this World Group. + */ + public Set getWorlds() { + return this.worlds; + } + + /** + * Checks if this group is sharing sharable. This will check both shares and negative shares of the group. + * This is the preferred method for checking if a group shares something as shares may contain ALL shares while + * ones indicated in negative shares means those aren't actually shared. + * + * @param sharable Sharable to check if sharing. + * @return true is the sharable is shared for this group. + */ + public boolean isSharing(Sharable sharable) { + return getShares().isSharing(sharable); + } + + /** + * Retrieves the shares for this World Group. Any changes to this group must be subsequently saved to the data + * source for the changes to be permanent. + * + * @return The shares for this World Group. + */ + public Shares getShares() { + return this.shares; + } + + /** + * @param worldName Name of world to check for. + * @return True if specified world is part of this group. + */ + public boolean containsWorld(String worldName) { + return this.getWorlds().contains(worldName.toLowerCase()); + } + + /** + * @return The name of the world that will be used as the spawn for this group. + * Or null if no world was specified as the group spawn world. + */ + public String getSpawnWorld() { + return this.spawnWorld; + } + + /** + * @param worldName The name of the world to set this groups spawn to. + */ + public void setSpawnWorld(String worldName) { + this.spawnWorld = worldName.toLowerCase(); + } + + /** + * @return The priority for the respawn event that this spawn will act on. + */ + public EventPriority getSpawnPriority() { + return this.spawnPriority; + } + + /** + * @param priority The priority that will be used for respawning the player at + * this group's spawn location if there is one set. + */ + public void setSpawnPriority(EventPriority priority) { + this.spawnPriority = priority; + } + + /** + * Is this a default group. + * + * @return true if this is the default group. + */ + public boolean isDefault() { + return AbstractWorldGroupManager.DEFAULT_GROUP_NAME.equals(getName()); + } + + /** + * Returns the profile container for this group. + * + * @return the profile container for this group. + */ + public ProfileContainer getGroupProfileContainer() { + return plugin.getGroupProfileContainerStore().getContainer(getName()); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append(this.getName()).append(": {Worlds: ["); + String[] worldsString = this.getWorlds().toArray(new String[this.getWorlds().size()]); + for (int i = 0; i < worldsString.length; i++) { + if (i != 0) { + builder.append(", "); + } + builder.append(worldsString[i]); + } + builder.append("], Shares: [").append(this.getShares().toString()).append("]"); + if (this.getSpawnWorld() != null) { + builder.append(", Spawn World: ").append(this.getSpawnWorld()); + builder.append(", Spawn Priority: ").append(this.getSpawnPriority().toString()); + } + builder.append("}"); + return builder.toString(); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java b/src/main/java/org/mvplugins/multiverse/inventories/YamlWorldGroupManager.java similarity index 97% rename from src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java rename to src/main/java/org/mvplugins/multiverse/inventories/YamlWorldGroupManager.java index a4ce12cf..32ab98db 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/YamlWorldGroupManager.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/YamlWorldGroupManager.java @@ -1,10 +1,10 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.minecraft.util.Logging; import com.google.common.collect.Lists; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.util.CommentedYamlConfiguration; -import com.onarandombox.multiverseinventories.util.DeserializationException; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.util.CommentedYamlConfiguration; +import org.mvplugins.multiverse.inventories.util.DeserializationException; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; import org.bukkit.World; diff --git a/src/main/java/com/onarandombox/multiverseinventories/blacklist/ItemBlacklist.java b/src/main/java/org/mvplugins/multiverse/inventories/blacklist/ItemBlacklist.java similarity index 52% rename from src/main/java/com/onarandombox/multiverseinventories/blacklist/ItemBlacklist.java rename to src/main/java/org/mvplugins/multiverse/inventories/blacklist/ItemBlacklist.java index 049ca185..36d808b6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/blacklist/ItemBlacklist.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/blacklist/ItemBlacklist.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.blacklist; +package org.mvplugins.multiverse.inventories.blacklist; /** * Placeholder. diff --git a/src/main/java/com/onarandombox/multiverseinventories/blacklist/SimpleItemBlacklist.java b/src/main/java/org/mvplugins/multiverse/inventories/blacklist/SimpleItemBlacklist.java similarity index 66% rename from src/main/java/com/onarandombox/multiverseinventories/blacklist/SimpleItemBlacklist.java rename to src/main/java/org/mvplugins/multiverse/inventories/blacklist/SimpleItemBlacklist.java index e0395f3b..67fb00c5 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/blacklist/SimpleItemBlacklist.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/blacklist/SimpleItemBlacklist.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.blacklist; +package org.mvplugins.multiverse.inventories.blacklist; /** * Simple Implementation of ItemBlacklist. diff --git a/src/main/java/com/onarandombox/multiverseinventories/blacklist/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/blacklist/package-info.java similarity index 73% rename from src/main/java/com/onarandombox/multiverseinventories/blacklist/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/blacklist/package-info.java index bf4177e5..8f81a034 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/blacklist/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/blacklist/package-info.java @@ -2,5 +2,5 @@ * This package contains classes related to Item Blacklisting per world group/world. * It is also very unfinished and likely to be refactored later. */ -package com.onarandombox.multiverseinventories.blacklist; +package org.mvplugins.multiverse.inventories.blacklist; diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/GroupCommand.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/GroupCommand.java new file mode 100644 index 00000000..bfc587a1 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/GroupCommand.java @@ -0,0 +1,46 @@ +package org.mvplugins.multiverse.inventories.commands; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.commands.prompts.GroupControlPrompt; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.Conversable; +import org.bukkit.conversations.Conversation; +import org.bukkit.conversations.ConversationFactory; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; +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.Subcommand; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +@Service +@CommandAlias("mvinv") +class GroupCommand extends InventoriesCommand { + + private final MultiverseInventories plugin; + + @Inject + GroupCommand(@NotNull MVCommandManager commandManager, @NotNull MultiverseInventories plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvinvgroup|mvinvg") + @Subcommand("group") + @CommandPermission("multiverse.inventories.group") + @Description("Manage a world group wiht prompts!") + void onGroupCommand(@NotNull CommandSender sender) { + if (!(sender instanceof Conversable conversable)) { + this.plugin.getMessager().normal(Message.NON_CONVERSABLE, sender); + return; + } + Conversation conversation = new ConversationFactory(plugin) + .withFirstPrompt(new GroupControlPrompt(plugin, sender)) + .withEscapeSequence("##") + .withModality(false).buildConversation(conversable); + conversation.begin(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/InfoCommand.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/InfoCommand.java new file mode 100644 index 00000000..b2945e23 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/InfoCommand.java @@ -0,0 +1,113 @@ +package org.mvplugins.multiverse.inventories.commands; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Single; +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.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +import java.util.List; +import java.util.Set; + +@Service +@CommandAlias("mvinv") +class InfoCommand extends InventoriesCommand { + + private final MultiverseInventories plugin; + + @Inject + InfoCommand(@NotNull MVCommandManager commandManager, @NotNull MultiverseInventories plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvinvinfo|mvinvi") + @Subcommand("info") + @CommandPermission("multiverse.inventories.info") + @CommandCompletion("@mvworlds") + @Syntax("") + @Description("World and Group Information") + void onInfoCommand( + @NotNull CommandSender sender, + + @Optional + @Single + @Syntax("") + @Description("World or Group") + @NotNull String name + ) { + if (name == null) { + if (!(sender instanceof Player)) { + this.plugin.getMessager().normal(Message.INFO_ZERO_ARG, sender); + return; + } + name = ((Player) sender).getWorld().getName(); + } + + ProfileContainer worldProfileContainer = this.plugin.getWorldProfileContainerStore().getContainer(name); + plugin.getMessager().normal(Message.INFO_WORLD, sender, name); + if (worldProfileContainer != null && Bukkit.getWorld(worldProfileContainer.getContainerName()) != null) { + worldInfo(sender, worldProfileContainer); + } else { + plugin.getMessager().normal(Message.ERROR_NO_WORLD_PROFILE, sender, name); + } + WorldGroup worldGroup = this.plugin.getGroupManager().getGroup(name); + this.plugin.getMessager().normal(Message.INFO_GROUP, sender, name); + if (worldGroup != null) { + this.groupInfo(sender, worldGroup); + } else { + this.plugin.getMessager().normal(Message.ERROR_NO_GROUP, sender, name); + } + } + + private void groupInfo(CommandSender sender, WorldGroup worldGroup) { + StringBuilder worldsString = new StringBuilder(); + Set worlds = worldGroup.getWorlds(); + if (worlds.isEmpty()) { + worldsString.append("N/A"); + } else { + for (String world : worlds) { + if (!worldsString.toString().isEmpty()) { + worldsString.append(", "); + } + worldsString.append(world); + } + } + this.plugin.getMessager().normal(Message.INFO_GROUPS_INFO, + sender, worldsString, worldGroup.getShares().toString()); + } + + private void worldInfo(CommandSender sender, ProfileContainer worldProfileContainer) { + StringBuilder groupsString = new StringBuilder(); + List worldGroups = this.plugin.getGroupManager() + .getGroupsForWorld(worldProfileContainer.getContainerName()); + + if (worldGroups.isEmpty()) { + groupsString.append("N/A"); + } else { + for (WorldGroup worldGroup : worldGroups) { + if (!groupsString.toString().isEmpty()) { + groupsString.append(", "); + } + groupsString.append(worldGroup.getName()); + } + } + + this.plugin.getMessager().normal(Message.INFO_WORLD_INFO, + sender, groupsString.toString()); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/InventoriesCommand.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/InventoriesCommand.java new file mode 100644 index 00000000..bc4c9ec3 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/InventoriesCommand.java @@ -0,0 +1,16 @@ +package org.mvplugins.multiverse.inventories.commands; + +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Contract; + +/** + * Base class for all multiverse inventories commands. + */ +@Contract +public abstract class InventoriesCommand extends MultiverseCommand { + protected InventoriesCommand(@NotNull MVCommandManager commandManager) { + super(commandManager); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/ListCommand.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/ListCommand.java new file mode 100644 index 00000000..0cb68940 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/ListCommand.java @@ -0,0 +1,49 @@ +package org.mvplugins.multiverse.inventories.commands; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.command.CommandSender; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; +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.Subcommand; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +import java.util.Collection; + +@Service +@CommandAlias("mvinv") +class ListCommand extends InventoriesCommand { + + private final MultiverseInventories plugin; + + @Inject + ListCommand(@NotNull MVCommandManager commandManager, @NotNull MultiverseInventories plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvinvlist|mvinvl") + @Subcommand("list") + @CommandPermission("multiverse.inventories.list") + @Description("World and Group Information") + void onListCommand(@NotNull CommandSender sender) { + Collection groups = this.plugin.getGroupManager().getGroups(); + String groupsString = "N/A"; + if (!groups.isEmpty()) { + StringBuilder builder = new StringBuilder(); + for (WorldGroup group : groups) { + if (!builder.toString().isEmpty()) { + builder.append(", "); + } + builder.append(group.getName()); + } + groupsString = builder.toString(); + } + this.plugin.getMessager().normal(Message.LIST_GROUPS, sender, groupsString); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/ReloadCommand.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/ReloadCommand.java new file mode 100644 index 00000000..f60e8fae --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/ReloadCommand.java @@ -0,0 +1,35 @@ +package org.mvplugins.multiverse.inventories.commands; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.command.CommandSender; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; +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.Subcommand; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +@Service +@CommandAlias("mvinv") +class ReloadCommand extends InventoriesCommand { + + private final MultiverseInventories plugin; + + @Inject + ReloadCommand(@NotNull MVCommandManager commandManager, @NotNull MultiverseInventories plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvinvreload") + @Subcommand("reload") + @CommandPermission("multiverse.inventories.reload") + @Description("Reloads config file") + void onReloadCommand(@NotNull CommandSender sender) { + this.plugin.reloadConfig(); + this.plugin.getMessager().normal(Message.RELOAD_COMPLETE, sender); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/ToggleCommand.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/ToggleCommand.java new file mode 100644 index 00000000..c83821ae --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/ToggleCommand.java @@ -0,0 +1,71 @@ +package org.mvplugins.multiverse.inventories.commands; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.bukkit.command.CommandSender; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Single; +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.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +@Service +@CommandAlias("mvinv") +class ToggleCommand extends InventoriesCommand { + + private final MultiverseInventories plugin; + + @Inject + ToggleCommand(MVCommandManager commandManager, @NotNull MultiverseInventories plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvinvtoggle") + @Subcommand("toggle") + @CommandPermission("multiverse.inventories.addshares") + @CommandCompletion("economy|last_location") + @Syntax("") + @Description("Toggles the usage of optional sharables") + void onToggleCommand( + @NotNull CommandSender sender, + + @Single + @Syntax("") + @Description("Share to toggle") + @NotNull String shareName + ) { + Shares shares = Sharables.lookup(shareName.toLowerCase()); + if (shares == null) { + this.plugin.getMessager().normal(Message.ERROR_NO_SHARES_SPECIFIED, sender); + return; + } + boolean foundOpt = false; + for (Sharable sharable : shares) { + if (sharable.isOptional()) { + foundOpt = true; + if (this.plugin.getMVIConfig().getOptionalShares().contains(sharable)) { + this.plugin.getMVIConfig().getOptionalShares().remove(sharable); + this.plugin.getMessager().normal(Message.NOW_NOT_USING_OPTIONAL, sender, sharable.getNames()[0]); + } else { + this.plugin.getMVIConfig().getOptionalShares().add(sharable); + this.plugin.getMessager().normal(Message.NOW_USING_OPTIONAL, sender, sharable.getNames()[0]); + } + } + } + if (foundOpt) { + this.plugin.getMVIConfig().save(); + } else { + this.plugin.getMessager().normal(Message.NO_OPTIONAL_SHARES, sender, shareName); + } + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/commands/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/package-info.java new file mode 100644 index 00000000..513b441b --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains all Commands. + */ +package org.mvplugins.multiverse.inventories.commands; + diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupControlPrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupControlPrompt.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupControlPrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupControlPrompt.java index fa517717..48c084fe 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupControlPrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupControlPrompt.java @@ -1,33 +1,33 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -public class GroupControlPrompt extends InventoriesPrompt { - - public GroupControlPrompt(final MultiverseInventories plugin, final CommandSender sender) { - super(plugin, sender); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - return messager.getMessage(Message.GROUP_COMMAND_PROMPT); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - if (s.equalsIgnoreCase("delete")) { - return new GroupDeletePrompt(plugin, sender); - } else if (s.equalsIgnoreCase("create")) { - return new GroupCreatePrompt(plugin, sender); - } else if (s.equalsIgnoreCase("edit")) { - return new GroupEditPrompt(plugin, sender); - } else { - messager.normal(Message.INVALID_PROMPT_OPTION, sender); - return this; - } - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +public class GroupControlPrompt extends InventoriesPrompt { + + public GroupControlPrompt(final MultiverseInventories plugin, final CommandSender sender) { + super(plugin, sender); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + return messager.getMessage(Message.GROUP_COMMAND_PROMPT); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + if (s.equalsIgnoreCase("delete")) { + return new GroupDeletePrompt(plugin, sender); + } else if (s.equalsIgnoreCase("create")) { + return new GroupCreatePrompt(plugin, sender); + } else if (s.equalsIgnoreCase("edit")) { + return new GroupEditPrompt(plugin, sender); + } else { + messager.normal(Message.INVALID_PROMPT_OPTION, sender); + return this; + } + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupCreatePrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupCreatePrompt.java similarity index 81% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupCreatePrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupCreatePrompt.java index ea03e3c1..c473178b 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupCreatePrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupCreatePrompt.java @@ -1,37 +1,37 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -class GroupCreatePrompt extends InventoriesPrompt { - - public GroupCreatePrompt(final MultiverseInventories plugin, final CommandSender sender) { - super(plugin, sender); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - return messager.getMessage(Message.GROUP_CREATE_PROMPT); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - final WorldGroup group = plugin.getGroupManager().getGroup(s); - if (group == null) { - if (s.isEmpty() || !s.matches("^[a-zA-Z0-9][a-zA-Z0-9_]*$")) { - messager.normal(Message.GROUP_INVALID_NAME, sender); - return this; - } - final WorldGroup newGroup = plugin.getGroupManager().newEmptyGroup(s); - return new GroupWorldsPrompt(plugin, sender, newGroup, - new GroupSharesPrompt(plugin, sender, newGroup, Prompt.END_OF_CONVERSATION, true), true); - } else { - messager.normal(Message.GROUP_EXISTS, sender, s); - } - return Prompt.END_OF_CONVERSATION; - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +class GroupCreatePrompt extends InventoriesPrompt { + + public GroupCreatePrompt(final MultiverseInventories plugin, final CommandSender sender) { + super(plugin, sender); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + return messager.getMessage(Message.GROUP_CREATE_PROMPT); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + final WorldGroup group = plugin.getGroupManager().getGroup(s); + if (group == null) { + if (s.isEmpty() || !s.matches("^[a-zA-Z0-9][a-zA-Z0-9_]*$")) { + messager.normal(Message.GROUP_INVALID_NAME, sender); + return this; + } + final WorldGroup newGroup = plugin.getGroupManager().newEmptyGroup(s); + return new GroupWorldsPrompt(plugin, sender, newGroup, + new GroupSharesPrompt(plugin, sender, newGroup, Prompt.END_OF_CONVERSATION, true), true); + } else { + messager.normal(Message.GROUP_EXISTS, sender, s); + } + return Prompt.END_OF_CONVERSATION; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupDeletePrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupDeletePrompt.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupDeletePrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupDeletePrompt.java index 12617b81..a1e64b8b 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupDeletePrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupDeletePrompt.java @@ -1,42 +1,42 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -class GroupDeletePrompt extends InventoriesPrompt { - - public GroupDeletePrompt(final MultiverseInventories plugin, final CommandSender sender) { - super(plugin, sender); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - final StringBuilder builder = new StringBuilder(); - for (WorldGroup group : plugin.getGroupManager().getGroups()) { - if (builder.length() == 0) { - builder.append(ChatColor.WHITE); - } else { - builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); - } - builder.append(group.getName()); - } - return messager.getMessage(Message.GROUP_DELETE_PROMPT, builder.toString()); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - final WorldGroup group = plugin.getGroupManager().getGroup(s); - if (group == null) { - messager.normal(Message.ERROR_NO_GROUP, sender, s); - } else { - plugin.getGroupManager().removeGroup(group); - messager.normal(Message.GROUP_REMOVED, sender, s); - } - return Prompt.END_OF_CONVERSATION; - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +class GroupDeletePrompt extends InventoriesPrompt { + + public GroupDeletePrompt(final MultiverseInventories plugin, final CommandSender sender) { + super(plugin, sender); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + final StringBuilder builder = new StringBuilder(); + for (WorldGroup group : plugin.getGroupManager().getGroups()) { + if (builder.length() == 0) { + builder.append(ChatColor.WHITE); + } else { + builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); + } + builder.append(group.getName()); + } + return messager.getMessage(Message.GROUP_DELETE_PROMPT, builder.toString()); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + final WorldGroup group = plugin.getGroupManager().getGroup(s); + if (group == null) { + messager.normal(Message.ERROR_NO_GROUP, sender, s); + } else { + plugin.getGroupManager().removeGroup(group); + messager.normal(Message.GROUP_REMOVED, sender, s); + } + return Prompt.END_OF_CONVERSATION; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupEditPrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupEditPrompt.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupEditPrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupEditPrompt.java index 395e99f3..67f1b439 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupEditPrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupEditPrompt.java @@ -1,41 +1,41 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -class GroupEditPrompt extends InventoriesPrompt { - - public GroupEditPrompt(final MultiverseInventories plugin, final CommandSender sender) { - super(plugin, sender); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - final StringBuilder builder = new StringBuilder(); - for (WorldGroup group : plugin.getGroupManager().getGroups()) { - if (builder.length() == 0) { - builder.append(ChatColor.WHITE); - } else { - builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); - } - builder.append(group.getName()); - } - return messager.getMessage(Message.GROUP_EDIT_PROMPT, builder.toString()); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - final WorldGroup group = plugin.getGroupManager().getGroup(s); - if (group == null) { - messager.normal(Message.ERROR_NO_GROUP, sender, s); - } else { - return new GroupModifyPrompt(plugin, sender, group); - } - return Prompt.END_OF_CONVERSATION; - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +class GroupEditPrompt extends InventoriesPrompt { + + public GroupEditPrompt(final MultiverseInventories plugin, final CommandSender sender) { + super(plugin, sender); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + final StringBuilder builder = new StringBuilder(); + for (WorldGroup group : plugin.getGroupManager().getGroups()) { + if (builder.length() == 0) { + builder.append(ChatColor.WHITE); + } else { + builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); + } + builder.append(group.getName()); + } + return messager.getMessage(Message.GROUP_EDIT_PROMPT, builder.toString()); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + final WorldGroup group = plugin.getGroupManager().getGroup(s); + if (group == null) { + messager.normal(Message.ERROR_NO_GROUP, sender, s); + } else { + return new GroupModifyPrompt(plugin, sender, group); + } + return Prompt.END_OF_CONVERSATION; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupModifyPrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupModifyPrompt.java similarity index 79% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupModifyPrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupModifyPrompt.java index 87a4abd4..17952186 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupModifyPrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupModifyPrompt.java @@ -1,36 +1,36 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -class GroupModifyPrompt extends InventoriesPrompt { - - protected final WorldGroup group; - - public GroupModifyPrompt(final MultiverseInventories plugin, final CommandSender sender, - final WorldGroup group) { - super(plugin, sender); - this.group = group; - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - return messager.getMessage(Message.GROUP_MODIFY_PROMPT, group.getName()); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - if (s.equalsIgnoreCase("worlds")) { - return new GroupWorldsPrompt(plugin, sender, group, this, false); - } else if (s.equalsIgnoreCase("shares")) { - return new GroupSharesPrompt(plugin, sender, group, this, false); - } else { - messager.normal(Message.INVALID_PROMPT_OPTION, sender); - return this; - } - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +class GroupModifyPrompt extends InventoriesPrompt { + + protected final WorldGroup group; + + public GroupModifyPrompt(final MultiverseInventories plugin, final CommandSender sender, + final WorldGroup group) { + super(plugin, sender); + this.group = group; + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + return messager.getMessage(Message.GROUP_MODIFY_PROMPT, group.getName()); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + if (s.equalsIgnoreCase("worlds")) { + return new GroupWorldsPrompt(plugin, sender, group, this, false); + } else if (s.equalsIgnoreCase("shares")) { + return new GroupSharesPrompt(plugin, sender, group, this, false); + } else { + messager.normal(Message.INVALID_PROMPT_OPTION, sender); + return this; + } + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupSharesPrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupSharesPrompt.java similarity index 84% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupSharesPrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupSharesPrompt.java index f2071f52..f20d8668 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupSharesPrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupSharesPrompt.java @@ -1,80 +1,80 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.share.Shares; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -class GroupSharesPrompt extends InventoriesPrompt { - - protected final WorldGroup group; - protected final Prompt nextPrompt; - protected final boolean isCreating; - protected final Shares shares; - - public GroupSharesPrompt(final MultiverseInventories plugin, final CommandSender sender, - final WorldGroup group, final Prompt nextPrompt, - final boolean creatingGroup) { - super(plugin, sender); - this.group = group; - this.nextPrompt = nextPrompt; - this.isCreating = creatingGroup; - this.shares = Sharables.fromShares(group.getShares()); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - final StringBuilder builder = new StringBuilder(); - for (final Sharable sharable : shares) { - if (builder.length() == 0) { - builder.append(ChatColor.WHITE); - } else { - builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); - } - builder.append(sharable.toString()); - } - return messager.getMessage(Message.GROUP_SHARES_PROMPT, group.getName(), builder.toString()); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - if (s.equals("@")) { - group.getShares().clear(); - group.getShares().addAll(this.shares); - plugin.getGroupManager().updateGroup(group); - if (isCreating) { - messager.normal(Message.GROUP_CREATION_COMPLETE, sender); - } else { - messager.normal(Message.GROUP_UPDATED, sender); - } - messager.normal(Message.INFO_GROUP, sender, group.getName()); - messager.normal(Message.INFO_GROUPS_INFO, sender, group.getWorlds(), group.getShares()); - plugin.getGroupManager().checkForConflicts(sender); - return nextPrompt; - } - - boolean negative = false; - Shares shares = Sharables.lookup(s.toLowerCase()); - if (shares == null && s.startsWith("-") && s.length() > 1) { - negative = true; - shares = Sharables.lookup(s.toLowerCase().substring(1)); - } - - if (shares == null) { - messager.normal(Message.ERROR_NO_SHARES_SPECIFIED, sender); - return this; - } - if (negative) { - this.shares.removeAll(shares); - return this; - } - this.shares.addAll(shares); - return this; - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +class GroupSharesPrompt extends InventoriesPrompt { + + protected final WorldGroup group; + protected final Prompt nextPrompt; + protected final boolean isCreating; + protected final Shares shares; + + public GroupSharesPrompt(final MultiverseInventories plugin, final CommandSender sender, + final WorldGroup group, final Prompt nextPrompt, + final boolean creatingGroup) { + super(plugin, sender); + this.group = group; + this.nextPrompt = nextPrompt; + this.isCreating = creatingGroup; + this.shares = Sharables.fromShares(group.getShares()); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + final StringBuilder builder = new StringBuilder(); + for (final Sharable sharable : shares) { + if (builder.length() == 0) { + builder.append(ChatColor.WHITE); + } else { + builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); + } + builder.append(sharable.toString()); + } + return messager.getMessage(Message.GROUP_SHARES_PROMPT, group.getName(), builder.toString()); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + if (s.equals("@")) { + group.getShares().clear(); + group.getShares().addAll(this.shares); + plugin.getGroupManager().updateGroup(group); + if (isCreating) { + messager.normal(Message.GROUP_CREATION_COMPLETE, sender); + } else { + messager.normal(Message.GROUP_UPDATED, sender); + } + messager.normal(Message.INFO_GROUP, sender, group.getName()); + messager.normal(Message.INFO_GROUPS_INFO, sender, group.getWorlds(), group.getShares()); + plugin.getGroupManager().checkForConflicts(sender); + return nextPrompt; + } + + boolean negative = false; + Shares shares = Sharables.lookup(s.toLowerCase()); + if (shares == null && s.startsWith("-") && s.length() > 1) { + negative = true; + shares = Sharables.lookup(s.toLowerCase().substring(1)); + } + + if (shares == null) { + messager.normal(Message.ERROR_NO_SHARES_SPECIFIED, sender); + return this; + } + if (negative) { + this.shares.removeAll(shares); + return this; + } + this.shares.addAll(shares); + return this; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupWorldsPrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupWorldsPrompt.java similarity index 89% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupWorldsPrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupWorldsPrompt.java index 6d428863..6050ecbf 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/GroupWorldsPrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/GroupWorldsPrompt.java @@ -1,87 +1,87 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.locale.Message; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -import java.util.HashSet; -import java.util.Set; - -class GroupWorldsPrompt extends InventoriesPrompt { - - protected final WorldGroup group; - protected final Prompt nextPrompt; - protected final boolean isCreating; - protected final Set worlds; - - public GroupWorldsPrompt(final MultiverseInventories plugin, final CommandSender sender, - final WorldGroup group, final Prompt nextPrompt, - final boolean creatingGroup) { - super(plugin, sender); - this.group = group; - this.nextPrompt = nextPrompt; - this.isCreating = creatingGroup; - this.worlds = new HashSet(group.getWorlds()); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - final StringBuilder builder = new StringBuilder(); - for (final String world : worlds) { - if (builder.length() == 0) { - builder.append(ChatColor.WHITE); - } else { - builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); - } - builder.append(world); - } - return messager.getMessage(Message.GROUP_WORLDS_PROMPT, group.getName(), builder.toString()); - } - - @Override - public Prompt acceptInput(final ConversationContext conversationContext, final String s) { - if (s.equals("@")) { - if (worlds.isEmpty()) { - messager.normal(Message.GROUP_WORLDS_EMPTY, sender); - return this; - } - group.removeAllWorlds(false); - group.addWorlds(worlds, false); - if (!isCreating) { - plugin.getGroupManager().updateGroup(group); - messager.normal(Message.GROUP_UPDATED, sender); - messager.normal(Message.INFO_GROUP, sender, group.getName()); - messager.normal(Message.INFO_GROUPS_INFO, sender, group.getWorlds(), group.getShares()); - } - return nextPrompt; - } - - boolean negative = false; - World world = Bukkit.getWorld(s); - if (world == null && s.startsWith("-") && s.length() > 1) { - negative = true; - world = Bukkit.getWorld(s.substring(1)); - } - - if (world == null) { - messager.normal(Message.ERROR_NO_WORLD, sender, s); - return this; - } - if (negative) { - if (!worlds.contains(world.getName())) { - messager.normal(Message.WORLD_NOT_IN_GROUP, sender, world.getName(), group.getName()); - return this; - } - worlds.remove(world.getName()); - return this; - } - worlds.add(world.getName()); - return this; - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.locale.Message; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +import java.util.HashSet; +import java.util.Set; + +class GroupWorldsPrompt extends InventoriesPrompt { + + protected final WorldGroup group; + protected final Prompt nextPrompt; + protected final boolean isCreating; + protected final Set worlds; + + public GroupWorldsPrompt(final MultiverseInventories plugin, final CommandSender sender, + final WorldGroup group, final Prompt nextPrompt, + final boolean creatingGroup) { + super(plugin, sender); + this.group = group; + this.nextPrompt = nextPrompt; + this.isCreating = creatingGroup; + this.worlds = new HashSet(group.getWorlds()); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + final StringBuilder builder = new StringBuilder(); + for (final String world : worlds) { + if (builder.length() == 0) { + builder.append(ChatColor.WHITE); + } else { + builder.append(ChatColor.GOLD).append(", ").append(ChatColor.WHITE); + } + builder.append(world); + } + return messager.getMessage(Message.GROUP_WORLDS_PROMPT, group.getName(), builder.toString()); + } + + @Override + public Prompt acceptInput(final ConversationContext conversationContext, final String s) { + if (s.equals("@")) { + if (worlds.isEmpty()) { + messager.normal(Message.GROUP_WORLDS_EMPTY, sender); + return this; + } + group.removeAllWorlds(false); + group.addWorlds(worlds, false); + if (!isCreating) { + plugin.getGroupManager().updateGroup(group); + messager.normal(Message.GROUP_UPDATED, sender); + messager.normal(Message.INFO_GROUP, sender, group.getName()); + messager.normal(Message.INFO_GROUPS_INFO, sender, group.getWorlds(), group.getShares()); + } + return nextPrompt; + } + + boolean negative = false; + World world = Bukkit.getWorld(s); + if (world == null && s.startsWith("-") && s.length() > 1) { + negative = true; + world = Bukkit.getWorld(s.substring(1)); + } + + if (world == null) { + messager.normal(Message.ERROR_NO_WORLD, sender, s); + return this; + } + if (negative) { + if (!worlds.contains(world.getName())) { + messager.normal(Message.WORLD_NOT_IN_GROUP, sender, world.getName(), group.getName()); + return this; + } + worlds.remove(world.getName()); + return this; + } + worlds.add(world.getName()); + return this; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/InventoriesPrompt.java b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/InventoriesPrompt.java similarity index 74% rename from src/main/java/com/onarandombox/multiverseinventories/command/prompts/InventoriesPrompt.java rename to src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/InventoriesPrompt.java index 7ec9f212..c3ed4c52 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/command/prompts/InventoriesPrompt.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/commands/prompts/InventoriesPrompt.java @@ -1,25 +1,25 @@ -package com.onarandombox.multiverseinventories.command.prompts; - -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.locale.Messager; -import org.bukkit.command.CommandSender; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; - -abstract class InventoriesPrompt implements Prompt { - - protected final MultiverseInventories plugin; - protected final Messager messager; - protected final CommandSender sender; - - InventoriesPrompt(final MultiverseInventories plugin, final CommandSender sender) { - this.plugin = plugin; - this.messager = plugin.getMessager(); - this.sender = sender; - } - - @Override - public boolean blocksForInput(final ConversationContext conversationContext) { - return true; - } -} +package org.mvplugins.multiverse.inventories.commands.prompts; + +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.locale.Messager; +import org.bukkit.command.CommandSender; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; + +abstract class InventoriesPrompt implements Prompt { + + protected final MultiverseInventories plugin; + protected final Messager messager; + protected final CommandSender sender; + + InventoriesPrompt(final MultiverseInventories plugin, final CommandSender sender) { + this.plugin = plugin; + this.messager = plugin.getMessager(); + this.sender = sender; + } + + @Override + public boolean blocksForInput(final ConversationContext conversationContext) { + return true; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/event/GameModeChangeShareHandlingEvent.java b/src/main/java/org/mvplugins/multiverse/inventories/event/GameModeChangeShareHandlingEvent.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/event/GameModeChangeShareHandlingEvent.java rename to src/main/java/org/mvplugins/multiverse/inventories/event/GameModeChangeShareHandlingEvent.java index b785a28b..2a397f1d 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/event/GameModeChangeShareHandlingEvent.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/event/GameModeChangeShareHandlingEvent.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.event; +package org.mvplugins.multiverse.inventories.event; -import com.onarandombox.multiverseinventories.ShareHandler; +import org.mvplugins.multiverse.inventories.ShareHandler; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/src/main/java/com/onarandombox/multiverseinventories/event/ShareHandlingEvent.java b/src/main/java/org/mvplugins/multiverse/inventories/event/ShareHandlingEvent.java similarity index 91% rename from src/main/java/com/onarandombox/multiverseinventories/event/ShareHandlingEvent.java rename to src/main/java/org/mvplugins/multiverse/inventories/event/ShareHandlingEvent.java index 9bc81d2f..29669135 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/event/ShareHandlingEvent.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/event/ShareHandlingEvent.java @@ -1,7 +1,7 @@ -package com.onarandombox.multiverseinventories.event; +package org.mvplugins.multiverse.inventories.event; -import com.onarandombox.multiverseinventories.ShareHandler; -import com.onarandombox.multiverseinventories.share.PersistingProfile; +import org.mvplugins.multiverse.inventories.ShareHandler; +import org.mvplugins.multiverse.inventories.share.PersistingProfile; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; diff --git a/src/main/java/com/onarandombox/multiverseinventories/event/WorldChangeShareHandlingEvent.java b/src/main/java/org/mvplugins/multiverse/inventories/event/WorldChangeShareHandlingEvent.java similarity index 91% rename from src/main/java/com/onarandombox/multiverseinventories/event/WorldChangeShareHandlingEvent.java rename to src/main/java/org/mvplugins/multiverse/inventories/event/WorldChangeShareHandlingEvent.java index 87bda1e1..71266aa3 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/event/WorldChangeShareHandlingEvent.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/event/WorldChangeShareHandlingEvent.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.event; +package org.mvplugins.multiverse.inventories.event; -import com.onarandombox.multiverseinventories.ShareHandler; +import org.mvplugins.multiverse.inventories.ShareHandler; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; diff --git a/src/main/java/com/onarandombox/multiverseinventories/event/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/event/package-info.java similarity index 69% rename from src/main/java/com/onarandombox/multiverseinventories/event/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/event/package-info.java index c9221141..deb2da33 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/event/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/event/package-info.java @@ -1,5 +1,5 @@ /** * This package contains event classes that are thrown by Multiverse-Inventories for handling by other plugins. */ -package com.onarandombox.multiverseinventories.event; +package org.mvplugins.multiverse.inventories.event; diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/LazyLocaleMessageProvider.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/LazyLocaleMessageProvider.java similarity index 96% rename from src/main/java/com/onarandombox/multiverseinventories/locale/LazyLocaleMessageProvider.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/LazyLocaleMessageProvider.java index baf9c688..a4fb2d58 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/LazyLocaleMessageProvider.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/LazyLocaleMessageProvider.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; import java.util.Locale; import java.util.Set; diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/LocalizationLoadingException.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/LocalizationLoadingException.java similarity index 95% rename from src/main/java/com/onarandombox/multiverseinventories/locale/LocalizationLoadingException.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/LocalizationLoadingException.java index f5bfea63..acd78fb4 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/LocalizationLoadingException.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/LocalizationLoadingException.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; import java.io.IOException; import java.util.Locale; diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/Message.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/Message.java similarity index 96% rename from src/main/java/com/onarandombox/multiverseinventories/locale/Message.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/Message.java index badd749d..42f6f27d 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/Message.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/Message.java @@ -1,113 +1,113 @@ -package com.onarandombox.multiverseinventories.locale; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * An enum containing all messages/strings used by Multiverse. - */ -public enum Message { - // BEGIN CHECKSTYLE-SUPPRESSION: Javadoc - TEST_STRING("a test-string from the enum"), - - // Generic Strings - GENERIC_SORRY("Sorry..."), - GENERIC_PAGE("Page"), - GENERIC_OF("of"), - GENERIC_UNLOADED("UNLOADED"), - GENERIC_PLUGIN_DISABLED("This plugin is Disabled!"), - GENERIC_ERROR("[Error]"), - GENERIC_SUCCESS("[Success]"), - GENERIC_INFO("[Info]"), - GENERIC_HELP("[Help]"), - GENERIC_COMMAND_NO_PERMISSION("You do not have permission to %1. (%2)"), - GENERIC_THE_CONSOLE("the console"), - GENERIC_NOT_LOGGED_IN("%1 is not logged on right now!"), - GENERIC_OFF("OFF"), - - // Errors - ERROR_CONFIG_LOAD("Encountered an error while loading the configuration file. Disabling..."), - ERROR_DATA_LOAD("Encountered an error while loading the data file. Disabling..."), - ERROR_NO_GROUP("&6There is no group with the name: &f%1"), - ERROR_NO_WORLD("&6There is no world with the name: &f%1"), - ERROR_NO_WORLD_PROFILE("&6There is no profile container for the world: &f%1"), - ERROR_PLUGIN_NOT_ENABLED("&f%1 &6is not enabled so you may not import data from it!"), - ERROR_UNSUPPORTED_IMPORT("&6Sorry, ''&f%1&6'' is not supported for importing."), - ERROR_NO_SHARES_SPECIFIED("&cYou did not specify any valid shares!"), - - // Group Conflicts - CONFLICT_RESULTS("Conflict found for groups: '%1' and '%2' because they both share: '%3' for the world(s): '%4'"), - CONFLICT_CHECKING("Checking for conflicts in groups..."), - CONFLICT_FOUND("Conflicts have been found... If these are not resolved, you may experience problems with your data."), - CONFLICT_NOT_FOUND("No group conflicts found!"), - - //// Commands - NON_CONVERSABLE("You are not allowed to access conversations (remote console?)"), - INVALID_PROMPT_OPTION("&cThat is not a valid option! Type &f##&c to stop working on groups."), - // Info Command - INFO_ZERO_ARG("You may only use the no argument version of this command in game!"), - INFO_WORLD("&b===[ Info for world: &6%1&b ]==="), - INFO_WORLD_INFO("&6Groups:&f %1"), - INFO_GROUP("&b===[ Info for group: &6%1&b ]==="), - INFO_GROUPS_INFO("&6Worlds:&f %1", "&bShares:&f %2"), - // Group Command - GROUP_COMMAND_PROMPT("&6What would you like to do? &fCreate&6, &fEdit &6or &fDelete&6. Enter &f##&6 at any time to cancel."), - GROUP_CREATE_PROMPT("&6Please name your new group: "), - GROUP_EDIT_PROMPT("&6Edit which group? %1"), - GROUP_DELETE_PROMPT("&6Delete which group? %1"), - GROUP_MODIFY_PROMPT("&6Which would you like to change for &e%1&6? &fWorlds &6or &fShares&6. Enter &f##&6 to finish."), - GROUP_WORLDS_PROMPT("&6Enter the name of a world to add to group &f%1&6 or enter &f@&6 to continue. To remove a world, precede the name with the minus symbol. (ex: &f-worldname&6). Current worlds: %2"), - GROUP_SHARES_PROMPT("&6Enter &fall&6 or a specific share to add to group &f%1&6 or enter &f@&6 to continue. To remove shares, precede the name with the minus symbol (ex: &f-inventory&6). Current shares: %2"), - GROUP_INVALID_NAME("&cThat name is not valid! May only contain letters, numbers, and underscores."), - GROUP_EXISTS("&cThat group already exists! (&f%1&c)"), - GROUP_REMOVED("&2Removed group: &f%1"), - GROUP_WORLDS_EMPTY("&cYou may not have a group with no worlds, please add worlds or type &f##&c to cancel."), - GROUP_CREATION_COMPLETE("&2You created a new group!"), - GROUP_UPDATED("&2Group has been updated!"), - // List Command - LIST_GROUPS("&b===[ Group List ]===", "&6Groups:&f %1"), - // Reload Command - RELOAD_COMPLETE("&b===[ Reload Complete! ]==="), - // AddWorld Command - WORLD_ADDED("&6World:&f %1 &6added to Group: &f%2"), - WORLD_ALREADY_EXISTS("&6World:&f %1 &6already part of Group: &f%2"), - // RemoveWorld Command - WORLD_REMOVED("&6World:&f %1 &6removed from Group: &f%2"), - WORLD_NOT_IN_GROUP("&6World:&f %1 &6is not part of Group: &f%2"), - // AddShares Command - NOW_SHARING("&6Group: &f%1 &6is now sharing: &f%2"), - // Spawn Command - TELEPORTING("Teleporting to this world group's spawn..."), - TELEPORTED_BY("You were teleported by: %1"), - TELEPORT_CONSOLE_ERROR("From the console, you must provide a PLAYER"), - // DebugCommand - INVALID_DEBUG("&fInvalid debug level. Please use number 0-3. &b(3 being many many messages!)"), - DEBUG_SET("Debug mode is %1"), - // Toggle Command - NOW_USING_OPTIONAL("&f%1 &6will now be considered when player's change world."), - NOW_NOT_USING_OPTIONAL("&f%1 &6will no longer be considered when player's change world."), - NO_OPTIONAL_SHARES("&f%1 &6is not an optional share!"), - // Migrate Command - MIGRATE_FAILED("Failed to migrate data from %1 to %2! Check logs for error details."), - MIGRATE_SUCCESSFUL("Migrated data from %1 to %2!"); - - // BEGIN CHECKSTYLE-SUPPRESSION: Javadoc - - private final List def; - - Message(String def, String... extra) { - this.def = new ArrayList(); - this.def.add(def); - this.def.addAll(Arrays.asList(extra)); - } - - /** - * @return This {@link Message}'s default-message - */ - public List getDefault() { - return def; - } - -} - +package org.mvplugins.multiverse.inventories.locale; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * An enum containing all messages/strings used by Multiverse. + */ +public enum Message { + // BEGIN CHECKSTYLE-SUPPRESSION: Javadoc + TEST_STRING("a test-string from the enum"), + + // Generic Strings + GENERIC_SORRY("Sorry..."), + GENERIC_PAGE("Page"), + GENERIC_OF("of"), + GENERIC_UNLOADED("UNLOADED"), + GENERIC_PLUGIN_DISABLED("This plugin is Disabled!"), + GENERIC_ERROR("[Error]"), + GENERIC_SUCCESS("[Success]"), + GENERIC_INFO("[Info]"), + GENERIC_HELP("[Help]"), + GENERIC_COMMAND_NO_PERMISSION("You do not have permission to %1. (%2)"), + GENERIC_THE_CONSOLE("the console"), + GENERIC_NOT_LOGGED_IN("%1 is not logged on right now!"), + GENERIC_OFF("OFF"), + + // Errors + ERROR_CONFIG_LOAD("Encountered an error while loading the configuration file. Disabling..."), + ERROR_DATA_LOAD("Encountered an error while loading the data file. Disabling..."), + ERROR_NO_GROUP("&6There is no group with the name: &f%1"), + ERROR_NO_WORLD("&6There is no world with the name: &f%1"), + ERROR_NO_WORLD_PROFILE("&6There is no profile container for the world: &f%1"), + ERROR_PLUGIN_NOT_ENABLED("&f%1 &6is not enabled so you may not import data from it!"), + ERROR_UNSUPPORTED_IMPORT("&6Sorry, ''&f%1&6'' is not supported for importing."), + ERROR_NO_SHARES_SPECIFIED("&cYou did not specify any valid shares!"), + + // Group Conflicts + CONFLICT_RESULTS("Conflict found for groups: '%1' and '%2' because they both share: '%3' for the world(s): '%4'"), + CONFLICT_CHECKING("Checking for conflicts in groups..."), + CONFLICT_FOUND("Conflicts have been found... If these are not resolved, you may experience problems with your data."), + CONFLICT_NOT_FOUND("No group conflicts found!"), + + //// Commands + NON_CONVERSABLE("You are not allowed to access conversations (remote console?)"), + INVALID_PROMPT_OPTION("&cThat is not a valid option! Type &f##&c to stop working on groups."), + // Info Command + INFO_ZERO_ARG("You may only use the no argument version of this command in game!"), + INFO_WORLD("&b===[ Info for world: &6%1&b ]==="), + INFO_WORLD_INFO("&6Groups:&f %1"), + INFO_GROUP("&b===[ Info for group: &6%1&b ]==="), + INFO_GROUPS_INFO("&6Worlds:&f %1", "&bShares:&f %2"), + // Group Command + GROUP_COMMAND_PROMPT("&6What would you like to do? &fCreate&6, &fEdit &6or &fDelete&6. Enter &f##&6 at any time to cancel."), + GROUP_CREATE_PROMPT("&6Please name your new group: "), + GROUP_EDIT_PROMPT("&6Edit which group? %1"), + GROUP_DELETE_PROMPT("&6Delete which group? %1"), + GROUP_MODIFY_PROMPT("&6Which would you like to change for &e%1&6? &fWorlds &6or &fShares&6. Enter &f##&6 to finish."), + GROUP_WORLDS_PROMPT("&6Enter the name of a world to add to group &f%1&6 or enter &f@&6 to continue. To remove a world, precede the name with the minus symbol. (ex: &f-worldname&6). Current worlds: %2"), + GROUP_SHARES_PROMPT("&6Enter &fall&6 or a specific share to add to group &f%1&6 or enter &f@&6 to continue. To remove shares, precede the name with the minus symbol (ex: &f-inventory&6). Current shares: %2"), + GROUP_INVALID_NAME("&cThat name is not valid! May only contain letters, numbers, and underscores."), + GROUP_EXISTS("&cThat group already exists! (&f%1&c)"), + GROUP_REMOVED("&2Removed group: &f%1"), + GROUP_WORLDS_EMPTY("&cYou may not have a group with no worlds, please add worlds or type &f##&c to cancel."), + GROUP_CREATION_COMPLETE("&2You created a new group!"), + GROUP_UPDATED("&2Group has been updated!"), + // List Command + LIST_GROUPS("&b===[ Group List ]===", "&6Groups:&f %1"), + // Reload Command + RELOAD_COMPLETE("&b===[ Reload Complete! ]==="), + // AddWorld Command + WORLD_ADDED("&6World:&f %1 &6added to Group: &f%2"), + WORLD_ALREADY_EXISTS("&6World:&f %1 &6already part of Group: &f%2"), + // RemoveWorld Command + WORLD_REMOVED("&6World:&f %1 &6removed from Group: &f%2"), + WORLD_NOT_IN_GROUP("&6World:&f %1 &6is not part of Group: &f%2"), + // AddShares Command + NOW_SHARING("&6Group: &f%1 &6is now sharing: &f%2"), + // Spawn Command + TELEPORTING("Teleporting to this world group's spawn..."), + TELEPORTED_BY("You were teleported by: %1"), + TELEPORT_CONSOLE_ERROR("From the console, you must provide a PLAYER"), + // DebugCommand + INVALID_DEBUG("&fInvalid debug level. Please use number 0-3. &b(3 being many many messages!)"), + DEBUG_SET("Debug mode is %1"), + // Toggle Command + NOW_USING_OPTIONAL("&f%1 &6will now be considered when player's change world."), + NOW_NOT_USING_OPTIONAL("&f%1 &6will no longer be considered when player's change world."), + NO_OPTIONAL_SHARES("&f%1 &6is not an optional share!"), + // Migrate Command + MIGRATE_FAILED("Failed to migrate data from %1 to %2! Check logs for error details."), + MIGRATE_SUCCESSFUL("Migrated data from %1 to %2!"); + + // BEGIN CHECKSTYLE-SUPPRESSION: Javadoc + + private final List def; + + Message(String def, String... extra) { + this.def = new ArrayList(); + this.def.add(def); + this.def.addAll(Arrays.asList(extra)); + } + + /** + * @return This {@link Message}'s default-message + */ + public List getDefault() { + return def; + } + +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/MessageProvider.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/MessageProvider.java similarity index 97% rename from src/main/java/com/onarandombox/multiverseinventories/locale/MessageProvider.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/MessageProvider.java index 815a8311..610d84ff 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/MessageProvider.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/MessageProvider.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; import java.util.List; import java.util.Locale; diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/Messager.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/Messager.java similarity index 97% rename from src/main/java/com/onarandombox/multiverseinventories/locale/Messager.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/Messager.java index 86ed0110..2f4efdc4 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/Messager.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/Messager.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/Messaging.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/Messaging.java similarity index 87% rename from src/main/java/com/onarandombox/multiverseinventories/locale/Messaging.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/Messaging.java index 971b4978..01cfb473 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/Messaging.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/Messaging.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; /** * This interface is implemented by classes that use a {@link Messager}. diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/NoSuchLocalizationException.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/NoSuchLocalizationException.java similarity index 91% rename from src/main/java/com/onarandombox/multiverseinventories/locale/NoSuchLocalizationException.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/NoSuchLocalizationException.java index 31dd92ae..f586b5ad 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/NoSuchLocalizationException.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/NoSuchLocalizationException.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; import java.util.Locale; diff --git a/src/main/java/com/onarandombox/multiverseinventories/locale/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/locale/package-info.java similarity index 59% rename from src/main/java/com/onarandombox/multiverseinventories/locale/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/locale/package-info.java index 6279ccea..e13d4271 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/locale/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/locale/package-info.java @@ -1,5 +1,5 @@ /** * This package contains Multiverse-Inventories localization features. */ -package com.onarandombox.multiverseinventories.locale; +package org.mvplugins.multiverse.inventories.locale; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/DataImporter.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/DataImporter.java similarity index 87% rename from src/main/java/com/onarandombox/multiverseinventories/migration/DataImporter.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/DataImporter.java index e97a5fbd..52af376f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/DataImporter.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/DataImporter.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.migration; +package org.mvplugins.multiverse.inventories.migration; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/ImportManager.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/ImportManager.java similarity index 83% rename from src/main/java/com/onarandombox/multiverseinventories/migration/ImportManager.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/ImportManager.java index b1eefaeb..1511eb8c 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/ImportManager.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/ImportManager.java @@ -1,71 +1,71 @@ -package com.onarandombox.multiverseinventories.migration; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.migration.multiinv.MultiInvImporter; -import com.onarandombox.multiverseinventories.migration.worldinventories.WorldInventoriesImporter; -import me.drayshak.WorldInventories.WorldInventories; -import uk.co.tggl.pluckerpluck.multiinv.MultiInv; - -/** - * Manages the import heplers for other similar plugins. - */ -public class ImportManager { - - private MultiInvImporter multiInvImporter = null; - private WorldInventoriesImporter worldInventoriesImporter = null; - private MultiverseInventories inventories; - - public ImportManager(MultiverseInventories inventories) { - this.inventories = inventories; - } - - /** - * Hooks MultiInv for importing it's data. - * - * @param plugin Instance of MultiInv. - */ - public void hookMultiInv(MultiInv plugin) { - this.multiInvImporter = new MultiInvImporter(this.inventories, plugin); - Logging.info("Hooked MultiInv for importing!"); - } - - /** - * Hooks WorldInventories for importing it's data. - * - * @param plugin Instance of WorldInventories. - */ - public void hookWorldInventories(WorldInventories plugin) { - this.worldInventoriesImporter = new WorldInventoriesImporter(this.inventories, plugin); - Logging.info("Hooked WorldInventories for importing!"); - } - - /** - * @return The MultiInv importer class or null if not hooked. - */ - public MultiInvImporter getMultiInvImporter() { - return this.multiInvImporter; - } - - /** - * @return The WorldInventories importer class or null if not hooked. - */ - public WorldInventoriesImporter getWorldInventoriesImporter() { - return this.worldInventoriesImporter; - } - - /** - * Un-hooks MultiInv so we're not able to import from it anymore. - */ - public void unHookMultiInv() { - this.multiInvImporter = null; - } - - /** - * Un-hooks WorldInventories so we're not able to import from it anymore. - */ - public void unHookWorldInventories() { - this.worldInventoriesImporter = null; - } -} - +package org.mvplugins.multiverse.inventories.migration; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.migration.multiinv.MultiInvImporter; +import org.mvplugins.multiverse.inventories.migration.worldinventories.WorldInventoriesImporter; +import me.drayshak.WorldInventories.WorldInventories; +import uk.co.tggl.pluckerpluck.multiinv.MultiInv; + +/** + * Manages the import heplers for other similar plugins. + */ +public class ImportManager { + + private MultiInvImporter multiInvImporter = null; + private WorldInventoriesImporter worldInventoriesImporter = null; + private MultiverseInventories inventories; + + public ImportManager(MultiverseInventories inventories) { + this.inventories = inventories; + } + + /** + * Hooks MultiInv for importing it's data. + * + * @param plugin Instance of MultiInv. + */ + public void hookMultiInv(MultiInv plugin) { + this.multiInvImporter = new MultiInvImporter(this.inventories, plugin); + Logging.info("Hooked MultiInv for importing!"); + } + + /** + * Hooks WorldInventories for importing it's data. + * + * @param plugin Instance of WorldInventories. + */ + public void hookWorldInventories(WorldInventories plugin) { + this.worldInventoriesImporter = new WorldInventoriesImporter(this.inventories, plugin); + Logging.info("Hooked WorldInventories for importing!"); + } + + /** + * @return The MultiInv importer class or null if not hooked. + */ + public MultiInvImporter getMultiInvImporter() { + return this.multiInvImporter; + } + + /** + * @return The WorldInventories importer class or null if not hooked. + */ + public WorldInventoriesImporter getWorldInventoriesImporter() { + return this.worldInventoriesImporter; + } + + /** + * Un-hooks MultiInv so we're not able to import from it anymore. + */ + public void unHookMultiInv() { + this.multiInvImporter = null; + } + + /** + * Un-hooks WorldInventories so we're not able to import from it anymore. + */ + public void unHookWorldInventories() { + this.worldInventoriesImporter = null; + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/MigrationException.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/MigrationException.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/migration/MigrationException.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/MigrationException.java index c169b378..f7319478 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/MigrationException.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/MigrationException.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.migration; +package org.mvplugins.multiverse.inventories.migration; /** * Exception thrown when migration doesn't go well. diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryConverter.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryConverter.java similarity index 85% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryConverter.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryConverter.java index 33f1d5e2..d4180de6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryConverter.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryConverter.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.migration.multiinv; +package org.mvplugins.multiverse.inventories.migration.multiinv; -import com.onarandombox.multiverseinventories.util.MinecraftTools; +import org.mvplugins.multiverse.inventories.util.MinecraftTools; import org.bukkit.inventory.ItemStack; import uk.co.tggl.pluckerpluck.multiinv.inventory.MIItemStack; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryInterface.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryInterface.java similarity index 84% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryInterface.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryInterface.java index 04f46b18..9259bd90 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryInterface.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryInterface.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.migration.multiinv; +package org.mvplugins.multiverse.inventories.migration.multiinv; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryOldWrapper.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryOldWrapper.java similarity index 91% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryOldWrapper.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryOldWrapper.java index d624a566..89b3b614 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryOldWrapper.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryOldWrapper.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.migration.multiinv; +package org.mvplugins.multiverse.inventories.migration.multiinv; import org.bukkit.inventory.ItemStack; import uk.co.tggl.pluckerpluck.multiinv.inventory.MIInventoryOld; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryWrapper.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryWrapper.java similarity index 90% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryWrapper.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryWrapper.java index 5572b3b3..7dadff75 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIInventoryWrapper.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIInventoryWrapper.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.migration.multiinv; +package org.mvplugins.multiverse.inventories.migration.multiinv; import org.bukkit.inventory.ItemStack; import uk.co.tggl.pluckerpluck.multiinv.inventory.MIInventory; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIPlayerFileLoader.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIPlayerFileLoader.java similarity index 93% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIPlayerFileLoader.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIPlayerFileLoader.java index ba0e6e02..b597d12f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MIPlayerFileLoader.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MIPlayerFileLoader.java @@ -1,114 +1,114 @@ -package com.onarandombox.multiverseinventories.migration.multiinv; - -import com.onarandombox.multiverseinventories.PlayerStats; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.YamlConfiguration; -import uk.co.tggl.pluckerpluck.multiinv.MultiInv; - -import java.io.File; - -/** - * A replacement for MultiInv's MIPlayerFile class so that it may accept an OfflinePlayer instead of Player. - */ -public class MIPlayerFileLoader { - - private YamlConfiguration playerFile; - private File file; - - public MIPlayerFileLoader(MultiInv plugin, OfflinePlayer player, String group) { - // Find and load configuration file for the player - File worldsFolder = new File(plugin.getDataFolder(), "Groups"); - file = new File(worldsFolder, group + File.separator + player.getName() + ".yml"); - - playerFile = new YamlConfiguration(); - } - - /** - * Loads the player file into memory. - * - * @return True if there was a file to load and it loaded successfully. - */ - public boolean load() { - if (file.exists()) { - try { - playerFile.load(file); - return true; - } catch (Exception ignore) { } - } - return false; - } - - /** - * Load particular inventory for specified player from specified group. - * - * @param inventoryName The gamemode for the inventory to load. - * @return An interface for retrieve the inventory/armor contents. - */ - public MIInventoryInterface getInventory(String inventoryName) { - // Get stored string from configuration file - MIInventoryInterface inventory; - String inventoryString = playerFile.getString(inventoryName, null); - // Check for old inventory save - if (inventoryString == null || inventoryString.contains(";-;")) { - inventory = new MIInventoryOldWrapper(inventoryString); - } else { - inventory = new MIInventoryWrapper(inventoryString); - } - return inventory; - } - - /** - * @return The player's health. - */ - public double getHealth() { - double health = playerFile.getDouble("health", PlayerStats.HEALTH); - if (health <= 0 || health > PlayerStats.HEALTH) { - health = PlayerStats.HEALTH; - } - return health; - } - - /** - * @return The player's hunger. - */ - public int getHunger() { - int hunger = playerFile.getInt("hunger", PlayerStats.FOOD_LEVEL); - if (hunger <= 0 || hunger > PlayerStats.FOOD_LEVEL) { - hunger = PlayerStats.FOOD_LEVEL; - } - return hunger; - } - - /** - * @return The player's saturation. - */ - public float getSaturation() { - double saturationDouble = playerFile.getDouble("saturation", 0); - float saturation = (float) saturationDouble; - return saturation; - } - - /** - * @return The player's total exp. - */ - public int getTotalExperience() { - return playerFile.getInt("experience", 0); - } - - /** - * @return The player's level. - */ - public int getLevel() { - return playerFile.getInt("level", 0); - } - - /** - * @return The player's exp. - */ - public float getExperience() { - double expDouble = playerFile.getDouble("exp", 0); - float exp = (float) expDouble; - return exp; - } -} - +package org.mvplugins.multiverse.inventories.migration.multiinv; + +import org.mvplugins.multiverse.inventories.PlayerStats; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.YamlConfiguration; +import uk.co.tggl.pluckerpluck.multiinv.MultiInv; + +import java.io.File; + +/** + * A replacement for MultiInv's MIPlayerFile class so that it may accept an OfflinePlayer instead of Player. + */ +public class MIPlayerFileLoader { + + private YamlConfiguration playerFile; + private File file; + + public MIPlayerFileLoader(MultiInv plugin, OfflinePlayer player, String group) { + // Find and load configuration file for the player + File worldsFolder = new File(plugin.getDataFolder(), "Groups"); + file = new File(worldsFolder, group + File.separator + player.getName() + ".yml"); + + playerFile = new YamlConfiguration(); + } + + /** + * Loads the player file into memory. + * + * @return True if there was a file to load and it loaded successfully. + */ + public boolean load() { + if (file.exists()) { + try { + playerFile.load(file); + return true; + } catch (Exception ignore) { } + } + return false; + } + + /** + * Load particular inventory for specified player from specified group. + * + * @param inventoryName The gamemode for the inventory to load. + * @return An interface for retrieve the inventory/armor contents. + */ + public MIInventoryInterface getInventory(String inventoryName) { + // Get stored string from configuration file + MIInventoryInterface inventory; + String inventoryString = playerFile.getString(inventoryName, null); + // Check for old inventory save + if (inventoryString == null || inventoryString.contains(";-;")) { + inventory = new MIInventoryOldWrapper(inventoryString); + } else { + inventory = new MIInventoryWrapper(inventoryString); + } + return inventory; + } + + /** + * @return The player's health. + */ + public double getHealth() { + double health = playerFile.getDouble("health", PlayerStats.HEALTH); + if (health <= 0 || health > PlayerStats.HEALTH) { + health = PlayerStats.HEALTH; + } + return health; + } + + /** + * @return The player's hunger. + */ + public int getHunger() { + int hunger = playerFile.getInt("hunger", PlayerStats.FOOD_LEVEL); + if (hunger <= 0 || hunger > PlayerStats.FOOD_LEVEL) { + hunger = PlayerStats.FOOD_LEVEL; + } + return hunger; + } + + /** + * @return The player's saturation. + */ + public float getSaturation() { + double saturationDouble = playerFile.getDouble("saturation", 0); + float saturation = (float) saturationDouble; + return saturation; + } + + /** + * @return The player's total exp. + */ + public int getTotalExperience() { + return playerFile.getInt("experience", 0); + } + + /** + * @return The player's level. + */ + public int getLevel() { + return playerFile.getInt("level", 0); + } + + /** + * @return The player's exp. + */ + public float getExperience() { + double expDouble = playerFile.getDouble("exp", 0); + float exp = (float) expDouble; + return exp; + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MultiInvImporter.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MultiInvImporter.java similarity index 89% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MultiInvImporter.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MultiInvImporter.java index c0f3ae8c..da976987 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/MultiInvImporter.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/MultiInvImporter.java @@ -1,167 +1,167 @@ -package com.onarandombox.multiverseinventories.migration.multiinv; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.profile.ProfileTypes; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.migration.DataImporter; -import com.onarandombox.multiverseinventories.migration.MigrationException; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.plugin.Plugin; -import uk.co.tggl.pluckerpluck.multiinv.MIYamlFiles; -import uk.co.tggl.pluckerpluck.multiinv.MultiInv; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -/** - * A class to help with importing data from MultiInv. - */ -public class MultiInvImporter implements DataImporter { - - private MultiInv miPlugin; - private MultiverseInventories inventories; - - public MultiInvImporter(MultiverseInventories inventories, MultiInv miPlugin) { - this.inventories = inventories; - this.miPlugin = miPlugin; - } - - /** - * @return The MultiInv plugin hooked to the importer. - */ - public MultiInv getMIPlugin() { - return this.miPlugin; - } - - /** - * {@inheritDoc} - */ - @Override - public Plugin getPlugin() { - return this.getMIPlugin(); - } - - /** - * Imports the data from MultiInv. - * - * @throws MigrationException If there was any MAJOR issue loading the data. - */ - @Override - public void importData() throws MigrationException { - HashMap miGroupMap = this.getGroupMap(); - if (miGroupMap == null) { - throw new MigrationException("There is no data to import from MultiInv!"); - } - if (!miGroupMap.isEmpty()) { - WorldGroup defaultWorldGroup = this.inventories.getGroupManager().getDefaultGroup(); - if (defaultWorldGroup != null) { - this.inventories.getGroupManager().removeGroup(defaultWorldGroup); - Logging.info("Removed automatically created world group in favor of imported groups."); - } - } - for (Map.Entry groupEntry : miGroupMap.entrySet()) { - WorldGroup worldGroup = this.inventories.getGroupManager().getGroup(groupEntry.getValue()); - if (worldGroup == null) { - worldGroup = this.inventories.getGroupManager().newEmptyGroup(groupEntry.getValue()); - worldGroup.getShares().mergeShares(Sharables.allOf()); - Logging.info("Importing group: " + groupEntry.getValue()); - this.inventories.getGroupManager().updateGroup(worldGroup); - } - worldGroup.addWorld(groupEntry.getValue()); - } - this.inventories.getMVIConfig().save(); - - for (OfflinePlayer player : Bukkit.getServer().getOfflinePlayers()) { - Logging.info("Processing MultiInv data for player: " + player.getName()); - for (Map.Entry entry : miGroupMap.entrySet()) { - String worldName = entry.getKey(); - String groupName = entry.getValue(); - MIPlayerFileLoader playerFileLoader = - new MIPlayerFileLoader(this.getMIPlugin(), player, groupName); - if (!playerFileLoader.load()) { - continue; - } - Logging.info("Processing MultiInv data for player: " + player.getName() - + " for group: " + groupName); - mergeData(player, playerFileLoader, groupName, ContainerType.GROUP); - } - for (World world : Bukkit.getWorlds()) { - String worldName = world.getName(); - MIPlayerFileLoader playerFileLoader = - new MIPlayerFileLoader(this.getMIPlugin(), player, worldName); - if (!playerFileLoader.load()) { - continue; - } - Logging.info("Processing MultiInv data for player: " + player.getName() - + " for world only: " + worldName); - mergeData(player, playerFileLoader, worldName, ContainerType.WORLD); - } - } - - Logging.info("Import from MultiInv finished. Disabling MultiInv."); - Bukkit.getPluginManager().disablePlugin(this.getMIPlugin()); - } - - private void mergeData(OfflinePlayer player, MIPlayerFileLoader playerFileLoader, - String dataName, ContainerType type) { - PlayerProfile playerProfile; - if (type.equals(ContainerType.GROUP)) { - WorldGroup group = this.inventories.getGroupManager() - .getGroup(dataName); - if (group == null) { - Logging.warning("Could not import player data for group: " + dataName); - return; - } - playerProfile = group.getGroupProfileContainer().getPlayerData(ProfileTypes.SURVIVAL, player); - } else { - playerProfile = this.inventories.getWorldProfileContainerStore() - .getContainer(dataName).getPlayerData(ProfileTypes.SURVIVAL, player); - } - MIInventoryInterface inventoryInterface = - playerFileLoader.getInventory(GameMode.SURVIVAL.toString()); - playerProfile.set(Sharables.INVENTORY, inventoryInterface.getInventoryContents()); - playerProfile.set(Sharables.ARMOR, inventoryInterface.getArmorContents()); - playerProfile.set(Sharables.HEALTH, playerFileLoader.getHealth()); - playerProfile.set(Sharables.SATURATION, playerFileLoader.getSaturation()); - playerProfile.set(Sharables.EXPERIENCE, playerFileLoader.getExperience()); - playerProfile.set(Sharables.TOTAL_EXPERIENCE, playerFileLoader.getTotalExperience()); - playerProfile.set(Sharables.LEVEL, playerFileLoader.getLevel()); - playerProfile.set(Sharables.FOOD_LEVEL, playerFileLoader.getHunger()); - this.inventories.getData().updatePlayerData(playerProfile); - } - - /** - * @return The group mapping from MultiInv, where worldName -> groupName. - * @throws MigrationException If there was any issues getting the data through reflection. - */ - private HashMap getGroupMap() throws MigrationException { - Field field; - try { - field = MIYamlFiles.class.getDeclaredField("groups"); - } catch (NoSuchFieldException nsfe) { - throw new MigrationException("The running version of MultiInv is " - + "incompatible with the import feature.").setCauseException(nsfe); - } - field.setAccessible(true); - HashMap miGroupMap = null; - try { - miGroupMap = (HashMap) field.get(null); - } catch (IllegalAccessException iae) { - throw new MigrationException("The running version of MultiInv is " - + "incompatible with the import feature.").setCauseException(iae); - } catch (ClassCastException cce) { - throw new MigrationException("The running version of MultiInv is " - + "incompatible with the import feature.").setCauseException(cce); - } - return miGroupMap; - } -} - +package org.mvplugins.multiverse.inventories.migration.multiinv; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.profile.ProfileTypes; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.migration.DataImporter; +import org.mvplugins.multiverse.inventories.migration.MigrationException; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.plugin.Plugin; +import uk.co.tggl.pluckerpluck.multiinv.MIYamlFiles; +import uk.co.tggl.pluckerpluck.multiinv.MultiInv; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +/** + * A class to help with importing data from MultiInv. + */ +public class MultiInvImporter implements DataImporter { + + private MultiInv miPlugin; + private MultiverseInventories inventories; + + public MultiInvImporter(MultiverseInventories inventories, MultiInv miPlugin) { + this.inventories = inventories; + this.miPlugin = miPlugin; + } + + /** + * @return The MultiInv plugin hooked to the importer. + */ + public MultiInv getMIPlugin() { + return this.miPlugin; + } + + /** + * {@inheritDoc} + */ + @Override + public Plugin getPlugin() { + return this.getMIPlugin(); + } + + /** + * Imports the data from MultiInv. + * + * @throws MigrationException If there was any MAJOR issue loading the data. + */ + @Override + public void importData() throws MigrationException { + HashMap miGroupMap = this.getGroupMap(); + if (miGroupMap == null) { + throw new MigrationException("There is no data to import from MultiInv!"); + } + if (!miGroupMap.isEmpty()) { + WorldGroup defaultWorldGroup = this.inventories.getGroupManager().getDefaultGroup(); + if (defaultWorldGroup != null) { + this.inventories.getGroupManager().removeGroup(defaultWorldGroup); + Logging.info("Removed automatically created world group in favor of imported groups."); + } + } + for (Map.Entry groupEntry : miGroupMap.entrySet()) { + WorldGroup worldGroup = this.inventories.getGroupManager().getGroup(groupEntry.getValue()); + if (worldGroup == null) { + worldGroup = this.inventories.getGroupManager().newEmptyGroup(groupEntry.getValue()); + worldGroup.getShares().mergeShares(Sharables.allOf()); + Logging.info("Importing group: " + groupEntry.getValue()); + this.inventories.getGroupManager().updateGroup(worldGroup); + } + worldGroup.addWorld(groupEntry.getValue()); + } + this.inventories.getMVIConfig().save(); + + for (OfflinePlayer player : Bukkit.getServer().getOfflinePlayers()) { + Logging.info("Processing MultiInv data for player: " + player.getName()); + for (Map.Entry entry : miGroupMap.entrySet()) { + String worldName = entry.getKey(); + String groupName = entry.getValue(); + MIPlayerFileLoader playerFileLoader = + new MIPlayerFileLoader(this.getMIPlugin(), player, groupName); + if (!playerFileLoader.load()) { + continue; + } + Logging.info("Processing MultiInv data for player: " + player.getName() + + " for group: " + groupName); + mergeData(player, playerFileLoader, groupName, ContainerType.GROUP); + } + for (World world : Bukkit.getWorlds()) { + String worldName = world.getName(); + MIPlayerFileLoader playerFileLoader = + new MIPlayerFileLoader(this.getMIPlugin(), player, worldName); + if (!playerFileLoader.load()) { + continue; + } + Logging.info("Processing MultiInv data for player: " + player.getName() + + " for world only: " + worldName); + mergeData(player, playerFileLoader, worldName, ContainerType.WORLD); + } + } + + Logging.info("Import from MultiInv finished. Disabling MultiInv."); + Bukkit.getPluginManager().disablePlugin(this.getMIPlugin()); + } + + private void mergeData(OfflinePlayer player, MIPlayerFileLoader playerFileLoader, + String dataName, ContainerType type) { + PlayerProfile playerProfile; + if (type.equals(ContainerType.GROUP)) { + WorldGroup group = this.inventories.getGroupManager() + .getGroup(dataName); + if (group == null) { + Logging.warning("Could not import player data for group: " + dataName); + return; + } + playerProfile = group.getGroupProfileContainer().getPlayerData(ProfileTypes.SURVIVAL, player); + } else { + playerProfile = this.inventories.getWorldProfileContainerStore() + .getContainer(dataName).getPlayerData(ProfileTypes.SURVIVAL, player); + } + MIInventoryInterface inventoryInterface = + playerFileLoader.getInventory(GameMode.SURVIVAL.toString()); + playerProfile.set(Sharables.INVENTORY, inventoryInterface.getInventoryContents()); + playerProfile.set(Sharables.ARMOR, inventoryInterface.getArmorContents()); + playerProfile.set(Sharables.HEALTH, playerFileLoader.getHealth()); + playerProfile.set(Sharables.SATURATION, playerFileLoader.getSaturation()); + playerProfile.set(Sharables.EXPERIENCE, playerFileLoader.getExperience()); + playerProfile.set(Sharables.TOTAL_EXPERIENCE, playerFileLoader.getTotalExperience()); + playerProfile.set(Sharables.LEVEL, playerFileLoader.getLevel()); + playerProfile.set(Sharables.FOOD_LEVEL, playerFileLoader.getHunger()); + this.inventories.getData().updatePlayerData(playerProfile); + } + + /** + * @return The group mapping from MultiInv, where worldName -> groupName. + * @throws MigrationException If there was any issues getting the data through reflection. + */ + private HashMap getGroupMap() throws MigrationException { + Field field; + try { + field = MIYamlFiles.class.getDeclaredField("groups"); + } catch (NoSuchFieldException nsfe) { + throw new MigrationException("The running version of MultiInv is " + + "incompatible with the import feature.").setCauseException(nsfe); + } + field.setAccessible(true); + HashMap miGroupMap = null; + try { + miGroupMap = (HashMap) field.get(null); + } catch (IllegalAccessException iae) { + throw new MigrationException("The running version of MultiInv is " + + "incompatible with the import feature.").setCauseException(iae); + } catch (ClassCastException cce) { + throw new MigrationException("The running version of MultiInv is " + + "incompatible with the import feature.").setCauseException(cce); + } + return miGroupMap; + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/package-info.java similarity index 55% rename from src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/package-info.java index 62a128b2..bfbc619f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/multiinv/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/multiinv/package-info.java @@ -1,5 +1,5 @@ /** * This package contains MultiInv classes to handle importing their data. */ -package com.onarandombox.multiverseinventories.migration.multiinv; +package org.mvplugins.multiverse.inventories.migration.multiinv; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/package-info.java similarity index 67% rename from src/main/java/com/onarandombox/multiverseinventories/migration/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/package-info.java index 139a8dbc..d66b1e65 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/package-info.java @@ -2,5 +2,5 @@ * This package contains thigns to help with importing player stats/inventory data from * other similar plugins. */ -package com.onarandombox.multiverseinventories.migration; +package org.mvplugins.multiverse.inventories.migration; diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/worldinventories/WorldInventoriesImporter.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/worldinventories/WorldInventoriesImporter.java similarity index 91% rename from src/main/java/com/onarandombox/multiverseinventories/migration/worldinventories/WorldInventoriesImporter.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/worldinventories/WorldInventoriesImporter.java index 7ff07ffd..7b5ff5ea 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/worldinventories/WorldInventoriesImporter.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/worldinventories/WorldInventoriesImporter.java @@ -1,274 +1,274 @@ -package com.onarandombox.multiverseinventories.migration.worldinventories; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.profile.ProfileTypes; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.profile.container.ProfileContainer; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.migration.DataImporter; -import com.onarandombox.multiverseinventories.migration.MigrationException; -import me.drayshak.WorldInventories.Group; -import me.drayshak.WorldInventories.WIPlayerInventory; -import me.drayshak.WorldInventories.WIPlayerStats; -import me.drayshak.WorldInventories.WorldInventories; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.plugin.Plugin; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -/** - * Handles the importing of data from WorldInventories. - */ -public class WorldInventoriesImporter implements DataImporter { - - private WorldInventories wiPlugin; - private MultiverseInventories inventories; - - public WorldInventoriesImporter(MultiverseInventories inventories, WorldInventories wiPlugin) { - this.inventories = inventories; - this.wiPlugin = wiPlugin; - } - - /** - * @return The WorldInventories plugin hooked to the importer. - */ - public WorldInventories getWIPlugin() { - return this.wiPlugin; - } - - /** - * {@inheritDoc} - */ - @Override - public Plugin getPlugin() { - return this.getWIPlugin(); - } - - /** - * Imports the data from WorldInventories into MultiverseInventories. - * - * @throws MigrationException If there was any MAJOR issues importing the data. - */ - @Override - public void importData() throws MigrationException { - List wiGroups; - try { - wiGroups = this.getWIPlugin().getGroups(); - } catch (Exception e) { - throw new MigrationException("Unable to import from this version of WorldInventories!") - .setCauseException(e); - } catch (Error e) { - throw new MigrationException("Unable to import from this version of WorldInventories!"); - } - if (wiGroups == null) { - throw new MigrationException("No data to import from WorldInventories!"); - } - - if (!wiGroups.isEmpty()) { - WorldGroup defaultWorldGroup = this.inventories.getGroupManager().getDefaultGroup(); - if (defaultWorldGroup != null) { - this.inventories.getGroupManager().removeGroup(defaultWorldGroup); - Logging.info("Removed automatically created world group in favor of imported groups."); - } - } - - this.createGroups(wiGroups); - Set noGroupWorlds = this.getWorldsWithoutGroups(); - this.inventories.getMVIConfig().save(); - - OfflinePlayer[] offlinePlayers = Bukkit.getServer().getOfflinePlayers(); - Logging.info("Processing data for " + offlinePlayers.length + " players. The larger than number, the longer" - + " this process will take. Please be patient. :) Your server will freeze for the duration."); - int playerCount = 0; - for (OfflinePlayer player : offlinePlayers) { - playerCount++; - Logging.finer("(" + playerCount + "/" + offlinePlayers.length - + ")Processing WorldInventories data for player: " + player.getName()); - for (Group wiGroup : wiGroups) { - WorldGroup worldGroup = inventories.getGroupManager().getGroup(wiGroup.getName()); - if (worldGroup == null) { - Logging.finest("Could not import player data for WorldInventories group: " + wiGroup.getName() - + " because there is no Multiverse-Inventories group by that name."); - continue; - } - this.transferData(player, wiGroup, worldGroup.getGroupProfileContainer()); - } - for (ProfileContainer container : noGroupWorlds) { - this.transferData(player, null, container); - } - } - - Logging.info("Import from WorldInventories finished. Disabling WorldInventories."); - Bukkit.getPluginManager().disablePlugin(this.getWIPlugin()); - } - - private void createGroups(List wiGroups) { - for (Group wiGroup : wiGroups) { - if (wiGroup.getWorlds().isEmpty()) { - Logging.warning("Group '" + wiGroup.getName() + "' has no worlds." - + " You may need to add these manually!"); - } - WorldGroup newGroup = inventories.getGroupManager().newEmptyGroup(wiGroup.getName()); - for (String worldName : wiGroup.getWorlds()) { - newGroup.addWorld(worldName); - } - - try { - if (WorldInventories.doStats) { - newGroup.getShares().mergeShares(Sharables.allOf()); - } else { - newGroup.getShares().setSharing(Sharables.ALL_INVENTORY, true); - } - } catch (Exception ignore) { - Logging.warning("Group '" + wiGroup.getName() + "' unable to import fully, sharing only inventory."); - newGroup.getShares().setSharing(Sharables.ALL_INVENTORY, true); - } catch (Error e) { - Logging.warning("Group '" + wiGroup.getName() + "' unable to import fully, sharing only inventory."); - newGroup.getShares().setSharing(Sharables.ALL_INVENTORY, true); - } - this.inventories.getGroupManager().updateGroup(newGroup); - Logging.info("Created Multiverse-Inventories group: " + wiGroup.getName()); - } - } - - private Set getWorldsWithoutGroups() { - Set noGroupWorlds = new LinkedHashSet<>(); - for (World world : Bukkit.getWorlds()) { - if (this.inventories.getGroupManager().getGroupsForWorld(world.getName()).isEmpty()) { - Logging.fine("Added ungrouped world for importing."); - ProfileContainer container = this.inventories.getWorldProfileContainerStore().getContainer(world.getName()); - noGroupWorlds.add(container); - } - } - return noGroupWorlds; - } - - private void transferData(OfflinePlayer player, Group wiGroup, ProfileContainer profileContainer) { - PlayerProfile playerProfile = profileContainer.getPlayerData(ProfileTypes.SURVIVAL, player); - WIPlayerInventory wiInventory = this.loadPlayerInventory(player, wiGroup); - WIPlayerStats wiStats = this.loadPlayerStats(player, wiGroup); - if (wiInventory != null) { - playerProfile.set(Sharables.INVENTORY, wiInventory.getItems()); - playerProfile.set(Sharables.ARMOR, wiInventory.getArmour()); - } - if (wiStats != null) { - playerProfile.set(Sharables.HEALTH, (double) wiStats.getHealth()); - playerProfile.set(Sharables.SATURATION, wiStats.getSaturation()); - playerProfile.set(Sharables.EXPERIENCE, wiStats.getExp()); - playerProfile.set(Sharables.LEVEL, wiStats.getLevel()); - playerProfile.set(Sharables.EXHAUSTION, wiStats.getExhaustion()); - playerProfile.set(Sharables.FOOD_LEVEL, wiStats.getFoodLevel()); - } - this.inventories.getData().updatePlayerData(playerProfile); - Logging.finest("Player's data imported successfully for group: " + profileContainer.getContainerName()); - } - - private File getFile(OfflinePlayer player, Group group, DataType dataType) { - StringBuilder path = new StringBuilder(); - path.append(File.separator); - - // Use default group - if (group == null) { - path.append("default"); - } else { - path.append(group.getName()); - } - path.insert(0, this.getWIPlugin().getDataFolder().getAbsolutePath()); - path.append(File.separator).append(player.getName()).append(dataType.fileExtension); - - File file = new File(path.toString()); - if (!file.exists()) { - file = null; - } - return file; - } - - // Copied and modified from WorldInventories - private WIPlayerInventory loadPlayerInventory(OfflinePlayer player, Group group) { - File file = this.getFile(player, group, DataType.INVENTORY); - if (file == null) { - return null; - } - WIPlayerInventory playerInventory = null; - FileInputStream fIS = null; - ObjectInputStream obIn = null; - try { - fIS = new FileInputStream(file); - obIn = new ObjectInputStream(fIS); - playerInventory = (WIPlayerInventory) obIn.readObject(); - } catch (Exception ignore) { - } finally { - if (obIn != null) { - try { - obIn.close(); - } catch (IOException ignore) { - } - } - if (fIS != null) { - try { - fIS.close(); - } catch (IOException ignore) { - } - } - } - - return playerInventory; - } - - // Copied and modified from WorldInventories - private WIPlayerStats loadPlayerStats(OfflinePlayer player, Group group) { - File file = this.getFile(player, group, DataType.STATS); - if (file == null) { - return null; - } - WIPlayerStats playerstats = null; - FileInputStream fIS = null; - ObjectInputStream obIn = null; - try { - fIS = new FileInputStream(file); - obIn = new ObjectInputStream(fIS); - playerstats = (WIPlayerStats) obIn.readObject(); - } catch (Exception ignore) { - } finally { - if (obIn != null) { - try { - obIn.close(); - } catch (IOException ignore) { - } - } - if (fIS != null) { - try { - fIS.close(); - } catch (IOException ignore) { - } - } - } - - return playerstats; - } - - /** - * Indicates the type of data we're importing for. - */ - private enum DataType { - INVENTORY(".inventory"), - STATS(".stats"); - - private String fileExtension; - - DataType(String fileExtension) { - this.fileExtension = fileExtension; - } - } -} - +package org.mvplugins.multiverse.inventories.migration.worldinventories; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.profile.ProfileTypes; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.container.ProfileContainer; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.migration.DataImporter; +import org.mvplugins.multiverse.inventories.migration.MigrationException; +import me.drayshak.WorldInventories.Group; +import me.drayshak.WorldInventories.WIPlayerInventory; +import me.drayshak.WorldInventories.WIPlayerStats; +import me.drayshak.WorldInventories.WorldInventories; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.plugin.Plugin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * Handles the importing of data from WorldInventories. + */ +public class WorldInventoriesImporter implements DataImporter { + + private WorldInventories wiPlugin; + private MultiverseInventories inventories; + + public WorldInventoriesImporter(MultiverseInventories inventories, WorldInventories wiPlugin) { + this.inventories = inventories; + this.wiPlugin = wiPlugin; + } + + /** + * @return The WorldInventories plugin hooked to the importer. + */ + public WorldInventories getWIPlugin() { + return this.wiPlugin; + } + + /** + * {@inheritDoc} + */ + @Override + public Plugin getPlugin() { + return this.getWIPlugin(); + } + + /** + * Imports the data from WorldInventories into MultiverseInventories. + * + * @throws MigrationException If there was any MAJOR issues importing the data. + */ + @Override + public void importData() throws MigrationException { + List wiGroups; + try { + wiGroups = this.getWIPlugin().getGroups(); + } catch (Exception e) { + throw new MigrationException("Unable to import from this version of WorldInventories!") + .setCauseException(e); + } catch (Error e) { + throw new MigrationException("Unable to import from this version of WorldInventories!"); + } + if (wiGroups == null) { + throw new MigrationException("No data to import from WorldInventories!"); + } + + if (!wiGroups.isEmpty()) { + WorldGroup defaultWorldGroup = this.inventories.getGroupManager().getDefaultGroup(); + if (defaultWorldGroup != null) { + this.inventories.getGroupManager().removeGroup(defaultWorldGroup); + Logging.info("Removed automatically created world group in favor of imported groups."); + } + } + + this.createGroups(wiGroups); + Set noGroupWorlds = this.getWorldsWithoutGroups(); + this.inventories.getMVIConfig().save(); + + OfflinePlayer[] offlinePlayers = Bukkit.getServer().getOfflinePlayers(); + Logging.info("Processing data for " + offlinePlayers.length + " players. The larger than number, the longer" + + " this process will take. Please be patient. :) Your server will freeze for the duration."); + int playerCount = 0; + for (OfflinePlayer player : offlinePlayers) { + playerCount++; + Logging.finer("(" + playerCount + "/" + offlinePlayers.length + + ")Processing WorldInventories data for player: " + player.getName()); + for (Group wiGroup : wiGroups) { + WorldGroup worldGroup = inventories.getGroupManager().getGroup(wiGroup.getName()); + if (worldGroup == null) { + Logging.finest("Could not import player data for WorldInventories group: " + wiGroup.getName() + + " because there is no Multiverse-Inventories group by that name."); + continue; + } + this.transferData(player, wiGroup, worldGroup.getGroupProfileContainer()); + } + for (ProfileContainer container : noGroupWorlds) { + this.transferData(player, null, container); + } + } + + Logging.info("Import from WorldInventories finished. Disabling WorldInventories."); + Bukkit.getPluginManager().disablePlugin(this.getWIPlugin()); + } + + private void createGroups(List wiGroups) { + for (Group wiGroup : wiGroups) { + if (wiGroup.getWorlds().isEmpty()) { + Logging.warning("Group '" + wiGroup.getName() + "' has no worlds." + + " You may need to add these manually!"); + } + WorldGroup newGroup = inventories.getGroupManager().newEmptyGroup(wiGroup.getName()); + for (String worldName : wiGroup.getWorlds()) { + newGroup.addWorld(worldName); + } + + try { + if (WorldInventories.doStats) { + newGroup.getShares().mergeShares(Sharables.allOf()); + } else { + newGroup.getShares().setSharing(Sharables.ALL_INVENTORY, true); + } + } catch (Exception ignore) { + Logging.warning("Group '" + wiGroup.getName() + "' unable to import fully, sharing only inventory."); + newGroup.getShares().setSharing(Sharables.ALL_INVENTORY, true); + } catch (Error e) { + Logging.warning("Group '" + wiGroup.getName() + "' unable to import fully, sharing only inventory."); + newGroup.getShares().setSharing(Sharables.ALL_INVENTORY, true); + } + this.inventories.getGroupManager().updateGroup(newGroup); + Logging.info("Created Multiverse-Inventories group: " + wiGroup.getName()); + } + } + + private Set getWorldsWithoutGroups() { + Set noGroupWorlds = new LinkedHashSet<>(); + for (World world : Bukkit.getWorlds()) { + if (this.inventories.getGroupManager().getGroupsForWorld(world.getName()).isEmpty()) { + Logging.fine("Added ungrouped world for importing."); + ProfileContainer container = this.inventories.getWorldProfileContainerStore().getContainer(world.getName()); + noGroupWorlds.add(container); + } + } + return noGroupWorlds; + } + + private void transferData(OfflinePlayer player, Group wiGroup, ProfileContainer profileContainer) { + PlayerProfile playerProfile = profileContainer.getPlayerData(ProfileTypes.SURVIVAL, player); + WIPlayerInventory wiInventory = this.loadPlayerInventory(player, wiGroup); + WIPlayerStats wiStats = this.loadPlayerStats(player, wiGroup); + if (wiInventory != null) { + playerProfile.set(Sharables.INVENTORY, wiInventory.getItems()); + playerProfile.set(Sharables.ARMOR, wiInventory.getArmour()); + } + if (wiStats != null) { + playerProfile.set(Sharables.HEALTH, (double) wiStats.getHealth()); + playerProfile.set(Sharables.SATURATION, wiStats.getSaturation()); + playerProfile.set(Sharables.EXPERIENCE, wiStats.getExp()); + playerProfile.set(Sharables.LEVEL, wiStats.getLevel()); + playerProfile.set(Sharables.EXHAUSTION, wiStats.getExhaustion()); + playerProfile.set(Sharables.FOOD_LEVEL, wiStats.getFoodLevel()); + } + this.inventories.getData().updatePlayerData(playerProfile); + Logging.finest("Player's data imported successfully for group: " + profileContainer.getContainerName()); + } + + private File getFile(OfflinePlayer player, Group group, DataType dataType) { + StringBuilder path = new StringBuilder(); + path.append(File.separator); + + // Use default group + if (group == null) { + path.append("default"); + } else { + path.append(group.getName()); + } + path.insert(0, this.getWIPlugin().getDataFolder().getAbsolutePath()); + path.append(File.separator).append(player.getName()).append(dataType.fileExtension); + + File file = new File(path.toString()); + if (!file.exists()) { + file = null; + } + return file; + } + + // Copied and modified from WorldInventories + private WIPlayerInventory loadPlayerInventory(OfflinePlayer player, Group group) { + File file = this.getFile(player, group, DataType.INVENTORY); + if (file == null) { + return null; + } + WIPlayerInventory playerInventory = null; + FileInputStream fIS = null; + ObjectInputStream obIn = null; + try { + fIS = new FileInputStream(file); + obIn = new ObjectInputStream(fIS); + playerInventory = (WIPlayerInventory) obIn.readObject(); + } catch (Exception ignore) { + } finally { + if (obIn != null) { + try { + obIn.close(); + } catch (IOException ignore) { + } + } + if (fIS != null) { + try { + fIS.close(); + } catch (IOException ignore) { + } + } + } + + return playerInventory; + } + + // Copied and modified from WorldInventories + private WIPlayerStats loadPlayerStats(OfflinePlayer player, Group group) { + File file = this.getFile(player, group, DataType.STATS); + if (file == null) { + return null; + } + WIPlayerStats playerstats = null; + FileInputStream fIS = null; + ObjectInputStream obIn = null; + try { + fIS = new FileInputStream(file); + obIn = new ObjectInputStream(fIS); + playerstats = (WIPlayerStats) obIn.readObject(); + } catch (Exception ignore) { + } finally { + if (obIn != null) { + try { + obIn.close(); + } catch (IOException ignore) { + } + } + if (fIS != null) { + try { + fIS.close(); + } catch (IOException ignore) { + } + } + } + + return playerstats; + } + + /** + * Indicates the type of data we're importing for. + */ + private enum DataType { + INVENTORY(".inventory"), + STATS(".stats"); + + private String fileExtension; + + DataType(String fileExtension) { + this.fileExtension = fileExtension; + } + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/migration/worldinventories/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/migration/worldinventories/package-info.java similarity index 54% rename from src/main/java/com/onarandombox/multiverseinventories/migration/worldinventories/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/migration/worldinventories/package-info.java index f82850c7..e7666201 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/migration/worldinventories/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/migration/worldinventories/package-info.java @@ -1,5 +1,5 @@ /** * This package contains WorldInventories classes to handle importing their data. */ -package com.onarandombox.multiverseinventories.migration.worldinventories; +package org.mvplugins.multiverse.inventories.migration.worldinventories; diff --git a/src/main/java/com/onarandombox/multiverseinventories/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/package-info.java similarity index 54% rename from src/main/java/com/onarandombox/multiverseinventories/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/package-info.java index e36f6040..e0176883 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/package-info.java @@ -1,5 +1,5 @@ /** * The main package for Multiverse-Inventories. */ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/GlobalProfile.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/GlobalProfile.java similarity index 98% rename from src/main/java/com/onarandombox/multiverseinventories/profile/GlobalProfile.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/GlobalProfile.java index 77c8c58b..c95f7ddf 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/GlobalProfile.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/GlobalProfile.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.profile; +package org.mvplugins.multiverse.inventories.profile; import org.bukkit.Bukkit; diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/GroupingConflict.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/GroupingConflict.java similarity index 87% rename from src/main/java/com/onarandombox/multiverseinventories/profile/GroupingConflict.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/GroupingConflict.java index cd30b4b5..cb0fc2fc 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/GroupingConflict.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/GroupingConflict.java @@ -1,72 +1,72 @@ -package com.onarandombox.multiverseinventories.profile; - -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.share.Shares; - -import java.util.ArrayList; -import java.util.List; - -/** - * A data class to hold information about any conflicts between world groups. - */ -public final class GroupingConflict { - - private WorldGroup groupOne; - private WorldGroup groupTwo; - private Shares conflictingShares; - - public GroupingConflict(WorldGroup groupOne, WorldGroup groupTwo, Shares conflictingShares) { - this.groupOne = groupOne; - this.groupTwo = groupTwo; - this.conflictingShares = conflictingShares; - } - - /** - * @return The first group in the conflict. - */ - public WorldGroup getFirstGroup() { - return this.groupOne; - } - - /** - * @return The second group in the conflict. - */ - public WorldGroup getSecondGroup() { - return this.groupTwo; - } - - /** - * @return The shares that are causing a conflict. - */ - public Shares getConflictingShares() { - return this.conflictingShares; - } - - /** - * @return The worlds the two groups share. - */ - public List getConflictingWorlds() { - List worlds = new ArrayList(); - for (String world : this.getFirstGroup().getWorlds()) { - if (this.getSecondGroup().getWorlds().contains(world)) { - worlds.add(world); - } - } - return worlds; - } - - /** - * @return The worlds the two groups share as a single string. - */ - public String getWorldsString() { - StringBuilder builder = new StringBuilder(); - for (String world : this.getConflictingWorlds()) { - if (!builder.toString().isEmpty()) { - builder.append(", "); - } - builder.append(world); - } - return builder.toString(); - } -} - +package org.mvplugins.multiverse.inventories.profile; + +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.share.Shares; + +import java.util.ArrayList; +import java.util.List; + +/** + * A data class to hold information about any conflicts between world groups. + */ +public final class GroupingConflict { + + private WorldGroup groupOne; + private WorldGroup groupTwo; + private Shares conflictingShares; + + public GroupingConflict(WorldGroup groupOne, WorldGroup groupTwo, Shares conflictingShares) { + this.groupOne = groupOne; + this.groupTwo = groupTwo; + this.conflictingShares = conflictingShares; + } + + /** + * @return The first group in the conflict. + */ + public WorldGroup getFirstGroup() { + return this.groupOne; + } + + /** + * @return The second group in the conflict. + */ + public WorldGroup getSecondGroup() { + return this.groupTwo; + } + + /** + * @return The shares that are causing a conflict. + */ + public Shares getConflictingShares() { + return this.conflictingShares; + } + + /** + * @return The worlds the two groups share. + */ + public List getConflictingWorlds() { + List worlds = new ArrayList(); + for (String world : this.getFirstGroup().getWorlds()) { + if (this.getSecondGroup().getWorlds().contains(world)) { + worlds.add(world); + } + } + return worlds; + } + + /** + * @return The worlds the two groups share as a single string. + */ + public String getWorldsString() { + StringBuilder builder = new StringBuilder(); + for (String world : this.getConflictingWorlds()) { + if (!builder.toString().isEmpty()) { + builder.append(", "); + } + builder.append(world); + } + return builder.toString(); + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/PlayerProfile.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerProfile.java similarity index 93% rename from src/main/java/com/onarandombox/multiverseinventories/profile/PlayerProfile.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerProfile.java index 2755e949..8ddc54d1 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/PlayerProfile.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerProfile.java @@ -1,8 +1,8 @@ -package com.onarandombox.multiverseinventories.profile; +package org.mvplugins.multiverse.inventories.profile; -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.SharableEntry; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.SharableEntry; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileDataSource.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileDataSource.java similarity index 94% rename from src/main/java/com/onarandombox/multiverseinventories/profile/ProfileDataSource.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileDataSource.java index 15427986..dbf8bcef 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileDataSource.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileDataSource.java @@ -1,104 +1,104 @@ -package com.onarandombox.multiverseinventories.profile; - -import com.onarandombox.multiverseinventories.profile.container.ContainerType; - -import java.io.IOException; -import java.util.UUID; - -/** - * A source for updating and retrieving player profiles via persistence. - */ -public interface ProfileDataSource { - - /** - * Updates the persisted data for a player for a specific profile. - * - * - * @param playerProfile The profile for the player that is being updated. - */ - void updatePlayerData(PlayerProfile playerProfile); - - /** - * Retrieves a PlayerProfile from the data source. - * - * @param containerType The type of container this profile is part of, world or group. - * @param dataName World/Group to retrieve from. - * @param profileType The type of profile to load data for, typically based on game mode. - * @param playerUUID UUID of the player to retrieve for. - * @return The player as returned from data. If no data was found, a new PlayerProfile will be - * created. - */ - PlayerProfile getPlayerData(ContainerType containerType, String dataName, ProfileType profileType, UUID playerUUID); - - /** - * Removes the persisted data for a player for a specific profile. - * - * @param containerType The type of container this profile is part of, world or group. - * @param dataName The name of the world/group the player's data is associated with. - * @param profileType The type of profile we're removing, as per {@link ProfileType}. If null, this will remove - * remove all profile types. - * @param playerName The name of the player whose data is being removed. - * @return True if successfully removed. - */ - boolean removePlayerData(ContainerType containerType, String dataName, ProfileType profileType, String playerName); - - /** - * Retrieves the global profile for a player which contains meta-data for the player. - * - * @param playerName The name of player to retrieve for. - * @return The global profile for the specified player. - * @deprecated UUID must be supported now. - */ - @Deprecated - GlobalProfile getGlobalProfile(String playerName); - - /** - * Retrieves the global profile for a player which contains meta-data for the player. - * - * @param playerName The name of the player to retrieve for. This is required for updating name last known as. - * @param playerUUID The UUID of the player. - * @return the global profile for the player with the given UUID. - */ - GlobalProfile getGlobalProfile(String playerName, UUID playerUUID); - - /** - * Update the file for a player's global profile. - * - * @param globalProfile The GlobalProfile object to update the file for. - * @return True if data successfully saved to file. - */ - boolean updateGlobalProfile(GlobalProfile globalProfile); - - /** - * A convenience method to update the GlobalProfile of a player with a specified world. - * - * @param playerName The player whose global profile this will update. - * @param worldName The world to update the global profile with. - */ - void updateLastWorld(String playerName, String worldName); - - /** - * A convenience method for setting whether player data should be loaded on login for the specified player. - * - * @param playerName The player whose data should be loaded. - * @param loadOnLogin Whether or not to load on login. - */ - void setLoadOnLogin(String playerName, boolean loadOnLogin); - - /** - * Copies all the data belonging to oldName to newName and removes the old data. - * - * @param oldName the previous name of the player. - * @param newName the new name of the player. - * @param playerUUID the UUID of the player. - * @param removeOldData whether or not to remove the data belonging to oldName. - * @throws IOException Thrown if something goes wrong while migrating the files. - */ - void migratePlayerData(String oldName, String newName, UUID playerUUID, boolean removeOldData) throws IOException; - - /** - * Clears a single profile in cache. - */ - void clearProfileCache(ProfileKey key); -} - +package org.mvplugins.multiverse.inventories.profile; + +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; + +import java.io.IOException; +import java.util.UUID; + +/** + * A source for updating and retrieving player profiles via persistence. + */ +public interface ProfileDataSource { + + /** + * Updates the persisted data for a player for a specific profile. + * + * + * @param playerProfile The profile for the player that is being updated. + */ + void updatePlayerData(PlayerProfile playerProfile); + + /** + * Retrieves a PlayerProfile from the data source. + * + * @param containerType The type of container this profile is part of, world or group. + * @param dataName World/Group to retrieve from. + * @param profileType The type of profile to load data for, typically based on game mode. + * @param playerUUID UUID of the player to retrieve for. + * @return The player as returned from data. If no data was found, a new PlayerProfile will be + * created. + */ + PlayerProfile getPlayerData(ContainerType containerType, String dataName, ProfileType profileType, UUID playerUUID); + + /** + * Removes the persisted data for a player for a specific profile. + * + * @param containerType The type of container this profile is part of, world or group. + * @param dataName The name of the world/group the player's data is associated with. + * @param profileType The type of profile we're removing, as per {@link ProfileType}. If null, this will remove + * remove all profile types. + * @param playerName The name of the player whose data is being removed. + * @return True if successfully removed. + */ + boolean removePlayerData(ContainerType containerType, String dataName, ProfileType profileType, String playerName); + + /** + * Retrieves the global profile for a player which contains meta-data for the player. + * + * @param playerName The name of player to retrieve for. + * @return The global profile for the specified player. + * @deprecated UUID must be supported now. + */ + @Deprecated + GlobalProfile getGlobalProfile(String playerName); + + /** + * Retrieves the global profile for a player which contains meta-data for the player. + * + * @param playerName The name of the player to retrieve for. This is required for updating name last known as. + * @param playerUUID The UUID of the player. + * @return the global profile for the player with the given UUID. + */ + GlobalProfile getGlobalProfile(String playerName, UUID playerUUID); + + /** + * Update the file for a player's global profile. + * + * @param globalProfile The GlobalProfile object to update the file for. + * @return True if data successfully saved to file. + */ + boolean updateGlobalProfile(GlobalProfile globalProfile); + + /** + * A convenience method to update the GlobalProfile of a player with a specified world. + * + * @param playerName The player whose global profile this will update. + * @param worldName The world to update the global profile with. + */ + void updateLastWorld(String playerName, String worldName); + + /** + * A convenience method for setting whether player data should be loaded on login for the specified player. + * + * @param playerName The player whose data should be loaded. + * @param loadOnLogin Whether or not to load on login. + */ + void setLoadOnLogin(String playerName, boolean loadOnLogin); + + /** + * Copies all the data belonging to oldName to newName and removes the old data. + * + * @param oldName the previous name of the player. + * @param newName the new name of the player. + * @param playerUUID the UUID of the player. + * @param removeOldData whether or not to remove the data belonging to oldName. + * @throws IOException Thrown if something goes wrong while migrating the files. + */ + void migratePlayerData(String oldName, String newName, UUID playerUUID, boolean removeOldData) throws IOException; + + /** + * Clears a single profile in cache. + */ + void clearProfileCache(ProfileKey key); +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileKey.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileKey.java similarity index 94% rename from src/main/java/com/onarandombox/multiverseinventories/profile/ProfileKey.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileKey.java index 0609391e..f0335e1c 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileKey.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileKey.java @@ -1,112 +1,112 @@ -package com.onarandombox.multiverseinventories.profile; - -import com.google.common.base.Objects; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import org.bukkit.Bukkit; - -import java.util.UUID; - -public final class ProfileKey { - - public static ProfileKey createProfileKey(ContainerType containerType, String dataName, - ProfileType profileType, UUID playerUUID, String playerName) { - return new ProfileKey(containerType, dataName, profileType, playerUUID, playerName); - } - - public static ProfileKey createProfileKey(ContainerType containerType, String dataName, - ProfileType profileType, UUID playerUUID) { - return new ProfileKey(containerType, dataName, profileType, playerUUID); - } - - public static ProfileKey createProfileKey(ProfileKey copyKey, ContainerType containerType) { - return new ProfileKey(containerType, copyKey.getDataName(), copyKey.getProfileType(), copyKey.getPlayerUUID(), - copyKey.getPlayerName()); - } - - public static ProfileKey createProfileKey(ProfileKey copyKey, ProfileType profileType) { - return new ProfileKey(copyKey.getContainerType(), copyKey.getDataName(), profileType, copyKey.getPlayerUUID(), - copyKey.getPlayerName()); - } - - public static ProfileKey createProfileKey(ProfileKey copyKey, ContainerType containerType, - ProfileType profileType) { - return new ProfileKey(containerType, copyKey.getDataName(), profileType, copyKey.getPlayerUUID(), - copyKey.getPlayerName()); - } - - public static ProfileKey createProfileKey(PlayerProfile profile) { - return new ProfileKey(profile.getContainerType(), profile.getContainerName(), profile.getProfileType(), - profile.getPlayer().getUniqueId(), profile.getPlayer().getName()); - } - - private final ContainerType containerType; - private final String dataName; - private final ProfileType profileType; - private final String playerName; - private final UUID playerUUID; - - private ProfileKey(ContainerType containerType, String dataName, ProfileType profileType, UUID playerUUID) { - this.containerType = containerType; - this.dataName = dataName; - this.profileType = profileType; - this.playerUUID = playerUUID; - this.playerName = Bukkit.getOfflinePlayer(playerUUID).getName(); - } - - private ProfileKey(ContainerType containerType, String dataName, ProfileType profileType, - UUID playerUUID, String playerName) { - this.containerType = containerType; - this.dataName = dataName; - this.profileType = profileType; - this.playerUUID = playerUUID; - this.playerName = playerName; - } - - public ContainerType getContainerType() { - return containerType; - } - - public String getDataName() { - return dataName; - } - - public ProfileType getProfileType() { - return profileType; - } - - public String getPlayerName() { - return playerName; - } - - public UUID getPlayerUUID() { - return playerUUID; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ProfileKey)) return false; - final ProfileKey that = (ProfileKey) o; - return getContainerType() == that.getContainerType() && - Objects.equal(getDataName(), that.getDataName()) && - Objects.equal(getProfileType(), that.getProfileType()) && - Objects.equal(getPlayerName(), that.getPlayerName()) && - Objects.equal(getPlayerUUID(), that.getPlayerUUID()); - } - - @Override - public int hashCode() { - return Objects.hashCode(getContainerType(), getDataName(), getProfileType(), getPlayerName(), getPlayerUUID()); - } - - @Override - public String toString() { - return "ProfileKey{" + - "containerType=" + containerType + - ", dataName='" + dataName + '\'' + - ", profileType=" + profileType + - ", playerName='" + playerName + '\'' + - ", playerUUID=" + playerUUID + - '}'; - } -} +package org.mvplugins.multiverse.inventories.profile; + +import com.google.common.base.Objects; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.bukkit.Bukkit; + +import java.util.UUID; + +public final class ProfileKey { + + public static ProfileKey createProfileKey(ContainerType containerType, String dataName, + ProfileType profileType, UUID playerUUID, String playerName) { + return new ProfileKey(containerType, dataName, profileType, playerUUID, playerName); + } + + public static ProfileKey createProfileKey(ContainerType containerType, String dataName, + ProfileType profileType, UUID playerUUID) { + return new ProfileKey(containerType, dataName, profileType, playerUUID); + } + + public static ProfileKey createProfileKey(ProfileKey copyKey, ContainerType containerType) { + return new ProfileKey(containerType, copyKey.getDataName(), copyKey.getProfileType(), copyKey.getPlayerUUID(), + copyKey.getPlayerName()); + } + + public static ProfileKey createProfileKey(ProfileKey copyKey, ProfileType profileType) { + return new ProfileKey(copyKey.getContainerType(), copyKey.getDataName(), profileType, copyKey.getPlayerUUID(), + copyKey.getPlayerName()); + } + + public static ProfileKey createProfileKey(ProfileKey copyKey, ContainerType containerType, + ProfileType profileType) { + return new ProfileKey(containerType, copyKey.getDataName(), profileType, copyKey.getPlayerUUID(), + copyKey.getPlayerName()); + } + + public static ProfileKey createProfileKey(PlayerProfile profile) { + return new ProfileKey(profile.getContainerType(), profile.getContainerName(), profile.getProfileType(), + profile.getPlayer().getUniqueId(), profile.getPlayer().getName()); + } + + private final ContainerType containerType; + private final String dataName; + private final ProfileType profileType; + private final String playerName; + private final UUID playerUUID; + + private ProfileKey(ContainerType containerType, String dataName, ProfileType profileType, UUID playerUUID) { + this.containerType = containerType; + this.dataName = dataName; + this.profileType = profileType; + this.playerUUID = playerUUID; + this.playerName = Bukkit.getOfflinePlayer(playerUUID).getName(); + } + + private ProfileKey(ContainerType containerType, String dataName, ProfileType profileType, + UUID playerUUID, String playerName) { + this.containerType = containerType; + this.dataName = dataName; + this.profileType = profileType; + this.playerUUID = playerUUID; + this.playerName = playerName; + } + + public ContainerType getContainerType() { + return containerType; + } + + public String getDataName() { + return dataName; + } + + public ProfileType getProfileType() { + return profileType; + } + + public String getPlayerName() { + return playerName; + } + + public UUID getPlayerUUID() { + return playerUUID; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ProfileKey)) return false; + final ProfileKey that = (ProfileKey) o; + return getContainerType() == that.getContainerType() && + Objects.equal(getDataName(), that.getDataName()) && + Objects.equal(getProfileType(), that.getProfileType()) && + Objects.equal(getPlayerName(), that.getPlayerName()) && + Objects.equal(getPlayerUUID(), that.getPlayerUUID()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getContainerType(), getDataName(), getProfileType(), getPlayerName(), getPlayerUUID()); + } + + @Override + public String toString() { + return "ProfileKey{" + + "containerType=" + containerType + + ", dataName='" + dataName + '\'' + + ", profileType=" + profileType + + ", playerName='" + playerName + '\'' + + ", playerUUID=" + playerUUID + + '}'; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileType.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileType.java similarity index 90% rename from src/main/java/com/onarandombox/multiverseinventories/profile/ProfileType.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileType.java index 6af78391..b4198653 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileType.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileType.java @@ -1,39 +1,39 @@ -package com.onarandombox.multiverseinventories.profile; - -/** - * Used to differentiate between profiles in the same world or world group, primarily for game modes. - */ -public final class ProfileType { - - static ProfileType createProfileType(String name) { - return new ProfileType(name); - } - - private String name; - - private ProfileType(String name) { - this.name = name; - } - - /** - * @return The name of the profile. The default profile type will return a blank string. - */ - public String getName() { - return name; - } - - @Override - public final boolean equals(Object o) { - return o instanceof ProfileType && ((ProfileType) o).getName().equals(this.getName()); - } - - @Override - public final int hashCode() { - return getName().hashCode(); - } - - @Override - public String toString() { - return "ProfileType:" + getName(); - } -} +package org.mvplugins.multiverse.inventories.profile; + +/** + * Used to differentiate between profiles in the same world or world group, primarily for game modes. + */ +public final class ProfileType { + + static ProfileType createProfileType(String name) { + return new ProfileType(name); + } + + private String name; + + private ProfileType(String name) { + this.name = name; + } + + /** + * @return The name of the profile. The default profile type will return a blank string. + */ + public String getName() { + return name; + } + + @Override + public final boolean equals(Object o) { + return o instanceof ProfileType && ((ProfileType) o).getName().equals(this.getName()); + } + + @Override + public final int hashCode() { + return getName().hashCode(); + } + + @Override + public String toString() { + return "ProfileType:" + getName(); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileTypes.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileTypes.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/profile/ProfileTypes.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileTypes.java index 4de6121b..cdf9c061 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/ProfileTypes.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileTypes.java @@ -1,47 +1,47 @@ -package com.onarandombox.multiverseinventories.profile; - -import org.bukkit.GameMode; - -/** - * Static class for profile type lookup and protected registration. - */ -public final class ProfileTypes { - - /** - * The profile type for the SURVIVAL Game Mode. - */ - public static final ProfileType SURVIVAL = ProfileType.createProfileType("SURVIVAL"); - - /** - * The profile type for the CREATIVE Game Mode. - */ - public static final ProfileType CREATIVE = ProfileType.createProfileType("CREATIVE"); - - /** - * The profile type for the ADVENTURE Game Mode. - */ - public static final ProfileType ADVENTURE = ProfileType.createProfileType("ADVENTURE"); - - /** - * Returns the appropriate ProfileType for the given game mode. - * - * @param mode The game mode to get the profile type for. - * @return The profile type for the given game mode. - */ - public static ProfileType forGameMode(GameMode mode) { - switch (mode) { - case SURVIVAL: - return SURVIVAL; - case CREATIVE: - return CREATIVE; - case ADVENTURE: - return ADVENTURE; - default: - return SURVIVAL; - } - } - - private ProfileTypes() { - throw new AssertionError(); - } -} +package org.mvplugins.multiverse.inventories.profile; + +import org.bukkit.GameMode; + +/** + * Static class for profile type lookup and protected registration. + */ +public final class ProfileTypes { + + /** + * The profile type for the SURVIVAL Game Mode. + */ + public static final ProfileType SURVIVAL = ProfileType.createProfileType("SURVIVAL"); + + /** + * The profile type for the CREATIVE Game Mode. + */ + public static final ProfileType CREATIVE = ProfileType.createProfileType("CREATIVE"); + + /** + * The profile type for the ADVENTURE Game Mode. + */ + public static final ProfileType ADVENTURE = ProfileType.createProfileType("ADVENTURE"); + + /** + * Returns the appropriate ProfileType for the given game mode. + * + * @param mode The game mode to get the profile type for. + * @return The profile type for the given game mode. + */ + public static ProfileType forGameMode(GameMode mode) { + switch (mode) { + case SURVIVAL: + return SURVIVAL; + case CREATIVE: + return CREATIVE; + case ADVENTURE: + return ADVENTURE; + default: + return SURVIVAL; + } + } + + private ProfileTypes() { + throw new AssertionError(); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/WorldGroupManager.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/WorldGroupManager.java similarity index 97% rename from src/main/java/com/onarandombox/multiverseinventories/profile/WorldGroupManager.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/WorldGroupManager.java index 251a2b1d..a79ca089 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/WorldGroupManager.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/WorldGroupManager.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.profile; +package org.mvplugins.multiverse.inventories.profile; -import com.onarandombox.multiverseinventories.WorldGroup; +import org.mvplugins.multiverse.inventories.WorldGroup; import org.bukkit.command.CommandSender; import java.util.List; diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/container/ContainerType.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/container/ContainerType.java similarity index 76% rename from src/main/java/com/onarandombox/multiverseinventories/profile/container/ContainerType.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/container/ContainerType.java index 4cb56a28..8659e22a 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/container/ContainerType.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/container/ContainerType.java @@ -1,17 +1,17 @@ -package com.onarandombox.multiverseinventories.profile.container; - -/** - * Used to describe whether a {@link ProfileContainer} represents a single world or a group of worlds. - */ -public enum ContainerType { - - /** - * Indicates World type profiles. - */ - WORLD, - /** - * Indicates Group type profiles. - */ - GROUP; -} - +package org.mvplugins.multiverse.inventories.profile.container; + +/** + * Used to describe whether a {@link ProfileContainer} represents a single world or a group of worlds. + */ +public enum ContainerType { + + /** + * Indicates World type profiles. + */ + WORLD, + /** + * Indicates Group type profiles. + */ + GROUP; +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/container/ProfileContainer.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/container/ProfileContainer.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/profile/container/ProfileContainer.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/container/ProfileContainer.java index e6ffc560..2cd4fb93 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/container/ProfileContainer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/container/ProfileContainer.java @@ -1,7 +1,7 @@ -package com.onarandombox.multiverseinventories.profile.container; +package org.mvplugins.multiverse.inventories.profile.container; -import com.onarandombox.multiverseinventories.profile.ProfileType; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.ProfileType; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/container/ProfileContainerStore.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/container/ProfileContainerStore.java similarity index 85% rename from src/main/java/com/onarandombox/multiverseinventories/profile/container/ProfileContainerStore.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/container/ProfileContainerStore.java index b7b4d9e2..91f5c873 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/container/ProfileContainerStore.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/container/ProfileContainerStore.java @@ -1,23 +1,23 @@ -package com.onarandombox.multiverseinventories.profile.container; - -/** - * A utility for storing and retrieving profile containers. - */ -public interface ProfileContainerStore { - - /** - * Adds a profile container to the store. - * - * @param container profile container to add. - */ - void addContainer(ProfileContainer container); - - /** - * Returns the profile container for the given name. - * - * @param containerName Name of the profile container to retrieve. - * @return the profile container for given name. - */ - ProfileContainer getContainer(String containerName); -} - +package org.mvplugins.multiverse.inventories.profile.container; + +/** + * A utility for storing and retrieving profile containers. + */ +public interface ProfileContainerStore { + + /** + * Adds a profile container to the store. + * + * @param container profile container to add. + */ + void addContainer(ProfileContainer container); + + /** + * Returns the profile container for the given name. + * + * @param containerName Name of the profile container to retrieve. + * @return the profile container for given name. + */ + ProfileContainer getContainer(String containerName); +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/profile/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/profile/package-info.java similarity index 64% rename from src/main/java/com/onarandombox/multiverseinventories/profile/package-info.java rename to src/main/java/org/mvplugins/multiverse/inventories/profile/package-info.java index 38c8b5f9..9480ae1f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/profile/package-info.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/profile/package-info.java @@ -1,5 +1,5 @@ -/** - * This package contains classes related to groups and worlds and the player profiles they contain. - */ -package com.onarandombox.multiverseinventories.profile; - +/** + * This package contains classes related to groups and worlds and the player profiles they contain. + */ +package org.mvplugins.multiverse.inventories.profile; + diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/DefaultSerializer.java b/src/main/java/org/mvplugins/multiverse/inventories/share/DefaultSerializer.java similarity index 87% rename from src/main/java/com/onarandombox/multiverseinventories/share/DefaultSerializer.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/DefaultSerializer.java index 1888dc38..ef524d28 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/DefaultSerializer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/DefaultSerializer.java @@ -1,30 +1,30 @@ -package com.onarandombox.multiverseinventories.share; - -/** - * The default Sharable serializer. It performs no special tasks on the objects being sent to persistence, they are - * sent as is. - * - * @param The type of data this serializer serializes. - */ -final class DefaultSerializer implements SharableSerializer { - - private Class type; - - public DefaultSerializer(Class type) { - this.type = type; - } - - private Class getType() { - return this.type; - } - - @Override - public T deserialize(Object obj) { - return getType().cast(obj); - } - - @Override - public Object serialize(T t) { - return t; - } -} +package org.mvplugins.multiverse.inventories.share; + +/** + * The default Sharable serializer. It performs no special tasks on the objects being sent to persistence, they are + * sent as is. + * + * @param The type of data this serializer serializes. + */ +final class DefaultSerializer implements SharableSerializer { + + private Class type; + + public DefaultSerializer(Class type) { + this.type = type; + } + + private Class getType() { + return this.type; + } + + @Override + public T deserialize(Object obj) { + return getType().cast(obj); + } + + @Override + public Object serialize(T t) { + return t; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/DefaultSharable.java b/src/main/java/org/mvplugins/multiverse/inventories/share/DefaultSharable.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/share/DefaultSharable.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/DefaultSharable.java index 306616e9..5d3c61ba 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/DefaultSharable.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/DefaultSharable.java @@ -1,83 +1,83 @@ -package com.onarandombox.multiverseinventories.share; - -/** - * A class used to define a value that can be shared between worlds and world groups in Multiverse-Inventories. - * - * @param The type of data this Sharable represents. - */ -final class DefaultSharable implements Sharable { - - private final String[] names; - private final SharableHandler handler; - private final SharableSerializer serializer; - private final ProfileEntry profileEntry; - private final boolean optional; - private final Class type; - - DefaultSharable(final String[] names, final Class type, final SharableHandler handler, - final SharableSerializer serializer, final ProfileEntry entry, final boolean optional) { - this.names = names; - this.handler = handler; - this.serializer = serializer; - this.profileEntry = entry; - this.optional = optional; - this.type = type; - Sharables.register(this); - } - - /** - * {@inheritDoc} - */ - @Override - public String[] getNames() { - return names; - } - - /** - * {@inheritDoc} - */ - @Override - public Class getType() { - return this.type; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.names[0]; - } - - /** - * {@inheritDoc} - */ - @Override - public SharableHandler getHandler() { - return this.handler; - } - - /** - * {@inheritDoc} - */ - @Override - public SharableSerializer getSerializer() { - return this.serializer; - } - - /** - * {@inheritDoc} - */ - @Override - public ProfileEntry getProfileEntry() { - return this.profileEntry; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isOptional() { - return this.optional; - } -} +package org.mvplugins.multiverse.inventories.share; + +/** + * A class used to define a value that can be shared between worlds and world groups in Multiverse-Inventories. + * + * @param The type of data this Sharable represents. + */ +final class DefaultSharable implements Sharable { + + private final String[] names; + private final SharableHandler handler; + private final SharableSerializer serializer; + private final ProfileEntry profileEntry; + private final boolean optional; + private final Class type; + + DefaultSharable(final String[] names, final Class type, final SharableHandler handler, + final SharableSerializer serializer, final ProfileEntry entry, final boolean optional) { + this.names = names; + this.handler = handler; + this.serializer = serializer; + this.profileEntry = entry; + this.optional = optional; + this.type = type; + Sharables.register(this); + } + + /** + * {@inheritDoc} + */ + @Override + public String[] getNames() { + return names; + } + + /** + * {@inheritDoc} + */ + @Override + public Class getType() { + return this.type; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return this.names[0]; + } + + /** + * {@inheritDoc} + */ + @Override + public SharableHandler getHandler() { + return this.handler; + } + + /** + * {@inheritDoc} + */ + @Override + public SharableSerializer getSerializer() { + return this.serializer; + } + + /** + * {@inheritDoc} + */ + @Override + public ProfileEntry getProfileEntry() { + return this.profileEntry; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isOptional() { + return this.optional; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/DefaultStringSerializer.java b/src/main/java/org/mvplugins/multiverse/inventories/share/DefaultStringSerializer.java similarity index 94% rename from src/main/java/com/onarandombox/multiverseinventories/share/DefaultStringSerializer.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/DefaultStringSerializer.java index c18f2374..f2c2c329 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/DefaultStringSerializer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/DefaultStringSerializer.java @@ -1,51 +1,51 @@ -package com.onarandombox.multiverseinventories.share; - -import com.dumptruckman.minecraft.util.Logging; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -/** - * This Sharable serializer attempts to deserialize the string form of objects passed to it through use of - * T.valueOf(String). Likewise, it serializes data simply by calling Object.toString() on the value passed in. - * - * @param The type of data this serializer serializes. This class MUST have a static valueOf(String) method that - * returns it's type. - */ -final class DefaultStringSerializer implements SharableSerializer { - - private Method valueOfMethod; - private Class clazz; - - DefaultStringSerializer(Class clazz) { - this.clazz = clazz; - try { - valueOfMethod = clazz.getMethod("valueOf", String.class); - valueOfMethod.setAccessible(true); - if (!valueOfMethod.getReturnType().equals(clazz) || !Modifier.isStatic(valueOfMethod.getModifiers())) { - throw new IllegalArgumentException(clazz.getName() + " has no static valueOf(String) method!"); - } - } catch (NoSuchMethodException e) { - throw new IllegalArgumentException(clazz.getName() + " has no static valueOf(String) method!"); - } - } - - @Override - public T deserialize(Object obj) { - try { - return clazz.cast(valueOfMethod.invoke(null, obj.toString())); - } catch (IllegalAccessException e) { - Logging.severe(this.clazz.getName() + " has no accessible static valueOf(String) method!"); - } catch (InvocationTargetException e) { - Logging.severe(this.clazz.getName() + ".valueOf(String) is throwing an exception:"); - e.printStackTrace(); - } - throw new IllegalStateException(this.getClass().getName() + " was used illegally! Contact dumptruckman!"); - } - - @Override - public Object serialize(T t) { - return t.toString(); - } -} +package org.mvplugins.multiverse.inventories.share; + +import com.dumptruckman.minecraft.util.Logging; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +/** + * This Sharable serializer attempts to deserialize the string form of objects passed to it through use of + * T.valueOf(String). Likewise, it serializes data simply by calling Object.toString() on the value passed in. + * + * @param The type of data this serializer serializes. This class MUST have a static valueOf(String) method that + * returns it's type. + */ +final class DefaultStringSerializer implements SharableSerializer { + + private Method valueOfMethod; + private Class clazz; + + DefaultStringSerializer(Class clazz) { + this.clazz = clazz; + try { + valueOfMethod = clazz.getMethod("valueOf", String.class); + valueOfMethod.setAccessible(true); + if (!valueOfMethod.getReturnType().equals(clazz) || !Modifier.isStatic(valueOfMethod.getModifiers())) { + throw new IllegalArgumentException(clazz.getName() + " has no static valueOf(String) method!"); + } + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(clazz.getName() + " has no static valueOf(String) method!"); + } + } + + @Override + public T deserialize(Object obj) { + try { + return clazz.cast(valueOfMethod.invoke(null, obj.toString())); + } catch (IllegalAccessException e) { + Logging.severe(this.clazz.getName() + " has no accessible static valueOf(String) method!"); + } catch (InvocationTargetException e) { + Logging.severe(this.clazz.getName() + ".valueOf(String) is throwing an exception:"); + e.printStackTrace(); + } + throw new IllegalStateException(this.getClass().getName() + " was used illegally! Contact dumptruckman!"); + } + + @Override + public Object serialize(T t) { + return t.toString(); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/InventorySerializer.java b/src/main/java/org/mvplugins/multiverse/inventories/share/InventorySerializer.java similarity index 90% rename from src/main/java/com/onarandombox/multiverseinventories/share/InventorySerializer.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/InventorySerializer.java index e1baa956..f4cca144 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/InventorySerializer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/InventorySerializer.java @@ -1,58 +1,58 @@ -package com.onarandombox.multiverseinventories.share; - -import com.onarandombox.multiverseinventories.util.MinecraftTools; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import java.util.HashMap; -import java.util.Map; - -/** - * A simple {@link SharableSerializer} usable with ItemStack[] which converts the ItemStack[] to the string format - * that is used by default in Multiverse-Inventories. - */ -public final class InventorySerializer implements SharableSerializer { - - private int inventorySize; - - public InventorySerializer(final int inventorySize) { - this.inventorySize = inventorySize; - } - - @Override - public ItemStack[] deserialize(Object obj) { - return unmapSlots(obj); - } - - @Override - public Object serialize(ItemStack[] itemStacks) { - return mapSlots(itemStacks); - } - - private Map mapSlots(ItemStack[] itemStacks) { - Map result = new HashMap<>(itemStacks.length); - for (int i = 0; i < itemStacks.length; i++) { - if (itemStacks[i] != null && itemStacks[i].getType() != Material.AIR) { - result.put(Integer.toString(i), itemStacks[i]); - } - } - return result; - } - - private ItemStack[] unmapSlots(Object obj) { - ItemStack[] result = new ItemStack[inventorySize]; - if (obj instanceof Map) { - Map invMap = (Map) obj; - for (int i = 0; i < result.length; i++) { - Object value = invMap.get(Integer.toString(i)); - if (value != null && value instanceof ItemStack) { - result[i] = (ItemStack) value; - } else { - result[i] = new ItemStack(Material.AIR); - } - } - return result; - } - return MinecraftTools.fillWithAir(result); - } -} +package org.mvplugins.multiverse.inventories.share; + +import org.mvplugins.multiverse.inventories.util.MinecraftTools; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +/** + * A simple {@link SharableSerializer} usable with ItemStack[] which converts the ItemStack[] to the string format + * that is used by default in Multiverse-Inventories. + */ +public final class InventorySerializer implements SharableSerializer { + + private int inventorySize; + + public InventorySerializer(final int inventorySize) { + this.inventorySize = inventorySize; + } + + @Override + public ItemStack[] deserialize(Object obj) { + return unmapSlots(obj); + } + + @Override + public Object serialize(ItemStack[] itemStacks) { + return mapSlots(itemStacks); + } + + private Map mapSlots(ItemStack[] itemStacks) { + Map result = new HashMap<>(itemStacks.length); + for (int i = 0; i < itemStacks.length; i++) { + if (itemStacks[i] != null && itemStacks[i].getType() != Material.AIR) { + result.put(Integer.toString(i), itemStacks[i]); + } + } + return result; + } + + private ItemStack[] unmapSlots(Object obj) { + ItemStack[] result = new ItemStack[inventorySize]; + if (obj instanceof Map) { + Map invMap = (Map) obj; + for (int i = 0; i < result.length; i++) { + Object value = invMap.get(Integer.toString(i)); + if (value != null && value instanceof ItemStack) { + result[i] = (ItemStack) value; + } else { + result[i] = new ItemStack(Material.AIR); + } + } + return result; + } + return MinecraftTools.fillWithAir(result); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/LocationSerializer.java b/src/main/java/org/mvplugins/multiverse/inventories/share/LocationSerializer.java similarity index 88% rename from src/main/java/com/onarandombox/multiverseinventories/share/LocationSerializer.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/LocationSerializer.java index 8284c7f0..98554ddf 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/LocationSerializer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/LocationSerializer.java @@ -1,36 +1,36 @@ -package com.onarandombox.multiverseinventories.share; - -import com.onarandombox.multiverseinventories.DataStrings; -import org.bukkit.Location; - -import java.util.Map; - -/** - * A simple {@link SharableSerializer} usable with {@link Location} which converts the {@link Location} to the string - * format that is used by default in Multiverse-Inventories. - * @deprecated Locations no longer need a special serializer because they are - * {@link org.bukkit.configuration.serialization.ConfigurationSerializable}. This remains to convert legacy data. - */ -@Deprecated -public final class LocationSerializer implements SharableSerializer { - - @Override - public Location deserialize(Object obj) { - if (obj instanceof Location) { - return (Location) obj; - } else if (obj instanceof String) { - return DataStrings.parseLocation(obj.toString()); - } else { - if (obj instanceof Map) { - return DataStrings.parseLocation((Map) obj); - } else { - return DataStrings.parseLocation(obj.toString()); - } - } - } - - @Override - public Object serialize(Location location) { - return location; - } -} +package org.mvplugins.multiverse.inventories.share; + +import org.mvplugins.multiverse.inventories.DataStrings; +import org.bukkit.Location; + +import java.util.Map; + +/** + * A simple {@link SharableSerializer} usable with {@link Location} which converts the {@link Location} to the string + * format that is used by default in Multiverse-Inventories. + * @deprecated Locations no longer need a special serializer because they are + * {@link org.bukkit.configuration.serialization.ConfigurationSerializable}. This remains to convert legacy data. + */ +@Deprecated +public final class LocationSerializer implements SharableSerializer { + + @Override + public Location deserialize(Object obj) { + if (obj instanceof Location) { + return (Location) obj; + } else if (obj instanceof String) { + return DataStrings.parseLocation(obj.toString()); + } else { + if (obj instanceof Map) { + return DataStrings.parseLocation((Map) obj); + } else { + return DataStrings.parseLocation(obj.toString()); + } + } + } + + @Override + public Object serialize(Location location) { + return location; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/PersistingProfile.java b/src/main/java/org/mvplugins/multiverse/inventories/share/PersistingProfile.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/share/PersistingProfile.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/PersistingProfile.java index 20fc431b..555015d1 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/PersistingProfile.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/PersistingProfile.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.share; +package org.mvplugins.multiverse.inventories.share; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; /** * Simple interface for groups that are going to be saved/loaded. This is used specifically for when a user's world diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/PotionEffectSerializer.java b/src/main/java/org/mvplugins/multiverse/inventories/share/PotionEffectSerializer.java similarity index 79% rename from src/main/java/com/onarandombox/multiverseinventories/share/PotionEffectSerializer.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/PotionEffectSerializer.java index f16c0bff..753170b6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/PotionEffectSerializer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/PotionEffectSerializer.java @@ -1,36 +1,36 @@ -package com.onarandombox.multiverseinventories.share; - -import com.onarandombox.multiverseinventories.DataStrings; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * A simple {@link com.onarandombox.multiverseinventories.share.SharableSerializer} usable with PotionEffect[] - * which converts the PotionEffect[] to the string format that is used by default in Multiverse-Inventories. - */ -public final class PotionEffectSerializer implements SharableSerializer { - - @Override - public PotionEffect[] deserialize(Object obj) { - if (obj instanceof List) { - List list = (List) obj; - List resultList = new ArrayList<>(list.size()); - for (Object o : list) { - if (o instanceof PotionEffect) { - resultList.add((PotionEffect) o); - } - } - return resultList.toArray(new PotionEffect[resultList.size()]); - } else { - return DataStrings.parsePotionEffects(obj.toString()); - } - } - - @Override - public Object serialize(PotionEffect[] potionEffects) { - return Arrays.asList(potionEffects); - } -} +package org.mvplugins.multiverse.inventories.share; + +import org.mvplugins.multiverse.inventories.DataStrings; +import org.bukkit.potion.PotionEffect; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * A simple {@link SharableSerializer} usable with PotionEffect[] + * which converts the PotionEffect[] to the string format that is used by default in Multiverse-Inventories. + */ +public final class PotionEffectSerializer implements SharableSerializer { + + @Override + public PotionEffect[] deserialize(Object obj) { + if (obj instanceof List) { + List list = (List) obj; + List resultList = new ArrayList<>(list.size()); + for (Object o : list) { + if (o instanceof PotionEffect) { + resultList.add((PotionEffect) o); + } + } + return resultList.toArray(new PotionEffect[resultList.size()]); + } else { + return DataStrings.parsePotionEffects(obj.toString()); + } + } + + @Override + public Object serialize(PotionEffect[] potionEffects) { + return Arrays.asList(potionEffects); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/ProfileEntry.java b/src/main/java/org/mvplugins/multiverse/inventories/share/ProfileEntry.java similarity index 94% rename from src/main/java/com/onarandombox/multiverseinventories/share/ProfileEntry.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/ProfileEntry.java index d3cf5a65..7145eb07 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/ProfileEntry.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/ProfileEntry.java @@ -1,70 +1,70 @@ -package com.onarandombox.multiverseinventories.share; - -import java.util.HashMap; -import java.util.Map; - -/** - * Indicates how a Sharable should be stored in the profile file. Serves as a lookup for finding a sharable based on - * it's file tag. - */ -public final class ProfileEntry { - - private static final Map STATS_MAP = new HashMap(); - private static final Map OTHERS_MAP = new HashMap(); - - private boolean isStat; - private String fileTag; - - public ProfileEntry(boolean isStat, String fileTag) { - this.isStat = isStat; - this.fileTag = fileTag; - } - - /** - * @return True if this indicates a {@link Sharable} whose data will be stored in the stats string of the player - * file. - */ - public boolean isStat() { - return this.isStat; - } - - /** - * @return The String that represents where this file is stored in the player profile. - */ - public String getFileTag() { - return this.fileTag; - } - - /** - * Registers a {@link Sharable} with it's respective ProfileEntry. - * - * @param sharable The sharable to register. - */ - static void register(Sharable sharable) { - ProfileEntry entry = sharable.getProfileEntry(); - if (entry == null) { - // This would mean the sharable is not intended for saving in profile files. - return; - } - if (entry.isStat()) { - STATS_MAP.put(entry.getFileTag(), sharable); - } else { - OTHERS_MAP.put(entry.getFileTag(), sharable); - } - } - - /** - * Used to look up a {@link Sharable} by it's file tag. - * - * @param stat True means this sharable is in the stats section of the player file. - * @param fileTag The string representing where the sharable is stored in the player file. - * @return A sharable if one has been registered with it's ProfileEntry otherwise null. - */ - public static Sharable lookup(boolean stat, String fileTag) { - if (stat) { - return STATS_MAP.get(fileTag); - } else { - return OTHERS_MAP.get(fileTag); - } - } -} +package org.mvplugins.multiverse.inventories.share; + +import java.util.HashMap; +import java.util.Map; + +/** + * Indicates how a Sharable should be stored in the profile file. Serves as a lookup for finding a sharable based on + * it's file tag. + */ +public final class ProfileEntry { + + private static final Map STATS_MAP = new HashMap(); + private static final Map OTHERS_MAP = new HashMap(); + + private boolean isStat; + private String fileTag; + + public ProfileEntry(boolean isStat, String fileTag) { + this.isStat = isStat; + this.fileTag = fileTag; + } + + /** + * @return True if this indicates a {@link Sharable} whose data will be stored in the stats string of the player + * file. + */ + public boolean isStat() { + return this.isStat; + } + + /** + * @return The String that represents where this file is stored in the player profile. + */ + public String getFileTag() { + return this.fileTag; + } + + /** + * Registers a {@link Sharable} with it's respective ProfileEntry. + * + * @param sharable The sharable to register. + */ + static void register(Sharable sharable) { + ProfileEntry entry = sharable.getProfileEntry(); + if (entry == null) { + // This would mean the sharable is not intended for saving in profile files. + return; + } + if (entry.isStat()) { + STATS_MAP.put(entry.getFileTag(), sharable); + } else { + OTHERS_MAP.put(entry.getFileTag(), sharable); + } + } + + /** + * Used to look up a {@link Sharable} by it's file tag. + * + * @param stat True means this sharable is in the stats section of the player file. + * @param fileTag The string representing where the sharable is stored in the player file. + * @return A sharable if one has been registered with it's ProfileEntry otherwise null. + */ + public static Sharable lookup(boolean stat, String fileTag) { + if (stat) { + return STATS_MAP.get(fileTag); + } else { + return OTHERS_MAP.get(fileTag); + } + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/Sharable.java b/src/main/java/org/mvplugins/multiverse/inventories/share/Sharable.java similarity index 95% rename from src/main/java/com/onarandombox/multiverseinventories/share/Sharable.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/Sharable.java index 64dca20a..e48e2c1a 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/Sharable.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/Sharable.java @@ -1,156 +1,156 @@ -package com.onarandombox.multiverseinventories.share; - -import com.onarandombox.multiverseinventories.InventoriesConfig; - -import java.util.ArrayList; -import java.util.List; - -/** - * An interface for any attribute that can be shared between worlds in a world group. These objects are intended to - * be used as constants and may not function properly otherwise. - * - * @param The type of data that this sharable represents. - */ -public interface Sharable { - - /** - * @return The names of this Sharable for setting as shared in the config. There should ALWAYS be a index-0 which - * represents the main name, and the one that will be used for storing the sharable in a groups shares list in - * the config file. All names in this array may be used to set a group as sharing this Sharable. - */ - String[] getNames(); - - /** - * @return The object that will handle changing out the player's data with the profile's data and vice versa when - * a player changes worlds. - */ - SharableHandler getHandler(); - - /** - * @return The object that will handle serializing a profile's data for this sharable for saving/loading in the - * profile's data file. If this is null it means that persistence is not handled by Multiverse-Inventories for - * this Sharable. - */ - SharableSerializer getSerializer(); - - /** - * @return The profile entry that describes how to store this Sharable in a profile's data file. This may NOT be - * null if this Sharable getSerializer() is not null. If getSerializer() IS null, this method is never called. - */ - ProfileEntry getProfileEntry(); - - /** - * @return The type of data this Sharable represents. Used primarily for casting. - */ - Class getType(); - - /** - * @return True if this Sharable is optional. That is to say that it is completely ignored when share handling - * takes place UNLESS it is present in {@link InventoriesConfig#getOptionalShares()}. - */ - boolean isOptional(); - - /** - * This class is used to build new {@link Sharable}s. Simply instantiate this and use method chaining to set - * all the options for your Sharable. - * - * @param The type of data the new Sharable will represent. - */ - class Builder { - - private List names = new ArrayList(); - private ProfileEntry profileEntry = null; - private SharableHandler handler; - private SharableSerializer serializer = null; - private boolean optional = false; - private Class type; - - /** - * @param name The primary name of the new Sharable. - * @param type The type of data the Sharable represents. - * @param handler The object that will handle switching the Sharable data between player and profile. - */ - public Builder(String name, Class type, SharableHandler handler) { - this.names.add(name); - this.handler = handler; - this.type = type; - } - - /** - * Indicates that the new Sharable is optional as described in {@link Sharable#isOptional()}. - * - * @return This builder object for method chaining. - */ - public Builder optional() { - this.optional = true; - return this; - } - - /** - * @param name An alternate name for this Sharable which can be used to indicate a group is sharing this - * Sharable. - * @return This builder object for method chaining. - */ - public Builder altName(String name) { - this.names.add(name); - return this; - } - - /** - * Sets this sharable to be serialized as a string in the profile data file. To use this, the class type - * indicates in the Builder's constructor MUST have a static .valueOf(String) method that returns it's type. - * - * @param entry The profile entry describing where this Sharable is located in the profile file. - * @return This builder object for method chaining. - * @throws IllegalArgumentException This is thrown if the type indicated in the Builder's constructor does not - * fit the constraints indicated above. - */ - public Builder stringSerializer(ProfileEntry entry) { - this.serializer = new DefaultStringSerializer(this.type); - this.profileEntry = entry; - return this; - } - - /** - * This will make the Sharable use the default serializer which simply passes the data as is to the persistence - * object for persistence. This will only work depending on the data type this Sharable represents and further - * depending on the types the persistence methods accept. Generally, boxed primitives are okay as well as - * Lists of boxed primitives and {@link java.util.Map}<{@link String}, {@link Object}>. All other types - * will likely require a custom {@link SharableSerializer} indicated with - * {@link #serializer(ProfileEntry, SharableSerializer)}. - * - * @param entry The profile entry describing where this Sharable is located in the profile file. - * @return This builder object for method chaining. - */ - public Builder defaultSerializer(ProfileEntry entry) { - this.serializer = new DefaultSerializer(this.type); - this.profileEntry = entry; - return this; - } - - /** - * This allows you to specify a custom {@link SharableSerializer} to use to convert the data represented by - * this Sharable into something acceptable by persistence. - * - * @param entry The profile entry describing where this Sharable is located in the profile file. - * @param serializer A custom serializer describing how to handle the data in order for it to be persisted in - * the profile. - * @return This builder object for method chaining. - */ - public Builder serializer(ProfileEntry entry, SharableSerializer serializer) { - this.serializer = serializer; - this.profileEntry = entry; - return this; - } - - /** - * @return The new Sharable object built by this Builder. - */ - public Sharable build() { - Sharable sharable = new DefaultSharable(names.toArray(new String[names.size()]), type, - handler, serializer, profileEntry, optional); - ProfileEntry.register(sharable); - return sharable; - } - } -} +package org.mvplugins.multiverse.inventories.share; + +import org.mvplugins.multiverse.inventories.InventoriesConfig; + +import java.util.ArrayList; +import java.util.List; + +/** + * An interface for any attribute that can be shared between worlds in a world group. These objects are intended to + * be used as constants and may not function properly otherwise. + * + * @param The type of data that this sharable represents. + */ +public interface Sharable { + + /** + * @return The names of this Sharable for setting as shared in the config. There should ALWAYS be a index-0 which + * represents the main name, and the one that will be used for storing the sharable in a groups shares list in + * the config file. All names in this array may be used to set a group as sharing this Sharable. + */ + String[] getNames(); + + /** + * @return The object that will handle changing out the player's data with the profile's data and vice versa when + * a player changes worlds. + */ + SharableHandler getHandler(); + + /** + * @return The object that will handle serializing a profile's data for this sharable for saving/loading in the + * profile's data file. If this is null it means that persistence is not handled by Multiverse-Inventories for + * this Sharable. + */ + SharableSerializer getSerializer(); + + /** + * @return The profile entry that describes how to store this Sharable in a profile's data file. This may NOT be + * null if this Sharable getSerializer() is not null. If getSerializer() IS null, this method is never called. + */ + ProfileEntry getProfileEntry(); + + /** + * @return The type of data this Sharable represents. Used primarily for casting. + */ + Class getType(); + + /** + * @return True if this Sharable is optional. That is to say that it is completely ignored when share handling + * takes place UNLESS it is present in {@link InventoriesConfig#getOptionalShares()}. + */ + boolean isOptional(); + + /** + * This class is used to build new {@link Sharable}s. Simply instantiate this and use method chaining to set + * all the options for your Sharable. + * + * @param The type of data the new Sharable will represent. + */ + class Builder { + + private List names = new ArrayList(); + private ProfileEntry profileEntry = null; + private SharableHandler handler; + private SharableSerializer serializer = null; + private boolean optional = false; + private Class type; + + /** + * @param name The primary name of the new Sharable. + * @param type The type of data the Sharable represents. + * @param handler The object that will handle switching the Sharable data between player and profile. + */ + public Builder(String name, Class type, SharableHandler handler) { + this.names.add(name); + this.handler = handler; + this.type = type; + } + + /** + * Indicates that the new Sharable is optional as described in {@link Sharable#isOptional()}. + * + * @return This builder object for method chaining. + */ + public Builder optional() { + this.optional = true; + return this; + } + + /** + * @param name An alternate name for this Sharable which can be used to indicate a group is sharing this + * Sharable. + * @return This builder object for method chaining. + */ + public Builder altName(String name) { + this.names.add(name); + return this; + } + + /** + * Sets this sharable to be serialized as a string in the profile data file. To use this, the class type + * indicates in the Builder's constructor MUST have a static .valueOf(String) method that returns it's type. + * + * @param entry The profile entry describing where this Sharable is located in the profile file. + * @return This builder object for method chaining. + * @throws IllegalArgumentException This is thrown if the type indicated in the Builder's constructor does not + * fit the constraints indicated above. + */ + public Builder stringSerializer(ProfileEntry entry) { + this.serializer = new DefaultStringSerializer(this.type); + this.profileEntry = entry; + return this; + } + + /** + * This will make the Sharable use the default serializer which simply passes the data as is to the persistence + * object for persistence. This will only work depending on the data type this Sharable represents and further + * depending on the types the persistence methods accept. Generally, boxed primitives are okay as well as + * Lists of boxed primitives and {@link java.util.Map}<{@link String}, {@link Object}>. All other types + * will likely require a custom {@link SharableSerializer} indicated with + * {@link #serializer(ProfileEntry, SharableSerializer)}. + * + * @param entry The profile entry describing where this Sharable is located in the profile file. + * @return This builder object for method chaining. + */ + public Builder defaultSerializer(ProfileEntry entry) { + this.serializer = new DefaultSerializer(this.type); + this.profileEntry = entry; + return this; + } + + /** + * This allows you to specify a custom {@link SharableSerializer} to use to convert the data represented by + * this Sharable into something acceptable by persistence. + * + * @param entry The profile entry describing where this Sharable is located in the profile file. + * @param serializer A custom serializer describing how to handle the data in order for it to be persisted in + * the profile. + * @return This builder object for method chaining. + */ + public Builder serializer(ProfileEntry entry, SharableSerializer serializer) { + this.serializer = serializer; + this.profileEntry = entry; + return this; + } + + /** + * @return The new Sharable object built by this Builder. + */ + public Sharable build() { + Sharable sharable = new DefaultSharable(names.toArray(new String[names.size()]), type, + handler, serializer, profileEntry, optional); + ProfileEntry.register(sharable); + return sharable; + } + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/SharableEntry.java b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableEntry.java similarity index 83% rename from src/main/java/com/onarandombox/multiverseinventories/share/SharableEntry.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/SharableEntry.java index 418c1fdc..9f13d1a6 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/SharableEntry.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableEntry.java @@ -1,20 +1,20 @@ -package com.onarandombox.multiverseinventories.share; - -public final class SharableEntry { - - private final Sharable sharable; - private final T value; - - public SharableEntry(Sharable sharable, T initialValue) { - this.sharable = sharable; - this.value = initialValue; - } - - public Sharable getSharable() { - return sharable; - } - - public T getValue() { - return value; - } -} +package org.mvplugins.multiverse.inventories.share; + +public final class SharableEntry { + + private final Sharable sharable; + private final T value; + + public SharableEntry(Sharable sharable, T initialValue) { + this.sharable = sharable; + this.value = initialValue; + } + + public Sharable getSharable() { + return sharable; + } + + public T getValue() { + return value; + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/SharableGroup.java b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableGroup.java similarity index 94% rename from src/main/java/com/onarandombox/multiverseinventories/share/SharableGroup.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/SharableGroup.java index c030cd8f..80724ddf 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/SharableGroup.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableGroup.java @@ -1,134 +1,134 @@ -package com.onarandombox.multiverseinventories.share; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * This class represents a grouping of Sharable objects for the sole purpose of being able to use one keyword in - * group setups to indicate multiple {@link Sharable}s. - */ -public final class SharableGroup implements Shares { - - private String[] names; - private Shares shares; - - public SharableGroup(String name, Shares shares, String... alternateNames) { - this.names = new String[alternateNames.length + 1]; - this.names[0] = name; - System.arraycopy(alternateNames, 0, this.names, 1, alternateNames.length); - this.shares = shares; - for (String lookupName : this.names) { - Sharables.LOOKUP_MAP.put(lookupName, this); - } - } - - /** - * @return The names of this SharableGroup for setting as shared in the config. - * All names in this array may be used to set a group as sharing this SharableGroup. - */ - public String[] getNames() { - return this.names; - } - - @Override - public void mergeShares(Shares newShares) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public boolean isSharing(Sharable sharable) { - return shares.isSharing(sharable); - } - - @Override - public boolean isSharing(Shares shares) { - return this.shares.isSharing(shares); - } - - @Override - public Shares compare(Shares shares) { - return this.shares.compare(shares); - } - - @Override - public void setSharing(Sharable sharable, boolean sharing) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public void setSharing(Shares sharables, boolean sharing) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public List toStringList() { - return shares.toStringList(); - } - - @Override - public Iterator iterator() { - return shares.iterator(); - } - - @Override - public int size() { - return shares.size(); - } - - @Override - public boolean isEmpty() { - return shares.isEmpty(); - } - - @Override - public boolean contains(Object o) { - return shares.contains(o); - } - - @Override - public Object[] toArray() { - return Collections.unmodifiableCollection(this).toArray(); - } - - @Override - public T[] toArray(T[] a) { - return Collections.unmodifiableCollection(this).toArray(a); - } - - @Override - public boolean add(Sharable sharable) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public boolean remove(Object o) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public boolean containsAll(Collection c) { - return shares.containsAll(c); - } - - @Override - public boolean addAll(Collection c) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public boolean removeAll(Collection c) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public boolean retainAll(Collection c) { - throw new IllegalStateException("May not alter SharableGroup!"); - } - - @Override - public void clear() { - throw new IllegalStateException("May not alter SharableGroup!"); - } -} +package org.mvplugins.multiverse.inventories.share; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * This class represents a grouping of Sharable objects for the sole purpose of being able to use one keyword in + * group setups to indicate multiple {@link Sharable}s. + */ +public final class SharableGroup implements Shares { + + private String[] names; + private Shares shares; + + public SharableGroup(String name, Shares shares, String... alternateNames) { + this.names = new String[alternateNames.length + 1]; + this.names[0] = name; + System.arraycopy(alternateNames, 0, this.names, 1, alternateNames.length); + this.shares = shares; + for (String lookupName : this.names) { + Sharables.LOOKUP_MAP.put(lookupName, this); + } + } + + /** + * @return The names of this SharableGroup for setting as shared in the config. + * All names in this array may be used to set a group as sharing this SharableGroup. + */ + public String[] getNames() { + return this.names; + } + + @Override + public void mergeShares(Shares newShares) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public boolean isSharing(Sharable sharable) { + return shares.isSharing(sharable); + } + + @Override + public boolean isSharing(Shares shares) { + return this.shares.isSharing(shares); + } + + @Override + public Shares compare(Shares shares) { + return this.shares.compare(shares); + } + + @Override + public void setSharing(Sharable sharable, boolean sharing) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public void setSharing(Shares sharables, boolean sharing) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public List toStringList() { + return shares.toStringList(); + } + + @Override + public Iterator iterator() { + return shares.iterator(); + } + + @Override + public int size() { + return shares.size(); + } + + @Override + public boolean isEmpty() { + return shares.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return shares.contains(o); + } + + @Override + public Object[] toArray() { + return Collections.unmodifiableCollection(this).toArray(); + } + + @Override + public T[] toArray(T[] a) { + return Collections.unmodifiableCollection(this).toArray(a); + } + + @Override + public boolean add(Sharable sharable) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public boolean remove(Object o) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public boolean containsAll(Collection c) { + return shares.containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public boolean removeAll(Collection c) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public boolean retainAll(Collection c) { + throw new IllegalStateException("May not alter SharableGroup!"); + } + + @Override + public void clear() { + throw new IllegalStateException("May not alter SharableGroup!"); + } +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/SharableHandler.java b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableHandler.java similarity index 92% rename from src/main/java/com/onarandombox/multiverseinventories/share/SharableHandler.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/SharableHandler.java index fe853755..30b3fd16 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/SharableHandler.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableHandler.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.share; +package org.mvplugins.multiverse.inventories.share; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; import org.bukkit.entity.Player; /** diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/SharableSerializer.java b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableSerializer.java similarity index 93% rename from src/main/java/com/onarandombox/multiverseinventories/share/SharableSerializer.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/SharableSerializer.java index 4c078b1c..d42fe40f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/SharableSerializer.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/SharableSerializer.java @@ -1,29 +1,29 @@ -package com.onarandombox.multiverseinventories.share; - -/** - * This represents how a Sharable's data will be serialized/deserialized. - * - * @param The type of data the {@link Sharable} this belongs to represents. - */ -public interface SharableSerializer { - - /** - * This deserializes the data for a Sharable. You must be expecting the type of data coming in in order to process - * this. That type will generally be the type that this serializes as with {@link #serialize(Object)}. - * - * @param obj The incoming (serialized) data to be deserialized. - * @return The data represented by the Sharable this object represents in deserialized form. - */ - T deserialize(Object obj); - - /** - * This serializes the data for a Sharable. The output is an Object but what you return is up to you, however, - * this is limited by the constraints of the persistence method. Generally, returning a String is the safest way - * to serialize your data. Most boxed primitives are accepted as well as Lists of boxed primitives and - * {@link java.util.Map}<{@link String}, {@link Object}>. - * - * @param t The value of the data represented by the Sharable. - * @return The serialized form of the data. - */ - Object serialize(T t); -} +package org.mvplugins.multiverse.inventories.share; + +/** + * This represents how a Sharable's data will be serialized/deserialized. + * + * @param The type of data the {@link Sharable} this belongs to represents. + */ +public interface SharableSerializer { + + /** + * This deserializes the data for a Sharable. You must be expecting the type of data coming in in order to process + * this. That type will generally be the type that this serializes as with {@link #serialize(Object)}. + * + * @param obj The incoming (serialized) data to be deserialized. + * @return The data represented by the Sharable this object represents in deserialized form. + */ + T deserialize(Object obj); + + /** + * This serializes the data for a Sharable. The output is an Object but what you return is up to you, however, + * this is limited by the constraints of the persistence method. Generally, returning a String is the safest way + * to serialize your data. Most boxed primitives are accepted as well as Lists of boxed primitives and + * {@link java.util.Map}<{@link String}, {@link Object}>. + * + * @param t The value of the data represented by the Sharable. + * @return The serialized form of the data. + */ + Object serialize(T t); +} diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/Sharables.java b/src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java similarity index 97% rename from src/main/java/com/onarandombox/multiverseinventories/share/Sharables.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java index c66aec90..8621d127 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/Sharables.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java @@ -1,18 +1,20 @@ -package com.onarandombox.multiverseinventories.share; +package org.mvplugins.multiverse.inventories.share; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.MultiverseInventories; -import com.onarandombox.multiverseinventories.WorldGroup; -import com.onarandombox.multiverseinventories.DataStrings; -import com.onarandombox.multiverseinventories.PlayerStats; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.util.MinecraftTools; +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.WorldGroup; +import org.mvplugins.multiverse.inventories.DataStrings; +import org.mvplugins.multiverse.inventories.PlayerStats; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.util.MinecraftTools; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; +import org.mvplugins.multiverse.core.economy.MVEconomist; + import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -37,6 +39,7 @@ public final class Sharables implements Shares { static final Map LOOKUP_MAP = new HashMap(); private static MultiverseInventories inventories = null; + private static MVEconomist economist = null; /** * Initialize this class with the instance of Inventories. @@ -47,6 +50,9 @@ public static void init(MultiverseInventories inventories) { if (Sharables.inventories == null) { Sharables.inventories = inventories; } + if (Sharables.economist == null) { + Sharables.economist = inventories.getServiceLocator().getService(MVEconomist.class); + } } /** @@ -536,7 +542,7 @@ public boolean updatePlayer(Player player, PlayerProfile profile) { public static final Sharable ECONOMY = new Sharable.Builder("economy", Double.class, new SharableHandler() { private boolean hasValidEconomyHandler() { - if (inventories.getCore().getEconomist().isUsingEconomyPlugin()) { + if (economist.isUsingEconomyPlugin()) { return true; } Logging.warning("You do not have an an economy plugin with Vault. Economy sharable will not work!"); @@ -550,7 +556,7 @@ public void updateProfile(PlayerProfile profile, Player player) { if (!hasValidEconomyHandler()) { return; } - profile.set(ECONOMY, inventories.getCore().getEconomist().getBalance(player)); + profile.set(ECONOMY, economist.getBalance(player)); } @Override @@ -560,10 +566,10 @@ public boolean updatePlayer(Player player, PlayerProfile profile) { } Double money = profile.get(ECONOMY); if (money == null) { - inventories.getCore().getEconomist().setBalance(player, 0); + economist.setBalance(player, 0); return false; } - inventories.getCore().getEconomist().setBalance(player, money); + economist.setBalance(player, money); return true; } }).stringSerializer(new ProfileEntry(false, "balance")).optional() diff --git a/src/main/java/com/onarandombox/multiverseinventories/share/Shares.java b/src/main/java/org/mvplugins/multiverse/inventories/share/Shares.java similarity index 93% rename from src/main/java/com/onarandombox/multiverseinventories/share/Shares.java rename to src/main/java/org/mvplugins/multiverse/inventories/share/Shares.java index a523bf27..7f289126 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/share/Shares.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/Shares.java @@ -1,56 +1,56 @@ -package com.onarandombox.multiverseinventories.share; - -import java.util.Collection; -import java.util.List; -import java.util.Set; - -/** - * Interface for getting what is shared in a world player. - */ -public interface Shares extends Cloneable, Iterable, Collection, Set { - - /** - * Merges what is shared with another share. Only the false items should be merged. - * - * @param newShares The set of shares to merge into this set of shares. - */ - void mergeShares(Shares newShares); - - /** - * @param sharable The Sharable you want to check for. - * @return True if it is sharing the sharable. - */ - boolean isSharing(Sharable sharable); - - /** - * @param shares Shares to compare with. - * @return True if it is sharing the same sharables. - */ - boolean isSharing(Shares shares); - - /** - * Checks to see if any of the sharables passed in are shared by this Shares. - * - * @param shares Shares to check for. - * @return A Set containing all of the Sharables both sets contain. - */ - Shares compare(Shares shares); - - /** - * @param sharable The Sharable you wish to set sharing for. - * @param sharing Whether to share or not. - */ - void setSharing(Sharable sharable, boolean sharing); - - /** - * @param sharables a Set of Sharables you wish to set sharing for. - * @param sharing Whether to share or not. - */ - void setSharing(Shares sharables, boolean sharing); - - /** - * @return These shares as a string list. - */ - List toStringList(); -} - +package org.mvplugins.multiverse.inventories.share; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +/** + * Interface for getting what is shared in a world player. + */ +public interface Shares extends Cloneable, Iterable, Collection, Set { + + /** + * Merges what is shared with another share. Only the false items should be merged. + * + * @param newShares The set of shares to merge into this set of shares. + */ + void mergeShares(Shares newShares); + + /** + * @param sharable The Sharable you want to check for. + * @return True if it is sharing the sharable. + */ + boolean isSharing(Sharable sharable); + + /** + * @param shares Shares to compare with. + * @return True if it is sharing the same sharables. + */ + boolean isSharing(Shares shares); + + /** + * Checks to see if any of the sharables passed in are shared by this Shares. + * + * @param shares Shares to check for. + * @return A Set containing all of the Sharables both sets contain. + */ + Shares compare(Shares shares); + + /** + * @param sharable The Sharable you wish to set sharing for. + * @param sharing Whether to share or not. + */ + void setSharing(Sharable sharable, boolean sharing); + + /** + * @param sharables a Set of Sharables you wish to set sharing for. + * @param sharing Whether to share or not. + */ + void setSharing(Shares sharables, boolean sharing); + + /** + * @return These shares as a string list. + */ + List toStringList(); +} + diff --git a/src/main/java/org/mvplugins/multiverse/inventories/share/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/share/package-info.java new file mode 100644 index 00000000..b4eb4791 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/package-info.java @@ -0,0 +1,5 @@ +/** + * Contains all external API classes for {@link org.mvplugins.multiverse.inventories.share.Sharable}s and handling the sharing of those between worlds. + */ +package org.mvplugins.multiverse.inventories.share; + diff --git a/src/main/java/com/onarandombox/multiverseinventories/util/CommentedYamlConfiguration.java b/src/main/java/org/mvplugins/multiverse/inventories/util/CommentedYamlConfiguration.java similarity index 99% rename from src/main/java/com/onarandombox/multiverseinventories/util/CommentedYamlConfiguration.java rename to src/main/java/org/mvplugins/multiverse/inventories/util/CommentedYamlConfiguration.java index 718b7da6..78993d16 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/util/CommentedYamlConfiguration.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/util/CommentedYamlConfiguration.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/com/onarandombox/multiverseinventories/util/DeserializationException.java b/src/main/java/org/mvplugins/multiverse/inventories/util/DeserializationException.java similarity index 82% rename from src/main/java/com/onarandombox/multiverseinventories/util/DeserializationException.java rename to src/main/java/org/mvplugins/multiverse/inventories/util/DeserializationException.java index 98a978e6..64c6f695 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/util/DeserializationException.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/util/DeserializationException.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; /** * Exception thrown when something goes wrong while deserializing this plugin's objects. diff --git a/src/main/java/com/onarandombox/multiverseinventories/util/Font.java b/src/main/java/org/mvplugins/multiverse/inventories/util/Font.java similarity index 99% rename from src/main/java/com/onarandombox/multiverseinventories/util/Font.java rename to src/main/java/org/mvplugins/multiverse/inventories/util/Font.java index 71779d20..494b211d 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/util/Font.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/util/Font.java @@ -1,4 +1,4 @@ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/com/onarandombox/multiverseinventories/util/MinecraftTools.java b/src/main/java/org/mvplugins/multiverse/inventories/util/MinecraftTools.java similarity index 90% rename from src/main/java/com/onarandombox/multiverseinventories/util/MinecraftTools.java rename to src/main/java/org/mvplugins/multiverse/inventories/util/MinecraftTools.java index a79e49cb..79181301 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/util/MinecraftTools.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/util/MinecraftTools.java @@ -1,38 +1,38 @@ -package com.onarandombox.multiverseinventories.util; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -/** - * General tools to help with minecraftian things. - */ -public class MinecraftTools { - - private static final int TICKS_PER_SECOND = 20; - - private MinecraftTools() { } - - /** - * Converts an amount of seconds to the appropriate amount of ticks. - * - * @param seconds Amount of seconds to convert - * @return Ticks converted from seconds. - */ - public static long convertSecondsToTicks(long seconds) { - return seconds * TICKS_PER_SECOND; - } - - /** - * Fills an ItemStack array with air. - * - * @param items The ItemStack array to fill. - * @return The air filled ItemStack array. - */ - public static ItemStack[] fillWithAir(ItemStack[] items) { - for (int i = 0; i < items.length; i++) { - items[i] = new ItemStack(Material.AIR); - } - return items; - } -} - +package org.mvplugins.multiverse.inventories.util; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +/** + * General tools to help with minecraftian things. + */ +public class MinecraftTools { + + private static final int TICKS_PER_SECOND = 20; + + private MinecraftTools() { } + + /** + * Converts an amount of seconds to the appropriate amount of ticks. + * + * @param seconds Amount of seconds to convert + * @return Ticks converted from seconds. + */ + public static long convertSecondsToTicks(long seconds) { + return seconds * TICKS_PER_SECOND; + } + + /** + * Fills an ItemStack array with air. + * + * @param items The ItemStack array to fill. + * @return The air filled ItemStack array. + */ + public static ItemStack[] fillWithAir(ItemStack[] items) { + for (int i = 0; i < items.length; i++) { + items[i] = new ItemStack(Material.AIR); + } + return items; + } +} + diff --git a/src/main/java/com/onarandombox/multiverseinventories/util/Perm.java b/src/main/java/org/mvplugins/multiverse/inventories/util/Perm.java similarity index 95% rename from src/main/java/com/onarandombox/multiverseinventories/util/Perm.java rename to src/main/java/org/mvplugins/multiverse/inventories/util/Perm.java index 42c1be28..19a57595 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/util/Perm.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/util/Perm.java @@ -1,226 +1,226 @@ -package com.onarandombox.multiverseinventories.util; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.multiverseinventories.MultiverseInventories; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.plugin.PluginManager; - -/** - * @author dumptruckman - */ -public enum Perm { - /** - * Permission for /mvinv info. - */ - COMMAND_INFO(new Permission("multiverse.inventories.info", "Displays information about a world or group.", PermissionDefault.OP)), - /** - * Permission for /mvinv list. - */ - COMMAND_LIST(new Permission("multiverse.inventories.list", "Displays a list of groups.", PermissionDefault.OP)), - /** - * Permission for /mvinv reload. - */ - COMMAND_RELOAD(new Permission("multiverse.inventories.reload", "Reloads config file.", PermissionDefault.OP)), - /** - * Permission for /mvinv import. - */ - COMMAND_IMPORT(new Permission("multiverse.inventories.import", "Imports data from MultiInv/WorldInventories", PermissionDefault.OP)), - /** - * Permission for /mvinv group. - */ - COMMAND_GROUP(new Permission("multiverse.inventories.group", "Begins a conversation about groups.", - PermissionDefault.OP)), - /** - * Permission for /mvinv addworld. - */ - COMMAND_ADDWORLD(new Permission("multiverse.inventories.addworld", "Adds a world to a world group", - PermissionDefault.OP)), - /** - * Permission for /mvinv remvoveworld. - */ - COMMAND_RMWORLD(new Permission("multiverse.inventories.removeworld", "Removes a world from a world group", - PermissionDefault.OP)), - /** - * Permission for /mvinv addshare. - */ - COMMAND_ADDSHARES(new Permission("multiverse.inventories.addshares", "Adds share(s) to a world group", - PermissionDefault.OP)), - /** - * Permission for /mvinv rmshare. - */ - COMMAND_RMSHARES(new Permission("multiverse.inventories.removeshares", "Removes share(s) from a world group", - PermissionDefault.OP)), - /** - * Permission for /mvinv creategroup. - */ - COMMAND_CREATEGROUP(new Permission("multiverse.inventories.creategroup", "Creates a world group", - PermissionDefault.OP)), - /** - * Permission for /mvinv deletegroup. - */ - COMMAND_DELETEGROUP(new Permission("multiverse.inventories.deletegroup", "Deletes a world group", - PermissionDefault.OP)), - /** - * Permissions for /mvinv spawn. - */ - COMMAND_SPAWN(new Permission("multiverse.inventories.spawn.self", "teleport yourself to group spawn", - PermissionDefault.OP)), - /** - * Permissions for /mvinv spawn. - */ - COMMAND_SPAWN_OTHER(new Permission("multiverse.inventories.spawn.other", "teleport other to group spawn", - PermissionDefault.OP)), - /** - * Permission for debug command. - */ - COMMAND_DEBUG(new Permission("multiverse.inventories.debug", "Spams the console a bunch.", PermissionDefault.OP)), - /** - * Permission for bypassing all groups. - */ - BYPASS_GROUP_ALL(new Permission("mvinv.bypass.group.*", "", PermissionDefault.FALSE)), - /** - * Permission prefix for bypassing groups. - */ - BYPASS_GROUP("mvinv.bypass.group.") { - private String getBypassMessage(Player player, String name) { - return "Player: " + player.getName() + " has bypass perms for group: " + name; - } - }, - /** - * Permission for bypassing all worlds. - */ - BYPASS_WORLD_ALL(new Permission("mvinv.bypass.world.*", "", PermissionDefault.FALSE)), - /** - * Permission prefix for bypassing worlds. - */ - BYPASS_WORLD("mvinv.bypass.world.") { - private String getBypassMessage(Player player, String name) { - return "Player: " + player.getName() + " has bypass perms for world: " + name; - } - }, - /** - * Permission for bypassing all worlds. - */ - BYPASS_GAME_MODE_ALL(new Permission("mvinv.bypass.gamemode.*", "", PermissionDefault.FALSE)), - /** - * Permission prefix for bypassing worlds. - */ - BYPASS_GAME_MODE("mvinv.bypass.gamemode.") { - private String getBypassMessage(Player player, String name) { - return "Player: " + player.getName() + " has bypass perms for game mode: " + name; - } - }, - /** - * Permissions for bypassing all world/groups inventory handling. - */ - BYPASS_ALL(new Permission("mvinv.bypass.*", "Allows bypassing all of your groups/worlds and constantly use " - + "the same inventory", PermissionDefault.FALSE)); - - private Permission perm = null; - private String permNode = ""; - - Perm(Permission perm) { - this.perm = perm; - } - - Perm(String permNode) { - this.permNode = permNode; - } - - /** - * @return the Permission. - */ - public Permission getPermission() { - return this.perm; - } - - /** - * @return the Permission node string. - */ - public String getNode() { - return this.permNode; - } - - /** - * @param finalNode String to add to the bypass prefix. - * @return The full permission node for bypass. - */ - public Permission getBypassPermission(String finalNode) { - String bypassNode = this.getNode() + finalNode; - Logging.finer("Checking node " + bypassNode + "..."); - - Permission permission = Bukkit.getPluginManager().getPermission(bypassNode); - if (permission == null) { - permission = new Permission(bypassNode, PermissionDefault.FALSE); - switch (this) { - case BYPASS_GROUP: - permission.addParent(BYPASS_GROUP_ALL.getPermission(), true); - break; - case BYPASS_WORLD: - permission.addParent(BYPASS_WORLD_ALL.getPermission(), true); - break; - case BYPASS_GAME_MODE: - permission.addParent(BYPASS_GAME_MODE_ALL.getPermission(), true); - break; - default: - } - Bukkit.getPluginManager().addPermission(permission); - } - return permission; - } - - /** - * Checks if a player has permission to bypass something which requires a name of an object to be bypassed. - * A World name for example. - * - * @param player Player to check permission for. - * @param name Name of object to bypass. - * @return True if player is allowed to bypass. - */ - public boolean hasBypass(Player player, String name) { - if (inventories != null && !inventories.getMVIConfig().isUsingBypass()) { - return false; - } - Permission bypassPerm = this.getBypassPermission(name); - boolean hasBypass = player.hasPermission(bypassPerm); - if (hasBypass) { - Logging.fine("Player: " + player.getName() + " in World: " + player.getWorld().getName() - + " has permission: " + bypassPerm.getName() + "(Default: " - + bypassPerm.getDefault().toString() + ")!"); - } - return hasBypass; - } - - /** - * Checks if the sender has the node in question. - * - * @param sender CommandSender to check permission for. - * @return True if sender has the permission. - */ - public boolean has(CommandSender sender) { - return sender.hasPermission(perm); - } - - private static MultiverseInventories inventories = null; - - /** - * Registers all Permission to the plugin. - * - * @param plugin Plugin to register permissions to. - */ - public static void register(MultiverseInventories plugin) { - inventories = plugin; - BYPASS_WORLD_ALL.getPermission().addParent(BYPASS_ALL.getPermission(), true); - BYPASS_GROUP_ALL.getPermission().addParent(BYPASS_ALL.getPermission(), true); - PluginManager pm = plugin.getServer().getPluginManager(); - for (Perm perm : Perm.values()) { - if (perm.getPermission() != null) { - pm.addPermission(perm.getPermission()); - } - } - } -} +package org.mvplugins.multiverse.inventories.util; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.inventories.MultiverseInventories; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; +import org.bukkit.plugin.PluginManager; + +/** + * @author dumptruckman + */ +public enum Perm { + /** + * Permission for /mvinv info. + */ + COMMAND_INFO(new Permission("multiverse.inventories.info", "Displays information about a world or group.", PermissionDefault.OP)), + /** + * Permission for /mvinv list. + */ + COMMAND_LIST(new Permission("multiverse.inventories.list", "Displays a list of groups.", PermissionDefault.OP)), + /** + * Permission for /mvinv reload. + */ + COMMAND_RELOAD(new Permission("multiverse.inventories.reload", "Reloads config file.", PermissionDefault.OP)), + /** + * Permission for /mvinv import. + */ + COMMAND_IMPORT(new Permission("multiverse.inventories.import", "Imports data from MultiInv/WorldInventories", PermissionDefault.OP)), + /** + * Permission for /mvinv group. + */ + COMMAND_GROUP(new Permission("multiverse.inventories.group", "Begins a conversation about groups.", + PermissionDefault.OP)), + /** + * Permission for /mvinv addworld. + */ + COMMAND_ADDWORLD(new Permission("multiverse.inventories.addworld", "Adds a world to a world group", + PermissionDefault.OP)), + /** + * Permission for /mvinv remvoveworld. + */ + COMMAND_RMWORLD(new Permission("multiverse.inventories.removeworld", "Removes a world from a world group", + PermissionDefault.OP)), + /** + * Permission for /mvinv addshare. + */ + COMMAND_ADDSHARES(new Permission("multiverse.inventories.addshares", "Adds share(s) to a world group", + PermissionDefault.OP)), + /** + * Permission for /mvinv rmshare. + */ + COMMAND_RMSHARES(new Permission("multiverse.inventories.removeshares", "Removes share(s) from a world group", + PermissionDefault.OP)), + /** + * Permission for /mvinv creategroup. + */ + COMMAND_CREATEGROUP(new Permission("multiverse.inventories.creategroup", "Creates a world group", + PermissionDefault.OP)), + /** + * Permission for /mvinv deletegroup. + */ + COMMAND_DELETEGROUP(new Permission("multiverse.inventories.deletegroup", "Deletes a world group", + PermissionDefault.OP)), + /** + * Permissions for /mvinv spawn. + */ + COMMAND_SPAWN(new Permission("multiverse.inventories.spawn.self", "teleport yourself to group spawn", + PermissionDefault.OP)), + /** + * Permissions for /mvinv spawn. + */ + COMMAND_SPAWN_OTHER(new Permission("multiverse.inventories.spawn.other", "teleport other to group spawn", + PermissionDefault.OP)), + /** + * Permission for debug command. + */ + COMMAND_DEBUG(new Permission("multiverse.inventories.debug", "Spams the console a bunch.", PermissionDefault.OP)), + /** + * Permission for bypassing all groups. + */ + BYPASS_GROUP_ALL(new Permission("mvinv.bypass.group.*", "", PermissionDefault.FALSE)), + /** + * Permission prefix for bypassing groups. + */ + BYPASS_GROUP("mvinv.bypass.group.") { + private String getBypassMessage(Player player, String name) { + return "Player: " + player.getName() + " has bypass perms for group: " + name; + } + }, + /** + * Permission for bypassing all worlds. + */ + BYPASS_WORLD_ALL(new Permission("mvinv.bypass.world.*", "", PermissionDefault.FALSE)), + /** + * Permission prefix for bypassing worlds. + */ + BYPASS_WORLD("mvinv.bypass.world.") { + private String getBypassMessage(Player player, String name) { + return "Player: " + player.getName() + " has bypass perms for world: " + name; + } + }, + /** + * Permission for bypassing all worlds. + */ + BYPASS_GAME_MODE_ALL(new Permission("mvinv.bypass.gamemode.*", "", PermissionDefault.FALSE)), + /** + * Permission prefix for bypassing worlds. + */ + BYPASS_GAME_MODE("mvinv.bypass.gamemode.") { + private String getBypassMessage(Player player, String name) { + return "Player: " + player.getName() + " has bypass perms for game mode: " + name; + } + }, + /** + * Permissions for bypassing all world/groups inventory handling. + */ + BYPASS_ALL(new Permission("mvinv.bypass.*", "Allows bypassing all of your groups/worlds and constantly use " + + "the same inventory", PermissionDefault.FALSE)); + + private Permission perm = null; + private String permNode = ""; + + Perm(Permission perm) { + this.perm = perm; + } + + Perm(String permNode) { + this.permNode = permNode; + } + + /** + * @return the Permission. + */ + public Permission getPermission() { + return this.perm; + } + + /** + * @return the Permission node string. + */ + public String getNode() { + return this.permNode; + } + + /** + * @param finalNode String to add to the bypass prefix. + * @return The full permission node for bypass. + */ + public Permission getBypassPermission(String finalNode) { + String bypassNode = this.getNode() + finalNode; + Logging.finer("Checking node " + bypassNode + "..."); + + Permission permission = Bukkit.getPluginManager().getPermission(bypassNode); + if (permission == null) { + permission = new Permission(bypassNode, PermissionDefault.FALSE); + switch (this) { + case BYPASS_GROUP: + permission.addParent(BYPASS_GROUP_ALL.getPermission(), true); + break; + case BYPASS_WORLD: + permission.addParent(BYPASS_WORLD_ALL.getPermission(), true); + break; + case BYPASS_GAME_MODE: + permission.addParent(BYPASS_GAME_MODE_ALL.getPermission(), true); + break; + default: + } + Bukkit.getPluginManager().addPermission(permission); + } + return permission; + } + + /** + * Checks if a player has permission to bypass something which requires a name of an object to be bypassed. + * A World name for example. + * + * @param player Player to check permission for. + * @param name Name of object to bypass. + * @return True if player is allowed to bypass. + */ + public boolean hasBypass(Player player, String name) { + if (inventories != null && !inventories.getMVIConfig().isUsingBypass()) { + return false; + } + Permission bypassPerm = this.getBypassPermission(name); + boolean hasBypass = player.hasPermission(bypassPerm); + if (hasBypass) { + Logging.fine("Player: " + player.getName() + " in World: " + player.getWorld().getName() + + " has permission: " + bypassPerm.getName() + "(Default: " + + bypassPerm.getDefault().toString() + ")!"); + } + return hasBypass; + } + + /** + * Checks if the sender has the node in question. + * + * @param sender CommandSender to check permission for. + * @return True if sender has the permission. + */ + public boolean has(CommandSender sender) { + return sender.hasPermission(perm); + } + + private static MultiverseInventories inventories = null; + + /** + * Registers all Permission to the plugin. + * + * @param plugin Plugin to register permissions to. + */ + public static void register(MultiverseInventories plugin) { + inventories = plugin; + BYPASS_WORLD_ALL.getPermission().addParent(BYPASS_ALL.getPermission(), true); + BYPASS_GROUP_ALL.getPermission().addParent(BYPASS_ALL.getPermission(), true); + PluginManager pm = plugin.getServer().getPluginManager(); + for (Perm perm : Perm.values()) { + if (perm.getPermission() != null) { + pm.addPermission(perm.getPermission()); + } + } + } +} diff --git a/src/main/java/org/mvplugins/multiverse/inventories/util/package-info.java b/src/main/java/org/mvplugins/multiverse/inventories/util/package-info.java new file mode 100644 index 00000000..ec546d9e --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/inventories/util/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains utility classes. + */ +package org.mvplugins.multiverse.inventories.util; + diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f49dcf43..936ac5a2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,108 +1,7 @@ name: Multiverse-Inventories -main: com.onarandombox.multiverseinventories.MultiverseInventories +main: org.mvplugins.multiverse.inventories.MultiverseInventories version: ${version} api-version: 1.13 -authors: ['dumptruckman'] +authors: ['dumptruckman', 'benwoo1110'] depend: ['Multiverse-Core'] -softdepend: [MultiInv, WorldInventories, Multiverse-Adventure] - -commands: - mvinv: - description: Generic Multiverse-Inventories Command - usage: / - mvinvinfo: - description: Generic Multiverse-Inventories Command - usage: / - mvinvi: - description: Generic Multiverse-Inventories Command - usage: / - mvinvim: - description: Generic Multiverse-Inventories Command - usage: / - mvinvimport: - description: Generic Multiverse-Inventories Command - usage: / - mvinvlist: - description: Generic Multiverse-Inventories Command - usage: / - mvinvl: - description: Generic Multiverse-Inventories Command - usage: / - mvinvreload: - description: Generic Multiverse-Inventories Command - usage: / - mvinvaddshares: - description: Generic Multiverse-Inventories Command - usage: / - mvinvadds: - description: Generic Multiverse-Inventories Command - usage: / - mvinvas: - description: Generic Multiverse-Inventories Command - usage: / - mvinvraddshare: - description: Generic Multiverse-Inventories Command - usage: / - mvinvaddworld: - description: Generic Multiverse-Inventories Command - usage: / - mvinvaddw: - description: Generic Multiverse-Inventories Command - usage: / - mvinvaw: - description: Generic Multiverse-Inventories Command - usage: / - mvinvremoveshares: - description: Generic Multiverse-Inventories Command - usage: / - mvinvremoveshare: - description: Generic Multiverse-Inventories Command - usage: / - mvinvremoves: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrmshares: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrmshare: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrms: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrs: - description: Generic Multiverse-Inventories Command - usage: / - mvinvremoveworld: - description: Generic Multiverse-Inventories Command - usage: / - mvinvremovew: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrmworld: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrmw: - description: Generic Multiverse-Inventories Command - usage: / - mvinvrw: - description: Generic Multiverse-Inventories Command - usage: / - mvinvspawn: - description: Generic Multiverse-Inventories Command - usage: / - mvinvs: - description: Generic Multiverse-Inventories Command - usage: / - ispawn: - description: Generic Multiverse-Inventories Command - usage: / - gspawn: - description: Generic Multiverse-Inventories Command - usage: / - mvinvdebug: - description: Generic Multiverse-Inventories Command - usage: / - mvinvd: - description: Generic Multiverse-Inventories Command - usage: / +softdepend: [MultiInv, WorldInventories] diff --git a/src/test/java/com/onarandombox/multiverseinventories/FlatFileDataHelper.java b/src/test/java/org/mvplugins/multiverse/inventories/FlatFileDataHelper.java similarity index 72% rename from src/test/java/com/onarandombox/multiverseinventories/FlatFileDataHelper.java rename to src/test/java/org/mvplugins/multiverse/inventories/FlatFileDataHelper.java index 85f1ba43..07f8e31c 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/FlatFileDataHelper.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/FlatFileDataHelper.java @@ -1,23 +1,23 @@ -package com.onarandombox.multiverseinventories; - -import com.onarandombox.multiverseinventories.profile.ProfileDataSource; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; - -import java.io.File; -import java.io.IOException; - -public class FlatFileDataHelper { - - private final FlatFileProfileDataSource data; - - public FlatFileDataHelper(ProfileDataSource data) { - if (!(data instanceof FlatFileProfileDataSource)) { - throw new ClassCastException("Must be instance of FlatFilePlayerData"); - } - this.data = (FlatFileProfileDataSource) data; - } - - public File getPlayerFile(ContainerType type, String dataName, String playerName) throws IOException { - return data.getPlayerFile(type, dataName, playerName); - } -} +package org.mvplugins.multiverse.inventories; + +import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; + +import java.io.File; +import java.io.IOException; + +public class FlatFileDataHelper { + + private final FlatFileProfileDataSource data; + + public FlatFileDataHelper(ProfileDataSource data) { + if (!(data instanceof FlatFileProfileDataSource)) { + throw new ClassCastException("Must be instance of FlatFilePlayerData"); + } + this.data = (FlatFileProfileDataSource) data; + } + + public File getPlayerFile(ContainerType type, String dataName, String playerName) throws IOException { + return data.getPlayerFile(type, dataName, playerName); + } +} diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestCommands.java b/src/test/java/org/mvplugins/multiverse/inventories/TestCommands.java similarity index 97% rename from src/test/java/com/onarandombox/multiverseinventories/TestCommands.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestCommands.java index 5be18d5e..1218cb3f 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestCommands.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestCommands.java @@ -5,10 +5,10 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.util.TestInstanceCreator; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.util.TestInstanceCreator; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestCommentedYamlConfiguration.java b/src/test/java/org/mvplugins/multiverse/inventories/TestCommentedYamlConfiguration.java similarity index 97% rename from src/test/java/com/onarandombox/multiverseinventories/TestCommentedYamlConfiguration.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestCommentedYamlConfiguration.java index 04b489f5..5a10dc48 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestCommentedYamlConfiguration.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestCommentedYamlConfiguration.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.util.CommentedYamlConfiguration; +import org.mvplugins.multiverse.inventories.util.CommentedYamlConfiguration; import org.junit.Test; import java.io.File; diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestPerformance.java b/src/test/java/org/mvplugins/multiverse/inventories/TestPerformance.java similarity index 97% rename from src/test/java/com/onarandombox/multiverseinventories/TestPerformance.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestPerformance.java index 60afbc57..3612b514 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestPerformance.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestPerformance.java @@ -1,10 +1,10 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.event.ShareHandlingEvent; -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.util.TestInstanceCreator; +import org.mvplugins.multiverse.inventories.event.ShareHandlingEvent; +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.util.TestInstanceCreator; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestPlayerNameChange.java b/src/test/java/org/mvplugins/multiverse/inventories/TestPlayerNameChange.java similarity index 96% rename from src/test/java/com/onarandombox/multiverseinventories/TestPlayerNameChange.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestPlayerNameChange.java index f33bdf31..1c16ff52 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestPlayerNameChange.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestPlayerNameChange.java @@ -1,8 +1,8 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; -import com.onarandombox.multiverseinventories.profile.GlobalProfile; -import com.onarandombox.multiverseinventories.util.MockPlayerFactory; -import com.onarandombox.multiverseinventories.util.TestInstanceCreator; +import org.mvplugins.multiverse.inventories.profile.GlobalProfile; +import org.mvplugins.multiverse.inventories.util.MockPlayerFactory; +import org.mvplugins.multiverse.inventories.util.TestInstanceCreator; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestResetWorld.java b/src/test/java/org/mvplugins/multiverse/inventories/TestResetWorld.java similarity index 97% rename from src/test/java/com/onarandombox/multiverseinventories/TestResetWorld.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestResetWorld.java index a55e38ed..2beb4a78 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestResetWorld.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestResetWorld.java @@ -1,7 +1,7 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.onarandombox.MultiverseAdventure.event.MVAResetFinishedEvent; -import com.onarandombox.multiverseinventories.util.TestInstanceCreator; +import org.mvplugins.multiverse.inventories.util.TestInstanceCreator; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestWSharableAPI.java b/src/test/java/org/mvplugins/multiverse/inventories/TestWSharableAPI.java similarity index 95% rename from src/test/java/com/onarandombox/multiverseinventories/TestWSharableAPI.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestWSharableAPI.java index ac44ae38..3dbd0338 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestWSharableAPI.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestWSharableAPI.java @@ -1,11 +1,11 @@ -package com.onarandombox.multiverseinventories; - -import com.onarandombox.multiverseinventories.profile.PlayerProfile; -import com.onarandombox.multiverseinventories.share.ProfileEntry; -import com.onarandombox.multiverseinventories.share.Sharable; -import com.onarandombox.multiverseinventories.share.SharableHandler; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.util.TestInstanceCreator; +package org.mvplugins.multiverse.inventories; + +import org.mvplugins.multiverse.inventories.profile.PlayerProfile; +import org.mvplugins.multiverse.inventories.share.ProfileEntry; +import org.mvplugins.multiverse.inventories.share.Sharable; +import org.mvplugins.multiverse.inventories.share.SharableHandler; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.util.TestInstanceCreator; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.command.Command; diff --git a/src/test/java/com/onarandombox/multiverseinventories/TestWorldChanged.java b/src/test/java/org/mvplugins/multiverse/inventories/TestWorldChanged.java similarity index 98% rename from src/test/java/com/onarandombox/multiverseinventories/TestWorldChanged.java rename to src/test/java/org/mvplugins/multiverse/inventories/TestWorldChanged.java index 4c17bbf6..026ea1c4 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/TestWorldChanged.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/TestWorldChanged.java @@ -1,10 +1,10 @@ -package com.onarandombox.multiverseinventories; +package org.mvplugins.multiverse.inventories; import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; -import com.onarandombox.multiverseinventories.profile.container.ContainerType; -import com.onarandombox.multiverseinventories.share.Sharables; -import com.onarandombox.multiverseinventories.share.Shares; -import com.onarandombox.multiverseinventories.util.TestInstanceCreator; +import org.mvplugins.multiverse.inventories.profile.container.ContainerType; +import org.mvplugins.multiverse.inventories.share.Sharables; +import org.mvplugins.multiverse.inventories.share.Shares; +import org.mvplugins.multiverse.inventories.util.TestInstanceCreator; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/MVTestLogFormatter.java b/src/test/java/org/mvplugins/multiverse/inventories/util/MVTestLogFormatter.java similarity index 96% rename from src/test/java/com/onarandombox/multiverseinventories/util/MVTestLogFormatter.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/MVTestLogFormatter.java index b568f14d..7a234a98 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/MVTestLogFormatter.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/MVTestLogFormatter.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/MockItemMeta.java b/src/test/java/org/mvplugins/multiverse/inventories/util/MockItemMeta.java similarity index 98% rename from src/test/java/com/onarandombox/multiverseinventories/util/MockItemMeta.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/MockItemMeta.java index b8e0b3ab..76c50097 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/MockItemMeta.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/MockItemMeta.java @@ -4,7 +4,7 @@ * For more information please check the README.md file included * * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import org.bukkit.Material; import org.bukkit.inventory.ItemFactory; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/MockPlayerFactory.java b/src/test/java/org/mvplugins/multiverse/inventories/util/MockPlayerFactory.java similarity index 98% rename from src/test/java/com/onarandombox/multiverseinventories/util/MockPlayerFactory.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/MockPlayerFactory.java index cd838ffe..a113d0ff 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/MockPlayerFactory.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/MockPlayerFactory.java @@ -5,9 +5,9 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; -import com.onarandombox.multiverseinventories.PlayerStats; +import org.mvplugins.multiverse.inventories.PlayerStats; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.entity.Player; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/MockPlayerInventory.java b/src/test/java/org/mvplugins/multiverse/inventories/util/MockPlayerInventory.java similarity index 98% rename from src/test/java/com/onarandombox/multiverseinventories/util/MockPlayerInventory.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/MockPlayerInventory.java index e178feab..55d06252 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/MockPlayerInventory.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/MockPlayerInventory.java @@ -1,6 +1,6 @@ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; -import com.onarandombox.multiverseinventories.PlayerStats; +import org.mvplugins.multiverse.inventories.PlayerStats; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/MockWorldFactory.java b/src/test/java/org/mvplugins/multiverse/inventories/util/MockWorldFactory.java similarity index 99% rename from src/test/java/com/onarandombox/multiverseinventories/util/MockWorldFactory.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/MockWorldFactory.java index 3dee7cbb..6356fe87 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/MockWorldFactory.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/MockWorldFactory.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java b/src/test/java/org/mvplugins/multiverse/inventories/util/TestInstanceCreator.java similarity index 99% rename from src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/TestInstanceCreator.java index 7552c09b..3740c644 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/TestInstanceCreator.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/TestInstanceCreator.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; @@ -15,8 +15,8 @@ import com.onarandombox.MultiverseCore.utils.FileUtils; import com.onarandombox.MultiverseCore.utils.TestingMode; import com.onarandombox.MultiverseCore.world.SimpleMVWorldManager; -import com.onarandombox.multiverseinventories.InventoriesListener; -import com.onarandombox.multiverseinventories.MultiverseInventories; +import org.mvplugins.multiverse.inventories.InventoriesListener; +import org.mvplugins.multiverse.inventories.MultiverseInventories; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/Util.java b/src/test/java/org/mvplugins/multiverse/inventories/util/Util.java similarity index 97% rename from src/test/java/com/onarandombox/multiverseinventories/util/Util.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/Util.java index 90f4fea0..e690c05e 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/Util.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/Util.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import com.dumptruckman.minecraft.util.Logging; diff --git a/src/test/java/com/onarandombox/multiverseinventories/util/WorldCreatorMatcher.java b/src/test/java/org/mvplugins/multiverse/inventories/util/WorldCreatorMatcher.java similarity index 97% rename from src/test/java/com/onarandombox/multiverseinventories/util/WorldCreatorMatcher.java rename to src/test/java/org/mvplugins/multiverse/inventories/util/WorldCreatorMatcher.java index e60c1476..0b91bf3b 100644 --- a/src/test/java/com/onarandombox/multiverseinventories/util/WorldCreatorMatcher.java +++ b/src/test/java/org/mvplugins/multiverse/inventories/util/WorldCreatorMatcher.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.multiverseinventories.util; +package org.mvplugins.multiverse.inventories.util; import org.bukkit.WorldCreator; import org.mockito.ArgumentMatcher;