Last active
February 11, 2018 20:02
-
-
Save Densyakun/9fc3916d8dccf5d51a60274b05954cf4 to your computer and use it in GitHub Desktop.
[BukkitPlugin]電鯖で発生した鶏大量発生事件で活躍した鶏制御プラグイン「ChickenControl3」のリニューアル版。
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
package org.densyakun.bukkit.cc3; | |
import java.util.List; | |
import org.bukkit.Chunk; | |
import org.bukkit.World; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.EntityType; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.world.ChunkLoadEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class Main extends JavaPlugin implements Runnable, Listener { | |
int chunkmaxchickenamount = 4; | |
@Override | |
public void onEnable() { | |
saveDefaultConfig(); | |
chunkmaxchickenamount = getConfig().getInt("chunkmaxchickenamount"); | |
getServer().getPluginManager().registerEvents(this, this); | |
new Thread(this).start(); | |
} | |
@Override | |
public void run() { | |
while (isEnabled()) { | |
try { | |
List<World> g = getServer().getWorlds(); | |
for (int h = 0; h < g.size(); h++) { | |
Chunk[] i = g.get(h).getLoadedChunks(); | |
for (int j = 0; j < i.length; j++) { | |
int e = 0; | |
for (int c = 0; c < i[j].getEntities().length; c++) | |
if (i[j].getEntities()[c].getType() == EntityType.CHICKEN) | |
e++; | |
int f = chunkmaxchickenamount; | |
if (e > f) { | |
Entity[] entitys = i[j].getEntities(); | |
for (int c = f; c < entitys.length; c++) | |
if (entitys[c].getType() == EntityType.CHICKEN) | |
entitys[c].remove(); | |
} | |
} | |
} | |
Thread.sleep(10000); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
@EventHandler | |
public void b(ChunkLoadEvent a) { | |
int e = 0; | |
for (int c = 0; c < a.getChunk().getEntities().length; c++) | |
if (a.getChunk().getEntities()[c].getType() == EntityType.CHICKEN) | |
e++; | |
int f = chunkmaxchickenamount; | |
if (e > f) { | |
Entity[] entitys = a.getChunk().getEntities(); | |
for (int c = f; c < entitys.length; c++) | |
if (entitys[c].getType() == EntityType.CHICKEN) | |
entitys[c].remove(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment