Fixed a bug with '/mmocore admin exportdata'

This commit is contained in:
Jules 2024-04-25 19:49:48 -07:00
parent 7593226610
commit be62d73fcb
14 changed files with 35 additions and 32 deletions

View File

@ -157,7 +157,7 @@ public class MMOCore extends MMOPlugin {
}
if (getConfig().isConfigurationSection("default-playerdata"))
dataProvider.getDataManager().loadDefaultData(getConfig().getConfigurationSection("default-playerdata"));
playerDataManager.loadDefaultData(getConfig().getConfigurationSection("default-playerdata"));
if (Bukkit.getPluginManager().getPlugin("Vault") != null) economy = new VaultEconomy();
@ -262,7 +262,7 @@ public class MMOCore extends MMOPlugin {
playerDataManager.initialize(EventPriority.LOW, EventPriority.NORMAL);
// load guild data after loading player data
dataProvider.getGuildManager().load();
nativeGuildManager.load();
// Toggleable Commands
ToggleableCommand.register();
@ -277,8 +277,8 @@ public class MMOCore extends MMOPlugin {
public void onDisable() {
// Save guild info
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
for (Guild guild : nativeGuildManager.getAll())
nativeGuildManager.save(guild);
// Close player data manager
playerDataManager.close();

View File

@ -1293,7 +1293,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
}
public static PlayerData get(@NotNull UUID uuid) {
return MMOCore.plugin.dataProvider.getDataManager().get(uuid);
return MMOCore.plugin.playerDataManager.get(uuid);
}
/**
@ -1325,10 +1325,10 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
* @return If player data for that player is loaded
*/
public static boolean has(UUID uuid) {
return MMOCore.plugin.dataProvider.getDataManager().isLoaded(uuid);
return MMOCore.plugin.playerDataManager.isLoaded(uuid);
}
public static Collection<PlayerData> getAll() {
return MMOCore.plugin.dataProvider.getDataManager().getLoaded();
return MMOCore.plugin.playerDataManager.getLoaded();
}
}

View File

@ -49,7 +49,7 @@ public class GuildCommand extends RegisteredCommand {
final Request req = MMOCore.plugin.requestManager.getRequest(uuid);
Validate.isTrue(!req.isTimedOut() && req instanceof GuildInvite);
invite = (GuildInvite) req;
Validate.isTrue(MMOCore.plugin.dataProvider.getGuildManager().isRegistered(invite.getGuild()));
Validate.isTrue(MMOCore.plugin.nativeGuildManager.isRegistered(invite.getGuild()));
} catch (Exception exception) {
return true;
}

View File

@ -52,7 +52,7 @@ public class ClassCommandTreeNode extends CommandTreeNode {
return CommandResult.SUCCESS;
(data.hasSavedClass(profess) ? data.getClassInfo(profess)
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, data);
: new SavedClassInformation(MMOCore.plugin.playerDataManager.getDefaultData())).load(profess, data);
if (data.isOnline()) {
ConfigMessage.fromKey("class-select", "class", profess.getName()).send(data.getPlayer());
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1);

View File

@ -6,6 +6,7 @@ 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;
@ -42,21 +43,25 @@ public class ExportDataTreeNode extends CommandTreeNode {
@Override
public CommandResult execute(CommandSender sender, String[] strings) {
if (!MMOCore.plugin.dataProvider.getDataManager().getLoaded().isEmpty()) {
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;
}
final List<UUID> playerIds = Arrays.stream(new File(MMOCore.plugin.getDataFolder() + "/userdata").listFiles())
.map(file -> UUID.fromString(file.getName().replace(".yml", ""))).collect(Collectors.toList());
.map(file -> UUID.fromString(file.getName().replace(".yml", "")))
.toList();
// Initialize fake SQL data provider
// 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 provider (see console for stack trace): " + exception.getMessage());
sender.sendMessage("Could not initialize SQL/YAML provider (see console for stack trace): " + exception.getMessage());
exception.printStackTrace();
return CommandResult.FAILURE;
}
@ -89,9 +94,7 @@ public class ExportDataTreeNode extends CommandTreeNode {
final UUID playerId = playerIds.get(index);
try {
final PlayerData offlinePlayerData = new PlayerData(new MMOPlayerData(playerId));
MMOCore.plugin.dataProvider.getDataManager().getDataHandler().loadData(offlinePlayerData);
// Player data is loaded, now it gets saved through SQL
ymlHandler.loadData(offlinePlayerData);
sqlHandler.saveData(offlinePlayerData, false);
} catch (RuntimeException exception) {
errorCount++;

View File

@ -50,7 +50,7 @@ public class ResetCommandTreeNode extends CommandTreeNode {
}
PlayerData data = PlayerData.get(player);
MMOCore.plugin.dataProvider.getDataManager().getDefaultData().apply(data);
MMOCore.plugin.playerDataManager.getDefaultData().apply(data);
data.setExperience(0);
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
data.getCollectionSkills().setExperience(profession, 0);
@ -245,7 +245,7 @@ public class ResetCommandTreeNode extends CommandTreeNode {
}
PlayerData data = PlayerData.get(player);
data.setLevel(MMOCore.plugin.dataProvider.getDataManager().getDefaultData().getLevel());
data.setLevel(MMOCore.plugin.playerDataManager.getDefaultData().getLevel());
data.setExperience(0);
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
data.getCollectionSkills().setExperience(profession, 0);

View File

@ -30,7 +30,7 @@ public class SaveDataTreeNode extends CommandTreeNode {
return CommandResult.FAILURE;
}
MMOCore.plugin.dataProvider.getDataManager().getDataHandler().saveData(PlayerData.get(player), false);
MMOCore.plugin.playerDataManager.getDataHandler().saveData(PlayerData.get(player), false);
return CommandResult.SUCCESS;
}

View File

@ -145,7 +145,7 @@ public class ClassConfirmation extends EditableInventory {
playerData.setClass(profess);
else
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess)
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
: new SavedClassInformation(MMOCore.plugin.playerDataManager.getDefaultData())).load(profess, playerData);
ConfigMessage.fromKey("class-select", "class", profess.getName()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.SELECT_CLASS).playTo(player);
player.closeInventory();

View File

@ -40,16 +40,16 @@ public class EditableGuildCreation extends EditableInventory {
if (item.getFunction().equals("create")) {
new ChatInput(player, PlayerInput.InputType.GUILD_CREATION_TAG, context.getInventoryHolder(), input -> {
if(MMOCore.plugin.dataProvider.getGuildManager().getConfig().shouldUppercaseTags())
if(MMOCore.plugin.nativeGuildManager.getConfig().shouldUppercaseTags())
input = input.toUpperCase();
if(check(player, input, MMOCore.plugin.dataProvider.getGuildManager().getConfig().getTagRules())) {
if(check(player, input, MMOCore.plugin.nativeGuildManager.getConfig().getTagRules())) {
String tag = input;
new ChatInput(player, PlayerInput.InputType.GUILD_CREATION_NAME, context.getInventoryHolder(), name -> {
if(check(player, name, MMOCore.plugin.dataProvider.getGuildManager().getConfig().getNameRules())) {
MMOCore.plugin.dataProvider.getGuildManager().newRegisteredGuild(playerData.getUniqueId(), name, tag);
MMOCore.plugin.dataProvider.getGuildManager().getGuild(tag.toLowerCase()).addMember(playerData.getUniqueId());
if(check(player, name, MMOCore.plugin.nativeGuildManager.getConfig().getNameRules())) {
MMOCore.plugin.nativeGuildManager.newRegisteredGuild(playerData.getUniqueId(), name, tag);
MMOCore.plugin.nativeGuildManager.getGuild(tag.toLowerCase()).addMember(playerData.getUniqueId());
InventoryManager.GUILD_VIEW.newInventory(playerData).open();
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
@ -76,7 +76,7 @@ public class EditableGuildCreation extends EditableInventory {
if(input.length() <= rules.getMax() && input.length() >= rules.getMin())
if(input.matches(rules.getRegex()))
if(!MMOCore.plugin.dataProvider.getGuildManager().isRegistered(input))
if(!MMOCore.plugin.nativeGuildManager.isRegistered(input))
return true;
else
reason = ConfigMessage.fromKey("guild-creation.reasons.already-taken").asLine();

View File

@ -190,7 +190,7 @@ public class EditableGuildView extends EditableInventory {
if (item.getFunction().equals("disband")) {
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
return;
MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(playerData.getGuild());
MMOCore.plugin.nativeGuildManager.unregisterGuild(playerData.getGuild());
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
player.closeInventory();
return;

View File

@ -74,7 +74,7 @@ public class Guild implements AbstractGuild {
// Disband the guild if no member left
if (members.size() < 1) {
MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(this);
MMOCore.plugin.nativeGuildManager.unregisterGuild(this);
return;
}

View File

@ -19,6 +19,6 @@ public interface OfflinePlayerData extends OfflineDataHolder {
public abstract long getLastLogin();
public static OfflinePlayerData get(UUID uuid) {
return MMOCore.plugin.dataProvider.getDataManager().getOffline(uuid);
return MMOCore.plugin.playerDataManager.getOffline(uuid);
}
}

View File

@ -75,7 +75,7 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer<PlayerData> {
}
getData().setUnlockedItems(unlockedItems);
if (!isEmpty(result.getString("guild"))) {
final Guild guild = MMOCore.plugin.dataProvider.getGuildManager().getGuild(result.getString("guild"));
final Guild guild = MMOCore.plugin.nativeGuildManager.getGuild(result.getString("guild"));
if (guild != null) getData().setGuild(guild.hasMember(getData().getUniqueId()) ? guild : null);
}
if (!isEmpty(result.getString("attributes"))) getData().getAttributes().load(result.getString("attributes"));

View File

@ -14,7 +14,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class GuildListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void a(AsyncPlayerChatEvent event) {
if (!event.getMessage().startsWith(MMOCore.plugin.dataProvider.getGuildManager().getConfig().getPrefix()))
if (!event.getMessage().startsWith(MMOCore.plugin.nativeGuildManager.getConfig().getPrefix()))
return;
PlayerData data = PlayerData.get(event.getPlayer());
@ -25,7 +25,7 @@ public class GuildListener implements Listener {
// Run it sync
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> {
ConfigMessage format = ConfigMessage.fromKey("guild-chat", "player", data.getPlayer().getName(), "tag", data.getGuild().getTag(), "message", event.getMessage().substring(MMOCore.plugin.dataProvider.getGuildManager().getConfig().getPrefix().length()));
ConfigMessage format = ConfigMessage.fromKey("guild-chat", "player", data.getPlayer().getName(), "tag", data.getGuild().getTag(), "message", event.getMessage().substring(MMOCore.plugin.nativeGuildManager.getConfig().getPrefix().length()));
GuildChatEvent called = new GuildChatEvent(data, format.asLine());
Bukkit.getPluginManager().callEvent(called);
if (!called.isCancelled())