From dffa00858de3bf1ab97cc762116fc0cf2f6e9042 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 2 Apr 2016 17:15:28 +1100 Subject: [PATCH 1/5] More than 2 lines --- .../bukkit/listeners/PlayerEvents.java | 2 +- .../bukkit/util/BukkitChunkManager.java | 16 ----- .../bukkit/util/block/FastQueue_1_8_3.java | 15 +++++ .../bukkit/util/block/FastQueue_1_9.java | 12 ++++ .../bukkit/util/block/SlowQueue.java | 6 ++ .../plot/util/ChunkManager.java | 17 +++++- .../plot/util/PlotQueue.java | 2 + .../plot/util/SetQueue.java | 6 +- .../com/plotsquared/sponge/SpongeMain.java | 4 -- .../sponge/util/SpongeChunkManager.java | 59 +------------------ .../plotsquared/sponge/util/SpongeUtil.java | 15 +++-- .../sponge/util/block/SlowQueue.java | 55 ++++++++++++++++- 12 files changed, 121 insertions(+), 88 deletions(-) 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 From 4da38a6f9c72cb999070365107f27a7fa204e737 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Mon, 4 Apr 2016 00:09:46 +0200 Subject: [PATCH 2/5] Add bypass permission to breaking blocks at y0 --- .../bukkit/listeners/PlayerEvents.java | 32 +++++++++++-------- .../intellectualcrafters/plot/config/C.java | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) 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 1557958e2..5633d333e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -28,16 +28,6 @@ import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.listener.PlayerBlockEventType; import com.plotsquared.listener.PlotListener; -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 org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -118,6 +108,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; /** * Player Events involving plots. @@ -615,11 +615,15 @@ 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); + // TODO test + 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; 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 eaaa4012d..b03fbf913 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandCaller; - import java.io.File; import java.util.EnumSet; import java.util.HashMap; @@ -59,6 +58,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"), From c69c4dd2e143b2643028ff3f89a2b27f5384ad4f Mon Sep 17 00:00:00 2001 From: manuelgu Date: Mon, 4 Apr 2016 00:11:32 +0200 Subject: [PATCH 3/5] It actually is tested --- .../main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java | 1 - 1 file changed, 1 deletion(-) 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 5633d333e..07f5d629c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -616,7 +616,6 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = area.getPlotAbs(loc); if (plot != null) { PlotPlayer pp = BukkitUtil.getPlayer(player); - // TODO test 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); From 6ab3a029b229a827658853f2f65b703265949b07 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Mon, 4 Apr 2016 11:31:15 +0200 Subject: [PATCH 4/5] Add teleport on death feature --- .../plotsquared/bukkit/listeners/PlayerEvents.java | 8 ++++++++ .../java/com/intellectualcrafters/plot/PS.java | 3 ++- .../intellectualcrafters/plot/config/Settings.java | 12 ++++++++---- .../intellectualcrafters/plot/util/EventUtil.java | 14 +++++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) 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 07f5d629c..96abea7f1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -96,6 +96,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; @@ -461,6 +462,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(); 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/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/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; From 3c5e7a15094d017f719aa7c71d91faa092512d8d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 4 Apr 2016 19:35:39 +1000 Subject: [PATCH 5/5] version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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