StringMan instead of StringUtils

This commit is contained in:
boy0001 2015-07-27 04:38:08 +10:00
parent 042a295a55
commit 393a5bffd5
24 changed files with 277 additions and 182 deletions

View File

@ -43,9 +43,7 @@ import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue;
import com.plotsquared.bukkit.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.generator.ClassicPlotWorld;
import com.plotsquared.bukkit.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.PlotGenerator2;
@ -70,10 +68,8 @@ import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.Logger;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.Logger.LogLevel;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlayerManager;
import com.plotsquared.bukkit.util.SetupUtils;
@ -1549,7 +1545,6 @@ public class PS {
setupStyle();
} catch (final Exception err) {
err.printStackTrace();
Logger.add(LogLevel.DANGER, "Failed to save style.yml");
log("failed to save style.yml");
}
try {
@ -1562,7 +1557,6 @@ public class PS {
config = YamlConfiguration.loadConfiguration(configFile);
setupConfig();
} catch (final Exception err_trans) {
Logger.add(LogLevel.DANGER, "Failed to save settings.yml");
log("Failed to save settings.yml");
}
try {
@ -1575,7 +1569,6 @@ public class PS {
storage = YamlConfiguration.loadConfiguration(storageFile);
setupStorage();
} catch (final Exception err_trans) {
Logger.add(LogLevel.DANGER, "Failed to save storage.yml");
log("Failed to save storage.yml");
}
try {
@ -1583,7 +1576,7 @@ public class PS {
config.save(configFile);
storage.save(storageFile);
} catch (final IOException e) {
Logger.add(LogLevel.DANGER, "Configuration file saving failed");
log("Configuration file saving failed");
e.printStackTrace();
}
}

View File

@ -24,10 +24,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Configuration Node
@ -91,7 +90,7 @@ public class ConfigurationNode {
public Object getDefaultValue() {
if (this.default_value instanceof Object[]) {
return StringUtils.join((Object[]) this.default_value, ",");
return StringMan.join((Object[]) this.default_value, ",");
}
return this.default_value;
}

View File

@ -37,7 +37,6 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.PS;
@ -53,6 +52,7 @@ import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
/**
@ -1100,7 +1100,7 @@ public class SQLManager implements AbstractDB {
}
} else {
element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
if (StringUtils.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
Flag flag = new Flag(FlagManager.getFlag(element, true), "");
flags.put(flag.getKey(), flag);
} else {
@ -1247,7 +1247,7 @@ public class SQLManager implements AbstractDB {
}
public void setFlags(final int id, final Collection<Flag> newflags) {
final String flag_string = StringUtils.join(newflags, ",");
final String flag_string = StringMan.join(newflags, ",");
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {

View File

@ -3,7 +3,7 @@ package com.intellectualcrafters.plot.database;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.util.StringMan;
public abstract class StmtMod<T> {
public abstract String getCreateMySQL(int size);
@ -11,15 +11,15 @@ public abstract class StmtMod<T> {
public String getCreateMySQL(int size, String query, int params) {
final StringBuilder statement = new StringBuilder(query);
for (int i = 0; i < size - 1; i++) {
statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + "),");
statement.append("(" + StringMan.repeat(",(?)", params).substring(1) + "),");
}
statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + ")");
statement.append("(" + StringMan.repeat(",(?)", params).substring(1) + ")");
return statement.toString();
}
public String getCreateSQLite(int size, String query, int params) {
StringBuilder statement = new StringBuilder(query);
String modParams = StringUtils.repeat(",?", params).substring(1);
String modParams = StringMan.repeat(",?", params).substring(1);
for (int i = 0; i < (size - 1); i++) {
statement.append("UNION SELECT " + modParams + " ");
}

View File

@ -20,7 +20,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Created 2014-09-23 for PlotSquared
@ -42,7 +42,7 @@ public class AbstractFlag {
* @param key
*/
public AbstractFlag(final String key, final FlagValue<?> value) {
if (!StringUtils.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
if (!StringMan.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
throw new IllegalArgumentException("Flag must be alphabetic characters");
}
if (key.length() > 16) {

View File

@ -20,7 +20,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.util.StringMan;
public class Flag {
private AbstractFlag key;
@ -36,7 +36,7 @@ public class Flag {
* @throws IllegalArgumentException if you provide inadequate inputs
*/
public Flag(final AbstractFlag key, final String value) {
if (!StringUtils.isAsciiPrintable(value)) {
if (!StringMan.isAsciiPrintable(value)) {
throw new IllegalArgumentException("Flag must be ascii");
}
if (value.length() > 128) {

View File

@ -5,9 +5,8 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Created 2014-11-17 for PlotSquared
@ -298,7 +297,7 @@ public abstract class FlagValue<T> {
@SuppressWarnings("unchecked")
@Override
public String toString(final Object t) {
return StringUtils.join((HashSet<PlotBlock>) t, ",");
return StringMan.join((HashSet<PlotBlock>) t, ",");
}
@SuppressWarnings("unchecked")
@ -357,7 +356,7 @@ public abstract class FlagValue<T> {
@SuppressWarnings("unchecked")
@Override
public String toString(final Object t) {
return StringUtils.join((List<Integer>) t, ",");
return StringMan.join((List<Integer>) t, ",");
}
@SuppressWarnings("unchecked")
@ -405,7 +404,7 @@ public abstract class FlagValue<T> {
@Override
public String toString(final Object t) {
return StringUtils.join((List<String>) t, ",");
return StringMan.join((List<String>) t, ",");
}
@Override
@ -445,7 +444,7 @@ public abstract class FlagValue<T> {
@SuppressWarnings("unchecked")
@Override
public String toString(final Object t) {
return StringUtils.join((List<Double>) t, ",");
return StringMan.join((List<Double>) t, ",");
}
@SuppressWarnings("unchecked")

View File

@ -5,9 +5,10 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import com.plotsquared.bukkit.generator.AugmentedPopulator;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@ -215,8 +216,8 @@ public class BukkitHybridUtils extends HybridUtils {
};
System.gc();
AugmentedPopulator.initCache();
TaskManager.index.increment();
final Integer currentIndex = TaskManager.index.toInteger();
TaskManager.index.incrementAndGet();
final Integer currentIndex = TaskManager.index.get();
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
@ -268,7 +269,7 @@ public class BukkitHybridUtils extends HybridUtils {
}
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
TaskManager.index.increment();
TaskManager.index.incrementAndGet();
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
int bx = bot.getX() >> 4;
@ -291,9 +292,9 @@ public class BukkitHybridUtils extends HybridUtils {
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
final MutableInt count = new MutableInt(0);
final AtomicInteger count = new AtomicInteger(0);
final Integer currentIndex = TaskManager.index.toInteger();
final Integer currentIndex = TaskManager.index.get();
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
@ -312,9 +313,9 @@ public class BukkitHybridUtils extends HybridUtils {
int ex = Math.min((chunk.getX() << 4) + 15, top.getX());
int ez = Math.min((chunk.getZ() << 4) + 15, top.getZ());
// count changes
count.add(checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK));
count.add(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK));
count.add(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) }));
count.addAndGet(checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK));
count.addAndGet(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK));
count.addAndGet(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) }));
}
}, 1);
TaskManager.tasks.put(currentIndex, task);
@ -414,11 +415,11 @@ public class BukkitHybridUtils extends HybridUtils {
BukkitHybridUtils.world = world;
chunks = new ArrayList<ChunkLoc>();
final Plugin plugin = BukkitMain.THIS;
final MutableInt count = new MutableInt(0);
final AtomicInteger count = new AtomicInteger(0);
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
count.increment();
count.incrementAndGet();
if (count.intValue() % 20 == 0) {
PS.log("PROGRESS: " + ((100 * (2048 - chunks.size())) / 2048) + "%");
}

View File

@ -1,11 +1,10 @@
package com.intellectualcrafters.plot.generator;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan;
public abstract class ClassicPlotWorld extends SquarePlotWorld {
public static int ROAD_HEIGHT_DEFAULT = 64;
@ -50,8 +49,8 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
super.loadConfiguration(config);
this.PLOT_BEDROCK = config.getBoolean("plot.bedrock");
this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height"));
this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.filling"), ','));
this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.floor"), ','));
this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringMan.join(config.getStringList("plot.filling"), ','));
this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringMan.join(config.getStringList("plot.floor"), ','));
this.WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block"));
this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
this.ROAD_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.block"));

View File

@ -6,8 +6,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.mutable.MutableInt;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS;
@ -139,12 +138,12 @@ public class PlotAnalysis {
final int[] ratings = new int[plots.size()];
final MutableInt mi = new MutableInt(0);
final AtomicInteger mi = new AtomicInteger(0);
Thread ratingAnalysis = new Thread(new Runnable() {
@Override
public void run() {
for (;mi.intValue() < plots.size(); mi.increment()) {
for (;mi.intValue() < plots.size(); mi.incrementAndGet()) {
int i = mi.intValue();
Plot plot = plots.get(i);
ratings[i] = (int) ((plot.getAverageRating() + plot.getSettings().ratings.size()) * 100);

View File

@ -25,8 +25,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Configuration;
@ -35,6 +33,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.StringMan;
/**
* @author Jesse Boyd
@ -189,7 +188,7 @@ public abstract class PlotWorld {
this.DEFAULT_FLAGS = FlagManager.parseFlags(flags);
} catch (final Exception e) {
e.printStackTrace();
PS.log("&cInvalid default flags for " + this.worldname + ": " + StringUtils.join(flags, ","));
PS.log("&cInvalid default flags for " + this.worldname + ": " + StringMan.join(flags, ","));
this.DEFAULT_FLAGS = new HashMap<>();
}
this.PVP = config.getBoolean("event.pvp");

View File

@ -1,89 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
/**
* Logging of errors and debug messages.
*
* @author Citymonstret
*/
public class Logger {
private static ArrayList<String> entries;
private static File log;
public static void setup(final File file) {
log = file;
entries = new ArrayList<>();
try {
final BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
entries.add(line);
}
reader.close();
} catch (final IOException e) {
PS.log(C.PREFIX.s() + "File setup error Logger#setup");
}
}
public static void write() throws IOException {
final FileWriter writer = new FileWriter(log);
for (final String string : entries) {
writer.write(string + System.lineSeparator());
}
writer.close();
}
public static void add(final LogLevel level, final String string) {
append("[" + level.toString() + "] " + string);
}
private static void append(final String string) {
entries.add("[" + new Date().toString() + "]" + string);
}
public enum LogLevel {
GENERAL("General"),
WARNING("Warning"),
DANGER("Danger");
private final String name;
LogLevel(final String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
}

View File

@ -24,6 +24,30 @@ public class MathMan {
return i * 2;
}
public static boolean isInteger(String str) {
if (str == null) {
return false;
}
int length = str.length();
if (length == 0) {
return false;
}
int i = 0;
if (str.charAt(0) == '-') {
if (length == 1) {
return false;
}
i = 1;
}
for (; i < length; i++) {
char c = str.charAt(i);
if (c <= '/' || c >= ':') {
return false;
}
}
return true;
}
public static double getSD(double[] array, double av) {
double sd = 0;
for (int i=0; i<array.length;i++)

View File

@ -53,7 +53,7 @@ public class SetBlockQueue {
runnables = new HashSet<>();
}
if (!running) {
TaskManager.index.increment();
TaskManager.index.incrementAndGet();
final int current = TaskManager.index.intValue();
int task = TaskManager.runTaskRepeat(new Runnable() {
@Override

View File

@ -23,8 +23,6 @@ package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.commons.lang.StringUtils;
/**
* String comparison library
*
@ -76,7 +74,7 @@ public class StringComparison<T> {
* @return match
*/
public static int compare(final String s1, final String s2) {
int distance = StringUtils.getLevenshteinDistance(s1, s2);
int distance = StringMan.getLevenshteinDistance(s1, s2);
if (s2.contains(s1)) {
distance -= (Math.min(s1.length(), s2.length()));
}

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.util;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
@ -41,8 +42,107 @@ public class StringMan {
return sb.toString();
}
public static boolean isAlphanumeric(String str) {
for (int i=0; i<str.length(); i++) {
char c = str.charAt(i);
if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a) {
return false;
}
}
return true;
}
public static boolean isAlpha(String str) {
for (int i=0; i<str.length(); i++) {
char c = str.charAt(i);
if ((c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a) {
return false;
}
}
return true;
}
public static String join(Collection<?> collection, String delimiter) {
return join(collection.toArray(), delimiter);
}
public static String join(Collection<?> collection, char delimiter) {
return join(collection.toArray(), delimiter + "");
}
public static boolean isAsciiPrintable(char c) {
return (c >= ' ') && (c < '');
}
public static boolean isAsciiPrintable(String s) {
for (char c: s.toCharArray()) {
if (!isAsciiPrintable(c)) {
return false;
}
}
return true;
}
public static int getLevenshteinDistance(String s, String t) {
int n = s.length();
int m = t.length();
if (n == 0) {
return m;
} else if (m == 0) {
return n;
}
if (n > m) {
String tmp = s;
s = t;
t = tmp;
n = m;
m = t.length();
}
int p[] = new int[n+1];
int d[] = new int[n+1];
int _d[];
int i;
int j;
char t_j;
int cost;
for (i = 0; i<=n; i++) {
p[i] = i;
}
for (j = 1; j<=m; j++) {
t_j = t.charAt(j-1);
d[0] = j;
for (i=1; i<=n; i++) {
cost = s.charAt(i-1)==t_j ? 0 : 1;
d[i] = Math.min(Math.min(d[i-1]+1, p[i]+1), p[i-1]+cost);
}
_d = p;
p = d;
d = _d;
}
return p[n];
}
public static String join(Object[] array, String delimiter) {
StringBuilder result = new StringBuilder();
for (int i = 0, j = array.length; i < j; i++) {
if (i > 0) {
result.append(delimiter);
}
result.append(array[i]);
}
return result.toString();
}
public static boolean isEqual(String a, String b ) {
return (a == b || (a.length() == b.length() && a.hashCode() == b.hashCode() && a.equals(b)));
}
public static String repeat(String s, int n) {
final StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++) {
sb.append(s);
}
return sb.toString();
}
}

View File

@ -2,15 +2,14 @@ package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.commons.lang.mutable.MutableInt;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.plot.PS;
public abstract class TaskManager {
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
public static MutableInt index = new MutableInt(0);
public static AtomicInteger index = new AtomicInteger(0);
public static HashMap<Integer, Integer> tasks = new HashMap<>();
public static int runTaskRepeat(final Runnable r, final int interval) {

View File

@ -93,8 +93,8 @@ public class ChunkListener implements Listener {
}
public void cleanChunk(final Chunk chunk) {
TaskManager.index.increment();
final Integer currentIndex = TaskManager.index.toInteger();
TaskManager.index.incrementAndGet();
final Integer currentIndex = TaskManager.index.get();
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {

View File

@ -10,7 +10,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@ -112,6 +111,7 @@ import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.RegExUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.UUIDHandler;
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
@ -304,7 +304,7 @@ public class PlayerEvents extends com.plotsquared.bukkit.listeners.PlotListener
if (split[0].equals("plotme") || split[0].equals("ap")) {
final Player player = event.getPlayer();
if (Settings.USE_PLOTME_ALIAS) {
player.performCommand("plots " + StringUtils.join(Arrays.copyOfRange(split, 1, split.length), " "));
player.performCommand("plots " + StringMan.join(Arrays.copyOfRange(split, 1, split.length), " "));
} else {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
}

View File

@ -8,7 +8,7 @@ import java.util.Map.Entry;
import com.intellectualcrafters.plot.object.schematic.ItemType;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import org.apache.commons.lang.StringUtils;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.InventoryHolder;
@ -19,7 +19,9 @@ import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.jnbt.ListTag;
import com.intellectualcrafters.jnbt.ShortTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import com.intellectualcrafters.plot.util.StringMan;
public class StateWrapper {
@ -48,7 +50,7 @@ public class StateWrapper {
CompoundTag itemComp = (CompoundTag) itemTag;
short id = itemComp.getShort("id");
String idStr = itemComp.getString("id");
if (!StringUtils.isNumeric(idStr) && idStr != null) {
if (idStr != null && !MathMan.isInteger(idStr)) {
idStr = idStr.split(":")[1].toLowerCase();
id = (short) ItemType.getId(idStr);
}

View File

@ -20,7 +20,6 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.DyeColor;
@ -64,6 +63,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class BukkitChunkManager extends ChunkManager {
@Override
@ -193,7 +193,7 @@ public class BukkitChunkManager extends ChunkManager {
*/
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
TaskManager.index.increment();
TaskManager.index.incrementAndGet();
final int relX = newPos.getX() - pos1.getX();
final int relZ = newPos.getZ() - pos1.getZ();
@ -224,7 +224,7 @@ public class BukkitChunkManager extends ChunkManager {
}
}
final Plugin plugin = BukkitMain.THIS;
final Integer currentIndex = TaskManager.index.toInteger();
final Integer currentIndex = TaskManager.index.get();
final int loadTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
@ -236,7 +236,7 @@ public class BukkitChunkManager extends ChunkManager {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
TaskManager.index.increment();
TaskManager.index.incrementAndGet();
// Copy entities
initMaps();
for (int x = c1x; x <= c2x; x++) {
@ -247,8 +247,8 @@ public class BukkitChunkManager extends ChunkManager {
}
}
// Copy blocks
final MutableInt mx = new MutableInt(sx);
final Integer currentIndex = TaskManager.index.toInteger();
final AtomicInteger mx = new AtomicInteger(sx);
final Integer currentIndex = TaskManager.index.get();
final int maxY = oldWorld.getMaxHeight();
final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
@ -265,7 +265,7 @@ public class BukkitChunkManager extends ChunkManager {
BukkitSetBlockManager.setBlockManager.set(newWorld, xv + relX, y, z + relZ, id, data);
}
}
mx.increment();
mx.incrementAndGet();
if (xv == ex) { // done!
for (int x = c1x; x <= c2x; x++) {
for (int z = c1z; z <= c2z; z++) {

View File

@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@ -35,6 +34,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.StringComparison;
public class BukkitUtil extends BlockManager {
@ -380,7 +380,7 @@ public class BukkitUtil extends BlockManager {
else {
data = 0;
}
if (StringUtils.isNumeric(split[0])) {
if (MathMan.isInteger(split[0])) {
id = Short.parseShort(split[0]);
match = 0;
}

View File

@ -0,0 +1,59 @@
package com.plotsquared.sponge;
import org.spongepowered.api.world.gen.WorldGenerator;
import com.intellectualcrafters.plot.generator.PlotGenerator2;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
public class SpongeGeneratorWrapper extends PlotGenerator2<WorldGenerator>{
public SpongeGeneratorWrapper(String world, WorldGenerator generator) {
super(world, generator);
// TODO Auto-generated constructor stub
}
@Override
public void initialize(PlotWorld plotworld) {
// TODO Auto-generated method stub
}
@Override
public void augment(PlotCluster cluster, PlotWorld plotworld) {
// TODO Auto-generated method stub
}
@Override
public void setGenerator(String generator) {
// TODO Auto-generated method stub
}
@Override
public PlotWorld getNewPlotWorld(String world) {
// TODO Auto-generated method stub
return null;
}
@Override
public PlotManager getPlotManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isFull() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.util.Collection;
import java.util.UUID;
import org.bukkit.generator.ChunkGenerator;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Server;
@ -14,12 +13,14 @@ import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.entity.player.PlayerChatEvent;
import org.spongepowered.api.event.state.PreInitializationEvent;
import org.spongepowered.api.event.state.ServerAboutToStartEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.world.DimensionTypes;
import org.spongepowered.api.world.GeneratorTypes;
import org.spongepowered.api.world.World;
import com.google.inject.Inject;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.IPlotMain;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
@ -42,7 +43,7 @@ import com.plotsquared.bukkit.util.UUIDHandler;
* Created by robin on 01/11/2014
*/
//@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0")
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.0.0")
public class SpongeMain implements IPlotMain, PluginContainer {
public static SpongeMain THIS;
@ -84,8 +85,16 @@ public class SpongeMain implements IPlotMain, PluginContainer {
///////////////////// ON ENABLE /////////////////////
@Subscribe
public void onInit(PreInitializationEvent event) {
log("PRE INIT");
}
@Subscribe
public void onServerAboutToStart(ServerAboutToStartEvent event) {
log("INIT");
THIS = this;
PS.instance = new PS(this);
// Setup metrics
if (Settings.METRICS) {
try {
final SpongeMetrics metrics = new SpongeMetrics(game, this);
@ -97,23 +106,26 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} else {
log("&dUsing metrics will allow us to improve the plugin, please consider it :)");
}
// Set the generators for each world...
server = game.getServer();
Collection<World> worlds = server.getWorlds();
if (worlds.size() > 0) {
log("INJECTING WORLDS!!!!!!!");
UUIDHandler.startCaching();
for (World world : server.getWorlds()) {
log("INJECTING WORLD: " + world.getName());
world.setWorldGenerator(new SpongePlotGenerator(world.getName()));
}
}
}
@Subscribe
public void onServerAboutToStart(ServerAboutToStartEvent event) {
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
for (String world : worldSection.getKeys(false)) {
this.modify = new WorldModify(this);
Game game = event.getGame();
game.getRegistry().registerWorldGeneratorModifier(modify);
game.getRegistry().getWorldBuilder()
.name("test")
.name(world)
.enabled(true)
.loadsOnStartup(true)
.keepsSpawnLoaded(true)
@ -123,6 +135,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
.generatorModifiers(modify)
.build();
}
}
public Logger getLogger() {
return logger;
@ -288,7 +301,7 @@ public class SpongeMain implements IPlotMain, PluginContainer {
}
@Override
public ChunkGenerator getGenerator(String world, String name) {
public SpongeGeneratorWrapper getGenerator(String world, String name) {
// TODO Auto-generated method stub
return null;
}