From 44469d91ecd5ef9e46402fd531922cf9be6d4231 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 12 May 2022 22:01:16 -0500 Subject: [PATCH] Account for non-Plex versions of BukkitTelnet --- .../java/dev/plex/BukkitTelnetModule.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/plex/BukkitTelnetModule.java b/src/main/java/dev/plex/BukkitTelnetModule.java index bb99097..2a5dcb0 100644 --- a/src/main/java/dev/plex/BukkitTelnetModule.java +++ b/src/main/java/dev/plex/BukkitTelnetModule.java @@ -2,6 +2,8 @@ package dev.plex; import dev.plex.listener.BukkitTelnetListener; import dev.plex.module.PlexModule; +import dev.plex.util.PlexLog; +import java.lang.reflect.Method; import lombok.Getter; import me.totalfreedom.bukkittelnet.BukkitTelnet; import org.bukkit.Bukkit; @@ -13,6 +15,8 @@ public class BukkitTelnetModule extends PlexModule private BukkitTelnet bukkitTelnet; + boolean failed = false; + @Override public void load() { @@ -22,14 +26,33 @@ public class BukkitTelnetModule extends PlexModule @Override public void enable() { - /*if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault")) + if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault")) { - throw new RuntimeException("Plex-BukkitTelnet requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault.' We recommend LuckPerms!"); - }*/ + failed = true; + PlexLog.error("Plex-BukkitTelnet requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault.' We recommend LuckPerms!"); + module.disable(); + return; + } if (!Bukkit.getPluginManager().isPluginEnabled("BukkitTelnet")) { - throw new RuntimeException("The Plex-BukkitTelnet module requires the BukkitTelnet plugin to work. Please download it from: https://github.com/plexusorg/BukkitTelnet/releases"); + failed = true; + PlexLog.error("The Plex-BukkitTelnet module requires the BukkitTelnet plugin to work. Please download it from: https://github.com/plexusorg/BukkitTelnet/releases"); + module.disable(); + return; + } + + try + { + failed = true; + Class clazz = Class.forName("me.totalfreedom.bukkittelnet.BukkitTelnet"); + Method method = clazz.getDeclaredMethod("getPlugin"); + } + catch (ClassNotFoundException | NoSuchMethodException ignored) + { + PlexLog.error("You are using an older version of BukkitTelnet that does not support Plex. Please download a version that does from: https://ci.plex.us.org/job/Plex-BukkitTelnet"); + module.disable(); + return; } this.registerListener(new BukkitTelnetListener()); @@ -39,5 +62,9 @@ public class BukkitTelnetModule extends PlexModule @Override public void disable() { + if (failed) + { + PlexLog.error("Disabling Module-BukkitTelnet. Please resolve the above error."); + } } }