More reformatting
This commit is contained in:
@@ -32,42 +32,40 @@ public class AsciiCompass {
|
||||
}
|
||||
|
||||
public static AsciiCompass.Point getCompassPointForDirection(double inDegrees) {
|
||||
double degrees = (inDegrees - 180) % 360;
|
||||
if (degrees < 0) { degrees += 360; }
|
||||
double degrees = (inDegrees - 180) % 360; if (degrees < 0) { degrees += 360; }
|
||||
|
||||
if (0 <= degrees && degrees < 22.5) { return AsciiCompass.Point.N; }
|
||||
else if (22.5 <= degrees && degrees < 67.5) { return AsciiCompass.Point.NE; }
|
||||
else if (67.5 <= degrees && degrees < 112.5) { return AsciiCompass.Point.E; }
|
||||
else if (112.5 <= degrees && degrees < 157.5) { return AsciiCompass.Point.SE; }
|
||||
else if (157.5 <= degrees && degrees < 202.5) { return AsciiCompass.Point.S; }
|
||||
else if (202.5 <= degrees && degrees < 247.5) { return AsciiCompass.Point.SW; }
|
||||
else if (247.5 <= degrees && degrees < 292.5) { return AsciiCompass.Point.W; }
|
||||
else if (292.5 <= degrees && degrees < 337.5) { return AsciiCompass.Point.NW; }
|
||||
else if (337.5 <= degrees && degrees < 360.0) { return AsciiCompass.Point.N; }
|
||||
else { return null; }
|
||||
if (0 <= degrees && degrees < 22.5) {
|
||||
return AsciiCompass.Point.N;
|
||||
} else if (22.5 <= degrees && degrees < 67.5) {
|
||||
return AsciiCompass.Point.NE;
|
||||
} else if (67.5 <= degrees && degrees < 112.5) {
|
||||
return AsciiCompass.Point.E;
|
||||
} else if (112.5 <= degrees && degrees < 157.5) {
|
||||
return AsciiCompass.Point.SE;
|
||||
} else if (157.5 <= degrees && degrees < 202.5) {
|
||||
return AsciiCompass.Point.S;
|
||||
} else if (202.5 <= degrees && degrees < 247.5) {
|
||||
return AsciiCompass.Point.SW;
|
||||
} else if (247.5 <= degrees && degrees < 292.5) {
|
||||
return AsciiCompass.Point.W;
|
||||
} else if (292.5 <= degrees && degrees < 337.5) {
|
||||
return AsciiCompass.Point.NW;
|
||||
} else if (337.5 <= degrees && degrees < 360.0) { return AsciiCompass.Point.N; } else { return null; }
|
||||
}
|
||||
|
||||
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
String row;
|
||||
ArrayList<String> ret = new ArrayList<String>(); String row;
|
||||
|
||||
row = "";
|
||||
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
|
||||
row = ""; row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
|
||||
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
|
||||
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault); ret.add(row);
|
||||
|
||||
row = "";
|
||||
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
|
||||
row += colorDefault + "+";
|
||||
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
row = ""; row += Point.W.toString(Point.W == point, colorActive, colorDefault); row += colorDefault + "+";
|
||||
row += Point.E.toString(Point.E == point, colorActive, colorDefault); ret.add(row);
|
||||
|
||||
row = "";
|
||||
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
|
||||
row = ""; row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
|
||||
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
|
||||
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
|
||||
ret.add(row);
|
||||
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault); ret.add(row);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -14,17 +14,14 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
private transient double toleranceMillis;
|
||||
|
||||
public AutoLeaveProcessTask() {
|
||||
ArrayList<FPlayer> fplayers = new ArrayList<FPlayer>(FPlayers.i.get());
|
||||
this.iterator = fplayers.listIterator();
|
||||
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
|
||||
this.readyToGo = true;
|
||||
ArrayList<FPlayer> fplayers = new ArrayList<FPlayer>(FPlayers.i.get()); this.iterator = fplayers.listIterator();
|
||||
this.toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000; this.readyToGo = true;
|
||||
this.finished = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (Conf.autoLeaveAfterDaysOfInactivity <= 0.0 || Conf.autoLeaveRoutineMaxMillisecondsPerTick <= 0.0) {
|
||||
this.stop();
|
||||
return;
|
||||
this.stop(); return;
|
||||
}
|
||||
|
||||
if (!readyToGo) { return; }
|
||||
@@ -38,8 +35,7 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
|
||||
// if this iteration has been running for maximum time, stop to take a breather until next tick
|
||||
if (now > loopStartTime + Conf.autoLeaveRoutineMaxMillisecondsPerTick) {
|
||||
readyToGo = true;
|
||||
return;
|
||||
readyToGo = true; return;
|
||||
}
|
||||
|
||||
FPlayer fplayer = iterator.next();
|
||||
@@ -54,8 +50,7 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
if (faction != null) { fplayer.getFaction().promoteNewLeader(); }
|
||||
}
|
||||
|
||||
fplayer.leave(false);
|
||||
iterator.remove(); // go ahead and remove this list's link to the FPlayer object
|
||||
fplayer.leave(false); iterator.remove(); // go ahead and remove this list's link to the FPlayer object
|
||||
fplayer.detach();
|
||||
}
|
||||
}
|
||||
@@ -66,8 +61,7 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
|
||||
|
||||
// we're done, shut down
|
||||
public void stop() {
|
||||
readyToGo = false;
|
||||
finished = true;
|
||||
readyToGo = false; finished = true;
|
||||
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ public class AutoLeaveTask implements Runnable {
|
||||
public synchronized void run() {
|
||||
if (task != null && !task.isFinished()) { return; }
|
||||
|
||||
task = new AutoLeaveProcessTask();
|
||||
task.runTaskTimer(P.p, 1, 1);
|
||||
task = new AutoLeaveProcessTask(); task.runTaskTimer(P.p, 1, 1);
|
||||
|
||||
// maybe setting has been changed? if so, restart this task at new rate
|
||||
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) { P.p.startAutoLeaveTask(true); }
|
||||
|
||||
@@ -27,30 +27,19 @@ public class LazyLocation {
|
||||
}
|
||||
|
||||
public LazyLocation(final String worldName, final double x, final double y, final double z, final float yaw, final float pitch) {
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.worldName = worldName; this.x = x; this.y = y; this.z = z; this.yaw = yaw; this.pitch = pitch;
|
||||
}
|
||||
|
||||
// This returns the actual Location
|
||||
public final Location getLocation() {
|
||||
// make sure Location is initialized before returning it
|
||||
initLocation();
|
||||
return location;
|
||||
initLocation(); return location;
|
||||
}
|
||||
|
||||
// change the Location
|
||||
public final void setLocation(Location loc) {
|
||||
this.location = loc;
|
||||
this.worldName = loc.getWorld().getName();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
this.yaw = loc.getYaw();
|
||||
this.pitch = loc.getPitch();
|
||||
this.location = loc; this.worldName = loc.getWorld().getName(); this.x = loc.getX(); this.y = loc.getY();
|
||||
this.z = loc.getZ(); this.yaw = loc.getYaw(); this.pitch = loc.getPitch();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +49,7 @@ public class LazyLocation {
|
||||
if (location != null) { return; }
|
||||
|
||||
// get World; hopefully it's initialized at this point
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) { return; }
|
||||
World world = Bukkit.getWorld(worldName); if (world == null) { return; }
|
||||
|
||||
// store the Location for future calls, and pass it on
|
||||
location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
@@ -19,27 +19,20 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
|
||||
@Override
|
||||
public Map<FLocation, Set<String>> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
if (obj == null) {
|
||||
JsonObject obj = json.getAsJsonObject(); if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<FLocation, Set<String>> locationMap = new ConcurrentHashMap<FLocation, Set<String>>();
|
||||
Set<String> nameSet;
|
||||
Iterator<JsonElement> iter;
|
||||
String worldName;
|
||||
String[] coords;
|
||||
int x, z;
|
||||
Set<String> nameSet; Iterator<JsonElement> iter; String worldName; String[] coords; int x, z;
|
||||
|
||||
for (Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||
worldName = entry.getKey();
|
||||
for (Entry<String, JsonElement> entry2 : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
coords = entry2.getKey().trim().split("[,\\s]+");
|
||||
x = Integer.parseInt(coords[0]);
|
||||
coords = entry2.getKey().trim().split("[,\\s]+"); x = Integer.parseInt(coords[0]);
|
||||
z = Integer.parseInt(coords[1]);
|
||||
|
||||
nameSet = new HashSet<String>();
|
||||
iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
nameSet = new HashSet<String>(); iter = entry2.getValue().getAsJsonArray().iterator();
|
||||
while (iter.hasNext()) {
|
||||
nameSet.add(iter.next().getAsString());
|
||||
}
|
||||
@@ -63,27 +56,18 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
|
||||
|
||||
try {
|
||||
if (src != null) {
|
||||
FLocation loc;
|
||||
String locWorld;
|
||||
Set<String> nameSet;
|
||||
Iterator<String> iter;
|
||||
JsonArray nameArray;
|
||||
FLocation loc; String locWorld; Set<String> nameSet; Iterator<String> iter; JsonArray nameArray;
|
||||
JsonPrimitive nameElement;
|
||||
|
||||
for (Entry<FLocation, Set<String>> entry : src.entrySet()) {
|
||||
loc = entry.getKey();
|
||||
locWorld = loc.getWorldName();
|
||||
nameSet = entry.getValue();
|
||||
loc = entry.getKey(); locWorld = loc.getWorldName(); nameSet = entry.getValue();
|
||||
|
||||
if (nameSet == null || nameSet.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nameArray = new JsonArray();
|
||||
iter = nameSet.iterator();
|
||||
while (iter.hasNext()) {
|
||||
nameElement = new JsonPrimitive(iter.next());
|
||||
nameArray.add(nameElement);
|
||||
nameArray = new JsonArray(); iter = nameSet.iterator(); while (iter.hasNext()) {
|
||||
nameElement = new JsonPrimitive(iter.next()); nameArray.add(nameElement);
|
||||
}
|
||||
|
||||
if (!obj.has(locWorld)) {
|
||||
@@ -92,8 +76,7 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLoca
|
||||
|
||||
obj.get(locWorld).getAsJsonObject().add(loc.getCoordString(), nameArray);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
} return obj;
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -97,12 +97,10 @@ public final class Metrics {
|
||||
this.plugin = plugin;
|
||||
|
||||
// load the config
|
||||
configurationFile = getConfigFile();
|
||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
configurationFile = getConfigFile(); configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
|
||||
// add some defaults
|
||||
configuration.addDefault("opt-out", false);
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("opt-out", false); configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("debug", false);
|
||||
|
||||
// Do we need to create the file?
|
||||
@@ -112,8 +110,7 @@ public final class Metrics {
|
||||
}
|
||||
|
||||
// Load the guid then
|
||||
guid = configuration.getString("guid");
|
||||
debug = configuration.getBoolean("debug", false);
|
||||
guid = configuration.getString("guid"); debug = configuration.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,8 +143,7 @@ public final class Metrics {
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
task.cancel(); task = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,8 +186,7 @@ public final class Metrics {
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
configuration.set("opt-out", false); configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
@@ -211,14 +206,12 @@ public final class Metrics {
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
configuration.set("opt-out", true); configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
task.cancel(); task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,30 +238,24 @@ public final class Metrics {
|
||||
*/
|
||||
private void postPlugin(boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
String pluginName = description.getName();
|
||||
PluginDescriptionFile description = plugin.getDescription(); String pluginName = description.getName();
|
||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
String pluginVersion = description.getVersion();
|
||||
String serverVersion = Bukkit.getVersion();
|
||||
String pluginVersion = description.getVersion(); String serverVersion = Bukkit.getVersion();
|
||||
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
// Construct the post data
|
||||
StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
StringBuilder json = new StringBuilder(1024); json.append('{');
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "guid", guid); appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
// New data as of R6
|
||||
String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version");
|
||||
String java_version = System.getProperty("java.version");
|
||||
String osname = System.getProperty("os.name"); String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version"); String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
@@ -276,12 +263,9 @@ public final class Metrics {
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
appendJSONPair(json, "osname", osname);
|
||||
appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion);
|
||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
appendJSONPair(json, "osname", osname); appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion); appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
@@ -301,14 +285,12 @@ public final class Metrics {
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent()) {
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
|
||||
byte[] uncompressed = json.toString().getBytes();
|
||||
byte[] compressed = gzip(json.toString());
|
||||
byte[] uncompressed = json.toString().getBytes(); byte[] compressed = gzip(json.toString());
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
@@ -325,23 +307,19 @@ public final class Metrics {
|
||||
}
|
||||
|
||||
// Write the data
|
||||
OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
OutputStream os = connection.getOutputStream(); os.write(compressed); os.flush();
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String response = reader.readLine();
|
||||
|
||||
// close resources
|
||||
os.close();
|
||||
reader.close();
|
||||
os.close(); reader.close();
|
||||
|
||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
response = "null";
|
||||
}
|
||||
else if (response.startsWith("7")) {
|
||||
} else if (response.startsWith("7")) {
|
||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||
}
|
||||
|
||||
@@ -357,12 +335,10 @@ public final class Metrics {
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = null;
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
gzos = new GZIPOutputStream(baos); gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@@ -384,8 +360,7 @@ public final class Metrics {
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
Class.forName("mineshafter.MineServer"); return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
@@ -405,8 +380,7 @@ public final class Metrics {
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
Double.parseDouble(value); isValueNumeric = true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
@@ -416,13 +390,11 @@ public final class Metrics {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
json.append(escapeJSON(key)); json.append(':');
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
@@ -437,40 +409,21 @@ public final class Metrics {
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
builder.append('"'); for (int index = 0; index < text.length(); index++) {
|
||||
char chr = text.charAt(index);
|
||||
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
case '"': case '\\': builder.append('\\'); builder.append(chr); break;
|
||||
case '\b': builder.append("\\b"); break; case '\t': builder.append("\\t"); break;
|
||||
case '\n': builder.append("\\n"); break; case '\r': builder.append("\\r"); break;
|
||||
default: if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u").append(t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u").append(t.substring(t.length() - 4));
|
||||
}
|
||||
else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
} builder.append('"');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ public class MiscUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
String name = entity.getClass().getSimpleName();
|
||||
name = name.substring(5); // Remove "Craft"
|
||||
String name = entity.getClass().getSimpleName(); name = name.substring(5); // Remove "Craft"
|
||||
|
||||
return EntityType.fromName(name);
|
||||
}
|
||||
@@ -25,9 +24,7 @@ public class MiscUtil {
|
||||
long[] values = new long[(int) Math.abs(end - start) + 1];
|
||||
|
||||
if (end < start) {
|
||||
long oldstart = start;
|
||||
start = end;
|
||||
end = oldstart;
|
||||
long oldstart = start; start = end; end = oldstart;
|
||||
}
|
||||
|
||||
for (long i = start; i <= end; i++) {
|
||||
@@ -38,25 +35,18 @@ public class MiscUtil {
|
||||
}
|
||||
|
||||
/// TODO create tag whitelist!!
|
||||
public static HashSet<String> substanceChars = new HashSet<String>(Arrays.asList(new String[]{
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
|
||||
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
|
||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
|
||||
"s", "t", "u", "v", "w", "x", "y", "z"
|
||||
}));
|
||||
public static HashSet<String> substanceChars = new HashSet<String>(Arrays.asList(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}));
|
||||
|
||||
public static String getComparisonString(String str) {
|
||||
String ret = "";
|
||||
|
||||
str = ChatColor.stripColor(str);
|
||||
str = str.toLowerCase();
|
||||
str = ChatColor.stripColor(str); str = str.toLowerCase();
|
||||
|
||||
for (char c : str.toCharArray()) {
|
||||
if (substanceChars.contains(String.valueOf(c))) {
|
||||
ret += c;
|
||||
}
|
||||
}
|
||||
return ret.toLowerCase();
|
||||
} return ret.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,18 +20,14 @@ public class MyLocationTypeAdapter implements JsonDeserializer<LazyLocation>, Js
|
||||
try {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
String worldName = obj.get(WORLD).getAsString();
|
||||
double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble();
|
||||
double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat();
|
||||
float pitch = obj.get(PITCH).getAsFloat();
|
||||
String worldName = obj.get(WORLD).getAsString(); double x = obj.get(X).getAsDouble();
|
||||
double y = obj.get(Y).getAsDouble(); double z = obj.get(Z).getAsDouble();
|
||||
float yaw = obj.get(YAW).getAsFloat(); float pitch = obj.get(PITCH).getAsFloat();
|
||||
|
||||
return new LazyLocation(worldName, x, y, z, yaw, pitch);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
|
||||
ex.printStackTrace(); P.p.log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -41,17 +37,12 @@ public class MyLocationTypeAdapter implements JsonDeserializer<LazyLocation>, Js
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
try {
|
||||
obj.addProperty(WORLD, src.getWorldName());
|
||||
obj.addProperty(X, src.getX());
|
||||
obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ());
|
||||
obj.addProperty(YAW, src.getYaw());
|
||||
obj.addProperty(PITCH, src.getPitch());
|
||||
obj.addProperty(WORLD, src.getWorldName()); obj.addProperty(X, src.getX()); obj.addProperty(Y, src.getY());
|
||||
obj.addProperty(Z, src.getZ()); obj.addProperty(YAW, src.getYaw()); obj.addProperty(PITCH, src.getPitch());
|
||||
|
||||
return obj;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
|
||||
ex.printStackTrace(); P.p.log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ public class RelationUtil {
|
||||
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) {
|
||||
String ret = "";
|
||||
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction == null) {
|
||||
Faction thatFaction = getFaction(that); if (thatFaction == null) {
|
||||
return "ERROR"; // ERROR
|
||||
}
|
||||
|
||||
@@ -23,20 +22,15 @@ public class RelationUtil {
|
||||
if (that instanceof Faction) {
|
||||
if (me instanceof FPlayer && myFaction == thatFaction) {
|
||||
ret = "your faction";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ret = thatFaction.getTag();
|
||||
}
|
||||
}
|
||||
else if (that instanceof FPlayer) {
|
||||
FPlayer fplayerthat = (FPlayer) that;
|
||||
if (that == me) {
|
||||
} else if (that instanceof FPlayer) {
|
||||
FPlayer fplayerthat = (FPlayer) that; if (that == me) {
|
||||
ret = "you";
|
||||
}
|
||||
else if (thatFaction == myFaction) {
|
||||
} else if (thatFaction == myFaction) {
|
||||
ret = fplayerthat.getNameAndTitle();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ret = fplayerthat.getNameAndTag();
|
||||
}
|
||||
}
|
||||
@@ -57,13 +51,11 @@ public class RelationUtil {
|
||||
}
|
||||
|
||||
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
|
||||
Faction fthat = getFaction(that);
|
||||
if (fthat == null) {
|
||||
Faction fthat = getFaction(that); if (fthat == null) {
|
||||
return Relation.NEUTRAL; // ERROR
|
||||
}
|
||||
|
||||
Faction fme = getFaction(me);
|
||||
if (fme == null) {
|
||||
Faction fme = getFaction(me); if (fme == null) {
|
||||
return Relation.NEUTRAL; // ERROR
|
||||
}
|
||||
|
||||
@@ -100,8 +92,7 @@ public class RelationUtil {
|
||||
}
|
||||
|
||||
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) {
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction != null) {
|
||||
Faction thatFaction = getFaction(that); if (thatFaction != null) {
|
||||
if (thatFaction.isPeaceful() && thatFaction != getFaction(me)) {
|
||||
return Conf.colorPeaceful;
|
||||
}
|
||||
|
||||
@@ -42,15 +42,11 @@ public abstract class SpiralTask implements Runnable {
|
||||
// limit is determined based on spiral leg length for given radius; see insideRadius()
|
||||
this.limit = (radius - 1) * 2;
|
||||
|
||||
this.world = Bukkit.getWorld(fLocation.getWorldName());
|
||||
if (this.world == null) {
|
||||
P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!");
|
||||
this.stop();
|
||||
return;
|
||||
this.world = Bukkit.getWorld(fLocation.getWorldName()); if (this.world == null) {
|
||||
P.p.log(Level.WARNING, "[SpiralTask] A valid world must be specified!"); this.stop(); return;
|
||||
}
|
||||
|
||||
this.x = (int) fLocation.getX();
|
||||
this.z = (int) fLocation.getZ();
|
||||
this.x = (int) fLocation.getX(); this.z = (int) fLocation.getZ();
|
||||
|
||||
this.readyToGo = true;
|
||||
|
||||
@@ -98,8 +94,7 @@ public abstract class SpiralTask implements Runnable {
|
||||
*/
|
||||
|
||||
public final void setTaskID(int ID) {
|
||||
if (ID == -1) { this.stop(); }
|
||||
taskID = ID;
|
||||
if (ID == -1) { this.stop(); } taskID = ID;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
@@ -118,8 +113,7 @@ public abstract class SpiralTask implements Runnable {
|
||||
while (now() < loopStartTime + 20) {
|
||||
// run the primary task on the current X/Z coordinates
|
||||
if (!this.work()) {
|
||||
this.finish();
|
||||
return;
|
||||
this.finish(); return;
|
||||
}
|
||||
|
||||
// move on to next chunk in spiral
|
||||
@@ -140,28 +134,22 @@ public abstract class SpiralTask implements Runnable {
|
||||
|
||||
// if we're outside the radius, we're done
|
||||
if (!this.insideRadius()) { return false; }
|
||||
}
|
||||
else { // one leg/side of the spiral down...
|
||||
current = 0;
|
||||
isZLeg ^= true;
|
||||
} else { // one leg/side of the spiral down...
|
||||
current = 0; isZLeg ^= true;
|
||||
// every second leg (between X and Z legs, negative or positive), length increases
|
||||
if (isZLeg) {
|
||||
isNeg ^= true;
|
||||
length++;
|
||||
isNeg ^= true; length++;
|
||||
}
|
||||
}
|
||||
|
||||
// move one chunk further in the appropriate direction
|
||||
if (isZLeg) { z += (isNeg) ? -1 : 1; }
|
||||
else { x += (isNeg) ? -1 : 1; }
|
||||
if (isZLeg) { z += (isNeg) ? -1 : 1; } else { x += (isNeg) ? -1 : 1; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean insideRadius() {
|
||||
boolean inside = current < limit;
|
||||
if (!inside) { this.finish(); }
|
||||
return inside;
|
||||
boolean inside = current < limit; if (!inside) { this.finish(); } return inside;
|
||||
}
|
||||
|
||||
// for successful completion
|
||||
@@ -174,9 +162,7 @@ public abstract class SpiralTask implements Runnable {
|
||||
public final void stop() {
|
||||
if (!this.valid()) { return; }
|
||||
|
||||
readyToGo = false;
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskID);
|
||||
taskID = -1;
|
||||
readyToGo = false; Bukkit.getServer().getScheduler().cancelTask(taskID); taskID = -1;
|
||||
}
|
||||
|
||||
// is this task still valid/workable?
|
||||
|
||||
Reference in New Issue
Block a user