Sanitized Server.Name setting in a shit way that will need refactoring at some point #472

This commit is contained in:
Rsl1122 2017-12-16 12:27:00 +02:00
parent 2e6d01eab3
commit 598fdc5d72
7 changed files with 12 additions and 9 deletions

View File

@ -69,7 +69,7 @@ public class AnalysisData extends RawData {
addValue("version", MiscUtils.getIPlan().getVersion()); addValue("version", MiscUtils.getIPlan().getVersion());
addValue("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE)); addValue("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE));
addValue("gmPieColors", Theme.getValue(ThemeVal.GRAPH_GM_PIE)); addValue("gmPieColors", Theme.getValue(ThemeVal.GRAPH_GM_PIE));
addValue("serverName", Settings.SERVER_NAME.toString()); addValue("serverName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
addValue("refresh", FormatUtils.formatTimeStamp(refreshDate)); addValue("refresh", FormatUtils.formatTimeStamp(refreshDate));

View File

@ -155,7 +155,6 @@ public class BukkitInformationManager extends InformationManager {
cacheInspectPluginsTab(uuid, origin); cacheInspectPluginsTab(uuid, origin);
} }
} else { } else {
String serverName = plugin.getServerInfoManager().getServerName();
HookHandler hookHandler = plugin.getHookHandler(); HookHandler hookHandler = plugin.getHookHandler();
List<PluginData> plugins = hookHandler.getAdditionalDataSources(); List<PluginData> plugins = hookHandler.getAdditionalDataSources();
Map<PluginData, InspectContainer> containers = new HashMap<>(); Map<PluginData, InspectContainer> containers = new HashMap<>();

View File

@ -235,7 +235,7 @@ public class InspectPageParser extends PageParser {
addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp())); addValue("playerStatus", HtmlStructure.playerStatus(online, profile.getBannedOnServers(), profile.isOp()));
if (!plugin.getInfoManager().isUsingAnotherWebServer()) { if (!plugin.getInfoManager().isUsingAnotherWebServer()) {
addValue("networkName", Settings.SERVER_NAME.toString()); addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
} }
return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/player.html"), placeHolders); return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/player.html"), placeHolders);

View File

@ -59,7 +59,7 @@ public class BukkitServerInfoManager {
registerServer(serverUUID); registerServer(serverUUID);
return; return;
} }
String name = Settings.SERVER_NAME.toString(); String name = Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_");
String webAddress = plugin.getWebServer().getAccessAddress(); String webAddress = plugin.getWebServer().getAccessAddress();
if ("plan".equalsIgnoreCase(name)) { if ("plan".equalsIgnoreCase(name)) {
name = "Server " + serverID.get(); name = "Server " + serverID.get();
@ -76,7 +76,7 @@ public class BukkitServerInfoManager {
private void registerServer(UUID serverUUID) throws SQLException, IOException { private void registerServer(UUID serverUUID) throws SQLException, IOException {
String webAddress = plugin.getWebServer().getAccessAddress(); String webAddress = plugin.getWebServer().getAccessAddress();
String name = Settings.SERVER_NAME.toString(); String name = Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_");
int maxPlayers = plugin.getVariable().getMaxPlayers(); int maxPlayers = plugin.getVariable().getMaxPlayers();
serverInfo = new ServerInfo(-1, serverUUID, name, webAddress, maxPlayers); serverInfo = new ServerInfo(-1, serverUUID, name, webAddress, maxPlayers);
serverTable.saveCurrentServerInfo(serverInfo); serverTable.saveCurrentServerInfo(serverInfo);

View File

@ -37,7 +37,7 @@ public class PlayersPageResponse extends Response {
Collections.sort(names); Collections.sort(names);
Map<String, String> replace = new HashMap<>(); Map<String, String> replace = new HashMap<>();
if (Check.isBukkitAvailable()) { if (Check.isBukkitAvailable()) {
replace.put("networkName", Settings.SERVER_NAME.toString()); replace.put("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
} else { } else {
replace.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString()); replace.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString());
} }

View File

@ -50,7 +50,7 @@ public class PostOriginalBukkitSettingsWebAPI extends WebAPI {
@Override @Override
public void sendRequest(String address) throws WebAPIException { public void sendRequest(String address) throws WebAPIException {
addVariable("WebServerPort", Integer.toString(Settings.WEBSERVER_PORT.getNumber())); addVariable("WebServerPort", Integer.toString(Settings.WEBSERVER_PORT.getNumber()));
addVariable("ServerName", Settings.SERVER_NAME.toString()); addVariable("ServerName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_"));
addVariable("ThemeBase", Settings.THEME_BASE.toString()); addVariable("ThemeBase", Settings.THEME_BASE.toString());
super.sendRequest(address); super.sendRequest(address);
} }

View File

@ -38,6 +38,7 @@ public class ServerAccordionCreator {
"</div>", ""}; "</div>", ""};
} }
int i = 0;
for (Map.Entry<UUID, WorldTimes> entry : worldTimesPerServer.entrySet()) { for (Map.Entry<UUID, WorldTimes> entry : worldTimesPerServer.entrySet()) {
UUID serverUUID = entry.getKey(); UUID serverUUID = entry.getKey();
String serverName = serverNames.getOrDefault(serverUUID, "Unknown"); String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
@ -60,7 +61,8 @@ public class ServerAccordionCreator {
String longest = sessionCount != 0 ? FormatUtils.formatTimeAmount(longestSession) : "-"; String longest = sessionCount != 0 ? FormatUtils.formatTimeAmount(longestSession) : "-";
String sanitizedServerName = new Format(serverName) String sanitizedServerName = new Format(serverName)
.removeSymbols().removeWhitespace().toString(); .removeSymbols()
.removeWhitespace().toString() + i;
String htmlID = "server_" + sanitizedServerName; String htmlID = "server_" + sanitizedServerName;
String worldId = "worldPieServer" + sanitizedServerName; String worldId = "worldPieServer" + sanitizedServerName;
@ -116,6 +118,8 @@ public class ServerAccordionCreator {
.append(worldId).append("series, ") .append(worldId).append("series, ")
.append(worldId).append("gmseries") .append(worldId).append("gmseries")
.append(");"); .append(");");
i++;
} }
return new String[]{html.append("</div>").toString(), viewScript.toString()}; return new String[]{html.append("</div>").toString(), viewScript.toString()};
} }