Fix speed on mob NPCs

This commit is contained in:
fullwall 2014-01-07 00:48:17 +08:00
parent 3808d7188a
commit 8ad3b1d674
3 changed files with 6 additions and 14 deletions

View File

@ -289,12 +289,12 @@ public class NPCCommands {
permission = "citizens.npc.create")
@Requirements
public void create(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
String name = Colorizer.parseColors(args.getJoinedStrings(1));
String name = Colorizer.parseColors(args.getJoinedStrings(1).trim());
if (name.length() > 16) {
Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG);
name = name.substring(0, 16);
}
if (name.length() <= 0)
if (name.length() == 0)
throw new CommandException();
EntityType type = EntityType.PLAYER;

View File

@ -110,7 +110,6 @@ public class CitizensNavigator implements Navigator, Runnable {
if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) {
defaultParams.baseSpeed(NMS.getSpeedFor(npc));
}
NMS.setSpeed(npc.getEntity(), defaultParams.speedModifier());
updatePathfindingRange();
}

View File

@ -213,12 +213,12 @@ public class NMS {
}
public static float getSpeedFor(NPC npc) {
if (!npc.isSpawned())
if (!npc.isSpawned() || !(npc instanceof LivingEntity))
return DEFAULT_SPEED;
// this is correct, but too slow. TODO: investigate
// return (float)
// NMS.getHandle(npc.getBukkitEntity()).getAttributeInstance(GenericAttributes.d).getValue();
return DEFAULT_SPEED;
return (float) ((EntityLiving) NMS.getHandle(npc.getEntity())).getAttributeInstance(GenericAttributes.d)
.getValue();
// return DEFAULT_SPEED;
}
public static void initNetworkManager(NetworkManager network) {
@ -381,13 +381,6 @@ public class NMS {
}
}
public static void setSpeed(org.bukkit.entity.Entity entity, float speedModifier) {
if (!(entity instanceof LivingEntity))
return;
EntityLiving handle = NMS.getHandle((LivingEntity) entity);
handle.getAttributeInstance(GenericAttributes.d).setValue(speedModifier);
}
public static void setStepHeight(EntityLiving entity, float height) {
entity.X = height;
}