mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-02-19 13:31:20 +01:00
Allow to display correctly the second line of a motd. Compacted code.
This commit is contained in:
parent
04bd6dca3f
commit
010b72fe7d
@ -5,12 +5,17 @@ public class BungeeServerInfo {
|
||||
private boolean isOnline;
|
||||
private int onlinePlayers;
|
||||
private int maxPlayers;
|
||||
private String motd; // Should never be null
|
||||
|
||||
// The two lines of a motd
|
||||
private String motd1; // Should never be null
|
||||
private String motd2; // Should never be null
|
||||
|
||||
private long lastRequest;
|
||||
|
||||
protected BungeeServerInfo() {
|
||||
isOnline = true;
|
||||
this.motd = "";
|
||||
this.motd1 = "";
|
||||
this.motd2 = "";
|
||||
updateLastRequest();
|
||||
}
|
||||
|
||||
@ -38,16 +43,29 @@ public class BungeeServerInfo {
|
||||
this.maxPlayers = maxPlayers;
|
||||
}
|
||||
|
||||
public String getMotd() {
|
||||
return motd;
|
||||
public String getMotd1() {
|
||||
return motd1;
|
||||
}
|
||||
|
||||
public String getMotd2() {
|
||||
return motd2;
|
||||
}
|
||||
|
||||
public void setMotd(String motd) {
|
||||
if (motd == null) {
|
||||
motd = "";
|
||||
this.motd1 = "";
|
||||
this.motd2 = "";
|
||||
return;
|
||||
}
|
||||
|
||||
this.motd = motd;
|
||||
if (motd.contains("\n")) {
|
||||
String[] split = motd.split("\n");
|
||||
this.motd1 = split[0];
|
||||
this.motd2 = split[1];
|
||||
} else {
|
||||
this.motd1 = motd;
|
||||
this.motd2 = "";
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastRequest() {
|
||||
|
@ -82,7 +82,7 @@ public class BungeeServerTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMotd(String server) {
|
||||
public static String getMotd1(String server) {
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
return "[Please enable pinger]";
|
||||
@ -91,7 +91,24 @@ public class BungeeServerTracker {
|
||||
BungeeServerInfo info = trackedServers.get(server);
|
||||
if (info != null) {
|
||||
info.updateLastRequest();
|
||||
return info.getMotd();
|
||||
return info.getMotd1();
|
||||
} else {
|
||||
// It was not tracked, add it.
|
||||
track(server);
|
||||
return "[Loading...]";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMotd2(String server) {
|
||||
|
||||
if (!Configuration.pingerEnable) {
|
||||
return "[Please enable pinger]";
|
||||
}
|
||||
|
||||
BungeeServerInfo info = trackedServers.get(server);
|
||||
if (info != null) {
|
||||
info.updateLastRequest();
|
||||
return info.getMotd2();
|
||||
} else {
|
||||
// It was not tracked, add it.
|
||||
track(server);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.gmail.filoghost.holographicdisplays.bridge.bungeecord.serverpinger;
|
||||
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
@ -21,7 +20,7 @@ public class ServerStatus
|
||||
|
||||
public ServerStatus(JSONObject json) {
|
||||
isOnline = true;
|
||||
motd = ((String) json.get("description")).replace("\n", "");
|
||||
motd = ((String) json.get("description"));
|
||||
|
||||
JSONObject playersJson = (JSONObject) json.get("players");
|
||||
onlinePlayers = ((Long) playersJson.get("online")).intValue();
|
||||
@ -44,11 +43,4 @@ public class ServerStatus
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServerStatus [motd=" + motd + ", onlinePlayers=" + onlinePlayers + ", maxPlayers=" + maxPlayers + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class PlaceholdersManager {
|
||||
private static final Pattern BUNGEE_ONLINE_PATTERN = makePlaceholderWithArgsPattern("online");
|
||||
private static final Pattern BUNGEE_MAX_PATTERN = makePlaceholderWithArgsPattern("max");
|
||||
private static final Pattern BUNGEE_MOTD_PATTERN = makePlaceholderWithArgsPattern("motd");
|
||||
private static final Pattern BUNGEE_MOTD_2_PATTERN = makePlaceholderWithArgsPattern("motd2");
|
||||
private static final Pattern BUNGEE_STATUS_PATTERN = makePlaceholderWithArgsPattern("status");
|
||||
private static final Pattern ANIMATION_PATTERN = makePlaceholderWithArgsPattern("animation");
|
||||
private static final Pattern WORLD_PATTERN = makePlaceholderWithArgsPattern("world");
|
||||
@ -115,10 +116,7 @@ public class PlaceholdersManager {
|
||||
// Lazy initialization.
|
||||
Set<Placeholder> normalPlaceholders = null;
|
||||
|
||||
Map<String, PlaceholderReplacer> bungeeOnlinePlayersReplacers = null;
|
||||
Map<String, PlaceholderReplacer> bungeeMaxPlayersReplacers = null;
|
||||
Map<String, PlaceholderReplacer> bungeeStatusReplacers = null;
|
||||
Map<String, PlaceholderReplacer> bungeeMotdReplacers = null;
|
||||
Map<String, PlaceholderReplacer> bungeeReplacers = null;
|
||||
|
||||
Map<String, PlaceholderReplacer> worldsOnlinePlayersReplacers = null;
|
||||
Map<String, Placeholder> animationsPlaceholders = null;
|
||||
@ -160,15 +158,15 @@ public class PlaceholdersManager {
|
||||
matcher = BUNGEE_ONLINE_PATTERN.matcher(name);
|
||||
while (matcher.find()) {
|
||||
|
||||
if (bungeeOnlinePlayersReplacers == null) {
|
||||
bungeeOnlinePlayersReplacers = Utils.newMap();
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = Utils.newMap();
|
||||
}
|
||||
|
||||
final String serverName = extractArgumentFromPlaceholder(matcher);
|
||||
BungeeServerTracker.track(serverName); // Track this server.
|
||||
|
||||
// Add it to tracked servers.
|
||||
bungeeOnlinePlayersReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
@ -181,15 +179,15 @@ public class PlaceholdersManager {
|
||||
matcher = BUNGEE_MAX_PATTERN.matcher(name);
|
||||
while (matcher.find()) {
|
||||
|
||||
if (bungeeMaxPlayersReplacers == null) {
|
||||
bungeeMaxPlayersReplacers = Utils.newMap();
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = Utils.newMap();
|
||||
}
|
||||
|
||||
final String serverName = extractArgumentFromPlaceholder(matcher);
|
||||
BungeeServerTracker.track(serverName); // Track this server.
|
||||
|
||||
// Add it to tracked servers.
|
||||
bungeeMaxPlayersReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
@ -202,19 +200,40 @@ public class PlaceholdersManager {
|
||||
matcher = BUNGEE_MOTD_PATTERN.matcher(name);
|
||||
while (matcher.find()) {
|
||||
|
||||
if (bungeeMotdReplacers == null) {
|
||||
bungeeMotdReplacers = Utils.newMap();
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = Utils.newMap();
|
||||
}
|
||||
|
||||
final String serverName = extractArgumentFromPlaceholder(matcher);
|
||||
BungeeServerTracker.track(serverName); // Track this server.
|
||||
|
||||
// Add it to tracked servers.
|
||||
bungeeMotdReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
return BungeeServerTracker.getMotd(serverName);
|
||||
return BungeeServerTracker.getMotd1(serverName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// BungeeCord motd (line 2) pattern.
|
||||
matcher = BUNGEE_MOTD_2_PATTERN.matcher(name);
|
||||
while (matcher.find()) {
|
||||
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = Utils.newMap();
|
||||
}
|
||||
|
||||
final String serverName = extractArgumentFromPlaceholder(matcher);
|
||||
BungeeServerTracker.track(serverName); // Track this server.
|
||||
|
||||
// Add it to tracked servers.
|
||||
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
return BungeeServerTracker.getMotd2(serverName);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -223,15 +242,15 @@ public class PlaceholdersManager {
|
||||
matcher = BUNGEE_STATUS_PATTERN.matcher(name);
|
||||
while (matcher.find()) {
|
||||
|
||||
if (bungeeStatusReplacers == null) {
|
||||
bungeeStatusReplacers = Utils.newMap();
|
||||
if (bungeeReplacers == null) {
|
||||
bungeeReplacers = Utils.newMap();
|
||||
}
|
||||
|
||||
final String serverName = extractArgumentFromPlaceholder(matcher);
|
||||
BungeeServerTracker.track(serverName); // Track this server.
|
||||
|
||||
// Add it to tracked servers.
|
||||
bungeeStatusReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
|
||||
|
||||
@Override
|
||||
public String update() {
|
||||
@ -263,7 +282,7 @@ public class PlaceholdersManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (Utils.isThereNonNull(normalPlaceholders, bungeeOnlinePlayersReplacers, bungeeMaxPlayersReplacers, bungeeMotdReplacers, bungeeStatusReplacers, worldsOnlinePlayersReplacers, animationsPlaceholders)) {
|
||||
if (Utils.isThereNonNull(normalPlaceholders, bungeeReplacers, worldsOnlinePlayersReplacers, animationsPlaceholders)) {
|
||||
|
||||
DynamicLineData lineData = new DynamicLineData(nameableEntity, name);
|
||||
|
||||
@ -271,20 +290,8 @@ public class PlaceholdersManager {
|
||||
lineData.setPlaceholders(normalPlaceholders);
|
||||
}
|
||||
|
||||
if (bungeeOnlinePlayersReplacers != null) {
|
||||
lineData.getReplacers().putAll(bungeeOnlinePlayersReplacers);
|
||||
}
|
||||
|
||||
if (bungeeMaxPlayersReplacers != null) {
|
||||
lineData.getReplacers().putAll(bungeeMaxPlayersReplacers);
|
||||
}
|
||||
|
||||
if (bungeeMotdReplacers != null) {
|
||||
lineData.getReplacers().putAll(bungeeMotdReplacers);
|
||||
}
|
||||
|
||||
if (bungeeStatusReplacers != null) {
|
||||
lineData.getReplacers().putAll(bungeeStatusReplacers);
|
||||
if (bungeeReplacers != null) {
|
||||
lineData.getReplacers().putAll(bungeeReplacers);
|
||||
}
|
||||
|
||||
if (worldsOnlinePlayersReplacers != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user