diff --git a/src/main/java/fr/communaywen/core/Managers.java b/src/main/java/fr/communaywen/core/Managers.java index d126b36e..b00c895e 100644 --- a/src/main/java/fr/communaywen/core/Managers.java +++ b/src/main/java/fr/communaywen/core/Managers.java @@ -169,6 +169,7 @@ public void init(AywenCraftPlugin plugin) { public void cleanup() { /* Besoin de la db */ reportManager.saveReports(); + homesManagers.saveHomesLimits(); DreamTabManager.close(); /* Plus besoin de la db */ diff --git a/src/main/java/fr/communaywen/core/quests/PlayerQuests.java b/src/main/java/fr/communaywen/core/quests/PlayerQuests.java index f3918b1a..bc830873 100644 --- a/src/main/java/fr/communaywen/core/quests/PlayerQuests.java +++ b/src/main/java/fr/communaywen/core/quests/PlayerQuests.java @@ -2,6 +2,7 @@ import fr.communaywen.core.quests.qenum.QUESTS; import lombok.Getter; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -9,8 +10,8 @@ @Getter public class PlayerQuests { - private final Map questsProgress; - public final Map questsTier; + @NotNull private final Map questsProgress; + @NotNull public final Map questsTier; public PlayerQuests() { this.questsProgress = new HashMap<>(); @@ -21,19 +22,19 @@ public PlayerQuests() { } } - public int getProgress(QUESTS quest) { + public int getProgress(@NotNull QUESTS quest) { return questsProgress.getOrDefault(quest, 0); } - public int getCurrentTier(QUESTS quest) { + public int getCurrentTier(@NotNull QUESTS quest) { return questsTier.getOrDefault(quest, 0); } - public void setCurrentTier(QUESTS quests, int tier) { + public void setCurrentTier(@NotNull QUESTS quests, int tier) { questsTier.put(quests, tier); } - public void setProgress(QUESTS quest, int progress) { + public void setProgress(@NotNull QUESTS quest, int progress) { questsProgress.put(quest, progress); int tier = 0; for (int i = 0; i < quest.getQtTiers().length; i++) { @@ -46,7 +47,7 @@ public void setProgress(QUESTS quest, int progress) { } } - public void addProgress(QUESTS quest, int amount) { + public void addProgress(@NotNull QUESTS quest, int amount) { int currentTier = getCurrentTier(quest); if(currentTier < 0 || currentTier >= quest.getQtTiers().length) throw new IllegalArgumentException("Invalid tier for quest " + quest.name()); @@ -58,12 +59,12 @@ public void addProgress(QUESTS quest, int amount) { } } - public boolean isQuestCompleted(QUESTS quest) { + public boolean isQuestCompleted(@NotNull QUESTS quest) { int currentTier = getCurrentTier(quest); return currentTier >= quest.getQtTiers().length - 1 && getProgress(quest) >= quest.getQt(quest.getQtTiers().length - 1); } - public void removeProgress(QUESTS quest, int amount) { + public void removeProgress(@NotNull QUESTS quest, int amount) { int currentProgress = questsProgress.getOrDefault(quest, 0); int newProgress = Math.max(0, currentProgress - amount); questsProgress.put(quest, newProgress); @@ -79,7 +80,7 @@ public void removeProgress(QUESTS quest, int amount) { } } - public void resetProgress(QUESTS quest) { + public void resetProgress(@NotNull QUESTS quest) { questsProgress.put(quest, 0); setCurrentTier(quest, 0); } diff --git a/src/main/java/fr/communaywen/core/quests/QuestsManager.java b/src/main/java/fr/communaywen/core/quests/QuestsManager.java index 51efc483..17ab83da 100644 --- a/src/main/java/fr/communaywen/core/quests/QuestsManager.java +++ b/src/main/java/fr/communaywen/core/quests/QuestsManager.java @@ -18,6 +18,7 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.sql.*; import java.util.*; @@ -58,8 +59,6 @@ public static void loadPlayerData(Player player) throws SQLException { playerQuests.put(playerId, pq); for (QUESTS quest : QUESTS.values()) { - int progress = pq.getProgress(quest); - int tier = pq.getCurrentTier(quest); StringBuilder tierInfo = new StringBuilder(); for (int i = 0; i < quest.getQtTiers().length; i++) { tierInfo.append("Tier ").append(i).append(": ").append(quest.getQt(i)).append(", "); @@ -73,11 +72,9 @@ public static PlayerQuests getPlayerQuests(UUID player) { public static void manageQuestsPlayer(UUID uuid, QUESTS quest, int amount, String actionBar) { Player player = Bukkit.getPlayer(uuid); - if(!player.isConnected()) return; - PlayerQuests pq = getPlayerQuests(uuid); + @NotNull PlayerQuests pq = getPlayerQuests(uuid); int currentTier = pq.getCurrentTier(quest); - - if (pq.isQuestCompleted(quest)) { return; } + if (!player.isConnected() || pq == null || pq.isQuestCompleted(quest)) { return; } if (currentTier < 0 || currentTier >= quest.getQtTiers().length) { return;