diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java index 2278d99d9..ba7bc464f 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java @@ -29,7 +29,6 @@ import lombok.Getter; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; import org.geysermc.geyser.dump.BootstrapDumpInfo; -import org.geysermc.geyser.text.AsteriskSerializer; import java.util.ArrayList; import java.util.Collections; @@ -52,15 +51,17 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo { this.plugins = new ArrayList<>(); for (net.md_5.bungee.api.config.ListenerInfo listener : proxy.getConfig().getListeners()) { - String hostname = listener.getHost().getHostString(); - if (!AsteriskSerializer.showSensitive && !(hostname.equals("") || hostname.equals("0.0.0.0"))) { - hostname = "***"; - } - this.listeners.add(new ListenerInfo(hostname, listener.getHost().getPort())); + this.listeners.add(new ListenerInfo(listener.getHost().getHostString(), listener.getHost().getPort())); } for (Plugin plugin : proxy.getPluginManager().getPlugins()) { - this.plugins.add(new PluginInfo(true, plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getMain(), Collections.singletonList(plugin.getDescription().getAuthor()))); + this.plugins.add(new PluginInfo( + true, + plugin.getDescription().getName(), + plugin.getDescription().getVersion(), + plugin.getDescription().getMain(), + Collections.singletonList(plugin.getDescription().getAuthor())) + ); } } } diff --git a/bootstrap/fabric/build.gradle.kts b/bootstrap/fabric/build.gradle.kts index 02f24bba5..743b75a26 100644 --- a/bootstrap/fabric/build.gradle.kts +++ b/bootstrap/fabric/build.gradle.kts @@ -1,8 +1,5 @@ plugins { id("fabric-loom") version "1.0-SNAPSHOT" - id("maven-publish") - id("com.github.johnrengelman.shadow") - id("java") } java { diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricDumpInfo.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricDumpInfo.java index 2db6a3729..ee986ee62 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricDumpInfo.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricDumpInfo.java @@ -25,65 +25,58 @@ package org.geysermc.geyser.platform.fabric; +import lombok.AllArgsConstructor; +import lombok.Getter; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.api.metadata.ModMetadata; +import net.fabricmc.loader.api.metadata.Person; import net.minecraft.server.MinecraftServer; import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.text.AsteriskSerializer; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; -@SuppressWarnings("unused") // The way that the dump renders makes them used +@Getter public class GeyserFabricDumpInfo extends BootstrapDumpInfo { private String platformVersion = null; private final EnvType environmentType; + @AsteriskSerializer.Asterisk(isIp = true) private final String serverIP; private final int serverPort; private final List mods; public GeyserFabricDumpInfo(MinecraftServer server) { - super(); - for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { - if (modContainer.getMetadata().getId().equals("fabricloader")) { - this.platformVersion = modContainer.getMetadata().getVersion().getFriendlyString(); - break; - } - } + FabricLoader.getInstance().getModContainer("fabricloader").ifPresent(mod -> + this.platformVersion = mod.getMetadata().getVersion().getFriendlyString()); + this.environmentType = FabricLoader.getInstance().getEnvironmentType(); - if (AsteriskSerializer.showSensitive || (server.getLocalIp() == null || server.getLocalIp().equals("") || server.getLocalIp().equals("0.0.0.0"))) { - this.serverIP = server.getLocalIp(); - } else { - this.serverIP = "***"; - } + this.serverIP = server.getLocalIp() == null ? "unknown" : server.getLocalIp(); this.serverPort = server.getPort(); this.mods = new ArrayList<>(); for (ModContainer mod : FabricLoader.getInstance().getAllMods()) { - this.mods.add(new ModInfo(mod)); + ModMetadata meta = mod.getMetadata(); + this.mods.add(new ModInfo( + FabricLoader.getInstance().isModLoaded(meta.getId()), + meta.getId(), + meta.getVersion().getFriendlyString(), + meta.getAuthors().stream().map(Person::getName).collect(Collectors.toList())) + ); } } - public String getPlatformVersion() { - return platformVersion; - } - - public EnvType getEnvironmentType() { - return environmentType; - } - - public String getServerIP() { - return this.serverIP; - } - - public int getServerPort() { - return this.serverPort; - } - - public List getMods() { - return this.mods; + @Getter + @AllArgsConstructor + public static class ModInfo { + public boolean enabled; + public String name; + public String version; + public List authors; } } diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java index 1e9543ff8..e5ff4b577 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java @@ -246,7 +246,10 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { @Override public InputStream getResourceOrNull(String resource) { // We need to handle this differently, because Fabric shares the classloader across multiple mods - Path path = this.mod.getPath(resource); + Path path = this.mod.findPath(resource).orElse(null); + if (path == null) { + return null; + } try { return path.getFileSystem() diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/ModInfo.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/ModInfo.java deleted file mode 100644 index b9137c438..000000000 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/ModInfo.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019-2022 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.geyser.platform.fabric; - -import net.fabricmc.loader.api.ModContainer; - -import java.util.ArrayList; -import java.util.List; - -/** - * A wrapper for Fabric mod information to be presented in a Geyser dump - */ -public class ModInfo { - - private final String name; - private final String id; - private final String version; - private final List authors; - - public ModInfo(ModContainer mod) { - this.name = mod.getMetadata().getName(); - this.id = mod.getMetadata().getId(); - this.authors = new ArrayList<>(); - mod.getMetadata().getAuthors().forEach((person) -> this.authors.add(person.getName())); - this.version = mod.getMetadata().getVersion().getFriendlyString(); - } - - public String getName() { - return this.name; - } - - public String getId() { - return this.id; - } - - public String getVersion() { - return this.version; - } - - public List getAuthors() { - return this.authors; - } -} diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java index 92c2fe16b..d340935b3 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java @@ -41,6 +41,8 @@ public class GeyserSpigotDumpInfo extends BootstrapDumpInfo { private final String platformVersion; private final String platformAPIVersion; private final boolean onlineMode; + + @AsteriskSerializer.Asterisk(isIp = true) private final String serverIP; private final int serverPort; private final List plugins; @@ -51,12 +53,7 @@ public class GeyserSpigotDumpInfo extends BootstrapDumpInfo { this.platformVersion = Bukkit.getVersion(); this.platformAPIVersion = Bukkit.getBukkitVersion(); this.onlineMode = Bukkit.getOnlineMode(); - String ip = Bukkit.getIp(); - if (AsteriskSerializer.showSensitive || (ip.equals("") || ip.equals("0.0.0.0"))) { - this.serverIP = ip; - } else { - this.serverIP = "***"; - } + this.serverIP = Bukkit.getIp(); this.serverPort = Bukkit.getPort(); this.plugins = new ArrayList<>(); diff --git a/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongeDumpInfo.java b/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongeDumpInfo.java index fc1bff3ef..628c85fd1 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongeDumpInfo.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/geyser/platform/sponge/GeyserSpongeDumpInfo.java @@ -45,6 +45,8 @@ public class GeyserSpongeDumpInfo extends BootstrapDumpInfo { private final String platformName; private final String platformVersion; private final boolean onlineMode; + + @AsteriskSerializer.Asterisk(isIp = true) private final String serverIP; private final int serverPort; private final List plugins; @@ -56,12 +58,7 @@ public class GeyserSpongeDumpInfo extends BootstrapDumpInfo { this.platformVersion = platformMeta.version().getQualifier(); this.onlineMode = Sponge.server().isOnlineModeEnabled(); Optional socketAddress = Sponge.server().boundAddress(); - String hostString = socketAddress.map(InetSocketAddress::getHostString).orElse("unknown"); - if (AsteriskSerializer.showSensitive || (hostString.equals("") || hostString.equals("0.0.0.0") || hostString.equals("unknown"))) { - this.serverIP = hostString; - } else { - this.serverIP = "***"; - } + this.serverIP = socketAddress.map(InetSocketAddress::getHostString).orElse("unknown"); this.serverPort = socketAddress.map(InetSocketAddress::getPort).orElse(-1); this.plugins = new ArrayList<>(); diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityDumpInfo.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityDumpInfo.java index b2765d3b2..45eb7abb9 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityDumpInfo.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityDumpInfo.java @@ -41,6 +41,8 @@ public class GeyserVelocityDumpInfo extends BootstrapDumpInfo { private final String platformVersion; private final String platformVendor; private final boolean onlineMode; + + @AsteriskSerializer.Asterisk(isIp = true) private final String serverIP; private final int serverPort; private final List plugins; @@ -51,12 +53,7 @@ public class GeyserVelocityDumpInfo extends BootstrapDumpInfo { this.platformVersion = proxy.getVersion().getVersion(); this.platformVendor = proxy.getVersion().getVendor(); this.onlineMode = proxy.getConfiguration().isOnlineMode(); - String hostString = proxy.getBoundAddress().getHostString(); - if (AsteriskSerializer.showSensitive || (hostString.equals("") || hostString.equals("0.0.0.0"))) { - this.serverIP = hostString; - } else { - this.serverIP = "***"; - } + this.serverIP = proxy.getBoundAddress().getHostString(); this.serverPort = proxy.getBoundAddress().getPort(); this.plugins = new ArrayList<>(); diff --git a/core/src/main/java/org/geysermc/geyser/dump/BootstrapDumpInfo.java b/core/src/main/java/org/geysermc/geyser/dump/BootstrapDumpInfo.java index 0bbc1c0ed..fda0566fd 100644 --- a/core/src/main/java/org/geysermc/geyser/dump/BootstrapDumpInfo.java +++ b/core/src/main/java/org/geysermc/geyser/dump/BootstrapDumpInfo.java @@ -29,6 +29,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import org.geysermc.common.PlatformType; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.text.AsteriskSerializer; import java.util.List; @@ -53,6 +54,8 @@ public class BootstrapDumpInfo { @Getter @AllArgsConstructor public static class ListenerInfo { + + @AsteriskSerializer.Asterisk(isIp = true) public String ip; public int port; } diff --git a/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java b/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java index 27b277c72..69dbb558e 100644 --- a/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java +++ b/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java @@ -43,6 +43,8 @@ import java.util.Optional; public class AsteriskSerializer extends StdSerializer implements ContextualSerializer { + public static final String[] NON_SENSITIVE_ADDRESSES = {"", "0.0.0.0", "localhost", "127.0.0.1", "auto", "unknown"}; + public static boolean showSensitive = false; @Target({ElementType.FIELD}) @@ -91,11 +93,11 @@ public class AsteriskSerializer extends StdSerializer implements Context } private boolean isSensitiveIp(String ip) { - if (ip.equalsIgnoreCase("localhost") || ip.equalsIgnoreCase("auto")) { - // `auto` should not be shown unless there is an obscure issue with setting the localhost address - return false; + for (String address : NON_SENSITIVE_ADDRESSES) { + if (address.equalsIgnoreCase(ip)) { + return false; + } } - - return !ip.isEmpty() && !ip.equals("0.0.0.0") && !ip.equals("127.0.0.1"); + return true; } }