mirror of
https://codeberg.org/Andre601/AdvancedServerList.git
synced 2026-11-05 17:02:34 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6392929298 | ||
|
|
0f7fb9b180 | ||
|
|
4b24da8409 | ||
|
|
afc32da0c3 |
No files matched your search
@@ -46,6 +46,7 @@ You can download AdvancedServerList on the following locations:
|
||||
- Custom MOTD.
|
||||
- Custom Player count text.
|
||||
- Custom hover for the player count hover.
|
||||
- Hide player count (Turn to `???`)
|
||||
- MiniMessage formatting for MOTD, player count and player count hover [[Read More][minimessage]]
|
||||
- Placeholder support [[Read More][placeholders]]
|
||||
|
||||
|
||||
+5
-11
@@ -96,14 +96,12 @@ public class ServerListProfile{
|
||||
for(String str : list){
|
||||
Expression expression = new Expression(str);
|
||||
|
||||
switch(expression.getResult()){
|
||||
case VALID -> expressions.add(expression);
|
||||
case INVALID_EMPTY_PARTS -> logInvalid(logger, str, "Either left or right part of condition was empty.");
|
||||
case INVALID_NO_EXPRESSION -> logInvalid(logger, str, "Empty conditions are not allowed.");
|
||||
case INVALID_DOUBLE_OPERATOR -> logInvalid(logger, str, "Condition had two operands!");
|
||||
case INVALID_BROKEN_NOT_EQUAL -> logInvalid(logger, str, "Found '!' without '=' following it.");
|
||||
default -> logInvalid(logger, str, "Encountered unknown issue.");
|
||||
if(expression.getResult() != Expression.ExpressionResult.VALID){
|
||||
logger.warn("Detected Invalid condition '%s'! Cause: %s", str, expression.getResult().getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
expressions.add(expression);
|
||||
}
|
||||
|
||||
return expressions;
|
||||
@@ -125,8 +123,4 @@ public class ServerListProfile{
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void logInvalid(PluginLogger logger, String expression, String reason){
|
||||
logger.warn("Invalid Condition '%s'! %s", expression, reason);
|
||||
}
|
||||
}
|
||||
+32
-18
@@ -42,8 +42,8 @@ public class Expression{
|
||||
}
|
||||
|
||||
public boolean evaluate(Map<String, Object> replacements){
|
||||
String newLeft = StringReplacer.replace(left, replacements);
|
||||
String newRight = StringReplacer.replace(right, replacements);
|
||||
String newLeft = StringReplacer.replace(left, replacements).trim();
|
||||
String newRight = StringReplacer.replace(right, replacements).trim();
|
||||
|
||||
return operator.evaluate(newLeft, newRight);
|
||||
}
|
||||
@@ -67,8 +67,10 @@ public class Expression{
|
||||
|
||||
for(int i = 0; i < chars.length; i++){
|
||||
char c = chars[i];
|
||||
char next = (i == (chars.length - 1)) ? '\0' : chars[i + 1];
|
||||
|
||||
if((c != '<' && c != '>' && c != '=' && c != '!') || i + 1 >= chars.length){
|
||||
Operator tmp = Operator.getOperand(c, next);
|
||||
if(tmp == Operator.UNKNOWN){
|
||||
if(foundOperator){
|
||||
right.append(c);
|
||||
}else{
|
||||
@@ -82,17 +84,8 @@ public class Expression{
|
||||
return;
|
||||
}
|
||||
|
||||
operator = tmp;
|
||||
foundOperator = true;
|
||||
|
||||
char next = chars[i + 1];
|
||||
if(c == '!' && next != '='){
|
||||
result = ExpressionResult.INVALID_BROKEN_NOT_EQUAL;
|
||||
return;
|
||||
}
|
||||
|
||||
operator = Operator.getOperand(c, next);
|
||||
if(operator.hasSecond() && operator != Operator.UNKNOWN)
|
||||
i++;
|
||||
}
|
||||
|
||||
if(left.isEmpty() || right.isEmpty()){
|
||||
@@ -198,11 +191,32 @@ public class Expression{
|
||||
}
|
||||
|
||||
public enum ExpressionResult{
|
||||
VALID,
|
||||
VALID{
|
||||
@Override
|
||||
public String getMessage(){
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
INVALID_NO_EXPRESSION,
|
||||
INVALID_DOUBLE_OPERATOR,
|
||||
INVALID_BROKEN_NOT_EQUAL,
|
||||
INVALID_EMPTY_PARTS
|
||||
INVALID_NO_EXPRESSION{
|
||||
@Override
|
||||
public String getMessage(){
|
||||
return "Received empty condition which isn't allowed!";
|
||||
}
|
||||
},
|
||||
INVALID_DOUBLE_OPERATOR{
|
||||
@Override
|
||||
public String getMessage(){
|
||||
return "Condition contained two operands.";
|
||||
}
|
||||
},
|
||||
INVALID_EMPTY_PARTS{
|
||||
@Override
|
||||
public String getMessage(){
|
||||
return "Received condition with either left or right part being empty.";
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String getMessage();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user