From 3edef1c2e40ecc4eb19ceb430d1e83a167e3e366 Mon Sep 17 00:00:00 2001 From: Andre601 Date: Wed, 29 Mar 2023 18:41:13 +0200 Subject: [PATCH] Bump API and plugin version for release --- .../bukkit/objects/PAPIPlaceholders.java | 14 +++--- .../advancedserverlist/spigot/SpigotCore.java | 3 +- .../events/ProtocolLibEventWrapper.java | 4 +- .../core/commands/CommandHandler.java | 2 +- .../core/events/PingEventHandler.java | 22 +++++----- .../core/profiles/profile/ProfileManager.java | 44 +++++++++---------- .../profiles/profile/ProfileSerializer.java | 14 +++--- docs/api/changelog.md | 7 +++ pom.xml | 4 +- 9 files changed, 62 insertions(+), 52 deletions(-) diff --git a/bukkit/src/main/java/ch/andre601/advancedserverlist/bukkit/objects/PAPIPlaceholders.java b/bukkit/src/main/java/ch/andre601/advancedserverlist/bukkit/objects/PAPIPlaceholders.java index e6468dd2..1d08fd75 100644 --- a/bukkit/src/main/java/ch/andre601/advancedserverlist/bukkit/objects/PAPIPlaceholders.java +++ b/bukkit/src/main/java/ch/andre601/advancedserverlist/bukkit/objects/PAPIPlaceholders.java @@ -91,25 +91,25 @@ public String onPlaceholderRequest(Player pl, @NotNull String identifier){ ProfileEntry entry = ProfileManager.merge(profile); - if(ProfileManager.checkOption(entry.isExtraPlayersEnabled())) - max = online + (entry.getExtraPlayersCount() == null ? 0 : entry.getExtraPlayersCount()); + if(ProfileManager.checkOption(entry.extraPlayersEnabled())) + max = online + (entry.extraPlayersCount() == null ? 0 : entry.extraPlayersCount()); GenericServer finalServer = new GenericServerImpl(online, max, host); return switch(identifier.toLowerCase(Locale.ROOT)){ - case "motd" -> ComponentParser.list(entry.getMotd()) + case "motd" -> ComponentParser.list(entry.motd()) .modifyText(text -> PlaceholderAPI.setPlaceholders(pl, text)) .modifyText(text -> StringReplacer.replace(text, player, finalServer)) .toString(); - case "favicon" -> ComponentParser.text(entry.getFavicon()) + case "favicon" -> ComponentParser.text(entry.favicon()) .modifyText(text -> PlaceholderAPI.setPlaceholders(pl, text)) .modifyText(text -> StringReplacer.replace(text, player, finalServer)) .toString(); - case "playercount_hover" -> ComponentParser.list(entry.getPlayers()) + case "playercount_hover" -> ComponentParser.list(entry.players()) .modifyText(text -> PlaceholderAPI.setPlaceholders(pl, text)) .modifyText(text -> StringReplacer.replace(text, player, finalServer)) .toString(); - case "playercount_text" -> ComponentParser.text(entry.getPlayerCountText()) + case "playercount_text" -> ComponentParser.text(entry.playerCountText()) .modifyText(text -> PlaceholderAPI.setPlaceholders(pl, text)) .modifyText(text -> StringReplacer.replace(text, player, finalServer)) .toString(); @@ -126,7 +126,7 @@ private int resolveProtocol(Player player){ if(plugin instanceof SpigotCore) return ProtocolLibrary.getProtocolManager().getProtocolVersion(player); - // getProtocolVersion is only in Paper, so this is only called when + // getProtocolVersion is only in Paper, so this is only called when main class isn't SpigotCore return Bukkit.getUnsafe().getProtocolVersion(); } diff --git a/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/SpigotCore.java b/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/SpigotCore.java index f19919a8..5542fa89 100644 --- a/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/SpigotCore.java +++ b/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/SpigotCore.java @@ -34,6 +34,7 @@ import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler; import ch.andre601.advancedserverlist.spigot.events.LoadEvent; import com.comphenix.protocol.wrappers.WrappedServerPing; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.command.PluginCommand; @@ -78,7 +79,7 @@ public void loadCommands(){ getPluginLogger().warn("Unable to register command /advancedserverlist"); return; } - cmd.setExecutor(new CmdAdvancedServerList(this)); + cmd.setExecutor(new CmdAdvancedServerList(this, BukkitAudiences.create(this))); } @Override diff --git a/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/events/ProtocolLibEventWrapper.java b/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/events/ProtocolLibEventWrapper.java index e83b1a34..d506bdc1 100644 --- a/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/events/ProtocolLibEventWrapper.java +++ b/bukkit/src/main/java/ch/andre601/advancedserverlist/spigot/events/ProtocolLibEventWrapper.java @@ -124,7 +124,9 @@ public void setDefaultFavicon(){ // Not used in ProtocolLib @Override - public void updateEvent(){} + public void updateEvent(){ + event.getPacket().getServerPings().write(0, ping); + } @Override public boolean isInvalidProtocol(){ diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/commands/CommandHandler.java b/core/src/main/java/ch/andre601/advancedserverlist/core/commands/CommandHandler.java index 8361969e..3d671413 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/commands/CommandHandler.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/commands/CommandHandler.java @@ -116,7 +116,7 @@ public void handle(CmdSender sender){ core.clearPlayerCache(); sender.sendPrefixedMsg("Successfully cleared Player Cache!"); - sender.sendErrorMsg("Reload complete!"); + sender.sendPrefixedMsg("Reload complete!"); } } diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/events/PingEventHandler.java b/core/src/main/java/ch/andre601/advancedserverlist/core/events/PingEventHandler.java index de301068..002a7bc9 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/events/PingEventHandler.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/events/PingEventHandler.java @@ -68,43 +68,43 @@ public static void handleEvent(GenericEventWrapper< if(entry.isInvalid()) return; - if(ProfileManager.checkOption(entry.isExtraPlayersEnabled())){ - max = online + (entry.getExtraPlayersCount() == null ? 0 : entry.getExtraPlayersCount()); + if(ProfileManager.checkOption(entry.extraPlayersEnabled())){ + max = online + (entry.extraPlayersCount() == null ? 0 : entry.extraPlayersCount()); event.setMaxPlayers(max); } GenericServer finalServer = new GenericServerImpl(online, max, host); - if(ProfileManager.checkOption(entry.getMotd())){ + if(ProfileManager.checkOption(entry.motd())){ event.setMotd( - ComponentParser.list(entry.getMotd()) + ComponentParser.list(entry.motd()) .modifyText(text -> StringReplacer.replace(text, player, finalServer)) .modifyText(text -> event.parsePAPIPlaceholders(text, player)) .toComponent() ); } - boolean hidePlayers = ProfileManager.checkOption(entry.isHidePlayersEnabled()); + boolean hidePlayers = ProfileManager.checkOption(entry.hidePlayersEnabled()); if(hidePlayers){ event.hidePlayers(); } - if(ProfileManager.checkOption(entry.getPlayerCountText()) && !hidePlayers){ + if(ProfileManager.checkOption(entry.playerCountText()) && !hidePlayers){ event.setPlayerCount( - ComponentParser.text(entry.getPlayerCountText()) + ComponentParser.text(entry.playerCountText()) .modifyText(text -> StringReplacer.replace(text, player, finalServer)) .modifyText(text -> event.parsePAPIPlaceholders(text, player)) .toString() ); } - if(ProfileManager.checkOption(entry.getPlayers()) && !hidePlayers){ - event.setPlayers(entry.getPlayers(), player, server); + if(ProfileManager.checkOption(entry.players()) && !hidePlayers){ + event.setPlayers(entry.players(), player, server); } - if(ProfileManager.checkOption(entry.getFavicon())){ - String favicon = StringReplacer.replace(entry.getFavicon(), player, server); + if(ProfileManager.checkOption(entry.favicon())){ + String favicon = StringReplacer.replace(entry.favicon(), player, server); F fav = plugin.getFaviconHandler().getFavicon(favicon, image -> { try{ diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileManager.java b/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileManager.java index 9a18418e..f2e696fd 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileManager.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileManager.java @@ -99,7 +99,7 @@ public static boolean checkOption(Object obj){ return !list.isEmpty(); // Check if list isn't empty }else if(obj instanceof String str){ - return !str.isEmpty(); // Check if list is not empty + return !str.isEmpty(); // Check if String is not empty }else if(obj instanceof NullBool nb){ return nb.getOrDefault(false); // Return NullBool's value @@ -109,52 +109,52 @@ public static boolean checkOption(Object obj){ } private static List resolveMOTD(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || !checkOption(profile.getMotd())) - return defaultProfile.getMotd(); + if(profile == null || !checkOption(profile.motd())) + return defaultProfile.motd(); - return profile.getMotd(); + return profile.motd(); } private static List resolvePlayers(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || !checkOption(profile.getPlayers())) - return defaultProfile.getPlayers(); + if(profile == null || !checkOption(profile.players())) + return defaultProfile.players(); - return profile.getPlayers(); + return profile.players(); } private static String resolvePlayerCountText(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || !checkOption(profile.getPlayerCountText())) - return defaultProfile.getPlayerCountText(); + if(profile == null || !checkOption(profile.playerCountText())) + return defaultProfile.playerCountText(); - return profile.getPlayerCountText(); + return profile.playerCountText(); } private static String resolveFavicon(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || !checkOption(profile.getFavicon())) - return defaultProfile.getFavicon(); + if(profile == null || !checkOption(profile.favicon())) + return defaultProfile.favicon(); - return profile.getFavicon(); + return profile.favicon(); } private static boolean resolveHidePlayersEnabled(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || !checkOption(profile.isHidePlayersEnabled())) - return defaultProfile.isHidePlayersEnabled().getOrDefault(false); + if(profile == null || !checkOption(profile.hidePlayersEnabled())) + return defaultProfile.hidePlayersEnabled().getOrDefault(false); - return profile.isHidePlayersEnabled().getOrDefault(false); + return profile.hidePlayersEnabled().getOrDefault(false); } private static boolean resolveExtraPlayersEnabled(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || !checkOption(profile.isExtraPlayersEnabled())) - return defaultProfile.isExtraPlayersEnabled().getOrDefault(false); + if(profile == null || !checkOption(profile.extraPlayersEnabled())) + return defaultProfile.extraPlayersEnabled().getOrDefault(false); - return profile.isExtraPlayersEnabled().getOrDefault(false); + return profile.extraPlayersEnabled().getOrDefault(false); } private static Integer resolveExtraPlayersCount(ProfileEntry profile, ProfileEntry defaultProfile){ - if(profile == null || profile.getExtraPlayersCount() == null) - return defaultProfile.getExtraPlayersCount() == null ? 0 : defaultProfile.getExtraPlayersCount(); + if(profile == null || profile.extraPlayersCount() == null) + return defaultProfile.extraPlayersCount() == null ? 0 : defaultProfile.extraPlayersCount(); - return profile.getExtraPlayersCount(); + return profile.extraPlayersCount(); } private static List resolveList(ConfigurationNode node, Object... path){ diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileSerializer.java b/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileSerializer.java index 403ac0d0..f7e41367 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileSerializer.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/profiles/profile/ProfileSerializer.java @@ -48,12 +48,12 @@ public void serialize(Type type, @Nullable ProfileEntry profile, ConfigurationNo return; } - node.node("motd").set(profile.getMotd()); - node.node("playerCount", "hover").set(profile.getPlayers()); - node.node("playerCount", "text").set(profile.getPlayerCountText()); - node.node("favicon").set(profile.getFavicon()); - node.node("playerCount", "hidePlayers").set(profile.isHidePlayersEnabled()); - node.node("playerCount", "extraPlayers", "enabled").set(profile.isExtraPlayersEnabled()); - node.node("playerCount", "extraPlayers", "amount").set(profile.getExtraPlayersCount()); + node.node("motd").set(profile.motd()); + node.node("playerCount", "hover").set(profile.players()); + node.node("playerCount", "text").set(profile.playerCountText()); + node.node("favicon").set(profile.favicon()); + node.node("playerCount", "hidePlayers").set(profile.hidePlayersEnabled()); + node.node("playerCount", "extraPlayers", "enabled").set(profile.extraPlayersEnabled()); + node.node("playerCount", "extraPlayers", "amount").set(profile.extraPlayersCount()); } } diff --git a/docs/api/changelog.md b/docs/api/changelog.md index 87d9b2df..a6ca6a35 100644 --- a/docs/api/changelog.md +++ b/docs/api/changelog.md @@ -3,6 +3,13 @@ This page lists the recent changes made towards the AdvancedServerListAPI. They are ordered newest to oldest. +## v2.1.0 + +### :octicons-pencil-24:{ .changelog-changed title="Changed" } Changed { #v-changed } + +- Turned `ProfileEntry` class into a record + - Former `getX()` methods are now deprecated in favour of the recor's own `x()` methods (i.e. `getMotd()` -> `motd()`) + ## v2.0.0 ### :octicons-alert-24:{ .changelog-breaking title="Breaking Changes" } Breaking Changes { #v2-breaking } diff --git a/pom.xml b/pom.xml index e91379bb..b7dac32a 100644 --- a/pom.xml +++ b/pom.xml @@ -37,10 +37,10 @@ UTF-8 - 3.0.0-b1 + 3.0.0-b2 Create multiple Server lists based on conditions. - v2.0.0 + v2.1.0 16 16