Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Bump API and plugin version for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Mar 29, 2023
1 parent 0c835da commit 3edef1c
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void handle(CmdSender sender){
core.clearPlayerCache();
sender.sendPrefixedMsg("<green>Successfully cleared Player Cache!");

sender.sendErrorMsg("<green>Reload complete!");
sender.sendPrefixedMsg("<green>Reload complete!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,43 +68,43 @@ public static <F, P extends GenericPlayer> 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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -109,52 +109,52 @@ public static boolean checkOption(Object obj){
}

private static List<String> 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<String> 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<String> resolveList(ConfigurationNode node, Object... path){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
7 changes: 7 additions & 0 deletions docs/api/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<plugin.version>3.0.0-b1</plugin.version>
<plugin.version>3.0.0-b2</plugin.version>
<plugin.description>Create multiple Server lists based on conditions.</plugin.description>

<api.version>v2.0.0</api.version>
<api.version>v2.1.0</api.version>

<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
Expand Down

0 comments on commit 3edef1c

Please sign in to comment.