diff --git a/build.gradle.kts b/build.gradle.kts index b84617b..ae1be11 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("java") } -version = "2.4.9" +version = "2.4.10" allprojects { repositories { diff --git a/core/src/main/java/fr/aerwyn81/headblocks/data/PlayerProfileLight.java b/core/src/main/java/fr/aerwyn81/headblocks/data/PlayerProfileLight.java index c5c1f0b..ab74e9f 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/data/PlayerProfileLight.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/data/PlayerProfileLight.java @@ -5,12 +5,12 @@ public final class PlayerProfileLight { private final UUID uuid; private final String name; - private final String displayName; + private final String customDisplay; - public PlayerProfileLight(UUID uuid, String name, String displayName) { + public PlayerProfileLight(UUID uuid, String name, String customDisplay) { this.uuid = uuid; this.name = name; - this.displayName = displayName; + this.customDisplay = customDisplay; } public UUID uuid() { @@ -21,7 +21,7 @@ public String name() { return name; } - public String displayName() { - return displayName; + public String customDisplay() { + return customDisplay; } } diff --git a/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MariaDB.java b/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MariaDB.java index 0f28232..3cf90d4 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MariaDB.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MariaDB.java @@ -142,7 +142,7 @@ public void updatePlayerInfo(PlayerProfileLight profile) throws InternalExceptio try (PreparedStatement ps = connection.prepareStatement(Requests.UPDATE_PLAYER_MYSQL)) { ps.setString(1, profile.uuid().toString()); ps.setString(2, profile.name()); - ps.setString(3, profile.displayName()); + ps.setString(3, profile.customDisplay()); ps.executeUpdate(); } catch (SQLException ex) { throw new InternalException(ex); @@ -358,7 +358,7 @@ public boolean hasPlayerRenamed(PlayerProfileLight profile) throws InternalExcep ResultSet rs = ps.executeQuery(); if (rs.next()) { - return !profile.name().equals(rs.getString("pName")) || !profile.displayName().equals(rs.getString("pDisplayName")); + return !profile.name().equals(rs.getString("pName")) || !profile.customDisplay().equals(rs.getString("pDisplayName")); } } catch (Exception ex) { throw new InternalException(ex); diff --git a/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MySQL.java b/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MySQL.java index bb9c86b..0d0f44d 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MySQL.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/databases/types/MySQL.java @@ -141,7 +141,7 @@ public void updatePlayerInfo(PlayerProfileLight profile) throws InternalExceptio try (PreparedStatement ps = connection.prepareStatement(Requests.UPDATE_PLAYER_MYSQL)) { ps.setString(1, profile.uuid().toString()); ps.setString(2, profile.name()); - ps.setString(3, profile.displayName()); + ps.setString(3, profile.customDisplay()); ps.executeUpdate(); } catch (SQLException ex) { throw new InternalException(ex); @@ -354,11 +354,11 @@ public boolean hasPlayerRenamed(PlayerProfileLight profile) throws InternalExcep try (PreparedStatement ps = connection.prepareStatement(Requests.CHECK_PLAYER_NAME)) { ps.setString(1, profile.uuid().toString()); - ps.setString(2, profile.displayName()); + ps.setString(2, profile.customDisplay()); ResultSet rs = ps.executeQuery(); if (rs.next()) { - return !profile.name().equals(rs.getString("pName")) || !profile.displayName().equals(rs.getString("pDisplayName")); + return !profile.name().equals(rs.getString("pName")) || !profile.customDisplay().equals(rs.getString("pDisplayName")); } } catch (Exception ex) { throw new InternalException(ex); diff --git a/core/src/main/java/fr/aerwyn81/headblocks/databases/types/SQLite.java b/core/src/main/java/fr/aerwyn81/headblocks/databases/types/SQLite.java index 7a7cf99..9933809 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/databases/types/SQLite.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/databases/types/SQLite.java @@ -123,7 +123,7 @@ public void updatePlayerInfo(PlayerProfileLight profile) throws InternalExceptio try (PreparedStatement ps = connection.prepareStatement(Requests.UPDATE_PLAYER)) { ps.setString(1, profile.uuid().toString()); ps.setString(2, profile.name()); - ps.setString(3, profile.displayName()); + ps.setString(3, profile.customDisplay()); ps.executeUpdate(); } catch (Exception ex) { @@ -309,7 +309,7 @@ public boolean hasPlayerRenamed(PlayerProfileLight profile) throws InternalExcep ResultSet rs = ps.executeQuery(); if (rs.next()) { - return !profile.name().equals(rs.getString("pName")) || !profile.displayName().equals(rs.getString("pDisplayName")); + return !profile.name().equals(rs.getString("pName")) || !profile.customDisplay().equals(rs.getString("pDisplayName")); } } catch (Exception ex) { throw new InternalException(ex); diff --git a/core/src/main/java/fr/aerwyn81/headblocks/hooks/PlaceholderHook.java b/core/src/main/java/fr/aerwyn81/headblocks/hooks/PlaceholderHook.java index de49449..e91c1e1 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/hooks/PlaceholderHook.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/hooks/PlaceholderHook.java @@ -3,7 +3,6 @@ import fr.aerwyn81.headblocks.HeadBlocks; import fr.aerwyn81.headblocks.data.HeadLocation; import fr.aerwyn81.headblocks.services.HeadService; -import fr.aerwyn81.headblocks.services.LanguageService; import fr.aerwyn81.headblocks.services.StorageService; import fr.aerwyn81.headblocks.utils.internal.InternalException; import fr.aerwyn81.headblocks.utils.message.MessageUtils; @@ -13,7 +12,6 @@ import org.jetbrains.annotations.NotNull; import java.util.*; -import java.util.stream.Collectors; public class PlaceholderHook extends PlaceholderExpansion { @@ -72,7 +70,7 @@ public String onRequest(OfflinePlayer player, @NotNull String identifier) { } } - // %headblocks_leaderboard__% + // %headblocks_leaderboard__% if (identifier.contains("leaderboard")) { var str = identifier.split("_"); try { @@ -94,19 +92,19 @@ public String onRequest(OfflinePlayer player, @NotNull String identifier) { case "name" -> { return p.getKey().name(); } - case "displayname" -> { - var displayName = p.getKey().displayName(); + case "custom" -> { + var displayName = p.getKey().customDisplay(); return displayName.isEmpty() ? p.getKey().name() : displayName; } case "value" -> { return String.valueOf(p.getValue()); } default -> { - return p.getKey().displayName() + " (" + p.getKey().name() + ") " + ": " + p.getValue(); + return p.getKey().customDisplay() + " (" + p.getKey().name() + ") " + ": " + p.getValue(); } } } catch (Exception ex) { - return "Cannot parse the leaderboard placeholder. Use %headblocks_leaderboard__%."; + return "Cannot parse the leaderboard placeholder. Use %headblocks_leaderboard__%."; } } diff --git a/core/src/main/java/fr/aerwyn81/headblocks/services/ConfigService.java b/core/src/main/java/fr/aerwyn81/headblocks/services/ConfigService.java index 0fe5bde..1233dd7 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/services/ConfigService.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/services/ConfigService.java @@ -393,4 +393,16 @@ public static int getHeadClickCommandsSlotsRequired() { public static boolean isPreventPistonExtension() { return config.getBoolean("externalInteractions.piston", true); } public static boolean isPreventLiquidFlow() { return config.getBoolean("externalInteractions.water", true); } + + public static String getPlaceholdersLeaderboardPrefix() { + return config.getString("placeholders.leaderboard.prefix", ""); + } + + public static String getPlaceholdersLeaderboardSuffix() { + return config.getString("placeholders.leaderboard.suffix", ""); + } + + public static boolean isPlaceholdersLeaderboardUseNickname() { + return config.getBoolean("placeholders.leaderboard.nickname", false); + } } diff --git a/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java b/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java index ca1bd63..f89b899 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java @@ -13,6 +13,7 @@ import fr.aerwyn81.headblocks.storages.types.Redis; import fr.aerwyn81.headblocks.utils.internal.InternalException; import fr.aerwyn81.headblocks.utils.message.MessageUtils; +import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.entity.Player; import java.io.*; @@ -187,11 +188,12 @@ private static boolean backupDatabase() { public static void loadPlayer(Player player) { UUID pUuid = player.getUniqueId(); String playerName = player.getName(); - String playerDisplayName = player.getDisplayName(); try { boolean isExist = containsPlayer(pUuid); + String playerDisplayName = getCustomDisplay(player); + var playerProfile = new PlayerProfileLight(pUuid, playerName, playerDisplayName); if (isExist) { @@ -215,6 +217,26 @@ public static void loadPlayer(Player player) { } } + private static String getCustomDisplay(Player player) { + var customName = player.getName(); + + if (ConfigService.isPlaceholdersLeaderboardUseNickname()) { + customName = player.getDisplayName(); + } + + var prefix = ConfigService.getPlaceholdersLeaderboardPrefix(); + if (!prefix.isEmpty()) { + customName = PlaceholderAPI.setPlaceholders(player, prefix) + customName; + } + + var suffix = ConfigService.getPlaceholdersLeaderboardSuffix(); + if (!prefix.isEmpty()) { + customName = customName + PlaceholderAPI.setPlaceholders(player, suffix); + } + + return customName; + } + public static void unloadPlayer(Player player) { UUID uuid = player.getUniqueId(); String playerName = player.getName(); diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 15f2a36..bf9206d 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -198,6 +198,15 @@ externalInteractions: piston: true water: true +# Used to customize the %headblocks_leaderboard__custom% placeholder +# Support placeholders (PlaceholderAPI) +# IMPORTANT: Player had to reconnect or server restart to make the modification effective +placeholders: + leaderboard: + prefix: "" + suffix: "" + nickname: false + # Tiered rewards : provide a head count to trigger a reward command list # Add the tier, then messages, commands or broadcast message which will be executed # You can add "slotsRequired" to give the reward only if the player has enough space in inventory diff --git a/docs/config/general.md b/docs/config/general.md index 36d116e..96aff9c 100644 --- a/docs/config/general.md +++ b/docs/config/general.md @@ -35,4 +35,4 @@ See the list below: - `%headblocks_order_previous%`: if order is specified, display the previous named head found (_raw integer or "-" if not calculable_) - `%headblocks_order_current%`: if order is specified, display the current named head found (_raw integer or "-" if not calculable_) - `%headblocks_order_next%`: if order is specified, display the next named head to found (_raw integer or "-" if not calculable_) -- `%headblocks_leaderboard__%`: used to build a leaderboard +- `%headblocks_leaderboard__%`: used to build a leaderboard (custom check config file)