From 26af09f2a4f3bb767e22c08b7a7678ac0d793209 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 5 Jul 2022 20:37:19 +0200 Subject: [PATCH] Update unsupported software list --- .../com/viaversion/viaversion/api/ViaAPI.java | 2 +- .../viaversion/api/platform/ViaPlatform.java | 8 ++ .../viaversion/ViaVersionPlugin.java | 13 ++- .../viaversion/viaversion/BungeePlugin.java | 5 + .../viaversion/viaversion/ViaManagerImpl.java | 2 +- .../unsupported/UnsupportedPlugin.java | 93 +++++++++++++++++++ ...pl.java => UnsupportedServerSoftware.java} | 13 +-- .../viaversion/common/dummy/TestPlatform.java | 5 + .../viaversion/viaversion/SpongePlugin.java | 5 + .../viaversion/viaversion/VelocityPlugin.java | 5 + 10 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedPlugin.java rename common/src/main/java/com/viaversion/viaversion/unsupported/{UnsupportedSoftwareImpl.java => UnsupportedServerSoftware.java} (87%) diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index 02eeed480..ec615322e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -64,7 +64,7 @@ public interface ViaAPI { * @return API version incremented with meaningful API changes */ default int apiVersion() { - return 12; + return 13; } /** diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java index 1dc22c51c..84264f7d0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java @@ -218,4 +218,12 @@ public interface ViaPlatform { default Collection getUnsupportedSoftwareClasses() { return Collections.emptyList(); } + + /** + * Returns whether the platform has a plugin/mod with the given name (even if disabled). + * + * @param name plugin or identifier + * @return whether the platform has a plugin/mod with the given name + */ + boolean hasPlugin(String name); } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java index 5bc47d61d..1a1c81fbe 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java @@ -37,7 +37,8 @@ import com.viaversion.viaversion.bukkit.platform.BukkitViaLoader; import com.viaversion.viaversion.bukkit.platform.BukkitViaTask; import com.viaversion.viaversion.bukkit.util.NMSUtil; import com.viaversion.viaversion.dump.PluginInfo; -import com.viaversion.viaversion.unsupported.UnsupportedSoftwareImpl; +import com.viaversion.viaversion.unsupported.UnsupportedPlugin; +import com.viaversion.viaversion.unsupported.UnsupportedServerSoftware; import com.viaversion.viaversion.util.GsonUtil; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -286,14 +287,22 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform @Override public final Collection getUnsupportedSoftwareClasses() { List list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses()); - list.add(new UnsupportedSoftwareImpl.Builder().name("Yatopia").reason(UnsupportedSoftwareImpl.Reason.DANGEROUS_SERVER_SOFTWARE) + list.add(new UnsupportedServerSoftware.Builder().name("Yatopia").reason(UnsupportedServerSoftware.Reason.DANGEROUS_SERVER_SOFTWARE) .addClassName("org.yatopiamc.yatopia.server.YatopiaConfig") .addClassName("net.yatopia.api.event.PlayerAttackEntityEvent") .addClassName("yatopiamc.org.yatopia.server.YatopiaConfig") // Only the best kind of software relocates its own classes to hide itself :tinfoilhat: .addMethod("org.bukkit.Server", "getLastTickTime").build()); + list.add(new UnsupportedPlugin.Builder().name("software to mess with message signing").reason(UnsupportedPlugin.Reason.SECURE_CHAT_BYPASS) + .addPlugin("NoEncryption") + .addPlugin("NoChatReports").build()); return Collections.unmodifiableList(list); } + @Override + public boolean hasPlugin(final String name) { + return getServer().getPluginManager().getPlugin(name) != null; + } + public boolean isLateBind() { return lateBind; } diff --git a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java index badb52042..8da295fb6 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java +++ b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java @@ -205,4 +205,9 @@ public class BungeePlugin extends Plugin implements ViaPlatform, public boolean isOldClientsAllowed() { return true; } + + @Override + public boolean hasPlugin(final String name) { + return getProxy().getPluginManager().getPlugin(name) != null; + } } diff --git a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java index 17297153a..521a3bb2b 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java @@ -238,7 +238,7 @@ public class ViaManagerImpl implements ViaManager { } } - private final void unsupportedSoftwareWarning() { + private void unsupportedSoftwareWarning() { boolean found = false; for (UnsupportedSoftware software : platform.getUnsupportedSoftwareClasses()) { if (!software.findMatch()) { diff --git a/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedPlugin.java b/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedPlugin.java new file mode 100644 index 000000000..980cf2b30 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedPlugin.java @@ -0,0 +1,93 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2022 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.unsupported; + +import com.google.common.base.Preconditions; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.platform.UnsupportedSoftware; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public final class UnsupportedPlugin implements UnsupportedSoftware { + + private final String name; + private final List identifiers; + private final String reason; + + public UnsupportedPlugin(final String name, final List identifiers, final String reason) { + Preconditions.checkNotNull(name); + Preconditions.checkNotNull(reason); + Preconditions.checkArgument(!identifiers.isEmpty()); + this.name = name; + this.identifiers = Collections.unmodifiableList(identifiers); + this.reason = reason; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getReason() { + return reason; + } + + @Override + public final boolean findMatch() { + for (final String identifier : identifiers) { + if (Via.getPlatform().hasPlugin(identifier)) { + return true; + } + } + return false; + } + + public static final class Builder { + + private final List identifiers = new ArrayList<>(); + private String name; + private String reason; + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder reason(final String reason) { + this.reason = reason; + return this; + } + + public Builder addPlugin(final String identifier) { + identifiers.add(identifier); + return this; + } + + public UnsupportedPlugin build() { + return new UnsupportedPlugin(name, identifiers, reason); + } + } + + public static final class Reason { + + public static final String SECURE_CHAT_BYPASS = "Instead of doing the obvious (or nothing at all), these kinds of plugins completely break chat message handling, usually then also breaking other plugins."; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedSoftwareImpl.java b/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedServerSoftware.java similarity index 87% rename from common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedSoftwareImpl.java rename to common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedServerSoftware.java index 7544dc7d0..1732b33ec 100644 --- a/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedSoftwareImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/unsupported/UnsupportedServerSoftware.java @@ -26,14 +26,17 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; -public final class UnsupportedSoftwareImpl implements UnsupportedSoftware { +public final class UnsupportedServerSoftware implements UnsupportedSoftware { private final String name; private final List classNames; private final List methods; private final String reason; - public UnsupportedSoftwareImpl(String name, List classNames, List methods, String reason) { + public UnsupportedServerSoftware(String name, List classNames, List methods, String reason) { + Preconditions.checkNotNull(name); + Preconditions.checkNotNull(reason); + Preconditions.checkArgument(!classNames.isEmpty() || !methods.isEmpty()); this.name = name; this.classNames = Collections.unmodifiableList(classNames); this.methods = Collections.unmodifiableList(methods); @@ -51,7 +54,7 @@ public final class UnsupportedSoftwareImpl implements UnsupportedSoftware { } @Override - public boolean findMatch() { + public final boolean findMatch() { for (String className : classNames) { try { Class.forName(className); @@ -100,9 +103,7 @@ public final class UnsupportedSoftwareImpl implements UnsupportedSoftware { } public UnsupportedSoftware build() { - Preconditions.checkNotNull(name); - Preconditions.checkNotNull(reason); - return new UnsupportedSoftwareImpl(name, classNames, methods, reason); + return new UnsupportedServerSoftware(name, classNames, methods, reason); } } diff --git a/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java b/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java index eee861ba2..6a1894e67 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java +++ b/common/src/test/java/com/viaversion/viaversion/common/dummy/TestPlatform.java @@ -137,4 +137,9 @@ public final class TestPlatform implements ViaPlatform { public boolean isOldClientsAllowed() { return false; } + + @Override + public boolean hasPlugin(final String name) { + return false; + } } diff --git a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java index 0d83edc98..95d8a73b5 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java +++ b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java @@ -228,6 +228,11 @@ public class SpongePlugin implements ViaPlatform { return true; } + @Override + public boolean hasPlugin(final String name) { + return game.pluginManager().plugin(name).isPresent(); + } + @Override public SpongeViaAPI getApi() { return api; diff --git a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java index 83f923ecd..287fd8fcd 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java @@ -239,6 +239,11 @@ public class VelocityPlugin implements ViaPlatform { return true; } + @Override + public boolean hasPlugin(final String name) { + return proxy.getPluginManager().getPlugin(name).isPresent(); + } + @Override public java.util.logging.Logger getLogger() { return logger;