Created
April 27, 2012 15:32
-
-
Save dunkfordyce/2510192 to your computer and use it in GitHub Desktop.
AikarMobFix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.empireminecraft.AikarMobFix; | |
import java.util.logging.Logger; | |
import org.bukkit.Chunk; | |
import org.bukkit.World; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.Monster; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.entity.CreatureSpawnEvent; | |
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class AikarMobFix extends JavaPlugin implements Listener { | |
Logger log; | |
public void onEnable() { | |
log = this.getLogger(); | |
getServer().getPluginManager().registerEvents(this, this); | |
} | |
private int countMobsInChunk(Chunk chunk) { | |
int count = 0; | |
for( Entity entity : chunk.getEntities()) { | |
if( entity instanceof Monster ) { | |
count ++; | |
} | |
} | |
return count; | |
} | |
@SuppressWarnings("unused") | |
@EventHandler | |
private void entitySpawn(CreatureSpawnEvent event) { | |
if( event.getSpawnReason() == SpawnReason.SPAWNER | |
|| (getConfig().getBoolean("limitNatural") && event.getSpawnReason() == SpawnReason.NATURAL) | |
) { | |
Chunk chunk = event.getLocation().getChunk(); | |
int mobCount = countMobsInChunk(chunk); | |
if( getConfig().getBoolean("countSurrounding") ) { | |
World world = chunk.getWorld(); | |
mobCount += countMobsInChunk(world.getChunkAt(chunk.getX()+1, chunk.getZ())); | |
mobCount += countMobsInChunk(world.getChunkAt(chunk.getX()-1, chunk.getZ())); | |
mobCount += countMobsInChunk(world.getChunkAt(chunk.getX(), chunk.getZ()+1)); | |
mobCount += countMobsInChunk(world.getChunkAt(chunk.getX(), chunk.getZ()-1)); | |
} | |
if( mobCount > getConfig().getInt("cap.chunk") ) { | |
event.setCancelled(true); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment