feat(internals): disable plugin when invalid server version is found

This commit is contained in:
aroooo 2022-10-20 21:45:32 +02:00
parent d74d583200
commit f31bcfc6d5
2 changed files with 9 additions and 2 deletions

View file

@ -15,6 +15,8 @@ import net.artelnatif.nicko.utils.ServerUtils;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Level;
public class NickoBukkit extends JavaPlugin { public class NickoBukkit extends JavaPlugin {
private static NickoBukkit plugin; private static NickoBukkit plugin;
@ -26,6 +28,12 @@ public class NickoBukkit extends JavaPlugin {
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
getLogger().info("Loading internals...");
if (getInternals() == null) {
getLogger().log(Level.SEVERE, "Nicko could not find a valid implementation for this server version. Is your server supported?");
getServer().getPluginManager().disablePlugin(this);
}
final PluginCommand command = getCommand("nicko"); final PluginCommand command = getCommand("nicko");
if (command != null) { if (command != null) {
command.setExecutor(new NickoCommand()); command.setExecutor(new NickoCommand());

View file

@ -3,7 +3,6 @@ package net.artelnatif.nicko.impl;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
public class InternalsProvider { public class InternalsProvider {
private static Internals internals; private static Internals internals;
@ -19,7 +18,7 @@ public class InternalsProvider {
internals = (Internals) Class.forName(fullClassName).getConstructors()[0].newInstance(); internals = (Internals) Class.forName(fullClassName).getConstructors()[0].newInstance();
} catch (InvocationTargetException | ClassNotFoundException | InstantiationException | IllegalAccessException | } catch (InvocationTargetException | ClassNotFoundException | InstantiationException | IllegalAccessException |
ClassCastException exception) { ClassCastException exception) {
Bukkit.getLogger().log(Level.SEVERE, "Nicko could not find a valid implementation for this server version. Is your server supported?"); internals = null;
} }
} }