From cb7a7254a6bab281f94e66202c50b0519c0bc4da Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sat, 8 May 2021 10:05:43 +0200 Subject: [PATCH] Make UnsupportedSoftware hold a list of class names --- .../api/platform/UnsupportedSoftware.java | 37 ++++++++++++++++--- .../viaversion/viaversion/ViaManagerImpl.java | 4 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/UnsupportedSoftware.java b/api/src/main/java/com/viaversion/viaversion/api/platform/UnsupportedSoftware.java index d7f6b6aec..d39b669dd 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/UnsupportedSoftware.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/UnsupportedSoftware.java @@ -22,15 +22,24 @@ */ package com.viaversion.viaversion.api.platform; +import java.util.Collections; +import java.util.List; + public final class UnsupportedSoftware { private final String name; - private final String className; + private final List classNames; private final String reason; + public UnsupportedSoftware(String name, List classNames, String reason) { + this.name = name; + this.classNames = Collections.unmodifiableList(classNames); + this.reason = reason; + } + public UnsupportedSoftware(String name, String className, String reason) { this.name = name; - this.className = className; + this.classNames = Collections.singletonList(className); this.reason = reason; } @@ -44,12 +53,12 @@ public final class UnsupportedSoftware { } /** - * Returns the fully qualified class name. + * Returns an immutable list of the fully qualified class name. * - * @return fully qualified class name + * @return immutable list of fully qualified class name */ - public String getClassName() { - return className; + public List getClassNames() { + return classNames; } /** @@ -61,6 +70,22 @@ public final class UnsupportedSoftware { return reason; } + /** + * Returns whether at least one of the held class names exists. + * + * @return true if at least one of the classes exists + */ + public boolean findMatch() { + for (String className : classNames) { + try { + Class.forName(className); + return true; + } catch (ClassNotFoundException ignored) { + } + } + return false; + } + 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/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java index aab5d17df..0977389ba 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java @@ -207,9 +207,7 @@ public class ViaManagerImpl implements ViaManager { private void unsupportedSoftwareWarning() { boolean found = false; for (UnsupportedSoftware software : platform.getUnsupportedSoftwareClasses()) { - try { - Class.forName(software.getClassName()); - } catch (ClassNotFoundException ignored) { + if (!software.findMatch()) { continue; }