diff --git a/src/com/massivecraft/mcore/ModuloRepeatTask.java b/src/com/massivecraft/mcore/ModuloRepeatTask.java index 14ab3964..d8a256fa 100644 --- a/src/com/massivecraft/mcore/ModuloRepeatTask.java +++ b/src/com/massivecraft/mcore/ModuloRepeatTask.java @@ -23,6 +23,8 @@ public abstract class ModuloRepeatTask implements Runnable public long getPreviousMillis() { return this.previousMillis; } public void setPreviousMillis(long previousMillis) { this.previousMillis = previousMillis; } + private Integer taskId = null; + // -------------------------------------------- // // INVOCATION NUMBER CALCULATION // -------------------------------------------- // @@ -80,9 +82,22 @@ public abstract class ModuloRepeatTask implements Runnable // EIGEN // -------------------------------------------- // + @Deprecated public int schedule(Plugin plugin) { - return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, 1, 1); + this.activate(plugin); + return this.taskId; + } + + public void activate(Plugin plugin) + { + this.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, 1, 1); + } + + public void deactivate() + { + if (this.taskId == null) return; + Bukkit.getScheduler().cancelTask(this.taskId); } // -------------------------------------------- // diff --git a/src/com/massivecraft/mcore/pager/PagerAbstract.java b/src/com/massivecraft/mcore/pager/PagerAbstract.java index f0c8ee7e..bc7d1494 100644 --- a/src/com/massivecraft/mcore/pager/PagerAbstract.java +++ b/src/com/massivecraft/mcore/pager/PagerAbstract.java @@ -77,7 +77,18 @@ public abstract class PagerAbstract implements Pager public String getMessageInvalid() { - return Txt.parse("Invalid, page must be between 1 and %d.", this.size()); + if (this.size() == 0) + { + return this.getMessageEmpty(); + } + else if (this.size() == 1) + { + return Txt.parse("Invalid, there is only one page.", this.size()); + } + else + { + return Txt.parse("Invalid, page must be between 1 and %d.", this.size()); + } } @Override diff --git a/src/com/massivecraft/mcore/util/ClassLoadHack.java b/src/com/massivecraft/mcore/util/ClassLoadHack.java deleted file mode 100644 index d335fadd..00000000 --- a/src/com/massivecraft/mcore/util/ClassLoadHack.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.mcore.util; - -import java.io.File; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; - -public class ClassLoadHack -{ - private static URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader(); - - public static boolean load(String filename) - { - return load(new File(filename)); - } - - public static boolean load(File file) - { - try - { - return load(file.toURI().toURL()); - } - catch (MalformedURLException e) - { - return false; - } - } - - public static boolean load(URL url) - { - // If the file already is loaded we can skip it - for (URL otherUrl : sysloader.getURLs()) - { - if (otherUrl.sameFile(url)) return true; - } - - try - { - Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{ URL.class }); - addURLMethod.setAccessible(true); - addURLMethod.invoke(sysloader, new Object[]{ url }); - return true; - } - catch (Exception e) - { - return false; - } - } - -} diff --git a/src/com/massivecraft/mcore/util/DiscUtil.java b/src/com/massivecraft/mcore/util/DiscUtil.java index 04e9119b..dc87b51c 100644 --- a/src/com/massivecraft/mcore/util/DiscUtil.java +++ b/src/com/massivecraft/mcore/util/DiscUtil.java @@ -1,9 +1,6 @@ package com.massivecraft.mcore.util; import java.io.*; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; public class DiscUtil { @@ -84,33 +81,6 @@ public class DiscUtil } } - // -------------------------------------------- // - // DOWNLOAD - // -------------------------------------------- // - - public static boolean downloadUrl(String urlstring, File file) - { - try - { - URL url = new URL(urlstring); - ReadableByteChannel rbc = Channels.newChannel(url.openStream()); - FileOutputStream fos = new FileOutputStream(file); - fos.getChannel().transferFrom(rbc, 0, 1 << 24); - fos.close(); - return true; - } - catch (Exception e) - { - e.printStackTrace(); - return false; - } - } - - public static boolean downloadUrl(String urlstring, String filename) - { - return downloadUrl(urlstring, new File(filename)); - } - // -------------------------------------------- // // FILE DELETION // -------------------------------------------- // diff --git a/src/com/massivecraft/mcore/util/LibLoader.java b/src/com/massivecraft/mcore/util/LibLoader.java deleted file mode 100644 index b2c9f6d1..00000000 --- a/src/com/massivecraft/mcore/util/LibLoader.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.mcore.util; - -import java.io.File; - -import com.massivecraft.mcore.MCore; -import com.massivecraft.mcore.MPlugin; - -public class LibLoader -{ - public static boolean require(String filename, String url, MPlugin p) - { - if ( ! include(filename, url)) - { - p.log("Failed to load the required library "+filename); - p.suicide(); - return false; - } - return true; - } - - public static boolean include (String filename, String url) - { - File file = getFile(filename); - if ( ! file.exists()) - { - File parent = file.getParentFile(); - if (parent != null && !parent.exists()) parent.mkdirs(); - - MCore.get().log("Downloading library "+filename); - if ( ! DiscUtil.downloadUrl(url, file)) - { - MCore.get().log(Txt.parse("Failed to download %s", filename)); - return false; - } - } - return ClassLoadHack.load(file); - } - - private static File getFile(String filename) - { - return new File("./lib/"+filename); - } - -}