Initial Commit. Auto Plugin Updater Project initialized.

master
sigonasr2 8 years ago
commit cd50091bf6
  1. BIN
      AutoPluginUpdate.jar
  2. 8
      projectBuilder.xml
  3. 4
      src/plugin.yml
  4. 9
      src/sig/plugin/AutoPluginUpdate/API.java
  5. 23
      src/sig/plugin/AutoPluginUpdate/AnnounceUpdateEvent.java
  6. 128
      src/sig/plugin/AutoPluginUpdate/AutoPluginUpdate.java

Binary file not shown.

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<project name="AutoPluginUpdate.makejar" default="makejar" basedir=".">
<target name ="makejar" description="Create a jar for the AutoPluginUpdate project">
<jar jarfile="AutoPluginUpdate.jar" includes="**/*.class,**/*.yml" basedir="bin"/>
<jar jarfile="D:\Documents\Test Server\plugins\AutoPluginUpdate.jar" includes="**/*.class,**/*.yml" basedir="bin"/>
</target>
</project>

@ -0,0 +1,4 @@
name: AutoPluginUpdate
main: sig.plugin.AutoPluginUpdate.AutoPluginUpdate
version: 001
commands:

@ -0,0 +1,9 @@
package sig.plugin.AutoPluginUpdate;
import org.bukkit.entity.Player;
public final class API {
public static void FetchPlugins() {
AutoPluginUpdate.pluginupdater.FetchPlugins();
}
}

@ -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;
}
}

@ -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<Bukkit.getWorlds().size();i++) {
Bukkit.getWorlds().get(i).save();
}
Bukkit.shutdown();
}
}
}
public static void updateServer() {
if (Bukkit.getOnlinePlayers().size()!=0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), pluginupdater);
BroadcastMessage(ChatColor.YELLOW+"The server is restarting in 1 minute for a plugin update!");
}
},20*120);
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), pluginupdater);
BroadcastMessage(ChatColor.RED+"The server is restarting in 10 seconds!");
}
},20*170);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), new Runnable() {
@Override
public void run() {
Bukkit.getScheduler().runTask(Bukkit.getPluginManager().getPlugin("AutoPluginUpdate"), pluginupdater);
Bukkit.savePlayers();
BroadcastMessage(ChatColor.ITALIC+"Server is shutting down...");
for (int i=0;i<Bukkit.getWorlds().size();i++) {
Bukkit.getWorlds().get(i).save();
}
Bukkit.shutdown();
}
},20*180*((Bukkit.getOnlinePlayers().size()==0)?0:1)+1);
}
public static void BroadcastMessage(String msg) {
Bukkit.getPluginManager().callEvent(new AnnounceUpdateEvent(msg));
Bukkit.broadcastMessage(msg);
}
}
Loading…
Cancel
Save