From def4a846b2d2528e4e0542edd49faabdcf7c372e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 19 Feb 2020 10:47:53 +0100 Subject: [PATCH] Reload other plugins, remove plugin updater #84 --- .../buttondevteam/core/ChromaCommand.java | 14 +- .../java/buttondevteam/core/MainPlugin.java | 15 -- .../core/component/updater/PluginUpdater.java | 130 +----------------- 3 files changed, 16 insertions(+), 143 deletions(-) diff --git a/Chroma-Core/src/main/java/buttondevteam/core/ChromaCommand.java b/Chroma-Core/src/main/java/buttondevteam/core/ChromaCommand.java index f17dbf8..7eea87d 100644 --- a/Chroma-Core/src/main/java/buttondevteam/core/ChromaCommand.java +++ b/Chroma-Core/src/main/java/buttondevteam/core/ChromaCommand.java @@ -1,16 +1,22 @@ package buttondevteam.core; +import buttondevteam.lib.architecture.ButtonPlugin; import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.ICommand2MC; import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; @CommandClass public class ChromaCommand extends ICommand2MC { - @Command2.Subcommand //TODO: Main permissions (groups) like 'mod' - public void reload(CommandSender sender) { - if (MainPlugin.Instance.tryReloadConfig()) - sender.sendMessage("§bCore config reloaded."); + @Command2.Subcommand + public void reload(CommandSender sender, @Command2.OptionalArg Plugin plugin) { + if(plugin==null) + plugin=MainPlugin.Instance; + if(!(plugin instanceof ButtonPlugin)) + plugin.reloadConfig(); + else if (((ButtonPlugin) plugin).tryReloadConfig()) + sender.sendMessage("§b"+plugin.getName()+" config reloaded."); else sender.sendMessage("§cFailed to reload config. Check console."); } diff --git a/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java b/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java index b450bf4..e250095 100755 --- a/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java +++ b/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.java @@ -155,21 +155,6 @@ public class MainPlugin extends ButtonPlugin { logger.info("Saving player data..."); TBMCPlayerBase.savePlayers(); logger.info("Player data saved."); - new Thread(() -> { - File[] files = PluginUpdater.updatedir.listFiles(); - if (files == null) - return; - logger.info("Updating " + files.length + " plugins..."); - for (File file : files) { - try { - Files.move(file.toPath(), new File("plugins", file.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING); - logger.info("Updated " + file.getName()); - } catch (IOException e) { - e.printStackTrace(); - } - } - logger.info("Update complete!"); - }).start(); } private boolean setupPermissions() { diff --git a/Chroma-Core/src/main/java/buttondevteam/core/component/updater/PluginUpdater.java b/Chroma-Core/src/main/java/buttondevteam/core/component/updater/PluginUpdater.java index 5454ea1..594124d 100755 --- a/Chroma-Core/src/main/java/buttondevteam/core/component/updater/PluginUpdater.java +++ b/Chroma-Core/src/main/java/buttondevteam/core/component/updater/PluginUpdater.java @@ -17,19 +17,17 @@ import java.util.List; import java.util.Optional; public class PluginUpdater { - private PluginUpdater() { - } - public static final File updatedir = new File("TBMC", "pluginupdates"); + private final File updatedir = Bukkit.getServer().getUpdateFolderFile(); /** * See {@link TBMCCoreAPI#UpdatePlugin(String, CommandSender, String)} */ - public static boolean UpdatePlugin(String name, CommandSender sender, String branch) { + public boolean UpdatePlugin(String name, CommandSender sender, String branch) { if (!updatedir.exists() && !updatedir.mkdirs()) { error(sender, "Failed to create update directory!"); return false; } - info(sender, "Checking plugin name..."); + /*info(sender, "Checking plugin name..."); List plugins = GetPluginNames(); String correctname = null; for (String plugin : plugins) { @@ -58,61 +56,9 @@ public class PluginUpdater { return false; } info(sender, "Updating TBMC plugin: " + correctname + " from " + correctbranch.get()); - return updatePluginJitPack(sender, correctname, correctbranch.get()); - } - - private static boolean updatePluginJitPack(CommandSender sender, String correctname, - String correctbranch) { - /*URL url; - File result = new File(updatedir, correctname + ".jar"); - try { - url = new URL("https://jitpack.io/com/github/TBMCPlugins/" - + (correctname.equals("ButtonCore") ? "ButtonCore/ButtonCore" : correctname) + "/" - + correctbranch + "-SNAPSHOT/" + correctname + "-" + correctbranch + "-SNAPSHOT.jar"); // ButtonCore exception required since it hosts Towny as well - FileUtils.copyURLToFile(url, result); - if (!result.exists() || result.length() < 25) { - result.delete(); - error(sender, "The downloaded JAR for " + correctname + " from " + correctbranch - + " is too small (smnaller than 25 bytes). Am I downloading from the right place?"); - return false; - } else { - info(sender, "Updating plugin " + correctname + " from " + correctbranch + " done!"); - return true; - } - } catch (FileNotFoundException e) { - error(sender, - "Can't find JAR for " + correctname + " from " + correctbranch - + ", the build probably failed. Build log (scroll to bottom):" + "\n" - + "https://jitpack.io/com/github/TBMCPlugins/" + correctname + "/" + correctbranch - + "-SNAPSHOT/build.log\nIf you'd like to rebuild the same commit, go to:\nhttps://jitpack.io/#TBMCPlugins/" - + correctname + "\nAnd delete the newest build."); - } catch (IOException e) { - error(sender, "IO error while updating " + correctname + "\n" + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - error(sender, "Unknown error while updating " + correctname + ": " + e); - TODO: Either add Commons or don't use FileUtils - }*/ - info(sender, "Plugin updating is currently not supported"); - return false; - } - - /** - * Checks if pom.xml is not present for the project. - * - * @param pluginname - * Does not have to match case - * @param branch - * Does not have to match case - */ - public static boolean isNotMaven(String pluginname, String branch) { - try { - return TBMCCoreAPI - .DownloadString( - "https://raw.githubusercontent.com/TBMCPlugins/" + pluginname + "/" + branch + "/pom.xml") - .equals("404: Not Found\n"); - } catch (IOException e1) { - return true; - } + return updatePluginJitPack(sender, correctname, correctbranch.get());*/ + info(sender, "Not implemented"); + return true; } private static void error(CommandSender sender, String message) { @@ -126,68 +72,4 @@ public class PluginUpdater { Bukkit.getLogger().info(message); sender.sendMessage("§b" + message); } - - /** - * Retrieves all the repository names from the GitHub organization. - * - * @return A list of names - */ - public static List GetPluginNames() { - List ret = new ArrayList<>(); - try { - String resp = TBMCCoreAPI.DownloadString("https://api.github.com/orgs/" + "TBMCPlugins" + "/repos"); //TODO: PluginUpdater - JsonArray arr = new JsonParser().parse(resp).getAsJsonArray(); - for (JsonElement obj : arr) { - JsonObject jobj = obj.getAsJsonObject(); - ret.add(jobj.get("name").getAsString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - return ret; - } - - /** - * Retrieves all the branches from the plugin repository. - * - * @return A list of names - */ - public static List GetPluginBranches(String plugin) { - List ret = new ArrayList<>(); - try { - String resp = TBMCCoreAPI - .DownloadString("https://api.github.com/repos/TBMCPlugins/" + plugin + "/branches"); - JsonArray arr = new JsonParser().parse(resp).getAsJsonArray(); - for (JsonElement obj : arr) { - JsonObject jobj = obj.getAsJsonObject(); - ret.add(jobj.get("name").getAsString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - return ret; - } - - public static class UpdatedEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - - private final JsonObject data; - - public UpdatedEvent(JsonObject data) { - this.data = data; - } - - public JsonObject getData() { - return data; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - } }