mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Sponge stuff
Added entity / mob / vehicle / animal / monster caps + entity clearing on plot clear.
This commit is contained in:
parent
b40c464da9
commit
7d3de207aa
@ -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<String> 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();
|
||||
|
@ -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")) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<org.spongepowered.api.world.Location>() {
|
||||
@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
|
||||
|
@ -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<Text> offering = new SpongeListValue<Text>(Keys.SIGN_LINES, text);
|
||||
sign.offer(offering);
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<Entity>() {
|
||||
@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<Entity>() {
|
||||
@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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user