More housekeeping

This commit is contained in:
gravitylow 2014-04-15 13:42:09 -04:00
parent 68d3145c7d
commit e3c0f6376f
13 changed files with 4 additions and 273 deletions

View File

@ -34,7 +34,7 @@ public class Board {
public static void setIdAt(String id, FLocation flocation) {
clearOwnershipAt(flocation);
if (id == "0") {
if (id.equals("0")) {
removeAt(flocation);
}

View File

@ -41,7 +41,6 @@ public class P extends MPlugin {
public final FactionsEntityListener entityListener;
public final FactionsExploitListener exploitListener;
public final FactionsBlockListener blockListener;
public final FactionsServerListener serverListener;
// Persistance related
private boolean locked = false;
@ -68,7 +67,6 @@ public class P extends MPlugin {
this.entityListener = new FactionsEntityListener(this);
this.exploitListener = new FactionsExploitListener();
this.blockListener = new FactionsBlockListener(this);
this.serverListener = new FactionsServerListener(this);
}
@ -112,7 +110,6 @@ public class P extends MPlugin {
getServer().getPluginManager().registerEvents(entityListener, this);
getServer().getPluginManager().registerEvents(exploitListener, this);
getServer().getPluginManager().registerEvents(blockListener, this);
getServer().getPluginManager().registerEvents(serverListener, this);
// since some other plugins execute commands directly through this command interface, provide it
this.getCommand(this.refCommand).setExecutor(this);

View File

@ -55,7 +55,7 @@ public class CmdConfig extends FCommand {
return;
}
String success = "";
String success;
String value = args.get(1);
for (int i = 2; i < args.size(); i++) {

View File

@ -124,10 +124,6 @@ public class Worldguard {
e.printStackTrace();
}
region = null;
allregionslist = null;
overlaps = null;
return foundregions;
}
}

View File

@ -95,7 +95,7 @@ public class FactionsChatListener implements Listener {
String msg = event.getMessage();
String eventFormat = event.getFormat();
FPlayer me = FPlayers.i.get(talkingPlayer);
int InsertIndex = 0;
int InsertIndex;
if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) {
// we're using the "replace" method of inserting the faction tags

View File

@ -1,29 +0,0 @@
package com.massivecraft.factions.listeners;
import com.massivecraft.factions.P;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
public class FactionsServerListener implements Listener {
public P p;
public FactionsServerListener(P p) {
this.p = p;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
String name = event.getPlugin().getDescription().getName();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
Plugin plug = event.getPlugin();
String name = plug.getDescription().getName();
}
}

View File

@ -10,12 +10,11 @@ import java.util.ListIterator;
public class AutoLeaveProcessTask extends BukkitRunnable {
private transient boolean readyToGo = false;
private transient boolean finished = false;
private transient ArrayList<FPlayer> fplayers;
private transient ListIterator<FPlayer> iterator;
private transient double toleranceMillis;
public AutoLeaveProcessTask() {
fplayers = new ArrayList<FPlayer>(FPlayers.i.get());
ArrayList<FPlayer> fplayers = new ArrayList<FPlayer>(FPlayers.i.get());
this.iterator = fplayers.listIterator();
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
this.readyToGo = true;

View File

@ -3,7 +3,6 @@ package com.massivecraft.factions.zcore;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.zcore.persist.EM;
import com.massivecraft.factions.zcore.persist.SaveTask;
import com.massivecraft.factions.zcore.util.LibLoader;
import com.massivecraft.factions.zcore.util.PermUtil;
import com.massivecraft.factions.zcore.util.Persist;
import com.massivecraft.factions.zcore.util.TextUtil;
@ -25,7 +24,6 @@ public abstract class MPlugin extends JavaPlugin {
// Some utils
public Persist persist;
public TextUtil txt;
public LibLoader lib;
public PermUtil perm;
// Persist related
@ -70,7 +68,6 @@ public abstract class MPlugin extends JavaPlugin {
// Create Utility Instances
this.perm = new PermUtil(this);
this.persist = new Persist(this);
this.lib = new LibLoader(this);
// GSON 2.1 is now embedded in CraftBukkit, used by the auto-updater: https://github.com/Bukkit/CraftBukkit/commit/0ed1d1fdbb1e0bc09a70bc7bfdf40c1de8411665
// if ( ! lib.require("gson.jar", "http://search.maven.org/remotecontent?filepath=com/google/code/gson/gson/2.1/gson-2.1.jar")) return false;

View File

@ -1,41 +0,0 @@
package com.massivecraft.factions.zcore.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;
}
}
}

View File

@ -1,9 +1,6 @@
package com.massivecraft.factions.zcore.util;
import java.io.*;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
public class DiscUtil {
// -------------------------------------------- //
@ -67,42 +64,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);
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
// -------------------------------------------- //
public static boolean deleteRecursive(File path) throws FileNotFoundException {
if (!path.exists()) throw new FileNotFoundException(path.getAbsolutePath());
boolean ret = true;
if (path.isDirectory()) {
for (File f : path.listFiles()) {
ret = ret && deleteRecursive(f);
}
}
return ret && path.delete();
}
// -------------------------------------------- //
// UTF8 ENCODE AND DECODE
// -------------------------------------------- //

View File

@ -1,43 +0,0 @@
package com.massivecraft.factions.zcore.util;
import com.massivecraft.factions.zcore.MPlugin;
import java.io.File;
public class LibLoader {
MPlugin p;
public LibLoader(MPlugin p) {
this.p = p;
new File("./lib").mkdirs();
}
public boolean require(String filename, String url) {
if (!include(filename, url)) {
p.log("Failed to load the required library " + filename);
p.suicide();
return false;
}
return true;
}
public boolean include(String filename, String url) {
File file = getFile(filename);
if (!file.exists()) {
p.log("Downloading library " + filename);
if (!DiscUtil.downloadUrl(url, file)) {
p.log("Failed to download " + filename);
return false;
}
}
return ClassLoadHack.load(file);
}
private static File getFile(String filename) {
return new File("./lib/" + filename);
}
}

View File

@ -185,76 +185,6 @@ public class TextUtil {
return ret;
}
// -------------------------------------------- //
// Describing Time
// -------------------------------------------- //
/**
* Using this function you transform a delta in milliseconds to a String like "2 weeks from now" or "7 days ago".
*/
public static final long millisPerSecond = 1000;
public static final long millisPerMinute = 60 * millisPerSecond;
public static final long millisPerHour = 60 * millisPerMinute;
public static final long millisPerDay = 24 * millisPerHour;
public static final long millisPerWeek = 7 * millisPerDay;
public static final long millisPerMonth = 31 * millisPerDay;
public static final long millisPerYear = 365 * millisPerDay;
public static String getTimeDeltaDescriptionRelNow(long millis) {
double absmillis = (double) Math.abs(millis);
String agofromnow = "from now";
String unit;
long num;
if (millis <= 0) {
agofromnow = "ago";
}
// We use a factor 3 below for a reason... why do you think?
// Answer: it is a way to make our round of error smaller.
if (absmillis < 3 * millisPerSecond) {
unit = "milliseconds";
num = (long) (absmillis);
} else if (absmillis < 3 * millisPerMinute) {
unit = "seconds";
num = (long) (absmillis / millisPerSecond);
} else if (absmillis < 3 * millisPerHour) {
unit = "minutes";
num = (long) (absmillis / millisPerMinute);
} else if (absmillis < 3 * millisPerDay) {
unit = "hours";
num = (long) (absmillis / millisPerHour);
} else if (absmillis < 3 * millisPerWeek) {
unit = "days";
num = (long) (absmillis / millisPerDay);
} else if (absmillis < 3 * millisPerMonth) {
unit = "weeks";
num = (long) (absmillis / millisPerWeek);
} else if (absmillis < 3 * millisPerYear) {
unit = "months";
num = (long) (absmillis / millisPerMonth);
} else {
unit = "years";
num = (long) (absmillis / millisPerYear);
}
return "" + num + " " + unit + " " + agofromnow;
}
// -------------------------------------------- //
// String comparison
// -------------------------------------------- //
/*private static int commonStartLength(String a, String b)
{
int len = a.length() < b.length() ? a.length() : b.length();
int i;
for (i = 0; i < len; i++)
{
if (a.charAt(i) != b.charAt(i)) break;
}
return i;
}*/
public static String getBestStartWithCI(Collection<String> candidates, String start) {
String ret = null;
int best = 0;

View File

@ -1,36 +0,0 @@
package com.massivecraft.factions.zcore.util;
import org.bukkit.Bukkit;
import java.io.File;
public class WorldUtil {
// Previously We had crappy support for multiworld management.
// This should however be handled by an external plugin!
/*public static boolean load(String name) {
if (isWorldLoaded(name)) {
return true;
}
if ( ! doesWorldExist(name)) {
return false;
}
Environment env = WorldEnv.get(name);
if (env == null) {
P.log(Level.WARNING, "Failed to load world. Environment was unknown.");
return false;
}
P.p.getServer().createWorld(name, env);
return true;
}*/
public static boolean isWorldLoaded(String name) {
return Bukkit.getServer().getWorld(name) != null;
}
public static boolean doesWorldExist(String name) {
return new File(name, "level.dat").exists();
}
}