Compare commits

...
9 Commits
Author SHA1 Message Date
Andre_601 f5d2fd1534 Merge pull request #39 from Andre601/feature/multiple-motds
Add option to have multiple MOTDs.
2022-12-20 22:22:49 +01:00
Andre601 90537eb004 Bump Version for release 2022-12-20 22:22:14 +01:00
Andre601 ce6a9e3b0b Use a Builder class to make ServerListProfile immutable... I guess? 2022-12-18 21:32:35 +01:00
Andre601 4d29f9e45e Add option to have multiple MOTDs. 2022-12-18 17:45:38 +01:00
Andre601 bf49636d6a Update workflow 2022-12-09 22:27:44 +01:00
Andre601 4a6c9a55d4 Update required libraries 2022-12-09 22:26:44 +01:00
Andre601 a5bfc0b6e3 Smaller format correction + version bump 2022-12-09 22:23:24 +01:00
Andre_601 dff332a83a Merge pull request #37 from Andre601/dependabot/maven/spigot/net.kyori-adventure-platform-bukkit-4.2.0
Bump adventure-platform-bukkit from 4.1.2 to 4.2.0 in /spigot
2022-12-09 16:10:29 +01:00
dependabot[bot] 58a16baaab Bump adventure-platform-bukkit from 4.1.2 to 4.2.0 in /spigot
Bumps [adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.1.2 to 4.2.0.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.1.2...v4.2.0)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-09 15:08:40 +00:00
10 changed files with 228 additions and 78 deletions

No files matched your search

+1
View File
@@ -96,6 +96,7 @@ jobs:
1.19
1.19.1
1.19.2
1.19.3
java: 16
modrinth-id: xss83sOY
modrinth-featured: false
@@ -70,23 +70,27 @@ public class PingEventHandler{
serverPlaceholders = new ServerPlaceholders(online, max, host);
if(!profile.getMotd().isEmpty()){
event.setMotd(
ComponentParser.list(profile.getMotd())
.replacements(playerPlaceholders)
.replacements(serverPlaceholders)
.modifyText(text -> event.parsePAPIPlaceholders(text, player))
.toComponent()
);
if(!profile.getMOTDs().isEmpty()){
ServerListProfile.Motd motd = profile.getRandomMOTD();
if(motd != null){
event.setMotd(
ComponentParser.text(motd.getText())
.replacements(playerPlaceholders)
.replacements(serverPlaceholders)
.modifyText(text -> event.parsePAPIPlaceholders(text, player))
.toComponent()
);
}
}
if(profile.shouldHidePlayers()){
if(profile.isHidePlayersEnabled()){
event.hidePlayers();
}
if(!profile.getPlayerCount().isEmpty() && !profile.shouldHidePlayers()){
if(!profile.getPlayerCountText().isEmpty() && !profile.isHidePlayersEnabled()){
event.setPlayerCount(
ComponentParser.text(profile.getPlayerCount())
ComponentParser.text(profile.getPlayerCountText())
.replacements(playerPlaceholders)
.replacements(serverPlaceholders)
.modifyText(text -> event.parsePAPIPlaceholders(text, player))
@@ -94,7 +98,7 @@ public class PingEventHandler{
);
}
if(!profile.getPlayers().isEmpty() && !profile.shouldHidePlayers()){
if(!profile.getPlayers().isEmpty() && !profile.isHidePlayersEnabled()){
event.setPlayers(profile.getPlayers(), player, playerPlaceholders, serverPlaceholders);
}
@@ -127,7 +127,7 @@ public class FileHandler{
if(tmp == null)
continue;
profiles.add(new ServerListProfile(tmp, logger));
profiles.add(ServerListProfile.Builder.resolve(tmp, logger).build());
logger.info("Loaded " + file.getName());
}
@@ -52,10 +52,10 @@ public class ProfileManager{
public ServerListProfile getProfile(){
for(ServerListProfile profile : core.getFileHandler().getProfiles()){
if(profile.isInvalid())
if(profile.isInvalidProfile())
continue;
if(profile.evalConditions(replacements))
if(profile.evaluateConditions(replacements))
return profile;
}
@@ -30,17 +30,14 @@ import ch.andre601.advancedserverlist.core.profiles.conditions.Expression;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ServerListProfile{
private final int priority;
private final List<Expression> expressions;
private final List<String> motd;
private final List<Motd> motds;
private final List<String> players;
private final String playerCount;
private final String favicon;
@@ -48,32 +45,47 @@ public class ServerListProfile{
private final boolean extraPlayersEnabled;
private final int extraPlayers;
public ServerListProfile(ConfigurationNode node, PluginLogger logger){
this.priority = node.node("priority").getInt();
this.expressions = createExpressions(getList(node, false, "conditions"), logger);
this.motd = getList(node, true, "motd");
this.players = getList(node, false, "playerCount", "hover");
this.playerCount = node.node("playerCount", "text").getString("");
this.favicon = node.node("favicon").getString("");
this.hidePlayers = node.node("playerCount", "hidePlayers").getBoolean();
this.extraPlayersEnabled = node.node("playerCount", "extraPlayers", "enabled").getBoolean();
this.extraPlayers = node.node("playerCount", "extraPlayers", "amount").getInt();
private final Random random = new Random();
public ServerListProfile(int priority, List<Expression> expressions, List<Motd> motds, List<String> players,
String playerCount, String favicon, boolean hidePlayers, boolean extraPlayersEnabled,
int extraPlayers){
this.priority = priority;
this.expressions = expressions;
this.motds = motds;
this.players = players;
this.playerCount = playerCount;
this.favicon = favicon;
this.hidePlayers = hidePlayers;
this.extraPlayersEnabled = extraPlayersEnabled;
this.extraPlayers = extraPlayers;
}
public int getPriority(){
return priority;
}
public List<String> getMotd(){
return motd;
public List<Motd> getMOTDs(){
return motds;
}
public Motd getRandomMOTD(){
if(motds.isEmpty())
return null;
if(motds.size() == 1)
return motds.get(0);
synchronized(random){
return motds.get(random.nextInt(motds.size()));
}
}
public List<String> getPlayers(){
return players;
}
public String getPlayerCount(){
public String getPlayerCountText(){
return playerCount;
}
@@ -81,7 +93,7 @@ public class ServerListProfile{
return favicon;
}
public boolean shouldHidePlayers(){
public boolean isHidePlayersEnabled(){
return hidePlayers;
}
@@ -93,59 +105,191 @@ public class ServerListProfile{
return extraPlayers;
}
public boolean evalConditions(Map<String, Object> replacements){
public boolean evaluateConditions(Map<String, Object> replacements){
if(expressions.isEmpty())
return true;
for(Expression expression : expressions){
if(!expression.evaluate(replacements)){
if(!expression.evaluate(replacements))
return false;
}
}
return true;
}
public boolean isInvalid(){
return getMotd().isEmpty() &&
/*
* Returns true if the Profile...
* ...doesn't have any valid MOTD set AND
* ...doesn't have any player hover set AND
* ...doesn't have a player count text set and hidePlayers is false AND
* ...doesn't have a favicon set.
*/
public boolean isInvalidProfile(){
return getMOTDs().isEmpty() &&
getPlayers().isEmpty() &&
(getPlayerCount().isEmpty() && !shouldHidePlayers()) &&
(getPlayerCountText().isEmpty() && !isHidePlayersEnabled()) &&
getFavicon().isEmpty();
}
private List<Expression> createExpressions(List<String> list, PluginLogger logger) {
if(list.isEmpty())
return Collections.emptyList();
public static class Builder{
List<Expression> expressions = new ArrayList<>();
for(String str : list){
Expression expression = new Expression(str);
private final ConfigurationNode node;
private final int priority;
private final PluginLogger logger;
private final List<Expression> expressions = new ArrayList<>();
private final List<Motd> motds = new ArrayList<>();
private List<String> players = new ArrayList<>();
private String playerCount = null;
private String favicon = null;
private boolean hidePlayers = false;
private boolean extraPlayersEnabled = false;
private int extraPlayers = 0;
private Builder(ConfigurationNode node, PluginLogger logger){
this.node = node;
this.priority = node.node("priority").getInt();
this.logger = logger;
}
public static Builder resolve(ConfigurationNode node, PluginLogger logger){
return new Builder(node, logger)
.resolveExpressions()
.resolveMOTDs()
.resolvePlayers()
.resolvePlayerCount()
.resolveFavicon()
.resolveHidePlayers()
.resolveExtraPlayers()
.resolveExtraPlayersCount();
}
private Builder resolveExpressions(){
List<String> list = getList("conditions");
if(list.isEmpty())
return this;
if(expression.getResult() != Expression.ExpressionResult.VALID){
logger.warn("Detected Invalid condition '%s'! Cause: %s", str, expression.getResult().getMessage());
continue;
for(String str : list){
Expression expression = new Expression(str);
if(expression.getResult() != Expression.ExpressionResult.VALID){
logger.warn("Detected invalid expression in condition '%s'! Reason: %s", str, expression.getResult().getMessage());
continue;
}
this.expressions.add(expression);
}
expressions.add(expression);
return this;
}
private Builder resolveMOTDs(){
List<String> list = getList("motds");
if(!list.isEmpty()){
for(String lines : list){
Motd motd = Motd.resolve(lines);
if(motd == null)
continue;
this.motds.add(motd);
}
return this;
}
list = getList("motd");
if(list.isEmpty())
return this;
Motd motd = Motd.resolve(list);
if(motd == null)
return this;
this.motds.add(motd);
return this;
}
private Builder resolvePlayers(){
this.players = getList("playerCount", "hover");
return this;
}
private Builder resolvePlayerCount(){
this.playerCount = node.node("playerCount", "text").getString("");
return this;
}
private Builder resolveFavicon(){
this.favicon = node.node("favicon").getString("");
return this;
}
private Builder resolveHidePlayers(){
this.hidePlayers = node.node("playerCount", "hidePlayers").getBoolean();
return this;
}
private Builder resolveExtraPlayers(){
this.extraPlayersEnabled = node.node("playerCount", "extraPlayers", "enabled").getBoolean();
return this;
}
private Builder resolveExtraPlayersCount(){
this.extraPlayers = node.node("playerCount", "extraPlayers", "amount").getInt();
return this;
}
public ServerListProfile build(){
return new ServerListProfile(this.priority, this.expressions, this.motds, this.players, this.playerCount,
this.favicon, this.hidePlayers, this.extraPlayersEnabled, this.extraPlayers);
}
return expressions;
private List<String> getList(Object... path){
List<String> temp;
try{
temp = node.node(path).getList(String.class);
}catch(SerializationException ex){
temp = null;
}
if(temp == null)
return Collections.emptyList();
return temp;
}
}
private List<String> getList(ConfigurationNode node, boolean trim, Object... path){
List<String> list;
try{
list = node.node(path).getList(String.class);
}catch(SerializationException ex){
return Collections.emptyList();
public static class Motd{
String text;
private Motd(String[] lines){
text = resolveLines(lines);
}
if(list == null)
return Collections.emptyList();
public static Motd resolve(String text){
String[] split = text.split("\n");
if(split.length == 0)
return null;
return new Motd(split);
}
if(trim && list.size() > 2)
return list.subList(0, 2);
return list;
public static Motd resolve(List<String> lines){
if(lines.size() == 0)
return null;
return new Motd(lines.toArray(new String[0]));
}
public String getText(){
return text;
}
private String resolveLines(String[] lines){
if(lines.length > 2)
return String.join("\n", lines[0], lines[1]);
return String.join("\n", lines);
}
}
}
@@ -192,8 +192,8 @@ public class Expression{
public enum ExpressionResult{
VALID(null),
INVALID_NO_EXPRESSION ("Received empty condition which isn't allowed!"),
INVALID_EMPTY_PARTS ("Received condition with either left or right part being empty.");
INVALID_NO_EXPRESSION("Received empty condition which isn't allowed!"),
INVALID_EMPTY_PARTS ("Received condition with either left or right part being empty.");
private final String message;
+7 -6
View File
@@ -16,16 +16,17 @@ priority: 0
# - '{playerVersion} < 759'
#
# Set the MOTD that should be displayed.
# Set the MOTDs that should be displayed.
# Supports HEX colors for 1.16+ servers including gradients using MiniMessage's <gradient:color:color> format.
#
# Remove this option or set it to motd: [] to not alter the MOTD.
# Remove this option or set it to motds: [] to not alter the MOTD.
#
# Read more: https://github.com/Andre601/AdvancedServerList/wiki/Profiles#motd
# Read more: https://github.com/Andre601/AdvancedServerList/wiki/Profiles#motds
#
motd:
- '<grey>Line 1'
- '<grey>Line 2'
motds:
- |-
<grey>Line 1
<grey>Line 2
#
# Allows you to set a favicon for this server list profile.
+1 -1
View File
@@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.version>1.8.0</plugin.version>
<plugin.version>1.9.0</plugin.version>
<plugin.description>Create multiple Server lists based on conditions.</plugin.description>
<maven.compiler.source>16</maven.compiler.source>
+1 -1
View File
@@ -74,7 +74,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.1.2</version>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
+4 -4
View File
@@ -9,10 +9,10 @@ api-version: 1.19
libraries:
- 'org.spongepowered:configurate-yaml:4.1.2'
- 'net.kyori:adventure-api:4.11.0'
- 'net.kyori:adventure-text-minimessage:4.11.0'
- 'net.kyori:adventure-text-serializer-legacy:4.11.0'
- 'net.kyori:adventure-platform-bukkit:4.1.2'
- 'net.kyori:adventure-api:4.12.0'
- 'net.kyori:adventure-text-minimessage:4.12.0'
- 'net.kyori:adventure-text-serializer-legacy:4.12.0'
- 'net.kyori:adventure-platform-bukkit:4.2.0'
- 'com.squareup.okhttp3:okhttp:4.10.0'
softdepend: