Skip to content

Commit

Permalink
Fix speed on mob NPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jan 6, 2014
1 parent 5668b9e commit 926f736
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ public void copy(CommandContext args, CommandSender sender, NPC npc) throws Comm
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public void onSpawn() {
if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) {
defaultParams.baseSpeed(NMS.getSpeedFor(npc));
}
NMS.setSpeed(npc.getEntity(), defaultParams.speedModifier());
updatePathfindingRange();
}

Expand Down
15 changes: 4 additions & 11 deletions src/main/java/net/citizensnpcs/util/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ public static Navigation getNavigation(EntityLiving handle) {
}

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) {
Expand Down Expand Up @@ -381,13 +381,6 @@ public static void setShouldJump(org.bukkit.entity.Entity entity) {
}
}

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;
}
Expand Down

0 comments on commit 926f736

Please sign in to comment.