diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 5a4f7b526..871f0d9dd 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -92,7 +92,14 @@ public class DebugExec extends SubCommand { File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js"); if (file.exists()) { init(); - onCommand(ConsolePlayer.getConsole(), new String[] {"run", "start.js"}); + try { + String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8), System.getProperty("line.separator")); + scope.put("THIS", this); + scope.put("PlotPlayer", ConsolePlayer.getConsole()); + engine.eval(script, scope); + } catch (Exception e) { + e.printStackTrace(); + } } } @@ -148,7 +155,7 @@ public class DebugExec extends SubCommand { } @Override - public boolean onCommand(final PlotPlayer player, String[] args) { + public boolean onCommand(final PlotPlayer player, String... args) { final List allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check"); if (args.length > 0) { final String arg = args[0].toLowerCase(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/list.java b/src/main/java/com/intellectualcrafters/plot/commands/list.java index 3a96124bd..c33b46cac 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -86,7 +86,7 @@ public class list extends SubCommand { if (Permissions.hasPermission(player, "plots.list.top")) { args.add("top"); } - if (Permissions.hasPermission(player, "plots.list..all")) { + if (Permissions.hasPermission(player, "plots.list.all")) { args.add("all"); } if (Permissions.hasPermission(player, "plots.list.unowned")) { diff --git a/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index 2b0051fd4..afe37354a 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -39,7 +39,7 @@ public enum Permissions { if ((player == null) || player.hasPermission(ADMIN.s) || player.hasPermission(STAR.s)) { return true; } - if (Permissions.hasPermission(player, perm)) { + if (player.hasPermission(perm)) { return true; } final String[] nodes = perm.split("\\."); @@ -67,11 +67,11 @@ public enum Permissions { if ((player == null) || player.hasPermission(ADMIN.s) || player.hasPermission(STAR.s)) { return Integer.MAX_VALUE; } - if (Permissions.hasPermission(player, stub + ".*")) { + if (player.hasPermission(stub + ".*")) { return Integer.MAX_VALUE; } for (int i = range; i > 0; i--) { - if (Permissions.hasPermission(player, stub + "." + i)) { + if (player.hasPermission(stub + "." + i)) { return i; } } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 03f68f4d8..69a2e006b 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -685,7 +685,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (Permissions.hasPermission(pp, PERMISSION_ADMIN_DESTROY_ROAD)) { return; } - if (MainUtil.isPlotArea(loc)) { + if (MainUtil.isPlotAreaAbs(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, PERMISSION_ADMIN_DESTROY_ROAD); event.setCancelled(true); } @@ -1268,6 +1268,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen int[] mobs = null; if (entityFlag != null) { int cap = ((Integer) entityFlag.getValue()); + if (cap == 0) { + return true; + } mobs = ChunkManager.manager.countEntities(plot); if (mobs[0] >= cap) { return true; @@ -1277,6 +1280,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen Flag mobFlag = FlagManager.getPlotFlag(plot, "mob-cap"); if (mobFlag != null) { int cap = ((Integer) mobFlag.getValue()); + if (cap == 0) { + return true; + } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[3] >= cap) { return true; @@ -1286,6 +1292,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap"); if (animalFlag != null) { int cap = ((Integer) animalFlag.getValue()); + if (cap == 0) { + return true; + } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[1] >= cap) { return true; @@ -1296,6 +1305,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap"); if (monsterFlag != null) { int cap = ((Integer) monsterFlag.getValue()); + if (cap == 0) { + return true; + } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[2] >= cap) { return true; @@ -1307,6 +1319,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap"); if (vehicleFlag != null) { int cap = ((Integer) vehicleFlag.getValue()); + if (cap == 0) { + return true; + } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[4] >= cap) { return true; diff --git a/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 78182fe9a..a042b744b 100644 --- a/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -21,11 +21,18 @@ import java.util.UUID; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.entity.living.Ambient; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.entity.living.animal.Animal; +import org.spongepowered.api.entity.living.monster.Monster; import org.spongepowered.api.entity.player.Player; +import org.spongepowered.api.entity.vehicle.Boat; +import org.spongepowered.api.entity.vehicle.minecart.Minecart; import org.spongepowered.api.event.Subscribe; import org.spongepowered.api.event.block.BlockMoveEvent; import org.spongepowered.api.event.block.BlockRedstoneUpdateEvent; import org.spongepowered.api.event.block.FloraGrowEvent; +import org.spongepowered.api.event.block.FluidSpreadEvent; import org.spongepowered.api.event.entity.EntityChangeBlockEvent; import org.spongepowered.api.event.entity.EntitySpawnEvent; import org.spongepowered.api.event.entity.EntityTeleportEvent; @@ -66,6 +73,7 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.MainUtil; @@ -90,19 +98,41 @@ public class MainListener { * - BlockFromToEvent * - BlockDamageEvent * - Structure (tree etc) - * - Per plot mob caps * - PlayerIgniteBlockEvent * - PlayerBucketEmptyEvent * - PlayerBucketFillEvent * - VehicleCreateEvent * - HangingPlaceEvent * - HangingBreakEvent + * - Liquid flow * - PVP * - PVE * - VehicleDestroy * - Projectile */ + @Subscribe + public void onFluidSpread(FluidSpreadEvent event) { + // TODO This event isn't called + Location loc = SpongeUtil.getLocation(event.getLocation()); + final Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(loc)) { + event.setCancelled(true); + } + return; + } + event.filterLocations(new Predicate() { + @Override + public boolean apply(org.spongepowered.api.world.Location loc) { + if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) { + return false; + } + return true; + } + }); + } + @Subscribe public void onMobSpawn(EntitySpawnEvent event) { Entity entity = event.getEntity(); @@ -133,10 +163,86 @@ public class MainListener { } return; } - - if (!plotworld.MOB_SPAWNING) { - event.setCancelled(true); + int[] mobs = null; + if (entity instanceof Living) { + if (!plotworld.MOB_SPAWNING) { + event.setCancelled(true); + return; + } + Flag mobCap = FlagManager.getPlotFlag(plot, "mob-cap"); + if (mobCap != null) { + Integer cap = (Integer) mobCap.getValue(); + if (cap == 0) { + event.setCancelled(true); + return; + } + if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); + if (mobs[3] >= cap) { + event.setCancelled(true); + return; + } + } + if (entity instanceof Ambient || entity instanceof Animal) { + Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap"); + if (animalFlag != null) { + int cap = ((Integer) animalFlag.getValue()); + if (cap == 0) { + event.setCancelled(true); + return; + } + if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); + if (mobs[1] >= cap) { + event.setCancelled(true); + return; + } + } + } + if (entity instanceof Monster) { + Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap"); + if (monsterFlag != null) { + int cap = ((Integer) monsterFlag.getValue()); + if (cap == 0) { + event.setCancelled(true); + return; + } + if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); + if (mobs[2] >= cap) { + event.setCancelled(true); + return; + } + } + } + return; } + if (entity instanceof Minecart || entity instanceof Boat) { + Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap"); + if (vehicleFlag != null) { + int cap = ((Integer) vehicleFlag.getValue()); + if (cap == 0) { + event.setCancelled(true); + return; + } + if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); + if (mobs[4] >= cap) { + event.setCancelled(true); + return; + } + } + } + Flag entityCap = FlagManager.getPlotFlag(plot, "entity-cap"); + if (entityCap != null) { + Integer cap = (Integer) entityCap.getValue(); + if (cap == 0) { + event.setCancelled(true); + return; + } + if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); + if (mobs[0] >= cap) { + event.setCancelled(true); + return; + } + } + } @Subscribe diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java index bfdfe4c87..9513d2f9c 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java @@ -10,10 +10,13 @@ import org.spongepowered.api.block.tileentity.Sign; import org.spongepowered.api.block.tileentity.TileEntity; import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.data.manipulator.mutable.tileentity.SignData; +import org.spongepowered.api.data.value.immutable.ImmutableListValue; +import org.spongepowered.api.data.value.mutable.ListValue; import org.spongepowered.api.text.Text; import org.spongepowered.api.world.World; import org.spongepowered.api.world.biome.BiomeType; import org.spongepowered.api.world.biome.BiomeTypes; +import org.spongepowered.common.data.value.mutable.SpongeListValue; import com.google.common.base.Optional; import com.intellectualcrafters.plot.object.Location; @@ -191,7 +194,13 @@ public class SpongeBlockManager extends BlockManager { for (int i = 0; i < 4; i++) { text.add(SpongeMain.THIS.getText(lines[i])); } - sign.offer(Keys.SIGN_LINES, text); + try { + SpongeListValue offering = new SpongeListValue(Keys.SIGN_LINES, text); + sign.offer(offering); + } + catch (NullPointerException e) { + e.printStackTrace(); + } } @Override diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index 3fc78acc5..47f42e9c0 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -4,11 +4,16 @@ import java.util.ArrayList; import java.util.List; import org.spongepowered.api.data.DataContainer; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.entity.living.animal.Animal; +import org.spongepowered.api.entity.living.monster.Monster; import org.spongepowered.api.world.Chunk; import org.spongepowered.api.world.World; import org.spongepowered.api.world.storage.ChunkDataStream; import com.google.common.base.Optional; +import com.google.common.base.Predicate; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -28,8 +33,42 @@ public class SpongeChunkManager extends ChunkManager { @Override public int[] countEntities(Plot plot) { - // TODO Auto-generated method stub - return new int[5]; + Location pos1 = plot.getBottom().add(1, 0, 1); + Location pos2 = plot.getTop(); + + String worldname = pos1.getWorld(); + World world = SpongeUtil.getWorld(worldname); + final int bx = pos1.getX(); + final int bz = pos1.getZ(); + final int tx = pos2.getX(); + final int tz = pos2.getZ(); + final int[] count = new int[5]; + world.getEntities(new Predicate() { + @Override + public boolean apply(Entity entity) { + org.spongepowered.api.world.Location loc = entity.getLocation(); + int x = loc.getBlockX(); + if (x >= bx && x <= tx) { + int z = loc.getBlockZ(); + if (z >= bz && z <= tz) { + count[0]++; + if (entity instanceof Living) { + count[3]++; + if (entity instanceof Animal) { + count[1]++; + } else if (entity instanceof Monster){ + count[2]++; + } + } else { + count[4]++; + } + } + } + return false; + } + }); + + return count; } @Override @@ -116,8 +155,26 @@ public class SpongeChunkManager extends ChunkManager { @Override public void clearAllEntities(Location pos1, Location pos2) { - // TODO Auto-generated method stub - + String worldname = pos1.getWorld(); + World world = SpongeUtil.getWorld(worldname); + final int bx = pos1.getX(); + final int bz = pos1.getZ(); + final int tx = pos2.getX(); + final int tz = pos2.getZ(); + world.getEntities(new Predicate() { + @Override + public boolean apply(Entity entity) { + org.spongepowered.api.world.Location loc = entity.getLocation(); + int x = loc.getBlockX(); + if (x >= bx && x <= tx) { + int z = loc.getBlockZ(); + if (z >= bz && z <= tz) { + entity.remove(); + } + } + return false; + } + }); } } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index a505a5ec7..701101025 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -89,4 +89,17 @@ public class SpongeUtil { public static Location getLocation(String world, org.spongepowered.api.world.Location spawn) { return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()); } + + public static String getWorldName(org.spongepowered.api.world.Location origin) { + Extent extent = origin.getExtent(); + if (extent == lastWorld) { + return last; + } + if (extent instanceof World) { + lastWorld = (World) extent; + last = ((World) extent).getName(); + return last; + } + return null; + } }