mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-02-12 13:01:32 +01:00
Fixed loot chests not loading. Requires latest ML
This commit is contained in:
parent
cb92620b1b
commit
62e1ace7b5
@ -11,6 +11,7 @@ import io.lumine.mythic.lib.skill.SimpleSkill;
|
||||
import io.lumine.mythic.lib.skill.Skill;
|
||||
import io.lumine.mythic.lib.skill.handler.MythicLibSkillHandler;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import io.lumine.mythic.lib.util.PostLoadAction;
|
||||
import io.lumine.mythic.lib.util.PreloadedObject;
|
||||
import io.lumine.mythic.lib.version.VParticle;
|
||||
@ -33,7 +34,6 @@ import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||
import net.Indyuce.mmocore.skill.binding.SkillSlot;
|
||||
import net.Indyuce.mmocore.skill.cast.ComboMap;
|
||||
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -1,23 +1,13 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.command.api.CommandTreeNode;
|
||||
import io.lumine.mythic.lib.data.DataExport;
|
||||
import io.lumine.mythic.lib.data.sql.SQLDataSource;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.data.sql.SQLDataHandler;
|
||||
import net.Indyuce.mmocore.manager.data.yaml.YAMLPlayerDataHandler;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This command allows to transfer data from your actual storage type
|
||||
@ -28,84 +18,15 @@ public class ExportDataTreeNode extends CommandTreeNode {
|
||||
super(parent, "exportdata");
|
||||
}
|
||||
|
||||
/**
|
||||
* Amount of requests generated every batch
|
||||
*/
|
||||
private static final int BATCH_AMOUNT = 50;
|
||||
|
||||
/**
|
||||
* Period in ticks
|
||||
*/
|
||||
private static final int BATCH_PERIOD = 20;
|
||||
|
||||
private static final DecimalFormat decFormat = new DecimalFormat("0.#");
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CommandResult execute(CommandSender sender, String[] strings) {
|
||||
|
||||
if (!MMOCore.plugin.playerDataManager.getLoaded().isEmpty()) {
|
||||
sender.sendMessage("Please make sure no players are logged in when using this command. " +
|
||||
"If you are still seeing this message, restart your server and execute this command before any player logs in.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
// Export YAML to SQL
|
||||
final boolean result = new DataExport<>(MMOCore.plugin.playerDataManager, sender).start(
|
||||
() -> new YAMLPlayerDataHandler(MMOCore.plugin),
|
||||
() -> new SQLDataHandler(new SQLDataSource(MMOCore.plugin)));
|
||||
|
||||
final List<UUID> playerIds = Arrays.stream(new File(MMOCore.plugin.getDataFolder() + "/userdata").listFiles())
|
||||
.map(file -> UUID.fromString(file.getName().replace(".yml", "")))
|
||||
.toList();
|
||||
|
||||
// Initialize fake SQL & YAML data provider
|
||||
final SQLDataHandler sqlHandler;
|
||||
final YAMLPlayerDataHandler ymlHandler;
|
||||
try {
|
||||
sqlHandler = new SQLDataHandler(new SQLDataSource(MMOCore.plugin));
|
||||
ymlHandler = new YAMLPlayerDataHandler(MMOCore.plugin);
|
||||
} catch (RuntimeException exception) {
|
||||
sender.sendMessage("Could not initialize SQL/YAML provider (see console for stack trace): " + exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
final double timeEstimation = (double) playerIds.size() / BATCH_AMOUNT * BATCH_PERIOD / 20;
|
||||
sender.sendMessage("Exporting " + playerIds.size() + " player data(s).. See console for details");
|
||||
sender.sendMessage("Minimum expected time: " + decFormat.format(timeEstimation) + "s");
|
||||
|
||||
// Save player data
|
||||
new BukkitRunnable() {
|
||||
int errorCount = 0;
|
||||
int batchCounter = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < BATCH_AMOUNT; i++) {
|
||||
final int index = BATCH_AMOUNT * batchCounter + i;
|
||||
|
||||
/*
|
||||
* Saving is done. Close connection to avoid memory
|
||||
* leaks and ouput the results to the command executor
|
||||
*/
|
||||
if (index >= playerIds.size()) {
|
||||
cancel();
|
||||
|
||||
sqlHandler.close();
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Exported " + playerIds.size() + " player datas to SQL database. Total errors: " + errorCount);
|
||||
return;
|
||||
}
|
||||
|
||||
final UUID playerId = playerIds.get(index);
|
||||
try {
|
||||
final PlayerData offlinePlayerData = new PlayerData(new MMOPlayerData(playerId));
|
||||
ymlHandler.loadData(offlinePlayerData);
|
||||
sqlHandler.saveData(offlinePlayerData, false);
|
||||
} catch (RuntimeException exception) {
|
||||
errorCount++;
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
batchCounter++;
|
||||
}
|
||||
}.runTaskTimerAsynchronously(MMOCore.plugin, 0, BATCH_PERIOD);
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
return result ? CommandResult.SUCCESS : CommandResult.FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.api.player.attribute.MMOCoreAttributeStatHandler;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -14,7 +13,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AttributeManager implements MMOCoreManager {
|
||||
private final Map<String, PlayerAttribute> map = new HashMap<>();
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.*;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.api.ConfigMessage;
|
||||
@ -8,7 +9,6 @@ import net.Indyuce.mmocore.api.util.input.ChatInput;
|
||||
import net.Indyuce.mmocore.api.util.input.PlayerInput;
|
||||
import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType;
|
||||
import net.Indyuce.mmocore.command.api.CommandVerbose;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -18,7 +18,6 @@ import org.bukkit.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.experience.ExpCurve;
|
||||
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.loot.chest.LootChest;
|
||||
import net.Indyuce.mmocore.loot.chest.LootChestRegion;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import net.Indyuce.mmocore.util.HashableLocation;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -69,7 +68,7 @@ public class LootChestManager implements MMOCoreManager {
|
||||
}
|
||||
|
||||
FileUtils.loadObjectsFromFolder(MMOCore.plugin, "loot-chests", false, (key, config) -> {
|
||||
LootChestRegion region = new LootChestRegion(config.getConfigurationSection(key));
|
||||
LootChestRegion region = new LootChestRegion(config);
|
||||
regions.put(region.getId(), region);
|
||||
}, "Could not load loot chest region '%s' from file '%s': %s");
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.quest.Quest;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -3,13 +3,13 @@ package net.Indyuce.mmocore.manager;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.skill.handler.SkillHandler;
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||
import net.Indyuce.mmocore.skill.list.Ambers;
|
||||
import net.Indyuce.mmocore.skill.list.Neptune_Gift;
|
||||
import net.Indyuce.mmocore.skill.list.Sneaky_Picky;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.manager.registry.MMOCoreRegister;
|
||||
import net.Indyuce.mmocore.skilltree.ParentType;
|
||||
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
||||
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -1,8 +1,7 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import net.Indyuce.mmocore.waypoint.Waypoint;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.Indyuce.mmocore.manager.profession;
|
||||
|
||||
import io.lumine.mythic.lib.util.FileUtils;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||
import net.Indyuce.mmocore.util.FileUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,138 +0,0 @@
|
||||
package net.Indyuce.mmocore.util;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static <T> void iterateConfigSectionList(@NotNull ConfigurationSection config,
|
||||
@NotNull List<T> list,
|
||||
@NotNull Function<ConfigurationSection, T> subconfigHandler,
|
||||
@NotNull Function<Integer, T> fill,
|
||||
@NotNull BiConsumer<String, RuntimeException> errorHandler) {
|
||||
int expectedOrdinal = 1;
|
||||
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
final int index = Integer.parseInt(key);
|
||||
final ConfigurationSection subconfig = config.getConfigurationSection(key);
|
||||
Validate.notNull(subconfig, "Not a configuration section");
|
||||
|
||||
// Replace
|
||||
if (index < expectedOrdinal) list.set(index, subconfigHandler.apply(subconfig));
|
||||
else {
|
||||
while (expectedOrdinal < index)
|
||||
list.add(fill.apply(expectedOrdinal++));
|
||||
list.add(subconfigHandler.apply(subconfig));
|
||||
expectedOrdinal++;
|
||||
}
|
||||
|
||||
} catch (RuntimeException exception) {
|
||||
errorHandler.accept(key, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadObjectsFromFolder(@NotNull Plugin plugin,
|
||||
@NotNull String path,
|
||||
boolean singleObject,
|
||||
@NotNull BiConsumer<String, ConfigurationSection> action,
|
||||
@NotNull String errorMessageFormat) {
|
||||
|
||||
// Action to perform
|
||||
final Consumer<File> fileAction = file -> {
|
||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
if (singleObject) try {
|
||||
final String name = file.getName().substring(0, file.getName().length() - 4);
|
||||
action.accept(name, config);
|
||||
} catch (Throwable throwable) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, errorMessageFormat.formatted(file.getName(), throwable.getMessage()));
|
||||
}
|
||||
else for (String key : config.getKeys(false))
|
||||
try {
|
||||
action.accept(key, config.getConfigurationSection(key));
|
||||
} catch (Throwable throwable) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, errorMessageFormat.formatted(key, file.getName(), throwable.getMessage()));
|
||||
}
|
||||
};
|
||||
|
||||
// Perform on all paths
|
||||
exploreFolderRecursively(getFile(plugin, path), fileAction);
|
||||
}
|
||||
|
||||
public static void loadObjectsFromFolderRaw(@NotNull Plugin plugin,
|
||||
@NotNull String path,
|
||||
@NotNull Consumer<File> action,
|
||||
@NotNull String errorMessageFormat) {
|
||||
|
||||
// Action to perform
|
||||
final Consumer<File> fileAction = file -> {
|
||||
try {
|
||||
action.accept(file);
|
||||
} catch (Throwable throwable) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, errorMessageFormat.formatted(file.getName(), throwable.getMessage()));
|
||||
}
|
||||
};
|
||||
|
||||
// Perform on all paths
|
||||
exploreFolderRecursively(getFile(plugin, path), fileAction);
|
||||
}
|
||||
|
||||
private static void exploreFolderRecursively(@Nullable File file, @NotNull Consumer<File> action) {
|
||||
if (!file.exists()) return;
|
||||
if (file.isFile()) action.accept(file);
|
||||
else Arrays.stream(file.listFiles()).sorted().forEach(subfile -> exploreFolderRecursively(subfile, action));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File getFile(@NotNull Plugin plugin, @NotNull String path) {
|
||||
return new File(plugin.getDataFolder() + "/" + path);
|
||||
}
|
||||
|
||||
public static boolean moveIfExists(@NotNull Plugin plugin,
|
||||
@NotNull String filePath,
|
||||
@NotNull String newFolderPath) {
|
||||
final File existing = getFile(plugin, filePath);
|
||||
final boolean result = existing.exists();
|
||||
if (result) {
|
||||
final String fullPath = newFolderPath + "/" + filePath;
|
||||
mkdirFolders(plugin, fullPath);
|
||||
Validate.isTrue(existing.renameTo(getFile(plugin, fullPath)), "Could not move '%s' to '%s'".formatted(filePath, newFolderPath));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void mkdirFolders(@NotNull Plugin plugin, @NotNull String fullPath) {
|
||||
String currentPath = "";
|
||||
final String[] subpaths = fullPath.split("/");
|
||||
for (int i = 0; i < subpaths.length - 1; i++) {
|
||||
currentPath += "/" + subpaths[i];
|
||||
getFile(plugin, currentPath).mkdir();
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyDefaultFile(@NotNull Plugin plugin, @NotNull String path) {
|
||||
mkdirFolders(plugin, path);
|
||||
|
||||
final File file = new File(plugin.getDataFolder(), path);
|
||||
if (!file.exists()) try {
|
||||
Files.copy(MMOCore.plugin.getResource("default/" + path), file.getAbsoluteFile().toPath());
|
||||
} catch (Throwable throwable) {
|
||||
throw new RuntimeException("Could not load default file '" + path + "'", throwable);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user