Allow horses to be forcibly spawned but prevent them from naturally occurring

This commit is contained in:
AlexTheCoder 2017-04-15 16:53:16 -04:00
parent c6bd00a811
commit 8c27c4349d

View File

@ -1,23 +1,18 @@
package mineplex.game.clans.gameplay;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.Recipe;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
public class CustomCreatures implements Listener
{
private static final EntityType[] DISABLED_CREATURES = { EntityType.WITCH, EntityType.PIG_ZOMBIE,
EntityType.HORSE, EntityType.ENDERMAN };
EntityType.ENDERMAN };
private static final EntityType[] DISABLED_NATURAL = { EntityType.HORSE };
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event)
@ -26,6 +21,10 @@ public class CustomCreatures implements Listener
{
event.setCancelled(true);
}
if (isDisabledNatural(event.getEntityType()) && event.getSpawnReason() != SpawnReason.CUSTOM)
{
event.setCancelled(true);
}
}
private boolean isDisabledCreature(EntityType entityType)
@ -40,4 +39,17 @@ public class CustomCreatures implements Listener
return false;
}
private boolean isDisabledNatural(EntityType entityType)
{
for (EntityType disabledCreature : DISABLED_NATURAL)
{
if (disabledCreature == entityType)
{
return true;
}
}
return false;
}
}