Skip to content

Commit 562bfec

Browse files
committed
Little changes to the behaviour of the server checker
1 parent 8454bfa commit 562bfec

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

Main Plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<name>PlayerBalancer Plugin</name>
1313
<artifactId>playerbalancer-plugin</artifactId>
14-
<version>2.1.3</version>
14+
<version>2.1.4</version>
1515

1616
<build>
1717
<finalName>PlayerBalancer</finalName>

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public void execute(CommandSender sender, String[] args) {
174174

175175
section.getServers().forEach(server -> {
176176
ServerStatus status = plugin.getStatusManager().getStatus(server);
177+
boolean accessible = plugin.getStatusManager().isAccessible(server);
177178
sender.sendMessage(new ComponentBuilder("\u2022 Server: ")
178179
.color(ChatColor.GRAY)
179180
.append(server.getName())
@@ -182,6 +183,10 @@ public void execute(CommandSender sender, String[] args) {
182183
.color(ChatColor.GRAY)
183184
.append(status.isOnline() ? "yes" : "no")
184185
.color(status.isOnline() ? ChatColor.GREEN : ChatColor.RED)
186+
.append("\nAccessible: ")
187+
.color(ChatColor.GRAY)
188+
.append(accessible ? "yes" : "no")
189+
.color(accessible ? ChatColor.GREEN : ChatColor.RED)
185190
.append("\nDescription: ")
186191
.color(ChatColor.GRAY)
187192
.append("\"")

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/ServerStatus.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.jaimemartz.playerbalancer.ping;
22

3+
import net.md_5.bungee.api.ChatColor;
34
import net.md_5.bungee.api.config.ServerInfo;
45

56
public class ServerStatus {
@@ -26,7 +27,7 @@ public ServerStatus() {
2627
* @param server the server for providing basic info about itself
2728
*/
2829
public ServerStatus(ServerInfo server) {
29-
this.description = server.getMotd();
30+
this.description = revertColor(server.getMotd());
3031
this.players = server.getPlayers().size();
3132
this.maximum = Integer.MAX_VALUE;
3233
this.online = true;
@@ -40,7 +41,7 @@ public ServerStatus(ServerInfo server) {
4041
* @param maximum the maximum amount of players possible from the ping result
4142
*/
4243
public ServerStatus(String description, int players, int maximum) {
43-
this.description = description;
44+
this.description = revertColor(description);
4445
this.players = players;
4546
this.maximum = maximum;
4647
this.online = maximum != 0 && players < maximum;
@@ -74,4 +75,8 @@ public boolean isOutdated() {
7475
public void setOutdated(boolean outdated) {
7576
this.outdated = outdated;
7677
}
78+
79+
private static String revertColor(String string) {
80+
return string.replace(ChatColor.COLOR_CHAR, '&');
81+
}
7782
}

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.jaimemartz.playerbalancer.PlayerBalancer;
66
import com.jaimemartz.playerbalancer.section.ServerSection;
77
import com.jaimemartz.playerbalancer.settings.props.features.ServerCheckerProps;
8-
import net.md_5.bungee.api.ChatColor;
98
import net.md_5.bungee.api.config.ServerInfo;
109
import net.md_5.bungee.api.connection.Server;
1110
import net.md_5.bungee.api.event.PluginMessageEvent;
@@ -77,8 +76,8 @@ private void update(ServerInfo server) {
7776

7877
if (props.isDebug()) {
7978
plugin.getLogger().info(String.format(
80-
"Updated server %s, status: [Description: \"%s\", Players: %s, Maximum Players: %s, Accessible: %s]",
81-
server.getName(), ChatColor.stripColor(status.getDescription()), status.getPlayers(), status.getMaximum(), isAccessible(server)
79+
"Updated server %s, status: [Description: \"%s\", Players: %s, Maximum Players: %s, Online: %s]",
80+
server.getName(), status.getDescription(), status.getPlayers(), status.getMaximum(), status.isOnline()
8281
));
8382
}
8483

@@ -98,18 +97,23 @@ public ServerStatus getStatus(ServerInfo server) {
9897
}
9998

10099
public boolean isAccessible(ServerInfo server) {
101-
if (overriders.containsKey(server))
100+
if (overriders.containsKey(server)) {
102101
return overriders.get(server);
102+
}
103103

104104
ServerStatus status = getStatus(server);
105105

106+
if (!status.isOnline()) {
107+
return false;
108+
}
109+
106110
for (String pattern : props.getMarkerDescs()) {
107111
if (status.getDescription().matches(pattern)) {
108112
return false;
109113
}
110114
}
111115

112-
return status.isOnline();
116+
return true;
113117
}
114118

115119
@EventHandler

Main Plugin/src/main/resources/default.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ features {
139139
debug-info=false
140140

141141
# When the description of a server matches these, it will be set as non accessible
142+
# Be aware of colors, it is recommended to use the "contains" rule below or some others
142143
marker-descs=[
143144
"(?i).*maintenance*" # match if contains (regex)
144145
"Game in progress", # match if exactly equal

Spigot Addon/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<name>PlayerBalancer Addon</name>
1313
<artifactId>playerbalancer-addon</artifactId>
14-
<version>1.2 for 2.1.2.0+</version>
14+
<version>1.3 for 2.1.3+</version>
1515

1616
<build>
1717
<finalName>PlayerBalancerAddon</finalName>

0 commit comments

Comments
 (0)