Warn about potentially unstable plugins/server software

This commit is contained in:
KennyTV 2021-04-03 17:00:39 +02:00
parent 9ccd8bff33
commit 26bbc92f94
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 108 additions and 0 deletions

View File

@ -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<T> {
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<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
return Collections.emptyList();
}
}

View File

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

View File

@ -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<Player>
return api;
}
@Override
public final Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
List<UnsupportedSoftware> 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;
}

View File

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