Added mob cap flag

This commit is contained in:
boy0001 2015-03-20 23:04:48 +11:00
parent 8a63b8937f
commit 91b7b41cfc
2 changed files with 17 additions and 0 deletions

View File

@ -676,6 +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");
for (final String flag : stringFlags) { for (final String flag : stringFlags) {
FlagManager.addFlag(new AbstractFlag(flag)); FlagManager.addFlag(new AbstractFlag(flag));
} }
@ -685,6 +686,9 @@ public class PlotSquared {
for (final String flag : booleanFlags) { for (final String flag : booleanFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.BooleanValue()));
} }
for (final String flag : intFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
}
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue()));

View File

@ -90,6 +90,7 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
@ -704,6 +705,18 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
Plot plot = MainUtil.getPlot(loc);
if (plot != null && plot.owner != null) {
Flag capFlag = FlagManager.getPlotFlag(plot, "mob-cap");
if (capFlag == null) {
return;
}
int cap = ((Integer) capFlag.getValue());
int mobs = ChunkManager.manager.countEntities(plot);
if (mobs >= cap) {
event.setCancelled(true);
}
}
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)