From d54ca50451e46aca407b8a8b6f05cde37aae4cc3 Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 1 Nov 2021 19:42:41 +0100 Subject: [PATCH] fixed quest objective doubling issue --- .../Indyuce/mmocore/api/player/PlayerData.java | 6 ++++++ .../Indyuce/mmocore/listener/PlayerListener.java | 5 +---- .../mmocore/manager/data/PlayerDataManager.java | 16 ++++++++++------ .../data/mysql/MySQLPlayerDataManager.java | 9 --------- .../manager/data/yaml/YAMLPlayerDataManager.java | 6 ------ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 94f17fad..c5ba3cdc 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -130,6 +130,12 @@ public class PlayerData extends OfflinePlayerData implements Closable { @Override public void close() { + + // Remove from party + if (hasParty()) + getParty().removeMember(this); + + // Close quest data questData.close(); } diff --git a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index 15f2b825..fd9ad9de 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -67,10 +67,7 @@ public class PlayerListener implements Listener { @EventHandler public void e(PlayerQuitEvent event) { PlayerData playerData = PlayerData.get(event.getPlayer()); - if (playerData.hasParty()) - playerData.getParty().removeMember(playerData); - - MMOCore.plugin.dataProvider.getDataManager().remove(playerData); + MMOCore.plugin.dataProvider.getDataManager().unregisterSafe(playerData); } /** diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java index e9a8cc7e..322d7e05 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java @@ -35,12 +35,18 @@ public abstract class PlayerDataManager { } /** - * Clears the data map from a certain key + * Safely unregisters the player data from the map. + * This saves the player data either through SQL or YAML, + * then closes the player data and clears it from the data map. * - * @param uuid Player UUID to clear + * @param playerData PLayer data to unregister */ - protected void unregisterData(UUID uuid) { - data.remove(uuid); + public void unregisterSafe(PlayerData playerData) { + if (playerData.isFullyLoaded()) + saveData(playerData); + + playerData.close(); + this.data.remove(playerData.getUniqueId()); } /** @@ -119,8 +125,6 @@ public abstract class PlayerDataManager { */ public abstract void saveData(PlayerData data); - public abstract void remove(PlayerData data); - public static class DefaultPlayerData { private final int level, classPoints, skillPoints, attributePoints, attrReallocPoints; diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index ddde0b4a..2d116970 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -235,13 +235,4 @@ public class MySQLPlayerDataManager extends PlayerDataManager { return lastLogin; } } - - @Override - public void remove(PlayerData data) { - if (data.isFullyLoaded()) - saveData(data); - - data.close(); - unregisterData(data.getUniqueId()); - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index baf7b9ad..21bca359 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -127,10 +127,4 @@ public class YAMLPlayerDataManager extends PlayerDataManager { public OfflinePlayerData getOffline(UUID uuid) { return isLoaded(uuid) ? get(uuid) : new YAMLOfflinePlayerData(uuid); } - - @Override - public void remove(PlayerData data) { - data.close(); - unregisterData(data.getUniqueId()); - } }