mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
Fixed mysql on sync
This commit is contained in:
parent
3a637d9144
commit
83739e9c66
2
pom.xml
2
pom.xml
@ -125,7 +125,7 @@
|
||||
<dependency>
|
||||
<groupId>io.lumine</groupId>
|
||||
<artifactId>MythicLib</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<version>1.1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -6,14 +6,13 @@ import io.lumine.mythic.lib.version.SpigotPlugin;
|
||||
import io.lumine.mythic.utils.plugin.LuminePlugin;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.api.PlayerActionBar;
|
||||
import net.Indyuce.mmocore.comp.MMOCoreTargetRestriction;
|
||||
import net.Indyuce.mmocore.loot.chest.LootChest;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.api.player.social.guilds.Guild;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.util.debug.DebugMode;
|
||||
import net.Indyuce.mmocore.command.*;
|
||||
import net.Indyuce.mmocore.comp.MMOCoreTargetRestriction;
|
||||
import net.Indyuce.mmocore.comp.anticheat.AntiCheatSupport;
|
||||
import net.Indyuce.mmocore.comp.anticheat.SpartanPlugin;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizenInteractEventListener;
|
||||
@ -33,7 +32,7 @@ import net.Indyuce.mmocore.listener.*;
|
||||
import net.Indyuce.mmocore.listener.option.*;
|
||||
import net.Indyuce.mmocore.listener.profession.FishingListener;
|
||||
import net.Indyuce.mmocore.listener.profession.PlayerCollectStats;
|
||||
import net.Indyuce.mmocore.manager.ExperienceManager;
|
||||
import net.Indyuce.mmocore.loot.chest.LootChest;
|
||||
import net.Indyuce.mmocore.manager.*;
|
||||
import net.Indyuce.mmocore.manager.data.DataProvider;
|
||||
import net.Indyuce.mmocore.manager.data.mysql.MySQLDataProvider;
|
||||
@ -299,9 +298,13 @@ public class MMOCore extends LuminePlugin {
|
||||
int autosave = getConfig().getInt("auto-save.interval") * 20;
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
for (PlayerData loaded : PlayerData.getAll())
|
||||
if(loaded.isFullyLoaded()) dataProvider.getDataManager().saveData(loaded);
|
||||
|
||||
// Save player data
|
||||
for (PlayerData data : PlayerData.getAll())
|
||||
if (data.isFullyLoaded())
|
||||
dataProvider.getDataManager().saveData(data);
|
||||
|
||||
// Save guild info
|
||||
for (Guild guild : dataProvider.getGuildManager().getAll())
|
||||
dataProvider.getGuildManager().save(guild);
|
||||
}
|
||||
@ -310,20 +313,26 @@ public class MMOCore extends LuminePlugin {
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
for (PlayerData data : PlayerData.getAll()) {
|
||||
if(!data.isFullyLoaded()) return;
|
||||
data.getQuestData().resetBossBar();
|
||||
|
||||
// Save player data
|
||||
for (PlayerData data : PlayerData.getAll())
|
||||
if (data.isFullyLoaded()) {
|
||||
data.close();
|
||||
dataProvider.getDataManager().saveData(data);
|
||||
}
|
||||
|
||||
// Save guild info
|
||||
for (Guild guild : dataProvider.getGuildManager().getAll())
|
||||
dataProvider.getGuildManager().save(guild);
|
||||
|
||||
// Close MySQL data provider (memory leaks)
|
||||
if (dataProvider instanceof MySQLDataProvider)
|
||||
((MySQLDataProvider) dataProvider).close();
|
||||
|
||||
// Reset active blocks
|
||||
mineManager.resetRemainingBlocks();
|
||||
|
||||
// Clear spawned loot chests
|
||||
lootChests.getActive().forEach(chest -> chest.unregister(false));
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,11 @@ public class PlayerQuests implements Closable {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
// Remove boss bar
|
||||
bossbar.removeAll();
|
||||
|
||||
// Close current objective progress
|
||||
if (current != null)
|
||||
current.getProgress().close();
|
||||
}
|
||||
@ -183,8 +188,4 @@ public class PlayerQuests implements Closable {
|
||||
bossbar.setTitle(current.getFormattedLore());
|
||||
bossbar.setProgress((double) current.getObjectiveNumber() / current.getQuest().getObjectives().size());
|
||||
}
|
||||
|
||||
public void resetBossBar() {
|
||||
bossbar.removeAll();
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,19 @@ import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.util.AltChar;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.experience.PlayerProfessions;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.quest.PlayerQuests;
|
||||
import net.Indyuce.mmocore.experience.PlayerProfessions;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.skill.Skill;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class RPGPlaceholders extends PlaceholderExpansion {
|
||||
@Override
|
||||
@ -56,6 +59,12 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
||||
if (identifier.equals("level"))
|
||||
return "" + playerData.getLevel();
|
||||
|
||||
else if (identifier.startsWith("skill_level_")) {
|
||||
String id = identifier.substring(12);
|
||||
Skill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.get(id), "Could not find skill with ID '" + id + "'");
|
||||
return String.valueOf(playerData.getSkillLevel(skill));
|
||||
}
|
||||
|
||||
else if (identifier.equals("level_percent")) {
|
||||
double current = playerData.getExperience(), next = playerData.getLevelUpExperience();
|
||||
return MythicLib.plugin.getMMOConfig().decimal.format(current / next * 100);
|
||||
|
@ -42,11 +42,22 @@ public abstract class PlayerDataManager {
|
||||
* @param playerData PLayer data to unregister
|
||||
*/
|
||||
public void unregisterSafe(PlayerData playerData) {
|
||||
|
||||
// Save data async if required
|
||||
if (playerData.isFullyLoaded())
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
saveData(playerData);
|
||||
|
||||
// Unregister once the data was saved
|
||||
playerData.close();
|
||||
this.data.remove(playerData.getUniqueId());
|
||||
});
|
||||
|
||||
// Just unregister data without saving
|
||||
else {
|
||||
playerData.close();
|
||||
this.data.remove(playerData.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,6 +131,8 @@ public abstract class PlayerDataManager {
|
||||
|
||||
/**
|
||||
* Called when player data must be saved in configs or database.
|
||||
* This method should always be called sync because it DOES register
|
||||
* an async task in case MySQL storage is used.
|
||||
*
|
||||
* @param data Player data to save
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user