Java Reference
In-Depth Information
import
net.canarymod.plugin.PluginListener;
import
net.canarymod.hook.world.ChunkLoadedHook;
import
net.canarymod.hook.world.ChunkCreatedHook;
import
net.canarymod.hook.world.ChunkUnloadHook;
import
net.canarymod.hook.entity.DamageHook;
import
net.canarymod.api.DamageType;
import
net.canarymod.api.world.Chunk;
import
com.pragprog.ahmine.ez.EZPlugin;
public class
CreeperCow
extends
EZPlugin
implements
PluginListener {
private static HashMap
<Cow, CreeperCowTimer> allCows =
new HashMap
<Cow, CreeperCowTimer>();
private static boolean
enabled = false;
private final static int
CHUNK_SIZE = 16;
@Override
public boolean
enable() {
Canary.hooks().registerListener(this, this);
return
super.enable();
// Call parent class's version too.
}
public void
spawnCows(Location target,
int
size,
int
count) {
World world = target.getWorld();
double
x = target.getX();
double
z = target.getZ();
for
(
int
i=0; i< count; i++) {
Location loc =
new
Location(world,
x + (
Math
.random() * size),
0,
z + (
Math
.random() * size),
0,0
);
loc.setY(world.getHighestBlockAt((
int
)loc.getX(), (
int
)loc.getZ()) + 2);
logger.info(
"[CreeperCow] spawned cow at "
+ printLoc(loc));
Cow cow = (Cow)spawnEntityLiving(loc, EntityType.COW);
CreeperCowTimer task =
new
CreeperCowTimer(this, cow);
Canary.getServer().addSynchronousTask(task);
allCows.put(cow, task);
}
}
public void
cowDied(Cow cow) {
logger.info(
"[CreeperCow] cow died."
);
allCows.remove(cow);
}
@Command(aliases = {
"creepercows"
},