From f60bac0e0e5fc129f0c0dfdd04c93c159dcd3486 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 29 Oct 2014 17:18:17 +1100 Subject: [PATCH 1/5] Fixed plot auto algorithms and also made some performance improvements --- .gitignore | 4 +- .../intellectualcrafters/plot/Metrics.java | 2 +- .../intellectualcrafters/plot/PlotMain.java | 4 + .../plot/commands/Auto.java | 103 ++++++++++++------ .../plot/commands/Delete.java | 3 + 5 files changed, 83 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 08cd04510..444077878 100644 --- a/.gitignore +++ b/.gitignore @@ -94,4 +94,6 @@ local.properties # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* .classpath -.project \ No newline at end of file +.project +/target +/plotsquared/target \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Metrics.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Metrics.java index 8df772230..4d38ff7ac 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Metrics.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Metrics.java @@ -326,7 +326,7 @@ public class Metrics { // enabled String pluginVersion = description.getVersion(); String serverVersion = Bukkit.getVersion(); - int playersOnline = Bukkit.getServer().getOnlinePlayers().size(); + int playersOnline = Bukkit.getServer().getOnlinePlayers().length; // END server software specific section -- all code below does not use // any code outside of this class / Java // Construct the post data diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index f73f387de..1c301f9bc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -9,6 +9,7 @@ package com.intellectualcrafters.plot; import com.intellectualcrafters.plot.Logger.LogLevel; +import com.intellectualcrafters.plot.commands.Auto; import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.database.*; import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; @@ -475,6 +476,9 @@ public class PlotMain extends JavaPlugin { PlotHelper.removeSign(worldobj, plot); DBFunc.delete(world, plot); removePlot(world, plot.id, true); + if (Math.abs(plot.id.x) absY) { + if (id.x > 0) { + return new PlotId(id.x, id.y + 1); + } + else { + return new PlotId(id.x, id.y - 1); + } + } + else if (absY > absX ){ + if (id.y > 0) { + return new PlotId(id.x - 1, id.y); + } + else { + return new PlotId(id.x + 1, id.y); + } + } + else { + if (id.x==id.y && id.x > 0) { + return new PlotId(id.x, id.y + step); + } + if (id.x==absX) { + return new PlotId(id.x, id.y + 1); + } + if (id.y == absY) { + return new PlotId(id.x, id.y - 1); + } + return new PlotId(id.x + 1, id.y); + } + } + public boolean isUnowned(World world, PlotId pos1, PlotId pos2) { for (int x = pos1.x; x <= pos2.x; x++) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index f285e71ff..5822117a0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -58,6 +58,9 @@ public class Delete extends SubCommand { if (result) { plot.clear(plr); DBFunc.delete(plr.getWorld().getName(), plot); + if (Math.abs(plot.id.x)<=Math.abs(Auto.lastPlot.x) && Math.abs(plot.id.y)<=Math.abs(Auto.lastPlot.y)) { + Auto.lastPlot = plot.id; + } } else { PlayerFunctions.sendMessage(plr, "Plot clearing has been denied."); From 0d305463fc08d3921b9f7a66416c08adc1760299 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 29 Oct 2014 19:15:58 +1100 Subject: [PATCH 2/5] So that's how you're meant to do it. --- .../plot/generator/WorldGenerator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java index 4ceb846f7..ed51db378 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java @@ -70,7 +70,13 @@ public class WorldGenerator extends PlotGenerator { } return manager; } - + /** + * Allow spawning everywhere (up to server owners to keep it safe) + */ + @Override + public boolean canSpawn(World world, int x, int z) { + return true; + } /** * Get a new plotworld class For square plots you can use the * DefaultPlotWorld class which comes with PlotSquared From 0aaf5731861063a97767cf89e03fce5fd3b1b521 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 29 Oct 2014 22:26:50 +1100 Subject: [PATCH 3/5] we could just drop support for worldedit... --- .../com/intellectualcrafters/plot/PWE.java | 34 ++++--------------- .../plot/database/sqlobjects/PlotTable.java | 8 +++-- .../plot/generator/WorldGenerator.java | 2 +- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java index 8e84eedbc..f17358bfd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java @@ -10,6 +10,8 @@ import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.regions.CuboidRegion; /** @@ -55,8 +57,7 @@ public class PWE { LocalWorld lw = PlotMain.worldEdit.wrapPlayer(p).getWorld(); CuboidRegion region = new CuboidRegion(lw, bvec, tvec); - com.sk89q.worldedit.masks.RegionMask mask = new com.sk89q.worldedit.masks.RegionMask(region); - + RegionMask mask = new RegionMask(region); s.setMask(mask); return; } @@ -65,8 +66,7 @@ public class PWE { if (noMask(s)) { BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p); Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); - - s.setMask(new com.sk89q.worldedit.masks.RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); + s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); } } catch (Exception e) { @@ -76,33 +76,13 @@ public class PWE { } } - @SuppressWarnings("unused") public static boolean noMask(LocalSession s) { -// try { -// com.sk89q.worldedit.masks.Mask mask = s.getMask(); -// return mask == null; -// } - - - -// catch (Throwable e) { -// -// -// return true; -// -// -// } - return true; + return s.getMask() == null; } public static void removeMask(Player p, LocalSession s) { -// try { -// s.setMask(null); -// } -// catch (Throwable e) { -// com.sk89q.worldedit.masks.Mask mask = null; -// s.setMask(mask); -// } + Mask mask = null; + s.setMask(mask); } public static void removeMask(Player p) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java index 01b4b0f5a..70f386b8b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java @@ -6,8 +6,12 @@ package com.intellectualcrafters.plot.database.sqlobjects; public class PlotTable extends SQLTable { public PlotTable() { - super("plots"); + super("plots", name, fields); } - public + @Override + public void create() { + // TODO Auto-generated method stub + + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java index ed51db378..331594518 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/WorldGenerator.java @@ -71,7 +71,7 @@ public class WorldGenerator extends PlotGenerator { return manager; } /** - * Allow spawning everywhere (up to server owners to keep it safe) + * Allow spawning everywhere */ @Override public boolean canSpawn(World world, int x, int z) { From 5395852cf013dcbe60dc240bce7842206541c947 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 30 Oct 2014 17:24:58 +1100 Subject: [PATCH 4/5] Async schematic pasting - We should replace the schematic on claim with this. - worldedit listener now listens to plot deletion - debugclaimtest command no longer pastes any schematics if there is on set --- .../java/com/intellectualcrafters/plot/C.java | 2 +- .../com/intellectualcrafters/plot/PWE.java | 18 + .../intellectualcrafters/plot/PlotHelper.java | 8 +- .../intellectualcrafters/plot/PlotMain.java | 5 +- .../plot/SchematicHandler.java | 43 +- .../plot/commands/Claim.java | 2 +- .../plot/commands/DebugClaimTest.java | 15 - .../plot/commands/Schematic.java | 366 +++++++++++------- .../plot/listeners/WorldEditListener.java | 24 ++ 9 files changed, 305 insertions(+), 178 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java index f339f78cb..c178fc8c2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java @@ -207,7 +207,7 @@ public enum C { * Info */ PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), - PLOT_INFO("&6ID&7: &a%id%&7\n&6Alias&7: &a%alias%\n&6Owner&7: &a%owner%\n&6Description&7: &a%desc%\n&6Rating&7: &a%rating%&7/&a10\n&6Can build&7: &a%build%"), + PLOT_INFO("&6ID&7: &a%id%&7\n&6Alias&7: &a%alias%\n&6Owner&7: &a%owner%\n&6Helpers&7: &a%helpers%\n&6Trusted&7: &a%trusted%\n&Denied&7: &a%denied%\n&6Denied&7: &a%denied%\n&6Flags&7: &a%flags%\n&6Biome&7: &a%biome%\n&6Rating&7: &a%rating%&7/&a10\n&6Can build&7: &a%build%"), PLOT_INFO_HELPERS("&6Helpers&7: %helpers%"), PLOT_INFO_TRUSTED("&6Trusted&7: %trusted%"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java index f17358bfd..3645fe1e5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java @@ -80,6 +80,24 @@ public class PWE { return s.getMask() == null; } + public static void setNoMask(Player p) { + try { + LocalSession s; + if (PlotMain.worldEdit == null) { + s = WorldEdit.getInstance().getSession(p.getName()); + } + else { + s = PlotMain.worldEdit.getSession(p); + } + BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p); + Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); + s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); + } + catch (Exception e) { + + } + } + public static void removeMask(Player p, LocalSession s) { Mask mask = null; s.setMask(mask); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java index 99ec7d275..d67bf573a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java @@ -266,18 +266,19 @@ public class PlotHelper { * @param block * @param plotblock */ - public static void setBlock(Block block, PlotBlock plotblock) { + public static boolean setBlock(Block block, PlotBlock plotblock) { if (canSetFast) { - if (block.getTypeId() != plotblock.id && plotblock.data != block.getData()) { + if (block.getTypeId() != plotblock.id || plotblock.data != block.getData()) { try { SetBlockFast.set(block.getWorld(), block.getX(), block.getY(), block.getZ(), plotblock.id, plotblock.data); - return; + return true; } catch (NoSuchMethodException e) { canSetFast = false; } } + return false; } if (block.getData() == plotblock.data) { if (block.getTypeId() != plotblock.id) { @@ -292,6 +293,7 @@ public class PlotHelper { block.setTypeIdAndData(plotblock.id, plotblock.data, false); } } + return false; } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 1c301f9bc..60eb2ec37 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -115,10 +115,9 @@ public class PlotMain extends JavaPlugin { return new WorldGenerator(worldname); } - @SuppressWarnings("deprecation") public static void checkForExpiredPlots() { final JavaPlugin plugin = PlotMain.getMain(); - Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { checkExpired(plugin, true); @@ -1217,7 +1216,7 @@ public class PlotMain extends JavaPlugin { options.put("mysql.user", "root"); options.put("mysql.password", "password"); options.put("mysql.database", "plot_db"); - options.put("prefix", "plotsquared_"); + options.put("prefix", ""); for (Entry node : options.entrySet()) { if (!storage.contains(node.getKey())) { storage.set(node.getKey(), node.getValue()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/SchematicHandler.java index 32f256ea2..2ad94f1d4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/SchematicHandler.java @@ -7,6 +7,7 @@ import org.bukkit.block.Block; import org.bukkit.plugin.java.JavaPlugin; import com.intellectualcrafters.jnbt.*; +import com.intellectualcrafters.plot.SchematicHandler.DataCollection; import java.io.File; import java.io.FileInputStream; @@ -27,7 +28,6 @@ import java.util.zip.GZIPOutputStream; */ @SuppressWarnings({"all"}) public class SchematicHandler { - /** * Paste a schematic * @param location origin @@ -35,13 +35,12 @@ public class SchematicHandler { * @param plot plot to paste in * @return true if succeeded */ - public static boolean paste(Location location, Schematic schematic, Plot plot) { + public static boolean paste(Location location, Schematic schematic, Plot plot, int x_offset, int z_offset) { if (schematic == null) { PlotMain.sendConsoleSenderMessage("Schematic == null :|"); return false; } try { - Dimension demensions = schematic.getSchematicDimension(); int WIDTH = demensions.getX(); @@ -68,7 +67,7 @@ public class SchematicHandler { short id = blocks[index].getBlock(); byte data = blocks[index].getData(); - Block block = world.getBlockAt(l1.getBlockX()+x, l1.getBlockY()+y, l1.getBlockZ()+z); + Block block = world.getBlockAt(l1.getBlockX()+x+x_offset, l1.getBlockY()+y, l1.getBlockZ()+z+z_offset); PlotBlock plotblock = new PlotBlock(id, data); @@ -274,9 +273,9 @@ public class SchematicHandler { PlotMain.sendConsoleSenderMessage("&7 - Cannot save: corrupt chunk at "+(i/16)+", "+(j/16)); return null; } - int width = pos2.getBlockX()-pos1.getBlockX(); + int width = pos2.getBlockX()-pos1.getBlockX()+1; int height = 256; - int length = pos2.getBlockZ()-pos1.getBlockZ(); + int length = pos2.getBlockZ()-pos1.getBlockZ()+1; HashMap schematic = new HashMap<>(); schematic.put("Width", new ShortTag("Width", (short) width)); @@ -354,4 +353,36 @@ public class SchematicHandler { return this.data; } } + + public static boolean pastePart(World world, DataCollection[] blocks, Location l1, int x_offset, int z_offset, int i1, int i2, int WIDTH, int LENGTH) { + boolean result = false; + for (int i = i1; i<=i2 ;i++) { + short id = blocks[i].getBlock(); + byte data = blocks[i].getData(); + if (id==0) { + continue; + } + + int area = WIDTH*LENGTH; + int r = i%(area); + + int x = r%WIDTH; + int y = i/area; + int z = r/WIDTH; + + if (y>256) { + break; + } + + Block block = world.getBlockAt(l1.getBlockX()+x+x_offset, l1.getBlockY()+y, l1.getBlockZ()+z+z_offset); + + PlotBlock plotblock = new PlotBlock(id, data); + + boolean set = PlotHelper.setBlock(block, plotblock); + if (!result && set) { + result = true; + } + } + return result; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 894bbc831..a240b6bbe 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -110,7 +110,7 @@ public class Claim extends SubCommand { sch = SchematicHandler.getSchematic(world.SCHEMATIC_FILE); } } - SchematicHandler.paste(player.getLocation(), sch, plot); + SchematicHandler.paste(player.getLocation(), sch, plot, 0, 0); } if (world.DEFAULT_FLAGS != null && world.DEFAULT_FLAGS.size() > 0) { plot.settings.setFlags(FlagManager.parseFlags(PlotMain.getWorldSettings(player.getWorld()).DEFAULT_FLAGS)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 91fa10d1f..f0413d8d3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -175,21 +175,6 @@ public class DebugClaimTest extends SubCommand { if (teleport) { PlotMain.teleportPlayer(player, player.getLocation(), plot); } - PlotWorld world = PlotMain.getWorldSettings(plot.getWorld()); - if (world.SCHEMATIC_ON_CLAIM) { - SchematicHandler handler = new SchematicHandler(); - SchematicHandler.Schematic sch; - if (schematic.equals("")) { - sch = handler.getSchematic(world.SCHEMATIC_FILE); - } - else { - sch = handler.getSchematic(schematic); - if (sch == null) { - sch = handler.getSchematic(world.SCHEMATIC_FILE); - } - } - handler.paste(player.getLocation(), sch, plot); - } plot.settings.setFlags(FlagManager.parseFlags(PlotMain.getWorldSettings(player.getWorld()).DEFAULT_FLAGS)); } return event.isCancelled(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java index 401e9842e..014fbbd0f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java @@ -2,7 +2,11 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.*; +import com.intellectualcrafters.plot.SchematicHandler.DataCollection; +import com.intellectualcrafters.plot.SchematicHandler.Dimension; + import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -11,122 +15,186 @@ import java.util.HashMap; public class Schematic extends SubCommand { - public Schematic() { - super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false); - - // TODO command to fetch schematic from worldedit directory - } - - private int counter = 0; - private boolean running = false; - private Plot[] plots; - private int task; - - - - - @Override - public boolean execute(final Player plr, String... args) { - if (args.length < 1) { - sendMessage(plr, C.SCHEMATIC_MISSING_ARG); - return true; - } - String arg = args[0].toLowerCase(); - String file; - SchematicHandler.Schematic schematic; - switch (arg) { - case "paste": - if (plr==null) { + public Schematic() { + super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false); + + // TODO command to fetch schematic from worldedit directory + } + + private int counter = 0; + private boolean running = false; + private Plot[] plots; + private int task; + + + @Override + public boolean execute(final Player plr, String... args) { + if (args.length < 1) { + sendMessage(plr, C.SCHEMATIC_MISSING_ARG); + return true; + } + String arg = args[0].toLowerCase(); + final String file; + final SchematicHandler.Schematic schematic; + switch (arg) { + case "paste": + if (plr==null) { PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE); return false; } - if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { + if (!PlotMain.hasPermission(plr, "plots.schematic.paste")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste"); return false; } - if (args.length < 2) { - sendMessage(plr, C.SCHEMATIC_MISSING_ARG); - break; - } - if (!PlayerFunctions.isInPlot(plr)) { - sendMessage(plr, C.NOT_IN_PLOT); - break; - } - file = args[1]; - schematic = SchematicHandler.getSchematic(file); - boolean s = SchematicHandler.paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr)); - if (s) { - sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); - } - else { - sendMessage(plr, C.SCHEMATIC_PASTE_FAILED); - } - break; - case "test": - if (plr==null) { + if (args.length < 2) { + sendMessage(plr, C.SCHEMATIC_MISSING_ARG); + break; + } + if (!PlayerFunctions.isInPlot(plr)) { + sendMessage(plr, C.NOT_IN_PLOT); + break; + } + if (running) { + PlayerFunctions.sendMessage(plr, "&cTask is already running."); + return false; + } + final String file2 = args[1]; + running = true; + this.counter = 0; + Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { + @Override + public void run() { + final SchematicHandler.Schematic schematic = SchematicHandler.getSchematic(file2); + if (schematic==null) { + sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format"); + running = false; + return; + } + + + final int x; + final int z; + + final Plot plot2 = PlayerFunctions.getCurrentPlot(plr); + + Dimension dem = schematic.getSchematicDimension(); + Location bot = PlotHelper.getPlotBottomLoc(plr.getWorld(), plot2.id).add(1, 0, 1); + int length2 = PlotHelper.getPlotWidth(plr.getWorld(), plot2.id); + + if ((dem.getX() > length2) || (dem.getZ() > length2)) { + sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", dem.getX(), dem.getZ(), length2)); + running = false; + return; + } + + if (dem.getX() != length2 || dem.getZ() != length2) { + Location loc = plr.getLocation(); + x = Math.min(length2-dem.getX(),loc.getBlockX() - bot.getBlockX()); + z = Math.min(length2-dem.getZ(),loc.getBlockZ() - bot.getBlockZ()); + } + else { + x = 0; + z = 0; + } + + final World w = plot2.getWorld(); + final DataCollection[] b = schematic.getBlockCollection(); + int sy = w.getHighestBlockYAt(bot.getBlockX(), bot.getBlockZ()); + final Location l1 = bot.add(0, sy-1, 0); + final int WIDTH = schematic.getSchematicDimension().getX(); + final int LENGTH = schematic.getSchematicDimension().getZ(); + final int blen = b.length-1; + + final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); + task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + boolean result = false; + while (!result) { + int start = counter*5000; + if (start>blen) { + sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); + if (PlotHelper.canSetFast) { + SetBlockFast.update(plr); + } + running = false; + Bukkit.getScheduler().cancelTask(task); + return; + } + int end = Math.min(start+5000,blen); + result = SchematicHandler.pastePart(w, b, l1, x, z, start, end, WIDTH, LENGTH); + counter++; + } + } + }, 1, 1); + } + }); + break; + case "test": + if (plr==null) { PlotMain.sendConsoleSenderMessage(C.IS_CONSOLE); return false; } - if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { + if (!PlotMain.hasPermission(plr, "plots.schematic.test")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test"); return false; } - if (args.length < 2) { - sendMessage(plr, C.SCHEMATIC_MISSING_ARG); - break; - } - file = args[1]; - schematic = SchematicHandler.getSchematic(file); - if (schematic == null) { - sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent"); - break; - } + if (args.length < 2) { + sendMessage(plr, C.SCHEMATIC_MISSING_ARG); + break; + } + file = args[1]; + schematic = SchematicHandler.getSchematic(file); + if (schematic == null) { + sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent"); + break; + } - int l1 = schematic.getSchematicDimension().getX(); - int l2 = schematic.getSchematicDimension().getZ(); + int l1 = schematic.getSchematicDimension().getX(); + int l2 = schematic.getSchematicDimension().getZ(); - Plot plot = PlayerFunctions.getCurrentPlot(plr); - int length = PlotHelper.getPlotWidth(plr.getWorld(), plot.id); + Plot plot = PlayerFunctions.getCurrentPlot(plr); + int length = PlotHelper.getPlotWidth(plr.getWorld(), plot.id); - if ((l1 != length) || (l2 != length)) { - sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length)); - break; - } - sendMessage(plr, C.SCHEMATIC_VALID); - break; - case "saveall": - case "exportall": - if (plr!=null) { + if ((l1 < length) || (l2 < length)) { + sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length)); + break; + } + sendMessage(plr, C.SCHEMATIC_VALID); + break; + case "saveall": + case "exportall": + if (plr!=null) { PlayerFunctions.sendMessage(plr, C.NOT_CONSOLE); return false; } - if (args.length!=2) { - PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall "); + if (args.length!=2) { + PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall "); return false; - } - HashMap plotmap = PlotMain.getPlots(args[1]); - if (plotmap==null || plotmap.size()==0) { - PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); + } + HashMap plotmap = PlotMain.getPlots(args[1]); + if (plotmap==null || plotmap.size()==0) { + PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); return false; - } - if (running) { - PlayerFunctions.sendMessage(plr, "&cTask is already running."); + } + if (running) { + PlayerFunctions.sendMessage(plr, "&cTask is already running."); return false; - } - - PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while."); - PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Found &c"+plotmap.size()+"&7 plots..."); - final World worldObj = Bukkit.getWorld(args[1]); - final String worldname = Bukkit.getWorld(args[1]).getName(); - - final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); - - - this.plots = plotmap.values().toArray(new Plot[0]); - this.running = true; - this.counter = 0; - - task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + } + + PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while."); + PlotMain.sendConsoleSenderMessage("&3PlotSquared&8->&3Schemaitc&8: &7Found &c"+plotmap.size()+"&7 plots..."); + final World worldObj = Bukkit.getWorld(args[1]); + final String worldname = Bukkit.getWorld(args[1]).getName(); + + final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); + + + this.plots = plotmap.values().toArray(new Plot[0]); + this.running = true; + this.counter = 0; + + task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { if (counter>=plots.length) { @@ -159,56 +227,56 @@ public class Schematic extends SubCommand { } counter++; } - }, 20, 20); - break; - case "export": - case "save": - if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { - PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save"); - return false; - } - if (running) { + }, 20, 20); + break; + case "export": + case "save": + if (!PlotMain.hasPermission(plr, "plots.schematic.save")) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save"); + return false; + } + if (running) { PlayerFunctions.sendMessage(plr, "&cTask is already running."); return false; } - final String world; - final Plot p2; - if (plr!=null) { - if(!PlayerFunctions.isInPlot(plr)) { - sendMessage(plr, C.NOT_IN_PLOT); - return false; - } - Plot myplot = PlayerFunctions.getCurrentPlot(plr); - if(!myplot.hasRights(plr)) { - sendMessage(plr, C.NO_PLOT_PERMS); - return false; - } - p2 = myplot; - world = plr.getWorld().getName(); - } - else { - if (args.length==3) { - try { - world = args[0]; - String[] split = args[2].split(";"); - PlotId i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1])); - if (PlotMain.getPlots(world)==null || PlotMain.getPlots(world).get(i) == null) { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); - return false; - } - p2 = PlotMain.getPlots(world).get(i); - } - catch (Exception e) { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); - return false; - } - } - else { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); - return false; - } - } - + final String world; + final Plot p2; + if (plr!=null) { + if(!PlayerFunctions.isInPlot(plr)) { + sendMessage(plr, C.NOT_IN_PLOT); + return false; + } + Plot myplot = PlayerFunctions.getCurrentPlot(plr); + if(!myplot.hasRights(plr)) { + sendMessage(plr, C.NO_PLOT_PERMS); + return false; + } + p2 = myplot; + world = plr.getWorld().getName(); + } + else { + if (args.length==3) { + try { + world = args[0]; + String[] split = args[2].split(";"); + PlotId i = new PlotId(Integer.parseInt(split[0]),Integer.parseInt(split[1])); + if (PlotMain.getPlots(world)==null || PlotMain.getPlots(world).get(i) == null) { + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); + return false; + } + p2 = PlotMain.getPlots(world).get(i); + } + catch (Exception e) { + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); + return false; + } + } + else { + PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); + return false; + } + } + final Plugin plugin2 = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); @@ -250,11 +318,11 @@ public class Schematic extends SubCommand { counter++; } }, 20, 60); - break; - default: - sendMessage(plr, C.SCHEMATIC_MISSING_ARG); - break; - } - return true; - } + break; + default: + sendMessage(plr, C.SCHEMATIC_MISSING_ARG); + break; + } + return true; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java index a0514e72d..bb32274cd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -25,6 +26,7 @@ import com.intellectualcrafters.plot.PlotHelper; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; /** * @author Citymonstret @@ -37,6 +39,28 @@ public class WorldEditListener implements Listener { private boolean isPlotWorld(Location l) { return (PlotMain.isPlotWorld(l.getWorld())); } + + @EventHandler( + priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onDelete(PlotDeleteEvent e) { + String world = e.getWorld(); + PlotId id = e.getPlotId(); + Plot plot = PlotMain.getPlots(world).get(id); + if (plot==null || plot.owner == null) { + return; + } + Player player = Bukkit.getPlayer(plot.owner); + if (player == null) { + return; + } + if (!world.equals(player.getWorld().getName())) { + return; + } + if (PlotMain.hasPermission(player, "plots.worldedit.bypass")) { + return; + } + PWE.setNoMask(player); + } @EventHandler( priority = EventPriority.LOWEST, ignoreCancelled = true) From 97b9198d77770aadf3f986cf89e1be8297e1c906 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 30 Oct 2014 22:32:04 +1100 Subject: [PATCH 5/5] fixes --- PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java | 2 +- .../java/com/intellectualcrafters/plot/database/SQLManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java index c178fc8c2..a5d47a4cf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java @@ -211,7 +211,7 @@ public enum C { PLOT_INFO_HELPERS("&6Helpers&7: %helpers%"), PLOT_INFO_TRUSTED("&6Trusted&7: %trusted%"), - PLOT_INFO_DENIED("&6DENIED&7: %denied%"), + PLOT_INFO_DENIED("&6Denied&7: %denied%"), PLOT_INFO_FLAGS("&6Flags&7: %flags%"), PLOT_INFO_BIOME("&6Biome&7: %biome%"), PLOT_INFO_RATING("&6Rating&7: %rating%"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index e406f5d5e..d33c678a7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1034,7 +1034,7 @@ public class SQLManager extends AbstractDB { public void run() { try { PreparedStatement statement = - connection.prepareStatement("DELETE FROM `"+PREFIX+"+plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); + connection.prepareStatement("DELETE FROM `"+PREFIX+"plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); statement.setInt(1, getId(world, plot.id)); statement.setString(2, player.getUniqueId().toString()); statement.executeUpdate();