Little changes to the behaviour of the server checker

This commit is contained in:
Jaime Martínez Rincón 2017-12-25 20:53:46 +01:00
parent 8454bfaaad
commit 562bfec13a
6 changed files with 24 additions and 9 deletions

View File

@ -11,7 +11,7 @@
<name>PlayerBalancer Plugin</name>
<artifactId>playerbalancer-plugin</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>
<build>
<finalName>PlayerBalancer</finalName>

View File

@ -174,6 +174,7 @@ public class ManageCommand extends Command {
section.getServers().forEach(server -> {
ServerStatus status = plugin.getStatusManager().getStatus(server);
boolean accessible = plugin.getStatusManager().isAccessible(server);
sender.sendMessage(new ComponentBuilder("\u2022 Server: ")
.color(ChatColor.GRAY)
.append(server.getName())
@ -182,6 +183,10 @@ public class ManageCommand extends Command {
.color(ChatColor.GRAY)
.append(status.isOnline() ? "yes" : "no")
.color(status.isOnline() ? ChatColor.GREEN : ChatColor.RED)
.append("\nAccessible: ")
.color(ChatColor.GRAY)
.append(accessible ? "yes" : "no")
.color(accessible ? ChatColor.GREEN : ChatColor.RED)
.append("\nDescription: ")
.color(ChatColor.GRAY)
.append("\"")

View File

@ -1,5 +1,6 @@
package com.jaimemartz.playerbalancer.ping;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.config.ServerInfo;
public class ServerStatus {
@ -26,7 +27,7 @@ public class ServerStatus {
* @param server the server for providing basic info about itself
*/
public ServerStatus(ServerInfo server) {
this.description = server.getMotd();
this.description = revertColor(server.getMotd());
this.players = server.getPlayers().size();
this.maximum = Integer.MAX_VALUE;
this.online = true;
@ -40,7 +41,7 @@ public class ServerStatus {
* @param maximum the maximum amount of players possible from the ping result
*/
public ServerStatus(String description, int players, int maximum) {
this.description = description;
this.description = revertColor(description);
this.players = players;
this.maximum = maximum;
this.online = maximum != 0 && players < maximum;
@ -74,4 +75,8 @@ public class ServerStatus {
public void setOutdated(boolean outdated) {
this.outdated = outdated;
}
private static String revertColor(String string) {
return string.replace(ChatColor.COLOR_CHAR, '&');
}
}

View File

@ -5,7 +5,6 @@ import com.google.common.io.ByteStreams;
import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.section.ServerSection;
import com.jaimemartz.playerbalancer.settings.props.features.ServerCheckerProps;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
@ -77,8 +76,8 @@ public class StatusManager implements Listener {
if (props.isDebug()) {
plugin.getLogger().info(String.format(
"Updated server %s, status: [Description: \"%s\", Players: %s, Maximum Players: %s, Accessible: %s]",
server.getName(), ChatColor.stripColor(status.getDescription()), status.getPlayers(), status.getMaximum(), isAccessible(server)
"Updated server %s, status: [Description: \"%s\", Players: %s, Maximum Players: %s, Online: %s]",
server.getName(), status.getDescription(), status.getPlayers(), status.getMaximum(), status.isOnline()
));
}
@ -98,18 +97,23 @@ public class StatusManager implements Listener {
}
public boolean isAccessible(ServerInfo server) {
if (overriders.containsKey(server))
if (overriders.containsKey(server)) {
return overriders.get(server);
}
ServerStatus status = getStatus(server);
if (!status.isOnline()) {
return false;
}
for (String pattern : props.getMarkerDescs()) {
if (status.getDescription().matches(pattern)) {
return false;
}
}
return status.isOnline();
return true;
}
@EventHandler

View File

@ -139,6 +139,7 @@ features {
debug-info=false
# When the description of a server matches these, it will be set as non accessible
# Be aware of colors, it is recommended to use the "contains" rule below or some others
marker-descs=[
"(?i).*maintenance*" # match if contains (regex)
"Game in progress", # match if exactly equal

View File

@ -11,7 +11,7 @@
<name>PlayerBalancer Addon</name>
<artifactId>playerbalancer-addon</artifactId>
<version>1.2 for 2.1.2.0+</version>
<version>1.3 for 2.1.3+</version>
<build>
<finalName>PlayerBalancerAddon</finalName>