A whole loads of rewritez

This commit is contained in:
sauilitired 2015-07-03 11:30:26 +02:00
parent 8e499dffb2
commit ebe80350dc
64 changed files with 1536 additions and 1806 deletions

View File

@ -1,12 +1,28 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File; import com.intellectualcrafters.plot.commands.*;
import java.util.Arrays; import com.intellectualcrafters.plot.config.C;
import java.util.HashMap; import com.intellectualcrafters.plot.config.Settings;
import java.util.List; import com.intellectualcrafters.plot.database.plotme.ClassicPlotMeConnector;
import java.util.UUID; import com.intellectualcrafters.plot.database.plotme.LikePlotMeConverter;
import java.util.Map.Entry; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.listeners.*;
import com.intellectualcrafters.plot.listeners.worldedit.WEListener;
import com.intellectualcrafters.plot.listeners.worldedit.WESubscriber;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.bukkit.*;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -19,130 +35,14 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.commands.Add; import java.io.File;
import com.intellectualcrafters.plot.commands.Auto; import java.util.Arrays;
import com.intellectualcrafters.plot.commands.BukkitCommand; import java.util.List;
import com.intellectualcrafters.plot.commands.Chat; import java.util.UUID;
import com.intellectualcrafters.plot.commands.Claim;
import com.intellectualcrafters.plot.commands.Clear;
import com.intellectualcrafters.plot.commands.Cluster;
import com.intellectualcrafters.plot.commands.Comment;
import com.intellectualcrafters.plot.commands.Condense;
import com.intellectualcrafters.plot.commands.Confirm;
import com.intellectualcrafters.plot.commands.Copy;
import com.intellectualcrafters.plot.commands.CreateRoadSchematic;
import com.intellectualcrafters.plot.commands.Database;
import com.intellectualcrafters.plot.commands.Debug;
import com.intellectualcrafters.plot.commands.DebugClaimTest;
import com.intellectualcrafters.plot.commands.DebugClear;
import com.intellectualcrafters.plot.commands.DebugExec;
import com.intellectualcrafters.plot.commands.DebugFill;
import com.intellectualcrafters.plot.commands.DebugFixFlags;
import com.intellectualcrafters.plot.commands.DebugLoadTest;
import com.intellectualcrafters.plot.commands.DebugRoadRegen;
import com.intellectualcrafters.plot.commands.DebugSaveTest;
import com.intellectualcrafters.plot.commands.DebugUUID;
import com.intellectualcrafters.plot.commands.Delete;
import com.intellectualcrafters.plot.commands.Deny;
import com.intellectualcrafters.plot.commands.FlagCmd;
import com.intellectualcrafters.plot.commands.Help;
import com.intellectualcrafters.plot.commands.Home;
import com.intellectualcrafters.plot.commands.Inbox;
import com.intellectualcrafters.plot.commands.Info;
import com.intellectualcrafters.plot.commands.Inventory;
import com.intellectualcrafters.plot.commands.Kick;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.Merge;
import com.intellectualcrafters.plot.commands.Move;
import com.intellectualcrafters.plot.commands.MusicSubcommand;
import com.intellectualcrafters.plot.commands.Purge;
import com.intellectualcrafters.plot.commands.Rate;
import com.intellectualcrafters.plot.commands.RegenAllRoads;
import com.intellectualcrafters.plot.commands.Reload;
import com.intellectualcrafters.plot.commands.Remove;
import com.intellectualcrafters.plot.commands.SchematicCmd;
import com.intellectualcrafters.plot.commands.Set;
import com.intellectualcrafters.plot.commands.SetOwner;
import com.intellectualcrafters.plot.commands.Setup;
import com.intellectualcrafters.plot.commands.Swap;
import com.intellectualcrafters.plot.commands.TP;
import com.intellectualcrafters.plot.commands.Target;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.commands.Toggle;
import com.intellectualcrafters.plot.commands.Trim;
import com.intellectualcrafters.plot.commands.Trust;
import com.intellectualcrafters.plot.commands.Unclaim;
import com.intellectualcrafters.plot.commands.Undeny;
import com.intellectualcrafters.plot.commands.Unlink;
import com.intellectualcrafters.plot.commands.Untrust;
import com.intellectualcrafters.plot.commands.Visit;
import com.intellectualcrafters.plot.commands.WE_Anywhere;
import com.intellectualcrafters.plot.commands.list;
import com.intellectualcrafters.plot.commands.plugin;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.plotme.ClassicPlotMeConnector;
import com.intellectualcrafters.plot.database.plotme.LikePlotMeConverter;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.listeners.ChunkListener;
import com.intellectualcrafters.plot.listeners.ForceFieldListener;
import com.intellectualcrafters.plot.listeners.InventoryListener;
import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8;
import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8_3;
import com.intellectualcrafters.plot.listeners.PlotListener;
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
import com.intellectualcrafters.plot.listeners.TNTListener;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.listeners.worldedit.WEListener;
import com.intellectualcrafters.plot.listeners.worldedit.WESubscriber;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler;
import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitInventoryUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils;
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.Metrics;
import com.intellectualcrafters.plot.util.bukkit.SendChunk;
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8;
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
import com.intellectualcrafters.plot.util.bukkit.SetGenCB;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
public static BukkitMain THIS = null; public static BukkitMain THIS = null;
public static PlotSquared MAIN = null;
private int[] version; private int[] version;
@ -168,7 +68,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override @Override
public void onEnable() { public void onEnable() {
THIS = this; THIS = this;
MAIN = new PlotSquared(this); PlotSquared.instance = new PlotSquared(this);
if (Settings.METRICS) { if (Settings.METRICS) {
try { try {
final Metrics metrics = new Metrics(this); final Metrics metrics = new Metrics(this);
@ -197,8 +97,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override @Override
public void onDisable() { public void onDisable() {
MAIN.disable(); PlotSquared.getInstance().disable();
MAIN = null;
THIS = null; THIS = null;
} }
@ -336,7 +235,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
this.error = 0l; this.error = 0l;
} }
World world; World world;
for (final String w : PlotSquared.getPlotWorlds()) { for (final String w : PlotSquared.getInstance().getPlotWorlds()) {
world = Bukkit.getWorld(w); world = Bukkit.getWorld(w);
try { try {
if (world.getLoadedChunks().length < 1) { if (world.getLoadedChunks().length < 1) {
@ -364,7 +263,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override @Override
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
WorldEvents.lastWorld = world; WorldEvents.lastWorld = world;
if (!PlotSquared.setupPlotWorld(world, id)) { if (!PlotSquared.getInstance().setupPlotWorld(world, id)) {
return null; return null;
} }
HybridGen result = new HybridGen(world); HybridGen result = new HybridGen(world);
@ -409,8 +308,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override @Override
public void registerWorldEditEvents() { public void registerWorldEditEvents() {
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) { if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
PlotSquared.worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit"); PlotSquared.getInstance().worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
final String version = PlotSquared.worldEdit.getDescription().getVersion(); final String version = PlotSquared.getInstance().worldEdit.getDescription().getVersion();
if ((version != null) && version.startsWith("5.")) { if ((version != null) && version.startsWith("5.")) {
log("&cThis version of WorldEdit does not support PlotSquared."); log("&cThis version of WorldEdit does not support PlotSquared.");
log("&cPlease use WorldEdit 6+ for masking support"); log("&cPlease use WorldEdit 6+ for masking support");
@ -430,8 +329,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
if (econ.init()) { if (econ.init()) {
return econ; return econ;
} }
} catch (Throwable e) {
} }
catch (Throwable e) {};
return null; return null;
} }
@ -472,10 +371,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
} }
}, 20); }, 20);
if (Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null) { return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null;
return true;
}
return false;
} }
@Override @Override

View File

@ -1,5 +1,22 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.*;
import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue;
import com.intellectualcrafters.plot.generator.*;
import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.Logger.LogLevel;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -8,101 +25,147 @@ import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import org.bukkit.configuration.file.YamlConfiguration; /**
* An implementation of the core,
* with a static getter for easy access
*/
public class PlotSquared implements PlotSquaredMain {
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.Database;
import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLManager;
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.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.generator.ClassicPlotWorld;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.SquarePlotManager;
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager;
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.Logger.LogLevel;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
public class PlotSquared {
public static final String MAIN_PERMISSION = "plots.use"; public static final String MAIN_PERMISSION = "plots.use";
public static final String ADMIN_PERMISSION = "plots.admin"; protected static PlotSquared instance;
public static File styleFile; private final HashMap<String, PlotWorld> plotworlds = new HashMap<>();
public static YamlConfiguration style; private final HashMap<String, PlotManager> plotmanagers = new HashMap<>();
public static File configFile; public WorldEditPlugin worldEdit = null;
public static YamlConfiguration config; private File styleFile;
public static File storageFile; private YamlConfiguration style;
public static YamlConfiguration storage; private File configFile;
public static PlotSquared THIS = null; // This class private YamlConfiguration config;
public static File FILE = null; // This file private File storageFile;
public static IPlotMain IMP = null; // Specific implementation of PlotSquared private YamlConfiguration storage;
public static String VERSION = null; private File FILE = null; // This file
public static TaskManager TASK = null; private IPlotMain IMP = null; // Specific implementation of PlotSquared
private static boolean LOADING_WORLD = false; private String VERSION = null;
public static WorldEditPlugin worldEdit = null; private boolean LOADING_WORLD = false;
private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>(); private LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>(); private Database database;
private Connection connection;
public PlotSquared(final IPlotMain imp_class) {
SetupUtils.generators = new HashMap<>();
IMP = imp_class;
try {
FILE = new File(PlotSquared.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
} catch (Exception e) {
log("Could not determine file path");
}
VERSION = IMP.getVersion();
EconHandler.manager = IMP.getEconomyHandler();
C.setupTranslations();
C.saveTranslations();
if (getJavaVersion() < 1.7) {
log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7.");
// Didn't know of any other link :D
log(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
IMP.disable();
return;
}
if (getJavaVersion() < 1.8) {
log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance");
}
TaskManager TASK = IMP.getTaskManager();
if (C.ENABLED.s().length() > 0) {
log(C.ENABLED.s());
}
setupConfigs();
setupDefaultFlags();
setupDatabase();
CommentManager.registerDefaultInboxes();
// Tasks
if (Settings.KILL_ROAD_MOBS) {
IMP.runEntityTask();
}
// Events
IMP.registerCommands();
IMP.registerPlayerEvents();
IMP.registerInventoryEvents();
IMP.registerPlotPlusEvents();
IMP.registerForceFieldEvents();
IMP.registerWorldEditEvents();
IMP.registerWorldEvents();
if (Settings.TNT_LISTENER) {
IMP.registerTNTListener();
}
if (Settings.CHUNK_PROCESSOR) {
IMP.registerChunkProcessor();
}
// create UUIDWrapper
UUIDHandler.uuidWrapper = IMP.initUUIDHandler();
// create event util class
EventUtil.manager = IMP.initEventUtil();
// create Hybrid utility class
HybridUtils.manager = IMP.initHybridUtils();
// Inventory utility class
InventoryUtil.manager = IMP.initInventoryUtil();
// create setup util class
SetupUtils.manager = IMP.initSetupUtils();
// Set block
BlockManager.manager = IMP.initBlockManager();
// Set chunk
ChunkManager.manager = IMP.initChunkManager();
// Plot listener
APlotListener.manager = IMP.initPlotListener();
// Player manager
PlayerManager.manager = IMP.initPlayerManager();
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots; // PlotMe
if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
if (IMP.initPlotMeConverter()) {
log("&c=== IMPORTANT ===");
log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!");
log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
}
}
}, 200);
}
if (Settings.AUTO_CLEAR) {
ExpireManager.runTask();
}
// Copy files
copyFile("town.template", "templates");
copyFile("skyblock.template", "templates");
copyFile("german.yml", "translations");
copyFile("s_chinese_unescaped.yml", "translations");
copyFile("s_chinese.yml", "translations");
copyFile("italian.yml", "translations");
showDebug();
}
private static Database database; public static PlotSquared getInstance() {
public static Connection connection; return instance;
}
public static Database getDatabase() { public static void log(final String message) {
getInstance().IMP.log(message);
}
@Override
public Database getDatabase() {
return database; return database;
} }
public static void updatePlot(final Plot plot) { @Override
public void updatePlot(final Plot plot) {
final String world = plot.world; final String world = plot.world;
if (!plots.containsKey(world)) { if (!plots.containsKey(world)) {
plots.put(world, new HashMap<PlotId, Plot>()); plots.put(world, new HashMap<PlotId, Plot>());
@ -111,14 +174,16 @@ public class PlotSquared {
plots.get(world).put(plot.id, plot); plots.get(world).put(plot.id, plot);
} }
public static PlotWorld getPlotWorld(final String world) { @Override
public PlotWorld getPlotWorld(final String world) {
if (plotworlds.containsKey(world)) { if (plotworlds.containsKey(world)) {
return plotworlds.get(world); return plotworlds.get(world);
} }
return null; return null;
} }
public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) { @Override
public void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) {
plotworlds.put(world, plotworld); plotworlds.put(world, plotworld);
plotmanagers.put(world, manager); plotmanagers.put(world, manager);
if (!plots.containsKey(world)) { if (!plots.containsKey(world)) {
@ -126,26 +191,31 @@ public class PlotSquared {
} }
} }
public static void removePlotWorld(final String world) { @Override
public void removePlotWorld(final String world) {
plots.remove(world); plots.remove(world);
plotmanagers.remove(world); plotmanagers.remove(world);
plotworlds.remove(world); plotworlds.remove(world);
} }
public static void removePlotWorldAbs(final String world) { @Override
public void removePlotWorldAbs(final String world) {
plotmanagers.remove(world); plotmanagers.remove(world);
plotworlds.remove(world); plotworlds.remove(world);
} }
public static HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw() { @Override
public HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw() {
return plots; return plots;
} }
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) { @Override
PlotSquared.plots = plots; public void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
this.plots = plots;
} }
public static Set<Plot> getPlots() { @Override
public Set<Plot> getPlots() {
final ArrayList<Plot> newplots = new ArrayList<>(); final ArrayList<Plot> newplots = new ArrayList<>();
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) { for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
if (isPlotWorld(entry.getKey())) { if (isPlotWorld(entry.getKey())) {
@ -155,7 +225,8 @@ public class PlotSquared {
return new LinkedHashSet<>(newplots); return new LinkedHashSet<>(newplots);
} }
public static Set<Plot> getPlotsRaw() { @Override
public Set<Plot> getPlotsRaw() {
final ArrayList<Plot> newplots = new ArrayList<>(); final ArrayList<Plot> newplots = new ArrayList<>();
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) { for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
newplots.addAll(entry.getValue().values()); newplots.addAll(entry.getValue().values());
@ -163,7 +234,8 @@ public class PlotSquared {
return new LinkedHashSet<>(newplots); return new LinkedHashSet<>(newplots);
} }
public static ArrayList<Plot> sortPlots(Collection<Plot> plots) { @Override
public ArrayList<Plot> sortPlots(Collection<Plot> plots) {
ArrayList<Plot> newPlots = new ArrayList<>(); ArrayList<Plot> newPlots = new ArrayList<>();
newPlots.addAll(plots); newPlots.addAll(plots);
Collections.sort(newPlots, new Comparator<Plot>() { Collections.sort(newPlots, new Comparator<Plot>() {
@ -189,9 +261,10 @@ public class PlotSquared {
return newPlots; return newPlots;
} }
public static ArrayList<Plot> sortPlots(Collection<Plot> plots, final String priorityWorld) { @Override
public ArrayList<Plot> sortPlots(Collection<Plot> plots, final String priorityWorld) {
ArrayList<Plot> newPlots = new ArrayList<>(); ArrayList<Plot> newPlots = new ArrayList<>();
HashMap<PlotId, Plot> worldPlots = PlotSquared.plots.get(priorityWorld); HashMap<PlotId, Plot> worldPlots = this.plots.get(priorityWorld);
if (worldPlots != null) { if (worldPlots != null) {
for (Plot plot : sortPlots(worldPlots.values())) { for (Plot plot : sortPlots(worldPlots.values())) {
if (plots.contains(plot)) { if (plots.contains(plot)) {
@ -199,11 +272,11 @@ public class PlotSquared {
} }
} }
} }
ArrayList<String> worlds = new ArrayList<>(PlotSquared.plots.keySet()); ArrayList<String> worlds = new ArrayList<>(this.plots.keySet());
Collections.sort(worlds); Collections.sort(worlds);
for (String world : worlds) { for (String world : worlds) {
if (!world.equals(priorityWorld)) { if (!world.equals(priorityWorld)) {
for (Plot plot : PlotSquared.plots.get(world).values()) { for (Plot plot : this.plots.get(world).values()) {
if (plots.contains(plot)) { if (plots.contains(plot)) {
newPlots.add(plot); newPlots.add(plot);
} }
@ -213,12 +286,13 @@ public class PlotSquared {
return newPlots; return newPlots;
} }
public static ArrayList<Plot> sortPlotsByWorld(Collection<Plot> plots) { @Override
public ArrayList<Plot> sortPlotsByWorld(Collection<Plot> plots) {
ArrayList<Plot> newPlots = new ArrayList<>(); ArrayList<Plot> newPlots = new ArrayList<>();
ArrayList<String> worlds = new ArrayList<>(PlotSquared.plots.keySet()); ArrayList<String> worlds = new ArrayList<>(this.plots.keySet());
Collections.sort(worlds); Collections.sort(worlds);
for (String world : worlds) { for (String world : worlds) {
for (Plot plot : PlotSquared.plots.get(world).values()) { for (Plot plot : this.plots.get(world).values()) {
if (plots.contains(plot)) { if (plots.contains(plot)) {
newPlots.add(plot); newPlots.add(plot);
} }
@ -227,17 +301,20 @@ public class PlotSquared {
return newPlots; return newPlots;
} }
public static Set<Plot> getPlots(final String world, final String player) { @Override
public Set<Plot> getPlots(final String world, final String player) {
final UUID uuid = UUIDHandler.getUUID(player); final UUID uuid = UUIDHandler.getUUID(player);
return getPlots(world, uuid); return getPlots(world, uuid);
} }
public static Set<Plot> getPlots(final String world, final PlotPlayer player) { @Override
public Set<Plot> getPlots(final String world, final PlotPlayer player) {
final UUID uuid = player.getUUID(); final UUID uuid = player.getUUID();
return getPlots(world, uuid); return getPlots(world, uuid);
} }
public static Set<Plot> getPlots(final String world, final UUID uuid) { @Override
public Set<Plot> getPlots(final String world, final UUID uuid) {
final ArrayList<Plot> myplots = new ArrayList<>(); final ArrayList<Plot> myplots = new ArrayList<>();
for (final Plot plot : getPlots(world).values()) { for (final Plot plot : getPlots(world).values()) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -249,34 +326,40 @@ public class PlotSquared {
return new HashSet<>(myplots); return new HashSet<>(myplots);
} }
public static boolean isPlotWorld(final String world) { @Override
public boolean isPlotWorld(final String world) {
return (plotworlds.containsKey(world)); return (plotworlds.containsKey(world));
} }
public static PlotManager getPlotManager(final String world) { @Override
public PlotManager getPlotManager(final String world) {
if (plotmanagers.containsKey(world)) { if (plotmanagers.containsKey(world)) {
return plotmanagers.get(world); return plotmanagers.get(world);
} }
return null; return null;
} }
public static String[] getPlotWorldsString() { @Override
public String[] getPlotWorldsString() {
final Set<String> strings = plots.keySet(); final Set<String> strings = plots.keySet();
return strings.toArray(new String[strings.size()]); return strings.toArray(new String[strings.size()]);
} }
public static HashMap<PlotId, Plot> getPlots(final String world) { @Override
public HashMap<PlotId, Plot> getPlots(final String world) {
if (plots.containsKey(world)) { if (plots.containsKey(world)) {
return plots.get(world); return plots.get(world);
} }
return new HashMap<>(); return new HashMap<>();
} }
public static Set<Plot> getPlots(final PlotPlayer player) { @Override
public Set<Plot> getPlots(final PlotPlayer player) {
return getPlots(player.getUUID()); return getPlots(player.getUUID());
} }
public static Set<Plot> getPlots(final UUID uuid) { @Override
public Set<Plot> getPlots(final UUID uuid) {
final ArrayList<Plot> myplots = new ArrayList<>(); final ArrayList<Plot> myplots = new ArrayList<>();
for (final String world : plots.keySet()) { for (final String world : plots.keySet()) {
if (isPlotWorld(world)) { if (isPlotWorld(world)) {
@ -292,7 +375,8 @@ public class PlotSquared {
return new HashSet<>(myplots); return new HashSet<>(myplots);
} }
public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) { @Override
public boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
if (callEvent) { if (callEvent) {
EventUtil.manager.callDelete(world, id); EventUtil.manager.callDelete(world, id);
} }
@ -308,7 +392,8 @@ public class PlotSquared {
return true; return true;
} }
public static void loadWorld(final String world, PlotGenerator generator) { @Override
public void loadWorld(final String world, PlotGenerator generator) {
PlotWorld plotWorld = getPlotWorld(world); PlotWorld plotWorld = getPlotWorld(world);
if (plotWorld != null) { if (plotWorld != null) {
if (generator != null) { if (generator != null) {
@ -404,7 +489,8 @@ public class PlotSquared {
} }
} }
public static boolean setupPlotWorld(final String world, final String id) { @Override
public boolean setupPlotWorld(final String world, final String id) {
if ((id != null) && (id.length() > 0)) { if ((id != null) && (id.length() > 0)) {
// save configuration // save configuration
final String[] split = id.split(","); final String[] split = id.split(",");
@ -428,39 +514,39 @@ public class PlotSquared {
switch (key) { switch (key) {
case "s": case "s":
case "size": { case "size": {
SquarePlotWorld.PLOT_WIDTH_DEFAULT = ((Integer) Configuration.INTEGER.parseString(value)).shortValue(); SquarePlotWorld.PLOT_WIDTH_DEFAULT = Configuration.INTEGER.parseString(value).shortValue();
break; break;
} }
case "g": case "g":
case "gap": { case "gap": {
SquarePlotWorld.ROAD_WIDTH_DEFAULT = ((Integer) Configuration.INTEGER.parseString(value)).shortValue(); SquarePlotWorld.ROAD_WIDTH_DEFAULT = Configuration.INTEGER.parseString(value).shortValue();
break; break;
} }
case "h": case "h":
case "height": { case "height": {
ClassicPlotWorld.PLOT_HEIGHT_DEFAULT = (Integer) Configuration.INTEGER.parseString(value); ClassicPlotWorld.PLOT_HEIGHT_DEFAULT = Configuration.INTEGER.parseString(value);
ClassicPlotWorld.ROAD_HEIGHT_DEFAULT = (Integer) Configuration.INTEGER.parseString(value); ClassicPlotWorld.ROAD_HEIGHT_DEFAULT = Configuration.INTEGER.parseString(value);
ClassicPlotWorld.WALL_HEIGHT_DEFAULT = (Integer) Configuration.INTEGER.parseString(value); ClassicPlotWorld.WALL_HEIGHT_DEFAULT = Configuration.INTEGER.parseString(value);
break; break;
} }
case "f": case "f":
case "floor": { case "floor": {
ClassicPlotWorld.TOP_BLOCK_DEFAULT = (PlotBlock[]) Configuration.BLOCKLIST.parseString(value); ClassicPlotWorld.TOP_BLOCK_DEFAULT = Configuration.BLOCKLIST.parseString(value);
break; break;
} }
case "m": case "m":
case "main": { case "main": {
ClassicPlotWorld.MAIN_BLOCK_DEFAULT = (PlotBlock[]) Configuration.BLOCKLIST.parseString(value); ClassicPlotWorld.MAIN_BLOCK_DEFAULT = Configuration.BLOCKLIST.parseString(value);
break; break;
} }
case "w": case "w":
case "wall": { case "wall": {
ClassicPlotWorld.WALL_FILLING_DEFAULT = (PlotBlock) Configuration.BLOCK.parseString(value); ClassicPlotWorld.WALL_FILLING_DEFAULT = Configuration.BLOCK.parseString(value);
break; break;
} }
case "b": case "b":
case "border": { case "border": {
ClassicPlotWorld.WALL_BLOCK_DEFAULT = (PlotBlock) Configuration.BLOCK.parseString(value); ClassicPlotWorld.WALL_BLOCK_DEFAULT = Configuration.BLOCK.parseString(value);
break; break;
} }
default: { default: {
@ -496,112 +582,109 @@ public class PlotSquared {
return true; return true;
} }
public static Connection getConnection() { @Override
public boolean setupPlotWorld(final String world, final String id) {
if ((id != null) && (id.length() > 0)) {
// save configuration
final String[] split = id.split(",");
final HybridPlotWorld plotworld = new HybridPlotWorld(world);
final int width = SquarePlotWorld.PLOT_WIDTH_DEFAULT;
final int gap = SquarePlotWorld.ROAD_WIDTH_DEFAULT;
final int height = ClassicPlotWorld.PLOT_HEIGHT_DEFAULT;
final PlotBlock[] floor = ClassicPlotWorld.TOP_BLOCK_DEFAULT;
final PlotBlock[] main = ClassicPlotWorld.MAIN_BLOCK_DEFAULT;
final PlotBlock wall = ClassicPlotWorld.WALL_FILLING_DEFAULT;
final PlotBlock border = ClassicPlotWorld.WALL_BLOCK_DEFAULT;
for (final String element : split) {
final String[] pair = element.split("=");
if (pair.length != 2) {
log("&cNo value provided for: &7" + element);
return false;
}
final String key = pair[0].toLowerCase();
final String value = pair[1];
try {
switch (key) {
case "s":
case "size": {
SquarePlotWorld.PLOT_WIDTH_DEFAULT = Configuration.INTEGER.parseString(value).shortValue();
break;
}
case "g":
case "gap": {
SquarePlotWorld.ROAD_WIDTH_DEFAULT = Configuration.INTEGER.parseString(value).shortValue();
break;
}
case "h":
case "height": {
ClassicPlotWorld.PLOT_HEIGHT_DEFAULT = Configuration.INTEGER.parseString(value);
ClassicPlotWorld.ROAD_HEIGHT_DEFAULT = Configuration.INTEGER.parseString(value);
ClassicPlotWorld.WALL_HEIGHT_DEFAULT = Configuration.INTEGER.parseString(value);
break;
}
case "f":
case "floor": {
ClassicPlotWorld.TOP_BLOCK_DEFAULT = Configuration.BLOCKLIST.parseString(value);
break;
}
case "m":
case "main": {
ClassicPlotWorld.MAIN_BLOCK_DEFAULT = Configuration.BLOCKLIST.parseString(value);
break;
}
case "w":
case "wall": {
ClassicPlotWorld.WALL_FILLING_DEFAULT = Configuration.BLOCK.parseString(value);
break;
}
case "b":
case "border": {
ClassicPlotWorld.WALL_BLOCK_DEFAULT = Configuration.BLOCK.parseString(value);
break;
}
default: {
log("&cKey not found: &7" + element);
return false;
}
}
} catch (final Exception e) {
e.printStackTrace();
log("&cInvalid value: &7" + value + " in arg " + element);
return false;
}
}
try {
final String root = "worlds." + world;
if (!config.contains(root)) {
config.createSection(root);
}
plotworld.saveConfiguration(config.getConfigurationSection(root));
ClassicPlotWorld.PLOT_HEIGHT_DEFAULT = height;
ClassicPlotWorld.ROAD_HEIGHT_DEFAULT = height;
ClassicPlotWorld.WALL_HEIGHT_DEFAULT = height;
ClassicPlotWorld.TOP_BLOCK_DEFAULT = floor;
ClassicPlotWorld.MAIN_BLOCK_DEFAULT = main;
ClassicPlotWorld.WALL_BLOCK_DEFAULT = border;
ClassicPlotWorld.WALL_FILLING_DEFAULT = wall;
SquarePlotWorld.PLOT_WIDTH_DEFAULT = width;
SquarePlotWorld.ROAD_WIDTH_DEFAULT = gap;
} catch (final Exception e) {
e.printStackTrace();
}
}
return true;
}
@Override
public Connection getConnection() {
return connection; return connection;
} }
public PlotSquared(final IPlotMain imp_class) { @Override
SetupUtils.generators = new HashMap<>();
THIS = this;
IMP = imp_class;
try {
FILE = new File(PlotSquared.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
}
catch (Exception e) {
log("Could not determine file path");
}
VERSION = IMP.getVersion();
EconHandler.manager = IMP.getEconomyHandler();
C.setupTranslations();
C.saveTranslations();
if (getJavaVersion() < 1.7) {
log(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7.");
// Didn't know of any other link :D
log(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
IMP.disable();
return;
}
if (getJavaVersion() < 1.8) {
log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance");
}
TASK = IMP.getTaskManager();
if (C.ENABLED.s().length() > 0) {
log(C.ENABLED.s());
}
setupConfigs();
setupDefaultFlags();
setupDatabase();
CommentManager.registerDefaultInboxes();
// Tasks
if (Settings.KILL_ROAD_MOBS) {
IMP.runEntityTask();
}
// Events
IMP.registerCommands();
IMP.registerPlayerEvents();
IMP.registerInventoryEvents();
IMP.registerPlotPlusEvents();
IMP.registerForceFieldEvents();
IMP.registerWorldEditEvents();
IMP.registerWorldEvents();
if (Settings.TNT_LISTENER) {
IMP.registerTNTListener();
}
if (Settings.CHUNK_PROCESSOR) {
IMP.registerChunkProcessor();
}
// create UUIDWrapper
UUIDHandler.uuidWrapper = IMP.initUUIDHandler();
// create event util class
EventUtil.manager = IMP.initEventUtil();
// create Hybrid utility class
HybridUtils.manager = IMP.initHybridUtils();
// Inventory utility class
InventoryUtil.manager = IMP.initInventoryUtil();
// create setup util class
SetupUtils.manager = IMP.initSetupUtils();
// Set block
BlockManager.manager = IMP.initBlockManager();
// Set chunk
ChunkManager.manager = IMP.initChunkManager();
// Plot listener
APlotListener.manager = IMP.initPlotListener();
// Player manager
PlayerManager.manager = IMP.initPlayerManager();
// PlotMe
if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
if (IMP.initPlotMeConverter()) {
log("&c=== IMPORTANT ===");
log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!");
log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
}
}
}, 200);
}
if (Settings.AUTO_CLEAR) {
ExpireManager.runTask();
}
// Copy files
copyFile("town.template", "templates");
copyFile("skyblock.template", "templates");
copyFile("german.yml", "translations");
copyFile("s_chinese_unescaped.yml", "translations");
copyFile("s_chinese.yml", "translations");
copyFile("italian.yml", "translations");
showDebug();
}
public void copyFile(String file, String folder) { public void copyFile(String file, String folder) {
try { try {
byte[] buffer = new byte[2048]; byte[] buffer = new byte[2048];
File output = PlotSquared.IMP.getDirectory(); File output = IMP.getDirectory();
if (!output.exists()) { if (!output.exists()) {
output.mkdirs(); output.mkdirs();
} }
@ -636,6 +719,7 @@ public class PlotSquared {
} }
} }
@Override
public void disable() { public void disable() {
try { try {
database.closeConnection(); database.closeConnection();
@ -644,14 +728,11 @@ public class PlotSquared {
} }
} }
public static void log(final String message) { @Override
IMP.log(message);
}
public void setupDatabase() { public void setupDatabase() {
if (Settings.DB.USE_MYSQL) { if (Settings.DB.USE_MYSQL) {
try { try {
database = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD); database = new MySQL(this, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD);
connection = database.openConnection(); connection = database.openConnection();
{ {
if (DBFunc.dbManager == null) { if (DBFunc.dbManager == null) {
@ -679,7 +760,7 @@ public class PlotSquared {
log(C.PREFIX.s() + "MongoDB is not yet implemented"); log(C.PREFIX.s() + "MongoDB is not yet implemented");
} else if (Settings.DB.USE_SQLITE) { } else if (Settings.DB.USE_SQLITE) {
try { try {
this.database = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db"); this.database = new SQLite(this, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db");
connection = this.database.openConnection(); connection = this.database.openConnection();
{ {
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX); DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
@ -705,7 +786,8 @@ public class PlotSquared {
} }
} }
public static void setupDefaultFlags() { @Override
public void setupDefaultFlags() {
final List<String> booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit", "redstone", "keep"); final List<String> booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit", "redstone", "keep");
final List<String> intervalFlags = Arrays.asList("feed", "heal"); final List<String> intervalFlags = Arrays.asList("feed", "heal");
final List<String> stringFlags = Arrays.asList("greeting", "farewell"); final List<String> stringFlags = Arrays.asList("greeting", "farewell");
@ -797,7 +879,8 @@ public class PlotSquared {
}); });
} }
public static void setupConfig() { @Override
public void setupConfig() {
config.set("version", VERSION); config.set("version", VERSION);
final Map<String, Object> options = new HashMap<>(); final Map<String, Object> options = new HashMap<>();
@ -976,7 +1059,8 @@ public class PlotSquared {
Settings.METRICS = config.getBoolean("metrics"); Settings.METRICS = config.getBoolean("metrics");
} }
public static void setupConfigs() { @Override
public void setupConfigs() {
final File folder = new File(IMP.getDirectory() + File.separator + "config"); final File folder = new File(IMP.getDirectory() + File.separator + "config");
if (!folder.exists() && !folder.mkdirs()) { if (!folder.exists() && !folder.mkdirs()) {
log(C.PREFIX.s() + "&cFailed to create the /plugins/config folder. Please create it manually."); log(C.PREFIX.s() + "&cFailed to create the /plugins/config folder. Please create it manually.");
@ -1030,7 +1114,7 @@ public class PlotSquared {
} }
} }
private static void setupStorage() { private void setupStorage() {
storage.set("version", VERSION); storage.set("version", VERSION);
final Map<String, Object> options = new HashMap<>(); final Map<String, Object> options = new HashMap<>();
options.put("mysql.use", false); options.put("mysql.use", false);
@ -1062,7 +1146,8 @@ public class PlotSquared {
Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban"); Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban");
} }
public static void showDebug() { @Override
public void showDebug() {
C.COLOR_1 = "&" + (style.getString("color.1")); C.COLOR_1 = "&" + (style.getString("color.1"));
C.COLOR_2 = "&" + (style.getString("color.2")); C.COLOR_2 = "&" + (style.getString("color.2"));
C.COLOR_3 = "&" + (style.getString("color.3")); C.COLOR_3 = "&" + (style.getString("color.3"));
@ -1085,7 +1170,7 @@ public class PlotSquared {
} }
} }
private static void setupStyle() { private void setupStyle() {
style.set("version", VERSION); style.set("version", VERSION);
final Map<String, Object> o = new HashMap<>(); final Map<String, Object> o = new HashMap<>();
o.put("color.1", C.COLOR_1.substring(1)); o.put("color.1", C.COLOR_1.substring(1));
@ -1099,15 +1184,18 @@ public class PlotSquared {
} }
} }
public static double getJavaVersion() { @Override
public double getJavaVersion() {
return Double.parseDouble(System.getProperty("java.specification.version")); return Double.parseDouble(System.getProperty("java.specification.version"));
} }
public static Set<String> getPlotWorlds() { @Override
public Set<String> getPlotWorlds() {
return plotworlds.keySet(); return plotworlds.keySet();
} }
public static Collection<PlotWorld> getPlotWorldObjects() { @Override
public Collection<PlotWorld> getPlotWorldObjects() {
return plotworlds.values(); return plotworlds.values();
} }
} }

View File

@ -0,0 +1,85 @@
package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.database.Database;
import com.intellectualcrafters.plot.object.*;
import java.sql.Connection;
import java.util.*;
/**
* Core of the PlotSquared Plugin
*/
public interface PlotSquaredMain {
Database getDatabase();
void updatePlot(Plot plot);
PlotWorld getPlotWorld(String world);
void addPlotWorld(String world, PlotWorld plotworld, PlotManager manager);
void removePlotWorld(String world);
void removePlotWorldAbs(String world);
HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw();
void setAllPlotsRaw(LinkedHashMap<String, HashMap<PlotId, Plot>> plots);
Set<Plot> getPlots();
Set<Plot> getPlotsRaw();
ArrayList<Plot> sortPlots(Collection<Plot> plots);
ArrayList<Plot> sortPlots(Collection<Plot> plots, String priorityWorld);
ArrayList<Plot> sortPlotsByWorld(Collection<Plot> plots);
Set<Plot> getPlots(String world, String player);
Set<Plot> getPlots(String world, PlotPlayer player);
Set<Plot> getPlots(String world, UUID uuid);
boolean isPlotWorld(String world);
PlotManager getPlotManager(String world);
String[] getPlotWorldsString();
HashMap<PlotId, Plot> getPlots(String world);
Set<Plot> getPlots(PlotPlayer player);
Set<Plot> getPlots(UUID uuid);
boolean removePlot(String world, PlotId id, boolean callEvent);
void loadWorld(String world, PlotGenerator generator);
boolean setupPlotWorld(String world, String id);
Connection getConnection();
void copyFile(String file, String folder);
void disable();
void setupDatabase();
void setupDefaultFlags();
void setupConfig();
void setupConfigs();
void showDebug();
double getJavaVersion();
Set<String> getPlotWorlds();
Collection<PlotWorld> getPlotWorldObjects();
}

View File

@ -21,37 +21,27 @@
package com.intellectualcrafters.plot.api; package com.intellectualcrafters.plot.api;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.commands.SubCommand; import com.intellectualcrafters.plot.commands.SubCommand;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
/** /**
* PlotSquared API * PlotSquared API
@ -93,7 +83,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.PlotSquared#getPlots() * @see com.intellectualcrafters.plot.PlotSquared#getPlots()
*/ */
public Set<Plot> getAllPlots() { public Set<Plot> getAllPlots() {
return PlotSquared.getPlots(); return PlotSquared.getInstance().getPlots();
} }
/** /**
@ -104,7 +94,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @return all plots that a player owns * @return all plots that a player owns
*/ */
public Set<Plot> getPlayerPlots(final Player player) { public Set<Plot> getPlayerPlots(final Player player) {
return PlotSquared.getPlots(BukkitUtil.getPlayer(player)); return PlotSquared.getInstance().getPlots(BukkitUtil.getPlayer(player));
} }
/** /**
@ -118,7 +108,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* com.intellectualcrafters.plot.object.PlotManager) * com.intellectualcrafters.plot.object.PlotManager)
*/ */
public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) { public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) {
PlotSquared.addPlotWorld(world, plotWorld, manager); PlotSquared.getInstance().addPlotWorld(world, plotWorld, manager);
} }
/** /**
@ -286,7 +276,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see PlotSquared#getPlotManager(String) * @see PlotSquared#getPlotManager(String)
*/ */
public PlotManager getPlotManager(final World world) { public PlotManager getPlotManager(final World world) {
return PlotSquared.getPlotManager(world.getName()); return PlotSquared.getInstance().getPlotManager(world.getName());
} }
/** /**
@ -301,7 +291,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.object.PlotManager * @see com.intellectualcrafters.plot.object.PlotManager
*/ */
public PlotManager getPlotManager(final String world) { public PlotManager getPlotManager(final String world) {
return PlotSquared.getPlotManager(world); return PlotSquared.getInstance().getPlotManager(world);
} }
/** /**
@ -316,7 +306,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.object.PlotWorld * @see com.intellectualcrafters.plot.object.PlotWorld
*/ */
public PlotWorld getWorldSettings(final World world) { public PlotWorld getWorldSettings(final World world) {
return PlotSquared.getPlotWorld(world.getName()); return PlotSquared.getInstance().getPlotWorld(world.getName());
} }
/** /**
@ -330,7 +320,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.object.PlotWorld * @see com.intellectualcrafters.plot.object.PlotWorld
*/ */
public PlotWorld getWorldSettings(final String world) { public PlotWorld getWorldSettings(final String world) {
return PlotSquared.getPlotWorld(world); return PlotSquared.getInstance().getPlotWorld(world);
} }
/** /**
@ -472,7 +462,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
*/ */
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) { public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
final ArrayList<Plot> pPlots = new ArrayList<>(); final ArrayList<Plot> pPlots = new ArrayList<>();
for (final Plot plot : PlotSquared.getPlots(world.getName()).values()) { for (final Plot plot : PlotSquared.getInstance().getPlots(world.getName()).values()) {
if (just_owner) { if (just_owner) {
if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))) { if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))) {
pPlots.add(plot); pPlots.add(plot);
@ -497,7 +487,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.object.Plot * @see com.intellectualcrafters.plot.object.Plot
*/ */
public Plot[] getPlots(final World world) { public Plot[] getPlots(final World world) {
Collection<Plot> plots = PlotSquared.getPlots(world.getName()).values(); Collection<Plot> plots = PlotSquared.getInstance().getPlots(world.getName()).values();
return plots.toArray(new Plot[plots.size()]); return plots.toArray(new Plot[plots.size()]);
} }
@ -509,7 +499,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.PlotSquared#getPlotWorlds() * @see com.intellectualcrafters.plot.PlotSquared#getPlotWorlds()
*/ */
public String[] getPlotWorlds() { public String[] getPlotWorlds() {
Set<String> worlds = PlotSquared.getPlotWorlds(); Set<String> worlds = PlotSquared.getInstance().getPlotWorlds();
return worlds.toArray(new String[worlds.size()]); return worlds.toArray(new String[worlds.size()]);
} }
@ -523,7 +513,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.PlotSquared#isPlotWorld(String) * @see com.intellectualcrafters.plot.PlotSquared#isPlotWorld(String)
*/ */
public boolean isPlotWorld(final World world) { public boolean isPlotWorld(final World world) {
return PlotSquared.isPlotWorld(world.getName()); return PlotSquared.getInstance().isPlotWorld(world.getName());
} }
/** /**
@ -652,7 +642,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* @see com.intellectualcrafters.plot.object.Plot * @see com.intellectualcrafters.plot.object.Plot
*/ */
public Set<Plot> getPlayerPlots(final World world, final Player player) { public Set<Plot> getPlayerPlots(final World world, final Player player) {
return PlotSquared.getPlots(world.getName(), BukkitUtil.getPlayer(player)); return PlotSquared.getInstance().getPlots(world.getName(), BukkitUtil.getPlayer(player));
} }
/** /**
@ -662,7 +652,6 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
* *
* @return the number of allowed plots * @return the number of allowed plots
* *
* @see com.intellectualcrafters.plot.util.MainUtil#getAllowedPlots(PlotPlayer, int)
*/ */
public int getAllowedPlots(final Player player) { public int getAllowedPlots(final Player player) {
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);

View File

@ -20,8 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -33,6 +31,8 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.UUID;
public class Add extends SubCommand { public class Add extends SubCommand {
public Add() { public Add() {
super(Command.ADD, "Allow a user to build while you are online", "add <player>", CommandCategory.ACTIONS, true); super(Command.ADD, "Allow a user to build while you are online", "add <player>", CommandCategory.ACTIONS, true);
@ -77,7 +77,7 @@ public class Add extends SubCommand {
DBFunc.removeTrusted(loc.getWorld(), plot, uuid); DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
} }
if (plot.denied.contains(uuid)) { if (plot.denied.contains(uuid)) {
if (plot.members.size() + plot.trusted.size() >= PlotSquared.getPlotWorld(plot.world).MAX_PLOT_MEMBERS) { if (plot.members.size() + plot.trusted.size() >= PlotSquared.getInstance().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; return false;
} }
@ -91,7 +91,7 @@ public class Add extends SubCommand {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false; return false;
} }
if (plot.members.size() + plot.trusted.size() >= PlotSquared.getPlotWorld(plot.world).MAX_PLOT_MEMBERS) { if (plot.members.size() + plot.trusted.size() >= PlotSquared.getInstance().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; return false;
} }

View File

@ -23,12 +23,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.*;
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.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -75,11 +70,11 @@ public class Auto extends SubCommand {
int size_x = 1; int size_x = 1;
int size_z = 1; int size_z = 1;
String schematic = ""; String schematic = "";
if (PlotSquared.getPlotWorlds().size() == 1) { if (PlotSquared.getInstance().getPlotWorlds().size() == 1) {
world = PlotSquared.getPlotWorlds().iterator().next(); world = PlotSquared.getInstance().getPlotWorlds().iterator().next();
} else { } else {
world = plr.getLocation().getWorld(); world = plr.getLocation().getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false; return false;
} }
@ -127,7 +122,7 @@ public class Auto extends SubCommand {
} }
return false; return false;
} }
final PlotWorld pWorld = PlotSquared.getPlotWorld(world); final PlotWorld pWorld = PlotSquared.getInstance().getPlotWorld(world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
double cost = pWorld.PLOT_PRICE; double cost = pWorld.PLOT_PRICE;
cost = (size_x * size_z) * cost; cost = (size_x * size_z) * cost;
@ -153,7 +148,7 @@ public class Auto extends SubCommand {
// } // }
} }
final String worldname = world; final String worldname = world;
final PlotWorld plotworld = PlotSquared.getPlotWorld(worldname); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(worldname);
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ())); final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
@ -204,7 +199,7 @@ public class Auto extends SubCommand {
MainUtil.lastPlot.put(worldname, start); MainUtil.lastPlot.put(worldname, start);
if (lastPlot) { if (lastPlot) {
} }
if ((PlotSquared.getPlots(worldname).get(start) != null) && (PlotSquared.getPlots(worldname).get(start).owner != null)) { if ((PlotSquared.getInstance().getPlots(worldname).get(start) != null) && (PlotSquared.getInstance().getPlots(worldname).get(start).owner != null)) {
continue; continue;
} else { } else {
lastPlot = false; lastPlot = false;

View File

@ -26,12 +26,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -51,7 +46,7 @@ public class Buy extends SubCommand {
} }
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final String world = loc.getWorld(); final String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return sendMessage(plr, C.NOT_IN_PLOT_WORLD); return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
} }
Plot plot; Plot plot;
@ -88,7 +83,7 @@ public class Buy extends SubCommand {
final PlotId id = plot.id; final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id; final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int size = MainUtil.getPlotSelectionIds(id, id2).size(); final int size = MainUtil.getPlotSelectionIds(id, id2).size();
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (plotworld.USE_ECONOMY) { if (plotworld.USE_ECONOMY) {
price += plotworld.PLOT_PRICE * size; price += plotworld.PLOT_PRICE * size;
initPrice += plotworld.SELL_PRICE * size; initPrice += plotworld.SELL_PRICE * size;

View File

@ -13,7 +13,7 @@ public class Chat extends SubCommand {
@Override @Override
public boolean execute(PlotPlayer plr, String... args) { public boolean execute(PlotPlayer plr, String... args) {
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
} }
boolean enable = !(plr.getMeta("chat") != null && (Boolean) plr.getMeta("chat")); boolean enable = !(plr.getMeta("chat") != null && (Boolean) plr.getMeta("chat"));
@ -24,7 +24,7 @@ public class Chat extends SubCommand {
enable = false; enable = false;
} }
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (!enable && plotworld.PLOT_CHAT) { if (!enable && plotworld.PLOT_CHAT) {
return !sendMessage(plr, C.PLOT_CHAT_FORCED); return !sendMessage(plr, C.PLOT_CHAT_FORCED);
} }

View File

@ -27,11 +27,7 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
/** /**
@ -60,8 +56,8 @@ public class Claim extends SubCommand {
MainUtil.teleportPlayer(player, loc, plot); MainUtil.teleportPlayer(player, loc, plot);
} }
final String world = plot.world; final String world = plot.world;
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final Plot plot2 = PlotSquared.getPlots(world).get(plot.id); final Plot plot2 = PlotSquared.getInstance().getPlots(world).get(plot.id);
if (plotworld.SCHEMATIC_ON_CLAIM) { if (plotworld.SCHEMATIC_ON_CLAIM) {
Schematic sch; Schematic sch;
if (schematic.equals("")) { if (schematic.equals("")) {
@ -74,7 +70,7 @@ public class Claim extends SubCommand {
} }
SchematicHandler.manager.paste(sch, plot2, 0, 0); SchematicHandler.manager.paste(sch, plot2, 0, 0);
} }
PlotSquared.getPlotManager(world).claimPlot(plotworld, plot); PlotSquared.getInstance().getPlotManager(world).claimPlot(plotworld, plot);
} }
return result; return result;
} }
@ -97,7 +93,7 @@ public class Claim extends SubCommand {
if (!MainUtil.canClaim(plr, plot)) { if (!MainUtil.canClaim(plr, plot)) {
return sendMessage(plr, C.PLOT_IS_CLAIMED); return sendMessage(plr, C.PLOT_IS_CLAIMED);
} }
final PlotWorld world = PlotSquared.getPlotWorld(plot.world); final PlotWorld world = PlotSquared.getInstance().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && world.USE_ECONOMY) { if ((EconHandler.manager != null) && world.USE_ECONOMY) {
final double cost = world.PLOT_PRICE; final double cost = world.PLOT_PRICE;
if (cost > 0d) { if (cost > 0d) {

View File

@ -20,8 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Set;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -35,6 +33,8 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.Set;
public class Clear extends SubCommand { public class Clear extends SubCommand {
public Clear() { public Clear() {
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false); super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false);
@ -52,7 +52,7 @@ public class Clear extends SubCommand {
if (id == null) { if (id == null) {
PlotSquared.log("Invalid Plot ID: " + args[0]); PlotSquared.log("Invalid Plot ID: " + args[0]);
} else { } else {
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
PlotSquared.log("Invalid plot world: " + world); PlotSquared.log("Invalid plot world: " + world);
} else { } else {
final Plot plot = MainUtil.getPlot(world, id); final Plot plot = MainUtil.getPlot(world, id);
@ -84,7 +84,7 @@ public class Clear extends SubCommand {
PlotId id = PlotId.fromString(args[0]); PlotId id = PlotId.fromString(args[0]);
if (id == null) { if (id == null) {
if (args[1].equalsIgnoreCase("mine")) { if (args[1].equalsIgnoreCase("mine")) {
Set<Plot> plots = PlotSquared.getPlots(plr); Set<Plot> plots = PlotSquared.getInstance().getPlots(plr);
if (plots.size() == 0) { if (plots.size() == 0) {
MainUtil.sendMessage(plr, C.NO_PLOTS); MainUtil.sendMessage(plr, C.NO_PLOTS);
return false; return false;

View File

@ -20,29 +20,21 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.AugmentedPopulator; import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
public class Cluster extends SubCommand { public class Cluster extends SubCommand {
public Cluster() { public Cluster() {
super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true); super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true);
@ -129,17 +121,17 @@ public class Cluster extends SubCommand {
} }
ClusterManager.clusters.get(world).add(cluster); ClusterManager.clusters.get(world).add(cluster);
// Add any existing plots to the current cluster // Add any existing plots to the current cluster
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) { for (final Plot plot : PlotSquared.getInstance().getPlots(plr.getLocation().getWorld()).values()) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = ClusterManager.getCluster(plot);
if (cluster.equals(current) && !cluster.isAdded(plot.owner)) { if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
cluster.invited.add(plot.owner); cluster.invited.add(plot.owner);
DBFunc.setInvited(world, cluster, plot.owner); DBFunc.setInvited(world, cluster, plot.owner);
} }
} }
PlotWorld plotworld = PlotSquared.getPlotWorld(world); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (plotworld == null) { if (plotworld == null) {
PlotSquared.config.createSection("worlds." + world); PlotSquared.config.createSection("worlds." + world);
PlotSquared.loadWorld(world, null); PlotSquared.getInstance().loadWorld(world, null);
} }
else { else {
final String gen_string = PlotSquared.config.getString("worlds." + world + "." + "generator.plugin"); final String gen_string = PlotSquared.config.getString("worlds." + world + "." + "generator.plugin");
@ -185,10 +177,10 @@ public class Cluster extends SubCommand {
return false; return false;
} }
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(plr.getLocation().getWorld()); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(plr.getLocation().getWorld());
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
final ArrayList<Plot> toRemove = new ArrayList<>(); final ArrayList<Plot> toRemove = new ArrayList<>();
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) { for (final Plot plot : PlotSquared.getInstance().getPlots(plr.getLocation().getWorld()).values()) {
final PlotCluster other = ClusterManager.getCluster(plot); final PlotCluster other = ClusterManager.getCluster(plot);
if (cluster.equals(other)) { if (cluster.equals(other)) {
toRemove.add(plot); toRemove.add(plot);
@ -369,7 +361,7 @@ public class Cluster extends SubCommand {
if (player != null) { if (player != null) {
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName()); MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
} }
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld(), uuid)) { for (final Plot plot : PlotSquared.getInstance().getPlots(plr.getLocation().getWorld(), uuid)) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
@ -419,7 +411,7 @@ public class Cluster extends SubCommand {
cluster.invited.remove(uuid); cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid); DBFunc.removeInvited(cluster, uuid);
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName()); MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld(), uuid)) { for (final Plot plot : PlotSquared.getInstance().getPlots(plr.getLocation().getWorld(), uuid)) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();

View File

@ -20,14 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -35,6 +27,10 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import org.apache.commons.lang.StringUtils;
import java.util.*;
import java.util.Set;
public class Condense extends SubCommand { public class Condense extends SubCommand {
public static boolean TASK = false; public static boolean TASK = false;
@ -43,6 +39,10 @@ public class Condense extends SubCommand {
super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false); super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false);
} }
public static void sendMessage(final String message) {
PlotSquared.log("&3PlotSquared -> Plot condense&8: &7" + message);
}
@Override @Override
public boolean execute(final PlotPlayer plr, final String... args) { public boolean execute(final PlotPlayer plr, final String... args) {
if (plr != null) { if (plr != null) {
@ -54,7 +54,7 @@ public class Condense extends SubCommand {
return false; return false;
} }
final String worldname = args[0]; final String worldname = args[0];
if (!BlockManager.manager.isWorld(worldname) || !PlotSquared.isPlotWorld(worldname)) { if (!BlockManager.manager.isWorld(worldname) || !PlotSquared.getInstance().isPlotWorld(worldname)) {
MainUtil.sendMessage(plr, "INVALID WORLD"); MainUtil.sendMessage(plr, "INVALID WORLD");
return false; return false;
} }
@ -199,8 +199,4 @@ public class Condense extends SubCommand {
} }
return outside; return outside;
} }
public static void sendMessage(final String message) {
PlotSquared.log("&3PlotSquared -> Plot condense&8: &7" + message);
}
} }

View File

@ -41,7 +41,7 @@ public class CreateRoadSchematic extends SubCommand {
if (plot == null) { if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT); return sendMessage(player, C.NOT_IN_PLOT);
} }
if (!(PlotSquared.getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) { if (!(PlotSquared.getInstance().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD); return sendMessage(player, C.NOT_IN_PLOT_WORLD);
} }
HybridUtils.manager.setupRoadSchematic(plot); HybridUtils.manager.setupRoadSchematic(plot);

View File

@ -1,10 +1,5 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.MySQL;
@ -16,6 +11,11 @@ import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.UUID;
/** /**
* Created 2014-11-15 for PlotSquared * Created 2014-11-15 for PlotSquared
* *
@ -41,7 +41,7 @@ public class Database extends SubCommand {
} }
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) { public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
final java.util.Set<Plot> plots = PlotSquared.getPlots(); final java.util.Set<Plot> plots = PlotSquared.getInstance().getPlots();
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -51,7 +51,7 @@ public class Debug extends SubCommand {
} }
{ {
final StringBuilder worlds = new StringBuilder(""); final StringBuilder worlds = new StringBuilder("");
for (final String world : PlotSquared.getPlotWorlds()) { for (final String world : PlotSquared.getInstance().getPlotWorlds()) {
worlds.append(world).append(" "); worlds.append(world).append(" ");
} }
information.append(header); information.append(header);
@ -61,7 +61,7 @@ public class Debug extends SubCommand {
information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%")); information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%"));
information.append(getSection(section, "PlotWorld")); information.append(getSection(section, "PlotWorld"));
information.append(getLine(line, "Plot Worlds", worlds)); information.append(getLine(line, "Plot Worlds", worlds));
information.append(getLine(line, "Owned Plots", PlotSquared.getPlots().size())); information.append(getLine(line, "Owned Plots", PlotSquared.getInstance().getPlots().size()));
information.append(getSection(section, "Messages")); information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages", C.values().length)); information.append(getLine(line, "Total Messages", C.values().length));
information.append(getLine(line, "View all captions", "/plot debug msg")); information.append(getLine(line, "View all captions", "/plot debug msg"));

View File

@ -20,27 +20,20 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.UUID;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.ArrayList;
import java.util.UUID;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
@ -73,7 +66,7 @@ public class DebugClaimTest extends SubCommand {
return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}"); return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
} }
final String world = args[0]; final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) { if (!BlockManager.manager.isWorld(world) || !PlotSquared.getInstance().isPlotWorld(world)) {
return !MainUtil.sendMessage(null, "&cInvalid plot world!"); return !MainUtil.sendMessage(null, "&cInvalid plot world!");
} }
PlotId min, max; PlotId min, max;
@ -87,12 +80,12 @@ public class DebugClaimTest extends SubCommand {
} }
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while..."); MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)"); MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final ArrayList<Plot> plots = new ArrayList<>(); final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) { for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
final Plot plot = MainUtil.getPlot(world, id); final Plot plot = MainUtil.getPlot(world, id);
final boolean contains = PlotSquared.getPlots(world).containsKey(plot.id); final boolean contains = PlotSquared.getInstance().getPlots(world).containsKey(plot.id);
if (contains) { if (contains) {
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id); MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
continue; continue;
@ -141,7 +134,7 @@ public class DebugClaimTest extends SubCommand {
} }
}); });
for (final Plot plot : plots) { for (final Plot plot : plots) {
PlotSquared.updatePlot(plot); PlotSquared.getInstance().updatePlot(plot);
} }
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!"); MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
} else { } else {

View File

@ -49,7 +49,7 @@ public class DebugClear extends SubCommand {
if (id == null) { if (id == null) {
PlotSquared.log("Invalid Plot ID: " + args[0]); PlotSquared.log("Invalid Plot ID: " + args[0]);
} else { } else {
if (!PlotSquared.isPlotWorld(world) || !(PlotSquared.getPlotWorld(world) instanceof SquarePlotWorld)) { if (!PlotSquared.getInstance().isPlotWorld(world) || !(PlotSquared.getInstance().getPlotWorld(world) instanceof SquarePlotWorld)) {
PlotSquared.log("Invalid plot world: " + world); PlotSquared.log("Invalid plot world: " + world);
} else { } else {
final Plot plot = MainUtil.getPlot(world, id); final Plot plot = MainUtil.getPlot(world, id);
@ -79,7 +79,7 @@ public class DebugClear extends SubCommand {
} }
final Location loc = plr.getLocation(); final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc); final Plot plot = MainUtil.getPlot(loc);
if ((plot == null) || !(PlotSquared.getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) { if ((plot == null) || !(PlotSquared.getInstance().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
return sendMessage(plr, C.NOT_IN_PLOT); return sendMessage(plr, C.NOT_IN_PLOT);
} }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {

View File

@ -20,38 +20,26 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue;
import com.intellectualcrafters.plot.flag.FlagValue.IntegerListValue;
import com.intellectualcrafters.plot.generator.BukkitHybridUtils; import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.*;
public class DebugExec extends SubCommand { public class DebugExec extends SubCommand {
public DebugExec() { public DebugExec() {
@ -60,7 +48,7 @@ public class DebugExec extends SubCommand {
@Override @Override
public boolean execute(final PlotPlayer player, final String... args) { public boolean execute(final PlotPlayer player, final String... args) {
final List<String> allowed_params = Arrays.asList(new String[] { "analyze", "reset-modified", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check" }); final List<String> allowed_params = Arrays.asList("analyze", "reset-modified", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
if (args.length > 0) { if (args.length > 0) {
final String arg = args[0].toLowerCase(); final String arg = args[0].toLowerCase();
switch (arg) { switch (arg) {
@ -70,13 +58,13 @@ public class DebugExec extends SubCommand {
@Override @Override
public void run() { public void run() {
List<Double> result = new ArrayList<>(); List<Double> result = new ArrayList<>();
result.add((double) (Math.round(value.air * 100) / 100d)); result.add(Math.round(value.air * 100) / 100d);
result.add((double) (Math.round(value.changes * 100) / 100d)); result.add(Math.round(value.changes * 100) / 100d);
result.add((double) (Math.round(value.complexity * 100) / 100d)); result.add(Math.round(value.complexity * 100) / 100d);
result.add((double) (Math.round(value.data * 100) / 100d)); result.add(Math.round(value.data * 100) / 100d);
result.add((double) (Math.round(value.faces * 100) / 100d)); result.add(Math.round(value.faces * 100) / 100d);
result.add((double) (Math.round(value.air * 100) / 100d)); result.add(Math.round(value.air * 100) / 100d);
result.add((double) (Math.round(value.variety * 100) / 100d)); result.add(Math.round(value.variety * 100) / 100d);
Flag flag = new Flag(FlagManager.getFlag("analysis"), result); Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
FlagManager.addPlotFlag(plot, flag); FlagManager.addPlotFlag(plot, flag);
} }
@ -98,7 +86,7 @@ public class DebugExec extends SubCommand {
return false; return false;
} }
String flag = args[1]; String flag = args[1];
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getInstance().getPlots()) {
if (FlagManager.getPlotFlag(plot, flag) != null) { if (FlagManager.getPlotFlag(plot, flag) != null) {
FlagManager.removePlotFlag(plot, flag); FlagManager.removePlotFlag(plot, flag);
} }
@ -111,7 +99,7 @@ public class DebugExec extends SubCommand {
return false; return false;
} }
boolean result; boolean result;
if (!PlotSquared.isPlotWorld(args[1])) { if (!PlotSquared.getInstance().isPlotWorld(args[1])) {
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]); MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
return false; return false;
} }
@ -138,7 +126,7 @@ public class DebugExec extends SubCommand {
while (BukkitHybridUtils.chunks.size() > 0) { while (BukkitHybridUtils.chunks.size() > 0) {
ChunkLoc chunk = BukkitHybridUtils.chunks.get(0); ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
BukkitHybridUtils.chunks.remove(0); BukkitHybridUtils.chunks.remove(0);
((BukkitHybridUtils)(HybridUtils.manager)).regenerateRoad(BukkitHybridUtils.world, chunk, 0); HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk); ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk);
} }
PlotSquared.log("&cCancelled!"); PlotSquared.log("&cCancelled!");
@ -209,7 +197,7 @@ public class DebugExec extends SubCommand {
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run"); return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
} }
final String world = args[1]; final String world = args[1];
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(args[1])) { if (!BlockManager.manager.isWorld(world) || !PlotSquared.getInstance().isPlotWorld(args[1])) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]); return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
} }
final ArrayList<ChunkLoc> empty = new ArrayList<>(); final ArrayList<ChunkLoc> empty = new ArrayList<>();

View File

@ -20,16 +20,9 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -37,6 +30,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
public class DebugFixFlags extends SubCommand { public class DebugFixFlags extends SubCommand {
public DebugFixFlags() { public DebugFixFlags() {
super(Command.DEBUGFIXFLAGS, "Attempt to fix all flags for a world", "debugclear", CommandCategory.DEBUG, false); super(Command.DEBUGFIXFLAGS, "Attempt to fix all flags for a world", "debugclear", CommandCategory.DEBUG, false);
@ -53,12 +50,12 @@ public class DebugFixFlags extends SubCommand {
return false; return false;
} }
final String world = args[0]; final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) { if (!BlockManager.manager.isWorld(world) || !PlotSquared.getInstance().isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]); MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
return false; return false;
} }
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---"); MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
for (final Plot plot : PlotSquared.getPlots(world).values()) { for (final Plot plot : PlotSquared.getInstance().getPlots(world).values()) {
final HashMap<String, Flag> flags = plot.settings.flags; final HashMap<String, Flag> flags = plot.settings.flags;
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator(); Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
boolean changed = false; boolean changed = false;

View File

@ -38,7 +38,7 @@ public class DebugRoadRegen extends SubCommand {
public boolean execute(final PlotPlayer player, final String... args) { public boolean execute(final PlotPlayer player, final String... args) {
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final String world = loc.getWorld(); final String world = loc.getWorld();
if (!(PlotSquared.getPlotWorld(world) instanceof HybridPlotWorld)) { if (!(PlotSquared.getInstance().getPlotWorld(world) instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD); return sendMessage(player, C.NOT_IN_PLOT_WORLD);
} }
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);

View File

@ -20,14 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import java.util.ArrayList;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
@ -40,7 +40,7 @@ public class DebugSaveTest extends SubCommand {
public boolean execute(final PlotPlayer plr, final String... args) { public boolean execute(final PlotPlayer plr, final String... args) {
if (plr == null) { if (plr == null) {
final ArrayList<Plot> plots = new ArrayList<Plot>(); final ArrayList<Plot> plots = new ArrayList<Plot>();
plots.addAll(PlotSquared.getPlots()); plots.addAll(PlotSquared.getInstance().getPlots());
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`"); MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
DBFunc.createPlotsAndData(plots, new Runnable() { DBFunc.createPlotsAndData(plots, new Runnable() {
@Override @Override

View File

@ -20,16 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -47,6 +37,15 @@ import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import org.bukkit.Bukkit;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
public class DebugUUID extends SubCommand { public class DebugUUID extends SubCommand {
public DebugUUID() { public DebugUUID() {
@ -216,7 +215,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendConsoleMessage("&7 - Updating plot objects"); MainUtil.sendConsoleMessage("&7 - Updating plot objects");
for (Plot plot : PlotSquared.getPlotsRaw()) { for (Plot plot : PlotSquared.getInstance().getPlotsRaw()) {
UUID value = uCMap.get(plot.owner); UUID value = uCMap.get(plot.owner);
if (value != null) { if (value != null) {
plot.owner = value; plot.owner = value;
@ -236,13 +235,13 @@ public class DebugUUID extends SubCommand {
database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite"); database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite");
if (!result) { if (!result) {
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery"); MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getInstance().getPlots()) {
UUID value = uCReverse.get(plot.owner); UUID value = uCReverse.get(plot.owner);
if (value != null) { if (value != null) {
plot.owner = value; plot.owner = value;
} }
} }
database.createPlotsAndData(new ArrayList<>(PlotSquared.getPlots()), new Runnable() { database.createPlotsAndData(new ArrayList<>(PlotSquared.getInstance().getPlots()), new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(null, "&6Recovery was successful!"); MainUtil.sendMessage(null, "&6Recovery was successful!");
@ -280,7 +279,7 @@ public class DebugUUID extends SubCommand {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots()); ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getInstance().getPlots());
database.createPlotsAndData(plots, new Runnable() { database.createPlotsAndData(plots, new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -28,11 +28,7 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class Delete extends SubCommand { public class Delete extends SubCommand {
@ -54,7 +50,7 @@ public class Delete extends SubCommand {
return !sendMessage(plr, C.NO_PLOT_PERMS); return !sendMessage(plr, C.NO_PLOT_PERMS);
} }
assert plot != null; assert plot != null;
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world); final PlotWorld pWorld = PlotSquared.getInstance().getPlotWorld(plot.world);
if (MainUtil.runners.containsKey(plot)) { if (MainUtil.runners.containsKey(plot)) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false; return false;
@ -69,7 +65,7 @@ public class Delete extends SubCommand {
sendMessage(plr, C.ADDED_BALANCE, c + ""); sendMessage(plr, C.ADDED_BALANCE, c + "");
} }
} }
PlotSquared.removePlot(loc.getWorld(), plot.id, true); PlotSquared.getInstance().removePlot(loc.getWorld(), plot.id, true);
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() { final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
@Override @Override

View File

@ -20,14 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import java.util.ArrayList;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
@ -37,7 +37,7 @@ public class Home extends SubCommand {
} }
private Plot isAlias(final String a) { private Plot isAlias(final String a) {
for (final Plot p : PlotSquared.getPlots()) { for (final Plot p : PlotSquared.getInstance().getPlots()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) { if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
return p; return p;
} }
@ -47,7 +47,7 @@ public class Home extends SubCommand {
@Override @Override
public boolean execute(final PlotPlayer plr, String... args) { public boolean execute(final PlotPlayer plr, String... args) {
final ArrayList<Plot> plots = PlotSquared.sortPlotsByWorld(PlotSquared.getPlots(plr)); final ArrayList<Plot> plots = PlotSquared.getInstance().sortPlotsByWorld(PlotSquared.getInstance().getPlots(plr));
if (plots.size() == 1) { if (plots.size() == 1) {
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0)); MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
return true; return true;

View File

@ -20,26 +20,17 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
@ -172,7 +163,7 @@ public class Merge extends SubCommand {
sendMessage(accepter, C.MERGE_NOT_VALID); sendMessage(accepter, C.MERGE_NOT_VALID);
return; return;
} }
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world); final PlotWorld plotWorld = PlotSquared.getInstance().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) { if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE; double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost; cost = plots.size() * cost;
@ -201,7 +192,7 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.MERGE_REQUESTED); MainUtil.sendMessage(plr, C.MERGE_REQUESTED);
return true; return true;
} }
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world); final PlotWorld plotWorld = PlotSquared.getInstance().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) { if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE; double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost; cost = plots.size() * cost;

View File

@ -22,11 +22,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
@ -65,12 +61,12 @@ public class Move extends SubCommand {
} }
String world2; String world2;
if (args.length == 2) { if (args.length == 2) {
PlotWorld other = PlotSquared.getPlotWorld(args[1]); PlotWorld other = PlotSquared.getInstance().getPlotWorld(args[1]);
PlotWorld current = PlotSquared.getPlotWorld(loc.getWorld()); PlotWorld current = PlotSquared.getInstance().getPlotWorld(loc.getWorld());
if (other == null || current == null || !other.equals(current)) { if (other == null || current == null || !other.equals(current)) {
MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE); MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE);
return false; return false;
} }
world2 = other.worldname; world2 = other.worldname;
} }
else { else {

View File

@ -20,11 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -34,6 +29,11 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@SuppressWarnings({ "javadoc" }) @SuppressWarnings({ "javadoc" })
public class Purge extends SubCommand { public class Purge extends SubCommand {
public Purge() { public Purge() {
@ -91,7 +91,7 @@ public class Purge extends SubCommand {
return false; return false;
} }
final String worldname = args[1]; final String worldname = args[1];
if (!PlotSquared.getAllPlotsRaw().containsKey(worldname)) { if (!PlotSquared.getInstance().getAllPlotsRaw().containsKey(worldname)) {
MainUtil.sendMessage(plr, "INVALID WORLD"); MainUtil.sendMessage(plr, "INVALID WORLD");
return false; return false;
} }
@ -107,7 +107,7 @@ public class Purge extends SubCommand {
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0); return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
} }
if (arg.equals("all")) { if (arg.equals("all")) {
final Set<PlotId> ids = PlotSquared.getPlots(worldname).keySet(); final Set<PlotId> ids = PlotSquared.getInstance().getPlots(worldname).keySet();
int length = ids.size(); int length = ids.size();
if (length == 0) { if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found"); return MainUtil.sendMessage(null, "&cNo plots found");
@ -116,7 +116,7 @@ public class Purge extends SubCommand {
return finishPurge(length); return finishPurge(length);
} }
if (arg.equals("unknown")) { if (arg.equals("unknown")) {
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values(); final Collection<Plot> plots = PlotSquared.getInstance().getPlots(worldname).values();
final Set<PlotId> ids = new HashSet<>(); final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) { for (final Plot plot : plots) {
if (plot.owner != null) { if (plot.owner != null) {
@ -134,7 +134,7 @@ public class Purge extends SubCommand {
return finishPurge(length); return finishPurge(length);
} }
if (arg.equals("unowned")) { if (arg.equals("unowned")) {
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values(); final Collection<Plot> plots = PlotSquared.getInstance().getPlots(worldname).values();
final Set<PlotId> ids = new HashSet<>(); final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) { for (final Plot plot : plots) {
if (plot.owner == null) { if (plot.owner == null) {
@ -150,7 +150,7 @@ public class Purge extends SubCommand {
} }
final UUID uuid = UUIDHandler.getUUID(args[0]); final UUID uuid = UUIDHandler.getUUID(args[0]);
if (uuid != null) { if (uuid != null) {
final Set<Plot> plots = PlotSquared.getPlots(worldname, uuid); final Set<Plot> plots = PlotSquared.getInstance().getPlots(worldname, uuid);
final Set<PlotId> ids = new HashSet<>(); final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) { for (final Plot plot : plots) {
ids.add(plot.id); ids.add(plot.id);

View File

@ -20,8 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.List;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotManager;
@ -31,6 +29,8 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import java.util.List;
public class RegenAllRoads extends SubCommand { public class RegenAllRoads extends SubCommand {
public RegenAllRoads() { public RegenAllRoads() {
super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false); super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false);
@ -58,7 +58,7 @@ public class RegenAllRoads extends SubCommand {
} }
} }
final String name = args[0]; final String name = args[0];
final PlotManager manager = PlotSquared.getPlotManager(name); final PlotManager manager = PlotSquared.getInstance().getPlotManager(name);
if ((manager == null) || !(manager instanceof HybridPlotManager)) { if ((manager == null) || !(manager instanceof HybridPlotManager)) {
sendMessage(player, C.NOT_VALID_PLOT_WORLD); sendMessage(player, C.NOT_VALID_PLOT_WORLD);
return false; return false;

View File

@ -37,10 +37,10 @@ public class Reload extends SubCommand {
// The following won't affect world generation, as that has to be // The following won't affect world generation, as that has to be
// loaded during startup unfortunately. // loaded during startup unfortunately.
PlotSquared.config.load(PlotSquared.configFile); PlotSquared.config.load(PlotSquared.configFile);
PlotSquared.setupConfig(); PlotSquared.getInstance().setupConfig();
C.setupTranslations(); C.setupTranslations();
for (final String pw : PlotSquared.getPlotWorlds()) { for (final String pw : PlotSquared.getInstance().getPlotWorlds()) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(pw); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(pw);
plotworld.loadDefaultConfiguration(PlotSquared.config.getConfigurationSection("worlds." + pw)); plotworld.loadDefaultConfiguration(PlotSquared.config.getConfigurationSection("worlds." + pw));
} }
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS); MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);

View File

@ -20,26 +20,22 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection; import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
public class SchematicCmd extends SubCommand { public class SchematicCmd extends SubCommand {
private int counter = 0; private int counter = 0;
private boolean running = false; private boolean running = false;
@ -202,7 +198,7 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>"); MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
return false; return false;
} }
final HashMap<PlotId, Plot> plotmap = PlotSquared.getPlots(args[1]); final HashMap<PlotId, Plot> plotmap = PlotSquared.getInstance().getPlots(args[1]);
if ((plotmap == null) || (plotmap.size() == 0)) { if ((plotmap == null) || (plotmap.size() == 0)) {
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>"); MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
return false; return false;
@ -254,11 +250,11 @@ public class SchematicCmd extends SubCommand {
world = args[1]; world = args[1];
final String[] split = args[2].split(";"); final String[] split = args[2].split(";");
final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
if ((PlotSquared.getPlots(world) == null) || (PlotSquared.getPlots(world).get(i) == null)) { if ((PlotSquared.getInstance().getPlots(world) == null) || (PlotSquared.getInstance().getPlots(world).get(i) == null)) {
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>"); MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
return false; return false;
} }
p2 = PlotSquared.getPlots(world).get(i); p2 = PlotSquared.getInstance().getPlots(world).get(i);
} catch (final Exception e) { } catch (final Exception e) {
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>"); MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
return false; return false;

View File

@ -20,12 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
@ -33,22 +27,15 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue.PlotBlockListValue;
import com.intellectualcrafters.plot.listeners.APlotListener; import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** /**
* @author Citymonstret * @author Citymonstret
@ -79,10 +66,10 @@ public class Set extends SubCommand {
} }
} }
if (args.length < 1) { if (args.length < 1) {
PlotManager manager = PlotSquared.getPlotManager(loc.getWorld()); PlotManager manager = PlotSquared.getInstance().getPlotManager(loc.getWorld());
ArrayList<String> newValues = new ArrayList<String>(); ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values)); newValues.addAll(Arrays.asList(values));
newValues.addAll(Arrays.asList(manager.getPlotComponents(PlotSquared.getPlotWorld(loc.getWorld()), plot.id))); newValues.addAll(Arrays.asList(manager.getPlotComponents(PlotSquared.getInstance().getPlotWorld(loc.getWorld()), plot.id)));
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues)); MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false; return false;
} }
@ -184,7 +171,7 @@ public class Set extends SubCommand {
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG); MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
return false; return false;
} }
for (final Plot p : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) { for (final Plot p : PlotSquared.getInstance().getPlots(plr.getLocation().getWorld()).values()) {
if (p.settings.getAlias().equalsIgnoreCase(alias)) { if (p.settings.getAlias().equalsIgnoreCase(alias)) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false; return false;
@ -230,8 +217,8 @@ public class Set extends SubCommand {
} }
// Get components // Get components
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final String[] components = manager.getPlotComponents(plotworld, plot.id); final String[] components = manager.getPlotComponents(plotworld, plot.id);
for (final String component : components) { for (final String component : components) {
if (component.equalsIgnoreCase(args[0])) { if (component.equalsIgnoreCase(args[0])) {
@ -321,7 +308,7 @@ public class Set extends SubCommand {
} }
ArrayList<String> newValues = new ArrayList<String>(); ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values)); newValues.addAll(Arrays.asList(values));
newValues.addAll(Arrays.asList(manager.getPlotComponents(PlotSquared.getPlotWorld(loc.getWorld()), plot.id))); newValues.addAll(Arrays.asList(manager.getPlotComponents(PlotSquared.getInstance().getPlotWorld(loc.getWorld()), plot.id)));
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues)); MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false; return false;
} }

View File

@ -20,9 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -35,6 +32,9 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.ArrayList;
import java.util.UUID;
public class SetOwner extends SubCommand { public class SetOwner extends SubCommand {
public SetOwner() { public SetOwner() {
super("setowner", "plots.set.owner", "Set the plot owner", "setowner <player>", "so", CommandCategory.ACTIONS, true); super("setowner", "plots.set.owner", "Set the plot owner", "setowner <player>", "so", CommandCategory.ACTIONS, true);
@ -93,14 +93,14 @@ public class SetOwner extends SubCommand {
final String world = loc.getWorld(); final String world = loc.getWorld();
for (final PlotId id : plots) { for (final PlotId id : plots) {
final Plot current = PlotSquared.getPlots(world).get(id); final Plot current = PlotSquared.getInstance().getPlots(world).get(id);
final UUID uuid = getUUID(args[0]); final UUID uuid = getUUID(args[0]);
if (uuid == null) { if (uuid == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
current.owner = uuid; current.owner = uuid;
PlotSquared.updatePlot(current); PlotSquared.getInstance().updatePlot(current);
DBFunc.setOwner(current, current.owner); DBFunc.setOwner(current, current.owner);
} }
MainUtil.setSign(args[0], plot); MainUtil.setSign(args[0], plot);

View File

@ -20,8 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -31,6 +29,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.apache.commons.lang.StringUtils;
/** /**
* @author Citymonstret * @author Citymonstret
@ -56,7 +55,7 @@ public class TP extends SubCommand {
world = args[1]; world = args[1];
} }
} }
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false; return false;
} }
@ -86,7 +85,7 @@ public class TP extends SubCommand {
} }
final PlotPlayer player = UUIDHandler.getPlayer(a); final PlotPlayer player = UUIDHandler.getPlayer(a);
if (player != null) { if (player != null) {
final java.util.Set<Plot> plotMainPlots = PlotSquared.getPlots(world, player); final java.util.Set<Plot> plotMainPlots = PlotSquared.getInstance().getPlots(world, player);
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]); final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
if (plots.length > index) { if (plots.length > index) {
return plots[index]; return plots[index];

View File

@ -35,7 +35,7 @@ public class Target extends SubCommand {
@Override @Override
public boolean execute(final PlotPlayer plr, final String... args) { public boolean execute(final PlotPlayer plr, final String... args) {
final Location ploc = plr.getLocation(); final Location ploc = plr.getLocation();
if (!PlotSquared.isPlotWorld(ploc.getWorld())) { if (!PlotSquared.getInstance().isPlotWorld(ploc.getWorld())) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false; return false;
} }

View File

@ -20,6 +20,17 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -29,125 +40,11 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
public class Template extends SubCommand { public class Template extends SubCommand {
public Template() { public Template() {
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false); super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false);
} }
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
if (args.length != 2 && args.length != 3) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("export")) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false;
}
else if (args[0].equalsIgnoreCase("import")) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false;
}
}
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world> [template]");
return false;
}
final String world = args[1];
switch (args[0].toLowerCase()) {
case "import": {
if (args.length != 3) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false;
}
if (PlotSquared.isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return false;
}
boolean result = extractAllFiles(world, args[2]);
if (!result) {
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] +".template");
return false;
}
File worldFile = new File(PlotSquared.IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
PlotSquared.config.set("worlds." + world, worldConfig.get(""));
try {
PlotSquared.config.save(PlotSquared.configFile);
PlotSquared.config.load(PlotSquared.configFile);
} catch (Exception e) {
e.printStackTrace();
}
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
generator = manager;
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
setup.terrain = terrain;
setup.step = new ConfigurationNode[0];
setup.world = world;
SetupUtils.manager.setupWorld(setup);
MainUtil.sendMessage(plr, "Done!");
if (plr != null) {
plr.teleport(BlockManager.manager.getSpawn(world));
}
return true;
}
case "export": {
if (args.length != 2) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false;
}
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
final PlotManager manager = PlotSquared.getPlotManager(world);
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
manager.exportTemplate(plotworld);
}
catch (Exception e) {
e.printStackTrace();
MainUtil.sendMessage(plr, "Failed: " + e.getMessage());
return;
}
MainUtil.sendMessage(plr, "Done!");
}
});
return true;
}
}
return true;
}
public static boolean extractAllFiles(String world, String template) { public static boolean extractAllFiles(String world, String template) {
byte[] buffer = new byte[2048]; byte[] buffer = new byte[2048];
try { try {
@ -155,7 +52,7 @@ public class Template extends SubCommand {
if (!folder.exists()) { if (!folder.exists()) {
return false; return false;
} }
File input = new File(folder + File.separator + template +".template"); File input = new File(folder + File.separator + template + ".template");
File output = PlotSquared.IMP.getDirectory(); File output = PlotSquared.IMP.getDirectory();
if (!output.exists()) { if (!output.exists()) {
output.mkdirs(); output.mkdirs();
@ -210,4 +107,102 @@ public class Template extends SubCommand {
zos.closeEntry(); zos.closeEntry();
zos.close(); zos.close();
} }
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
if (args.length != 2 && args.length != 3) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("export")) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false;
}
else if (args[0].equalsIgnoreCase("import")) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false;
}
}
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world> [template]");
return false;
}
final String world = args[1];
switch (args[0].toLowerCase()) {
case "import": {
if (args.length != 3) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false;
}
if (PlotSquared.getInstance().isPlotWorld(world)) {
MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return false;
}
boolean result = extractAllFiles(world, args[2]);
if (!result) {
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] +".template");
return false;
}
File worldFile = new File(PlotSquared.IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
PlotSquared.config.set("worlds." + world, worldConfig.get(""));
try {
PlotSquared.config.save(PlotSquared.configFile);
PlotSquared.config.load(PlotSquared.configFile);
} catch (Exception e) {
e.printStackTrace();
}
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
generator = manager;
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
setup.terrain = terrain;
setup.step = new ConfigurationNode[0];
setup.world = world;
SetupUtils.manager.setupWorld(setup);
MainUtil.sendMessage(plr, "Done!");
if (plr != null) {
plr.teleport(BlockManager.manager.getSpawn(world));
}
return true;
}
case "export": {
if (args.length != 2) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false;
}
final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
manager.exportTemplate(plotworld);
}
catch (Exception e) {
e.printStackTrace();
MainUtil.sendMessage(plr, "Failed: " + e.getMessage());
return;
}
MainUtil.sendMessage(plr, "Done!");
}
});
return true;
}
}
return true;
}
} }

View File

@ -20,6 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -28,84 +36,15 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
public class Trim extends SubCommand { public class Trim extends SubCommand {
public static boolean TASK = false; public static boolean TASK = false;
public static ArrayList<Plot> expired = null;
private static int TASK_ID = 0; private static int TASK_ID = 0;
public Trim() { public Trim() {
super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false); super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false);
} }
public PlotId getId(final String id) {
try {
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
return null;
}
}
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
if (plr != null) {
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
return false;
}
if (args.length == 1) {
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
return false;
}
if (arg.equals("all")) {
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
if (args.length != 2) {
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String arg = args[0].toLowerCase();
if (!arg.equals("all")) {
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String world = args[1];
if (!BlockManager.manager.isWorld(world) || (PlotSquared.getPlotWorld(world) == null)) {
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
return false;
}
if (Trim.TASK) {
sendMessage(C.TRIM_IN_PROGRESS.s());
return false;
}
sendMessage(C.TRIM_START.s());
final ArrayList<ChunkLoc> empty = new ArrayList<>();
getTrimRegions(empty, world, new Runnable() {
@Override
public void run() {
deleteChunks(world, empty);
}
});
return true;
}
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) { public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
if (Trim.TASK) { if (Trim.TASK) {
return false; return false;
@ -167,7 +106,7 @@ public class Trim extends SubCommand {
System.currentTimeMillis(); System.currentTimeMillis();
sendMessage("Collecting region data..."); sendMessage("Collecting region data...");
final ArrayList<Plot> plots = new ArrayList<>(); final ArrayList<Plot> plots = new ArrayList<>();
plots.addAll(PlotSquared.getPlots(world).values()); plots.addAll(PlotSquared.getInstance().getPlots(world).values());
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
sendMessage(" - MCA #: " + chunks.size()); sendMessage(" - MCA #: " + chunks.size());
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)"); sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
@ -201,8 +140,6 @@ public class Trim extends SubCommand {
return true; return true;
} }
public static ArrayList<Plot> expired = null;
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) { public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
ChunkManager.manager.deleteRegionFiles(world, chunks); ChunkManager.manager.deleteRegionFiles(world, chunks);
} }
@ -210,4 +147,62 @@ public class Trim extends SubCommand {
public static void sendMessage(final String message) { public static void sendMessage(final String message) {
PlotSquared.log("&3PlotSquared -> World trim&8: &7" + message); PlotSquared.log("&3PlotSquared -> World trim&8: &7" + message);
} }
public PlotId getId(final String id) {
try {
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
return null;
}
}
@Override
public boolean execute(final PlotPlayer plr, final String... args) {
if (plr != null) {
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
return false;
}
if (args.length == 1) {
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
return false;
}
if (arg.equals("all")) {
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
if (args.length != 2) {
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String arg = args[0].toLowerCase();
if (!arg.equals("all")) {
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String world = args[1];
if (!BlockManager.manager.isWorld(world) || (PlotSquared.getInstance().getPlotWorld(world) == null)) {
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
return false;
}
if (Trim.TASK) {
sendMessage(C.TRIM_IN_PROGRESS.s());
return false;
}
sendMessage(C.TRIM_START.s());
final ArrayList<ChunkLoc> empty = new ArrayList<>();
getTrimRegions(empty, world, new Runnable() {
@Override
public void run() {
deleteChunks(world, empty);
}
});
return true;
}
} }

View File

@ -20,8 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -33,6 +31,8 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.UUID;
public class Trust extends SubCommand { public class Trust extends SubCommand {
public Trust() { public Trust() {
super(Command.TRUST, "Allow a player to build in a plot", "trust <player>", CommandCategory.ACTIONS, true); super(Command.TRUST, "Allow a player to build in a plot", "trust <player>", CommandCategory.ACTIONS, true);
@ -77,7 +77,7 @@ public class Trust extends SubCommand {
DBFunc.removeMember(loc.getWorld(), plot, uuid); DBFunc.removeMember(loc.getWorld(), plot, uuid);
} }
if (plot.denied.contains(uuid)) { if (plot.denied.contains(uuid)) {
if (plot.members.size() + plot.trusted.size() >= PlotSquared.getPlotWorld(plot.world).MAX_PLOT_MEMBERS) { if (plot.members.size() + plot.trusted.size() >= PlotSquared.getInstance().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; return false;
} }
@ -91,7 +91,7 @@ public class Trust extends SubCommand {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false; return false;
} }
if (plot.members.size() + plot.trusted.size() >= PlotSquared.getPlotWorld(plot.world).MAX_PLOT_MEMBERS) { if (plot.members.size() + plot.trusted.size() >= PlotSquared.getInstance().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false; return false;
} }

View File

@ -50,7 +50,7 @@ public class Unclaim extends SubCommand {
return !sendMessage(plr, C.NO_PLOT_PERMS); return !sendMessage(plr, C.NO_PLOT_PERMS);
} }
assert plot != null; assert plot != null;
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world); final PlotWorld pWorld = PlotSquared.getInstance().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
final double c = pWorld.SELL_PRICE; final double c = pWorld.SELL_PRICE;
if (c > 0d) { if (c > 0d) {
@ -58,10 +58,10 @@ public class Unclaim extends SubCommand {
sendMessage(plr, C.ADDED_BALANCE, c + ""); sendMessage(plr, C.ADDED_BALANCE, c + "");
} }
} }
final boolean result = PlotSquared.removePlot(loc.getWorld(), plot.id, true); final boolean result = PlotSquared.getInstance().removePlot(loc.getWorld(), plot.id, true);
if (result) { if (result) {
final String worldname = plr.getLocation().getWorld(); final String worldname = plr.getLocation().getWorld();
PlotSquared.getPlotManager(worldname).unclaimPlot(pWorld, plot); PlotSquared.getInstance().getPlotManager(worldname).unclaimPlot(pWorld, plot);
DBFunc.delete(worldname, plot); DBFunc.delete(worldname, plot);
// TODO set wall block // TODO set wall block
} else { } else {

View File

@ -20,19 +20,18 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Visit extends SubCommand { public class Visit extends SubCommand {
public Visit() { public Visit() {
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true); super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true);
@ -40,7 +39,7 @@ public class Visit extends SubCommand {
public List<Plot> getPlots(final UUID uuid) { public List<Plot> getPlots(final UUID uuid) {
final List<Plot> plots = new ArrayList<>(); final List<Plot> plots = new ArrayList<>();
for (final Plot p : PlotSquared.getPlots()) { for (final Plot p : PlotSquared.getInstance().getPlots()) {
if (p.hasOwner() && p.isOwner(uuid)) { if (p.hasOwner() && p.isOwner(uuid)) {
plots.add(p); plots.add(p);
} }
@ -57,11 +56,10 @@ public class Visit extends SubCommand {
UUID user = UUIDHandler.getUUID(args[0]); UUID user = UUIDHandler.getUUID(args[0]);
if (user != null ) { if (user != null ) {
// do plots by username // do plots by username
plots.addAll(PlotSquared.getPlots(user)); plots.addAll(PlotSquared.getInstance().getPlots(user));
} } else if (PlotSquared.getInstance().isPlotWorld(args[0])) {
else if (PlotSquared.isPlotWorld(args[0])) {
// do plots by world // do plots by world
plots.addAll(PlotSquared.getPlots(args[0]).values()); plots.addAll(PlotSquared.getInstance().getPlots(args[0]).values());
} }
else { else {
Plot plot = MainUtil.getPlotFromString(plr, args[0], true); Plot plot = MainUtil.getPlotFromString(plr, args[0], true);

View File

@ -20,19 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -47,6 +34,12 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.util.bukkit.chat.FancyMessage; import com.intellectualcrafters.plot.util.bukkit.chat.FancyMessage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
/** /**
* @author Citymonstret * @author Citymonstret
@ -109,7 +102,7 @@ public class list extends SubCommand {
world = plr.getLocation().getWorld(); world = plr.getLocation().getWorld();
} }
else { else {
Set<String> worlds = PlotSquared.getPlotWorlds(); Set<String> worlds = PlotSquared.getInstance().getPlotWorlds();
if (worlds.size() == 0) { if (worlds.size() == 0) {
world = "world"; world = "world";
} }
@ -128,7 +121,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine");
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.getPlots(plr)); plots = new ArrayList<>(PlotSquared.getInstance().getPlots(plr));
break; break;
} }
case "shared": { case "shared": {
@ -140,7 +133,7 @@ public class list extends SubCommand {
return false; return false;
} }
plots = new ArrayList<Plot>(); plots = new ArrayList<Plot>();
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getInstance().getPlots()) {
if (plot.trusted.contains(plr.getUUID()) || plot.members.contains(plr.getUUID())) { if (plot.trusted.contains(plr.getUUID()) || plot.members.contains(plr.getUUID())) {
plots.add(plot); plots.add(plot);
} }
@ -156,7 +149,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.getPlots(world).values()); plots = new ArrayList<>(PlotSquared.getInstance().getPlots(world).values());
break; break;
} }
case "all": { case "all": {
@ -164,7 +157,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.all"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.all");
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.getPlots()); plots = new ArrayList<>(PlotSquared.getInstance().getPlots());
break; break;
} }
case "top": { case "top": {
@ -172,7 +165,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.top"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.top");
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.getPlots()); plots = new ArrayList<>(PlotSquared.getInstance().getPlots());
Collections.sort(plots, new Comparator<Plot>() { Collections.sort(plots, new Comparator<Plot>() {
@Override @Override
public int compare(Plot p1, Plot p2) { public int compare(Plot p1, Plot p2) {
@ -210,7 +203,7 @@ public class list extends SubCommand {
break; break;
} }
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getInstance().getPlots()) {
final Flag price = FlagManager.getPlotFlag(plot, "price"); final Flag price = FlagManager.getPlotFlag(plot, "price");
if (price != null) { if (price != null) {
plots.add(plot); plots.add(plot);
@ -224,7 +217,7 @@ public class list extends SubCommand {
return false; return false;
} }
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getInstance().getPlots()) {
if (plot.owner == null) { if (plot.owner == null) {
plots.add(plot); plots.add(plot);
} }
@ -237,7 +230,7 @@ public class list extends SubCommand {
return false; return false;
} }
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getInstance().getPlots()) {
if (plot.owner == null) { if (plot.owner == null) {
continue; continue;
} }
@ -248,7 +241,7 @@ public class list extends SubCommand {
break; break;
} }
default: { default: {
if (PlotSquared.isPlotWorld(args[0])) { if (PlotSquared.getInstance().isPlotWorld(args[0])) {
if (!Permissions.hasPermission(plr, "plots.list.world")) { if (!Permissions.hasPermission(plr, "plots.list.world")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
return false; return false;
@ -257,7 +250,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.getPlots(args[0]).values()); plots = new ArrayList<>(PlotSquared.getInstance().getPlots(args[0]).values());
break; break;
} }
UUID uuid = UUIDHandler.getUUID(args[0]); UUID uuid = UUIDHandler.getUUID(args[0]);
@ -266,7 +259,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player");
return false; return false;
} }
plots = new ArrayList<>(PlotSquared.getPlots(uuid)); plots = new ArrayList<>(PlotSquared.getInstance().getPlots(uuid));
break; break;
} }
} }
@ -288,10 +281,10 @@ public class list extends SubCommand {
public void displayPlots(PlotPlayer player, List<Plot> plots, int pageSize, int page, String world, String[] args, boolean sort) { public void displayPlots(PlotPlayer player, List<Plot> plots, int pageSize, int page, String world, String[] args, boolean sort) {
if (sort) { if (sort) {
if (world != null) { if (world != null) {
plots = PlotSquared.sortPlots(plots, world); plots = PlotSquared.getInstance().sortPlots(plots, world);
} }
else { else {
plots = PlotSquared.sortPlots(plots); plots = PlotSquared.getInstance().sortPlots(plots);
} }
} }
if (page < 0) { if (page < 0) {

View File

@ -20,40 +20,19 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
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.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import org.apache.commons.lang.StringUtils;
import org.bukkit.block.Biome;
import java.sql.*;
import java.util.*;
/** /**
* @author Citymonstret * @author Citymonstret
@ -71,10 +50,6 @@ public class SQLManager implements AbstractDB {
// Private Final // Private Final
private Connection connection; private Connection connection;
public Connection getConnection() {
return this.connection;
}
/** /**
* Constructor * Constructor
* *
@ -101,9 +76,8 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void run() { public void run() {
try { try {
SQLManager.this.connection = PlotSquared.getDatabase().forceConnection(); SQLManager.this.connection = PlotSquared.getInstance().getDatabase().forceConnection();
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -112,6 +86,10 @@ public class SQLManager implements AbstractDB {
updateTables(); updateTables();
} }
public Connection getConnection() {
return this.connection;
}
/** /**
* Set Plot owner * Set Plot owner
* *
@ -139,26 +117,6 @@ public class SQLManager implements AbstractDB {
}); });
} }
private class UUIDPair {
public final int id;
public final UUID uuid;
public UUIDPair(int id, UUID uuid) {
this.id = id;
this.uuid = uuid;
}
}
private class SettingsPair {
public final int id;
public final PlotSettings settings;
public SettingsPair(int id, PlotSettings settings) {
this.id = id;
this.settings = settings;
}
}
@Override @Override
public void createPlotsAndData(final ArrayList<Plot> myList, final Runnable whenDone) { public void createPlotsAndData(final ArrayList<Plot> myList, final Runnable whenDone) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@ -211,8 +169,7 @@ public class SQLManager implements AbstractDB {
createTiers(trusted, "trusted"); createTiers(trusted, "trusted");
createTiers(denied, "denied"); createTiers(denied, "denied");
TaskManager.runTaskLater(whenDone, 60); TaskManager.runTaskLater(whenDone, 60);
} } catch (SQLException e) {
catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots"); PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots");
} }
@ -235,7 +192,7 @@ public class SQLManager implements AbstractDB {
@Override @Override
public String getCreateSQLite(int size) { public String getCreateSQLite(int size) {
return getCreateSQLite(size, return getCreateSQLite(size,
"INSERT INTO `" + prefix + "plot_" + tier + "` SELECT ? AS `plot_plot_id`, ? AS `user_uuid`", 2); "INSERT INTO `" + prefix + "plot_" + tier + "` SELECT ? AS `plot_plot_id`, ? AS `user_uuid`", 2);
} }
@Override @Override
@ -324,10 +281,10 @@ public class SQLManager implements AbstractDB {
} }
public <T> void setBulk(ArrayList<T> objList, StmtMod<T> mod) { public <T> void setBulk(ArrayList<T> objList, StmtMod<T> mod) {
final int size = objList.size(); final int size = objList.size();
if (size == 0) { if (size == 0) {
return; return;
} }
int packet; int packet;
if (Settings.DB.USE_MYSQL) { if (Settings.DB.USE_MYSQL) {
packet = Math.min(size, 5000); packet = Math.min(size, 5000);
@ -360,7 +317,7 @@ public class SQLManager implements AbstractDB {
for (int i = 0; i < subList.size(); i++) { for (int i = 0; i < subList.size(); i++) {
count++; count++;
final T obj = subList.get(i); final T obj = subList.get(i);
mod.setMySQL(preparedStmt, i , obj); mod.setMySQL(preparedStmt, i, obj);
} }
last = subList.size(); last = subList.size();
preparedStmt.addBatch(); preparedStmt.addBatch();
@ -370,8 +327,7 @@ public class SQLManager implements AbstractDB {
preparedStmt.clearParameters(); preparedStmt.clearParameters();
preparedStmt.close(); preparedStmt.close();
return; return;
} } catch (Exception e) {
catch (Exception e) {
if (Settings.DB.USE_MYSQL) { if (Settings.DB.USE_MYSQL) {
e.printStackTrace(); e.printStackTrace();
PlotSquared.log("&cERROR 1: " + " | " + objList.get(0).getClass().getCanonicalName()); PlotSquared.log("&cERROR 1: " + " | " + objList.get(0).getClass().getCanonicalName());
@ -402,7 +358,7 @@ public class SQLManager implements AbstractDB {
for (int i = 0; i < subList.size(); i++) { for (int i = 0; i < subList.size(); i++) {
count++; count++;
final T obj = subList.get(i); final T obj = subList.get(i);
mod.setSQLite(preparedStmt, i , obj); mod.setSQLite(preparedStmt, i, obj);
} }
last = subList.size(); last = subList.size();
preparedStmt.addBatch(); preparedStmt.addBatch();
@ -412,8 +368,7 @@ public class SQLManager implements AbstractDB {
preparedStmt.clearParameters(); preparedStmt.clearParameters();
preparedStmt.close(); preparedStmt.close();
return; return;
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
PlotSquared.log("&cERROR 2: " + " | " + objList.get(0).getClass().getCanonicalName()); PlotSquared.log("&cERROR 2: " + " | " + objList.get(0).getClass().getCanonicalName());
} }
@ -434,8 +389,7 @@ public class SQLManager implements AbstractDB {
PlotSquared.log("&aBatch 3"); PlotSquared.log("&aBatch 3");
preparedStmt.executeBatch(); preparedStmt.executeBatch();
preparedStmt.close(); preparedStmt.close();
} } catch (Exception e3) {
catch (Exception e3) {
e3.printStackTrace(); e3.printStackTrace();
PlotSquared.log("&c[ERROR] " + "Failed to save all!"); PlotSquared.log("&c[ERROR] " + "Failed to save all!");
} }
@ -460,7 +414,7 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void setMySQL(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException { public void setMySQL(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException {
stmt.setInt((i * 10) + 1, pair.id ); // id stmt.setInt((i * 10) + 1, pair.id); // id
stmt.setNull((i * 10) + 2, 4); // biome stmt.setNull((i * 10) + 2, 4); // biome
stmt.setNull((i * 10) + 3, 4); // rain stmt.setNull((i * 10) + 3, 4); // rain
stmt.setNull((i * 10) + 4, 4); // custom_time stmt.setNull((i * 10) + 4, 4); // custom_time
@ -468,14 +422,12 @@ public class SQLManager implements AbstractDB {
stmt.setNull((i * 10) + 6, 4); // deny_entry stmt.setNull((i * 10) + 6, 4); // deny_entry
if (pair.settings.getAlias().equals("")) { if (pair.settings.getAlias().equals("")) {
stmt.setNull((i * 10) + 7, 4); stmt.setNull((i * 10) + 7, 4);
} } else {
else {
stmt.setString((i * 10) + 7, pair.settings.getAlias()); stmt.setString((i * 10) + 7, pair.settings.getAlias());
} }
if (pair.settings.flags == null) { if (pair.settings.flags == null) {
stmt.setNull((i * 10) + 8, 4); stmt.setNull((i * 10) + 8, 4);
} } else {
else {
final StringBuilder flag_string = new StringBuilder(); final StringBuilder flag_string = new StringBuilder();
int k = 0; int k = 0;
for (final Flag flag : pair.settings.flags.values()) { for (final Flag flag : pair.settings.flags.values()) {
@ -497,8 +449,7 @@ public class SQLManager implements AbstractDB {
String position; String position;
if (loc.y == 0) { if (loc.y == 0) {
position = "DEFAULT"; position = "DEFAULT";
} } else {
else {
position = loc.x + "," + loc.y + "," + loc.z; position = loc.x + "," + loc.y + "," + loc.z;
} }
stmt.setString((i * 10) + 10, position); stmt.setString((i * 10) + 10, position);
@ -506,7 +457,7 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void setSQLite(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException { public void setSQLite(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException {
stmt.setInt((i * 10) + 1, pair.id ); // id stmt.setInt((i * 10) + 1, pair.id); // id
stmt.setNull((i * 10) + 2, 4); // biome stmt.setNull((i * 10) + 2, 4); // biome
stmt.setNull((i * 10) + 3, 4); // rain stmt.setNull((i * 10) + 3, 4); // rain
stmt.setNull((i * 10) + 4, 4); // custom_time stmt.setNull((i * 10) + 4, 4); // custom_time
@ -514,14 +465,12 @@ public class SQLManager implements AbstractDB {
stmt.setNull((i * 10) + 6, 4); // deny_entry stmt.setNull((i * 10) + 6, 4); // deny_entry
if (pair.settings.getAlias().equals("")) { if (pair.settings.getAlias().equals("")) {
stmt.setNull((i * 10) + 7, 4); stmt.setNull((i * 10) + 7, 4);
} } else {
else {
stmt.setString((i * 10) + 7, pair.settings.getAlias()); stmt.setString((i * 10) + 7, pair.settings.getAlias());
} }
if (pair.settings.flags == null) { if (pair.settings.flags == null) {
stmt.setNull((i * 10) + 8, 4); stmt.setNull((i * 10) + 8, 4);
} } else {
else {
final StringBuilder flag_string = new StringBuilder(); final StringBuilder flag_string = new StringBuilder();
int k = 0; int k = 0;
for (final Flag flag : pair.settings.flags.values()) { for (final Flag flag : pair.settings.flags.values()) {
@ -543,8 +492,7 @@ public class SQLManager implements AbstractDB {
String position; String position;
if (loc.y == 0) { if (loc.y == 0) {
position = "DEFAULT"; position = "DEFAULT";
} } else {
else {
position = loc.x + "," + loc.y + "," + loc.z; position = loc.x + "," + loc.y + "," + loc.z;
} }
stmt.setString((i * 10) + 10, position); stmt.setString((i * 10) + 10, position);
@ -587,7 +535,7 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException { public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException {
stmt.setInt((i * 10) + 1, id ); stmt.setInt((i * 10) + 1, id);
stmt.setNull((i * 10) + 2, 4); stmt.setNull((i * 10) + 2, 4);
stmt.setNull((i * 10) + 3, 4); stmt.setNull((i * 10) + 3, 4);
stmt.setNull((i * 10) + 4, 4); stmt.setNull((i * 10) + 4, 4);
@ -675,10 +623,9 @@ public class SQLManager implements AbstractDB {
public void createTables(final String database) throws SQLException { public void createTables(final String database) throws SQLException {
final String[] tables; final String[] tables;
if (Settings.ENABLE_CLUSTERS) { if (Settings.ENABLE_CLUSTERS) {
tables = new String[] { "plot", "plot_denied", "plot_helpers", "plot_comments", "plot_trusted", "plot_rating", "plot_settings", "cluster" }; tables = new String[]{"plot", "plot_denied", "plot_helpers", "plot_comments", "plot_trusted", "plot_rating", "plot_settings", "cluster"};
} } else {
else { tables = new String[]{"plot", "plot_denied", "plot_helpers", "plot_comments", "plot_trusted", "plot_rating", "plot_settings"};
tables = new String[] { "plot", "plot_denied", "plot_helpers", "plot_comments", "plot_trusted", "plot_rating", "plot_settings" };
} }
final DatabaseMetaData meta = connection.getMetaData(); final DatabaseMetaData meta = connection.getMetaData();
int create = 0; int create = 0;
@ -693,12 +640,7 @@ public class SQLManager implements AbstractDB {
return; return;
} }
boolean add_constraint; boolean add_constraint;
if (create == tables.length) { add_constraint = create == tables.length;
add_constraint = true;
}
else {
add_constraint = false;
}
PlotSquared.log("Creating tables"); PlotSquared.log("Creating tables");
final boolean mysql = database.equals("mysql"); final boolean mysql = database.equals("mysql");
final Statement stmt = this.connection.createStatement(); final Statement stmt = this.connection.createStatement();
@ -706,7 +648,7 @@ public class SQLManager implements AbstractDB {
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_rating` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_rating` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8");
@ -742,7 +684,7 @@ public class SQLManager implements AbstractDB {
*/ */
@Override @Override
public void delete(final String world, final Plot plot) { public void delete(final String world, final Plot plot) {
PlotSquared.removePlot(world, plot.id, false); PlotSquared.getInstance().removePlot(world, plot.id, false);
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -840,15 +782,13 @@ public class SQLManager implements AbstractDB {
final Statement statement = this.connection.createStatement(); final Statement statement = this.connection.createStatement();
statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`"); statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`");
if (Settings.DB.USE_MYSQL) { if (Settings.DB.USE_MYSQL) {
statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
} } else {
else {
statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")");
} }
statement.executeBatch(); statement.executeBatch();
statement.close(); statement.close();
} } catch (SQLException e) {
catch (SQLException e) {
final Statement statement = this.connection.createStatement(); final Statement statement = this.connection.createStatement();
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`");
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0"); statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0");
@ -859,8 +799,7 @@ public class SQLManager implements AbstractDB {
} }
} }
rs.close(); rs.close();
} } catch (SQLException e) {
catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -907,7 +846,7 @@ public class SQLManager implements AbstractDB {
user = UUID.fromString(o); user = UUID.fromString(o);
uuids.put(o, user); uuids.put(o, user);
} }
p = new Plot(plot_id, user, new ArrayList<UUID>(), new ArrayList<UUID>(), new ArrayList<UUID>(), "", null, null, worldname, new boolean[] { false, false, false, false }); p = new Plot(plot_id, user, new ArrayList<UUID>(), new ArrayList<UUID>(), new ArrayList<UUID>(), "", null, null, worldname, new boolean[]{false, false, false, false});
plots.put(id, p); plots.put(id, p);
} }
@ -923,7 +862,7 @@ public class SQLManager implements AbstractDB {
} }
final Plot plot = plots.get(id); final Plot plot = plots.get(id);
if (plot != null) { if (plot != null) {
if (plot.settings.ratings == null ) { if (plot.settings.ratings == null) {
plot.settings.ratings = new HashMap<UUID, Integer>(); plot.settings.ratings = new HashMap<UUID, Integer>();
} }
plot.settings.ratings.put(user, r.getInt("rating")); plot.settings.ratings.put(user, r.getInt("rating"));
@ -1033,17 +972,17 @@ public class SQLManager implements AbstractDB {
} }
plot.settings.setMerged(merged); plot.settings.setMerged(merged);
} else { } else {
plot.settings.setMerged(new boolean[] { false, false, false, false }); plot.settings.setMerged(new boolean[]{false, false, false, false});
} }
String[] flags_string; String[] flags_string;
final String myflags = r.getString("flags"); final String myflags = r.getString("flags");
if (myflags == null) { if (myflags == null) {
flags_string = new String[] {}; flags_string = new String[]{};
} else { } else {
if (myflags.length() > 0) { if (myflags.length() > 0) {
flags_string = myflags.split(","); flags_string = myflags.split(",");
} else { } else {
flags_string = new String[] {}; flags_string = new String[]{};
} }
} }
final HashMap<String, Flag> flags = new HashMap<>(); final HashMap<String, Flag> flags = new HashMap<>();
@ -1064,8 +1003,7 @@ public class SQLManager implements AbstractDB {
if (StringUtils.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { if (StringUtils.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
Flag flag = new Flag(FlagManager.getFlag(element, true), ""); Flag flag = new Flag(FlagManager.getFlag(element, true), "");
flags.put(flag.getKey(), flag); flags.put(flag.getKey(), flag);
} } else {
else {
PlotSquared.log("INVALID FLAG: " + element); PlotSquared.log("INVALID FLAG: " + element);
} }
} }
@ -1308,11 +1246,11 @@ public class SQLManager implements AbstractDB {
purgeIds(world, ids); purgeIds(world, ids);
stmt.close(); stmt.close();
r.close(); r.close();
for (Iterator<PlotId> iter = plots.iterator(); iter.hasNext();) { for (Iterator<PlotId> iter = plots.iterator(); iter.hasNext(); ) {
PlotId plotId = iter.next(); PlotId plotId = iter.next();
iter.remove(); iter.remove();
PlotId id = new PlotId(plotId.x, plotId.y); PlotId id = new PlotId(plotId.x, plotId.y);
PlotSquared.removePlot(world, new PlotId(id.x, id.y), true); PlotSquared.getInstance().removePlot(world, new PlotId(id.x, id.y), true);
} }
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -1470,8 +1408,7 @@ public class SQLManager implements AbstractDB {
PlotId id; PlotId id;
if (hash != 0) { if (hash != 0) {
id = PlotId.unpair(hash); id = PlotId.unpair(hash);
} } else {
else {
id = null; id = null;
} }
final String msg = set.getString("comment"); final String msg = set.getString("comment");
@ -1653,7 +1590,7 @@ public class SQLManager implements AbstractDB {
final PreparedStatement statement = this.connection.prepareStatement("SELECT `rating`, `player` FROM `" + this.prefix + "plot_rating` WHERE `plot_plot_id` = ? "); final PreparedStatement statement = this.connection.prepareStatement("SELECT `rating`, `player` FROM `" + this.prefix + "plot_rating` WHERE `plot_plot_id` = ? ");
statement.setInt(1, getId(plot.world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
final ResultSet set = statement.executeQuery(); final ResultSet set = statement.executeQuery();
while(set.next()) { while (set.next()) {
UUID uuid = UUID.fromString(set.getString("player")); UUID uuid = UUID.fromString(set.getString("player"));
int rating = set.getInt("rating"); int rating = set.getInt("rating");
map.put(uuid, rating); map.put(uuid, rating);
@ -1667,7 +1604,6 @@ public class SQLManager implements AbstractDB {
return map; return map;
} }
@Override @Override
public void setRating(final Plot plot, final UUID rater, final int value) { public void setRating(final Plot plot, final UUID rater, final int value) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@ -1866,17 +1802,17 @@ public class SQLManager implements AbstractDB {
} }
cluster.settings.setMerged(merged); cluster.settings.setMerged(merged);
} else { } else {
cluster.settings.setMerged(new boolean[] { false, false, false, false }); cluster.settings.setMerged(new boolean[]{false, false, false, false});
} }
String[] flags_string; String[] flags_string;
final String myflags = r.getString("flags"); final String myflags = r.getString("flags");
if (myflags == null) { if (myflags == null) {
flags_string = new String[] {}; flags_string = new String[]{};
} else { } else {
if (myflags.length() > 0) { if (myflags.length() > 0) {
flags_string = myflags.split(","); flags_string = myflags.split(",");
} else { } else {
flags_string = new String[] {}; flags_string = new String[]{};
} }
} }
final HashMap<String, Flag> flags = new HashMap<>(); final HashMap<String, Flag> flags = new HashMap<>();
@ -2184,7 +2120,7 @@ public class SQLManager implements AbstractDB {
public boolean deleteTables() { public boolean deleteTables() {
try { try {
SQLManager.this.connection.close(); SQLManager.this.connection.close();
SQLManager.this.connection = PlotSquared.getDatabase().forceConnection(); SQLManager.this.connection = PlotSquared.getInstance().getDatabase().forceConnection();
final Statement stmt = this.connection.createStatement(); final Statement stmt = this.connection.createStatement();
stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`"); stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`"); stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`");
@ -2203,10 +2139,29 @@ public class SQLManager implements AbstractDB {
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
return true; return true;
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} }
private class UUIDPair {
public final int id;
public final UUID uuid;
public UUIDPair(int id, UUID uuid) {
this.id = id;
this.uuid = uuid;
}
}
private class SettingsPair {
public final int id;
public final PlotSettings settings;
public SettingsPair(int id, PlotSettings settings) {
this.id = id;
this.settings = settings;
}
}
} }

View File

@ -20,6 +20,19 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database.plotme; package com.intellectualcrafters.plot.database.plotme;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.TaskManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -34,20 +47,6 @@ import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.TaskManager;
/** /**
* Created 2014-08-17 for PlotSquared * Created 2014-08-17 for PlotSquared
* *
@ -66,6 +65,15 @@ public class LikePlotMeConverter {
this.plugin = plugin; this.plugin = plugin;
} }
public static String getWorld(final String world) {
for (final World newworld : Bukkit.getWorlds()) {
if (newworld.getName().equalsIgnoreCase(world)) {
return newworld.getName();
}
}
return world;
}
private void sendMessage(final String message) { private void sendMessage(final String message) {
PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message); PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
} }
@ -102,7 +110,24 @@ public class LikePlotMeConverter {
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared"); content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
content = content.replaceAll(plugin, "PlotSquared"); content = content.replaceAll(plugin, "PlotSquared");
Files.write(path, content.getBytes(charset)); Files.write(path, content.getBytes(charset));
} catch (Exception e) {}; } catch (Exception e) {
}
}
public void updateWorldYml(String plugin, String location) {
try {
Path path = Paths.get(location);
File file = new File(location);
if (!file.exists()) {
return;
}
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
content = content.replaceAll(plugin, "PlotSquared");
Files.write(path, content.getBytes(charset));
} catch (Exception e) {
}
} }
public boolean run(final APlotMeConnector connector) { public boolean run(final APlotMeConnector connector) {
@ -249,7 +274,7 @@ public class LikePlotMeConverter {
PlotSquared.log("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml"); PlotSquared.log("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly"); PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
PlotSquared.log("&c - Start the server"); PlotSquared.log("&c - Start the server");
PlotSquared.setAllPlotsRaw(DBFunc.getPlots()); PlotSquared.getInstance().setAllPlotsRaw(DBFunc.getPlots());
} }
}); });
sendMessage("Saving configuration..."); sendMessage("Saving configuration...");
@ -276,7 +301,7 @@ public class LikePlotMeConverter {
} }
final String actualWorldName = world.getName(); final String actualWorldName = world.getName();
sendMessage("Reloading generator for world: '" + actualWorldName + "'..."); sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
PlotSquared.removePlotWorld(actualWorldName); PlotSquared.getInstance().removePlotWorld(actualWorldName);
if (MV) { if (MV) {
// unload world with MV // unload world with MV
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
@ -316,13 +341,4 @@ public class LikePlotMeConverter {
} }
return true; return true;
} }
public static String getWorld(final String world) {
for (final World newworld : Bukkit.getWorlds()) {
if (newworld.getName().equalsIgnoreCase(world)) {
return newworld.getName();
}
}
return world;
}
} }

View File

@ -20,24 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag; package com.intellectualcrafters.plot.flag;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import java.util.*;
/** /**
* Flag Manager Utility * Flag Manager Utility
* *
@ -101,14 +91,14 @@ public class FlagManager {
public static boolean addFlag(AbstractFlag af, boolean reserved) { public static boolean addFlag(AbstractFlag af, boolean reserved) {
PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af); PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
for (PlotWorld plotworld : PlotSquared.getPlotWorldObjects()) { for (PlotWorld plotworld : PlotSquared.getInstance().getPlotWorldObjects()) {
Flag flag = ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(af.getKey()); Flag flag = ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(af.getKey());
if (flag != null) { if (flag != null) {
flag.setKey(af); flag.setKey(af);
} }
} }
if (PlotSquared.getAllPlotsRaw() != null) { if (PlotSquared.getInstance().getAllPlotsRaw() != null) {
for (final Plot plot : PlotSquared.getPlotsRaw()) { for (final Plot plot : PlotSquared.getInstance().getPlotsRaw()) {
Flag flag = plot.settings.flags.get(af.getKey()); Flag flag = plot.settings.flags.get(af.getKey());
if (flag != null) { if (flag != null) {
flag.setKey(af); flag.setKey(af);
@ -125,7 +115,7 @@ public class FlagManager {
public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) { public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) {
Flag flag = settings.flags.get(id); Flag flag = settings.flags.get(id);
if (flag == null) { if (flag == null) {
PlotWorld plotworld = PlotSquared.getPlotWorld(world); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (plotworld == null) { if (plotworld == null) {
return null; return null;
} }
@ -237,7 +227,7 @@ public class FlagManager {
} }
public static Collection<Flag> getSettingFlags(final String world, final PlotSettings settings) { public static Collection<Flag> getSettingFlags(final String world, final PlotSettings settings) {
PlotWorld plotworld = PlotSquared.getPlotWorld(world); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
HashMap<String, Flag> map; HashMap<String, Flag> map;
if (plotworld == null) { if (plotworld == null) {
map = new HashMap<>(); map = new HashMap<>();

View File

@ -1,32 +1,26 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.HashMap; import com.intellectualcrafters.plot.PlotSquared;
import java.util.Iterator; import com.intellectualcrafters.plot.object.*;
import java.util.Map.Entry; import com.intellectualcrafters.plot.util.ChunkManager;
import java.util.Random; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared; import java.util.HashMap;
import com.intellectualcrafters.plot.object.BlockWrapper; import java.util.Iterator;
import com.intellectualcrafters.plot.object.Location; import java.util.Map.Entry;
import com.intellectualcrafters.plot.object.PlotCluster; import java.util.Random;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
public class AugmentedPopulator extends BlockPopulator { public class AugmentedPopulator extends BlockPopulator {
public static short[][] x_loc;
public static short[][] y_loc;
public static short[][] z_loc;
public final PlotWorld plotworld; public final PlotWorld plotworld;
public final PlotManager manager; public final PlotManager manager;
public final PlotGenerator generator; public final PlotGenerator generator;
@ -40,59 +34,11 @@ public class AugmentedPopulator extends BlockPopulator {
private final int tx; private final int tx;
private final int tz; private final int tz;
public static void removePopulator(final String worldname, final PlotCluster cluster) {
final World world = Bukkit.getWorld(worldname);
for (final Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();) {
final BlockPopulator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
iterator.remove();
}
}
}
}
public BlockWrapper get(final int x, final int z, final int i, final int j, final short[][] r, final boolean c) {
final int y = (i << 4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8));
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
if (r[i] == null) {
return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, (short) 0, (byte) 0);
} else {
return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, r[i][j], (byte) 0);
}
}
public static short[][] x_loc;
public static short[][] y_loc;
public static short[][] z_loc;
public static void initCache() {
if (x_loc == null) {
x_loc = new short[16][4096];
y_loc = new short[16][4096];
z_loc = new short[16][4096];
for (int i = 0; i < 16; i++) {
int i4 = i << 4;
for (int j = 0; j < 4096; j++) {
final int y = (i4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8));
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
x_loc[i][j] = (short) x1;
y_loc[i][j] = (short) y;
z_loc[i][j] = (short) z1;
}
}
}
}
public AugmentedPopulator(final String world, final PlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) { public AugmentedPopulator(final String world, final PlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
initCache(); initCache();
this.cluster = cluster; this.cluster = cluster;
this.generator = generator; this.generator = generator;
this.plotworld = PlotSquared.getPlotWorld(world); this.plotworld = PlotSquared.getInstance().getPlotWorld(world);
this.manager = generator.getPlotManager(); this.manager = generator.getPlotManager();
this.p = p; this.p = p;
this.b = b; this.b = b;
@ -119,6 +65,50 @@ public class AugmentedPopulator extends BlockPopulator {
} }
} }
public static void removePopulator(final String worldname, final PlotCluster cluster) {
final World world = Bukkit.getWorld(worldname);
for (final Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();) {
final BlockPopulator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
iterator.remove();
}
}
}
}
public static void initCache() {
if (x_loc == null) {
x_loc = new short[16][4096];
y_loc = new short[16][4096];
z_loc = new short[16][4096];
for (int i = 0; i < 16; i++) {
int i4 = i << 4;
for (int j = 0; j < 4096; j++) {
final int y = (i4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8));
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
x_loc[i][j] = (short) x1;
y_loc[i][j] = (short) y;
z_loc[i][j] = (short) z1;
}
}
}
}
public BlockWrapper get(final int x, final int z, final int i, final int j, final short[][] r, final boolean c) {
final int y = (i << 4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8));
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
if (r[i] == null) {
return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, (short) 0, (byte) 0);
} else {
return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, r[i][j], (byte) 0);
}
}
@Override @Override
public void populate(final World world, final Random rand, final Chunk chunk) { public void populate(final World world, final Random rand, final Chunk chunk) {
if (this.plotworld.TERRAIN == 3) { if (this.plotworld.TERRAIN == 3) {
@ -139,7 +129,7 @@ public class AugmentedPopulator extends BlockPopulator {
else { else {
data = 0; data = 0;
} }
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, blocks.get(y), (byte) data); BukkitSetBlockManager.setBlockManager.set(world, x, y, z, blocks.get(y), data);
} }
} }
} }
@ -163,7 +153,7 @@ public class AugmentedPopulator extends BlockPopulator {
int zz = loc.z - Z; int zz = loc.z - Z;
if (xx >= 0 && xx < 16) { if (xx >= 0 && xx < 16) {
if (zz >= 0 && zz < 16) { if (zz >= 0 && zz < 16) {
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, entry2.getValue(), (byte) data); BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, entry2.getValue(), data);
} }
} }
} }
@ -187,11 +177,7 @@ public class AugmentedPopulator extends BlockPopulator {
return; return;
} }
final boolean check; final boolean check;
if (!inX1 || !inX2 || !inZ1 || !inZ2) { check = !inX1 || !inX2 || !inZ1 || !inZ2;
check = true;
} else {
check = false;
}
if (this.plotworld.TERRAIN > 1) { if (this.plotworld.TERRAIN > 1) {
final PlotId plot1 = this.manager.getPlotIdAbs(this.plotworld, x, 0, z); final PlotId plot1 = this.manager.getPlotIdAbs(this.plotworld, x, 0, z);
final PlotId plot2 = this.manager.getPlotIdAbs(this.plotworld, x2, 0, z2); final PlotId plot2 = this.manager.getPlotIdAbs(this.plotworld, x2, 0, z2);

View File

@ -1,12 +1,13 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.ArrayList; import com.intellectualcrafters.plot.BukkitMain;
import java.util.Arrays; import com.intellectualcrafters.plot.PlotSquared;
import java.util.HashSet; import com.intellectualcrafters.plot.config.C;
import java.util.Iterator; import com.intellectualcrafters.plot.object.*;
import java.util.List; import com.intellectualcrafters.plot.util.ChunkManager;
import java.util.Random; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import org.apache.commons.lang.mutable.MutableInt; import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -14,31 +15,23 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.material.Directional; import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.BukkitMain; import java.util.*;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class BukkitHybridUtils extends HybridUtils { public class BukkitHybridUtils extends HybridUtils {
public static List<ChunkLoc> regions;
public static List<ChunkLoc> chunks = new ArrayList<>();
public static String world;
private static boolean UPDATE = false;
public int task;
private long last;
public double getMean(int[] array) { public double getMean(int[] array) {
double count = 0; double count = 0;
for (int i : array) { for (int i : array) {
@ -275,15 +268,15 @@ public class BukkitHybridUtils extends HybridUtils {
} }
} }
} }
}; }
}, 1); }, 1);
TaskManager.tasks.put(currentIndex, task); TaskManager.tasks.put(currentIndex, task);
} }
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) { public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
TaskManager.index.increment(); TaskManager.index.increment();
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
int bx = bot.getX() >> 4; int bx = bot.getX() >> 4;
int bz = bot.getZ() >> 4; int bz = bot.getZ() >> 4;
int tx = top.getX() >> 4; int tx = top.getX() >> 4;
@ -295,7 +288,7 @@ public class BukkitHybridUtils extends HybridUtils {
chunks.add(world.getChunkAt(X,Z)); chunks.add(world.getChunkAt(X,Z));
} }
} }
PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(plot.world);
if (!(plotworld instanceof ClassicPlotWorld)) { if (!(plotworld instanceof ClassicPlotWorld)) {
whenDone.value = -1; whenDone.value = -1;
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
@ -412,10 +405,6 @@ public class BukkitHybridUtils extends HybridUtils {
return chunks; return chunks;
} }
private static boolean UPDATE = false;
public int task;
private long last;
@Override @Override
public boolean scheduleRoadUpdate(final String world, int extend) { public boolean scheduleRoadUpdate(final String world, int extend) {
if (BukkitHybridUtils.UPDATE) { if (BukkitHybridUtils.UPDATE) {
@ -426,10 +415,6 @@ public class BukkitHybridUtils extends HybridUtils {
return scheduleRoadUpdate(world, regions, extend); return scheduleRoadUpdate(world, regions, extend);
} }
public static List<ChunkLoc> regions;
public static List<ChunkLoc> chunks = new ArrayList<>();
public static String world;
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) { public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) {
BukkitHybridUtils.regions = rgs; BukkitHybridUtils.regions = rgs;
BukkitHybridUtils.world = world; BukkitHybridUtils.world = world;

View File

@ -1,19 +1,14 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.HashMap; import com.intellectualcrafters.plot.PlotSquared;
import java.util.HashSet; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.PlotSquared; import java.util.HashMap;
import com.intellectualcrafters.plot.object.PlotLoc; import java.util.HashSet;
import com.intellectualcrafters.plot.object.PlotPopulator;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
/** /**
* @author Citymonstret * @author Citymonstret
@ -35,9 +30,9 @@ public class HybridPop extends PlotPopulator {
final int plotheight; final int plotheight;
final byte[] plotfloors; final byte[] plotfloors;
final byte[] filling; final byte[] filling;
private final HybridPlotWorld plotworld;
final short pathWidthLower; final short pathWidthLower;
final short pathWidthUpper; final short pathWidthUpper;
private final HybridPlotWorld plotworld;
Biome biome; Biome biome;
private long state; private long state;
private boolean doFilling = false; private boolean doFilling = false;
@ -111,7 +106,7 @@ public class HybridPop extends PlotPopulator {
@Override @Override
public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) { public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) {
PlotSquared.getPlotManager(world.getName()); PlotSquared.getInstance().getPlotManager(world.getName());
int sx = (short) ((this.X) % this.size); int sx = (short) ((this.X) % this.size);
int sz = (short) ((this.Z) % this.size); int sz = (short) ((this.Z) % this.size);

View File

@ -1,24 +1,16 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.io.File;
import java.util.HashMap;
import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import java.io.File;
import java.util.HashMap;
public abstract class HybridUtils { public abstract class HybridUtils {
public static HybridUtils manager; public static HybridUtils manager;
@ -33,7 +25,7 @@ public abstract class HybridUtils {
final String world = plot.world; final String world = plot.world;
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id); final Location bot = MainUtil.getPlotBottomLoc(world, plot.id);
final Location top = MainUtil.getPlotTopLoc(world, plot.id); final Location top = MainUtil.getPlotTopLoc(world, plot.id);
final HybridPlotWorld plotworld = (HybridPlotWorld) PlotSquared.getPlotWorld(world); final HybridPlotWorld plotworld = (HybridPlotWorld) PlotSquared.getInstance().getPlotWorld(world);
final int sx = (bot.getX() - plotworld.ROAD_WIDTH) + 1; final int sx = (bot.getX() - plotworld.ROAD_WIDTH) + 1;
final int sz = bot.getZ() + 1; final int sz = bot.getZ() + 1;
final int sy = plotworld.ROAD_HEIGHT; final int sy = plotworld.ROAD_HEIGHT;
@ -69,7 +61,7 @@ public abstract class HybridUtils {
final int z = chunk.z << 4; final int z = chunk.z << 4;
final int ex = x + 15; final int ex = x + 15;
final int ez = z + 15; final int ez = z + 15;
final HybridPlotWorld plotworld = (HybridPlotWorld) PlotSquared.getPlotWorld(world); final HybridPlotWorld plotworld = (HybridPlotWorld) PlotSquared.getInstance().getPlotWorld(world);
extend = Math.min(extend, 255 - plotworld.ROAD_HEIGHT - plotworld.SCHEMATIC_HEIGHT); extend = Math.min(extend, 255 - plotworld.ROAD_HEIGHT - plotworld.SCHEMATIC_HEIGHT);
if (!plotworld.ROAD_SCHEMATIC_ENABLED) { if (!plotworld.ROAD_SCHEMATIC_ENABLED) {
return false; return false;
@ -85,7 +77,7 @@ public abstract class HybridUtils {
toCheck = c1 ^ c2; toCheck = c1 ^ c2;
} }
} }
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotId id1 = manager.getPlotId(plotworld, x, 0, z); final PlotId id1 = manager.getPlotId(plotworld, x, 0, z);
final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez); final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez);
if ((id1 == null) || (id2 == null) || (id1 != id2)) { if ((id1 == null) || (id2 == null) || (id1 != id2)) {

View File

@ -1,9 +1,11 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.util.TaskManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
@ -12,20 +14,18 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.util.TaskManager;
public class ChunkListener implements Listener { public class ChunkListener implements Listener {
private Chunk lastChunk = null;
private long last = 0;
private int count = 0;
@EventHandler @EventHandler
public void onChunkUnload(ChunkUnloadEvent event) { public void onChunkUnload(ChunkUnloadEvent event) {
if (processChunk(event.getChunk(), true)) { if (processChunk(event.getChunk(), true)) {
@ -38,8 +38,6 @@ public class ChunkListener implements Listener {
processChunk(event.getChunk(), false); processChunk(event.getChunk(), false);
} }
private Chunk lastChunk = null;
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority=EventPriority.LOWEST)
public void onItemSpawn(ItemSpawnEvent event) { public void onItemSpawn(ItemSpawnEvent event) {
Item entity = event.getEntity(); Item entity = event.getEntity();
@ -49,7 +47,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { if (!PlotSquared.getInstance().isPlotWorld(chunk.getWorld().getName())) {
return; return;
} }
Entity[] entities = chunk.getEntities(); Entity[] entities = chunk.getEntities();
@ -63,9 +61,6 @@ public class ChunkListener implements Listener {
} }
} }
private long last = 0;
private int count = 0;
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority=EventPriority.LOWEST)
public void onBlockPhysics(BlockPhysicsEvent event) { public void onBlockPhysics(BlockPhysicsEvent event) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -90,7 +85,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { if (!PlotSquared.getInstance().isPlotWorld(chunk.getWorld().getName())) {
return; return;
} }
Entity[] entities = chunk.getEntities(); Entity[] entities = chunk.getEntities();
@ -144,7 +139,7 @@ public class ChunkListener implements Listener {
} }
public boolean processChunk(Chunk chunk, boolean unload) { public boolean processChunk(Chunk chunk, boolean unload) {
if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { if (!PlotSquared.getInstance().isPlotWorld(chunk.getWorld().getName())) {
return false; return false;
} }
Entity[] entities = chunk.getEntities(); Entity[] entities = chunk.getEntities();

View File

@ -1,91 +1,5 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.minecart.RideableMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Tree;
import org.bukkit.material.Wool;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -93,25 +7,41 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.listeners.worldedit.WEManager; import com.intellectualcrafters.plot.listeners.worldedit.WEManager;
import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.*;
import org.bukkit.entity.minecart.RideableMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import java.util.*;
/** /**
* Player Events involving plots * Player Events involving plots
@ -121,11 +51,37 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
*/ */
public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener { public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener {
private boolean pistonBlocks = true;
public static void sendBlockChange(final org.bukkit.Location bloc, final Material type, final byte data) {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
String world = bloc.getWorld().getName();
int x = bloc.getBlockX();
int z = bloc.getBlockZ();
int distance = Bukkit.getViewDistance() * 16;
for (PlotPlayer player : UUIDHandler.players.values()) {
Location loc = player.getLocation();
if (loc.getWorld().equals(world)) {
if (16 * (Math.abs(loc.getX() - x) / 16) > distance) {
continue;
}
if (16 * (Math.abs(loc.getZ() - z) / 16) > distance) {
continue;
}
((BukkitPlayer) player).player.sendBlockChange(bloc, type, data);
}
}
}
}, 3);
}
@EventHandler @EventHandler
public void onRedstoneEvent(BlockRedstoneEvent event) { public void onRedstoneEvent(BlockRedstoneEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
if (!PlotSquared.isPlotWorld(loc.getWorld())) { if (!PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
return; return;
} }
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
@ -184,35 +140,11 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setNewCurrent(0); event.setNewCurrent(0);
} }
public static void sendBlockChange(final org.bukkit.Location bloc, final Material type, final byte data) {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
String world = bloc.getWorld().getName();
int x = bloc.getBlockX();
int z = bloc.getBlockZ();
int distance = Bukkit.getViewDistance() * 16;
for (PlotPlayer player : UUIDHandler.players.values()) {
Location loc = player.getLocation();
if (loc.getWorld().equals(world)) {
if (16 * (Math.abs(loc.getX() - x)/16) > distance) {
continue;
}
if (16 * (Math.abs(loc.getZ() - z)/16) > distance) {
continue;
}
((BukkitPlayer) player).player.sendBlockChange(bloc, type, data);
}
}
}
}, 3);
}
@EventHandler @EventHandler
public void onPhysicsEvent(BlockPhysicsEvent event) { public void onPhysicsEvent(BlockPhysicsEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
if (!PlotSquared.isPlotWorld(loc.getWorld())) { if (!PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
return; return;
} }
switch (block.getType()) { switch (block.getType()) {
@ -244,12 +176,11 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
} }
@EventHandler @EventHandler
public void onProjectileHit(ProjectileHitEvent event) { public void onProjectileHit(ProjectileHitEvent event) {
Projectile entity = (Projectile) event.getEntity(); Projectile entity = event.getEntity();
Location loc = BukkitUtil.getLocation(entity); Location loc = BukkitUtil.getLocation(entity);
if (!PlotSquared.isPlotWorld(loc.getWorld())) { if (!PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
return; return;
} }
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
@ -360,7 +291,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
TaskManager.TELEPORT_QUEUE.remove(player.getName()); TaskManager.TELEPORT_QUEUE.remove(player.getName());
} }
final String worldname = t.getWorld(); final String worldname = t.getWorld();
if (!PlotSquared.isPlotWorld(worldname)) { if (!PlotSquared.getInstance().isPlotWorld(worldname)) {
return; return;
} }
if (MainUtil.worldBorder.containsKey(worldname)) { if (MainUtil.worldBorder.containsKey(worldname)) {
@ -417,10 +348,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onChat(final AsyncPlayerChatEvent event) { public void onChat(final AsyncPlayerChatEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String world = player.getWorld().getName(); final String world = player.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotPlayer plr = BukkitUtil.getPlayer(player); final PlotPlayer plr = BukkitUtil.getPlayer(player);
if (!plotworld.PLOT_CHAT && (plr.getMeta("chat") == null || !(Boolean) plr.getMeta("chat"))) { if (!plotworld.PLOT_CHAT && (plr.getMeta("chat") == null || !(Boolean) plr.getMeta("chat"))) {
return; return;
@ -450,7 +381,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void BlockDestroy(final BlockBreakEvent event) { public void BlockDestroy(final BlockBreakEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String world = player.getWorld().getName(); final String world = player.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
@ -500,7 +431,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onBigBoom(final EntityExplodeEvent event) { public void onBigBoom(final EntityExplodeEvent event) {
Location loc = BukkitUtil.getLocation(event.getLocation()); Location loc = BukkitUtil.getLocation(event.getLocation());
final String world = loc.getWorld(); final String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final Plot plot = MainUtil.getPlot(loc); final Plot plot = MainUtil.getPlot(loc);
@ -547,7 +478,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) { public void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) {
final String world = event.getBlock().getWorld().getName(); final String world = event.getBlock().getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final Entity e = event.getEntity(); final Entity e = event.getEntity();
@ -597,7 +528,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityBlockForm(final EntityBlockFormEvent e) { public void onEntityBlockForm(final EntityBlockFormEvent e) {
final String world = e.getBlock().getWorld().getName(); final String world = e.getBlock().getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
if ((!(e.getEntity() instanceof Player))) { if ((!(e.getEntity() instanceof Player))) {
@ -611,7 +542,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onBS(final BlockSpreadEvent e) { public void onBS(final BlockSpreadEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true); e.setCancelled(true);
} }
@ -622,7 +553,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onBF(final BlockFormEvent e) { public void onBF(final BlockFormEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true); e.setCancelled(true);
} }
@ -634,14 +565,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (player == null) { if (player == null) {
final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
final String world = player.getWorld().getName(); final String world = player.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
@ -691,7 +622,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onFade(final BlockFadeEvent e) { public void onFade(final BlockFadeEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true); e.setCancelled(true);
} }
@ -702,7 +633,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onChange(final BlockFromToEvent e) { public void onChange(final BlockFromToEvent e) {
final Block b = e.getToBlock(); final Block b = e.getToBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true); e.setCancelled(true);
} }
@ -719,7 +650,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onGrow(final BlockGrowEvent e) { public void onGrow(final BlockGrowEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true); e.setCancelled(true);
} }
@ -731,7 +662,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Block block = event.getBlock(); final Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
String world = loc.getWorld(); String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
@ -768,14 +699,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
} }
private boolean pistonBlocks = true;
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockPistonRetract(final BlockPistonRetractEvent event) { public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
final Block block = event.getBlock(); final Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
String world = loc.getWorld(); String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
if (block.getType() != Material.PISTON_STICKY_BASE && block.getType() != Material.PISTON_BASE && block.getType() != Material.PISTON_MOVING_PIECE) { if (block.getType() != Material.PISTON_STICKY_BASE && block.getType() != Material.PISTON_BASE && block.getType() != Material.PISTON_MOVING_PIECE) {
@ -811,7 +740,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onStructureGrow(final StructureGrowEvent e) { public void onStructureGrow(final StructureGrowEvent e) {
if (!PlotSquared.isPlotWorld(e.getWorld().getName())) { if (!PlotSquared.getInstance().isPlotWorld(e.getWorld().getName())) {
return; return;
} }
final List<BlockState> blocks = e.getBlocks(); final List<BlockState> blocks = e.getBlocks();
@ -837,6 +766,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
Material type = block.getType(); Material type = block.getType();
if (action == Action.RIGHT_CLICK_BLOCK && type.isSolid() && type.isBlock() && type.isOccluding() && !type.isBurnable()) { if (action == Action.RIGHT_CLICK_BLOCK && type.isSolid() && type.isBlock() && type.isOccluding() && !type.isBurnable()) {
BlockState state = block.getState(); BlockState state = block.getState();
if (state.getData().getClass().equals(MaterialData.class)) { if (state.getData().getClass().equals(MaterialData.class)) {
@ -848,7 +778,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String world = player.getWorld().getName(); final String world = player.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final Location loc = BukkitUtil.getLocation(event.getClickedBlock().getLocation()); final Location loc = BukkitUtil.getLocation(event.getClickedBlock().getLocation());
@ -866,6 +796,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
final Flag use = FlagManager.getPlotFlag(plot, "use"); final Flag use = FlagManager.getPlotFlag(plot, "use");
if ((use != null) && ((HashSet<PlotBlock>) use.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { if ((use != null) && ((HashSet<PlotBlock>) use.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
return; return;
@ -904,13 +835,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
final Location loc = BukkitUtil.getLocation(event.getLocation()); final Location loc = BukkitUtil.getLocation(event.getLocation());
final String world = loc.getWorld(); final String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
if (!MainUtil.isPlotArea(loc)) { if (!MainUtil.isPlotArea(loc)) {
return; return;
} }
final PlotWorld pW = PlotSquared.getPlotWorld(world); final PlotWorld pW = PlotSquared.getInstance().getPlotWorld(world);
final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason(); final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
if ((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG || reason == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) && !pW.SPAWN_EGGS) { if ((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG || reason == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) && !pW.SPAWN_EGGS) {
event.setCancelled(true); event.setCancelled(true);
@ -922,6 +853,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
if (checkEntity(entity, plot)) { if (checkEntity(entity, plot)) {
event.setCancelled(true); event.setCancelled(true);
@ -936,7 +868,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
Block block = event.getBlock(); Block block = event.getBlock();
World world = block.getWorld(); World world = block.getWorld();
String worldname = world.getName(); String worldname = world.getName();
if (!PlotSquared.isPlotWorld(worldname)) { if (!PlotSquared.getInstance().isPlotWorld(worldname)) {
return; return;
} }
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
@ -1034,7 +966,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} else { } else {
return; return;
} }
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
if (e.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) { if (e.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) {
@ -1090,7 +1022,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Location t = BukkitUtil.getLocation(event.getTo()); final Location t = BukkitUtil.getLocation(event.getTo());
final Location q = new Location(t.getWorld(), t.getX(), 64, t.getZ()); final Location q = new Location(t.getWorld(), t.getX(), 64, t.getZ());
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (PlotSquared.isPlotWorld(q.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(q.getWorld())) {
final Plot plot = MainUtil.getPlot(q); final Plot plot = MainUtil.getPlot(q);
if (plot != null) { if (plot != null) {
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -1124,7 +1056,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final BlockFace bf = e.getBlockFace(); final BlockFace bf = e.getBlockFace();
final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
if (plot == null) { if (plot == null) {
@ -1200,8 +1132,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) { if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) {
final Collection<Plot> plots = PlotSquared.getPlots(pp.getName()).values(); final Collection<Plot> plots = PlotSquared.getPlots(pp.getName()).values();
for (final Plot plot : plots) { for (final Plot plot : plots) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(plot.world);
final PlotManager manager = PlotSquared.getPlotManager(plot.world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(plot.world);
manager.clearPlot(plotworld, plot, true, null); manager.clearPlot(plotworld, plot, true, null);
DBFunc.delete(plot.world, plot); DBFunc.delete(plot.world, plot);
PlotSquared.log(String.format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", plot.getId(), event.getPlayer().getName())); PlotSquared.log(String.format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", plot.getId(), event.getPlayer().getName()));
@ -1214,7 +1146,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onBucketFill(final PlayerBucketFillEvent e) { public void onBucketFill(final PlayerBucketFillEvent e) {
final Block b = e.getBlockClicked(); final Block b = e.getBlockClicked();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
@ -1258,7 +1190,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void onHangingPlace(final HangingPlaceEvent e) { public void onHangingPlace(final HangingPlaceEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
final Location loc = BukkitUtil.getLocation(b.getLocation()); final Location loc = BukkitUtil.getLocation(b.getLocation());
if (PlotSquared.isPlotWorld(loc.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(loc.getWorld())) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
@ -1300,7 +1232,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final Player p = (Player) r; final Player p = (Player) r;
final Location l = BukkitUtil.getLocation(e.getEntity()); final Location l = BukkitUtil.getLocation(e.getEntity());
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (PlotSquared.isPlotWorld(l.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(l.getWorld())) {
Plot plot = MainUtil.getPlot(l); Plot plot = MainUtil.getPlot(l);
if (plot == null) { if (plot == null) {
if (MainUtil.isPlotAreaAbs(l)) { if (MainUtil.isPlotAreaAbs(l)) {
@ -1337,7 +1269,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteractEntity(final PlayerInteractEntityEvent e) { public void onPlayerInteractEntity(final PlayerInteractEntityEvent e) {
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation()); final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
if (PlotSquared.isPlotWorld(l.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(l.getWorld())) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = MainUtil.getPlot(l); Plot plot = MainUtil.getPlot(l);
@ -1396,11 +1328,11 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onVehicleDestroy(final VehicleDestroyEvent e) { public void onVehicleDestroy(final VehicleDestroyEvent e) {
final Location l = BukkitUtil.getLocation(e.getVehicle()); final Location l = BukkitUtil.getLocation(e.getVehicle());
if (PlotSquared.isPlotWorld(l.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(l.getWorld())) {
final Entity d = e.getAttacker(); final Entity d = e.getAttacker();
if (d instanceof Player) { if (d instanceof Player) {
final Player p = (Player) d; final Player p = (Player) d;
PlotSquared.getPlotWorld(l.getWorld()); PlotSquared.getInstance().getPlotWorld(l.getWorld());
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = MainUtil.getPlot(l); Plot plot = MainUtil.getPlot(l);
if (plot == null) { if (plot == null) {
@ -1450,7 +1382,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
TaskManager.TELEPORT_QUEUE.remove(name); TaskManager.TELEPORT_QUEUE.remove(name);
} }
} }
if (PlotSquared.isPlotWorld(l.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(l.getWorld())) {
Player p = null; Player p = null;
Projectile projectile = null; Projectile projectile = null;
if (damager instanceof Player) { if (damager instanceof Player) {
@ -1489,7 +1421,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
if (p != null) { if (p != null) {
final boolean aPlr = victim instanceof Player; final boolean aPlr = victim instanceof Player;
final PlotWorld pW = PlotSquared.getPlotWorld(l.getWorld()); final PlotWorld pW = PlotSquared.getInstance().getPlotWorld(l.getWorld());
if (!aPlr && pW.PVE && (!(victim instanceof ItemFrame) && !(victim.getType().getTypeId() == 30))) { if (!aPlr && pW.PVE && (!(victim instanceof ItemFrame) && !(victim.getType().getTypeId() == 30))) {
return; return;
} else if (aPlr && pW.PVP) { } else if (aPlr && pW.PVP) {
@ -1559,7 +1491,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerEggThrow(final PlayerEggThrowEvent e) { public void onPlayerEggThrow(final PlayerEggThrowEvent e) {
final Location l = BukkitUtil.getLocation(e.getEgg().getLocation()); final Location l = BukkitUtil.getLocation(e.getEgg().getLocation());
if (PlotSquared.isPlotWorld(l.getWorld())) { if (PlotSquared.getInstance().isPlotWorld(l.getWorld())) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = MainUtil.getPlot(l); Plot plot = MainUtil.getPlot(l);
@ -1596,7 +1528,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
public void BlockCreate(final BlockPlaceEvent event) { public void BlockCreate(final BlockPlaceEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String world = player.getWorld().getName(); final String world = player.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);

View File

@ -1,9 +1,13 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import java.util.HashSet; import com.intellectualcrafters.plot.PlotSquared;
import java.util.List; import com.intellectualcrafters.plot.config.C;
import java.util.UUID; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
@ -20,14 +24,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.intellectualcrafters.plot.PlotSquared; import java.util.HashSet;
import com.intellectualcrafters.plot.config.C; import java.util.List;
import com.intellectualcrafters.plot.object.Location; import java.util.UUID;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class PlayerEvents_1_8 extends PlotListener implements Listener { public class PlayerEvents_1_8 extends PlotListener implements Listener {
@ -37,7 +36,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
return; return;
} }
HumanEntity entity = event.getWhoClicked(); HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player) || !PlotSquared.isPlotWorld(entity.getWorld().getName())) { if (!(entity instanceof Player) || !PlotSquared.getInstance().isPlotWorld(entity.getWorld().getName())) {
return; return;
} }
Player player = (Player) entity; Player player = (Player) entity;
@ -124,7 +123,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
} }
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation()); final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
String world = l.getWorld(); String world = l.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
Plot plot = MainUtil.getPlot(l); Plot plot = MainUtil.getPlot(l);

View File

@ -1,19 +1,18 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import java.util.Iterator;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import java.util.Iterator;
public class PlayerEvents_1_8_3 implements Listener { public class PlayerEvents_1_8_3 implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -21,7 +20,7 @@ public class PlayerEvents_1_8_3 implements Listener {
Block block = event.getBlock(); Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation()); Location loc = BukkitUtil.getLocation(block.getLocation());
final String world = loc.getWorld(); final String world = loc.getWorld();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
final Plot plot = MainUtil.getPlot(loc); final Plot plot = MainUtil.getPlot(loc);

View File

@ -20,17 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import java.util.Arrays;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -47,6 +36,11 @@ import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.bukkit.*;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.UUID;
/** /**
* @author Citymonstret * @author Citymonstret
@ -54,7 +48,7 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
*/ */
public class PlotListener extends APlotListener { public class PlotListener extends APlotListener {
public void textures(final Player p) { public void textures(final Player p) {
if ((Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1) && PlotSquared.isPlotWorld(p.getWorld().getName())) { if ((Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1) && PlotSquared.getInstance().isPlotWorld(p.getWorld().getName())) {
p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK); p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK);
} }
} }
@ -148,7 +142,7 @@ public class PlotListener extends APlotListener {
if (id >= 2256 && id <= 2267) { if (id >= 2256 && id <= 2267) {
Location center = MainUtil.getPlotCenter(plot); Location center = MainUtil.getPlotCenter(plot);
org.bukkit.Location newLoc = BukkitUtil.getLocation(center); org.bukkit.Location newLoc = BukkitUtil.getLocation(center);
newLoc.setY(Math.min((((int) player.getLocation().getBlockY())/16) * 16, 240)); newLoc.setY(Math.min((player.getLocation().getBlockY() / 16) * 16, 240));
try { try {
player.playEffect(newLoc, Effect.RECORD_PLAY, Material.getMaterial(id)); player.playEffect(newLoc, Effect.RECORD_PLAY, Material.getMaterial(id));
} }

View File

@ -1,7 +1,11 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import java.util.List; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -12,12 +16,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.PlotSquared; import java.util.List;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class TNTListener implements Listener { public class TNTListener implements Listener {
private double lastRadius; private double lastRadius;
@ -34,7 +33,7 @@ public class TNTListener implements Listener {
} }
World world = entity.getWorld(); World world = entity.getWorld();
String worldname = world.getName(); String worldname = world.getName();
if (!PlotSquared.isPlotWorld(worldname)) { if (!PlotSquared.getInstance().isPlotWorld(worldname)) {
return; return;
} }
Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(entity)); Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(entity));

View File

@ -1,5 +1,8 @@
package com.intellectualcrafters.plot.listeners; package com.intellectualcrafters.plot.listeners;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -8,10 +11,6 @@ import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class WorldEvents implements Listener { public class WorldEvents implements Listener {
public static String lastWorld = null; public static String lastWorld = null;
@ -32,10 +31,10 @@ public class WorldEvents implements Listener {
final ChunkGenerator gen = world.getGenerator(); final ChunkGenerator gen = world.getGenerator();
if (gen instanceof PlotGenerator) { if (gen instanceof PlotGenerator) {
// //
PlotSquared.loadWorld(name, (PlotGenerator) gen); PlotSquared.getInstance().loadWorld(name, (PlotGenerator) gen);
} else { } else {
if (PlotSquared.config.contains("worlds." + name)) { if (PlotSquared.config.contains("worlds." + name)) {
PlotSquared.loadWorld(name, null); PlotSquared.getInstance().loadWorld(name, null);
} }
} }
lastWorld = null; lastWorld = null;

View File

@ -1,16 +1,5 @@
package com.intellectualcrafters.plot.listeners.worldedit; package com.intellectualcrafters.plot.listeners.worldedit;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -22,6 +11,16 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.bukkit.selections.Selection; import com.sk89q.worldedit.bukkit.selections.Selection;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
public class WEListener implements Listener { public class WEListener implements Listener {
@ -138,7 +137,7 @@ public class WEListener implements Listener {
public boolean onPlayerCommand(final PlayerCommandPreprocessEvent e) { public boolean onPlayerCommand(final PlayerCommandPreprocessEvent e) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(p); final PlotPlayer pp = BukkitUtil.getPlayer(p);
if (!PlotSquared.isPlotWorld(p.getWorld().getName())) { if (!PlotSquared.getInstance().isPlotWorld(p.getWorld().getName())) {
return true; return true;
} }
String cmd = e.getMessage().toLowerCase(); String cmd = e.getMessage().toLowerCase();

View File

@ -1,7 +1,5 @@
package com.intellectualcrafters.plot.listeners.worldedit; package com.intellectualcrafters.plot.listeners.worldedit;
import java.util.HashSet;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -15,11 +13,13 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.eventbus.Subscribe;
import java.util.HashSet;
public class WESubscriber { public class WESubscriber {
@Subscribe(priority=Priority.VERY_EARLY) @Subscribe(priority=Priority.VERY_EARLY)
public void onEditSession(EditSessionEvent event) { public void onEditSession(EditSessionEvent event) {
String world = event.getWorld().getName(); String world = event.getWorld().getName();
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.getInstance().isPlotWorld(world)) {
return; return;
} }
Actor actor = event.getActor(); Actor actor = event.getActor();

View File

@ -20,30 +20,29 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.util.ChunkManager;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.util.ChunkManager;
public abstract class PlotGenerator extends ChunkGenerator { public abstract class PlotGenerator extends ChunkGenerator {
private boolean loaded = false;
private short[][] result;
public int X;
public int Z;
private PseudoRandom random = new PseudoRandom();
public static short[][][] CACHE_I = null; public static short[][][] CACHE_I = null;
public static short[][][] CACHE_J = null; public static short[][][] CACHE_J = null;
public int X;
public int Z;
private boolean loaded = false;
private short[][] result;
private PseudoRandom random = new PseudoRandom();
public PlotGenerator(String world) { public PlotGenerator(String world) {
WorldEvents.lastWorld = world; WorldEvents.lastWorld = world;
@ -72,8 +71,8 @@ public abstract class PlotGenerator extends ChunkGenerator {
public List<BlockPopulator> getDefaultPopulators(World world) { public List<BlockPopulator> getDefaultPopulators(World world) {
try { try {
if (!loaded) { if (!loaded) {
PlotSquared.loadWorld(WorldEvents.getName(world), this); PlotSquared.getInstance().loadWorld(WorldEvents.getName(world), this);
PlotWorld plotworld = PlotSquared.getPlotWorld(WorldEvents.getName(world)); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(WorldEvents.getName(world));
if (!plotworld.MOB_SPAWNING) { if (!plotworld.MOB_SPAWNING) {
if (!plotworld.SPAWN_EGGS) { if (!plotworld.SPAWN_EGGS) {
world.setSpawnFlags(false, false); world.setSpawnFlags(false, false);
@ -104,7 +103,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) { public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
try { try {
if (!loaded) { if (!loaded) {
PlotSquared.loadWorld(WorldEvents.getName(world), this); PlotSquared.getInstance().loadWorld(WorldEvents.getName(world), this);
loaded = true; loaded = true;
} }
final int prime = 13; final int prime = 13;
@ -116,7 +115,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
this.X = cx << 4; this.X = cx << 4;
this.Z = cz << 4; this.Z = cz << 4;
if (ChunkManager.FORCE_PASTE) { if (ChunkManager.FORCE_PASTE) {
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world.getName());
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME); Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
@ -243,5 +242,6 @@ public abstract class PlotGenerator extends ChunkGenerator {
* Feel free to extend BukkitSetupUtils and customize world creation * Feel free to extend BukkitSetupUtils and customize world creation
* @param object * @param object
*/ */
public void processSetup(SetupObject object) {}; public void processSetup(SetupObject object) {
}
} }

View File

@ -1,41 +1,28 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class ClusterManager { public class ClusterManager {
public static HashMap<String, HashSet<PlotCluster>> clusters; public static HashMap<String, HashSet<PlotCluster>> clusters;
private static HashSet<String> regenerating = new HashSet<>();
public static PlotCluster last; public static PlotCluster last;
private static HashSet<String> regenerating = new HashSet<>();
public static boolean contains(final PlotCluster cluster, final PlotId id) { public static boolean contains(final PlotCluster cluster, final PlotId id) {
if ((cluster.getP1().x <= id.x) && (cluster.getP1().y <= id.y) && (cluster.getP2().x >= id.x) && (cluster.getP2().y >= id.y)) { return (cluster.getP1().x <= id.x) && (cluster.getP1().y <= id.y) && (cluster.getP2().x >= id.x) && (cluster.getP2().y >= id.y);
return true;
}
return false;
} }
public static HashSet<PlotCluster> getClusters(final World world) { public static HashSet<PlotCluster> getClusters(final World world) {
@ -57,8 +44,8 @@ public class ClusterManager {
final PlotId center = getCenterPlot(cluster); final PlotId center = getCenterPlot(cluster);
toReturn = MainUtil.getPlotHome(cluster.world, center); toReturn = MainUtil.getPlotHome(cluster.world, center);
if (toReturn.getY() == 0) { if (toReturn.getY() == 0) {
final PlotManager manager = PlotSquared.getPlotManager(cluster.world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(cluster.world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(cluster.world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(cluster.world);
final Location loc = manager.getSignLoc(plotworld, MainUtil.getPlot(cluster.world, center)); final Location loc = manager.getSignLoc(plotworld, MainUtil.getPlot(cluster.world, center));
toReturn.setY(loc.getY()); toReturn.setY(loc.getY());
} }
@ -80,15 +67,15 @@ public class ClusterManager {
public static Location getClusterBottom(final PlotCluster cluster) { public static Location getClusterBottom(final PlotCluster cluster) {
final String world = cluster.world; final String world = cluster.world;
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
return manager.getPlotBottomLocAbs(plotworld, cluster.getP1()); return manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
} }
public static Location getClusterTop(final PlotCluster cluster) { public static Location getClusterTop(final PlotCluster cluster) {
final String world = cluster.world; final String world = cluster.world;
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
return manager.getPlotTopLocAbs(plotworld, cluster.getP2()); return manager.getPlotTopLocAbs(plotworld, cluster.getP2());
} }
@ -106,14 +93,11 @@ public class ClusterManager {
public static boolean contains(final PlotCluster cluster, final Location loc) { public static boolean contains(final PlotCluster cluster, final Location loc) {
final String world = loc.getWorld(); final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()); final Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
final Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1); final Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
if ((bot.getX() < loc.getX()) && (bot.getZ() < loc.getZ()) && (top.getX() > loc.getX()) && (top.getZ() > loc.getZ())) { return (bot.getX() < loc.getX()) && (bot.getZ() < loc.getZ()) && (top.getX() > loc.getX()) && (top.getZ() > loc.getZ());
return true;
}
return false;
} }
public static HashSet<PlotCluster> getIntersects(final String world, final PlotClusterId id) { public static HashSet<PlotCluster> getIntersects(final String world, final PlotClusterId id) {
@ -132,10 +116,7 @@ public class ClusterManager {
public static boolean intersects(final PlotCluster cluster, final PlotClusterId id) { public static boolean intersects(final PlotCluster cluster, final PlotClusterId id) {
final PlotId pos1 = cluster.getP1(); final PlotId pos1 = cluster.getP1();
final PlotId pos2 = cluster.getP2(); final PlotId pos2 = cluster.getP2();
if ((pos1.x <= id.pos2.x) && (pos2.x >= id.pos1.x) && (pos1.y <= id.pos2.y) && (pos2.y >= id.pos1.y)) { return (pos1.x <= id.pos2.x) && (pos2.x >= id.pos1.x) && (pos1.y <= id.pos2.y) && (pos2.y >= id.pos1.y);
return true;
}
return false;
} }
public static PlotCluster getCluster(final Plot plot) { public static PlotCluster getCluster(final Plot plot) {
@ -167,8 +148,8 @@ public class ClusterManager {
public static PlotCluster getCluster(final Location loc) { public static PlotCluster getCluster(final Location loc) {
final String world = loc.getWorld(); final String world = loc.getWorld();
PlotManager manager = PlotSquared.getPlotManager(world); PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
PlotId id = manager.getPlotIdAbs(PlotSquared.getPlotWorld(world), loc.getX(), loc.getY(), loc.getZ()); PlotId id = manager.getPlotIdAbs(PlotSquared.getInstance().getPlotWorld(world), loc.getX(), loc.getY(), loc.getZ());
if (id != null) { if (id != null) {
return getCluster(world, id); return getCluster(world, id);
} }
@ -229,12 +210,12 @@ public class ClusterManager {
int xw; int xw;
int zw; int zw;
final String world = loc.getWorld(); final String world = loc.getWorld();
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (plotworld == null) { if (plotworld == null) {
xw = 39; xw = 39;
zw = 39; zw = 39;
} else { } else {
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final Location al = manager.getPlotBottomLocAbs(plotworld, a); final Location al = manager.getPlotBottomLocAbs(plotworld, a);
final Location bl = manager.getPlotBottomLocAbs(plotworld, b); final Location bl = manager.getPlotBottomLocAbs(plotworld, b);
xw = bl.getX() - al.getX(); xw = bl.getX() - al.getX();
@ -254,7 +235,7 @@ public class ClusterManager {
int i = 0; int i = 0;
final Random rand = new Random(); final Random rand = new Random();
final World world = Bukkit.getWorld(cluster.world); final World world = Bukkit.getWorld(cluster.world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(cluster.world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(cluster.world);
final Location bot = getClusterBottom(cluster); final Location bot = getClusterBottom(cluster);
final Location top = getClusterTop(cluster); final Location top = getClusterTop(cluster);
final int minChunkX = bot.getX() >> 4; final int minChunkX = bot.getX() >> 4;

View File

@ -1,17 +1,5 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -19,16 +7,15 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.ClassicPlotManager; import com.intellectualcrafters.plot.generator.ClassicPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.io.File;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ExpireManager { public class ExpireManager {
public static ConcurrentHashMap<String, List<Plot>> expiredPlots = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, List<Plot>> expiredPlots = new ConcurrentHashMap<>();
@ -77,7 +64,7 @@ public class ExpireManager {
@Override @Override
public void run() { public void run() {
try { try {
for (final String world : PlotSquared.getPlotWorldsString()) { for (final String world : PlotSquared.getInstance().getPlotWorldsString()) {
if (!ExpireManager.updatingPlots.containsKey(world)) { if (!ExpireManager.updatingPlots.containsKey(world)) {
ExpireManager.updatingPlots.put(world, false); ExpireManager.updatingPlots.put(world, false);
} }
@ -117,17 +104,17 @@ public class ExpireManager {
MainUtil.sendMessage(player, C.PLOT_REMOVED_USER, plot.id.toString()); MainUtil.sendMessage(player, C.PLOT_REMOVED_USER, plot.id.toString());
} }
} }
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
if (manager == null) { if (manager == null) {
PlotSquared.log("&7[&5Expire&dManager&7] &cThis is a friendly reminder to create or delete " + world +" as it is currently setup incorrectly"); PlotSquared.log("&7[&5Expire&dManager&7] &cThis is a friendly reminder to create or delete " + world +" as it is currently setup incorrectly");
expiredPlots.get(world).remove(plot); expiredPlots.get(world).remove(plot);
return; return;
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
RunnableVal run = new RunnableVal<Integer>() { RunnableVal run = new RunnableVal<Integer>() {
@Override @Override
public void run() { public void run() {
int changed = (Integer) this.value; int changed = this.value;
if (Settings.MIN_BLOCKS_CHANGED_IGNORED > 0 || Settings.MIN_BLOCKS_CHANGED > 0 && manager instanceof ClassicPlotManager) { if (Settings.MIN_BLOCKS_CHANGED_IGNORED > 0 || Settings.MIN_BLOCKS_CHANGED > 0 && manager instanceof ClassicPlotManager) {
if (changed >= Settings.MIN_BLOCKS_CHANGED && Settings.MIN_BLOCKS_CHANGED > 0) { if (changed >= Settings.MIN_BLOCKS_CHANGED && Settings.MIN_BLOCKS_CHANGED > 0) {
PlotSquared.log("&7[&5Expire&dManager&7] &bKeep flag added to: " + plot.id + (changed != -1 ? " (changed " + value + ")" : "")); PlotSquared.log("&7[&5Expire&dManager&7] &bKeep flag added to: " + plot.id + (changed != -1 ? " (changed " + value + ")" : ""));
@ -148,7 +135,7 @@ public class ExpireManager {
manager.clearPlot(plotworld, plot, false, null); manager.clearPlot(plotworld, plot, false, null);
MainUtil.removeSign(plot); MainUtil.removeSign(plot);
DBFunc.delete(world, plot); DBFunc.delete(world, plot);
PlotSquared.removePlot(world, plot.id, false); PlotSquared.getInstance().removePlot(world, plot.id, false);
expiredPlots.get(world).remove(plot); expiredPlots.get(world).remove(plot);
PlotSquared.log("&7[&5Expire&dManager&7] &cDeleted expired plot: " + plot.id + (changed != -1 ? " (changed " + value + ")" : "")); PlotSquared.log("&7[&5Expire&dManager&7] &cDeleted expired plot: " + plot.id + (changed != -1 ? " (changed " + value + ")" : ""));
PlotSquared.log("&3 - World: " + plot.world); PlotSquared.log("&3 - World: " + plot.world);
@ -228,7 +215,7 @@ public class ExpireManager {
} }
public static List<Plot> getOldPlots(final String world) { public static List<Plot> getOldPlots(final String world) {
final Collection<Plot> plots = PlotSquared.getPlots(world).values(); final Collection<Plot> plots = PlotSquared.getInstance().getPlots(world).values();
final List<Plot> toRemove = new ArrayList<>(); final List<Plot> toRemove = new ArrayList<>();
Iterator<Plot> iter = plots.iterator(); Iterator<Plot> iter = plots.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {

View File

@ -20,31 +20,20 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
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.object.*;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
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.object.BlockLoc;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
/** /**
* plot functions * plot functions
* *
@ -55,13 +44,13 @@ public class MainUtil {
public static boolean canSendChunk = false; public static boolean canSendChunk = false;
public static boolean canSetFast = true; public static boolean canSetFast = true;
public static ArrayList<String> runners_p = new ArrayList<>(); public static ArrayList<String> runners_p = new ArrayList<>();
static long state = 1;
public static HashMap<String, PlotId> lastPlot = new HashMap<>(); public static HashMap<String, PlotId> lastPlot = new HashMap<>();
public static HashMap<String, Integer> worldBorder = new HashMap<>(); public static HashMap<String, Integer> worldBorder = new HashMap<>();
static long state = 1;
static PseudoRandom random = new PseudoRandom(); static PseudoRandom random = new PseudoRandom();
public static boolean isPlotArea(final Location location) { public static boolean isPlotArea(final Location location) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(location.getWorld());
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
return ClusterManager.getCluster(location) != null; return ClusterManager.getCluster(location) != null;
} }
@ -101,21 +90,21 @@ public class MainUtil {
} }
else { else {
if (worldname == null) { if (worldname == null) {
if (PlotSquared.getPlotWorlds().size() == 0) { if (PlotSquared.getInstance().getPlotWorlds().size() == 0) {
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD); if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
return null; return null;
} }
worldname = PlotSquared.getPlotWorlds().iterator().next(); worldname = PlotSquared.getInstance().getPlotWorlds().iterator().next();
} }
for (Plot p : PlotSquared.getPlots(worldname).values()) { for (Plot p : PlotSquared.getInstance().getPlots(worldname).values()) {
String name = p.settings.getAlias(); String name = p.settings.getAlias();
if (name.length() != 0 && name.equalsIgnoreCase(arg)) { if (name.length() != 0 && name.equalsIgnoreCase(arg)) {
return p; return p;
} }
} }
for (String world : PlotSquared.getPlotWorlds()) { for (String world : PlotSquared.getInstance().getPlotWorlds()) {
if (!world.endsWith(worldname)) { if (!world.endsWith(worldname)) {
for (Plot p : PlotSquared.getPlots(world).values()) { for (Plot p : PlotSquared.getInstance().getPlots(world).values()) {
String name = p.settings.getAlias(); String name = p.settings.getAlias();
if (name.length() != 0 && name.equalsIgnoreCase(arg)) { if (name.length() != 0 && name.equalsIgnoreCase(arg)) {
return p; return p;
@ -124,7 +113,7 @@ public class MainUtil {
} }
} }
} }
if (worldname == null || !PlotSquared.isPlotWorld(worldname)) { if (worldname == null || !PlotSquared.getInstance().isPlotWorld(worldname)) {
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD); if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
System.out.print("INVALID WORLD: "); System.out.print("INVALID WORLD: ");
return null; return null;
@ -148,7 +137,7 @@ public class MainUtil {
* @return boolean * @return boolean
*/ */
public static boolean mergePlots(final PlotPlayer player, final String world, final ArrayList<PlotId> plotIds) { public static boolean mergePlots(final PlotPlayer player, final String world, final ArrayList<PlotId> plotIds) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY) { if ((EconHandler.manager != null) && plotworld.USE_ECONOMY) {
final double cost = plotIds.size() * plotworld.MERGE_PRICE; final double cost = plotIds.size() * plotworld.MERGE_PRICE;
if (cost > 0d) { if (cost > 0d) {
@ -172,11 +161,11 @@ public class MainUtil {
if (!result) { if (!result) {
return false; return false;
} }
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
manager.startPlotUnlink(plotworld, ids); manager.startPlotUnlink(plotworld, ids);
for (final PlotId id : ids) { for (final PlotId id : ids) {
final Plot myplot = PlotSquared.getPlots(world).get(id); final Plot myplot = PlotSquared.getInstance().getPlots(world).get(id);
if (plot == null) { if (plot == null) {
continue; continue;
} }
@ -223,7 +212,7 @@ public class MainUtil {
} }
public static boolean isPlotAreaAbs(final Location location) { public static boolean isPlotAreaAbs(final Location location) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(location.getWorld());
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
return ClusterManager.getClusterAbs(location) != null; return ClusterManager.getClusterAbs(location) != null;
} }
@ -231,19 +220,19 @@ public class MainUtil {
} }
public static boolean isPlotRoad(final Location location) { public static boolean isPlotRoad(final Location location) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(location.getWorld());
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
PlotCluster cluster = ClusterManager.getCluster(location); PlotCluster cluster = ClusterManager.getCluster(location);
if (cluster == null) { if (cluster == null) {
return false; return false;
} }
} }
PlotManager manager = PlotSquared.getPlotManager(location.getWorld()); PlotManager manager = PlotSquared.getInstance().getPlotManager(location.getWorld());
return manager.getPlotId(plotworld, location.getX(), location.getY(), location.getZ()) == null; return manager.getPlotId(plotworld, location.getX(), location.getY(), location.getZ()) == null;
} }
public static boolean isPlotArea(final Plot plot) { public static boolean isPlotArea(final Plot plot) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(plot.world);
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
return ClusterManager.getCluster(plot) != null; return ClusterManager.getCluster(plot) != null;
} }
@ -264,8 +253,8 @@ public class MainUtil {
public static ArrayList<PlotId> getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) { public static ArrayList<PlotId> getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) {
final Plot plot1 = PlotSquared.getPlots(world).get(pos1); final Plot plot1 = PlotSquared.getInstance().getPlots(world).get(pos1);
final Plot plot2 = PlotSquared.getPlots(world).get(pos2); final Plot plot2 = PlotSquared.getInstance().getPlots(world).get(pos2);
if (plot1 != null) { if (plot1 != null) {
pos1 = getBottomPlot(plot1).id; pos1 = getBottomPlot(plot1).id;
@ -304,7 +293,7 @@ public class MainUtil {
public static int getPlayerPlotCount(final String world, final PlotPlayer plr) { public static int getPlayerPlotCount(final String world, final PlotPlayer plr) {
final UUID uuid = plr.getUUID(); final UUID uuid = plr.getUUID();
int count = 0; int count = 0;
for (final Plot plot : PlotSquared.getPlots(world).values()) { for (final Plot plot : PlotSquared.getInstance().getPlots(world).values()) {
if (plot.hasOwner() && plot.owner.equals(uuid) && plot.countsTowardsMax) { if (plot.hasOwner() && plot.owner.equals(uuid) && plot.countsTowardsMax) {
count++; count++;
} }
@ -314,17 +303,17 @@ public class MainUtil {
public static int getPlayerPlotCount(final PlotPlayer plr) { public static int getPlayerPlotCount(final PlotPlayer plr) {
int count = 0; int count = 0;
for (final String world : PlotSquared.getPlotWorldsString()) { for (final String world : PlotSquared.getInstance().getPlotWorldsString()) {
count += getPlayerPlotCount(world, plr); count += getPlayerPlotCount(world, plr);
} }
return count; return count;
} }
public static Location getDefaultHome(Plot plot) { public static Location getDefaultHome(Plot plot) {
PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(plot.world);
if (plotworld.DEFAULT_HOME != null) { if (plotworld.DEFAULT_HOME != null) {
final Location bot = getPlotBottomLoc(plot.world, plot.id); final Location bot = getPlotBottomLoc(plot.world, plot.id);
final PlotManager manager = PlotSquared.getPlotManager(plot.world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(plot.world);
final int x; final int x;
final int z; final int z;
if (plotworld.DEFAULT_HOME.x == Integer.MAX_VALUE && plotworld.DEFAULT_HOME.z == Integer.MAX_VALUE) { if (plotworld.DEFAULT_HOME.x == Integer.MAX_VALUE && plotworld.DEFAULT_HOME.z == Integer.MAX_VALUE) {
@ -336,15 +325,15 @@ public class MainUtil {
x = bot.getX() + plotworld.DEFAULT_HOME.x; x = bot.getX() + plotworld.DEFAULT_HOME.x;
z = bot.getZ() + plotworld.DEFAULT_HOME.z; z = bot.getZ() + plotworld.DEFAULT_HOME.z;
} }
final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(plot.world), plot).getY()); final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getInstance().getPlotWorld(plot.world), plot).getY());
return new Location(plot.world, x, y + 1, z); return new Location(plot.world, x, y + 1, z);
} }
final Location top = getPlotTopLoc(plot.world, plot.id); final Location top = getPlotTopLoc(plot.world, plot.id);
final Location bot = getPlotBottomLoc(plot.world, plot.id); final Location bot = getPlotBottomLoc(plot.world, plot.id);
final int x = ((top.getX() - bot.getX()) / 2) + bot.getX(); final int x = ((top.getX() - bot.getX()) / 2) + bot.getX();
final int z = bot.getZ(); final int z = bot.getZ();
PlotManager manager = PlotSquared.getPlotManager(plot.world); PlotManager manager = PlotSquared.getInstance().getPlotManager(plot.world);
final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(plot.world), plot).getY()); final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getInstance().getPlotWorld(plot.world), plot).getY());
return new Location(plot.world, x, y + 1, z); return new Location(plot.world, x, y + 1, z);
} }
@ -355,7 +344,7 @@ public class MainUtil {
if (result) { if (result) {
final Location location; final Location location;
if (PlotSquared.getPlotWorld(plot.world).HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) { if (PlotSquared.getInstance().getPlotWorld(plot.world).HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) {
location = MainUtil.getPlotHome(bot.world, bot); location = MainUtil.getPlotHome(bot.world, bot);
} }
else { else {
@ -391,21 +380,21 @@ public class MainUtil {
public static int getBorder(final String worldname) { public static int getBorder(final String worldname) {
if (worldBorder.containsKey(worldname)) { if (worldBorder.containsKey(worldname)) {
PlotSquared.getPlotWorld(worldname); PlotSquared.getInstance().getPlotWorld(worldname);
return worldBorder.get(worldname) + 16; return worldBorder.get(worldname) + 16;
} }
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public static void setupBorder(final String world) { public static void setupBorder(final String world) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (!plotworld.WORLD_BORDER) { if (!plotworld.WORLD_BORDER) {
return; return;
} }
if (!worldBorder.containsKey(world)) { if (!worldBorder.containsKey(world)) {
worldBorder.put(world, 0); worldBorder.put(world, 0);
} }
for (final Plot plot : PlotSquared.getPlots(world).values()) { for (final Plot plot : PlotSquared.getInstance().getPlots(world).values()) {
updateWorldBorder(plot); updateWorldBorder(plot);
} }
} }
@ -495,8 +484,8 @@ public class MainUtil {
} }
final PlotId pos1 = plotIds.get(0); final PlotId pos1 = plotIds.get(0);
final PlotId pos2 = plotIds.get(plotIds.size() - 1); final PlotId pos2 = plotIds.get(plotIds.size() - 1);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
boolean result = EventUtil.manager.callMerge(world, getPlot(world, pos1), plotIds); boolean result = EventUtil.manager.callMerge(world, getPlot(world, pos1), plotIds);
if (!result) { if (!result) {
@ -509,7 +498,7 @@ public class MainUtil {
final boolean lx = x < pos2.x; final boolean lx = x < pos2.x;
final boolean ly = y < pos2.y; final boolean ly = y < pos2.y;
final PlotId id = new PlotId(x, y); final PlotId id = new PlotId(x, y);
final Plot plot = PlotSquared.getPlots(world).get(id); final Plot plot = PlotSquared.getInstance().getPlots(world).get(id);
Plot plot2 = null; Plot plot2 = null;
if (removeRoads) { if (removeRoads) {
removeSign(plot); removeSign(plot);
@ -523,7 +512,7 @@ public class MainUtil {
} }
} }
if (!plot.settings.getMerged(1)) { if (!plot.settings.getMerged(1)) {
plot2 = PlotSquared.getPlots(world).get(new PlotId(x + 1, y)); plot2 = PlotSquared.getInstance().getPlots(world).get(new PlotId(x + 1, y));
mergePlot(world, plot, plot2, removeRoads); mergePlot(world, plot, plot2, removeRoads);
plot.settings.setMerged(1, true); plot.settings.setMerged(1, true);
plot2.settings.setMerged(3, true); plot2.settings.setMerged(3, true);
@ -531,7 +520,7 @@ public class MainUtil {
} }
if (ly) { if (ly) {
if (!plot.settings.getMerged(2)) { if (!plot.settings.getMerged(2)) {
plot2 = PlotSquared.getPlots(world).get(new PlotId(x, y + 1)); plot2 = PlotSquared.getInstance().getPlots(world).get(new PlotId(x, y + 1));
mergePlot(world, plot, plot2, removeRoads); mergePlot(world, plot, plot2, removeRoads);
plot.settings.setMerged(2, true); plot.settings.setMerged(2, true);
plot2.settings.setMerged(0, true); plot2.settings.setMerged(0, true);
@ -542,7 +531,7 @@ public class MainUtil {
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) { for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y); final PlotId id = new PlotId(x, y);
final Plot plot = PlotSquared.getPlots(world).get(id); final Plot plot = PlotSquared.getInstance().getPlots(world).get(id);
DBFunc.setMerged(world, plot, plot.settings.getMerged()); DBFunc.setMerged(world, plot, plot.settings.getMerged());
} }
} }
@ -564,7 +553,7 @@ public class MainUtil {
ChunkManager.manager.regenerateRegion(pos1, pos2, null); ChunkManager.manager.regenerateRegion(pos1, pos2, null);
} }
else { else {
PlotSquared.getPlotManager(plot.world).removeRoadSouthEast(plotworld, plot); PlotSquared.getInstance().getPlotManager(plot.world).removeRoadSouthEast(plotworld, plot);
} }
} }
@ -582,7 +571,7 @@ public class MainUtil {
ChunkManager.manager.regenerateRegion(pos1, pos2, null); ChunkManager.manager.regenerateRegion(pos1, pos2, null);
} }
else { else {
PlotSquared.getPlotManager(plot.world).removeRoadEast(plotworld, plot); PlotSquared.getInstance().getPlotManager(plot.world).removeRoadEast(plotworld, plot);
} }
} }
@ -600,7 +589,7 @@ public class MainUtil {
ChunkManager.manager.regenerateRegion(pos1, pos2, null); ChunkManager.manager.regenerateRegion(pos1, pos2, null);
} }
else { else {
PlotSquared.getPlotManager(plot.world).removeRoadSouth(plotworld, plot); PlotSquared.getInstance().getPlotManager(plot.world).removeRoadSouth(plotworld, plot);
} }
} }
@ -614,7 +603,7 @@ public class MainUtil {
* @param greaterPlot * @param greaterPlot
*/ */
public static void mergePlot(final String world, final Plot lesserPlot, final Plot greaterPlot, final boolean removeRoads) { public static void mergePlot(final String world, final Plot lesserPlot, final Plot greaterPlot, final boolean removeRoads) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (lesserPlot.id.x.equals(greaterPlot.id.x)) { if (lesserPlot.id.x.equals(greaterPlot.id.x)) {
if (!lesserPlot.settings.getMerged(2)) { if (!lesserPlot.settings.getMerged(2)) {
lesserPlot.settings.setMerged(2, true); lesserPlot.settings.setMerged(2, true);
@ -636,8 +625,8 @@ public class MainUtil {
public static void removeSign(final Plot p) { public static void removeSign(final Plot p) {
final String world = p.world; final String world = p.world;
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
if (!plotworld.ALLOW_SIGNS) { if (!plotworld.ALLOW_SIGNS) {
return; return;
} }
@ -649,8 +638,8 @@ public class MainUtil {
if (name == null) { if (name == null) {
name = "unknown"; name = "unknown";
} }
final PlotManager manager = PlotSquared.getPlotManager(p.world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(p.world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(p.world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(p.world);
if (plotworld.ALLOW_SIGNS) { if (plotworld.ALLOW_SIGNS) {
final Location loc = manager.getSignLoc(plotworld, p); final Location loc = manager.getSignLoc(plotworld, p);
final String id = p.id.x + ";" + p.id.y; final String id = p.id.x + ";" + p.id.y;
@ -726,7 +715,7 @@ public class MainUtil {
final PlotId id_min = plots.get(0); final PlotId id_min = plots.get(0);
final PlotId id_max = plots.get(plots.size() - 1); final PlotId id_max = plots.get(plots.size() - 1);
for (final PlotId myid : plots) { for (final PlotId myid : plots) {
final Plot myplot = PlotSquared.getPlots(world).get(myid); final Plot myplot = PlotSquared.getInstance().getPlots(world).get(myid);
if ((myplot == null) || myplot.owner == null || !(myplot.owner.equals(uuid))) { if ((myplot == null) || myplot.owner == null || !(myplot.owner.equals(uuid))) {
return false; return false;
} }
@ -747,8 +736,8 @@ public class MainUtil {
return; return;
} }
final String world = plot.world; final String world = plot.world;
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final Location bot = manager.getPlotBottomLocAbs(plotworld, plot.id); final Location bot = manager.getPlotBottomLocAbs(plotworld, plot.id);
final Location top = manager.getPlotTopLocAbs(plotworld, plot.id); final Location top = manager.getPlotTopLocAbs(plotworld, plot.id);
final int border = worldBorder.get(plot.world); final int border = worldBorder.get(plot.world);
@ -768,7 +757,7 @@ public class MainUtil {
updateWorldBorder(plot); updateWorldBorder(plot);
} }
final Plot p = createPlotAbs(uuid, plot); final Plot p = createPlotAbs(uuid, plot);
final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(plot.world);
if (plotworld.AUTO_MERGE) { if (plotworld.AUTO_MERGE) {
autoMerge(plot.world, p, uuid); autoMerge(plot.world, p, uuid);
} }
@ -781,7 +770,7 @@ public class MainUtil {
public static Plot createPlotAbs(final UUID uuid, final Plot plot) { public static Plot createPlotAbs(final UUID uuid, final Plot plot) {
final String w = plot.world; final String w = plot.world;
final Plot p = new Plot(plot.id, uuid, new ArrayList<UUID>(), new ArrayList<UUID>(), w); final Plot p = new Plot(plot.id, uuid, new ArrayList<UUID>(), new ArrayList<UUID>(), w);
PlotSquared.updatePlot(p); PlotSquared.getInstance().updatePlot(p);
DBFunc.createPlotAndSettings(p); DBFunc.createPlotAndSettings(p);
return p; return p;
} }
@ -820,7 +809,7 @@ public class MainUtil {
} }
public static void clear(final String world, final Plot plot, final boolean isDelete, final Runnable whenDone) { public static void clear(final String world, final Plot plot, final boolean isDelete, final Runnable whenDone) {
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final int prime = 31; final int prime = 31;
int h = 1; int h = 1;
@ -828,7 +817,7 @@ public class MainUtil {
h = (prime * h) + pos1.getZ(); h = (prime * h) + pos1.getZ();
state = h; state = h;
System.currentTimeMillis(); System.currentTimeMillis();
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
runners.put(plot, 1); runners.put(plot, 1);
if (plotworld.TERRAIN != 0 || Settings.FAST_CLEAR) { if (plotworld.TERRAIN != 0 || Settings.FAST_CLEAR) {
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
@ -959,7 +948,7 @@ public class MainUtil {
final Plot plot = getPlot(w, plotid); final Plot plot = getPlot(w, plotid);
final BlockLoc home = plot.settings.getPosition(); final BlockLoc home = plot.settings.getPosition();
final Location bot = getPlotBottomLoc(w, plotid); final Location bot = getPlotBottomLoc(w, plotid);
final PlotManager manager = PlotSquared.getPlotManager(w); final PlotManager manager = PlotSquared.getInstance().getPlotManager(w);
if ((home == null) || ((home.x == 0) && (home.z == 0))) { if ((home == null) || ((home.x == 0) && (home.z == 0))) {
return getDefaultHome(plot); return getDefaultHome(plot);
} else { } else {
@ -992,8 +981,8 @@ public class MainUtil {
* @return Location top * @return Location top
*/ */
public static Location getPlotTopLocAbs(final String world, final PlotId id) { public static Location getPlotTopLocAbs(final String world, final PlotId id) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
return manager.getPlotTopLocAbs(plotworld, id); return manager.getPlotTopLocAbs(plotworld, id);
} }
@ -1007,8 +996,8 @@ public class MainUtil {
* @return Location bottom * @return Location bottom
*/ */
public static Location getPlotBottomLocAbs(final String world, final PlotId id) { public static Location getPlotBottomLocAbs(final String world, final PlotId id) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
return manager.getPlotBottomLocAbs(plotworld, id); return manager.getPlotBottomLocAbs(plotworld, id);
} }
@ -1034,12 +1023,12 @@ public class MainUtil {
* @return Location top of mega plot * @return Location top of mega plot
*/ */
public static Location getPlotTopLoc(final String world, PlotId id) { public static Location getPlotTopLoc(final String world, PlotId id) {
final Plot plot = PlotSquared.getPlots(world).get(id); final Plot plot = PlotSquared.getInstance().getPlots(world).get(id);
if (plot != null) { if (plot != null) {
id = getTopPlot(plot).id; id = getTopPlot(plot).id;
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
return manager.getPlotTopLocAbs(plotworld, id); return manager.getPlotTopLocAbs(plotworld, id);
} }
@ -1053,12 +1042,12 @@ public class MainUtil {
* @return Location bottom of mega plot * @return Location bottom of mega plot
*/ */
public static Location getPlotBottomLoc(final String world, PlotId id) { public static Location getPlotBottomLoc(final String world, PlotId id) {
final Plot plot = PlotSquared.getPlots(world).get(id); final Plot plot = PlotSquared.getInstance().getPlots(world).get(id);
if (plot != null) { if (plot != null) {
id = getBottomPlot(plot).id; id = getBottomPlot(plot).id;
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
return manager.getPlotBottomLocAbs(plotworld, id); return manager.getPlotBottomLocAbs(plotworld, id);
} }
@ -1087,18 +1076,15 @@ public class MainUtil {
} }
} }
} }
if (plot.owner != null) { return plot.owner == null;
return false;
}
return true;
} }
public static boolean isUnowned(final String world, final PlotId pos1, final PlotId pos2) { public static boolean isUnowned(final String world, final PlotId pos1, final PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) { for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y); final PlotId id = new PlotId(x, y);
if (PlotSquared.getPlots(world).get(id) != null) { if (PlotSquared.getInstance().getPlots(world).get(id) != null) {
if (PlotSquared.getPlots(world).get(id).owner != null) { if (PlotSquared.getInstance().getPlots(world).get(id).owner != null) {
return false; return false;
} }
} }
@ -1108,8 +1094,8 @@ public class MainUtil {
} }
public static boolean swap(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { public static boolean swap(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
Plot p1 = PlotSquared.getPlots(world).get(current); Plot p1 = PlotSquared.getInstance().getPlots(world).get(current);
Plot p2 = PlotSquared.getPlots(world).get(newPlot); Plot p2 = PlotSquared.getInstance().getPlots(world).get(newPlot);
if (p1==null || p2 == null || p1.owner == null || !p1.owner.equals(p2.owner)) { if (p1==null || p2 == null || p1.owner == null || !p1.owner.equals(p2.owner)) {
return false; return false;
} }
@ -1121,20 +1107,20 @@ public class MainUtil {
p1.id.y = p2.id.y.intValue(); p1.id.y = p2.id.y.intValue();
p2.id.x = temp.x; p2.id.x = temp.x;
p2.id.y = temp.y; p2.id.y = temp.y;
PlotSquared.getPlots(world).remove(p1.id); PlotSquared.getInstance().getPlots(world).remove(p1.id);
PlotSquared.getPlots(world).remove(p2.id); PlotSquared.getInstance().getPlots(world).remove(p2.id);
p1.id.recalculateHash(); p1.id.recalculateHash();
p2.id.recalculateHash(); p2.id.recalculateHash();
PlotSquared.getPlots(world).put(p1.id, p1); PlotSquared.getInstance().getPlots(world).put(p1.id, p1);
PlotSquared.getPlots(world).put(p2.id, p2); PlotSquared.getInstance().getPlots(world).put(p2.id, p2);
// Swap database // Swap database
DBFunc.dbManager.swapPlots(p2, p1); DBFunc.dbManager.swapPlots(p2, p1);
return true; return true;
} }
public static boolean swapData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { public static boolean swapData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
Plot p1 = PlotSquared.getPlots(world).get(current); Plot p1 = PlotSquared.getInstance().getPlots(world).get(current);
Plot p2 = PlotSquared.getPlots(world).get(newPlot); Plot p2 = PlotSquared.getInstance().getPlots(world).get(newPlot);
if (p1 == null || p1.owner == null) { if (p1 == null || p1.owner == null) {
if (p2 != null && p2.owner != null) { if (p2 != null && p2.owner != null) {
moveData(p2, p1, whenDone); moveData(p2, p1, whenDone);
@ -1155,12 +1141,12 @@ public class MainUtil {
p1.id.y = p2.id.y.intValue(); p1.id.y = p2.id.y.intValue();
p2.id.x = temp.x; p2.id.x = temp.x;
p2.id.y = temp.y; p2.id.y = temp.y;
PlotSquared.getPlots(world).remove(p1.id); PlotSquared.getInstance().getPlots(world).remove(p1.id);
PlotSquared.getPlots(world).remove(p2.id); PlotSquared.getInstance().getPlots(world).remove(p2.id);
p1.id.recalculateHash(); p1.id.recalculateHash();
p2.id.recalculateHash(); p2.id.recalculateHash();
PlotSquared.getPlots(world).put(p1.id, p1); PlotSquared.getInstance().getPlots(world).put(p1.id, p1);
PlotSquared.getPlots(world).put(p2.id, p2); PlotSquared.getInstance().getPlots(world).put(p2.id, p2);
// Swap database // Swap database
DBFunc.dbManager.swapPlots(p2, p1); DBFunc.dbManager.swapPlots(p2, p1);
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
@ -1184,12 +1170,12 @@ public class MainUtil {
final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id); final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
for (final PlotId id : selection) { for (final PlotId id : selection) {
DBFunc.movePlot(getPlot(plot1.world, new PlotId(id.x, id.y)), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); DBFunc.movePlot(getPlot(plot1.world, new PlotId(id.x, id.y)), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y)));
final Plot plot = PlotSquared.getPlots(plot1.world).get(id); final Plot plot = PlotSquared.getInstance().getPlots(plot1.world).get(id);
PlotSquared.getPlots(plot1.world).remove(id); PlotSquared.getInstance().getPlots(plot1.world).remove(id);
plot.id.x += offset_x; plot.id.x += offset_x;
plot.id.y += offset_y; plot.id.y += offset_y;
plot.id.recalculateHash(); plot.id.recalculateHash();
PlotSquared.getPlots(plot2.world).put(plot.id, plot); PlotSquared.getInstance().getPlots(plot2.world).put(plot.id, plot);
} }
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return true; return true;
@ -1214,12 +1200,12 @@ public class MainUtil {
for (final PlotId id : selection) { for (final PlotId id : selection) {
String worldOriginal = plot1.world; String worldOriginal = plot1.world;
PlotId idOriginal = new PlotId(id.x, id.y); PlotId idOriginal = new PlotId(id.x, id.y);
final Plot plot = PlotSquared.getPlots(plot1.world).get(id); final Plot plot = PlotSquared.getInstance().getPlots(plot1.world).get(id);
PlotSquared.getPlots(plot1.world).remove(id); PlotSquared.getInstance().getPlots(plot1.world).remove(id);
plot.id.x += offset_x; plot.id.x += offset_x;
plot.id.y += offset_y; plot.id.y += offset_y;
plot.id.recalculateHash(); plot.id.recalculateHash();
PlotSquared.getPlots(plot2.world).put(plot.id, plot); PlotSquared.getInstance().getPlots(plot2.world).put(plot.id, plot);
DBFunc.movePlot(getPlot(worldOriginal, idOriginal), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); DBFunc.movePlot(getPlot(worldOriginal, idOriginal), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y)));
} }
ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() { ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() {
@ -1282,7 +1268,7 @@ public class MainUtil {
DBFunc.setDenied(world, plot, denied); DBFunc.setDenied(world, plot, denied);
} }
} }
PlotSquared.getPlots(world).put(plot.id, plot); PlotSquared.getInstance().getPlots(world).put(plot.id, plot);
} }
ChunkManager.manager.copyRegion(bot1, top, bot2, whenDone); ChunkManager.manager.copyRegion(bot1, top, bot2, whenDone);
return true; return true;
@ -1449,14 +1435,14 @@ public class MainUtil {
public static Plot getBottomPlot(final Plot plot) { public static Plot getBottomPlot(final Plot plot) {
if (plot.settings.getMerged(0)) { if (plot.settings.getMerged(0)) {
final Plot p = PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y - 1)); final Plot p = PlotSquared.getInstance().getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y - 1));
if (p == null) { if (p == null) {
return plot; return plot;
} }
return getBottomPlot(p); return getBottomPlot(p);
} }
if (plot.settings.getMerged(3)) { if (plot.settings.getMerged(3)) {
final Plot p = PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x - 1, plot.id.y)); final Plot p = PlotSquared.getInstance().getPlots(plot.world).get(new PlotId(plot.id.x - 1, plot.id.y));
if (p == null) { if (p == null) {
return plot; return plot;
} }
@ -1467,14 +1453,14 @@ public class MainUtil {
public static Plot getTopPlot(final Plot plot) { public static Plot getTopPlot(final Plot plot) {
if (plot.settings.getMerged(2)) { if (plot.settings.getMerged(2)) {
final Plot p = PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y + 1)); final Plot p = PlotSquared.getInstance().getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y + 1));
if (p == null) { if (p == null) {
return plot; return plot;
} }
return getTopPlot(p); return getTopPlot(p);
} }
if (plot.settings.getMerged(1)) { if (plot.settings.getMerged(1)) {
final Plot p = PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x + 1, plot.id.y)); final Plot p = PlotSquared.getInstance().getPlots(plot.world).get(new PlotId(plot.id.x + 1, plot.id.y));
if (p == null) { if (p == null) {
return plot; return plot;
} }
@ -1501,8 +1487,8 @@ public class MainUtil {
if (id == null) { if (id == null) {
return null; return null;
} }
if (PlotSquared.getPlots(world).containsKey(id)) { if (PlotSquared.getInstance().getPlots(world).containsKey(id)) {
return PlotSquared.getPlots(world).get(id); return PlotSquared.getInstance().getPlots(world).get(id);
} }
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world); return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
} }
@ -1514,11 +1500,11 @@ public class MainUtil {
*/ */
public static PlotId getPlotAbs(final Location loc) { public static PlotId getPlotAbs(final Location loc) {
final String world = loc.getWorld(); final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
if (manager == null) { if (manager == null) {
return null; return null;
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
return manager.getPlotIdAbs(plotworld, loc.getX(), loc.getY(), loc.getZ()); return manager.getPlotIdAbs(plotworld, loc.getX(), loc.getY(), loc.getZ());
} }
@ -1529,11 +1515,11 @@ public class MainUtil {
*/ */
public static PlotId getPlotId(final Location loc) { public static PlotId getPlotId(final Location loc) {
final String world = loc.getWorld(); final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world); final PlotManager manager = PlotSquared.getInstance().getPlotManager(world);
if (manager == null) { if (manager == null) {
return null; return null;
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(world); final PlotWorld plotworld = PlotSquared.getInstance().getPlotWorld(world);
final PlotId id = manager.getPlotId(plotworld, loc.getX(), loc.getY(), loc.getZ()); final PlotId id = manager.getPlotId(plotworld, loc.getX(), loc.getY(), loc.getZ());
if ((id != null) && (plotworld.TYPE == 2)) { if ((id != null) && (plotworld.TYPE == 2)) {
if (ClusterManager.getCluster(world, id) == null) { if (ClusterManager.getCluster(world, id) == null) {

View File

@ -20,18 +20,17 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/** /**
* Functions involving players, plots and locations. * Functions involving players, plots and locations.
@ -111,7 +110,7 @@ public class BukkitPlayerFunctions {
* @return boolean * @return boolean
*/ */
public static Plot getCurrentPlot(final Player player) { public static Plot getCurrentPlot(final Player player) {
if (!PlotSquared.isPlotWorld(player.getWorld().getName())) { if (!PlotSquared.getInstance().isPlotWorld(player.getWorld().getName())) {
return null; return null;
} }
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(player)); final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(player));
@ -133,7 +132,7 @@ public class BukkitPlayerFunctions {
* @return boolean * @return boolean
*/ */
public static Set<Plot> getPlayerPlots(final String world, final Player plr) { public static Set<Plot> getPlayerPlots(final String world, final Player plr) {
final Set<Plot> p = PlotSquared.getPlots(world, plr.getName()); final Set<Plot> p = PlotSquared.getInstance().getPlots(world, plr.getName());
if (p == null) { if (p == null) {
return new HashSet<>(); return new HashSet<>();
} }

View File

@ -1,21 +1,20 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.io.IOException;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import java.io.IOException;
import java.util.Map.Entry;
public class BukkitSetupUtils extends SetupUtils { public class BukkitSetupUtils extends SetupUtils {
@ -29,7 +28,7 @@ public class BukkitSetupUtils extends SetupUtils {
if (plugin.isEnabled()) { if (plugin.isEnabled()) {
final ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, ""); final ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
if (generator != null) { if (generator != null) {
PlotSquared.removePlotWorld(testWorld); PlotSquared.getInstance().removePlotWorld(testWorld);
final String name = plugin.getDescription().getName(); final String name = plugin.getDescription().getName();
// final PlotGenerator pgen = (PlotGenerator) generator; // final PlotGenerator pgen = (PlotGenerator) generator;
// if (pgen.getPlotManager() instanceof SquarePlotManager) { // if (pgen.getPlotManager() instanceof SquarePlotManager) {

View File

@ -1,22 +1,21 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.util.SetupUtils;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.util.SetupUtils;
public class SetGenCB { public class SetGenCB {
public static void setGenerator(World world) throws Exception { public static void setGenerator(World world) throws Exception {
SetupUtils.manager.updateGenerators(); SetupUtils.manager.updateGenerators();
PlotSquared.removePlotWorldAbs(world.getName()); PlotSquared.getInstance().removePlotWorldAbs(world.getName());
ChunkGenerator gen = world.getGenerator(); ChunkGenerator gen = world.getGenerator();
if (gen == null) { if (gen == null) {
return; return;
@ -50,6 +49,6 @@ public class SetGenCB {
} }
} }
} }
PlotSquared.loadWorld(world.getName(), null); PlotSquared.getInstance().loadWorld(world.getName(), null);
} }
} }

View File

@ -1,52 +1,41 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.io.InputSupplier; import com.google.common.io.InputSupplier;
import com.google.common.io.OutputSupplier;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.NbtFactory; import com.intellectualcrafters.plot.util.NbtFactory;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.NbtFactory.NbtCompound; import com.intellectualcrafters.plot.util.NbtFactory.NbtCompound;
import com.intellectualcrafters.plot.util.NbtFactory.StreamOptions; import com.intellectualcrafters.plot.util.NbtFactory.StreamOptions;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import org.bukkit.Bukkit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
public class UUIDHandler { public class UUIDHandler {
public static boolean CACHED = false;
public static UUIDWrapper uuidWrapper = null;
public static HashMap<String, PlotPlayer> players = new HashMap<>();
/** /**
* Map containing names and UUIDs * Map containing names and UUIDs
* *
* @see com.google.common.collect.BiMap * @see com.google.common.collect.BiMap
*/ */
private final static BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>()); private final static BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
public static boolean CACHED = false;
public static UUIDWrapper uuidWrapper = null;
public static HashMap<String, PlotPlayer> players = new HashMap<>();
public static void add(final StringWrapper name, final UUID uuid) { public static void add(final StringWrapper name, final UUID uuid) {
if ((uuid == null) || (name == null)) { if ((uuid == null) || (name == null)) {
@ -101,7 +90,7 @@ public class UUIDHandler {
public static HashSet<UUID> getAllUUIDS() { public static HashSet<UUID> getAllUUIDS() {
HashSet<UUID> uuids = new HashSet<UUID>(); HashSet<UUID> uuids = new HashSet<UUID>();
for (Plot plot : PlotSquared.getPlotsRaw()) { for (Plot plot : PlotSquared.getInstance().getPlotsRaw()) {
for (UUID uuid : plot.trusted) { for (UUID uuid : plot.trusted) {
uuids.add(uuid); uuids.add(uuid);
} }