diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 2dd7ad786..c137ed548 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -97,6 +97,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; @@ -109,6 +110,16 @@ import org.bukkit.plugin.Plugin; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; import java.util.ArrayList; import java.util.Arrays; @@ -463,6 +474,13 @@ public class PlayerEvents extends PlotListener implements Listener { }, 20); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void playerRespawn(PlayerRespawnEvent event) { + final Player player = event.getPlayer(); + final PlotPlayer pp = BukkitUtil.getPlayer(player); + EventUtil.manager.doDeathTask(pp); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerMove(PlayerMoveEvent event) { org.bukkit.Location from = event.getFrom(); @@ -616,11 +634,14 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = area.getPlotAbs(loc); if (plot != null) { - if (event.getBlock().getY() == 0) { - event.setCancelled(true); - return; - } PlotPlayer pp = BukkitUtil.getPlayer(player); + if (event.getBlock().getY() == 0) { + if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL); + event.setCancelled(true); + return; + } + } if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_UNOWNED)) { return; @@ -727,7 +748,7 @@ public class PlayerEvents extends PlotListener implements Listener { plotExit(pp, plot); } - if (BukkitMain.worldEdit != null) { + if (BukkitMain.worldEdit != null && PS.get().worldedit != null) { if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) { if (pp.getAttribute("worldedit")) { pp.removeAttribute("worldedit"); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 30b8e3b25..0829e123f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -20,6 +20,14 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.bukkit.object.entity.EntityWrapper; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.DyeColor; @@ -52,17 +60,545 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - public class BukkitChunkManager extends ChunkManager { + public static class ContentMap { + public HashMap chestContents; + public HashMap furnaceContents; + public HashMap dispenserContents; + public HashMap dropperContents; + public HashMap brewingStandContents; + public HashMap beaconContents; + public HashMap hopperContents; + public HashMap furnaceTime; + public HashMap skullData; + public HashMap jukeboxDisc; + public HashMap brewTime; + public HashMap spawnerData; + public HashMap cmdData; + public HashMap signContents; + public HashMap noteBlockContents; + public HashMap> bannerPatterns; + public HashMap bannerBase; + public HashSet entities; + public HashMap allBlocks; + + public ContentMap() { + chestContents = new HashMap<>(); + furnaceContents = new HashMap<>(); + dispenserContents = new HashMap<>(); + dropperContents = new HashMap<>(); + brewingStandContents = new HashMap<>(); + beaconContents = new HashMap<>(); + hopperContents = new HashMap<>(); + furnaceTime = new HashMap<>(); + skullData = new HashMap<>(); + brewTime = new HashMap<>(); + jukeboxDisc = new HashMap<>(); + spawnerData = new HashMap<>(); + noteBlockContents = new HashMap<>(); + signContents = new HashMap<>(); + cmdData = new HashMap<>(); + bannerBase = new HashMap<>(); + bannerPatterns = new HashMap<>(); + entities = new HashSet<>(); + allBlocks = new HashMap<>(); + } + + public void saveRegion(World world, int x1, int x2, int z1, int z2) { + if (z1 > z2) { + int tmp = z1; + z1 = z2; + z2 = tmp; + } + if (x1 > x2) { + int tmp = x1; + x1 = x2; + x2 = tmp; + } + for (int x = x1; x <= x2; x++) { + for (int z = z1; z <= z2; z++) { + saveBlocks(world, 256, x, z, 0, 0, true); + } + } + } + + public void saveEntitiesIn(Chunk chunk, RegionWrapper region) { + saveEntitiesIn(chunk, region, 0, 0, false); + } + + public void saveEntitiesOut(Chunk chunk, RegionWrapper region) { + for (Entity entity : chunk.getEntities()) { + Location loc = BukkitUtil.getLocation(entity); + int x = loc.getX(); + int z = loc.getZ(); + if (isIn(region, x, z)) { + continue; + } + if (entity.getVehicle() != null) { + continue; + } + EntityWrapper wrap = new EntityWrapper(entity, (short) 2); + entities.add(wrap); + } + } + + public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, boolean delete) { + for (Entity entity : chunk.getEntities()) { + Location loc = BukkitUtil.getLocation(entity); + int x = loc.getX(); + int z = loc.getZ(); + if (!isIn(region, x, z)) { + continue; + } + if (entity.getVehicle() != null) { + continue; + } + EntityWrapper wrap = new EntityWrapper(entity, (short) 2); + wrap.x += offsetX; + wrap.z += offsetZ; + entities.add(wrap); + if (delete) { + if (!(entity instanceof Player)) { + entity.remove(); + } + } + } + } + + public void restoreEntities(World world, int xOffset, int zOffset) { + for (EntityWrapper entity : entities) { + try { + entity.spawn(world, xOffset, zOffset); + } catch (Exception e) { + PS.debug("Failed to restore entity (e): " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.type); + e.printStackTrace(); + } + } + entities.clear(); + } + + public void restoreBlocks(World world, int xOffset, int zOffset) { + for (Entry blockLocEntry : chestContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof InventoryHolder) { + InventoryHolder chest = (InventoryHolder) state; + chest.getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : signContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Sign) { + Sign sign = (Sign) state; + int i = 0; + for (String line : blockLocEntry.getValue()) { + sign.setLine(i, line); + i++; + } + state.update(true); + } else { + PS.debug( + "&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y + + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } catch (IndexOutOfBoundsException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y + + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : dispenserContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Dispenser) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : dropperContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Dropper) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : beaconContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Beacon) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocMaterialEntry : jukeboxDisc.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset, blockLocMaterialEntry.getKey().y, blockLocMaterialEntry + .getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Jukebox) { + ((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + "," + + blockLocMaterialEntry + .getKey().y + "," + ( + blockLocMaterialEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + "," + + blockLocMaterialEntry + .getKey().y + "," + ( + blockLocMaterialEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : skullData.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Skull) { + Object[] data = blockLocEntry.getValue(); + if (data[0] != null) { + ((Skull) state).setOwner((String) data[0]); + } + if ((Integer) data[1] != 0) { + ((Skull) state).setRotation(BlockFace.values()[(int) data[1]]); + } + if ((Integer) data[2] != 0) { + ((Skull) state).setSkullType(SkullType.values()[(int) data[2]]); + } + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y + + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : hopperContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Hopper) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocNoteEntry : noteBlockContents.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocNoteEntry.getKey().x + xOffset, blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof NoteBlock) { + ((NoteBlock) state).setNote(blockLocNoteEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + "," + + blockLocNoteEntry + .getKey().y + "," + ( + blockLocNoteEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + "," + + blockLocNoteEntry + .getKey().y + "," + ( + blockLocNoteEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocShortEntry : brewTime.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocShortEntry.getKey().x + xOffset, blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof BrewingStand) { + ((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue()); + } else { + PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + "," + + blockLocShortEntry + .getKey().y + "," + ( + blockLocShortEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + "," + + blockLocShortEntry.getKey().y + "," + (blockLocShortEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntityTypeEntry : spawnerData.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset, blockLocEntityTypeEntry.getKey().y, blockLocEntityTypeEntry + .getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof CreatureSpawner) { + ((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," + + blockLocEntityTypeEntry + .getKey().y + "," + ( + blockLocEntityTypeEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," + + blockLocEntityTypeEntry.getKey().y + "," + (blockLocEntityTypeEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocStringEntry : cmdData.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocStringEntry.getKey().x + xOffset, blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof CommandBlock) { + ((CommandBlock) state).setCommand(blockLocStringEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + "," + + blockLocStringEntry + .getKey().y + "," + ( + blockLocStringEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + "," + + blockLocStringEntry + .getKey().y + "," + ( + blockLocStringEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : brewingStandContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof BrewingStand) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + + zOffset)); + } + } + for (Entry blockLocEntry : furnaceTime.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Furnace) { + Short[] time = blockLocEntry.getValue(); + ((Furnace) state).setBurnTime(time[0]); + ((Furnace) state).setCookTime(time[1]); + } else { + PS.debug("&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : furnaceContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Furnace) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocByteEntry : bannerBase.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocByteEntry.getKey().x + xOffset, blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Banner) { + Banner banner = (Banner) state; + DyeColor base = blockLocByteEntry.getValue(); + List patterns = bannerPatterns.get(blockLocByteEntry.getKey()); + banner.setBaseColor(base); + banner.setPatterns(patterns); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + "," + blockLocByteEntry + .getKey().y + "," + ( + blockLocByteEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + "," + blockLocByteEntry + .getKey().y + "," + ( + blockLocByteEntry.getKey().z + zOffset)); + } + } + } + + public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, boolean storeNormal) { + maxY = Math.min(255, maxY); + PlotBlock[] ids; + if (storeNormal) { + ids = new PlotBlock[maxY + 1]; + } else { + ids = null; + } + for (short y = 0; y <= maxY; y++) { + Block block = world.getBlockAt(x, y, z); + Material id = block.getType(); + if (storeNormal) { + int typeId = id.getId(); + ids[y] = new PlotBlock((short) typeId, typeId == 0 ? 0 : block.getData()); + } + if (!id.equals(Material.AIR)) { + try { + BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ); + if (block.getState() instanceof InventoryHolder) { + InventoryHolder inventoryHolder = (InventoryHolder) block.getState(); + ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone(); + if (id == Material.CHEST) { + chestContents.put(bl, inventory); + } else if (id == Material.DISPENSER) { + dispenserContents.put(bl, inventory); + } else if (id == Material.BEACON) { + beaconContents.put(bl, inventory); + } else if (id == Material.DROPPER) { + dropperContents.put(bl, inventory); + } else if (id == Material.HOPPER) { + hopperContents.put(bl, inventory); + } else if (id == Material.BREWING_STAND) { + BrewingStand brewingStand = (BrewingStand) inventoryHolder; + short time = (short) brewingStand.getBrewingTime(); + if (time > 0) { + brewTime.put(bl, time); + } + ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); + brewingStandContents.put(bl, invBre); + } else if (id == Material.FURNACE || id == Material.BURNING_FURNACE) { + Furnace furnace = (Furnace) inventoryHolder; + short burn = furnace.getBurnTime(); + short cook = furnace.getCookTime(); + ItemStack[] invFur = furnace.getInventory().getContents().clone(); + furnaceContents.put(bl, invFur); + if (cook != 0) { + furnaceTime.put(bl, new Short[]{burn, cook}); + } + } + } else if (block.getState() instanceof CreatureSpawner) { + CreatureSpawner spawner = (CreatureSpawner) block.getState(); + EntityType type = spawner.getSpawnedType(); + if (type != null) { + spawnerData.put(bl, type); + } + } else if (block.getState() instanceof CommandBlock) { + CommandBlock cmd = (CommandBlock) block.getState(); + String string = cmd.getCommand(); + if (string != null && !string.isEmpty()) { + cmdData.put(bl, string); + } + } else if (block.getState() instanceof NoteBlock) { + NoteBlock noteBlock = (NoteBlock) block.getState(); + Note note = noteBlock.getNote(); + noteBlockContents.put(bl, note); + } else if (block.getState() instanceof Jukebox) { + Jukebox jukebox = (Jukebox) block.getState(); + Material playing = jukebox.getPlaying(); + if (playing != null) { + jukeboxDisc.put(bl, playing); + } + } else if (block.getState() instanceof Skull) { + Skull skull = (Skull) block.getState(); + String o = skull.getOwner(); + byte skullType = getOrdinal(SkullType.values(), skull.getSkullType()); + skull.getRotation(); + short rot = getOrdinal(BlockFace.values(), skull.getRotation()); + skullData.put(bl, new Object[]{o, rot, skullType}); + } else if (block.getState() instanceof Banner) { + Banner banner = (Banner) block.getState(); + DyeColor base = banner.getBaseColor(); + bannerBase.put(bl, base); + bannerPatterns.put(bl, banner.getPatterns()); + + } + } catch (Exception e) { + PS.debug("------------ FAILED TO DO SOMETHING --------"); + e.printStackTrace(); + PS.debug("------------ but we caught it ^ --------"); + } + } + } + PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ); + allBlocks.put(loc, ids); + } + } + public static boolean isIn(RegionWrapper region, int x, int z) { return x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ; } @@ -137,22 +673,6 @@ public class BukkitChunkManager extends ChunkManager { return chunks; } - @Override - public void regenerateChunk(String world, ChunkLoc loc) { - World worldObj = Bukkit.getWorld(world); - worldObj.regenerateChunk(loc.x, loc.z); - SetQueue.IMP.queue.sendChunk(world, Collections.singletonList(loc)); - for (Entry entry : UUIDHandler.getPlayers().entrySet()) { - PlotPlayer pp = entry.getValue(); - Location pLoc = pp.getLocation(); - if (!StringMan.isEqual(world, pLoc.getWorld()) || !pLoc.getChunkLoc().equals(loc)) { - continue; - } - pLoc.setY(WorldUtil.IMP.getHighestBlock(world, pLoc.getX(), pLoc.getZ())); - pp.teleport(pLoc); - } - } - @Override public boolean copyRegion(Location pos1, Location pos2, Location newPos, final Runnable whenDone) { final int relX = newPos.getX() - pos1.getX(); @@ -407,7 +927,7 @@ public class BukkitChunkManager extends ChunkManager { RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); final World world1 = Bukkit.getWorld(bot1.getWorld()); - World world2 = Bukkit.getWorld(bot2.getWorld()); + final World world2 = Bukkit.getWorld(bot2.getWorld()); int relX = bot2.getX() - bot1.getX(); int relZ = bot2.getZ() - bot1.getZ(); @@ -611,550 +1131,4 @@ public class BukkitChunkManager extends ChunkManager { } count[0]++; } - - public static class ContentMap { - - public final HashMap chestContents; - public final HashMap furnaceContents; - public final HashMap dispenserContents; - public final HashMap dropperContents; - public final HashMap brewingStandContents; - public final HashMap beaconContents; - public final HashMap hopperContents; - public final HashMap furnaceTime; - public final HashMap skullData; - public final HashMap jukeboxDisc; - public final HashMap brewTime; - public final HashMap spawnerData; - public final HashMap cmdData; - public final HashMap signContents; - public final HashMap noteBlockContents; - public final HashMap> bannerPatterns; - public final HashMap bannerBase; - public final HashSet entities; - public final HashMap allBlocks; - - public ContentMap() { - this.chestContents = new HashMap<>(); - this.furnaceContents = new HashMap<>(); - this.dispenserContents = new HashMap<>(); - this.dropperContents = new HashMap<>(); - this.brewingStandContents = new HashMap<>(); - this.beaconContents = new HashMap<>(); - this.hopperContents = new HashMap<>(); - this.furnaceTime = new HashMap<>(); - this.skullData = new HashMap<>(); - this.brewTime = new HashMap<>(); - this.jukeboxDisc = new HashMap<>(); - this.spawnerData = new HashMap<>(); - this.noteBlockContents = new HashMap<>(); - this.signContents = new HashMap<>(); - this.cmdData = new HashMap<>(); - this.bannerBase = new HashMap<>(); - this.bannerPatterns = new HashMap<>(); - this.entities = new HashSet<>(); - this.allBlocks = new HashMap<>(); - } - - public void saveRegion(World world, int x1, int x2, int z1, int z2) { - if (z1 > z2) { - int tmp = z1; - z1 = z2; - z2 = tmp; - } - if (x1 > x2) { - int tmp = x1; - x1 = x2; - x2 = tmp; - } - for (int x = x1; x <= x2; x++) { - for (int z = z1; z <= z2; z++) { - saveBlocks(world, 256, x, z, 0, 0, true); - } - } - } - - public void saveEntitiesIn(Chunk chunk, RegionWrapper region) { - saveEntitiesIn(chunk, region, 0, 0, false); - } - - public void saveEntitiesOut(Chunk chunk, RegionWrapper region) { - for (Entity entity : chunk.getEntities()) { - Location loc = BukkitUtil.getLocation(entity); - int x = loc.getX(); - int z = loc.getZ(); - if (isIn(region, x, z)) { - continue; - } - if (entity.getVehicle() != null) { - continue; - } - EntityWrapper wrap = new EntityWrapper(entity, (short) 2); - this.entities.add(wrap); - } - } - - public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, boolean delete) { - for (Entity entity : chunk.getEntities()) { - Location loc = BukkitUtil.getLocation(entity); - int x = loc.getX(); - int z = loc.getZ(); - if (!isIn(region, x, z)) { - continue; - } - if (entity.getVehicle() != null) { - continue; - } - EntityWrapper wrap = new EntityWrapper(entity, (short) 2); - wrap.x += offsetX; - wrap.z += offsetZ; - this.entities.add(wrap); - if (delete) { - if (!(entity instanceof Player)) { - entity.remove(); - } - } - } - } - - public void restoreEntities(World world, int xOffset, int zOffset) { - for (EntityWrapper entity : this.entities) { - try { - entity.spawn(world, xOffset, zOffset); - } catch (Exception e) { - PS.debug("Failed to restore entity (e): " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.type); - e.printStackTrace(); - } - } - this.entities.clear(); - } - - public void restoreBlocks(World world, int xOffset, int zOffset) { - for (Entry blockLocEntry : this.chestContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof InventoryHolder) { - InventoryHolder chest = (InventoryHolder) state; - chest.getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.signContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Sign) { - Sign sign = (Sign) state; - int i = 0; - for (String line : blockLocEntry.getValue()) { - sign.setLine(i, line); - i++; - } - state.update(true); - } else { - PS.debug( - "&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y - + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } catch (IndexOutOfBoundsException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y - + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.dispenserContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Dispenser) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.dropperContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Dropper) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.beaconContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Beacon) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocMaterialEntry : this.jukeboxDisc.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset, blockLocMaterialEntry.getKey().y, blockLocMaterialEntry - .getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Jukebox) { - ((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + "," - + blockLocMaterialEntry - .getKey().y + "," + ( - blockLocMaterialEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + "," - + blockLocMaterialEntry - .getKey().y + "," + ( - blockLocMaterialEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.skullData.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Skull) { - Object[] data = blockLocEntry.getValue(); - if (data[0] != null) { - ((Skull) state).setOwner((String) data[0]); - } - if ((Integer) data[1] != 0) { - ((Skull) state).setRotation(BlockFace.values()[(int) data[1]]); - } - if ((Integer) data[2] != 0) { - ((Skull) state).setSkullType(SkullType.values()[(int) data[2]]); - } - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y - + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.hopperContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Hopper) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocNoteEntry : this.noteBlockContents.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocNoteEntry.getKey().x + xOffset, blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof NoteBlock) { - ((NoteBlock) state).setNote(blockLocNoteEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + "," - + blockLocNoteEntry - .getKey().y + "," + ( - blockLocNoteEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + "," - + blockLocNoteEntry - .getKey().y + "," + ( - blockLocNoteEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocShortEntry : this.brewTime.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocShortEntry.getKey().x + xOffset, blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof BrewingStand) { - ((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue()); - } else { - PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + "," - + blockLocShortEntry - .getKey().y + "," + ( - blockLocShortEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + "," - + blockLocShortEntry.getKey().y + "," + (blockLocShortEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntityTypeEntry : this.spawnerData.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset, blockLocEntityTypeEntry.getKey().y, blockLocEntityTypeEntry - .getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof CreatureSpawner) { - ((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," - + blockLocEntityTypeEntry - .getKey().y + "," + ( - blockLocEntityTypeEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," - + blockLocEntityTypeEntry.getKey().y + "," + (blockLocEntityTypeEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocStringEntry : this.cmdData.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocStringEntry.getKey().x + xOffset, blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof CommandBlock) { - ((CommandBlock) state).setCommand(blockLocStringEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + "," - + blockLocStringEntry - .getKey().y + "," + ( - blockLocStringEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + "," - + blockLocStringEntry - .getKey().y + "," + ( - blockLocStringEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.brewingStandContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof BrewingStand) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + "," - + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z - + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + "," - + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z - + zOffset)); - } - } - for (Entry blockLocEntry : this.furnaceTime.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Furnace) { - Short[] time = blockLocEntry.getValue(); - ((Furnace) state).setBurnTime(time[0]); - ((Furnace) state).setCookTime(time[1]); - } else { - PS.debug( - "&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug( - "&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : this.furnaceContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Furnace) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocByteEntry : this.bannerBase.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocByteEntry.getKey().x + xOffset, blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Banner) { - Banner banner = (Banner) state; - DyeColor base = blockLocByteEntry.getValue(); - List patterns = this.bannerPatterns.get(blockLocByteEntry.getKey()); - banner.setBaseColor(base); - banner.setPatterns(patterns); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + "," - + blockLocByteEntry - .getKey().y + "," + ( - blockLocByteEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + "," - + blockLocByteEntry - .getKey().y + "," + ( - blockLocByteEntry.getKey().z + zOffset)); - } - } - } - - public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, boolean storeNormal) { - maxY = Math.min(255, maxY); - PlotBlock[] ids; - if (storeNormal) { - ids = new PlotBlock[maxY + 1]; - } else { - ids = null; - } - for (short y = 0; y <= maxY; y++) { - Block block = world.getBlockAt(x, y, z); - Material id = block.getType(); - if (storeNormal) { - int typeId = id.getId(); - ids[y] = new PlotBlock((short) typeId, typeId == 0 ? 0 : block.getData()); - } - if (!id.equals(Material.AIR)) { - try { - BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ); - if (block.getState() instanceof InventoryHolder) { - InventoryHolder inventoryHolder = (InventoryHolder) block.getState(); - ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone(); - if (id == Material.CHEST) { - this.chestContents.put(bl, inventory); - } else if (id == Material.DISPENSER) { - this.dispenserContents.put(bl, inventory); - } else if (id == Material.BEACON) { - this.beaconContents.put(bl, inventory); - } else if (id == Material.DROPPER) { - this.dropperContents.put(bl, inventory); - } else if (id == Material.HOPPER) { - this.hopperContents.put(bl, inventory); - } else if (id == Material.BREWING_STAND) { - BrewingStand brewingStand = (BrewingStand) inventoryHolder; - short time = (short) brewingStand.getBrewingTime(); - if (time > 0) { - this.brewTime.put(bl, time); - } - ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); - this.brewingStandContents.put(bl, invBre); - } else if (id == Material.FURNACE || id == Material.BURNING_FURNACE) { - Furnace furnace = (Furnace) inventoryHolder; - short burn = furnace.getBurnTime(); - short cook = furnace.getCookTime(); - ItemStack[] invFur = furnace.getInventory().getContents().clone(); - this.furnaceContents.put(bl, invFur); - if (cook != 0) { - this.furnaceTime.put(bl, new Short[]{burn, cook}); - } - } - } else if (block.getState() instanceof CreatureSpawner) { - CreatureSpawner spawner = (CreatureSpawner) block.getState(); - EntityType type = spawner.getSpawnedType(); - if (type != null) { - this.spawnerData.put(bl, type); - } - } else if (block.getState() instanceof CommandBlock) { - CommandBlock cmd = (CommandBlock) block.getState(); - String string = cmd.getCommand(); - if (string != null && !string.isEmpty()) { - this.cmdData.put(bl, string); - } - } else if (block.getState() instanceof NoteBlock) { - NoteBlock noteBlock = (NoteBlock) block.getState(); - Note note = noteBlock.getNote(); - this.noteBlockContents.put(bl, note); - } else if (block.getState() instanceof Jukebox) { - Jukebox jukebox = (Jukebox) block.getState(); - Material playing = jukebox.getPlaying(); - if (playing != null) { - this.jukeboxDisc.put(bl, playing); - } - } else if (block.getState() instanceof Skull) { - Skull skull = (Skull) block.getState(); - String o = skull.getOwner(); - byte skullType = getOrdinal(SkullType.values(), skull.getSkullType()); - skull.getRotation(); - short rot = getOrdinal(BlockFace.values(), skull.getRotation()); - this.skullData.put(bl, new Object[]{o, rot, skullType}); - } else if (block.getState() instanceof Banner) { - Banner banner = (Banner) block.getState(); - DyeColor base = banner.getBaseColor(); - this.bannerBase.put(bl, base); - this.bannerPatterns.put(bl, banner.getPatterns()); - - } - } catch (Exception e) { - PS.debug("------------ FAILED TO DO SOMETHING --------"); - e.printStackTrace(); - PS.debug("------------ but we caught it ^ --------"); - } - } - } - PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ); - this.allBlocks.put(loc, ids); - } - } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java index 4fe6218af..719819955 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java @@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; +import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.SendChunk; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -37,6 +38,7 @@ public class FastQueue_1_8_3 extends SlowQueue { private final SendChunk sendChunk; private final HashMap toUpdate = new HashMap<>(); private final RefMethod methodGetHandleChunk; + private final RefMethod methodGetHandleWorld; private final RefMethod methodInitLighting; private final RefConstructor classBlockPositionConstructor; private final RefConstructor classChunkSectionConstructor; @@ -50,6 +52,7 @@ public class FastQueue_1_8_3 extends SlowQueue { public FastQueue_1_8_3() throws RuntimeException { RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); + RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); RefClass classChunk = getRefClass("{nms}.Chunk"); this.methodInitLighting = classChunk.getMethod("initLighting"); @@ -64,6 +67,7 @@ public class FastQueue_1_8_3 extends SlowQueue { this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class); this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class); this.tileEntityListTick = classWorld.getField("tileEntityList"); + this.methodGetHandleWorld = classCraftWorld.getMethod("getHandle"); this.methodGetWorld = classChunk.getMethod("getWorld"); this.sendChunk = new SendChunk(); TaskManager.runTaskRepeat(new Runnable() { @@ -257,6 +261,17 @@ public class FastQueue_1_8_3 extends SlowQueue { return new FastChunk_1_8_3(wrap); } + @Override + public void regenerateChunk(String worldname, ChunkLoc loc) { + World world = BukkitUtil.getWorld(worldname); + Chunk chunk = world.getChunkAt(loc.x, loc.z); + if (chunk.getTileEntities().length > 0) { + Object w = methodGetHandleWorld.of(world).call(); + ((Collection) this.tileEntityListTick.of(w).get()).clear(); + } + super.regenerateChunk(worldname, loc); + } + /** * This should be overridden by any specialized queues * @param plotChunk diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index 04b3eaa91..c0d7b8f06 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -80,6 +80,18 @@ public class FastQueue_1_9 extends SlowQueue { MainUtil.initCache(); } + @Override + public void regenerateChunk(String worldname, ChunkLoc loc) { + World world = BukkitUtil.getWorld(worldname); + Chunk chunk = world.getChunkAt(loc.x, loc.z); + if (chunk.getTileEntities().length > 0) { + Object c = methodGetHandleChunk.of(chunk).call(); + Object w = methodGetWorld.of(c).call(); + ((Collection) this.tileEntityListTick.of(w).get()).clear(); + } + super.regenerateChunk(worldname, loc); + } + /** * This should be overridden by any specialized queues * @param plotChunk diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java index 60405a756..86821aae4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java @@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.util.PlotChunk; import com.intellectualcrafters.plot.util.PlotQueue; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import com.plotsquared.bukkit.util.BukkitUtil; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; @@ -103,6 +104,11 @@ public class SlowQueue implements PlotQueue { this.blocks.clear(); } + @Override + public void regenerateChunk(String world, ChunkLoc loc) { + BukkitUtil.getWorld(world).regenerateChunk(loc.x, loc.z); + } + /** * This should be overridden by any specialized queues. * @param plotChunk diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 634247e9e..dccd9cf7d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -53,7 +53,6 @@ import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.area.QuadMap; import com.plotsquared.listener.WESubscriber; import com.sk89q.worldedit.WorldEdit; - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -2030,6 +2029,7 @@ public class PS { // Teleportation options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); + options.put("teleport.on_death", Settings.TELEPORT_ON_DEATH); options.put("teleport.delay", Settings.TELEPORT_DELAY); // WorldEdit @@ -2140,6 +2140,7 @@ public class PS { // Teleportation Settings.TELEPORT_DELAY = this.config.getInt("teleport.delay"); Settings.TELEPORT_ON_LOGIN = this.config.getBoolean("teleport.on_login"); + Settings.TELEPORT_ON_DEATH = this.config.getBoolean("teleport.on_death"); // WorldEdit Settings.QUEUE_COMMANDS = this.config.getBoolean("worldedit.queue-commands"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index f59c94032..43c9e244f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -5,7 +5,6 @@ import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandCaller; - import java.io.File; import java.util.EnumSet; import java.util.HashMap; @@ -58,6 +57,7 @@ public enum C { PERMISSION_COMMANDS_CHAT("plots.admin.command.chat", "static.permissions"), PERMISSION_MERGE_OTHER("plots.merge.other", "static.permissions"), PERMISSION_ADMIN_DESTROY_UNOWNED("plots.admin.destroy.unowned", "static.permissions"), + PERMISSION_ADMIN_DESTROY_GROUNDLEVEL("plots.admin.destroy.groundlevel", "static.permissions"), PERMISSION_ADMIN_DESTROY_OTHER("plots.admin.destroy.other", "static.permissions"), PERMISSION_ADMIN_DESTROY_ROAD("plots.admin.destroy.road", "static.permissions"), PERMISSION_ADMIN_BUILD_ROAD("plots.admin.build.road", "static.permissions"), diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index ef028ed88..d911f5748 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -11,10 +11,10 @@ import java.util.List; */ public class Settings { public static boolean USE_SQLUUIDHANDLER = false; - + public static boolean AUTO_PURGE = false; /** - * + * */ public static boolean UPDATE_NOTIFICATIONS = true; @@ -26,7 +26,7 @@ public class Settings { public static boolean PERMISSION_CACHING = true; public static boolean CACHE_RATINGS = true; public static boolean UUID_FROM_DISK = false; - + /** * Web */ @@ -82,6 +82,10 @@ public class Settings { * Teleport to path on login */ public static boolean TELEPORT_ON_LOGIN = false; + /** + * Teleport to path on death + */ + public static boolean TELEPORT_ON_DEATH = false; /** * Display titles */ @@ -156,7 +160,7 @@ public class Settings { * Use global plot limit? */ public static boolean GLOBAL_LIMIT = false; - + /** * Database settings * diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index bbb7292e5..1b904dd14 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.PS; 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.util.SetQueue.ChunkWrapper; @@ -11,7 +12,9 @@ import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Set; public abstract class ChunkManager { @@ -226,7 +229,19 @@ public abstract class ChunkManager { return chunks; } - public abstract void regenerateChunk(String world, ChunkLoc loc); + public void regenerateChunk(String world, ChunkLoc loc) { + SetQueue.IMP.regenerateChunk(world, loc); + SetQueue.IMP.queue.sendChunk(world, Collections.singletonList(loc)); + for (Map.Entry entry : UUIDHandler.getPlayers().entrySet()) { + PlotPlayer pp = entry.getValue(); + Location pLoc = pp.getLocation(); + if (!StringMan.isEqual(world, pLoc.getWorld()) || !pLoc.getChunkLoc().equals(loc)) { + continue; + } + pLoc.setY(WorldUtil.IMP.getHighestBlock(world, pLoc.getX(), pLoc.getZ())); + pp.teleport(pLoc); + } + } public void deleteRegionFiles(String world, Collection chunks) { deleteRegionFiles(world, chunks, null); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 76d4c213c..c7adcbfb5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.Rating; import com.plotsquared.listener.PlayerBlockEventType; - import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; @@ -78,6 +77,19 @@ public abstract class EventUtil { } } + public void doDeathTask(final PlotPlayer pp) { + final Plot plot = pp.getCurrentPlot(); + if (Settings.TELEPORT_ON_DEATH && plot != null) { + TaskManager.runTask(new Runnable() { + @Override + public void run() { + plot.teleportPlayer(pp); + } + }); + MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); + } + } + public boolean checkPlayerBlockEvent(PlotPlayer pp, PlayerBlockEventType type, Location loc, LazyBlock block, boolean notifyPerms) { PlotArea area = PS.get().getPlotAreaAbs(loc); Plot plot; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java b/Core/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java index 29d4d5bf6..940a9c42c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java @@ -26,5 +26,7 @@ public interface PlotQueue { PlotChunk next(ChunkWrapper wrap, boolean fixLighting); void clear(); + + void regenerateChunk(String world, ChunkLoc loc); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java index e9c1f04c3..5c2b6619e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java @@ -1,7 +1,7 @@ package com.intellectualcrafters.plot.util; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotBlock; - import java.util.ArrayDeque; import java.util.concurrent.atomic.AtomicInteger; @@ -149,6 +149,10 @@ public class SetQueue { return this.queue.setBlock(world, x, y, z, (short) id, (byte) 0); } + public void regenerateChunk(String world, ChunkLoc loc) { + queue.regenerateChunk(world, loc); + } + public class ChunkWrapper { public final int x; diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index f55c9ba76..312910917 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -1,13 +1,13 @@ package com.plotsquared.sponge.util; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.TaskManager; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.ChunkProviderServer; +import java.util.Optional; +import java.util.Set; +import java.util.function.Predicate; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.entity.living.animal.Animal; @@ -15,10 +15,6 @@ import org.spongepowered.api.entity.living.monster.Monster; import org.spongepowered.api.world.Chunk; import org.spongepowered.api.world.World; -import java.util.Optional; -import java.util.Set; -import java.util.function.Predicate; - public class SpongeChunkManager extends ChunkManager { @Override @@ -68,55 +64,6 @@ public class SpongeChunkManager extends ChunkManager { return super.getChunkChunks(world); } - @Override - public void regenerateChunk(String world, ChunkLoc loc) { - World spongeWorld = SpongeUtil.getWorld(world); - net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld; - Optional chunkOpt = spongeWorld.getChunk(loc.x, 0, loc.z); - if (chunkOpt.isPresent()) { - try { - Chunk spongeChunk = chunkOpt.get(); - IChunkProvider provider = nmsWorld.getChunkProvider(); - if (!(provider instanceof ChunkProviderServer)) { - PS.debug("Not valid world generator for: " + world); - return; - } -/* ChunkProviderServer chunkServer = (ChunkProviderServer) provider; - IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; - - long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z); - net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk; - if (chunkServer.chunkExists(loc.x, loc.z)) { - mcChunk = chunkServer.loadChunk(loc.x, loc.z); - mcChunk.onChunkUnload(); - } - Field fieldDroppedChunksSet; - try { - fieldDroppedChunksSet = chunkServer.getClass().getField("droppedChunksSet"); - } catch (Throwable t) { - fieldDroppedChunksSet = ReflectionUtils.findField(chunkServer.getClass(), Set.class); - } - Set set = (Set) fieldDroppedChunksSet.get(chunkServer); - set.remove(pos); - ReflectionUtils.findField(chunkServer.getClass(),) - chunkServer.id2ChunkMap.remove(pos); - mcChunk = chunkProvider.provideChunk(loc.x, loc.z); - chunkServer.id2ChunkMap.add(pos, mcChunk); - chunkServer.loadedChunks.add(mcChunk); - if (mcChunk != null) { - mcChunk.onChunkLoad(); - mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z); - SetQueue.IMP.queue.sendChunk(world, Arrays.asList(loc)); - } - else { - PS.debug("CHUNK IS NULL!?"); - }*/ - } catch (Throwable e){ - e.printStackTrace(); - } - } - } - @Override public boolean copyRegion(Location pos1, Location pos2, Location newPos, Runnable whenDone) { // TODO copy a region diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 3f8b61a20..0a473f649 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -17,6 +17,13 @@ import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Optional; import net.minecraft.block.Block; import net.minecraft.world.biome.BiomeGenBase; import org.apache.commons.lang3.NotImplementedException; @@ -42,14 +49,6 @@ import org.spongepowered.api.world.biome.BiomeType; import org.spongepowered.api.world.biome.BiomeTypes; import org.spongepowered.api.world.extent.Extent; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; - public class SpongeUtil extends WorldUtil { public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared")); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java index 6e7ceda80..8581b889c 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java @@ -10,6 +10,9 @@ import com.intellectualcrafters.plot.util.PlotQueue; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.plotsquared.sponge.util.SpongeUtil; +import java.util.Optional; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderServer; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.world.Chunk; @@ -17,6 +20,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import org.spongepowered.api.world.World; public class SlowQueue implements PlotQueue { @@ -100,7 +104,56 @@ public class SlowQueue implements PlotQueue { public void clear() { this.blocks.clear(); } - + + @Override + public void regenerateChunk(String world, ChunkLoc loc) { + World spongeWorld = SpongeUtil.getWorld(world); + net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeWorld; + Optional chunkOpt = spongeWorld.getChunk(loc.x, 0, loc.z); + if (chunkOpt.isPresent()) { + try { + Chunk spongeChunk = chunkOpt.get(); + IChunkProvider provider = nmsWorld.getChunkProvider(); + if (!(provider instanceof ChunkProviderServer)) { + PS.debug("Not valid world generator for: " + world); + return; + } +/* ChunkProviderServer chunkServer = (ChunkProviderServer) provider; + IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; + + long pos = ChunkCoordIntPair.chunkXZ2Int(loc.x, loc.z); + net.minecraft.world.chunk.Chunk mcChunk = (net.minecraft.world.chunk.Chunk) spongeChunk; + if (chunkServer.chunkExists(loc.x, loc.z)) { + mcChunk = chunkServer.loadChunk(loc.x, loc.z); + mcChunk.onChunkUnload(); + } + Field fieldDroppedChunksSet; + try { + fieldDroppedChunksSet = chunkServer.getClass().getField("droppedChunksSet"); + } catch (Throwable t) { + fieldDroppedChunksSet = ReflectionUtils.findField(chunkServer.getClass(), Set.class); + } + Set set = (Set) fieldDroppedChunksSet.get(chunkServer); + set.remove(pos); + ReflectionUtils.findField(chunkServer.getClass(),) + chunkServer.id2ChunkMap.remove(pos); + mcChunk = chunkProvider.provideChunk(loc.x, loc.z); + chunkServer.id2ChunkMap.add(pos, mcChunk); + chunkServer.loadedChunks.add(mcChunk); + if (mcChunk != null) { + mcChunk.onChunkLoad(); + mcChunk.populateChunk(chunkProvider, chunkProvider, loc.x, loc.z); + SetQueue.IMP.queue.sendChunk(world, Arrays.asList(loc)); + } + else { + PS.debug("CHUNK IS NULL!?"); + }*/ + } catch (Throwable e){ + e.printStackTrace(); + } + } + } + /** * This should be overriden by any specialized queues. * @param plotChunk diff --git a/pom.xml b/pom.xml index c5a00f5eb..4d2e24e5e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ UTF-8 PlotSquared - 3.3.3 + 3.4.0-SNAPSHOT PlotSquared jar