commit cd50091bf6dc13040d0766a8d83faac4f9a6ea60 Author: sigonasr2 Date: Tue Dec 20 01:47:11 2016 -0600 Initial Commit. Auto Plugin Updater Project initialized. diff --git a/AutoPluginUpdate.jar b/AutoPluginUpdate.jar new file mode 100644 index 0000000..e2b2e1e Binary files /dev/null and b/AutoPluginUpdate.jar differ diff --git a/projectBuilder.xml b/projectBuilder.xml new file mode 100644 index 0000000..f323917 --- /dev/null +++ b/projectBuilder.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..97734d3 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,4 @@ +name: AutoPluginUpdate +main: sig.plugin.AutoPluginUpdate.AutoPluginUpdate +version: 001 +commands: \ No newline at end of file diff --git a/src/sig/plugin/AutoPluginUpdate/API.java b/src/sig/plugin/AutoPluginUpdate/API.java new file mode 100644 index 0000000..bb116a7 --- /dev/null +++ b/src/sig/plugin/AutoPluginUpdate/API.java @@ -0,0 +1,9 @@ +package sig.plugin.AutoPluginUpdate; + +import org.bukkit.entity.Player; + +public final class API { + public static void FetchPlugins() { + AutoPluginUpdate.pluginupdater.FetchPlugins(); + } +} diff --git a/src/sig/plugin/AutoPluginUpdate/AnnounceUpdateEvent.java b/src/sig/plugin/AutoPluginUpdate/AnnounceUpdateEvent.java new file mode 100644 index 0000000..742d8fa --- /dev/null +++ b/src/sig/plugin/AutoPluginUpdate/AnnounceUpdateEvent.java @@ -0,0 +1,23 @@ +package sig.plugin.AutoPluginUpdate; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class AnnounceUpdateEvent extends Event{ + private static final HandlerList handlers = new HandlerList(); + private String announce_msg; + + public AnnounceUpdateEvent(String announce_msg) { + this.announce_msg=announce_msg; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public String getAnnouncementMessage() { + return announce_msg; + } + +} diff --git a/src/sig/plugin/AutoPluginUpdate/AutoPluginUpdate.java b/src/sig/plugin/AutoPluginUpdate/AutoPluginUpdate.java new file mode 100644 index 0000000..c23da89 --- /dev/null +++ b/src/sig/plugin/AutoPluginUpdate/AutoPluginUpdate.java @@ -0,0 +1,128 @@ +package sig.plugin.AutoPluginUpdate; + +import java.io.File; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class AutoPluginUpdate extends JavaPlugin implements Listener{ + + public final String LOG_PREFIX = "[AutoPluginUpdate]"; + + public AutoPluginUpdate plugin = this; + public static File datafolder; + public static boolean restarting_server=false; + + public final int LOG_ERROR=0; + public final int LOG_WARNING=1; + public final int LOG_NORMAL=2; + public final int LOG_DETAIL=3; + public final int LOG_VERBOSE=4; + public final int LOG_DEBUG=5; + + public static PluginManager pluginupdater; + + @Override + public void onEnable() { + log("Booting up...",LOG_NORMAL); + datafolder = getDataFolder(); + log("Data folder is located at "+datafolder,LOG_DETAIL); + + pluginupdater = new PluginManager(plugin); + pluginupdater.AddPlugin("TwosideKeeper", "https://dl.dropboxusercontent.com/s/z5ram6vi3jipiit/TwosideKeeper.jar"); + pluginupdater.AddPlugin("aPlugin", "https://dl.dropboxusercontent.com/u/62434995/aPlugin.jar"); + + Bukkit.getPluginManager().registerEvents(this, this); + + if (!restarting_server) { + Bukkit.getScheduler().runTaskTimerAsynchronously(this, pluginupdater, 6000l, 6000l); + } + } + + @Override + public void onDisable() { + + } + + @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent ev) { + if (!restarting_server) { + Bukkit.getScheduler().runTaskAsynchronously(this, pluginupdater); + } + } + + @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) + public void onPlayerLeave(PlayerQuitEvent ev) { + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new ShutdownServerForUpdate(),5); + } + + private void log(String msg, int loglv) { + switch (loglv) { + case LOG_ERROR:{ + Bukkit.getConsoleSender().sendMessage(LOG_PREFIX+" "+ChatColor.RED+"[ERROR]"+ChatColor.RESET+msg+ChatColor.RESET); + }break; + case LOG_WARNING:{ + Bukkit.getConsoleSender().sendMessage(LOG_PREFIX+" "+ChatColor.YELLOW+"[WARNING]"+ChatColor.RESET+msg+ChatColor.RESET); + }break; + default:{ + Bukkit.getConsoleSender().sendMessage(LOG_PREFIX+" "+ChatColor.RESET+msg+ChatColor.RESET); + }break; + } + } + + private final class ShutdownServerForUpdate implements Runnable { + @Override + public void run() { + if (Bukkit.getOnlinePlayers().size()==0 && restarting_server) { + Bukkit.savePlayers(); + for (int i=0;i