diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index f8112e478..16e9ca76c 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -213,7 +213,7 @@ public interface IPlotMain { /** * */ - GeneratorWrapper wrapPlotGenerator(String world, IndependentPlotGenerator generator); + GeneratorWrapper wrapPlotGenerator(IndependentPlotGenerator generator); /** * Register the chunk processor which will clean out chunks that have too many blockstates or entities diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index f58b74d1e..bef02243c 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1294,7 +1294,6 @@ public class PS { public Collection getPlots(final String world) { final HashSet set = new HashSet<>(); - foreachPlotArea(null); foreachPlotArea(world, new RunnableVal() { @Override public void run(PlotArea value) { @@ -2436,6 +2435,21 @@ public class PS { } } + public void foreachPlotRaw(final RunnableVal runnable) { + for (PlotArea area : plotareas) { + for (Plot plot : area.getPlots()) { + runnable.run(plot); + } + } + if (plots_tmp != null) { + for (Entry> entry : plots_tmp.entrySet()) { + for (Entry entry2 : entry.getValue().entrySet()) { + runnable.run(entry2.getValue()); + } + } + } + } + public void foreachBasePlot(RunnableVal run) { for (PlotArea area : plotareas) { area.foreachBasePlot(run); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Area.java b/src/main/java/com/intellectualcrafters/plot/commands/Area.java index 6a47420da..1a8ce9151 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -131,8 +131,8 @@ public class Area extends SubCommand { if (area.TERRAIN != 3) { ChunkManager.largeRegionTask(world, region, new RunnableVal() { @Override - public void run(ChunkLoc value) { - AugmentedUtils.generate(world, value.x, value.z); + public void run(final ChunkLoc value) { + AugmentedUtils.generate(world, value.x, value.z, null); } }, null); } @@ -415,7 +415,7 @@ public class Area extends SubCommand { ChunkManager.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal() { @Override public void run(ChunkLoc value) { - AugmentedUtils.generate(area.worldname, value.x, value.z); + AugmentedUtils.generate(area.worldname, value.x, value.z, null); } }, null); return true; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 5632b9ecb..6ccad5e9a 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -21,12 +21,9 @@ package com.intellectualcrafters.plot.commands; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.sql.Timestamp; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -47,7 +44,6 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.HybridUtils; -import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; @@ -158,7 +154,7 @@ public class DebugExec extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String... args) { - final List allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check"); + final List allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen"); if (args.length > 0) { final String arg = args[0].toLowerCase(); String script; @@ -313,46 +309,6 @@ public class DebugExec extends SubCommand { MainUtil.sendMessage(player, "GMT: " + date.toGMTString()); MainUtil.sendMessage(player, "Local: " + date.toLocaleString()); return true; - case "trim-check": - if (args.length != 2) { - MainUtil.sendMessage(player, "Use /plot debugexec trim-check "); - MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim"); - return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run"); - } - final String world = args[1]; - if (!WorldUtil.IMP.isWorld(world) || !PS.get().hasPlotArea(args[1])) { - return MainUtil.sendMessage(player, "Invalid world: " + args[1]); - } - final ArrayList empty = new ArrayList<>(); - final boolean result = Trim.getTrimRegions(empty, world, new Runnable() { - @Override - public void run() { - Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:"); - Trim.sendMessage(" - MCA #: " + empty.size()); - Trim.sendMessage(" - CHUNKS: " + empty.size() * 1024 + " (max)"); - Trim.sendMessage("Exporting log for manual approval..."); - final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt"); - try { - PrintWriter writer = new PrintWriter(file); - for (final ChunkLoc loc : empty) { - writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca"); - } - writer.close(); - Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'"); - } catch (final FileNotFoundException e) { - e.printStackTrace(); - Trim.sendMessage("File failed to save! :("); - } - Trim.sendMessage("How to get the chunk coords from a region file:"); - Trim.sendMessage(" - Locate the x,z values for the region file (the two numbers which are separated by a dot)"); - Trim.sendMessage(" - Multiply each number by 32; this gives you the starting position"); - Trim.sendMessage(" - Add 31 to each number to get the end position"); - } - }); - if (!result) { - MainUtil.sendMessage(player, "Trim task already started!"); - } - return result; case "h": case "he": case "?": diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java index 1343a9c35..7564075c4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java @@ -35,7 +35,7 @@ import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration(command = "deny", aliases = { "d" }, description = "Deny a user from a plot", usage = "/plot deny ", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE) +@CommandDeclaration(command = "deny", aliases = { "d", "ban" }, description = "Deny a user from a plot", usage = "/plot deny ", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE) public class Deny extends SubCommand { public Deny() { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Grant.java b/src/main/java/com/intellectualcrafters/plot/commands/Grant.java index 4eff905ec..a577ee8f0 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Grant.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Grant.java @@ -1,78 +1,60 @@ package com.intellectualcrafters.plot.commands; +import java.util.UUID; + import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.ByteArrayUtilities; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.UUID; - @CommandDeclaration( command = "grant", category = CommandCategory.CLAIMING, - usage = "/plot grant [...]", + usage = "/plot grant [player]", permission = "plots.grant", requiredType = RequiredType.NONE ) public class Grant extends SubCommand { - - void grantPlayer(PlotPlayer plr, String enteredName) { - PlotPlayer player; - if (enteredName.length() > 16) { - player = PlotPlayer.wrap(UUID.fromString(enteredName)); - } else { - player = UUIDHandler.getPlayer(enteredName); - } - if (player == null) { - sendMessage(plr, C.GRANTED_PLOT_FAILED, "Player not found"); - } else { - int n = 1; - if (player.hasPersistentMeta("grantedPlots")) { - n += ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots")); - } - player.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(n)); - sendMessage(plr, C.GRANTED_PLOT, enteredName); - } - } - @Override - public boolean onCommand(PlotPlayer plr, String[] arguments) { - if (plr == null || plr instanceof ConsolePlayer) { - if (arguments.length != 1) { - MainUtil.sendMessage(null, "Usage: /plot grant "); - } else { - grantPlayer(null, arguments[0]); - return true; - } - } else { - if (arguments.length < 1) { - arguments = new String[] { "check" }; - } - switch (arguments[0]) { - case "check": { - int grantedPlots = 0; - if (plr.hasPersistentMeta("grantedPlots")) { - grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); - } - return sendMessage(plr, C.GRANTED_PLOTS, "" + grantedPlots); + public boolean onCommand(final PlotPlayer plr, final String[] args) { + final String arg0 = args[0].toLowerCase(); + switch (arg0) { + case "add": + case "check": + if (Permissions.hasPermission(plr, "plots.grant." + arg0)) { + C.NO_PERMISSION.send(plr, "plots.grant." + arg0); + return false; } - case "add": { - if (!plr.hasPermission("plots.grant.add")) { - return sendMessage(plr, C.NO_PERMISSION, "plots.grant.add"); + if (args.length > 2) { + break; + } + final UUID uuid = args.length == 2 ? UUIDHandler.getUUIDFromString(args[1]) : plr.getUUID(); + if (uuid == null) { + C.INVALID_PLAYER.send(plr, args[1]); + return false; + } + MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal() { + @Override + public void run(byte[] array) { + if (arg0.equals("check")) { // check + int granted = array == null ? 0 : ByteArrayUtilities.bytesToInteger(array); + C.GRANTED_PLOTS.send(plr, granted); + } else { // add + int amount = 1 + (array == null ? 0 : ByteArrayUtilities.bytesToInteger(array)); + boolean replace = array != null; + DBFunc.dbManager.addPersistentMeta(uuid, "grantedPlots", ByteArrayUtilities.integerToBytes(amount), replace); + } } - if (arguments.length < 2) { - plr.sendMessage("&cUsage: /plot grant add "); - } else { - grantPlayer(plr, arguments[1]); - } - } break; - default: return onCommand(plr, new String[] { "check" }); - } + }); + return true; } - return true; + C.COMMAND_SYNTAX.send(plr, getUsage()); + return false; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index fdd1af3f9..dcbfa847f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -20,20 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.object.ChunkLoc; -import com.intellectualcrafters.plot.object.ConsolePlayer; -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.ChunkManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.WorldUtil; -import com.plotsquared.general.commands.CommandDeclaration; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -42,19 +28,34 @@ import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import com.intellectualcrafters.plot.PS; +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.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.RunnableVal2; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.WorldUtil; +import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( command = "trim", permission = "plots.admin", description = "Delete unmodified portions of your plotworld", -usage = "/plot trim", +usage = "/plot trim [regenerate]", requiredType = RequiredType.CONSOLE, category = CommandCategory.ADMINISTRATION) public class Trim extends SubCommand { - public static boolean TASK = false; public static ArrayList expired = null; - private static int TASK_ID = 0; public static boolean getBulkRegions(final ArrayList empty, final String world, final Runnable whenDone) { if (Trim.TASK) { @@ -110,114 +111,127 @@ public class Trim extends SubCommand { return true; } - public static boolean getTrimRegions(final ArrayList empty, final String world, final Runnable whenDone) { - if (Trim.TASK) { + /** + * Runs the result task with the parameters (viable, nonViable).
+ * @param world + * @param result (viable = .mcr to trim, nonViable = .mcr keep) + * @return + */ + public static boolean getTrimRegions(final String world, final RunnableVal2, Set> result) { + if (result == null) { return false; } - System.currentTimeMillis(); - sendMessage("Collecting region data..."); + MainUtil.sendMessage(null, "Collecting region data..."); final ArrayList plots = new ArrayList<>(); plots.addAll(PS.get().getPlots(world)); - final HashSet chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); - sendMessage(" - MCA #: " + chunks.size()); - sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)"); - sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes"); - Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() { + result.value1 = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); + result.value2 = new HashSet(); + MainUtil.sendMessage(null, " - MCA #: " + result.value1.size()); + MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)"); + MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs"); + TaskManager.objectTask(plots, new RunnableVal() { @Override - public void run() { - final long start = System.currentTimeMillis(); - while ((System.currentTimeMillis() - start) < 50) { - if (plots.isEmpty()) { - empty.addAll(chunks); - Trim.TASK = false; - TaskManager.runTaskAsync(whenDone); - PS.get().TASK.cancelTask(Trim.TASK_ID); - return; - } - final Plot plot = plots.remove(0); - - final Location pos1 = plot.getBottom(); - final Location pos2 = plot.getTop(); - - final int ccx1 = (pos1.getX() >> 9); - final int ccz1 = (pos1.getZ() >> 9); - final int ccx2 = (pos2.getX() >> 9); - final int ccz2 = (pos2.getZ() >> 9); - - for (int x = ccx1; x <= ccx2; x++) { - for (int z = ccz1; z <= ccz2; z++) { - chunks.remove(new ChunkLoc(x, z)); + public void run(Plot plot) { + final Location pos1 = plot.getBottom(); + final Location pos2 = plot.getTop(); + final int ccx1 = (pos1.getX() >> 9); + final int ccz1 = (pos1.getZ() >> 9); + final int ccx2 = (pos2.getX() >> 9); + final int ccz2 = (pos2.getZ() >> 9); + for (int x = ccx1; x <= ccx2; x++) { + for (int z = ccz1; z <= ccz2; z++) { + ChunkLoc loc = new ChunkLoc(x, z); + if (result.value1.remove(loc)) { + result.value2.add(loc); } } } } - }, 20); - Trim.TASK = true; + }, result); return true; } - public static void deleteChunks(final String world, final ArrayList chunks, final Runnable whenDone) { - ChunkManager.manager.deleteRegionFiles(world, chunks, whenDone); - } - - public static void sendMessage(final String message) { - ConsolePlayer.getConsole().sendMessage("&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; - } - } - + private static volatile boolean TASK = false; + @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { - 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"); - return false; - } - if (arg.equals("all")) { - MainUtil.sendMessage(plr, "/plot trim all &l"); - return false; - } - MainUtil.sendMessage(plr, C.TRIM_SYNTAX); + if (args.length == 0) { + C.COMMAND_SYNTAX.send(plr, getUsage()); 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]; + final String world = args[0]; if (!WorldUtil.IMP.isWorld(world) || (!PS.get().hasPlotArea(world))) { MainUtil.sendMessage(plr, C.NOT_VALID_WORLD); return false; } if (Trim.TASK) { - sendMessage(C.TRIM_IN_PROGRESS.s()); + C.TRIM_IN_PROGRESS.send(plr); return false; } - sendMessage(C.TASK_START.s()); - final ArrayList empty = new ArrayList<>(); - getTrimRegions(empty, world, new Runnable() { + Trim.TASK = true; + final boolean regen = args.length == 2 ? Boolean.parseBoolean(args[1]) : false; + getTrimRegions(world, new RunnableVal2, Set>() { @Override - public void run() { - deleteChunks(world, empty, new Runnable() { - @Override - public void run() { - ConsolePlayer.getConsole().sendMessage("$1Trim task complete!"); - } - }); + public void run(final Set viable, final Set nonViable) { + Runnable regenTask; + if (regen) { + regenTask = new Runnable() { + @Override + public void run() { + if (nonViable.size() == 0) { + Trim.TASK = false; + plr.sendMessage("Trim done!"); + return; + } + Iterator iter = nonViable.iterator(); + ChunkLoc mcr = iter.next(); + iter.remove(); + int cbx = mcr.x << 5; + int cbz = mcr.z << 5; + // get all 1024 chunks + HashSet chunks = new HashSet<>(); + for (int x = cbx; x < cbx + 32; x++) { + for (int z = cbz; z < cbz + 32; z++) { + ChunkLoc loc = new ChunkLoc(x, z); + chunks.add(loc); + } + } + int bx = cbx << 4; + int bz = cbz << 4; + RegionWrapper region = new RegionWrapper(bx, bx + 511, bz, bz + 511); + for (Plot plot : PS.get().getPlots(world)) { + Location bot = plot.getBottomAbs(); + Location top = plot.getExtendedTopAbs(); + RegionWrapper plotReg = new RegionWrapper(bot.getX(), top.getX(), bot.getZ(), top.getZ()); + if (!region.intersects(plotReg)) { + continue; + } + for (int x = plotReg.minX >> 4; x <= plotReg.maxX >> 4; x++) { + for (int z = plotReg.minZ >> 4; z <= plotReg.maxZ >> 4; z++) { + ChunkLoc loc = new ChunkLoc(x, z); + chunks.remove(loc); + } + } + } + TaskManager.objectTask(chunks, new RunnableVal() { + @Override + public void run(ChunkLoc value) { + ChunkManager.manager.regenerateChunk(world, value); + } + }, this); + } + }; + } + else { + regenTask = new Runnable() { + @Override + public void run() { + Trim.TASK = false; + } + }; + } + ChunkManager.manager.deleteRegionFiles(world, viable, regenTask); + } }); return true; diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 141706133..3ee601f08 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -31,7 +31,7 @@ import java.util.Set; import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandCaller; @@ -393,7 +393,6 @@ public enum C { /* * trim */ - TRIM_SYNTAX("Use /plot trim ", "Trim"), TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"), NOT_VALID_HYBRID_PLOT_WORLD("The hybrid plot manager is required to perform this action", "Trim"), /* @@ -611,8 +610,11 @@ public enum C { * Direction */ DIRECTION("$1Current direction: %dir%", "Help"), - GRANTED_PLOTS("$1You've got $2%s $1grants left", "Grants"), - GRANTED_PLOT("$1You granted 1 plot to $2%s", "Grants"), + /* + * Grant + */ + GRANTED_PLOTS("$1Result: $2%s $1grants left", "Grants"), + GRANTED_PLOT("$1You granted %s0 plot to $2%s1", "Grants"), GRANTED_PLOT_FAILED("$1Grant failed: $2%s", "Grants"), /* * Custom @@ -693,7 +695,7 @@ public enum C { } public static String format(final C c, final Object... args) { - return format(c.s, args); + return (c.usePrefix() ? C.PREFIX.s() : "") + format(c.s, args); } public static String color(final String string) { @@ -801,10 +803,15 @@ public enum C { } public void send(final CommandCaller plr, final String... args) { + send(plr, (Object[]) args); + } + + public void send(final CommandCaller plr, final Object... args) { + String msg = format(this, args); if (plr == null) { - MainUtil.sendConsoleMessage(this, args); + ConsolePlayer.getConsole().sendMessage(msg); } else { - plr.sendMessage(this, args); + plr.sendMessage(msg); } } } diff --git a/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 0b9bf3551..a34bd191f 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -34,7 +34,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; @@ -103,7 +102,7 @@ public interface AbstractDB { void removePersistentMeta(UUID uuid, String key); - void getPersistentMeta(PlotPlayer player, RunnableVal> result); + void getPersistentMeta(UUID uuid, RunnableVal> result); /** * Create plot settings diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index d6adfc034..536bbe538 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -54,7 +54,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; @@ -2421,16 +2420,17 @@ public class SQLManager implements AbstractDB { } @Override - public void addPersistentMeta(final UUID uuid, final String key, final byte[] meta, final boolean delete) { + public void addPersistentMeta(final UUID uuid, final String key, final byte[] meta, final boolean replace) { addPlayerTask(uuid, new UniqueStatement("addPersistentMeta") { @Override public void set(final PreparedStatement stmt) throws SQLException { - if (delete) { - stmt.setString(1, uuid.toString()); - stmt.setString(2, key); + Blob blob = connection.createBlob(); + blob.setBytes(1, meta); + if (replace) { + stmt.setBlob(1, blob); + stmt.setString(2, uuid.toString()); + stmt.setString(3, key); } else { - Blob blob = connection.createBlob(); - blob.setBytes(1, meta); stmt.setString(1, uuid.toString()); stmt.setString(2, key); stmt.setBlob(3, blob); @@ -2439,8 +2439,8 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - if (delete) { - return connection.prepareStatement("DELETE FROM `" + prefix + "player_meta` WHERE `uuid` = ? AND `key` = ?"); + if (replace) { + return connection.prepareStatement("UPDATE `" + prefix + "player_meta` SET `value` = ? WHERE `uuid` = ? AND `key` = ?"); } else { return connection.prepareStatement("INSERT INTO `" + prefix + "player_meta`(`uuid`, `key`, `value`) VALUES(?, ? ,?)"); } @@ -2465,11 +2465,11 @@ public class SQLManager implements AbstractDB { } @Override - public void getPersistentMeta(final PlotPlayer player, final RunnableVal> result) { - addPlayerTask(player.getUUID(), new UniqueStatement("getPersistentMeta") { + public void getPersistentMeta(final UUID uuid, final RunnableVal> result) { + addPlayerTask(uuid, new UniqueStatement("getPersistentMeta") { @Override public void set(final PreparedStatement stmt) throws SQLException { - stmt.setString(1, player.getUUID().toString()); + stmt.setString(1, uuid.toString()); } @Override diff --git a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index f9d91200d..90c2ef5cb 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -20,6 +20,13 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.flag; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -32,13 +39,6 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.Permissions; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - /** * Flag Manager Utility * @@ -100,13 +100,13 @@ public class FlagManager { PS.get().foreachPlotArea(new RunnableVal() { @Override public void run(PlotArea value) { - final Flag flag = ((HashMap) value.DEFAULT_FLAGS.clone()).get(af.getKey()); + final Flag flag = value.DEFAULT_FLAGS.get(af.getKey()); if (flag != null) { flag.setKey(af); } } }); - PS.get().foreachPlot(new RunnableVal() { + PS.get().foreachPlotRaw(new RunnableVal() { @Override public void run(Plot value) { final Flag flag = value.getFlags().get(af.getKey()); @@ -115,11 +115,12 @@ public class FlagManager { } } }); - if (getFlag(af.getKey()) == null && flags.add(af)) { - if (reserved) { - reserveFlag(af.getKey()); - } - return true; + if (flags.remove(af)) { + PS.debug("(Replaced existing flag)"); + } + flags.add(af); + if (reserved) { + reserveFlag(af.getKey()); } return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java b/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java index 23462ac94..86a63eb15 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java @@ -1,6 +1,9 @@ package com.intellectualcrafters.plot.generator; +import java.util.Set; + import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.LazyResult; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotManager; @@ -10,8 +13,6 @@ import com.intellectualcrafters.plot.util.PlotChunk; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; -import java.util.Set; - public class AugmentedUtils { private static boolean enabled = true; @@ -22,10 +23,18 @@ public class AugmentedUtils { enabled = true; } - public static void generate(String world, int cx, int cz) { + public static void generate(final String world, final int cx, final int cz, LazyResult> lazyChunk) { if (!enabled) { return; } + if (lazyChunk == null) { + lazyChunk = new LazyResult>() { + @Override + public PlotChunk create() { + return SetQueue.IMP.queue.getChunk(SetQueue.IMP.new ChunkWrapper(world, cx, cz)); + } + }; + } final int bx = cx << 4; final int bz = cz << 4; RegionWrapper region = new RegionWrapper(bx, bx + 15, bz, bz + 15); @@ -35,7 +44,6 @@ public class AugmentedUtils { } final PseudoRandom r = new PseudoRandom(); r.state = (cx << 16) | (cz & 0xFFFF);; - PlotChunk cache_chunk = null; ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, cx, cz); for (final PlotArea area : areas) { if (area.TYPE == 0) { @@ -48,10 +56,7 @@ public class AugmentedUtils { if (generator == null) { continue; } - if (cache_chunk == null) { - cache_chunk = SetQueue.IMP.queue.getChunk(wrap); - } - final PlotChunk result = cache_chunk; + final PlotChunk result = lazyChunk.getOrCreate(); final PlotChunk primaryMask; // coords int bxx = Math.max(0, area.getRegion().minX - bx); @@ -154,9 +159,9 @@ public class AugmentedUtils { } generator.generateChunk(secondaryMask, area, r); } - if (cache_chunk != null) { - cache_chunk.addToQueue(); - cache_chunk.flush(false); + if (lazyChunk.get() != null) { + lazyChunk.get().addToQueue(); + lazyChunk.get().flush(false); } } } diff --git a/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java b/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java index 6dc5db703..1cf13a986 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java @@ -61,8 +61,8 @@ public abstract class IndependentPlotGenerator { * @param * @return */ - public GeneratorWrapper specify(String world) { - return (GeneratorWrapper) PS.get().IMP.wrapPlotGenerator(world, this); + public GeneratorWrapper specify() { + return (GeneratorWrapper) PS.get().IMP.wrapPlotGenerator(this); } @Override diff --git a/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java b/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java index 1dbb1f827..0ca0822a5 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java @@ -5,9 +5,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.RequiredType; -import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotWeather; @@ -75,11 +73,6 @@ public class ConsolePlayer extends PlotPlayer { PS.log(message); } - @Override - public void sendMessage(final C c, final String... args) { - MainUtil.sendMessage(this, c, args); - } - @Override public void teleport(final Location loc) { final Plot plot = loc.getPlot(); diff --git a/src/main/java/com/intellectualcrafters/plot/object/LazyResult.java b/src/main/java/com/intellectualcrafters/plot/object/LazyResult.java new file mode 100644 index 000000000..5778b2da3 --- /dev/null +++ b/src/main/java/com/intellectualcrafters/plot/object/LazyResult.java @@ -0,0 +1,18 @@ +package com.intellectualcrafters.plot.object; + +public abstract class LazyResult { + private T result; + + public T get() { + return result; + } + + public T getOrCreate() { + if (this.result == null) { + return (this.result = create()); + } + return result; + } + + public abstract T create(); +} diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index f9bcb4a7a..37c4be8a9 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -422,7 +422,7 @@ public abstract class PlotPlayer implements CommandCaller { } public void populatePersistentMetaMap() { - DBFunc.dbManager.getPersistentMeta(this, new RunnableVal>() { + DBFunc.dbManager.getPersistentMeta(getUUID(), new RunnableVal>() { @Override public void run(Map value) { PlotPlayer.this.metaMap = value; diff --git a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 662b18c4d..f1df09b06 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -1,5 +1,11 @@ package com.intellectualcrafters.plot.util; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ConsolePlayer; @@ -9,12 +15,6 @@ import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - public abstract class ChunkManager { public static ChunkManager manager = null; @@ -206,11 +206,11 @@ public abstract class ChunkManager { public abstract void regenerateChunk(final String world, final ChunkLoc loc); - public void deleteRegionFiles(String world, List chunks) { + public void deleteRegionFiles(String world, Collection chunks) { deleteRegionFiles(world, chunks, null); } - public void deleteRegionFiles(final String world, final List chunks, final Runnable whenDone) { + public void deleteRegionFiles(final String world, final Collection chunks, final Runnable whenDone) { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { @@ -222,9 +222,7 @@ public abstract class ChunkManager { file.delete(); } } - if (whenDone != null) { - whenDone.run(); - } + TaskManager.runTask(whenDone); } }); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java b/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java index 0feec9218..c1e1d09d5 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java +++ b/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java @@ -11,9 +11,11 @@ public abstract class EconHandler { if (ConsolePlayer.isConsole(player)) { return Double.MAX_VALUE; } - return Double.NaN; + return getBalance(player); } + public abstract double getBalance(PlotPlayer player); + public abstract void withdrawMoney(final PlotPlayer player, final double amount); public abstract void depositMoney(final PlotPlayer player, final double amount); diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 74f5d806d..4737b2740 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.UUID; import java.util.regex.Matcher; @@ -525,14 +526,11 @@ public class MainUtil { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - String msg = c.s(); - if (args.length != 0) { - msg = C.format(c, args); - } - if (plr != null) { - plr.sendMessage(c.usePrefix() ? C.PREFIX.s() + msg : msg); + String m = C.format(c, args); + if (plr == null) { + ConsolePlayer.getConsole().sendMessage(m); } else { - ConsolePlayer.getConsole().sendMessage((c.usePrefix() ? C.PREFIX.s() : "") + msg); + plr.sendMessage(m); } } }); @@ -712,4 +710,18 @@ public class MainUtil { } return list.toString(); } + + public static void getPersistentMeta(final UUID uuid, final String key, final RunnableVal result) { + PlotPlayer pp = UUIDHandler.getPlayer(uuid); + if (pp != null) { + result.run(pp.getPersistentMeta(key)); + } else { + DBFunc.dbManager.getPersistentMeta(uuid, new RunnableVal>() { + @Override + public void run(Map value) { + result.run(value.get(key)); + } + }); + } + } } diff --git a/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index 2de8697e6..5c243aebf 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -1,5 +1,9 @@ package com.intellectualcrafters.plot.util; +import java.util.HashSet; +import java.util.Map; +import java.util.UUID; + import com.google.common.collect.BiMap; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; @@ -9,10 +13,6 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; -import java.util.HashSet; -import java.util.Map; -import java.util.UUID; - public class UUIDHandler { public static UUIDHandlerImplementation implementation; @@ -107,6 +107,13 @@ public class UUIDHandler { return implementation.getPlayer(name); } + public static UUID getUUIDFromString(String nameOrUUIDString) { + if (nameOrUUIDString.length() > 16) { + return UUID.fromString(nameOrUUIDString); + } + return UUIDHandler.getUUID(nameOrUUIDString, null); + } + public static UUID getUUID(final String name, final RunnableVal ifFetch) { return implementation.getUUID(name, ifFetch); } diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 98ba6ee5c..101bb9729 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -375,9 +375,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void registerInventoryEvents() { - // Part of PlayerEvents - can be moved if necessary - } @Override @@ -486,7 +484,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return new BukkitPlotGenerator(world, gen); } else { - return new BukkitPlotGenerator(world, new HybridGen()); + return new BukkitPlotGenerator(new HybridGen()); } } @@ -654,11 +652,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } else if (obj instanceof String) { return UUIDHandler.getPlayer((String) obj); } else if (obj instanceof UUID) { - PlotPlayer player = UUIDHandler.getPlayer((UUID) obj); - if (player == null) { - return BukkitUtil.getPlayer(Bukkit.getOfflinePlayer((UUID) obj)); - } - return player; + return UUIDHandler.getPlayer((UUID) obj); } return null; } @@ -697,7 +691,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public GeneratorWrapper wrapPlotGenerator(String world, IndependentPlotGenerator generator) { - return new BukkitPlotGenerator(world, generator); + return new BukkitPlotGenerator(generator); } @Override diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java b/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java index d6e8b29f1..5f6fd9b09 100644 --- a/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java +++ b/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java @@ -371,7 +371,7 @@ public class LikePlotMeConverter { // Load using Bukkit API // - User must set generator manually Bukkit.getServer().unloadWorld(world, true); - final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(actualWorldName, new HybridGen())).createWorld(); + final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld(); myworld.save(); } } diff --git a/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java b/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java index b94ed2261..b13552295 100644 --- a/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java +++ b/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java @@ -28,7 +28,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator { } @Override - public void populate(World world, Random r, Chunk chunk) { - AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ()); + public void populate(final World world, Random r, final Chunk chunk) { + AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null); } } diff --git a/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index ba29c4393..e2093b9cd 100644 --- a/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -20,6 +20,17 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.plotsquared.bukkit.generator; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.block.Biome; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; + import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridGen; @@ -36,16 +47,6 @@ import com.intellectualcrafters.plot.util.SetQueue; import com.plotsquared.bukkit.listeners.WorldEvents; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.block.GenChunk; -import org.bukkit.Chunk; -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.List; -import java.util.Random; -import java.util.Set; public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper { @@ -54,12 +55,10 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap private final IndependentPlotGenerator plotGenerator; private final List populators = new ArrayList<>(); private boolean loaded = false; - private PlotManager manager; private ChunkGenerator platformGenerator; private boolean full; - public BukkitPlotGenerator(final String world, IndependentPlotGenerator generator) { - WorldEvents.lastWorld = world; + public BukkitPlotGenerator(IndependentPlotGenerator generator) { this.plotGenerator = generator; this.platformGenerator = this; populators.add(new BlockPopulator() { @@ -87,7 +86,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } } }); - chunkSetter = new GenChunk(null, SetQueue.IMP.new ChunkWrapper(world, 0, 0)); + chunkSetter = new GenChunk(null, null); this.full = true; MainUtil.initCache(); } diff --git a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index 3cda97f6c..297ebdf7c 100644 --- a/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -1,14 +1,7 @@ package com.plotsquared.bukkit.object; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.EconHandler; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.PlotGamemode; -import com.intellectualcrafters.plot.util.PlotWeather; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.bukkit.util.BukkitUtil; +import java.util.UUID; + import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.GameMode; @@ -18,7 +11,14 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.permissions.Permission; import org.bukkit.plugin.PluginManager; -import java.util.UUID; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.PlotGamemode; +import com.intellectualcrafters.plot.util.PlotWeather; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.plotsquared.bukkit.util.BukkitUtil; public class BukkitPlayer extends PlotPlayer { @@ -101,11 +101,6 @@ public class BukkitPlayer extends PlotPlayer { player.sendMessage(message); } - @Override - public void sendMessage(final C c, final String... args) { - MainUtil.sendMessage(this, c, args); - } - @Override public void teleport(final Location loc) { if (Math.abs(loc.getX()) >= 30000000 || Math.abs(loc.getZ()) >= 30000000) { @@ -145,7 +140,6 @@ public class BukkitPlayer extends PlotPlayer { @Override public boolean getAttribute(String key) { - if (!hasPersistentMeta(key)) { return false; } diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 2094d3448..51b005887 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -1,14 +1,16 @@ package com.plotsquared.bukkit.util; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.RegisteredServiceProvider; + import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EconHandler; import com.plotsquared.bukkit.object.BukkitOfflinePlayer; import com.plotsquared.bukkit.object.BukkitPlayer; -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.permission.Permission; -import org.bukkit.Bukkit; -import org.bukkit.plugin.RegisteredServiceProvider; public class BukkitEconHandler extends EconHandler { @@ -88,4 +90,9 @@ public class BukkitEconHandler extends EconHandler { public boolean hasPermission(final String world, final String player, final String perm) { return perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm); } + + @Override + public double getBalance(PlotPlayer player) { + return econ.getBalance(player.getName()); + } } diff --git a/src/main/java/com/plotsquared/general/commands/CommandCaller.java b/src/main/java/com/plotsquared/general/commands/CommandCaller.java index aeb131958..43092c43e 100644 --- a/src/main/java/com/plotsquared/general/commands/CommandCaller.java +++ b/src/main/java/com/plotsquared/general/commands/CommandCaller.java @@ -1,13 +1,10 @@ package com.plotsquared.general.commands; import com.intellectualcrafters.plot.commands.RequiredType; -import com.intellectualcrafters.plot.config.C; public interface CommandCaller { void sendMessage(final String message); - void sendMessage(final C c, final String... args); - boolean hasPermission(final String perm); RequiredType getSuperCaller();