From 393a5bffd5635080242fd2f60ff04985534438e5 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 27 Jul 2015 04:38:08 +1000 Subject: [PATCH] StringMan instead of StringUtils --- .../com/intellectualcrafters/plot/PS.java | 9 +- .../plot/config/ConfigurationNode.java | 5 +- .../plot/database/SQLManager.java | 6 +- .../plot/database/StmtMod.java | 8 +- .../plot/flag/AbstractFlag.java | 4 +- .../intellectualcrafters/plot/flag/Flag.java | 4 +- .../plot/flag/FlagValue.java | 11 +- .../plot/generator/BukkitHybridUtils.java | 23 ++-- .../plot/generator/ClassicPlotWorld.java | 7 +- .../plot/object/PlotAnalysis.java | 7 +- .../plot/object/PlotWorld.java | 5 +- .../plot/util/Logger.java | 89 --------------- .../plot/util/MathMan.java | 24 +++++ .../plot/util/SetBlockQueue.java | 2 +- .../plot/util/StringComparison.java | 4 +- .../plot/util/StringMan.java | 102 +++++++++++++++++- .../plot/util/TaskManager.java | 5 +- .../bukkit/listeners/ChunkListener.java | 4 +- .../bukkit/listeners/PlayerEvents.java | 4 +- .../bukkit/object/schematic/StateWrapper.java | 6 +- .../util/bukkit/BukkitChunkManager.java | 14 +-- .../bukkit/util/bukkit/BukkitUtil.java | 4 +- .../sponge/SpongeGeneratorWrapper.java | 59 ++++++++++ .../com/plotsquared/sponge/SpongeMain.java | 53 +++++---- 24 files changed, 277 insertions(+), 182 deletions(-) delete mode 100644 src/main/java/com/intellectualcrafters/plot/util/Logger.java create mode 100644 src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 782d0dcc4..2ec317410 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -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(); } } diff --git a/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java b/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java index 8f6a09b17..c6bb2259e 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java +++ b/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java @@ -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; } diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index ce5001610..31e3abd87 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -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 newflags) { - final String flag_string = StringUtils.join(newflags, ","); + final String flag_string = StringMan.join(newflags, ","); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { diff --git a/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java b/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java index 09e7284c8..2aaa21c6c 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java +++ b/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java @@ -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 { public abstract String getCreateMySQL(int size); @@ -11,15 +11,15 @@ public abstract class StmtMod { 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 + " "); } diff --git a/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java b/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java index 1fdbb1d0b..c3d0ce9ef 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java @@ -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) { diff --git a/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index b8504cbce..7054d0e90 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -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) { diff --git a/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java b/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java index e52682ab5..f4b09ae9a 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java @@ -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 { @SuppressWarnings("unchecked") @Override public String toString(final Object t) { - return StringUtils.join((HashSet) t, ","); + return StringMan.join((HashSet) t, ","); } @SuppressWarnings("unchecked") @@ -357,7 +356,7 @@ public abstract class FlagValue { @SuppressWarnings("unchecked") @Override public String toString(final Object t) { - return StringUtils.join((List) t, ","); + return StringMan.join((List) t, ","); } @SuppressWarnings("unchecked") @@ -405,7 +404,7 @@ public abstract class FlagValue { @Override public String toString(final Object t) { - return StringUtils.join((List) t, ","); + return StringMan.join((List) t, ","); } @Override @@ -445,7 +444,7 @@ public abstract class FlagValue { @SuppressWarnings("unchecked") @Override public String toString(final Object t) { - return StringUtils.join((List) t, ","); + return StringMan.join((List) t, ","); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java b/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java index fe50ee55f..5a802389d 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -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 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(); 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) + "%"); } diff --git a/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java b/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java index 072695eaa..eb2cf1002 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java @@ -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")); diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java index 3b4b32d2c..b37059615 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -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); diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index e2ca93094..12c1c65f2 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -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"); diff --git a/src/main/java/com/intellectualcrafters/plot/util/Logger.java b/src/main/java/com/intellectualcrafters/plot/util/Logger.java deleted file mode 100644 index dbea9f79c..000000000 --- a/src/main/java/com/intellectualcrafters/plot/util/Logger.java +++ /dev/null @@ -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 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; - } - } -} diff --git a/src/main/java/com/intellectualcrafters/plot/util/MathMan.java b/src/main/java/com/intellectualcrafters/plot/util/MathMan.java index aa72e9c3b..ec5f86dca 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MathMan.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MathMan.java @@ -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(); } if (!running) { - TaskManager.index.increment(); + TaskManager.index.incrementAndGet(); final int current = TaskManager.index.intValue(); int task = TaskManager.runTaskRepeat(new Runnable() { @Override diff --git a/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java b/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java index 8f6f91efd..1b55d6e0f 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java +++ b/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java @@ -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 { * @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())); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java index 435efa540..4cd6b9409 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java +++ b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java @@ -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= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a) { + return false; + } + } + return true; + } + + public static boolean isAlpha(String str) { + for (int i=0; i 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(); + } } diff --git a/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index f4274bc95..ec83706bd 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -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 TELEPORT_QUEUE = new HashSet<>(); - public static MutableInt index = new MutableInt(0); + public static AtomicInteger index = new AtomicInteger(0); public static HashMap tasks = new HashMap<>(); public static int runTaskRepeat(final Runnable r, final int interval) { diff --git a/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java b/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java index 82204868d..958f22a4a 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/ChunkListener.java @@ -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() { diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index bc9b60c6e..376f90c65 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -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); } diff --git a/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java b/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java index 0e94ff941..bb96e6c41 100644 --- a/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java +++ b/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java @@ -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); } diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java index e55185f4b..fb650667a 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java @@ -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++) { diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java index 3ba079382..43879bb94 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitUtil.java @@ -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; } diff --git a/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java b/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java new file mode 100644 index 000000000..f7cd68f96 --- /dev/null +++ b/src/main/java/com/plotsquared/sponge/SpongeGeneratorWrapper.java @@ -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{ + + 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; + } + +} diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index 20ee7b842..092422ff4 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -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,31 +106,35 @@ 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 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) { - this.modify = new WorldModify(this); - Game game = event.getGame(); - game.getRegistry().registerWorldGeneratorModifier(modify); - game.getRegistry().getWorldBuilder() - .name("test") - .enabled(true) - .loadsOnStartup(true) - .keepsSpawnLoaded(true) - .dimensionType(DimensionTypes.OVERWORLD) - .generator(GeneratorTypes.DEBUG) - .gameMode(GameModes.CREATIVE) - .generatorModifiers(modify) - .build(); + + 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(world) + .enabled(true) + .loadsOnStartup(true) + .keepsSpawnLoaded(true) + .dimensionType(DimensionTypes.OVERWORLD) + .generator(GeneratorTypes.DEBUG) + .gameMode(GameModes.CREATIVE) + .generatorModifiers(modify) + .build(); + } } public Logger getLogger() { @@ -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; }