From 26bbc92f949c86d631161263c03c6ceaaaad45a1 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sat, 3 Apr 2021 17:00:39 +0200 Subject: [PATCH] Warn about potentially unstable plugins/server software --- .../ViaVersion/api/platform/ViaPlatform.java | 13 +++++ .../ViaVersion/util/UnsupportedSoftware.java | 53 +++++++++++++++++++ .../us/myles/ViaVersion/ViaVersionPlugin.java | 10 ++++ .../us/myles/ViaVersion/ViaManagerImpl.java | 32 +++++++++++ 4 files changed, 108 insertions(+) create mode 100644 api/src/main/java/us/myles/ViaVersion/util/UnsupportedSoftware.java diff --git a/api/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java b/api/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java index fde8274c2..beb67b828 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java +++ b/api/src/main/java/us/myles/ViaVersion/api/platform/ViaPlatform.java @@ -31,8 +31,11 @@ import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.util.UnsupportedSoftware; import java.io.File; +import java.util.Collection; +import java.util.Collections; import java.util.UUID; import java.util.logging.Logger; @@ -224,4 +227,14 @@ public interface ViaPlatform { default ViaConnectionManager getConnectionManager() { return Via.getManager().getConnectionManager(); } + + /** + * Returns an immutable collection of classes to be checked as unsupported software with their software name. + * If any of the classes exist at runtime, a warning about their potential instability will be given to the console. + * + * @return immutable collection of unsupported software to be checked + */ + default Collection getUnsupportedSoftwareClasses() { + return Collections.emptyList(); + } } diff --git a/api/src/main/java/us/myles/ViaVersion/util/UnsupportedSoftware.java b/api/src/main/java/us/myles/ViaVersion/util/UnsupportedSoftware.java new file mode 100644 index 000000000..5235f2452 --- /dev/null +++ b/api/src/main/java/us/myles/ViaVersion/util/UnsupportedSoftware.java @@ -0,0 +1,53 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * 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. + */ +package us.myles.ViaVersion.util; + +public final class UnsupportedSoftware { + + private final String name; + private final String className; + private final String reason; + + public UnsupportedSoftware(String name, String className, String reason) { + this.name = name; + this.className = className; + this.reason = reason; + } + + public String getName() { + return name; + } + + public String getClassName() { + return className; + } + + public String getReason() { + return reason; + } + + public static final class Reason { + + public static final String DANGEROUS_SERVER_SOFTWARE = "You are using server software that - outside of possibly breaking ViaVersion - can also cause severe damage to your server's integrity as a whole."; + } +} diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 756e1ab38..f6420ecfd 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -42,8 +42,11 @@ import us.myles.ViaVersion.bukkit.platform.BukkitViaLoader; import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.util.GsonUtil; +import us.myles.ViaVersion.util.UnsupportedSoftware; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.UUID; @@ -294,6 +297,13 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform return api; } + @Override + public final Collection getUnsupportedSoftwareClasses() { + List list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses()); + list.add(new UnsupportedSoftware("Yatopia", "org.yatopiamc.yatopia.server.YatopiaConfig", UnsupportedSoftware.Reason.DANGEROUS_SERVER_SOFTWARE)); + return Collections.unmodifiableList(list); + } + public boolean isCompatSpigotBuild() { return compatSpigotBuild; } diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManagerImpl.java b/common/src/main/java/us/myles/ViaVersion/ViaManagerImpl.java index ab5339d98..d9ec8c815 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManagerImpl.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManagerImpl.java @@ -35,6 +35,7 @@ import us.myles.ViaVersion.commands.ViaCommandHandler; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread; import us.myles.ViaVersion.update.UpdateUtil; +import us.myles.ViaVersion.util.UnsupportedSoftware; import java.util.ArrayList; import java.util.Arrays; @@ -137,6 +138,9 @@ public class ViaManagerImpl implements ViaManager { } } + // Check for unsupported plugins/software + unsupportedSoftwareWarning(); + // Load Listeners / Tasks protocolManager.onServerLoaded(); @@ -198,6 +202,34 @@ public class ViaManagerImpl implements ViaManager { loader.unload(); } + private void unsupportedSoftwareWarning() { + boolean found = false; + for (UnsupportedSoftware software : platform.getUnsupportedSoftwareClasses()) { + try { + Class.forName(software.getClassName()); + } catch (ClassNotFoundException ignored) { + continue; + } + + // Found something + if (!found) { + platform.getLogger().severe("************************************************"); + platform.getLogger().severe("You are using unsupported software and may encounter unforeseeable issues."); + platform.getLogger().severe(""); + found = true; + } + + platform.getLogger().severe("We strongly advise against using " + software.getName() + ":"); + platform.getLogger().severe(software.getReason()); + platform.getLogger().severe(""); + } + + if (found) { + platform.getLogger().severe("We will not provide support in case you encounter issues possibly related to this software."); + platform.getLogger().severe("************************************************"); + } + } + @Override public ViaPlatform getPlatform() { return platform;