Adds new Animals flag

This commit is contained in:
Mark Hughes 2015-09-08 13:06:57 +10:00 committed by Olof Larsson
parent 74b9319a1a
commit 0728f0cfd2
4 changed files with 43 additions and 13 deletions

View File

@ -87,6 +87,7 @@ import com.massivecraft.factions.spigot.SpigotFeatures;
import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.PriorityLines;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.money.Money;
@ -117,6 +118,19 @@ public class EngineMain extends EngineAbstract
return Factions.get();
}
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public static final Set<SpawnReason> NATURAL_SPAWN_REASONS = new MassiveSet<SpawnReason>(
SpawnReason.NATURAL,
SpawnReason.JOCKEY,
SpawnReason.CHUNK_GEN,
SpawnReason.OCELOT_BABY,
SpawnReason.NETHER_PORTAL,
SpawnReason.MOUNT
);
// -------------------------------------------- //
// FACTION SHOW
// -------------------------------------------- //
@ -1117,23 +1131,16 @@ public class EngineMain extends EngineAbstract
}
// -------------------------------------------- //
// FLAG: MONSTERS
// FLAG: MONSTERS & ANIMALS
// -------------------------------------------- //
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockMonsters(CreatureSpawnEvent event)
public void blockMonstersAndAnimals(CreatureSpawnEvent event)
{
// If a creature is spawning ...
EntityType type = event.getEntityType();
// First check that it's a natural spawn ..
if ( ! NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) return;
// ... and that creature is a monster ...
if ( ! MConf.get().entityTypesMonsters.contains(type)) return;
// ... and the reason for the spawn is natural ...
SpawnReason reason = event.getSpawnReason();
if (reason != SpawnReason.NATURAL && reason != SpawnReason.JOCKEY && reason != SpawnReason.NETHER_PORTAL) return;
// ... and monsters are forbidden at the location ...
// .. and if they can spawn here ..
Location location = event.getLocation();
if (location == null) return;
@ -1142,7 +1149,10 @@ public class EngineMain extends EngineAbstract
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction == null) return;
if (faction.getFlag(MFlag.getFlagMonsters())) return;
EntityType type = event.getEntityType();
if ((faction.getFlag(MFlag.getFlagMonsters()) && MConf.get().entityTypesMonsters.contains(type)) &&
(faction.getFlag(MFlag.getFlagAnimals()) && MConf.get().entityTypesAnimals.contains(type))) return;
// ... block the spawn.
event.setCancelled(true);

View File

@ -108,6 +108,7 @@ public class FactionColl extends Coll<Faction>
faction.setFlag(MFlag.getFlagPvp(), true);
faction.setFlag(MFlag.getFlagFriendlyire(), false);
faction.setFlag(MFlag.getFlagMonsters(), true);
faction.setFlag(MFlag.getFlagAnimals(), true);
faction.setFlag(MFlag.getFlagExplosions(), true);
faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
faction.setFlag(MFlag.getFlagFirespread(), true);
@ -142,6 +143,7 @@ public class FactionColl extends Coll<Faction>
faction.setFlag(MFlag.getFlagPvp(), false);
faction.setFlag(MFlag.getFlagFriendlyire(), false);
faction.setFlag(MFlag.getFlagMonsters(), false);
faction.setFlag(MFlag.getFlagAnimals(), true);
faction.setFlag(MFlag.getFlagExplosions(), false);
faction.setFlag(MFlag.getFlagOfflineexplosions(), false);
faction.setFlag(MFlag.getFlagFirespread(), false);
@ -175,6 +177,7 @@ public class FactionColl extends Coll<Faction>
faction.setFlag(MFlag.getFlagPvp(), true);
faction.setFlag(MFlag.getFlagFriendlyire(), true);
faction.setFlag(MFlag.getFlagMonsters(), true);
faction.setFlag(MFlag.getFlagAnimals(), true);
faction.setFlag(MFlag.getFlagExplosions(), true);
faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
faction.setFlag(MFlag.getFlagFirespread(), true);

View File

@ -596,6 +596,19 @@ public class MConf extends Entity<MConf>
"ZOMBIE" // Minecraft 1.?
);
// List of entities considered to be animals.
public BackstringEnumSet<EntityType> entityTypesAnimals = new BackstringEnumSet<EntityType>(EntityType.class,
"CHICKEN", // Minecraft 1.?
"COW", // Minecraft 1.?
"HORSE", // Minecraft 1.?
"MUSHROOM_COW", // Minecraft 1.?
"OCELOT", // Minecraft 1.?
"PIG", // Minecraft 1.?
"RABBIT", // Minecraft 1.?
"SHEEP", // Minecraft 1.?
"SQUID" // Minecraft 1.?
);
// -------------------------------------------- //
// INTEGRATION: HeroChat
// -------------------------------------------- //

View File

@ -19,6 +19,7 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
public final static transient String ID_OPEN = "open";
public final static transient String ID_MONSTERS = "monsters";
public final static transient String ID_ANIMALS = "animals";
public final static transient String ID_POWERLOSS = "powerloss";
public final static transient String ID_PVP = "pvp";
public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
@ -32,6 +33,7 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
public final static transient int PRIORITY_OPEN = 1000;
public final static transient int PRIORITY_MONSTERS = 2000;
public final static transient int PRIORITY_ANIMALS = 2500;
public final static transient int PRIORITY_POWERLOSS = 3000;
public final static transient int PRIORITY_PVP = 4000;
public final static transient int PRIORITY_FRIENDLYFIRE = 5000;
@ -68,6 +70,7 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
{
getFlagOpen();
getFlagMonsters();
getFlagAnimals();
getFlagPowerloss();
getFlagPvp();
getFlagFriendlyire();
@ -82,6 +85,7 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); }
public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); }
public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); }
public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); }
public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); }
public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); }