Citizens2/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java

121 lines
3.6 KiB
Java
Raw Normal View History

2012-02-03 10:20:48 +01:00
package net.citizensnpcs.npc.entity;
2012-07-28 09:02:57 +02:00
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
2012-02-04 09:13:20 +01:00
import net.citizensnpcs.npc.CitizensMobNPC;
2012-04-19 05:52:07 +02:00
import net.citizensnpcs.npc.CitizensNPC;
2012-07-19 17:10:30 +02:00
import net.citizensnpcs.npc.ai.NPCHolder;
2012-09-01 12:05:22 +02:00
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
2012-12-06 16:59:17 +01:00
import net.minecraft.server.v1_4_5.EntitySilverfish;
import net.minecraft.server.v1_4_5.World;
2012-02-03 10:20:48 +01:00
import org.bukkit.Bukkit;
2012-12-06 16:59:17 +01:00
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftSilverfish;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Silverfish;
import org.bukkit.util.Vector;
public class CitizensSilverfishNPC extends CitizensMobNPC {
2012-02-03 10:20:48 +01:00
public CitizensSilverfishNPC(int id, String name) {
super(id, name, EntitySilverfishNPC.class);
2012-02-03 10:20:48 +01:00
}
@Override
public Silverfish getBukkitEntity() {
return (Silverfish) super.getBukkitEntity();
}
2012-07-19 17:10:30 +02:00
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder {
2012-04-19 05:52:07 +02:00
private final CitizensNPC npc;
public EntitySilverfishNPC(World world) {
this(world, null);
}
public EntitySilverfishNPC(World world, NPC npc) {
super(world);
this.npc = (CitizensNPC) npc;
2012-07-19 17:10:30 +02:00
if (npc != null) {
2012-09-01 12:05:22 +02:00
NMS.clearGoals(goalSelector, targetSelector);
2012-12-06 16:59:17 +01:00
2012-07-19 17:10:30 +02:00
}
}
@Override
2012-11-16 08:47:51 +01:00
public void bl() {
super.bl();
2012-08-02 15:44:59 +02:00
if (npc != null)
npc.update();
}
@Override
2012-11-16 08:47:51 +01:00
public void bn() {
2012-08-02 15:44:59 +02:00
if (npc == null)
2012-11-16 08:47:51 +01:00
super.bn();
2012-09-01 12:05:22 +02:00
else {
NMS.updateAI(this);
2012-08-02 15:44:59 +02:00
npc.update();
2012-09-01 12:05:22 +02:00
}
2012-07-28 09:02:57 +02:00
}
@Override
2012-12-06 16:59:17 +01:00
public void collide(net.minecraft.server.v1_4_5.Entity entity) {
2012-07-28 09:02:57 +02:00
// this method is called by both the entities involved - cancelling
// it will not stop the NPC from moving.
super.collide(entity);
2012-09-07 12:25:54 +02:00
if (npc != null)
Util.callCollisionEvent(npc, entity);
}
@Override
2012-08-02 15:44:59 +02:00
public void g(double x, double y, double z) {
if (npc == null) {
super.g(x, y, z);
return;
}
2012-09-07 12:25:54 +02:00
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
super.g(x, y, z);
2012-08-02 15:44:59 +02:00
return;
2012-09-07 12:25:54 +02:00
}
2012-08-04 07:39:04 +02:00
Vector vector = new Vector(x, y, z);
NPCPushEvent event = Util.callPushEvent(npc, vector);
if (!event.isCancelled()) {
vector = event.getCollisionVector();
super.g(vector.getX(), vector.getY(), vector.getZ());
}
2012-08-02 15:44:59 +02:00
// when another entity collides, this method is called to push the
// NPC so we prevent it from doing anything if the event is
// cancelled.
}
@Override
public Entity getBukkitEntity() {
if (bukkitEntity == null && npc != null)
bukkitEntity = new SilverfishNPC(this);
return super.getBukkitEntity();
}
@Override
public NPC getNPC() {
return npc;
}
}
public static class SilverfishNPC extends CraftSilverfish implements NPCHolder {
private final CitizensNPC npc;
public SilverfishNPC(EntitySilverfishNPC entity) {
super((CraftServer) Bukkit.getServer(), entity);
this.npc = entity.npc;
}
@Override
public NPC getNPC() {
return npc;
}
}
2012-02-03 10:20:48 +01:00
}