From da6343368e216b14ced935679f1215dd6f829b3e Mon Sep 17 00:00:00 2001 From: Allink Date: Sun, 15 May 2022 01:18:30 +0100 Subject: [PATCH] Check if BukkitTelnet is enabled & delete .gradle folder on compilation success --- .../automation/PatchedTelnetCompiler.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java b/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java index bbbde8f..dac582e 100644 --- a/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java +++ b/src/main/java/dev/plex/automation/PatchedTelnetCompiler.java @@ -31,6 +31,7 @@ public class PatchedTelnetCompiler private static final Path PLUGIN_DIRECTORY = Bukkit.getServer().getPluginsFolder().toPath(); private static final File TARGET_PLUGIN = PLUGIN_DIRECTORY.resolve("BukkitTelnet.jar").toFile(); private static final Path WORKING_DIRECTORY = Path.of(System.getProperty("user.dir")); + private static final Path HIDDEN_GRADLE = WORKING_DIRECTORY.resolve(".gradle"); private static final Path ROOT_PATH = WORKING_DIRECTORY.resolve("build"); private static final Path EXTRACT_TARGET = ROOT_PATH.resolve("extract"); private static final Path EXTRACT_SUBDIR = EXTRACT_TARGET.resolve("BukkitTelnet-master"); @@ -40,6 +41,18 @@ public class PatchedTelnetCompiler public static void execute() throws Exception { + // Check if incorrect BukkitTelnet plugin is present + if (PLUGIN_MANAGER.isPluginEnabled("BukkitTelnet")) + { + Plugin plugin = PLUGIN_MANAGER.getPlugin("BukkitTelnet"); + if (plugin == null) throw new IllegalStateException("Unpatched BukkitTelnet cannot be null while enabled!"); + PLUGIN_MANAGER.disablePlugin(plugin); + + Path path = Path.of(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); + Files.delete(path); + } + + // Create directories final List directories = ImmutableList.of(ROOT_PATH, EXTRACT_TARGET); @@ -170,6 +183,14 @@ public class PatchedTelnetCompiler .map(Path::toFile) .forEach(File::delete); + if (Files.exists(HIDDEN_GRADLE)) + { + Files.walk(HIDDEN_GRADLE) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + Timer timer = new Timer(); final Plugin plugin = PLUGIN_MANAGER.loadPlugin(TARGET_PLUGIN);