diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 4cf51a847..68d0054ff 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -92,7 +92,7 @@ public class Database extends SubCommand { } Connection n; try { - n = new MySQL(PlotSquared.THIS, host, port, database, username, password).openConnection(); + n = new MySQL(PlotSquared.getInstance(), host, port, database, username, password).openConnection(); // Connection if (n.isClosed()) { return sendMessage(plr, "Failed to open connection"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index c4f3418c5..990f579fb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -20,33 +20,21 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.mutable.MutableInt; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.listeners.PlotListener; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotInventory; -import com.intellectualcrafters.plot.object.PlotItemStack; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.mutable.MutableInt; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map.Entry; +import java.util.UUID; public class Rate extends SubCommand { /* @@ -61,7 +49,7 @@ public class Rate extends SubCommand { public boolean execute(final PlotPlayer player, final String... args) { if (args.length == 1) { if (args[0].equalsIgnoreCase("next")) { - ArrayList plots = new ArrayList<>(PlotSquared.getPlots()); + ArrayList plots = new ArrayList<>(PlotSquared.getInstance().getPlots()); Collections.sort(plots, new Comparator() { @Override public int compare(Plot p1, Plot p2) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index dfdd69b16..8587ca70c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -134,7 +134,7 @@ public class SchematicCmd extends SubCommand { SchematicHandler.manager.pasteStates(schematic, plot, 0, 0); sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); SchematicCmd.this.running = false; - PlotSquared.TASK.cancelTask(SchematicCmd.this.task); + PlotSquared.getInstance().TASK.cancelTask(SchematicCmd.this.task); return; } final int end = Math.min(start + 5000, blen); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java index 333847663..2c0714f78 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java @@ -34,7 +34,7 @@ public class WE_Anywhere extends SubCommand { @Override public boolean execute(final PlotPlayer plr, final String... args) { - if (PlotSquared.worldEdit == null) { + if (PlotSquared.getInstance().worldEdit == null) { MainUtil.sendMessage(plr, "&cWorldEdit is not enabled on this server"); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index f26f0b0a2..71c30115f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -20,17 +20,17 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.TaskManager; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; -import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.TaskManager; - public class plugin extends SubCommand { public static String downloads, version; @@ -93,7 +93,7 @@ public class plugin extends SubCommand { public void run() { final ArrayList strings = new ArrayList() { { - add(String.format("&c>> &6PlotSquared (Version: %s)", PlotSquared.IMP.getVersion())); + add(String.format("&c>> &6PlotSquared (Version: %s)", PlotSquared.getInstance().IMP.getVersion())); add(String.format("&c>> &6Made by Citymonstret and Empire92")); add(String.format("&c>> &6Download at &lhttp://www.spigotmc.org/resources/1177")); add(String.format("&c>> &cNewest Version (Spigot): %s", version)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java index 468886f41..c2ae36128 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java @@ -1,26 +1,5 @@ package com.intellectualcrafters.plot.database.plotme; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.SQLite; @@ -30,10 +9,29 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.File; +import java.sql.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.UUID; public class ClassicPlotMeConnector extends APlotMeConnector { private String plugin; + + public static String getWorld(final String world) { + for (final World newworld : Bukkit.getWorlds()) { + if (newworld.getName().equalsIgnoreCase(world)) { + return newworld.getName(); + } + } + return world; + } @Override public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) { @@ -46,13 +44,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector { return DriverManager.getConnection(con, user, password); // return new MySQL(plotsquared, hostname, port, database, username, password) } else { - return new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection(); + return new SQLite(PlotSquared.getInstance(), dataFolder + File.separator + "plots.db").openConnection(); } } catch (SQLException | ClassNotFoundException e) {} return null; } - + public void setMerged(HashMap> merges, String world, PlotId id, int direction) { HashMap plots = merges.get(world); PlotId id2; @@ -96,15 +94,6 @@ public class ClassicPlotMeConnector extends APlotMeConnector { plots.put(id, merge1); plots.put(id2, merge1); } - - public static String getWorld(final String world) { - for (final World newworld : Bukkit.getWorlds()) { - if (newworld.getName().equalsIgnoreCase(world)) { - return newworld.getName(); - } - } - return world; - } @Override public HashMap> getPlotMePlots(Connection connection) throws SQLException { @@ -123,8 +112,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector { final String name = r.getString("owner"); final String world = LikePlotMeConverter.getWorld(r.getString("world")); if (!plots.containsKey(world)) { - int plot = PlotSquared.config.getInt("worlds." + world + ".plot.size"); - int path = PlotSquared.config.getInt("worlds." + world + ".road.width"); + int plot = PlotSquared.getInstance().config.getInt("worlds." + world + ".plot.size"); + int path = PlotSquared.getInstance().config.getInt("worlds." + world + ".road.width"); if (plot == 0 && path == 0) { } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java index 9c1bee8be..c8aa956ae 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java @@ -20,6 +20,14 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.generator; +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.commands.Template; +import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetBlockQueue; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -27,26 +35,12 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.commands.Template; -import com.intellectualcrafters.plot.object.FileBytes; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotLoc; -import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.SetBlockQueue; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; - public class HybridPlotManager extends ClassicPlotManager { @Override public void exportTemplate(final PlotWorld plotworld) throws IOException { final HashSet files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld)))); - final String psRoot = PlotSquared.IMP.getDirectory() + File.separator; + final String psRoot = PlotSquared.getInstance().IMP.getDirectory() + File.separator; final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator; final String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator; try { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index eb59a889c..26049ffed 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -122,7 +122,7 @@ public abstract class SquarePlotManager extends GridPlotManager { // This means you are in the intersection final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, 0, z + dpw.ROAD_WIDTH); final PlotId id = MainUtil.getPlotAbs(loc); - final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); + final Plot plot = PlotSquared.getInstance().getPlots(plotworld.worldname).get(id); if (plot == null) { return null; } @@ -135,7 +135,7 @@ public abstract class SquarePlotManager extends GridPlotManager { // You are on a road running West to East (yeah, I named the var poorly) final Location loc = new Location(plotworld.worldname, x, 0, z + dpw.ROAD_WIDTH); final PlotId id = MainUtil.getPlotAbs(loc); - final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); + final Plot plot = PlotSquared.getInstance().getPlots(plotworld.worldname).get(id); if (plot == null) { return null; } @@ -148,7 +148,7 @@ public abstract class SquarePlotManager extends GridPlotManager { // This is the road separating an Eastern and Western plot final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH, 0, z); final PlotId id = MainUtil.getPlotAbs(loc); - final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); + final Plot plot = PlotSquared.getInstance().getPlots(plotworld.worldname).get(id); if (plot == null) { return null; } @@ -158,7 +158,7 @@ public abstract class SquarePlotManager extends GridPlotManager { return null; } final PlotId id = new PlotId(dx, dz); - final Plot plot = PlotSquared.getPlots(plotworld.worldname).get(id); + final Plot plot = PlotSquared.getInstance().getPlots(plotworld.worldname).get(id); if (plot == null) { return id; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java index d5659c4c5..fce9b7389 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java @@ -1,8 +1,5 @@ package com.intellectualcrafters.plot.listeners.worldedit; -import java.util.HashSet; -import java.util.UUID; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; @@ -11,6 +8,9 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.MainUtil; +import java.util.HashSet; +import java.util.UUID; + public class WEManager { public static HashSet bypass = new HashSet<>(); @@ -26,7 +26,7 @@ public class WEManager { public static HashSet getMask(PlotPlayer player) { HashSet regions = new HashSet<>(); UUID uuid = player.getUUID(); - for (Plot plot : PlotSquared.getPlots(player.getLocation().getWorld()).values()) { + for (Plot plot : PlotSquared.getInstance().getPlots(player.getLocation().getWorld()).values()) { if (!plot.settings.getMerged(0) && !plot.settings.getMerged(3)) { if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (plot.isOwner(uuid) || plot.trusted.contains(uuid))) { Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index b81464456..1eea292ea 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -20,14 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.object; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.configuration.ConfigurationSection; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.ConfigurationNode; @@ -35,6 +27,13 @@ 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 org.apache.commons.lang.StringUtils; +import org.bukkit.configuration.ConfigurationSection; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; /** * @author Jesse Boyd @@ -111,7 +110,7 @@ public abstract class PlotWorld { return false; } PlotWorld plotworld = (PlotWorld) obj; - ConfigurationSection section = PlotSquared.config.getConfigurationSection("worlds"); + ConfigurationSection section = PlotSquared.getInstance().config.getConfigurationSection("worlds"); for (ConfigurationNode setting : plotworld.getSettingNodes()) { Object constant = section.get(plotworld.worldname + "." + setting.getConstant()); if (constant == null) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index c9abf104a..65a36f655 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -1,15 +1,11 @@ package com.intellectualcrafters.plot.util; -import java.util.ArrayList; -import java.util.UUID; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotCluster; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.*; + +import java.util.ArrayList; +import java.util.UUID; public abstract class EventUtil { @@ -21,7 +17,7 @@ public abstract class EventUtil { SetupUtils.setupMap.remove(name); } CmdConfirm.removePending(name); - PlotSquared.IMP.unregister(player); + PlotSquared.getInstance().IMP.unregister(player); } public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 97f76b364..f85a33f44 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -1,30 +1,6 @@ package com.intellectualcrafters.plot.util; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -import org.bukkit.Bukkit; - -import com.intellectualcrafters.jnbt.ByteArrayTag; -import com.intellectualcrafters.jnbt.CompoundTag; -import com.intellectualcrafters.jnbt.IntTag; -import com.intellectualcrafters.jnbt.ListTag; -import com.intellectualcrafters.jnbt.NBTInputStream; -import com.intellectualcrafters.jnbt.NBTOutputStream; -import com.intellectualcrafters.jnbt.ShortTag; -import com.intellectualcrafters.jnbt.Tag; +import com.intellectualcrafters.jnbt.*; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; @@ -34,6 +10,12 @@ import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.StateWrapper; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; +import org.bukkit.Bukkit; + +import java.io.*; +import java.util.*; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; public abstract class SchematicHandler { public static SchematicHandler manager = new BukkitSchematicHandler(); @@ -82,7 +64,7 @@ public abstract class SchematicHandler { else { directory = outputDir.getPath(); } - if (PlotSquared.worldEdit != null) { + if (PlotSquared.getInstance().worldEdit != null) { new WorldEditSchematic().saveSchematic(directory + File.separator + name + ".schematic", plot.world, plot.id); } else { @@ -254,14 +236,14 @@ public abstract class SchematicHandler { */ public Schematic getSchematic(final String name) { { - final File parent = new File(PlotSquared.IMP.getDirectory() + File.separator + "schematics"); + final File parent = new File(PlotSquared.getInstance().IMP.getDirectory() + File.separator + "schematics"); if (!parent.exists()) { if (!parent.mkdir()) { throw new RuntimeException("Could not create schematic parent directory"); } } } - final File file = new File(PlotSquared.IMP.getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic"); + final File file = new File(PlotSquared.getInstance().IMP.getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic"); return getSchematic(file); } @@ -326,7 +308,7 @@ public abstract class SchematicHandler { * @return tag */ public CompoundTag getCompoundTag(final String world, final PlotId id) { - if (!PlotSquared.getPlots(world).containsKey(id)) { + if (!PlotSquared.getInstance().getPlots(world).containsKey(id)) { return null; } final Location pos1 = MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1); @@ -390,6 +372,12 @@ public abstract class SchematicHandler { private final File file; private HashSet items; + public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) { + this.blockCollection = blockCollection; + this.schematicDimension = schematicDimension; + this.file = file; + } + public void addItem(PlotItem item) { if (this.items == null) { this.items = new HashSet<>(); @@ -400,12 +388,6 @@ public abstract class SchematicHandler { public HashSet getItems() { return this.items; } - - public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) { - this.blockCollection = blockCollection; - this.schematicDimension = schematicDimension; - this.file = file; - } public File getFile() { return this.file; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java index 14f111665..745a6592e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java @@ -1,14 +1,14 @@ package com.intellectualcrafters.plot.util; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map.Entry; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.generator.AugmentedPopulator; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotBlock; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; + public class SetBlockQueue { private volatile static HashMap blocks; @@ -17,6 +17,9 @@ public class SetBlockQueue { private volatile static boolean locked = false; private volatile static HashSet runnables; private volatile static boolean slow = false; + private static long last; + private static int lastInt = 0; + private static PlotBlock lastBlock = new PlotBlock((short) 0, (byte) 0); public synchronized static void allocate(int t) { allocate = t; @@ -40,9 +43,7 @@ public class SetBlockQueue { runnables.add(whenDone); } } - - private static long last; - + public synchronized static void init() { if (blocks == null) { if (AugmentedPopulator.x_loc == null) { @@ -61,7 +62,7 @@ public class SetBlockQueue { return; } if (blocks.size() == 0) { - PlotSquared.TASK.cancelTask(TaskManager.tasks.get(current)); + PlotSquared.getInstance().TASK.cancelTask(TaskManager.tasks.get(current)); for (Runnable runnable : runnables) { TaskManager.runTask(runnable); } @@ -141,7 +142,7 @@ public class SetBlockQueue { blocks.put(wrap, result); locked = false; } - + public static void setBlock(final String world, int x, final int y, int z, final PlotBlock block) { locked = true; if (!running) { @@ -151,15 +152,15 @@ public class SetBlockQueue { int Z = z >> 4; x -= X << 4; z -= Z << 4; - + ChunkWrapper wrap = new ChunkWrapper(world, X, Z); - PlotBlock[][] result; + PlotBlock[][] result; result = blocks.get(wrap); if (!blocks.containsKey(wrap)) { result = new PlotBlock[16][]; blocks.put(wrap, result); } - + if (result[y >> 4] == null) { result[y >> 4] = new PlotBlock[4096]; } @@ -167,9 +168,6 @@ public class SetBlockQueue { locked = false; } - private static int lastInt = 0; - private static PlotBlock lastBlock = new PlotBlock((short) 0, (byte) 0); - public static void setData(final String world, int x, final int y, int z, final byte data) { locked = true; if (!running) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index ec1a6898c..b40b055c7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -1,18 +1,53 @@ package com.intellectualcrafters.plot.util; +import com.intellectualcrafters.plot.PlotSquared; +import org.apache.commons.lang.mutable.MutableInt; + import java.util.HashMap; import java.util.HashSet; -import org.apache.commons.lang.mutable.MutableInt; - -import com.intellectualcrafters.plot.PlotSquared; - public abstract class TaskManager { public static HashSet TELEPORT_QUEUE = new HashSet<>(); public static MutableInt index = new MutableInt(0); public static HashMap tasks = new HashMap<>(); + public static int runTaskRepeat(final Runnable r, final int interval) { + if (r != null) { + return PlotSquared.getInstance().TASK.taskRepeat(r, interval); + } + return -1; + } + + public static void runTaskAsync(final Runnable r) { + if (r != null) { + PlotSquared.getInstance().TASK.taskAsync(r); + } + } + + public static void runTask(final Runnable r) { + if (r != null) { + PlotSquared.getInstance().TASK.task(r); + } + } + + /** + * Run task later (delay in ticks) + * @param r + * @param delay + */ + public static void runTaskLater(final Runnable r, final int delay) { + if (r != null) { + PlotSquared.getInstance().TASK.taskLater(r, delay); + } + } + + public static void runTaskLaterAsync(final Runnable r, final int delay) { + if (r != null) { + PlotSquared.getInstance().TASK.taskLaterAsync(r, delay); + } + } + public abstract int taskRepeat(final Runnable r, int interval); public abstract void taskAsync(final Runnable r); @@ -24,40 +59,4 @@ public abstract class TaskManager { public abstract void taskLaterAsync(final Runnable r, int delay); public abstract void cancelTask(int task); - - public static int runTaskRepeat(final Runnable r, final int interval) { - if (r != null) { - return PlotSquared.TASK.taskRepeat(r, interval); - } - return -1; - } - - public static void runTaskAsync(final Runnable r) { - if (r != null) { - PlotSquared.TASK.taskAsync(r); - } - } - - public static void runTask(final Runnable r) { - if (r != null) { - PlotSquared.TASK.task(r); - } - } - - /** - * Run task later (delay in ticks) - * @param r - * @param delay - */ - public static void runTaskLater(final Runnable r, final int delay) { - if (r != null) { - PlotSquared.TASK.taskLater(r, delay); - } - } - - public static void runTaskLaterAsync(final Runnable r, final int delay) { - if (r != null) { - PlotSquared.TASK.taskLaterAsync(r, delay); - } - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java index 622a21b32..6e5d14543 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java @@ -1,9 +1,5 @@ package com.intellectualcrafters.plot.util; -import java.io.File; - -import org.bukkit.Bukkit; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotId; @@ -11,6 +7,9 @@ import com.sk89q.worldedit.CuboidClipboard; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitWorld; +import org.bukkit.Bukkit; + +import java.io.File; public class WorldEditSchematic { public void saveSchematic(String file, final String world, final PlotId id) { @@ -21,7 +20,7 @@ public class WorldEditSchematic { CuboidClipboard clipboard = new CuboidClipboard(size, origin); Vector pos1 = new Vector(bot.getX(), bot.getY(), bot.getZ()); Vector pos2 = new Vector(top.getX(), top.getY(), top.getZ()); - EditSession session = PlotSquared.worldEdit.getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorld(world)), 999999999); + EditSession session = PlotSquared.getInstance().worldEdit.getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorld(world)), 999999999); clipboard.copy(session); try { clipboard.saveSchematic(new File(file)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java index 6bcff08fc..9da8fa77a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java @@ -1,22 +1,20 @@ package com.intellectualcrafters.plot.util.bukkit; -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.World; - -import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; import com.intellectualcrafters.plot.util.ReflectionUtils.RefField; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.World; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; /** * An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS) @@ -25,13 +23,13 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; */ public class SendChunk { - private static boolean v1_7_10 = PlotSquared.IMP.checkVersion(1, 7, 10) && !PlotSquared.IMP.checkVersion(1, 8, 0); // Ref Class private static final RefClass classWorld = getRefClass("{nms}.World"); private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); private static final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair"); private static final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); private static final RefClass classChunk = getRefClass("{nms}.Chunk"); + private static boolean v1_7_10 = PlotSquared.getInstance().IMP.checkVersion(1, 7, 10) && !PlotSquared.getInstance().IMP.checkVersion(1, 8, 0); // Ref Method private static RefMethod methodGetHandle; // Ref Field diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java index 7561edf3f..f59405134 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java @@ -1,14 +1,13 @@ package com.intellectualsites.translation.bukkit; -import java.io.File; - -import org.bukkit.Material; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualsites.translation.TranslationAsset; import com.intellectualsites.translation.TranslationLanguage; import com.intellectualsites.translation.TranslationManager; import com.intellectualsites.translation.TranslationObject; +import org.bukkit.Material; + +import java.io.File; /** * @author Citymonstret @@ -34,16 +33,7 @@ public class BukkitTranslation { * @return parent folder */ public static File getParent() { - return new File(PlotSquared.IMP.getDirectory() + File.separator + "translations"); - } - - /** - * The default translation language - * - * @return default translation language - */ - public TranslationLanguage getDefaultLanguage() { - return TranslationLanguage.englishAmerican; + return new File(PlotSquared.getInstance().IMP.getDirectory() + File.separator + "translations"); } /** @@ -54,4 +44,13 @@ public class BukkitTranslation { manager.addTranslationObject(new TranslationObject(material.name(), material.name().replace("_", " ").toLowerCase(), "Material." + material.toString(), "")); } } + + /** + * The default translation language + * + * @return default translation language + */ + public TranslationLanguage getDefaultLanguage() { + return TranslationLanguage.englishAmerican; + } }