Created
April 12, 2015 02:21
-
-
Save PaulBGD/af05e99be6ba0fd1d2f6 to your computer and use it in GitHub Desktop.
No spawning mobs
This file contains 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
/** | |
* @author PaulBGD | |
*/ | |
public class ChunkProviderServerHook extends ChunkProviderServer { | |
@Setter | |
private static int distance = FactionConfiguration.getConfiguration().spawnProtection; | |
public ChunkProviderServerHook(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) { | |
super(worldserver, ichunkloader, ichunkprovider); | |
} | |
@Override | |
public List<BiomeBase.BiomeMeta> getMobsFor(EnumCreatureType enumcreaturetype, BlockPosition blockposition) { | |
SerializedLocation serializedLocation = FactionConfiguration.getConfiguration().spawn; | |
if (MathUtils.square(serializedLocation.x - blockposition.getX()) + MathUtils.square(serializedLocation.z - blockposition.getZ()) < MathUtils.square(distance)) { | |
return ImmutableList.of(); // empty list, as no mobs spawn here | |
} | |
return super.getMobsFor(enumcreaturetype, blockposition); | |
} | |
public static void setup(org.bukkit.World world) { | |
WorldServer handle = ((CraftWorld) world).getHandle(); | |
ChunkProviderServer chunkProviderServer = handle.chunkProviderServer; | |
IChunkLoader iChunkLoader = null; | |
try { | |
Field chunkLoader = ChunkProviderServer.class.getDeclaredField("chunkLoader"); | |
chunkLoader.setAccessible(true); | |
iChunkLoader = (IChunkLoader) chunkLoader.get(chunkProviderServer); | |
} catch (NoSuchFieldException | IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
ChunkProviderServerHook hook = new ChunkProviderServerHook(handle, iChunkLoader, chunkProviderServer.chunkProvider); | |
// transfer fields | |
hook.unloadQueue = chunkProviderServer.unloadQueue; | |
hook.chunks = chunkProviderServer.chunks; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment