Make UnsupportedSoftware hold a list of class names

This commit is contained in:
KennyTV 2021-05-08 10:05:43 +02:00
parent fe3f247eb1
commit cb7a7254a6
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 32 additions and 9 deletions

View File

@ -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<String> classNames;
private final String reason;
public UnsupportedSoftware(String name, List<String> 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<String> 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.";

View File

@ -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;
}