Update for 1.3

This commit is contained in:
fullwall 2012-08-02 21:44:59 +08:00
parent 3c3c6cc5f1
commit b9b6004e65
41 changed files with 648 additions and 790 deletions

View File

@ -11,7 +11,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<craftbukkit.version>1.2.5-R4.1-SNAPSHOT</craftbukkit.version> <craftbukkit.version>1.3.1-R0.1-SNAPSHOT</craftbukkit.version>
<citizensapi.version>2.0-SNAPSHOT</citizensapi.version> <citizensapi.version>2.0-SNAPSHOT</citizensapi.version>
<build.number>Unknown</build.number> <build.number>Unknown</build.number>
</properties> </properties>

View File

@ -367,5 +367,5 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
Thread.currentThread().setContextClassLoader(contextClassLoader); Thread.currentThread().setContextClassLoader(contextClassLoader);
} }
private static final String COMPATIBLE_MC_VERSION = "1.2.5"; private static final String COMPATIBLE_MC_VERSION = "1.3.1";
} }

View File

@ -201,7 +201,7 @@ public class NPCCommands {
if (npc == null || args.argsLength() == 2) { if (npc == null || args.argsLength() == 2) {
if (args.argsLength() < 2) if (args.argsLength() < 2)
throw new CommandException("No NPC selected."); throw new CommandException("No NPC selected.");
npc = CitizensAPI.getNPCRegistry().getById(args.getInteger(2)); npc = CitizensAPI.getNPCRegistry().getById(args.getInteger(1));
if (npc == null) if (npc == null)
throw new CommandException("No NPC found with that ID."); throw new CommandException("No NPC found with that ID.");
} }

View File

@ -18,22 +18,20 @@ import org.bukkit.command.CommandSender;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
public class ScriptCommands { public class ScriptCommands {
private final Citizens plugin;
public ScriptCommands(Citizens plugin) { public ScriptCommands(Citizens plugin) {
this.plugin = plugin;
} }
@Command( @Command(
aliases = { "script" }, aliases = { "script" },
modifiers = { "compile", "run" }, modifiers = { "compile", "run" },
usage = "compile|run [file]", usage = "compile|run [file] (--methods [methods])",
desc = "compile and run a script", desc = "compile and run a script",
min = 2, min = 2,
max = 2, max = 2,
permission = "script.compile") permission = "script.compile")
public void runScript(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException { public void runScript(final CommandContext args, final CommandSender sender, NPC npc)
File file = new File(plugin.getDataFolder(), args.getString(1)); throws CommandException {
File file = new File(CitizensAPI.getScriptFolder(), args.getString(1));
if (!file.exists()) if (!file.exists())
throw new CommandException("The file '" + args.getString(1) + "' doesn't exist!"); throw new CommandException("The file '" + args.getString(1) + "' doesn't exist!");
CitizensAPI.getScriptCompiler().compile(file).withCallback(new CompileCallback() { CitizensAPI.getScriptCompiler().compile(file).withCallback(new CompileCallback() {

View File

@ -141,7 +141,7 @@ public class CitizensNavigator implements Navigator {
private void updatePathfindingRange() { private void updatePathfindingRange() {
if (PATHFINDING_RANGE == null) if (PATHFINDING_RANGE == null)
return; return;
Navigation navigation = npc.getHandle().al(); Navigation navigation = npc.getHandle().getNavigation();
try { try {
PATHFINDING_RANGE.set(navigation, pathfindingRange); PATHFINDING_RANGE.set(navigation, pathfindingRange);
} catch (Exception ex) { } catch (Exception ex) {
@ -168,7 +168,7 @@ public class CitizensNavigator implements Navigator {
MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F); MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F);
MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F); MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F);
try { try {
SPEED_FIELD = EntityLiving.class.getDeclaredField("bb"); SPEED_FIELD = EntityLiving.class.getDeclaredField("bw");
SPEED_FIELD.setAccessible(true); SPEED_FIELD.setAccessible(true);
PATHFINDING_RANGE = Navigation.class.getDeclaredField("e"); PATHFINDING_RANGE = Navigation.class.getDeclaredField("e");
PATHFINDING_RANGE.setAccessible(true); PATHFINDING_RANGE.setAccessible(true);

View File

@ -31,7 +31,7 @@ public class MCNavigationStrategy implements PathStrategy {
// navigation won't execute, and calling entity.move doesn't // navigation won't execute, and calling entity.move doesn't
// entirely fix the problem. // entirely fix the problem.
} }
navigation = entity.al(); navigation = entity.getNavigation();
} }
@Override @Override
@ -46,6 +46,6 @@ public class MCNavigationStrategy implements PathStrategy {
@Override @Override
public boolean update() { public boolean update() {
return navigation.e(); return navigation.f();
} }
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.entity.LivingEntity;
public class MCTargetStrategy implements PathStrategy, EntityTarget { public class MCTargetStrategy implements PathStrategy, EntityTarget {
private final boolean aggro; private final boolean aggro;
private int attackTicks;
private final EntityLiving handle, target; private final EntityLiving handle, target;
private final float speed; private final float speed;
@ -26,9 +27,9 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
} }
private boolean canAttack() { private boolean canAttack() {
return handle.attackTicks == 0 return attackTicks == 0
&& (handle.boundingBox.e > target.boundingBox.b && handle.boundingBox.b < target.boundingBox.e) && (handle.boundingBox.e > target.boundingBox.b && handle.boundingBox.b < target.boundingBox.e)
&& distanceSquared() <= ATTACK_DISTANCE && handle.h(target); && distanceSquared() <= ATTACK_DISTANCE && handle.l(target);
} }
private double distanceSquared() { private double distanceSquared() {
@ -60,10 +61,10 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
if (target == null || target.dead) if (target == null || target.dead)
return true; return true;
new MCNavigationStrategy(handle, target, speed).update(); new MCNavigationStrategy(handle, target, speed).update();
handle.getControllerLook().a(target, 10.0F, handle.D()); handle.getControllerLook().a(target, 10.0F, handle.bf());
if (aggro && canAttack()) { if (aggro && canAttack()) {
if (handle instanceof EntityMonster) { if (handle instanceof EntityMonster) {
((EntityMonster) handle).a((net.minecraft.server.Entity) target); ((EntityMonster) handle).k(target);
// the cast is necessary to resolve overloaded method a // the cast is necessary to resolve overloaded method a
} else if (handle instanceof EntityPlayer) { } else if (handle instanceof EntityPlayer) {
EntityPlayer humanHandle = (EntityPlayer) handle; EntityPlayer humanHandle = (EntityPlayer) handle;
@ -71,10 +72,15 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
Util.sendPacketNearby(handle.getBukkitEntity().getLocation(), new Packet18ArmAnimation( Util.sendPacketNearby(handle.getBukkitEntity().getLocation(), new Packet18ArmAnimation(
humanHandle, 1), 64); humanHandle, 1), 64);
} }
attackTicks = ATTACK_DELAY_TICKS;
} }
if (attackTicks > 0)
attackTicks--;
return false; return false;
} }
private static final int ATTACK_DELAY_TICKS = 20;
private static final double ATTACK_DISTANCE = 1.75 * 1.75; private static final double ATTACK_DISTANCE = 1.75 * 1.75;
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityBlaze; import net.minecraft.server.EntityBlaze;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Blaze; import org.bukkit.entity.Blaze;
@ -35,24 +34,16 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void be() {
if (npc == null) { if (npc != null)
super.b_(x, y, z); npc.update();
return; else
} super.be();
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,11 +55,19 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc != null) if (npc == null) {
npc.update(); super.g(x, y, z);
else return;
super.d_(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityCaveSpider; import net.minecraft.server.EntityCaveSpider;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.CaveSpider; import org.bukkit.entity.CaveSpider;
@ -31,24 +30,22 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); npc.update();
return; }
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) @Override
return; public void be() {
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); if (npc == null)
if (!event.isCancelled()) super.be();
super.b_(x, y, z); else
// when another entity collides, b_ is called to push the NPC npc.update();
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -60,22 +57,24 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc == null) if (npc == null) {
super.d_(); super.g(x, y, z);
else return;
npc.update(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
npc.update();
}
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityChicken; import net.minecraft.server.EntityChicken;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Chicken; import org.bukkit.entity.Chicken;
@ -35,24 +34,15 @@ public class CitizensChickenNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensChickenNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityCow; import net.minecraft.server.EntityCow;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Cow; import org.bukkit.entity.Cow;
@ -35,24 +34,15 @@ public class CitizensCowNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensCowNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,8 +7,7 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityCreeper; import net.minecraft.server.EntityCreeper;
import net.minecraft.server.EntityWeatherLighting; import net.minecraft.server.EntityLightning;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
@ -36,30 +35,21 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void a(EntityWeatherLighting entityweatherlighting) { public void a(EntityLightning entitylightning) {
if (npc == null) if (npc == null)
super.a(entityweatherlighting); super.a(entitylightning);
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -71,15 +61,24 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityEnderDragon; import net.minecraft.server.EntityEnderDragon;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
@ -31,24 +30,14 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void be() {
if (npc == null) { if (npc == null)
super.b_(x, y, z); super.be();
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -60,17 +49,27 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void d() {
if (npc == null)
super.d_();
}
@Override
public void e() {
if (npc != null) if (npc != null)
npc.update(); npc.update();
else else
super.e(); super.d();
}
@Override
public void g(double x, double y, double z) {
if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override

View File

@ -10,7 +10,6 @@ import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityEnderman; import net.minecraft.server.EntityEnderman;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.Material; import org.bukkit.Material;
@ -73,24 +72,24 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { if (npc == null)
super.b_(x, y, z); super.bc();
return; else
} npc.update();
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) }
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); @Override
if (!event.isCancelled()) public void be() {
super.b_(x, y, z); if (npc == null)
// when another entity collides, b_ is called to push the NPC super.be();
// so we prevent b_ from doing anything if the event is cancelled. else
npc.update();
} }
@Override @Override
@ -102,27 +101,30 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
} }
@Override @Override
public void d_() { public void d() {
if (npc == null) if (npc == null)
super.d_(); super.d();
else
npc.update();
} }
@Override @Override
public void e() { public void g(double x, double y, double z) {
if (npc == null) if (npc == null) {
super.e(); super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
}
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityGhast; import net.minecraft.server.EntityGhast;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Ghast; import org.bukkit.entity.Ghast;
@ -35,24 +34,16 @@ public class CitizensGhastNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void be() {
if (npc == null) { if (npc != null)
super.b_(x, y, z); npc.update();
return; else
} super.be();
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,11 +55,19 @@ public class CitizensGhastNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc != null) if (npc == null) {
npc.update(); super.g(x, y, z);
else return;
super.d_(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityGiantZombie; import net.minecraft.server.EntityGiantZombie;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Giant; import org.bukkit.entity.Giant;
@ -31,24 +30,16 @@ public class CitizensGiantNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void be() {
if (npc == null) { if (npc == null)
super.b_(x, y, z); super.be();
return; else
} npc.update();
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -60,8 +51,19 @@ public class CitizensGiantNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
npc.update(); if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override

View File

@ -32,11 +32,12 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
handle.X = loc.getYaw() % 360; handle.as = loc.getYaw() % 360;
// set the head yaw in another tick - if done immediately, // set the head yaw in another tick - if done immediately,
// minecraft will not update it. // minecraft will not update it.
} }
}); });
handle.getBukkitEntity().setSleepingIgnored(true);
return handle; return handle;
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityIronGolem; import net.minecraft.server.EntityIronGolem;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.IronGolem; import org.bukkit.entity.IronGolem;
@ -31,24 +30,15 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -60,15 +50,24 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityMagmaCube; import net.minecraft.server.EntityMagmaCube;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.MagmaCube; import org.bukkit.entity.MagmaCube;
@ -36,24 +35,23 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
setSize(3); setSize(3);
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
} }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return; @Override
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); public void be() {
if (!event.isCancelled()) if (npc != null)
super.b_(x, y, z); npc.update();
// when another entity collides, b_ is called to push the NPC else
// so we prevent b_ from doing anything if the event is cancelled. super.be();
} }
@Override @Override
@ -65,23 +63,24 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc != null) if (npc == null) {
npc.update(); super.g(x, y, z);
else return;
super.d_(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityMushroomCow; import net.minecraft.server.EntityMushroomCow;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.MushroomCow; import org.bukkit.entity.MushroomCow;
@ -35,24 +34,15 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityOcelot; import net.minecraft.server.EntityOcelot;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Ocelot; import org.bukkit.entity.Ocelot;
@ -35,24 +34,15 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -10,9 +10,8 @@ import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityLightning;
import net.minecraft.server.EntityPig; import net.minecraft.server.EntityPig;
import net.minecraft.server.EntityWeatherLighting;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.Material; import org.bukkit.Material;
@ -62,30 +61,21 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void a(EntityWeatherLighting entityweatherlighting) { public void a(EntityLightning entitylightning) {
if (npc == null) if (npc == null)
super.a(entityweatherlighting); super.a(entitylightning);
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -97,15 +87,24 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityPigZombie; import net.minecraft.server.EntityPigZombie;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.PigZombie; import org.bukkit.entity.PigZombie;
@ -35,24 +34,23 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
} }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return; @Override
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); public void be() {
if (!event.isCancelled()) if (npc != null)
super.b_(x, y, z); npc.update();
// when another entity collides, b_ is called to push the NPC else
// so we prevent b_ from doing anything if the event is cancelled. super.be();
} }
@Override @Override
@ -64,23 +62,24 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc != null) if (npc == null) {
npc.update(); super.g(x, y, z);
else return;
super.d_(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -12,7 +12,6 @@ import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySheep; import net.minecraft.server.EntitySheep;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
@ -73,24 +72,15 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -102,15 +92,24 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySilverfish; import net.minecraft.server.EntitySilverfish;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Silverfish; import org.bukkit.entity.Silverfish;
@ -35,24 +34,23 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
} }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return; @Override
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); public void be() {
if (!event.isCancelled()) if (npc == null)
super.b_(x, y, z); super.be();
// when another entity collides, b_ is called to push the NPC else
// so we prevent b_ from doing anything if the event is cancelled. npc.update();
} }
@Override @Override
@ -64,23 +62,24 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc == null) if (npc == null) {
super.d_(); super.g(x, y, z);
else return;
npc.update(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySkeleton; import net.minecraft.server.EntitySkeleton;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
@ -35,24 +34,15 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySlime; import net.minecraft.server.EntitySlime;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
@ -36,24 +35,23 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
setSize(3); setSize(3);
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
} }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return; @Override
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); public void be() {
if (!event.isCancelled()) if (npc == null)
super.b_(x, y, z); super.be();
// when another entity collides, b_ is called to push the NPC else
// so we prevent b_ from doing anything if the event is cancelled. npc.update();
} }
@Override @Override
@ -65,23 +63,24 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc == null) if (npc == null) {
super.d_(); super.g(x, y, z);
else return;
npc.update(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySnowman; import net.minecraft.server.EntitySnowman;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Snowman; import org.bukkit.entity.Snowman;
@ -31,24 +30,14 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); npc.update();
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -60,14 +49,24 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySpider; import net.minecraft.server.EntitySpider;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Spider; import org.bukkit.entity.Spider;
@ -34,24 +33,23 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
} }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return; @Override
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z)); public void be() {
if (!event.isCancelled()) if (npc == null)
super.b_(x, y, z); super.be();
// when another entity collides, b_ is called to push the NPC else
// so we prevent b_ from doing anything if the event is cancelled. npc.update();
} }
@Override @Override
@ -63,23 +61,24 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc == null) if (npc == null) {
super.d_(); super.g(x, y, z);
else return;
npc.update(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySquid; import net.minecraft.server.EntitySquid;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Squid; import org.bukkit.entity.Squid;
@ -35,24 +34,16 @@ public class CitizensSquidNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void be() {
if (npc == null) { if (npc != null)
super.b_(x, y, z); npc.update();
return; else
} super.be();
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,11 +55,19 @@ public class CitizensSquidNPC extends CitizensMobNPC {
} }
@Override @Override
public void d_() { public void g(double x, double y, double z) {
if (npc != null) if (npc == null) {
npc.update(); super.g(x, y, z);
else return;
super.d_(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityVillager; import net.minecraft.server.EntityVillager;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
@ -35,24 +34,15 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityWolf; import net.minecraft.server.EntityWolf;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
@ -35,24 +34,15 @@ public class CitizensWolfNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensWolfNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityZombie; import net.minecraft.server.EntityZombie;
import net.minecraft.server.PathfinderGoalSelector;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
@ -35,24 +34,15 @@ public class CitizensZombieNPC extends CitizensMobNPC {
super(world); super(world);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
goalSelector = new PathfinderGoalSelector(); Util.clearGoals(goalSelector, targetSelector);
targetSelector = new PathfinderGoalSelector();
} }
} }
@Override @Override
public void b_(double x, double y, double z) { public void bc() {
if (npc == null) { super.bc();
super.b_(x, y, z); if (npc != null)
return; npc.update();
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
} }
@Override @Override
@ -64,15 +54,24 @@ public class CitizensZombieNPC extends CitizensMobNPC {
} }
@Override @Override
public NPC getNPC() { public void g(double x, double y, double z) {
return npc; if (npc == null) {
super.g(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 @Override
public void z_() { public NPC getNPC() {
super.z_(); return npc;
if (npc != null)
npc.update();
} }
} }
} }

View File

@ -6,11 +6,12 @@ import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.network.NPCNetHandler; import net.citizensnpcs.npc.network.EmptyNetHandler;
import net.citizensnpcs.npc.network.NPCNetworkManager; import net.citizensnpcs.npc.network.EmptyNetworkManager;
import net.citizensnpcs.npc.network.NPCSocket; import net.citizensnpcs.npc.network.NPCSocket;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EnumGamemode;
import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Navigation; import net.minecraft.server.Navigation;
@ -21,46 +22,31 @@ import net.minecraft.server.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class EntityHumanNPC extends EntityPlayer implements NPCHolder { public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
private CitizensNPC npc; private final CitizensNPC npc;
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string, public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
ItemInWorldManager itemInWorldManager, NPC npc) { ItemInWorldManager itemInWorldManager, NPC npc) {
super(minecraftServer, world, string, itemInWorldManager); super(minecraftServer, world, string, itemInWorldManager);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
itemInWorldManager.setGameMode(0); itemInWorldManager.setGameMode(EnumGamemode.SURVIVAL);
NPCSocket socket = new NPCSocket(); NPCSocket socket = new NPCSocket();
NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() { NetworkManager netMgr = new EmptyNetworkManager(socket, "npc mgr", new NetHandler() {
@Override @Override
public boolean c() { public boolean a() {
return false; return false;
} }
}); }, server.E().getPrivate());
netServerHandler = new NPCNetHandler(minecraftServer, netMgr, this); netServerHandler = new EmptyNetHandler(minecraftServer, netMgr, this);
netMgr.a(netServerHandler); netMgr.a(netServerHandler);
try { try {
socket.close(); socket.close();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); // swallow
} }
} }
@Override
public void b_(double x, double y, double z) {
if (npc == null) {
super.b_(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.b_(x, y, z);
// when another entity collides, b_ is called to push the NPC
// so we prevent b_ from doing anything if the event is cancelled.
}
@Override @Override
public void collide(net.minecraft.server.Entity entity) { public void collide(net.minecraft.server.Entity entity) {
// this method is called by both the entities involved - cancelling // this method is called by both the entities involved - cancelling
@ -70,11 +56,31 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
} }
@Override @Override
public void F_() { public void g(double x, double y, double z) {
super.F_(); if (npc == null) {
Navigation navigation = al(); super.g(x, y, z);
if (!navigation.e()) { return;
navigation.d(); }
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0)
return;
NPCPushEvent event = Util.callPushEvent(npc, new Vector(x, y, z));
if (!event.isCancelled())
super.g(x, y, z);
// 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 NPC getNPC() {
return npc;
}
@Override
public void h_() {
super.h_();
Navigation navigation = getNavigation();
if (!navigation.f()) {
navigation.e();
moveOnCurrentHeading(); moveOnCurrentHeading();
} else if (motX != 0 || motZ != 0 || motY != 0) { } else if (motX != 0 || motZ != 0 || motY != 0) {
// a(0, 0); // a(0, 0);
@ -84,33 +90,28 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
npc.update(); npc.update();
} }
@Override
public NPC getNPC() {
return npc;
}
private void moveOnCurrentHeading() { private void moveOnCurrentHeading() {
getControllerMove().c(); getControllerMove().c();
getControllerLook().a(); getControllerLook().a();
getControllerJump().b(); getControllerJump().b();
// taken from EntityLiving // taken from EntityLiving
if (aZ) { if (bu) {
boolean inLiquid = aT() || aU(); boolean inLiquid = G() || H();
if (inLiquid) { if (inLiquid) {
motY += 0.04; motY += 0.04;
} else if (onGround && q == 0) { } else if (onGround && bE == 0) {
// this.ac(); - this doesn't jump high enough // this.ac(); - this doesn't jump high enough
motY = 0.6; motY = 0.6;
q = 10; bE = 10;
} }
} else { } else {
q = 0; bE = 0;
} }
aX *= 0.98F; aX *= 0.98F;
a(aW, aX); a(aW, aX);
X = yaw; as = yaw;
} }
} }

View File

@ -18,14 +18,11 @@ import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet51MapChunk; import net.minecraft.server.Packet51MapChunk;
public class EmptyNetHandler extends NetServerHandler { public class EmptyNetHandler extends NetServerHandler {
public EmptyNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) { public EmptyNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager,
EntityPlayer entityPlayer) {
super(minecraftServer, networkManager, entityPlayer); super(minecraftServer, networkManager, entityPlayer);
} }
@Override
public void a() {
}
@Override @Override
public void a(Packet102WindowClick packet) { public void a(Packet102WindowClick packet) {
} }
@ -74,10 +71,6 @@ public class EmptyNetHandler extends NetServerHandler {
public void a(String string, Object[] objects) { public void a(String string, Object[] objects) {
} }
@Override
public void sendMessage(String string) {
}
@Override @Override
public void sendPacket(Packet packet) { public void sendPacket(Packet packet) {
} }

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.network;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.Socket; import java.net.Socket;
import java.security.PrivateKey;
import net.minecraft.server.NetHandler; import net.minecraft.server.NetHandler;
import net.minecraft.server.NetworkManager; import net.minecraft.server.NetworkManager;
@ -9,8 +10,8 @@ import net.minecraft.server.Packet;
public class EmptyNetworkManager extends NetworkManager { public class EmptyNetworkManager extends NetworkManager {
public EmptyNetworkManager(Socket socket, String string, NetHandler netHandler) { public EmptyNetworkManager(Socket socket, String string, NetHandler netHandler, PrivateKey key) {
super(socket, string, netHandler); super(socket, string, netHandler, key);
try { try {
// the field above the 3 synchronized lists // the field above the 3 synchronized lists

View File

@ -1,85 +0,0 @@
package net.citizensnpcs.npc.network;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.Packet;
import net.minecraft.server.Packet102WindowClick;
import net.minecraft.server.Packet106Transaction;
import net.minecraft.server.Packet10Flying;
import net.minecraft.server.Packet130UpdateSign;
import net.minecraft.server.Packet14BlockDig;
import net.minecraft.server.Packet15Place;
import net.minecraft.server.Packet16BlockItemSwitch;
import net.minecraft.server.Packet255KickDisconnect;
import net.minecraft.server.Packet28EntityVelocity;
import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet51MapChunk;
public class NPCNetHandler extends NetServerHandler {
public NPCNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) {
super(minecraftServer, networkManager, entityPlayer);
}
@Override
public void a() {
}
@Override
public void a(Packet102WindowClick packet) {
}
@Override
public void a(Packet106Transaction packet) {
}
@Override
public void a(Packet10Flying packet) {
}
@Override
public void a(Packet130UpdateSign packet) {
}
@Override
public void a(Packet14BlockDig packet) {
}
@Override
public void a(Packet15Place packet) {
}
@Override
public void a(Packet16BlockItemSwitch packet) {
}
@Override
public void a(Packet255KickDisconnect packet) {
}
@Override
public void a(Packet28EntityVelocity packet) {
}
@Override
public void a(Packet3Chat packet) {
}
@Override
public void a(Packet51MapChunk packet) {
}
@Override
public void a(String string, Object[] objects) {
}
@Override
public void sendMessage(String string) {
}
@Override
public void sendPacket(Packet packet) {
}
}

View File

@ -1,52 +0,0 @@
package net.citizensnpcs.npc.network;
import java.lang.reflect.Field;
import java.net.Socket;
import net.minecraft.server.NetHandler;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.Packet;
public class NPCNetworkManager extends NetworkManager {
public NPCNetworkManager(Socket socket, String string, NetHandler netHandler) {
super(socket, string, netHandler);
try {
// the field above the 3 synchronized lists
Field f = NetworkManager.class.getDeclaredField("l");
f.setAccessible(true);
f.set(this, false);
} catch (Exception e) {
}
}
@Override
public void a() {
}
@Override
public void a(NetHandler netHandler) {
}
@Override
public void a(String s, Object... objects) {
}
@Override
public void b() {
}
@Override
public void d() {
}
@Override
public int e() {
return 0;
}
@Override
public void queue(Packet packet) {
}
}

View File

@ -42,7 +42,7 @@ public class Behaviour extends Trait {
} }
public void addScripts(Iterable<String> scripts) { public void addScripts(Iterable<String> scripts) {
BehaviourCallback callback = new BehaviourCallback(new Goals()); BehaviourCallback callback = new BehaviourCallback();
Iterable<File> transformed = Iterables.transform(scripts, fileConverterFunction); Iterable<File> transformed = Iterables.transform(scripts, fileConverterFunction);
CitizensAPI.getScriptCompiler().compile(transformed).withCallback(callback).begin(); CitizensAPI.getScriptCompiler().compile(transformed).withCallback(callback).begin();
} }
@ -85,35 +85,27 @@ public class Behaviour extends Trait {
key.setString("scripts", Joiner.on(",").join(scripts)); key.setString("scripts", Joiner.on(",").join(scripts));
} }
private class BehaviourCallback implements CompileCallback { public class BehaviourCallback implements CompileCallback {
private final Goals goals; private final Map<Goal, Integer> goals = Maps.newHashMap();
private BehaviourCallback(Goals goals) { public void addGoal(int priority, Goal goal) {
this.goals = goals; Validate.notNull(goal);
goals.put(goal, priority);
} }
@Override @Override
public void onCompileTaskFinished() { public void onCompileTaskFinished() {
addedGoals.putAll(goals.goals); addedGoals.putAll(goals);
if (!npc.isSpawned()) if (!npc.isSpawned())
return; return;
for (Entry<Goal, Integer> entry : goals.goals.entrySet()) { for (Entry<Goal, Integer> entry : goals.entrySet()) {
npc.getDefaultGoalController().addGoal(entry.getKey(), entry.getValue()); npc.getDefaultGoalController().addGoal(entry.getKey(), entry.getValue());
} }
} }
@Override @Override
public void onScriptCompiled(ScriptFactory script) { public void onScriptCompiled(ScriptFactory script) {
script.newInstance().invoke("addGoals", goals, npc); script.newInstance().invoke("addGoals", this, npc);
}
}
public static class Goals {
private final Map<Goal, Integer> goals = Maps.newHashMap();
public void addGoal(Goal goal, int priority) {
Validate.notNull(goal);
goals.put(goal, priority);
} }
} }
} }

View File

@ -44,7 +44,7 @@ public class LookClose extends Trait implements Toggleable {
EntityLiving handle = ((CraftLivingEntity) from).getHandle(); EntityLiving handle = ((CraftLivingEntity) from).getHandle();
handle.yaw = (float) yaw - 90; handle.yaw = (float) yaw - 90;
handle.pitch = (float) pitch; handle.pitch = (float) pitch;
handle.X = handle.yaw; handle.as = handle.yaw;
} }
private void findNewTarget() { private void findNewTarget() {

View File

@ -1,9 +1,11 @@
package net.citizensnpcs.util; package net.citizensnpcs.util;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
@ -11,6 +13,7 @@ import net.citizensnpcs.api.event.NPCCollisionEvent;
import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.minecraft.server.Packet; import net.minecraft.server.Packet;
import net.minecraft.server.PathfinderGoalSelector;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -31,6 +34,8 @@ public class Util {
private Util() { private Util() {
} }
private static Field GOAL_FIELD;
private static final Map<Class<?>, Class<?>> primitiveClassMap = Maps.newHashMap(); private static final Map<Class<?>, Class<?>> primitiveClassMap = Maps.newHashMap();
public static void callCollisionEvent(NPC npc, net.minecraft.server.Entity entity) { public static void callCollisionEvent(NPC npc, net.minecraft.server.Entity entity) {
@ -44,6 +49,18 @@ public class Util {
return event; return event;
} }
public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
if (GOAL_FIELD == null || goalSelectors == null)
return;
for (PathfinderGoalSelector selector : goalSelectors) {
try {
List<?> list = (List<?>) GOAL_FIELD.get(selector);
list.clear();
} catch (Exception e) {
}
}
}
/** /**
* Given a set of instantiation parameters, attempts to find a matching * Given a set of instantiation parameters, attempts to find a matching
* constructor with the greatest number of matching class parameters and * constructor with the greatest number of matching class parameters and
@ -178,5 +195,10 @@ public class Util {
primitiveClassMap.put(long.class, Long.class); primitiveClassMap.put(long.class, Long.class);
primitiveClassMap.put(float.class, Float.class); primitiveClassMap.put(float.class, Float.class);
primitiveClassMap.put(double.class, Double.class); primitiveClassMap.put(double.class, Double.class);
try {
GOAL_FIELD = PathfinderGoalSelector.class.getDeclaredField("a");
} catch (Exception e) {
GOAL_FIELD = null;
}
} }
} }