mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-01-20 01:09:34 +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> 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> intervalFlags = Arrays.asList("feed", "heal");
|
||||||
final List<String> stringFlags = Arrays.asList("greeting", "farewell");
|
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) {
|
for (final String flag : stringFlags) {
|
||||||
FlagManager.addFlag(new AbstractFlag(flag));
|
FlagManager.addFlag(new AbstractFlag(flag));
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,9 @@ public class Merge extends SubCommand {
|
|||||||
}
|
}
|
||||||
if (multiMerge) {
|
if (multiMerge) {
|
||||||
for (final UUID uuid : multiUUID) {
|
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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||||
@ -197,6 +199,7 @@ public class Merge extends SubCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
MainUtil.sendMessage(plr, "SENT MERGE REQUEST!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world);
|
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)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public static void MobSpawn(final CreatureSpawnEvent event) {
|
public static void MobSpawn(final CreatureSpawnEvent event) {
|
||||||
if (event.getEntity() instanceof Player) {
|
Entity entity = event.getEntity();
|
||||||
|
if (entity instanceof Player) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location loc = BukkitUtil.getLocation(event.getLocation());
|
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);
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
if (plot != null && plot.owner != null) {
|
if (plot != null && plot.owner != null) {
|
||||||
Flag capFlag = FlagManager.getPlotFlag(plot, "mob-cap");
|
Flag entityFlag = FlagManager.getPlotFlag(plot, "entity-cap");
|
||||||
if (capFlag == null) {
|
Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
|
||||||
|
Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
|
||||||
|
if (!(entity instanceof Creature)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int cap = ((Integer) capFlag.getValue());
|
if (entityFlag == null) {
|
||||||
int mobs = ChunkManager.manager.countEntities(plot);
|
if (animalFlag == null && (entity instanceof Animals)) {
|
||||||
if (mobs >= cap) {
|
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);
|
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);
|
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);
|
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.Skull;
|
||||||
import org.bukkit.block.banner.Pattern;
|
import org.bukkit.block.banner.Pattern;
|
||||||
import org.bukkit.block.banner.PatternType;
|
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.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -867,8 +869,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int countEntities(Plot plot) {
|
public int[] countEntities(Plot plot) {
|
||||||
int count = 0;
|
int[] count = new int[3];
|
||||||
World world = BukkitUtil.getWorld(plot.world);
|
World world = BukkitUtil.getWorld(plot.world);
|
||||||
|
|
||||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||||
@ -899,18 +901,33 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
|
|
||||||
if (doWhole) {
|
if (doWhole) {
|
||||||
for (final Entity entity : entities) {
|
for (final Entity entity : entities) {
|
||||||
|
if (!(entity instanceof Creature)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
org.bukkit.Location loc = entity.getLocation();
|
org.bukkit.Location loc = entity.getLocation();
|
||||||
Chunk chunk = loc.getChunk();
|
Chunk chunk = loc.getChunk();
|
||||||
if (chunks.contains(chunk)) {
|
if (chunks.contains(chunk)) {
|
||||||
int X = chunk.getX();
|
int X = chunk.getX();
|
||||||
int Z = chunk.getX();
|
int Z = chunk.getX();
|
||||||
if (X > bx && X < tx && Z > bz && Z < tz) {
|
if (X > bx && X < tx && Z > bz && Z < tz) {
|
||||||
count++;
|
count[0]++;
|
||||||
|
if (entity instanceof Animals) {
|
||||||
|
count[1]++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count[2]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(loc));
|
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(loc));
|
||||||
if (plot.id.equals(id)) {
|
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();
|
Entity[] ents = chunk.getEntities();
|
||||||
if (X == bx || X == tx || Z == bz || Z == tz) {
|
if (X == bx || X == tx || Z == bz || Z == tz) {
|
||||||
for (final Entity entity : ents) {
|
for (final Entity entity : ents) {
|
||||||
|
if (!(entity instanceof Creature)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity));
|
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity));
|
||||||
if (plot.id.equals(id)) {
|
if (plot.id.equals(id)) {
|
||||||
count++;
|
count[0]++;
|
||||||
|
if (entity instanceof Animals) {
|
||||||
|
count[1]++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count[2]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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;
|
return count;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user