From 92f94ecedc712425b7bcb94d6f811134d142be7c Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 24 Sep 2017 00:13:05 +1000 Subject: [PATCH] Tweaks Use sign with plot schematic Tweak world unloading --- .../com/plotsquared/bukkit/BukkitMain.java | 25 ++++++++++------ .../plotsquared/bukkit/util/BukkitUtil.java | 10 ++++++- .../plot/generator/HybridGen.java | 6 +++- .../plot/generator/HybridPlotManager.java | 9 ++++++ .../plot/generator/HybridPlotWorld.java | 30 ++++++++++++++++++- .../plot/generator/SquarePlotManager.java | 24 +++++++++++++++ .../plot/util/MathMan.java | 6 ++++ 7 files changed, 98 insertions(+), 12 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index db343dd4d..ace0a25c9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -200,7 +200,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain public void run() { unload(); } - }, 20); + }, 5); } } @@ -211,19 +211,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea(); for (World world : Bukkit.getWorlds()) { String name = world.getName(); + char char0 = name.charAt(0); + if (!Character.isDigit(char0) && char0 != '-') continue; + if (!world.getPlayers().isEmpty()) continue; + PlotId id = PlotId.fromString(name); if (id != null) { Plot plot = area.getOwnedPlot(id); if (plot != null) { - List players = plot.getPlayersInPlot(); - if (players.isEmpty() && PlotPlayer.wrap(plot.owner) == null) { - for (Chunk chunk : world.getLoadedChunks()) { - if (!chunk.unload(true, false)) return; - if (System.currentTimeMillis() - start > 20) { - return; - } + if (PlotPlayer.wrap(plot.owner) == null) { + if (world.getKeepSpawnInMemory()) { + world.setKeepSpawnInMemory(false); + return; + } + Chunk[] chunks = world.getLoadedChunks(); + if (chunks.length == 0) { + if (!Bukkit.unloadWorld(world, true)) { + PS.debug("Failed to unload " + world.getName()); + } + return; } - Bukkit.unloadWorld(world, true); } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index a515cdfd6..a401cf037 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -119,7 +119,15 @@ public class BukkitUtil extends WorldUtil { World world = getWorld(worldName); Block block = world.getBlockAt(x, y, z); // block.setType(Material.AIR); - block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false); + Material type = block.getType(); + if (type != Material.SIGN && type != Material.SIGN_POST) { + int data = 2; + if (world.getBlockAt(x, y, z + 1).getType().isSolid()) data = 2; + else if (world.getBlockAt(x + 1, y, z).getType().isSolid()) data = 4; + else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) data = 3; + else if (world.getBlockAt(x - 1, y, z).getType().isSolid()) data = 5; + block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) data, false); + } BlockState blockstate = block.getState(); if (blockstate instanceof Sign) { final Sign sign = (Sign) blockstate; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 404ea688f..5c7db22ef 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -214,11 +214,15 @@ public class HybridGen extends IndependentPlotGenerator { if (queue == null) { queue = GlobalBlockQueue.IMP.getNewQueue(hpw.worldname, false); } - SchematicHandler.manager.restoreTile(queue, entry.getValue(), p1x + x, entry.getKey(), p1z + z); + CompoundTag tag = entry.getValue(); + SchematicHandler.manager.restoreTile(queue, tag, p1x + x, entry.getKey(), p1z + z); } } } } + if (queue != null) { + queue.flush(); + } } return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java index 49211ba23..7c374f197 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java @@ -208,4 +208,13 @@ public class HybridPlotManager extends ClassicPlotManager { } createSchemAbs(plotWorld, queue, l1, l2, false); } + + /** + * Remove sign for a plot. + */ + @Override + public Location getSignLoc(PlotArea plotArea, Plot plot) { + HybridPlotWorld dpw = (HybridPlotWorld) plotArea; + return dpw.getSignLocation(plot); + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index c0ff84a78..d413c582a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -2,18 +2,21 @@ package com.intellectualcrafters.plot.generator; import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.jnbt.CompoundTag; +import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.BlockLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.ReflectionUtils; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; - import java.io.File; import java.util.HashMap; import java.util.Map; @@ -26,6 +29,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { public short PATH_WIDTH_UPPER; public HashMap G_SCH; public HashMap> G_SCH_STATE; + private Location SIGN_LOCATION; public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) { super(worldName, id, generator, min, max); @@ -45,6 +49,19 @@ public class HybridPlotWorld extends ClassicPlotWorld { return data; } + public Location getSignLocation(Plot plot) { + plot = plot.getBasePlot(false); + Location bot = plot.getBottomAbs(); + if (SIGN_LOCATION == null) { + bot.setY(ROAD_HEIGHT + 1); + return bot.add(-1, ROAD_HEIGHT, -2); + } else { + bot.setY(0); + Location loc = bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ()); + return loc; + } + } + // FIXME depends on block ids // Possibly make abstract? public static byte rotate(short id, byte data) { @@ -228,6 +245,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { HashMap items = schematic3.getTiles(); if (!items.isEmpty()) { this.G_SCH_STATE = new HashMap<>(); + outer: for (Map.Entry entry : items.entrySet()) { BlockLoc loc = entry.getKey(); short x = (short) (loc.x + shift + oddshift + centerShiftX); @@ -240,6 +258,16 @@ public class HybridPlotWorld extends ClassicPlotWorld { this.G_SCH_STATE.put(pair, existing); } existing.put((int) y, entry.getValue()); + + CompoundTag tag = entry.getValue(); + Map map = ReflectionUtils.getMap(tag.getValue()); + for (int i = 1; i <= 4; i++) { + String ln = tag.getString("Line" + i); + if (ln == null || ln.length() > 11) continue outer; + } + SIGN_LOCATION = new Location(worldname, loc.x + centerShiftX, this.PLOT_HEIGHT + loc.y, loc.z + centerShiftZ); + ALLOW_SIGNS = true; + continue outer; } } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index bea05ebe0..524463365 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -96,6 +96,30 @@ public abstract class SquarePlotManager extends GridPlotManager { } } + public PlotId getNearestPlotId(PlotArea plotArea, int x, int y, int z) { + SquarePlotWorld dpw = (SquarePlotWorld) plotArea; + if (dpw.ROAD_OFFSET_X != 0) { + x -= dpw.ROAD_OFFSET_X; + } + if (dpw.ROAD_OFFSET_Z != 0) { + z -= dpw.ROAD_OFFSET_Z; + } + int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; + int idx; + if (x < 0) { + idx = x / size; + } else { + idx = (x / size) + 1; + } + int idz; + if (z < 0) { + idz = z / size; + } else { + idz = (z / size) + 1; + } + return new PlotId(idx, idz); + } + @Override public PlotId getPlotId(PlotArea plotArea, int x, int y, int z) { try { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java index 10beca24f..4007249d7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java @@ -182,6 +182,12 @@ public class MathMan { return new float[]{(float) (pitch_sin * Math.cos(yaw)), (float) (pitch_sin * Math.sin(yaw)), (float) Math.cos(pitch)}; } + public static int floorMod(int x, int y) { + int i = x % y; + if (i < 0) i += y; + return i; + } + public static int roundInt(double value) { return (int) (value < 0 ? (value == (int) value) ? value : value - 1 : value); }