Skip to content

Commit

Permalink
Merge branch 'ServerOpenMC:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
iambibi authored Oct 23, 2024
2 parents c2b2b1c + d6c6741 commit ba72fa1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ gradle-app.setting
### Project ###

/builds/

bin/

/server/
/server/
!.idea/icon.png
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/java/fr/communaywen/core/Managers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/fr/communaywen/core/quests/PlayerQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import fr.communaywen.core.quests.qenum.QUESTS;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

@Getter
public class PlayerQuests {

private final Map<QUESTS, Integer> questsProgress;
public final Map<QUESTS, Integer> questsTier;
@NotNull private final Map<QUESTS, Integer> questsProgress;
@NotNull public final Map<QUESTS, Integer> questsTier;

public PlayerQuests() {
this.questsProgress = new HashMap<>();
Expand All @@ -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++) {
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/fr/communaywen/core/quests/QuestsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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(", ");
Expand All @@ -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;
Expand Down

0 comments on commit ba72fa1

Please sign in to comment.