Pager fixes and removed library download utilities. No need for them anymore.
This commit is contained in:
parent
579919f75f
commit
e54b708936
@ -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);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
@ -77,7 +77,18 @@ public abstract class PagerAbstract<T> implements Pager<T>
|
||||
|
||||
public String getMessageInvalid()
|
||||
{
|
||||
return Txt.parse("<b>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("<b>Invalid, there is only one page.", this.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Txt.parse("<b>Invalid, page must be between 1 and %d.", this.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
// -------------------------------------------- //
|
||||
|
@ -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("<b>Failed to download <h>%s", filename));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return ClassLoadHack.load(file);
|
||||
}
|
||||
|
||||
private static File getFile(String filename)
|
||||
{
|
||||
return new File("./lib/"+filename);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user