mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
Added mob spawn control Flags and global settings
This commit is contained in:
parent
23aa6dc743
commit
38077275bc
@ -52,6 +52,7 @@ fire:
|
||||
mobs:
|
||||
block-creeper-explosions: off
|
||||
block-creeper-block-damage: off
|
||||
block-creature-spawn: []
|
||||
|
||||
spawn:
|
||||
login-protection: 3
|
||||
|
@ -23,6 +23,7 @@
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -286,6 +287,51 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CreatureType creaType = (CreatureType)CreatureType.valueOf(event.getMobType().toString());
|
||||
String creaName = "";
|
||||
Boolean cancelEvent = false;
|
||||
|
||||
switch(creaType) {
|
||||
case SPIDER: if (plugin.blockCreatureSpawn.contains("spider")) { cancelEvent = true; } creaName = "spider"; break;
|
||||
case ZOMBIE: if (plugin.blockCreatureSpawn.contains("zombie")) { cancelEvent = true; } creaName = "zombie"; break;
|
||||
case CREEPER: if (plugin.blockCreatureSpawn.contains("creeper")) { cancelEvent = true; } creaName = "creeper"; break;
|
||||
case SKELETON: if (plugin.blockCreatureSpawn.contains("skeleton")) { cancelEvent = true; } creaName = "skeleton"; break;
|
||||
case SQUID: if (plugin.blockCreatureSpawn.contains("squid")) { cancelEvent = true; } creaName = "squid"; break;
|
||||
case PIG_ZOMBIE: if (plugin.blockCreatureSpawn.contains("pigzombie")) { cancelEvent = true; } creaName = "pigzombie"; break;
|
||||
case GHAST: if (plugin.blockCreatureSpawn.contains("ghast")) { cancelEvent = true; } creaName = "ghast"; break;
|
||||
case SLIME: if (plugin.blockCreatureSpawn.contains("slime")) { cancelEvent = true; } creaName = "slime"; break;
|
||||
case PIG: if (plugin.blockCreatureSpawn.contains("pig")) { cancelEvent = true; } creaName = "pig"; break;
|
||||
case COW: if (plugin.blockCreatureSpawn.contains("cow")) { cancelEvent = true; } creaName = "cow"; break;
|
||||
case SHEEP: if (plugin.blockCreatureSpawn.contains("sheep")) { cancelEvent = true; } creaName = "sheep"; break;
|
||||
case CHICKEN: if (plugin.blockCreatureSpawn.contains("chicken")) { cancelEvent = true; } creaName = "chicken"; break;
|
||||
}
|
||||
|
||||
if (cancelEvent) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.useRegions && creaName != "") {
|
||||
Vector pt = toVector(event.getEntity().getLocation());
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(event.getEntity().getWorld().getName());
|
||||
|
||||
Boolean flagValue = mgr.getApplicableRegions(pt)
|
||||
.getBooleanAreaFlag("creaturespawn", creaName, true, null);
|
||||
if (flagValue != null) {
|
||||
if (!flagValue) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a position for the player to stand that is not inside a block.
|
||||
|
@ -73,7 +73,7 @@
|
||||
* @author sk89qs
|
||||
*/
|
||||
public class WorldGuardPlugin extends JavaPlugin {
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
public static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||
|
||||
private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
|
||||
private static int CMD_LIST_SIZE = 9;
|
||||
@ -123,6 +123,7 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||
|
||||
boolean blockCreeperExplosions;
|
||||
boolean blockCreeperBlockDamage;
|
||||
String blockCreatureSpawn;
|
||||
|
||||
int loginProtection;
|
||||
int spawnProtection;
|
||||
@ -208,6 +209,7 @@ private void registerEvents() {
|
||||
|
||||
registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.High);
|
||||
registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.High);
|
||||
registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.High);
|
||||
|
||||
registerEvent(Event.Type.PLAYER_ITEM, playerListener, Priority.High);
|
||||
registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.High);
|
||||
@ -304,6 +306,9 @@ public void loadConfiguration() {
|
||||
|
||||
blockCreeperExplosions = config.getBoolean("mobs.block-creeper-explosions", false);
|
||||
blockCreeperBlockDamage = config.getBoolean("mobs.block-creeper-block-damage", false);
|
||||
for (String creature: config.getStringList("mobs.block-creature-spawn", null)) {
|
||||
blockCreatureSpawn += creature.toLowerCase() + " ";
|
||||
}
|
||||
|
||||
loginProtection = config.getInt("spawn.login-protection", 3);
|
||||
spawnProtection = config.getInt("spawn.spawn-protection", 0);
|
||||
|
Loading…
Reference in New Issue
Block a user