diff --git a/src/main/java/dev/nopro263/buildmcfromgit/Config.java b/src/main/java/dev/nopro263/buildmcfromgit/Config.java index f805e9c..528b94e 100644 --- a/src/main/java/dev/nopro263/buildmcfromgit/Config.java +++ b/src/main/java/dev/nopro263/buildmcfromgit/Config.java @@ -11,6 +11,7 @@ import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoader; +import org.bukkit.scheduler.BukkitRunnable; import org.yaml.snakeyaml.reader.StreamReader; import java.io.*; @@ -209,18 +210,37 @@ public void build(CommandSender sender) throws InvalidPluginException, InvalidDe throw new RuntimeException(ex); } - String name = loader.getPluginDescription(f).getName(); - - for(org.bukkit.plugin.Plugin p:Bukkit.getPluginManager().getPlugins()) { - if(p.getName().equals(name)) { - Bukkit.getPluginManager().disablePlugin(p); - PluginUtils.unload(p); + File finalF = f; + new BukkitRunnable() { + @Override + public void run() { + String name = null; + try { + name = loader.getPluginDescription(finalF).getName(); + } catch (InvalidDescriptionException e) { + throw new RuntimeException(e); + } + + for(org.bukkit.plugin.Plugin p:Bukkit.getPluginManager().getPlugins()) { + if(p.getName().equals(name)) { + Bukkit.getPluginManager().disablePlugin(p); + PluginUtils.unload(p); + } + } + + org.bukkit.plugin.Plugin plugin = null; + try { + plugin = Bukkit.getPluginManager().loadPlugin(finalF); + } catch (InvalidPluginException e) { + throw new RuntimeException(e); + } catch (InvalidDescriptionException e) { + throw new RuntimeException(e); + } + plugin.onLoad(); + Bukkit.getPluginManager().enablePlugin(plugin); } - } + }.runTask(Main.getInstance()); - org.bukkit.plugin.Plugin plugin = Bukkit.getPluginManager().loadPlugin(f); - plugin.onLoad(); - Bukkit.getPluginManager().enablePlugin(plugin); } public boolean canBuild(String player, boolean isOp) { diff --git a/src/main/java/dev/nopro263/buildmcfromgit/Main.java b/src/main/java/dev/nopro263/buildmcfromgit/Main.java index 0a181a6..e929738 100644 --- a/src/main/java/dev/nopro263/buildmcfromgit/Main.java +++ b/src/main/java/dev/nopro263/buildmcfromgit/Main.java @@ -12,6 +12,7 @@ public final class Main extends JavaPlugin { private static Config config; + private static Main instance; private void fillDefaultFile(File file) throws IOException { OutputStream stream = Files.newOutputStream(file.toPath()); @@ -49,7 +50,12 @@ private void loadConfig() throws IOException { public static Config getPluginConfig() { return config; } + public static Main getInstance() {return instance;} + @Override + public void onLoad() { + instance = this; + } @Override public void onEnable() { try { diff --git a/src/main/java/dev/nopro263/buildmcfromgit/command/GitBuild.java b/src/main/java/dev/nopro263/buildmcfromgit/command/GitBuild.java index aba05e2..98c7076 100644 --- a/src/main/java/dev/nopro263/buildmcfromgit/command/GitBuild.java +++ b/src/main/java/dev/nopro263/buildmcfromgit/command/GitBuild.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.scheduler.BukkitRunnable; public class GitBuild implements CommandExecutor { @Override @@ -27,14 +28,20 @@ public boolean onCommand(CommandSender commandSender, Command command, String s, } if(canBuild) { - try { - plugin.build(commandSender); - commandSender.sendMessage(ChatColor.GREEN + "Built '" + strings[0] + "' successfully"); - } catch (InvalidPluginException | InvalidDescriptionException | RuntimeException e) { - commandSender.sendMessage(ChatColor.RED + "Building '" + strings[0] + "' failed:"); - commandSender.sendMessage(e.getMessage()); - e.printStackTrace(); - } + new BukkitRunnable() { + @Override + public void run() { + try { + commandSender.sendMessage(ChatColor.GRAY + "Building '" + strings[0] + "'"); + plugin.build(commandSender); + commandSender.sendMessage(ChatColor.GREEN + "Built '" + strings[0] + "' successfully"); + } catch (InvalidPluginException | InvalidDescriptionException | RuntimeException e) { + commandSender.sendMessage(ChatColor.RED + "Building '" + strings[0] + "' failed:"); + commandSender.sendMessage(e.getMessage()); + e.printStackTrace(); + } + } + }.runTaskAsynchronously(Main.getInstance()); } else { commandSender.sendMessage(ChatColor.RED + "You are not allowed to build this"); }