mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-01-19 16:59:36 +01:00
Added animal-cap, hostile-cap, mob-cap
This commit is contained in:
parent
294c11a534
commit
e2f372927d
@ -676,7 +676,7 @@ public class PlotSquared {
|
||||
final List<String> booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit");
|
||||
final List<String> intervalFlags = Arrays.asList("feed", "heal");
|
||||
final List<String> stringFlags = Arrays.asList("greeting", "farewell");
|
||||
final List<String> intFlags = Arrays.asList("mob-cap");
|
||||
final List<String> intFlags = Arrays.asList("entity-cap", "animal-cap", "hostile-cap");
|
||||
for (final String flag : stringFlags) {
|
||||
FlagManager.addFlag(new AbstractFlag(flag));
|
||||
}
|
||||
|
@ -159,7 +159,9 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
if (multiMerge) {
|
||||
for (final UUID uuid : multiUUID) {
|
||||
CmdConfirm.addPending(UUIDHandler.getPlayer(uuid), "merge request", new Runnable() {
|
||||
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||
MainUtil.sendMessage(accepter, "ADDING REQUEST FOR: " + accepter.getName());
|
||||
CmdConfirm.addPending(accepter, "merge request", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||
@ -197,6 +199,7 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
});
|
||||
}
|
||||
MainUtil.sendMessage(plr, "SENT MERGE REQUEST!");
|
||||
return true;
|
||||
}
|
||||
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world);
|
||||
|
@ -682,7 +682,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void MobSpawn(final CreatureSpawnEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
return;
|
||||
}
|
||||
final Location loc = BukkitUtil.getLocation(event.getLocation());
|
||||
@ -707,14 +708,46 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
}
|
||||
Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot != null && plot.owner != null) {
|
||||
Flag capFlag = FlagManager.getPlotFlag(plot, "mob-cap");
|
||||
if (capFlag == null) {
|
||||
Flag entityFlag = FlagManager.getPlotFlag(plot, "entity-cap");
|
||||
Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
|
||||
Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
|
||||
if (!(entity instanceof Creature)) {
|
||||
return;
|
||||
}
|
||||
int cap = ((Integer) capFlag.getValue());
|
||||
int mobs = ChunkManager.manager.countEntities(plot);
|
||||
if (mobs >= cap) {
|
||||
event.setCancelled(true);
|
||||
if (entityFlag == null) {
|
||||
if (animalFlag == null && (entity instanceof Animals)) {
|
||||
return;
|
||||
}
|
||||
if (monsterFlag == null && (entity instanceof Monster)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int[] mobs = ChunkManager.manager.countEntities(plot);
|
||||
if (entity instanceof Creature) {
|
||||
if (entityFlag != null) {
|
||||
int cap = ((Integer) entityFlag.getValue());
|
||||
if (mobs[0] >= cap) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entity instanceof Animals) {
|
||||
if (animalFlag != null) {
|
||||
int cap = ((Integer) animalFlag.getValue());
|
||||
if (mobs[1] >= cap) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (entity instanceof Monster) {
|
||||
if (monsterFlag != null) {
|
||||
int cap = ((Integer) monsterFlag.getValue());
|
||||
if (mobs[2] >= cap) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public abstract class ChunkManager {
|
||||
return new ChunkLoc(x, z);
|
||||
}
|
||||
|
||||
public abstract int countEntities(Plot plot);
|
||||
public abstract int[] countEntities(Plot plot);
|
||||
|
||||
public abstract boolean loadChunk(String world, ChunkLoc loc);
|
||||
|
||||
|
@ -34,6 +34,8 @@ import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -867,8 +869,8 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countEntities(Plot plot) {
|
||||
int count = 0;
|
||||
public int[] countEntities(Plot plot) {
|
||||
int[] count = new int[3];
|
||||
World world = BukkitUtil.getWorld(plot.world);
|
||||
|
||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
@ -899,18 +901,33 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
|
||||
if (doWhole) {
|
||||
for (final Entity entity : entities) {
|
||||
if (!(entity instanceof Creature)) {
|
||||
continue;
|
||||
}
|
||||
org.bukkit.Location loc = entity.getLocation();
|
||||
Chunk chunk = loc.getChunk();
|
||||
if (chunks.contains(chunk)) {
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getX();
|
||||
if (X > bx && X < tx && Z > bz && Z < tz) {
|
||||
count++;
|
||||
count[0]++;
|
||||
if (entity instanceof Animals) {
|
||||
count[1]++;
|
||||
}
|
||||
else {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(loc));
|
||||
if (plot.id.equals(id)) {
|
||||
count++;
|
||||
count[0]++;
|
||||
if (entity instanceof Animals) {
|
||||
count[1]++;
|
||||
}
|
||||
else {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -923,17 +940,36 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
Entity[] ents = chunk.getEntities();
|
||||
if (X == bx || X == tx || Z == bz || Z == tz) {
|
||||
for (final Entity entity : ents) {
|
||||
if (!(entity instanceof Creature)) {
|
||||
continue;
|
||||
}
|
||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity));
|
||||
if (plot.id.equals(id)) {
|
||||
count++;
|
||||
count[0]++;
|
||||
if (entity instanceof Animals) {
|
||||
count[1]++;
|
||||
}
|
||||
else {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
count += ents.length;
|
||||
for (final Entity entity : ents) {
|
||||
if (!(entity instanceof Creature)) {
|
||||
continue;
|
||||
}
|
||||
count[0]++;
|
||||
if (entity instanceof Animals) {
|
||||
count[1]++;
|
||||
}
|
||||
else {
|
||||
count[2]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user