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 5aa5baa56..1557958e2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -726,7 +726,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 aecbaa448..0829e123f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -673,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(); 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/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index e7e562c5e..bf99024c0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -5,13 +5,16 @@ import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import java.io.File; import java.util.ArrayList; import java.util.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/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/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 500724a80..759a0ebef 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -76,10 +76,6 @@ import java.util.Collection; import java.util.List; import java.util.UUID; -/** - * Created by robin on 01/11/2014 - */ - @Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.3") public class SpongeMain implements IPlotMain { public static SpongeMain THIS; 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