Fix incorrectly formatted commit

This commit is contained in:
Allink 2022-05-14 11:25:17 +01:00
parent 950cf97ff6
commit 4d3873cb1f
No known key found for this signature in database
GPG Key ID: 7F1F1B98F0FAAD13
2 changed files with 66 additions and 31 deletions

View File

@ -10,52 +10,66 @@ import org.bukkit.Bukkit;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class BukkitTelnetModule extends PlexModule { public class BukkitTelnetModule extends PlexModule
{
@Getter @Getter
private static BukkitTelnetModule module; private static BukkitTelnetModule module;
boolean failed = false; boolean failed = false;
private BukkitTelnet bukkitTelnet; private BukkitTelnet bukkitTelnet;
@Override @Override
public void load() { public void load()
{
module = this; module = this;
} }
@Override @Override
public void enable() { public void enable()
if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault")) { {
if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault"))
{
failed = true; failed = true;
PlexLog.error("Plex-BukkitTelnet requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault.' We recommend LuckPerms!"); PlexLog.error("Plex-BukkitTelnet requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault.' We recommend LuckPerms!");
module.disable(); module.disable();
return; return;
} }
if (!Bukkit.getPluginManager().isPluginEnabled("BukkitTelnet")) { if (!Bukkit.getPluginManager().isPluginEnabled("BukkitTelnet"))
{
failed = true; failed = true;
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"); 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");
try { try
{
PatchedTelnetCompiler.execute(); PatchedTelnetCompiler.execute();
return; return;
} catch (Exception e) { }
catch (Exception e)
{
PlexLog.error("Failed to compile patched telnet."); PlexLog.error("Failed to compile patched telnet.");
e.printStackTrace(); e.printStackTrace();
} }
module.disable(); module.disable();
return; return;
} }
try { try
{
failed = true; failed = true;
Class<?> clazz = Class.forName("me.totalfreedom.bukkittelnet.BukkitTelnet"); Class<?> clazz = Class.forName("me.totalfreedom.bukkittelnet.BukkitTelnet");
Method method = clazz.getDeclaredMethod("getPlugin"); Method method = clazz.getDeclaredMethod("getPlugin");
} catch (ClassNotFoundException | NoSuchMethodException ignored) { }
catch (ClassNotFoundException | NoSuchMethodException ignored)
{
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"); 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");
try { try
{
PatchedTelnetCompiler.execute(); PatchedTelnetCompiler.execute();
return; return;
} catch (Exception e) { }
catch (Exception e)
{
PlexLog.error("Failed to compile patched telnet."); PlexLog.error("Failed to compile patched telnet.");
e.printStackTrace(); e.printStackTrace();
} }
@ -69,8 +83,10 @@ public class BukkitTelnetModule extends PlexModule {
} }
@Override @Override
public void disable() { public void disable()
if (failed) { {
if (failed)
{
PlexLog.error("Disabling Module-BukkitTelnet. Please resolve the above error."); PlexLog.error("Disabling Module-BukkitTelnet. Please resolve the above error.");
} }
} }

View File

@ -24,7 +24,8 @@ import java.util.Timer;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
public class PatchedTelnetCompiler { public class PatchedTelnetCompiler
{
private static final PluginManager PLUGIN_MANAGER = Bukkit.getPluginManager(); private static final PluginManager PLUGIN_MANAGER = Bukkit.getPluginManager();
private static final URI CODE_ARCHIVE = URI.create("https://github.com/plexusorg/BukkitTelnet/archive/refs/heads/master.zip"); private static final URI CODE_ARCHIVE = URI.create("https://github.com/plexusorg/BukkitTelnet/archive/refs/heads/master.zip");
private static final Path PLUGIN_DIRECTORY = Bukkit.getServer().getPluginsFolder().toPath(); private static final Path PLUGIN_DIRECTORY = Bukkit.getServer().getPluginsFolder().toPath();
@ -37,13 +38,16 @@ public class PatchedTelnetCompiler {
private static final String DOWNLOADED_ARCHIVE_PATH = String.valueOf(ROOT_PATH.resolve("BukkitTelnet-master.zip")); private static final String DOWNLOADED_ARCHIVE_PATH = String.valueOf(ROOT_PATH.resolve("BukkitTelnet-master.zip"));
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient(); private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
public static void execute() throws Exception { public static void execute() throws Exception
{
// Create directories // Create directories
final List<Path> directories = ImmutableList.of(ROOT_PATH, EXTRACT_TARGET); final List<Path> directories = ImmutableList.of(ROOT_PATH, EXTRACT_TARGET);
for (Path directory : directories) { for (Path directory : directories)
{
PlexLog.debug("Checking if {0} exists...", String.valueOf(directory)); PlexLog.debug("Checking if {0} exists...", String.valueOf(directory));
if (Files.notExists(directory)) { if (Files.notExists(directory))
{
PlexLog.debug("It doesn't! Creating directory..."); PlexLog.debug("It doesn't! Creating directory...");
Files.createDirectory(directory); Files.createDirectory(directory);
} }
@ -52,7 +56,8 @@ public class PatchedTelnetCompiler {
downloadArchive(); downloadArchive();
} }
private static void downloadArchive() throws Exception { private static void downloadArchive() throws Exception
{
PlexLog.log("Downloading archive..."); PlexLog.log("Downloading archive...");
// Create the request // Create the request
final HttpRequest request = HttpRequest.newBuilder() final HttpRequest request = HttpRequest.newBuilder()
@ -80,23 +85,30 @@ public class PatchedTelnetCompiler {
extractArchive(); extractArchive();
} }
private static void extractArchive() throws Exception { private static void extractArchive() throws Exception
{
PlexLog.log("Extracting archive..."); PlexLog.log("Extracting archive...");
final ZipInputStream inputStream = new ZipInputStream(new FileInputStream(DOWNLOADED_ARCHIVE_PATH)); final ZipInputStream inputStream = new ZipInputStream(new FileInputStream(DOWNLOADED_ARCHIVE_PATH));
ZipEntry entry = inputStream.getNextEntry(); ZipEntry entry = inputStream.getNextEntry();
while (entry != null) { while (entry != null)
{
final Path outputDestination = EXTRACT_TARGET.resolve(entry.getName()); final Path outputDestination = EXTRACT_TARGET.resolve(entry.getName());
if (entry.isDirectory()) { if (entry.isDirectory())
if (Files.notExists(outputDestination)) { {
if (Files.notExists(outputDestination))
{
PlexLog.debug("{0} doesn't exist, creating it!", String.valueOf(outputDestination)); PlexLog.debug("{0} doesn't exist, creating it!", String.valueOf(outputDestination));
Files.createDirectory(outputDestination); Files.createDirectory(outputDestination);
} }
} else { }
else
{
final FileOutputStream outputStream = new FileOutputStream(String.valueOf(outputDestination)); final FileOutputStream outputStream = new FileOutputStream(String.valueOf(outputDestination));
int read = 0; int read = 0;
while ((read = inputStream.read()) != -1) { while ((read = inputStream.read()) != -1)
{
outputStream.write(read); outputStream.write(read);
} }
@ -110,12 +122,14 @@ public class PatchedTelnetCompiler {
executeGradleTarget(); executeGradleTarget();
} }
private static void executeGradleTarget() throws Exception { private static void executeGradleTarget() throws Exception
{
PlexLog.log("Executing gradle target..."); PlexLog.log("Executing gradle target...");
boolean nix = !System.getProperty("os.name").toLowerCase().contains("win"); // Assume Windows if name contains win boolean nix = !System.getProperty("os.name").toLowerCase().contains("win"); // Assume Windows if name contains win
String gradlew = String.valueOf(nix ? EXTRACT_SUBDIR.resolve("gradlew") : EXTRACT_SUBDIR.resolve("gradlew.bat")); String gradlew = String.valueOf(nix ? EXTRACT_SUBDIR.resolve("gradlew") : EXTRACT_SUBDIR.resolve("gradlew.bat"));
if (nix) { if (nix)
{
final ProcessBuilder chmodBuilder = new ProcessBuilder("chmod", "+x", gradlew); final ProcessBuilder chmodBuilder = new ProcessBuilder("chmod", "+x", gradlew);
Process chmodProcess = chmodBuilder.start(); Process chmodProcess = chmodBuilder.start();
chmodProcess.waitFor(); chmodProcess.waitFor();
@ -135,14 +149,18 @@ public class PatchedTelnetCompiler {
copyBinary(); copyBinary();
} }
private static void copyBinary() throws Exception { private static void copyBinary() throws Exception
{
PlexLog.log("Copying binaries..."); PlexLog.log("Copying binaries...");
final File binaryDirectory = new File(String.valueOf(BINARIES_PATH)); final File binaryDirectory = new File(String.valueOf(BINARIES_PATH));
final File[] files = binaryDirectory.listFiles(); final File[] files = binaryDirectory.listFiles();
if (files == null) { if (files == null)
{
throw new IllegalStateException("Didn't manage to compile jars!"); throw new IllegalStateException("Didn't manage to compile jars!");
} else if (files.length == 0) { }
else if (files.length == 0)
{
throw new IllegalStateException("Didn't manage to compile jars!"); throw new IllegalStateException("Didn't manage to compile jars!");
} }
@ -162,7 +180,8 @@ public class PatchedTelnetCompiler {
done(); done();
} }
private static void done() { private static void done()
{
BukkitTelnetModule.getModule().enable(); BukkitTelnetModule.getModule().enable();
} }
} }