From f00ac79c91bb8daaabaa4f07aefeb16d6ced8981 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 2 Mar 2016 17:42:04 +1100 Subject: [PATCH] Bump version / misc Fix regenallroads Add schematic y_offset Change visit/list for multi-owner plots Fix updater (pre-1.7.10) --- .../bukkit/util/block/GenChunk.java | 11 +++- .../com/intellectualcrafters/plot/PS.java | 17 ++++++ .../intellectualcrafters/plot/Updater.java | 57 ++++++++----------- .../plot/commands/Claim.java | 2 +- .../plot/commands/Load.java | 2 +- .../plot/commands/RegenAllRoads.java | 2 +- .../plot/commands/SchematicCmd.java | 19 +++---- .../plot/commands/Visit.java | 14 ++--- .../plot/commands/list.java | 2 +- .../plot/generator/HybridUtils.java | 2 +- .../plot/util/SchematicHandler.java | 29 ++++++---- .../com/plotsquared/sponge/SpongeMain.java | 2 +- build.gradle | 2 +- pom.xml | 2 +- 14 files changed, 85 insertions(+), 78 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java index c4044fb042..6258b8ecb8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java @@ -34,7 +34,7 @@ public GenChunk(Chunk chunk, ChunkWrapper wrap) { @Override public Chunk getChunkAbs() { ChunkWrapper wrap = getChunkWrapper(); - if (wrap.x != chunk.getX() || wrap.z != chunk.getZ()) { + if (chunk == null || wrap.x != chunk.getX() || wrap.z != chunk.getZ()) { chunk = BukkitUtil.getWorld(wrap.world).getChunkAt(wrap.x, wrap.z); } return chunk; @@ -65,9 +65,14 @@ public void setBlock(int x, int y, int z, int id, byte data) { modified = true; result[i] = v = new short[4096]; } - v[MainUtil.CACHE_J[y][x][z]] = (short) id; + int j = MainUtil.CACHE_J[y][x][z]; + v[j] = (short) id; if (data != 0) { - getChunk().getBlock(x, y, z).setData(data); + byte[] vd = result_data[i]; + if (vd == null) { + result_data[i] = vd = new byte[4096]; + } + vd[j] = data; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index fd472f856c..b3ab8c93a8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1332,6 +1332,10 @@ public Set getPlots(final PlotPlayer player) { return getPlots(player.getUUID()); } + public Set getBasePlots(final PlotPlayer player) { + return getBasePlots(player.getUUID()); + } + /** * Get the plots for a UUID * @param uuid @@ -1350,6 +1354,19 @@ public void run(Plot value) { return new HashSet<>(myplots); } + public Set getBasePlots(final UUID uuid) { + final ArrayList myplots = new ArrayList<>(); + foreachBasePlot(new RunnableVal() { + @Override + public void run(Plot value) { + if (value.isOwner(uuid)) { + myplots.add(value); + } + } + }); + return new HashSet<>(myplots); + } + /** * Get the plots for a UUID * @param uuid diff --git a/Core/src/main/java/com/intellectualcrafters/plot/Updater.java b/Core/src/main/java/com/intellectualcrafters/plot/Updater.java index dbfe55aafb..b813640ef7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/Updater.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/Updater.java @@ -1,16 +1,15 @@ package com.intellectualcrafters.plot; -import static com.intellectualcrafters.plot.PS.log; - -import com.google.gson.Gson; -import com.google.gson.annotations.SerializedName; +import com.intellectualcrafters.json.JSONArray; +import com.intellectualcrafters.json.JSONObject; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; -import java.util.List; + +import static com.intellectualcrafters.plot.PS.log; public class Updater { @@ -44,42 +43,32 @@ private static String readUrl(String urlString) { public static URL getUpdate() { String str = readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest"); - Gson gson = new Gson(); - URL url = null; - Release release = gson.fromJson(str, Release.class); + JSONObject release = new JSONObject(str); + JSONArray assets = (JSONArray) release.get("assets"); String downloadURL = String.format("PlotSquared-%s%n.jar", PS.get().getPlatform()); - List assets = release.assets; - for (Release.Asset asset : assets) { - if (asset.name.equals(downloadURL)) { + for (int i = 0; i < assets.length(); i++) { + JSONObject asset = assets.getJSONObject(i); + String name = asset.getString("name"); + if (downloadURL.equals(name)) { try { - url = new URL(asset.downloadUrl); - break; + String version = release.getString("name"); + URL url = new URL(asset.getString("downloadUrl")); + if (!PS.get().canUpdate(PS.get().config.getString("version"), version)) { + PS.debug("&7PlotSquared is already up to date!"); + return null; + } + log("&6PlotSquared " + version + " is available:"); + log("&8 - &3Use: &7/plot update"); + log("&8 - &3Or: &7" + downloadURL); + return url; } catch (MalformedURLException e) { e.printStackTrace(); - log("&dCould not check for updates (0)"); + log("&dCould not check for updates (1)"); log("&7 - Manually check for updates: https://github.com/IntellectualSites/PlotSquared/releases"); } } } - if (!PS.get().canUpdate(PS.get().config.getString("version"), release.name)) { - PS.debug("&7PlotSquared is already up to date!"); - return null; - } - log("&6PlotSquared " + release.tagName + " is available:"); - log("&8 - &3Use: &7/plot update"); - log("&8 - &3Or: &7" + downloadURL); - return url; - } - - - private static class Release { - public String name; - @SerializedName("tag_name") String tagName; - List assets; - static class Asset { - public String name; - @SerializedName("browser_download_url") String downloadUrl; - } - + log("You are running the latest version of PlotSquared"); + return null; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index ede8545ade..444f26db51 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -64,7 +64,7 @@ public static boolean claimPlot(final PlotPlayer player, final Plot plot, final sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE); } } - SchematicHandler.manager.paste(sch, plot, 0, 0, new RunnableVal() { + SchematicHandler.manager.paste(sch, plot, 0, 0, 0, true, new RunnableVal() { @Override public void run(Boolean value) { if (value) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java index f092768627..ad00530e87 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java @@ -91,7 +91,7 @@ public void run() { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format"); return; } - SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal() { + SchematicHandler.manager.paste(schematic, plot, 0, 0, 0, true, new RunnableVal() { @Override public void run(Boolean value) { plot.removeRunning(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java index 68bd938a25..fc5aa27ddb 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java @@ -61,7 +61,7 @@ public boolean onCommand(final PlotPlayer plr, final String[] args) { return false; } PlotArea area = PS.get().getPlotAreaByString(args[0]); - if (area == null || WorldUtil.IMP.isWorld(area.worldname)) { + if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) { C.NOT_VALID_PLOT_WORLD.send(plr, args[0]); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index 6541f8df3c..57e457c397 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -20,20 +20,10 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.UUID; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.object.ConsolePlayer; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; @@ -41,6 +31,11 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.UUID; + @CommandDeclaration( command = "schematic", permission = "plots.schematic", @@ -114,7 +109,7 @@ public void run() { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format"); return; } - SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal() { + SchematicHandler.manager.paste(schematic, plot, 0, 0, 0, true, new RunnableVal() { @Override public void run(Boolean value) { running = false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index 23cefc5879..adb217a52d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -20,14 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; @@ -39,6 +31,8 @@ import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; +import java.util.*; + @CommandDeclaration( command = "visit", permission = "plots.visit", @@ -83,11 +77,11 @@ public boolean onCommand(final PlotPlayer player, String[] args) { final UUID user = UUIDHandler.getCachedUUID(args[0], null); if (page == Integer.MIN_VALUE && user == null && MathMan.isInteger(args[0])) { page = Integer.parseInt(args[0]); - unsorted = PS.get().getPlots(player); + unsorted = PS.get().getBasePlots(player); break; } if (user != null) { - unsorted = PS.get().getPlots(user); + unsorted = PS.get().getBasePlots(user); } else if (PS.get().getPlotAreaByString(args[0]) != null) { unsorted = PS.get().getPlotAreaByString(args[0]).getPlots(); } else { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java index 9d97e46a10..7b37b720a4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -132,7 +132,7 @@ public boolean onCommand(final PlotPlayer plr, final String[] args) { return false; } sort = false; - plots = PS.get().sortPlotsByTemp(PS.get().getPlots(plr)); + plots = PS.get().sortPlotsByTemp(PS.get().getBasePlots(plr)); break; } case "shared": { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index b7efebc956..1102f82b62 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -409,7 +409,7 @@ public boolean regenerateRoad(final PlotArea area, final ChunkLoc chunk, int ext } if (blocks != null) { for (Entry entry : blocks.entrySet()) { - SetQueue.IMP.setBlock(area.worldname, x + X + plotworld.ROAD_OFFSET_X, sy + entry.getKey(), z + Z + plotworld.ROAD_OFFSET_Z, entry.getValue()); + SetQueue.IMP.setBlock(area.worldname, x + X + plotworld.ROAD_OFFSET_X, entry.getKey(), z + Z + plotworld.ROAD_OFFSET_Z, entry.getValue()); } } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index c0a487b816..892da8296c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -96,6 +96,8 @@ public void run() { }); return true; } + + /** * Paste a schematic @@ -107,7 +109,7 @@ public void run() { * * @return boolean true if succeeded */ - public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset, final RunnableVal whenDone) { + public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int y_offset, final int z_offset, final boolean autoHeight, final RunnableVal whenDone) { TaskManager.runTask(new Runnable() { @Override public void run() { @@ -147,18 +149,23 @@ public void run() { final short[] ids = schematic.ids; final byte[] datas = schematic.datas; // Calculate the optimal height to paste the schematic at - final int y_offset; - if (HEIGHT >= 256) { - y_offset = 0; - } else { - PlotArea pw = plot.getArea(); - if (pw instanceof ClassicPlotWorld) { - y_offset = ((ClassicPlotWorld) pw).PLOT_HEIGHT; + final int y_offset_actual; + if (autoHeight) { + if (HEIGHT >= 256) { + y_offset_actual = y_offset; } else { - y_offset = MainUtil.getHeighestBlock(plot.getArea().worldname, region.minX + 1, region.minZ + 1); + PlotArea pw = plot.getArea(); + if (pw instanceof ClassicPlotWorld) { + y_offset_actual = y_offset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; + } else { + y_offset_actual = y_offset + MainUtil.getHeighestBlock(plot.getArea().worldname, region.minX + 1, region.minZ + 1); + } } } - final Location pos1 = new Location(plot.getArea().worldname, region.minX + x_offset, y_offset, region.minZ + z_offset); + else { + y_offset_actual = y_offset; + } + final Location pos1 = new Location(plot.getArea().worldname, region.minX + x_offset, y_offset_actual, region.minZ + z_offset); final Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); // TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate); final int p1x = pos1.getX(); @@ -203,7 +210,7 @@ public void run() { // Paste schematic here for (int ry = 0; ry < Math.min(256, HEIGHT); ry++) { - final int yy = y_offset + ry; + final int yy = y_offset_actual + ry; if (yy > 255) { continue; } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 828603ea4c..edd5d02c4a 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -50,7 +50,7 @@ * Created by robin on 01/11/2014 */ -@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.3.0", dependencies = "before:WorldEdit") +@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.3.1", dependencies = "before:WorldEdit") public class SpongeMain implements IPlotMain { public static SpongeMain THIS; diff --git a/build.gradle b/build.gradle index 736f61b57a..ea64759216 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { } group = 'com.intellectualcrafters' -version = '3.3.0' +version = '3.3.1' description = """PlotSquared""" subprojects { diff --git a/pom.xml b/pom.xml index 02f0ea8720..1a819a0e32 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.3.0 + 3.3.1 PlotSquared jar