mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
fixed quest objective doubling issue
This commit is contained in:
parent
8b317db4b8
commit
4c3c3c9dfe
2
pom.xml
2
pom.xml
@ -125,7 +125,7 @@
|
||||
<dependency>
|
||||
<groupId>io.lumine</groupId>
|
||||
<artifactId>MythicLib</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<version>1.1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.Indyuce.mmocore.api.player;
|
||||
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.player.CooldownInfo;
|
||||
import io.lumine.mythic.lib.player.CooldownMap;
|
||||
import io.lumine.mythic.lib.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.player.cooldown.CooldownInfo;
|
||||
import io.lumine.mythic.lib.player.cooldown.CooldownMap;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigMessage;
|
||||
import net.Indyuce.mmocore.api.Waypoint;
|
||||
@ -19,6 +19,7 @@ import net.Indyuce.mmocore.api.player.social.guilds.Guild;
|
||||
import net.Indyuce.mmocore.api.player.stats.PlayerStats;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.quest.PlayerQuests;
|
||||
import net.Indyuce.mmocore.api.util.Closable;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
|
||||
import net.Indyuce.mmocore.experience.EXPSource;
|
||||
@ -45,7 +46,7 @@ import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class PlayerData extends OfflinePlayerData {
|
||||
public class PlayerData extends OfflinePlayerData implements Closable {
|
||||
|
||||
/**
|
||||
* Corresponds to the MythicLib player data. It is used to keep
|
||||
@ -127,6 +128,11 @@ public class PlayerData extends OfflinePlayerData {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
questData.close();
|
||||
}
|
||||
|
||||
public MMOPlayerData getMMOPlayerData() {
|
||||
return mmoData;
|
||||
}
|
||||
@ -896,7 +902,23 @@ public class PlayerData extends OfflinePlayerData {
|
||||
* @return If player data for that player is loaded
|
||||
*/
|
||||
public static boolean has(Player player) {
|
||||
return MMOCore.plugin.dataProvider.getDataManager().isLoaded(player.getUniqueId());
|
||||
return has(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to check if the player data is loaded for a
|
||||
* specific player. This might seem redundant because the given
|
||||
* Player instance is linked to an online player, and data
|
||||
* is always loaded for an online player.
|
||||
* <p>
|
||||
* In fact a Player instance can be attached to a Citizens NPC
|
||||
* which has no player data loaded hence this method
|
||||
*
|
||||
* @param uuid A (real or fictive) player UUID
|
||||
* @return If player data for that player is loaded
|
||||
*/
|
||||
public static boolean has(UUID uuid) {
|
||||
return MMOCore.plugin.dataProvider.getDataManager().isLoaded(uuid);
|
||||
}
|
||||
|
||||
public static Collection<PlayerData> getAll() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.api.quest;
|
||||
|
||||
import net.Indyuce.mmocore.api.util.Closable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -8,7 +9,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.objective.Objective;
|
||||
|
||||
public abstract class ObjectiveProgress {
|
||||
public abstract class ObjectiveProgress implements Closable {
|
||||
private final Objective objective;
|
||||
private final QuestProgress questProgress;
|
||||
|
||||
@ -32,6 +33,7 @@ public abstract class ObjectiveProgress {
|
||||
return questProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (this instanceof Listener)
|
||||
HandlerList.unregisterAll((Listener) this);
|
||||
|
@ -6,6 +6,7 @@ import com.google.gson.JsonObject;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.Closable;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
@ -19,7 +20,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PlayerQuests {
|
||||
public class PlayerQuests implements Closable {
|
||||
private final PlayerData playerData;
|
||||
private final BossBar bossbar;
|
||||
private final Map<String, Long> finished = new HashMap<>();
|
||||
@ -36,12 +37,6 @@ public class PlayerQuests {
|
||||
bossbar.addPlayer(playerData.getPlayer());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public PlayerQuests(PlayerData playerData, BossBar bar) {
|
||||
this.playerData = playerData;
|
||||
this.bossbar = bar;
|
||||
}
|
||||
|
||||
public PlayerQuests load(ConfigurationSection config) {
|
||||
if (config.contains("current"))
|
||||
try {
|
||||
@ -148,15 +143,20 @@ public class PlayerQuests {
|
||||
|
||||
public void start(Quest quest) {
|
||||
|
||||
// close current objective progress if quest is active
|
||||
if (hasCurrent())
|
||||
current.getProgress().close();
|
||||
// Close current objective progress if quest is active
|
||||
close();
|
||||
|
||||
// apply newer quest
|
||||
// Apply newest quest
|
||||
current = quest == null ? null : quest.generateNewProgress(playerData);
|
||||
updateBossBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (current != null)
|
||||
current.getProgress().close();
|
||||
}
|
||||
|
||||
public boolean checkCooldownAvailability(Quest quest) {
|
||||
return (finished.get(quest.getId()) + quest.getDelayMillis()) < System.currentTimeMillis();
|
||||
}
|
||||
|
15
src/main/java/net/Indyuce/mmocore/api/util/Closable.java
Normal file
15
src/main/java/net/Indyuce/mmocore/api/util/Closable.java
Normal file
@ -0,0 +1,15 @@
|
||||
package net.Indyuce.mmocore.api.util;
|
||||
|
||||
/**
|
||||
* Indicates that a class temporarily registers something
|
||||
* such as a Bukkit event, which needs to be unregistered
|
||||
* when the class is finally garbage collected.
|
||||
*/
|
||||
public interface Closable {
|
||||
|
||||
/**
|
||||
* Method that must be called before the class
|
||||
* is garbage collected
|
||||
*/
|
||||
void close();
|
||||
}
|
@ -34,7 +34,12 @@ public abstract class PlayerDataManager {
|
||||
return Objects.requireNonNull(data.get(uuid), "Player data is not loaded");
|
||||
}
|
||||
|
||||
public void remove(UUID uuid) {
|
||||
/**
|
||||
* Clears the data map from a certain key
|
||||
*
|
||||
* @param uuid Player UUID to clear
|
||||
*/
|
||||
protected void unregisterData(UUID uuid) {
|
||||
data.remove(uuid);
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
|
||||
@Override
|
||||
public void remove(PlayerData data) {
|
||||
if (data.isFullyLoaded()) saveData(data);
|
||||
remove(data.getUniqueId());
|
||||
if (data.isFullyLoaded())
|
||||
saveData(data);
|
||||
|
||||
data.close();
|
||||
unregisterData(data.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -129,5 +129,8 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(PlayerData data) {}
|
||||
public void remove(PlayerData data) {
|
||||
data.close();
|
||||
unregisterData(data.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user