From 41c1be42628766e23170030986ae767e536d61f3 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Tue, 8 Jun 2021 08:17:12 +0200 Subject: [PATCH 1/4] Only listen for Geyser news --- .../main/java/org/geysermc/connector/utils/Constants.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/Constants.java b/connector/src/main/java/org/geysermc/connector/utils/Constants.java index a0cc9bf80..2a47a5bce 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Constants.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Constants.java @@ -27,18 +27,14 @@ package org.geysermc.connector.utils; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.Set; public final class Constants { public static final URI GLOBAL_API_WS_URI; public static final String NTP_SERVER = "time.cloudflare.com"; - public static final Set NEWS_PROJECT_LIST = Collections.unmodifiableSet( - new HashSet<>(Arrays.asList("geyser", "floodgate")) - ); + public static final Set NEWS_PROJECT_LIST = Collections.singleton("geyser"); public static final String NEWS_OVERVIEW_URL = "https://api.geysermc.org/v1/news"; From 1eef152f43992e0ccfb16b72df8236d3a268b71c Mon Sep 17 00:00:00 2001 From: Tim203 Date: Tue, 8 Jun 2021 10:04:40 +0200 Subject: [PATCH 2/4] Added Java Version to the metrics --- .../geysermc/connector/GeyserConnector.java | 36 +++++++++++++++++++ .../geysermc/connector/metrics/Metrics.java | 5 --- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 946e699fb..1d11c52d9 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -81,6 +81,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Getter public class GeyserConnector { @@ -330,6 +332,40 @@ public class GeyserConnector { return versionMap; })); } + + // The following code can be attributed to the PaperMC project + // https://github.com/PaperMC/Paper/blob/master/Spigot-Server-Patches/0005-Paper-Metrics.patch#L614 + metrics.addCustomChart(new Metrics.DrilldownPie("javaVersion", () -> { + Map> map = new HashMap<>(); + String javaVersion = System.getProperty("java.version"); + Map entry = new HashMap<>(); + entry.put(javaVersion, 1); + + // http://openjdk.java.net/jeps/223 + // Java decided to change their versioning scheme and in doing so modified the + // java.version system property to return $major[.$minor][.$security][-ea], as opposed to + // 1.$major.0_$identifier we can handle pre-9 by checking if the "major" is equal to "1", + // otherwise, 9+ + String majorVersion = javaVersion.split("\\.")[0]; + String release; + + int indexOf = javaVersion.lastIndexOf('.'); + + if (majorVersion.equals("1")) { + release = "Java " + javaVersion.substring(0, indexOf); + } else { + // of course, it really wouldn't be all that simple if they didn't add a quirk, now + // would it valid strings for the major may potentially include values such as -ea to + // denote a pre release + Matcher versionMatcher = Pattern.compile("\\d+").matcher(majorVersion); + if (versionMatcher.find()) { + majorVersion = versionMatcher.group(0); + } + release = "Java " + majorVersion; + } + map.put(release, entry); + return map; + })); } boolean isGui = false; diff --git a/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java b/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java index 1457780b1..6ebca3f8c 100644 --- a/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java +++ b/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java @@ -152,20 +152,15 @@ public class Metrics { */ private ObjectNode getServerData() { // OS specific data - int playerAmount = connector.getPlayers().size(); - String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String osVersion = System.getProperty("os.version"); - String javaVersion = System.getProperty("java.version"); int coreCount = Runtime.getRuntime().availableProcessors(); ObjectNode data = mapper.createObjectNode(); data.put("serverUUID", serverUUID); - data.put("playerAmount", playerAmount); - data.put("javaVersion", javaVersion); data.put("osName", osName); data.put("osArch", osArch); data.put("osVersion", osVersion); From 68cd2eb4f1f66aaafabd02a33a5ed0ad8b07ae24 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Tue, 8 Jun 2021 10:12:52 +0200 Subject: [PATCH 3/4] Moved Floodgate dump info to one class --- .../floodgate/util/FloodgateConfigHolder.java | 35 ------------------- ...esHolder.java => FloodgateInfoHolder.java} | 6 +++- .../org/geysermc/connector/dump/DumpInfo.java | 7 ++-- 3 files changed, 8 insertions(+), 40 deletions(-) delete mode 100644 common/src/main/java/org/geysermc/floodgate/util/FloodgateConfigHolder.java rename common/src/main/java/org/geysermc/floodgate/util/{FloodgateGitPropertiesHolder.java => FloodgateInfoHolder.java} (93%) diff --git a/common/src/main/java/org/geysermc/floodgate/util/FloodgateConfigHolder.java b/common/src/main/java/org/geysermc/floodgate/util/FloodgateConfigHolder.java deleted file mode 100644 index d33840bb4..000000000 --- a/common/src/main/java/org/geysermc/floodgate/util/FloodgateConfigHolder.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2019-2021 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.floodgate.util; - -import lombok.Getter; -import lombok.Setter; - -public final class FloodgateConfigHolder { - @Getter - @Setter - private static Object config; -} diff --git a/common/src/main/java/org/geysermc/floodgate/util/FloodgateGitPropertiesHolder.java b/common/src/main/java/org/geysermc/floodgate/util/FloodgateInfoHolder.java similarity index 93% rename from common/src/main/java/org/geysermc/floodgate/util/FloodgateGitPropertiesHolder.java rename to common/src/main/java/org/geysermc/floodgate/util/FloodgateInfoHolder.java index 5f157aceb..c7a681f9d 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/FloodgateGitPropertiesHolder.java +++ b/common/src/main/java/org/geysermc/floodgate/util/FloodgateInfoHolder.java @@ -27,9 +27,13 @@ package org.geysermc.floodgate.util; import lombok.Getter; import lombok.Setter; + import java.util.Properties; -public class FloodgateGitPropertiesHolder { +public final class FloodgateInfoHolder { + @Getter + @Setter + private static Object config; @Getter @Setter private static Properties gitProperties; diff --git a/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java b/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java index f83598469..fee4ac7a4 100644 --- a/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java +++ b/connector/src/main/java/org/geysermc/connector/dump/DumpInfo.java @@ -42,8 +42,7 @@ import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.DockerCheck; import org.geysermc.connector.utils.FileUtils; import org.geysermc.floodgate.util.DeviceOs; -import org.geysermc.floodgate.util.FloodgateConfigHolder; -import org.geysermc.floodgate.util.FloodgateGitPropertiesHolder; +import org.geysermc.floodgate.util.FloodgateInfoHolder; import java.io.File; import java.io.IOException; @@ -184,8 +183,8 @@ public class DumpInfo { private final Object config; Floodgate() { - this.gitInfo = FloodgateGitPropertiesHolder.getGitProperties(); - this.config = FloodgateConfigHolder.getConfig(); + this.gitInfo = FloodgateInfoHolder.getGitProperties(); + this.config = FloodgateInfoHolder.getConfig(); } } From acc3a8222ac1e90e3b70c67df8db8ac3773674de Mon Sep 17 00:00:00 2001 From: Tim203 Date: Tue, 8 Jun 2021 12:53:00 +0200 Subject: [PATCH 4/4] Check if item is active and added global items --- .../src/main/java/org/geysermc/floodgate/news/NewsItem.java | 4 ++++ .../main/java/org/geysermc/connector/utils/NewsHandler.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java b/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java index 2f6bb4852..be0634a6d 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java +++ b/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java @@ -100,6 +100,10 @@ public final class NewsItem { return project; } + public boolean isGlobal() { + return "all".equals(getProject()); + } + public boolean isActive() { return active; } diff --git a/connector/src/main/java/org/geysermc/connector/utils/NewsHandler.java b/connector/src/main/java/org/geysermc/connector/utils/NewsHandler.java index aa8fe2efc..fb945edc6 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/NewsHandler.java +++ b/connector/src/main/java/org/geysermc/connector/utils/NewsHandler.java @@ -142,7 +142,11 @@ public class NewsHandler { return; } - if (!Constants.NEWS_PROJECT_LIST.contains(item.getProject())) { + if (!item.isActive()) { + return; + } + + if (!item.isGlobal() && !Constants.NEWS_PROJECT_LIST.contains(item.getProject())) { return; }