diff --git a/PlayerHeadHunt.iml b/PlayerHeadHunt.iml
index 8b7a1e1..3cf00db 100644
--- a/PlayerHeadHunt.iml
+++ b/PlayerHeadHunt.iml
@@ -5,8 +5,6 @@
PAPER
- ADVENTURE
- SPIGOT
1
diff --git a/pom.xml b/pom.xml
index be2b865..79a78cc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,6 +23,27 @@
17
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.4.1
+
+
+ package
+
+ shade
+
+
+
+
+ org.apache.hc
+ org.modularsoft.PlayerHeadHunt.shaded.org.apache.hc
+
+
+
+
+
+
@@ -60,13 +81,6 @@
-
-
- mysql
- mysql-connector-java
- 8.0.33
-
-
com.sk89q.worldedit
@@ -100,6 +114,25 @@
1.18.30
provided
+
+
+ org.yaml
+ snakeyaml
+ 2.0
+
+
+
+ org.apache.httpcomponents.client5
+ httpclient5
+ 5.2
+
+
+
+ net.luckperms
+ api
+ 5.4
+ provided
+
diff --git a/src/main/java/org/modularsoft/PlayerHeadHunt/HeadChatController.java b/src/main/java/org/modularsoft/PlayerHeadHunt/HeadChatController.java
index a545a0f..d1320e1 100644
--- a/src/main/java/org/modularsoft/PlayerHeadHunt/HeadChatController.java
+++ b/src/main/java/org/modularsoft/PlayerHeadHunt/HeadChatController.java
@@ -9,13 +9,13 @@
import java.util.List;
-import static org.modularsoft.PlayerHeadHunt.HeadQuery.foundHeadsAlreadyCount;
-
public class HeadChatController {
private final PlayerHeadHuntMain plugin;
+ private final HeadQuery headQuery;
- public HeadChatController(PlayerHeadHuntMain plugin) {
+ public HeadChatController(PlayerHeadHuntMain plugin, HeadQuery headQuery) {
this.plugin = plugin;
+ this.headQuery = headQuery;
}
public void headFoundResponse(Player player, boolean hasAlreadyBeenFound, int headCount, int x, int y, int z) {
@@ -28,7 +28,8 @@ public void headFoundResponse(Player player, boolean hasAlreadyBeenFound, int he
player.playSound(player.getLocation(), plugin.config().getHeadFoundSound(), 1, 1);
}
- int otherPlayerFoundHead = foundHeadsAlreadyCount(plugin, x, y, z) - 1;
+ // Get the number of other players who have found this head
+ int otherPlayerFoundHead = Math.max(0, headQuery.foundHeadsAlreadyCount(x, y, z) - 1);
String otherPlayersHaveFoundSuffix;
if (otherPlayerFoundHead == 0) {
@@ -39,18 +40,18 @@ public void headFoundResponse(Player player, boolean hasAlreadyBeenFound, int he
}
} else if (otherPlayerFoundHead == 1) {
otherPlayersHaveFoundSuffix = plugin.config().getLangHeadNotFirstFinderSingle()
- .replace("%OTHERPLAYERSFOUNDHEAD%", "" + otherPlayerFoundHead);
+ .replace("%OTHERPLAYERSFOUNDHEAD%", String.valueOf(otherPlayerFoundHead));
} else {
otherPlayersHaveFoundSuffix = plugin.config().getLangHeadNotFirstFinderMultiple()
- .replace("%OTHERPLAYERSFOUNDHEAD%", "" + otherPlayerFoundHead);
+ .replace("%OTHERPLAYERSFOUNDHEAD%", String.valueOf(otherPlayerFoundHead));
}
+ // Replace placeholders in the message
String message = baseMessage
- .replace("%FOUNDHEADS%", "" + headCount)
- .replace("%NUMBEROFHEADS%", "" + plugin.config().getTotalHeads())
+ .replace("%FOUNDHEADS%", String.valueOf(headCount))
+ .replace("%NUMBEROFHEADS%", String.valueOf(plugin.config().getTotalHeads()))
.replace("%ALREADYFOUNDHEADS%", otherPlayersHaveFoundSuffix);
- // Play sound for a Player Head that is found.
player.sendMessage(message);
}
@@ -100,9 +101,9 @@ public void newPlayerJoinsTheHunt(Player player) {
}
public void playersOwnHeadCountResponse(Player player) {
- // Players wants to see their own head count
+ // Use the instance of HeadQuery to call the method
player.sendMessage(plugin.config().getLangHeadCount()
- .replace("%FOUNDHEADS%", "" + HeadQuery.foundHeadsCount(plugin, player))
+ .replace("%FOUNDHEADS%", "" + headQuery.foundHeadsCount(player))
.replace("%NUMBEROFHEADS%", "" + plugin.config().getTotalHeads()));
}
diff --git a/src/main/java/org/modularsoft/PlayerHeadHunt/HeadQuery.java b/src/main/java/org/modularsoft/PlayerHeadHunt/HeadQuery.java
index af057aa..b2a77cc 100644
--- a/src/main/java/org/modularsoft/PlayerHeadHunt/HeadQuery.java
+++ b/src/main/java/org/modularsoft/PlayerHeadHunt/HeadQuery.java
@@ -1,218 +1,239 @@
package org.modularsoft.PlayerHeadHunt;
import lombok.Getter;
+import net.luckperms.api.LuckPerms;
+import net.luckperms.api.LuckPermsProvider;
+import net.luckperms.api.util.Tristate;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.modularsoft.PlayerHeadHunt.helpers.YamlFileManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
public class HeadQuery {
+ private final YamlFileManager yamlFileManager;
+ RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
+ private final LuckPerms luckPerms;
+
+ public HeadQuery(YamlFileManager yamlFileManager) {
+ this.yamlFileManager = yamlFileManager;
+
+ // Get the LuckPerms provider from the Bukkit services manager
+ RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
+ if (provider != null) {
+ this.luckPerms = provider.getProvider();
+ } else {
+ throw new IllegalStateException("LuckPerms API is not available!");
+ }
+ }
+
public record HeadHunter(@Getter String name, @Getter int headsCollected) { }
- /**
- * @param plugin The PlayerHeadHunt main plugin
- * @param player The player to check
- * @return Returns the number of heads found by the player
- */
- public static int foundHeadsCount(PlayerHeadHuntMain plugin, Player player) {
- String playerUUID = "" + player.getUniqueId();
+ public int foundHeadsCount(Player player) {
+ String playerUUID = player.getUniqueId().toString();
+ Map data = yamlFileManager.getData();
+ Map playerData = (Map) data.get(playerUUID);
- try {
- // Check how many heads the player has collected.
- PreparedStatement foundHeadsCount = plugin.getConnection().prepareStatement(
- "SELECT headsCollected AS 'heads' FROM playerdata WHERE uuid=?");
- foundHeadsCount.setString(1, playerUUID);
- ResultSet results = foundHeadsCount.executeQuery();
-
- if (results.next()) return results.getInt("heads");
- } catch (SQLException e) {
- e.printStackTrace();
- player.sendMessage(plugin.config().getLangDatabaseConnectionError());
+ if (playerData == null) {
+ return 0; // No data for the player, so no heads collected
+ }
+
+ List