Module-BukkitTelnet/src/main/java/dev/plex/BukkitTelnetModule.java

94 lines
2.9 KiB
Java
Raw Normal View History

2022-03-31 06:35:22 +00:00
package dev.plex;
2022-05-14 10:19:13 +00:00
import dev.plex.automation.PatchedTelnetCompiler;
2022-03-31 06:35:22 +00:00
import dev.plex.listener.BukkitTelnetListener;
import dev.plex.module.PlexModule;
import dev.plex.util.PlexLog;
2022-03-31 06:35:22 +00:00
import lombok.Getter;
2022-04-11 05:01:34 +00:00
import me.totalfreedom.bukkittelnet.BukkitTelnet;
2022-03-31 06:35:22 +00:00
import org.bukkit.Bukkit;
2022-05-14 10:19:13 +00:00
import java.lang.reflect.Method;
2022-05-14 10:25:17 +00:00
public class BukkitTelnetModule extends PlexModule
{
2022-03-31 06:35:22 +00:00
@Getter
private static BukkitTelnetModule module;
boolean failed = false;
2022-05-14 10:19:13 +00:00
private BukkitTelnet bukkitTelnet;
2022-03-31 06:35:22 +00:00
@Override
2022-05-14 10:25:17 +00:00
public void load()
{
2022-03-31 06:35:22 +00:00
module = this;
}
@Override
2022-05-14 10:25:17 +00:00
public void enable()
{
if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault"))
{
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;
}
2022-03-31 06:35:22 +00:00
2022-05-14 10:25:17 +00:00
if (!Bukkit.getPluginManager().isPluginEnabled("BukkitTelnet"))
{
failed = true;
2022-05-14 10:19:13 +00:00
PlexLog.warn("The Plex-BukkitTelnet module requires the BukkitTelnet plugin to work. I am automatically compiling BukkitTelnet plugin for you, however if something fails, please download it from: https://github.com/plexusorg/BukkitTelnet/releases");
2022-05-14 10:25:17 +00:00
try
{
2022-05-14 10:19:13 +00:00
PatchedTelnetCompiler.execute();
return;
2022-05-14 10:25:17 +00:00
}
catch (Exception e)
{
2022-05-14 10:19:13 +00:00
PlexLog.error("Failed to compile patched telnet.");
e.printStackTrace();
}
2022-05-14 10:25:17 +00:00
module.disable();
return;
}
2022-05-14 10:25:17 +00:00
try
{
failed = true;
Class<?> clazz = Class.forName("me.totalfreedom.bukkittelnet.BukkitTelnet");
Method method = clazz.getDeclaredMethod("getPlugin");
2022-05-14 10:25:17 +00:00
}
catch (ClassNotFoundException | NoSuchMethodException ignored)
{
2022-05-14 10:19:13 +00:00
PlexLog.warn("You are using an older version of BukkitTelnet that does not support Plex. I am automatically compiling a build that does work for you, however if something fails, please download a version that does from: https://ci.plex.us.org/job/Plex-BukkitTelnet");
2022-05-14 10:25:17 +00:00
try
{
2022-05-14 10:19:13 +00:00
PatchedTelnetCompiler.execute();
return;
2022-05-14 10:25:17 +00:00
}
catch (Exception e)
{
2022-05-14 10:19:13 +00:00
PlexLog.error("Failed to compile patched telnet.");
e.printStackTrace();
}
module.disable();
return;
2022-04-14 22:20:38 +00:00
}
2022-03-31 06:35:22 +00:00
this.registerListener(new BukkitTelnetListener());
2022-04-11 05:01:34 +00:00
this.bukkitTelnet = BukkitTelnet.getPlugin();
2022-03-31 06:35:22 +00:00
}
@Override
2022-05-14 10:25:17 +00:00
public void disable()
{
if (failed)
{
PlexLog.error("Disabling Module-BukkitTelnet. Please resolve the above error.");
}
2022-03-31 06:35:22 +00:00
}
}