Print plugin name in unsupported software matching

This commit is contained in:
Nassim Jahnke 2023-04-02 09:40:35 +02:00
parent 7b0160d6c3
commit 8864b161f9
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 24 additions and 10 deletions

View File

@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.platform;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface UnsupportedSoftware {
/**
@ -38,10 +40,19 @@ public interface UnsupportedSoftware {
*/
String getReason();
/**
* Returns the name of unsupported software if present.
*
* @return name of unsupported software if it is matched, else null
*/
@Nullable String match();
/**
* Returns whether the unsupported software is present.
*
* @return true if the unsupported software is found
*/
boolean findMatch();
default boolean findMatch() {
return match() != null;
}
}

View File

@ -237,7 +237,8 @@ public class ViaManagerImpl implements ViaManager {
private void unsupportedSoftwareWarning() {
boolean found = false;
for (final UnsupportedSoftware software : platform.getUnsupportedSoftwareClasses()) {
if (!software.findMatch()) {
final String match = software.match();
if (match == null) {
continue;
}
@ -249,7 +250,7 @@ public class ViaManagerImpl implements ViaManager {
found = true;
}
platform.getLogger().severe("We strongly advise against using " + software.getName() + ":");
platform.getLogger().severe("We strongly advise against using " + match + ":");
platform.getLogger().severe(software.getReason());
platform.getLogger().severe("");
}

View File

@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class UnsupportedPlugin implements UnsupportedSoftware {
@ -50,13 +51,13 @@ public final class UnsupportedPlugin implements UnsupportedSoftware {
}
@Override
public final boolean findMatch() {
public final @Nullable String match() {
for (final String identifier : identifiers) {
if (Via.getPlatform().hasPlugin(identifier)) {
return true;
return identifier;
}
}
return false;
return null;
}
public static final class Builder {

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class UnsupportedServerSoftware implements UnsupportedSoftware {
@ -53,20 +54,20 @@ public final class UnsupportedServerSoftware implements UnsupportedSoftware {
}
@Override
public final boolean findMatch() {
public final @Nullable String match() {
for (String className : classNames) {
try {
Class.forName(className);
return true;
return name;
} catch (ClassNotFoundException ignored) {
}
}
for (UnsupportedMethods method : methods) {
if (method.findMatch()) {
return true;
return name;
}
}
return false;
return null;
}
public static final class Builder {