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/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/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/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(); } } 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); 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"; 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; }