diff --git a/src/com/massivecraft/mcore/NaturalOrderComparator.java b/src/com/massivecraft/mcore/NaturalOrderComparator.java index 93a1edc9..2ed8913b 100644 --- a/src/com/massivecraft/mcore/NaturalOrderComparator.java +++ b/src/com/massivecraft/mcore/NaturalOrderComparator.java @@ -44,145 +44,145 @@ public class NaturalOrderComparator implements Comparator // OVERRIDE // -------------------------------------------- // - @Override - public int compare(Object o1, Object o2) - { - String a = o1.toString(); - String b = o2.toString(); + @Override + public int compare(Object o1, Object o2) + { + String a = o1.toString(); + String b = o2.toString(); - int ia = 0, ib = 0; - int nza = 0, nzb = 0; - char ca, cb; - int result; + int ia = 0, ib = 0; + int nza = 0, nzb = 0; + char ca, cb; + int result; - while (true) - { - // only count the number of zeroes leading the last number compared - nza = nzb = 0; + while (true) + { + // only count the number of zeroes leading the last number compared + nza = nzb = 0; - ca = charAt(a, ia); - cb = charAt(b, ib); + ca = charAt(a, ia); + cb = charAt(b, ib); - // skip over leading spaces or zeros - while (Character.isSpaceChar(ca) || ca == '0') - { - if (ca == '0') - { - nza++; - } - else - { - // only count consecutive zeroes - nza = 0; - } + // skip over leading spaces or zeros + while (Character.isSpaceChar(ca) || ca == '0') + { + if (ca == '0') + { + nza++; + } + else + { + // only count consecutive zeroes + nza = 0; + } - ca = charAt(a, ++ia); - } + ca = charAt(a, ++ia); + } - while (Character.isSpaceChar(cb) || cb == '0') - { - if (cb == '0') - { - nzb++; - } - else - { - // only count consecutive zeroes - nzb = 0; - } + while (Character.isSpaceChar(cb) || cb == '0') + { + if (cb == '0') + { + nzb++; + } + else + { + // only count consecutive zeroes + nzb = 0; + } - cb = charAt(b, ++ib); - } + cb = charAt(b, ++ib); + } - // process run of digits - if (Character.isDigit(ca) && Character.isDigit(cb)) - { - if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) - { - return result; - } - } + // process run of digits + if (Character.isDigit(ca) && Character.isDigit(cb)) + { + if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) + { + return result; + } + } - if (ca == 0 && cb == 0) - { - // The strings compare the same. Perhaps the caller - // will want to call strcmp to break the tie. - return nza - nzb; - } + if (ca == 0 && cb == 0) + { + // The strings compare the same. Perhaps the caller + // will want to call strcmp to break the tie. + return nza - nzb; + } - if (ca < cb) - { - return -1; - } - else if (ca > cb) - { - return +1; - } + if (ca < cb) + { + return -1; + } + else if (ca > cb) + { + return +1; + } - ++ia; - ++ib; - } - } + ++ia; + ++ib; + } + } // -------------------------------------------- // // UTIL // -------------------------------------------- // - - int compareRight(String a, String b) - { - int bias = 0; - int ia = 0; - int ib = 0; + + int compareRight(String a, String b) + { + int bias = 0; + int ia = 0; + int ib = 0; - // The longest run of digits wins. That aside, the greatest - // value wins, but we can't know that it will until we've scanned - // both numbers to know that they have the same magnitude, so we - // remember it in BIAS. - for (;; ia++, ib++) - { - char ca = charAt(a, ia); - char cb = charAt(b, ib); + // The longest run of digits wins. That aside, the greatest + // value wins, but we can't know that it will until we've scanned + // both numbers to know that they have the same magnitude, so we + // remember it in BIAS. + for (;; ia++, ib++) + { + char ca = charAt(a, ia); + char cb = charAt(b, ib); - if (!Character.isDigit(ca) && !Character.isDigit(cb)) - { - return bias; - } - else if (!Character.isDigit(ca)) - { - return -1; - } - else if (!Character.isDigit(cb)) - { - return +1; - } - else if (ca < cb) - { - if (bias == 0) - { - bias = -1; - } - } - else if (ca > cb) - { - if (bias == 0) - bias = +1; - } - else if (ca == 0 && cb == 0) - { - return bias; - } - } - } - - static char charAt(String s, int i) - { - if (i >= s.length()) - { - return 0; - } - else - { - return s.charAt(i); - } - } + if (!Character.isDigit(ca) && !Character.isDigit(cb)) + { + return bias; + } + else if (!Character.isDigit(ca)) + { + return -1; + } + else if (!Character.isDigit(cb)) + { + return +1; + } + else if (ca < cb) + { + if (bias == 0) + { + bias = -1; + } + } + else if (ca > cb) + { + if (bias == 0) + bias = +1; + } + else if (ca == 0 && cb == 0) + { + return bias; + } + } + } + + static char charAt(String s, int i) + { + if (i >= s.length()) + { + return 0; + } + else + { + return s.charAt(i); + } + } } \ No newline at end of file diff --git a/src/com/massivecraft/mcore/PriorityComparator.java b/src/com/massivecraft/mcore/PriorityComparator.java index 8a10c479..c916e7a3 100644 --- a/src/com/massivecraft/mcore/PriorityComparator.java +++ b/src/com/massivecraft/mcore/PriorityComparator.java @@ -4,6 +4,17 @@ import java.util.Comparator; public class PriorityComparator implements Comparator { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static PriorityComparator i = new PriorityComparator(); + public static PriorityComparator get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COMPARATOR + // -------------------------------------------- // + @Override public int compare(Prioritized one, Prioritized two) { @@ -14,11 +25,4 @@ public class PriorityComparator implements Comparator return Integer.valueOf(one.getPriority()).compareTo(two.getPriority()); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static PriorityComparator i = new PriorityComparator(); - public static PriorityComparator get() { return i; } - } diff --git a/src/com/massivecraft/mcore/ReversePriorityComparator.java b/src/com/massivecraft/mcore/ReversePriorityComparator.java index 02aed0c9..6059c7eb 100644 --- a/src/com/massivecraft/mcore/ReversePriorityComparator.java +++ b/src/com/massivecraft/mcore/ReversePriorityComparator.java @@ -4,6 +4,17 @@ import java.util.Comparator; public class ReversePriorityComparator implements Comparator { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReversePriorityComparator i = new ReversePriorityComparator(); + public static ReversePriorityComparator get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: COMPARATOR + // -------------------------------------------- // + @Override public int compare(Prioritized one, Prioritized two) { @@ -14,11 +25,4 @@ public class ReversePriorityComparator implements Comparator return Integer.valueOf(two.getPriority()).compareTo(one.getPriority()); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ReversePriorityComparator i = new ReversePriorityComparator(); - public static ReversePriorityComparator get() { return i; } - } diff --git a/src/com/massivecraft/mcore/SimpleConfig.java b/src/com/massivecraft/mcore/SimpleConfig.java index b3fd8f17..1caa6447 100644 --- a/src/com/massivecraft/mcore/SimpleConfig.java +++ b/src/com/massivecraft/mcore/SimpleConfig.java @@ -13,6 +13,7 @@ public class SimpleConfig // -------------------------------------------- // // FIELDS // -------------------------------------------- // + protected transient Plugin plugin; protected Plugin getPlugin() { return this.plugin; } diff --git a/src/com/massivecraft/mcore/adapter/FireworkEffectAdapter.java b/src/com/massivecraft/mcore/adapter/FireworkEffectAdapter.java index 559c05b6..1e88a8ee 100644 --- a/src/com/massivecraft/mcore/adapter/FireworkEffectAdapter.java +++ b/src/com/massivecraft/mcore/adapter/FireworkEffectAdapter.java @@ -23,17 +23,16 @@ public class FireworkEffectAdapter // -------------------------------------------- // public static final String FLICKER = "flicker"; - public static final String TRAIL = "trail"; - public static final String COLORS = "colors"; - public static final String FADE_COLORS = "fade-colors"; - public static final String TYPE = "type"; + public static final String TRAIL = "trail"; + public static final String COLORS = "colors"; + public static final String FADE_COLORS = "fade-colors"; + public static final String TYPE = "type"; - public static final boolean FLICKER_DEFAULT = false; - public static final boolean TRAIL_DEFAULT = false; - public static final List COLORS_DEFAULT = Collections.unmodifiableList(MUtil.list(Color.GREEN)); - public static final List FADE_COLORS_DEFAULT = Collections.unmodifiableList(new ArrayList()); - public static final Type TYPE_DEFAULT = Type.BALL_LARGE; - + public static final boolean FLICKER_DEFAULT = false; + public static final boolean TRAIL_DEFAULT = false; + public static final List COLORS_DEFAULT = Collections.unmodifiableList(MUtil.list(Color.GREEN)); + public static final List FADE_COLORS_DEFAULT = Collections.unmodifiableList(new ArrayList()); + public static final Type TYPE_DEFAULT = Type.BALL_LARGE; // -------------------------------------------- // // TO JSON @@ -65,51 +64,51 @@ public class FireworkEffectAdapter JsonObject json = jsonElement.getAsJsonObject(); - boolean flicker = FLICKER_DEFAULT; - boolean trail = TRAIL_DEFAULT; - List colors = COLORS_DEFAULT; - List fadeColors = FADE_COLORS_DEFAULT; - Type type = TYPE_DEFAULT; + boolean flicker = FLICKER_DEFAULT; + boolean trail = TRAIL_DEFAULT; + List colors = COLORS_DEFAULT; + List fadeColors = FADE_COLORS_DEFAULT; + Type type = TYPE_DEFAULT; - JsonElement element; - - element = json.get(FLICKER); - if (element != null) - { - flicker = element.getAsBoolean(); - } - - element = json.get(TRAIL); - if (element != null) - { - trail = element.getAsBoolean(); - } - - element = json.get(COLORS); - if (element != null) - { - colors = toColorCollection(element); - } - - element = json.get(FADE_COLORS); - if (element != null) - { - fadeColors = toColorCollection(element); - } - - element = json.get(TYPE); - if (element != null) - { - type = Type.valueOf(element.getAsString()); - } + JsonElement element; + + element = json.get(FLICKER); + if (element != null) + { + flicker = element.getAsBoolean(); + } + + element = json.get(TRAIL); + if (element != null) + { + trail = element.getAsBoolean(); + } + + element = json.get(COLORS); + if (element != null) + { + colors = toColorCollection(element); + } + + element = json.get(FADE_COLORS); + if (element != null) + { + fadeColors = toColorCollection(element); + } + + element = json.get(TYPE); + if (element != null) + { + type = Type.valueOf(element.getAsString()); + } FireworkEffect ret = FireworkEffect.builder() - .flicker(flicker) - .trail(trail) - .withColor(colors) - .withFade(fadeColors) - .with(type) - .build(); + .flicker(flicker) + .trail(trail) + .withColor(colors) + .withFade(fadeColors) + .with(type) + .build(); return ret; } diff --git a/src/com/massivecraft/mcore/adapter/InventoryAdapter.java b/src/com/massivecraft/mcore/adapter/InventoryAdapter.java index e12be197..08e949e1 100644 --- a/src/com/massivecraft/mcore/adapter/InventoryAdapter.java +++ b/src/com/massivecraft/mcore/adapter/InventoryAdapter.java @@ -47,7 +47,7 @@ public class InventoryAdapter implements JsonDeserializer, JsonSerial public static InventoryAdapter get() { return i; } // -------------------------------------------- // - // IMPLEMENTATION + // OVERRIDE // -------------------------------------------- // @Override @@ -63,7 +63,7 @@ public class InventoryAdapter implements JsonDeserializer, JsonSerial } // -------------------------------------------- // - // JSON + // IMPLEMENTATION // -------------------------------------------- // public static JsonElement toJson(Inventory src) diff --git a/src/com/massivecraft/mcore/adapter/MongoURIAdapter.java b/src/com/massivecraft/mcore/adapter/MongoURIAdapter.java index 26260052..77d35f4d 100644 --- a/src/com/massivecraft/mcore/adapter/MongoURIAdapter.java +++ b/src/com/massivecraft/mcore/adapter/MongoURIAdapter.java @@ -14,7 +14,14 @@ import com.massivecraft.mcore.xlib.mongodb.MongoURI; public class MongoURIAdapter implements JsonDeserializer, JsonSerializer { // -------------------------------------------- // - // IMPLEMENTATION + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + protected static MongoURIAdapter i = new MongoURIAdapter(); + public static MongoURIAdapter get() { return i; } + + // -------------------------------------------- // + // OVERRIDE // -------------------------------------------- // @Override @@ -42,11 +49,5 @@ public class MongoURIAdapter implements JsonDeserializer, JsonSerializ { return new MongoURI(json.getAsString()); } - - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - protected static MongoURIAdapter i = new MongoURIAdapter(); - public static MongoURIAdapter get() { return i; } + } diff --git a/src/com/massivecraft/mcore/money/Money.java b/src/com/massivecraft/mcore/money/Money.java index c575ea6f..1f0b6a57 100644 --- a/src/com/massivecraft/mcore/money/Money.java +++ b/src/com/massivecraft/mcore/money/Money.java @@ -77,12 +77,22 @@ public class Money return mixin.exists(universe(universe), accountId(accountId)); } + public static boolean exists(Object account) + { + return exists(account, account); + } + public static boolean create(Object universe, Object accountId) { if (disabled(universe)) return false; return mixin.create(universe(universe), accountId(accountId)); } + public static boolean create(Object account) + { + return create(account, account); + } + // -------------------------------------------- // // GET AND SET // -------------------------------------------- // @@ -93,12 +103,22 @@ public class Money return mixin.get(universe(universe), accountId(accountId)); } + public static double get(Object account) + { + return get(account, account); + } + public static boolean set(Object universe, Object accountId, double amount) { if (disabled(universe)) return false; return mixin.set(universe(universe), accountId(accountId), amount); } + public static boolean set(Object account, double amount) + { + return set(account, account, amount); + } + // -------------------------------------------- // // MODIFY // -------------------------------------------- // @@ -109,10 +129,20 @@ public class Money return mixin.add(universe(universe), accountId(accountId), amount); } + public static boolean add(Object account, double amount) + { + return add(account, account, amount); + } + public static boolean subtract(Object universe, Object accountId, double amount) { if (disabled(universe)) return false; return mixin.subtract(universe(universe), accountId(accountId), amount); } + public static boolean subtract(Object account, double amount) + { + return subtract(account, account, amount); + } + }