3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-08 10:50:11 +02:00

Add more metrics (#1896)

- Add the Java version being used
- Add the Minecraft server version being used, alongside the platform type that is using that version. Not used for proxies as those have to be on latest to support the latest Minecraft version
Dieser Commit ist enthalten in:
Camotoy 2021-02-03 19:54:35 -05:00 committet von GitHub
Ursprung 254990148c
Commit c26a2baed6
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 53 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -69,6 +69,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
private GeyserConnector connector; private GeyserConnector connector;
/**
* The Minecraft server version, formatted as <code>1.#.#</code>
*/
private String minecraftVersion;
@Override @Override
public void onEnable() { public void onEnable() {
// This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed // This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed
@ -118,6 +123,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
geyserConfig.loadFloodgate(this); geyserConfig.loadFloodgate(this);
// Turn "(MC: 1.16.4)" into 1.16.4.
this.minecraftVersion = Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
this.connector = GeyserConnector.start(PlatformType.SPIGOT, this); this.connector = GeyserConnector.start(PlatformType.SPIGOT, this);
if (geyserConfig.isLegacyPingPassthrough()) { if (geyserConfig.isLegacyPingPassthrough()) {
@ -239,6 +247,11 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
return new GeyserSpigotDumpInfo(); return new GeyserSpigotDumpInfo();
} }
@Override
public String getMinecraftServerVersion() {
return this.minecraftVersion;
}
public boolean isCompatible(String version, String whichVersion) { public boolean isCompatible(String version, String whichVersion) {
int[] currentVersion = parseVersion(version); int[] currentVersion = parseVersion(version);
int[] otherVersion = parseVersion(whichVersion); int[] otherVersion = parseVersion(whichVersion);
@ -277,10 +290,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
* @return the server version before ViaVersion finishes initializing * @return the server version before ViaVersion finishes initializing
*/ */
public ProtocolVersion getServerProtocolVersion() { public ProtocolVersion getServerProtocolVersion() {
String bukkitVersion = Bukkit.getServer().getVersion(); return ProtocolVersion.getClosest(this.minecraftVersion);
// Turn "(MC: 1.16.4)" into 1.16.4.
String version = bukkitVersion.split("\\(MC: ")[1].split("\\)")[0];
return ProtocolVersion.getClosest(version);
} }
/** /**

Datei anzeigen

@ -163,4 +163,9 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
public BootstrapDumpInfo getDumpInfo() { public BootstrapDumpInfo getDumpInfo() {
return new GeyserSpongeDumpInfo(); return new GeyserSpongeDumpInfo();
} }
@Override
public String getMinecraftServerVersion() {
return Sponge.getPlatform().getMinecraftVersion().getName();
}
} }

Datei anzeigen

@ -244,6 +244,20 @@ public class GeyserConnector {
} }
return valueMap; return valueMap;
})); }));
String minecraftVersion = bootstrap.getMinecraftServerVersion();
if (minecraftVersion != null) {
Map<String, Map<String, Integer>> versionMap = new HashMap<>();
Map<String, Integer> platformMap = new HashMap<>();
platformMap.put(platformType.getPlatformName(), 1);
versionMap.put(minecraftVersion, platformMap);
metrics.addCustomChart(new Metrics.DrilldownPie("minecraftServerVersion", () -> {
// By the end, we should return, for example:
// 1.16.5 => (Spigot, 1)
return versionMap;
}));
}
} }
boolean isGui = false; boolean isGui = false;

Datei anzeigen

@ -33,6 +33,7 @@ import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.network.translators.world.GeyserWorldManager; import org.geysermc.connector.network.translators.world.GeyserWorldManager;
import org.geysermc.connector.network.translators.world.WorldManager; import org.geysermc.connector.network.translators.world.WorldManager;
import javax.annotation.Nullable;
import java.nio.file.Path; import java.nio.file.Path;
public interface GeyserBootstrap { public interface GeyserBootstrap {
@ -99,4 +100,18 @@ public interface GeyserBootstrap {
* @return The info about the bootstrap * @return The info about the bootstrap
*/ */
BootstrapDumpInfo getDumpInfo(); BootstrapDumpInfo getDumpInfo();
/**
* Returns the Minecraft version currently being used on the server. This should be only be implemented on platforms
* that have direct server access - platforms such as proxies always have to be on their latest version to support
* the newest Minecraft version, but older servers can use ViaVersion to enable newer versions to join.
* <br>
* If used, this should not be null before {@link org.geysermc.connector.GeyserConnector} initialization.
*
* @return the Minecraft version being used on the server, or <code>null</code> if not applicable
*/
@Nullable
default String getMinecraftServerVersion() {
return null;
}
} }

Datei anzeigen

@ -36,6 +36,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -75,7 +76,7 @@ public class Metrics {
private final static ObjectMapper mapper = new ObjectMapper(); private final static ObjectMapper mapper = new ObjectMapper();
private GeyserConnector connector; private final GeyserConnector connector;
/** /**
* Class constructor. * Class constructor.
@ -156,6 +157,7 @@ public class Metrics {
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch"); String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version"); String osVersion = System.getProperty("os.version");
String javaVersion = System.getProperty("java.version");
int coreCount = Runtime.getRuntime().availableProcessors(); int coreCount = Runtime.getRuntime().availableProcessors();
ObjectNode data = mapper.createObjectNode(); ObjectNode data = mapper.createObjectNode();
@ -163,6 +165,7 @@ public class Metrics {
data.put("serverUUID", serverUUID); data.put("serverUUID", serverUUID);
data.put("playerAmount", playerAmount); data.put("playerAmount", playerAmount);
data.put("javaVersion", javaVersion);
data.put("osName", osName); data.put("osName", osName);
data.put("osArch", osArch); data.put("osArch", osArch);
data.put("osVersion", osVersion); data.put("osVersion", osVersion);
@ -241,7 +244,7 @@ public class Metrics {
} }
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(outputStream); GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
gzip.write(str.getBytes("UTF-8")); gzip.write(str.getBytes(StandardCharsets.UTF_8));
gzip.close(); gzip.close();
return outputStream.toByteArray(); return outputStream.toByteArray();
} }