This commit is contained in:
fullwall 2012-08-17 22:05:30 +08:00
parent 4ac86c4e30
commit aa095e0d1b
4 changed files with 10 additions and 14 deletions

View File

@ -31,26 +31,22 @@ public class TraitCommands {
throw new NoPermissionsException();
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitName);
if (clazz == null)
throw new CommandException("Trait not found.");
boolean remove = npc.hasTrait(clazz);
if (remove) {
if (clazz == null)
throw new CommandException("Trait not found.");
npc.removeTrait(clazz);
Messaging.sendF(sender, ChatColor.GREEN + "Trait %s removed successfully.",
StringHelper.wrap(traitName));
return;
}
Trait trait = CitizensAPI.getTraitFactory().getTrait(traitName);
if (trait == null)
throw new CommandException("Trait not found.");
npc.addTrait(trait);
npc.addTrait(clazz);
Messaging.sendF(sender, ChatColor.GREEN + "Trait %s added successfully.",
StringHelper.wrap(traitName));
}
@Command(
aliases = { "traitc, trc,tc" },
aliases = { "traitc", "trc", "tc" },
usage = "[trait name] [flags]",
desc = "Configures a trait",
modifiers = { "*" },

View File

@ -21,8 +21,7 @@ public class CitizensNavigator implements Navigator {
private PathStrategy executing;
private final CitizensNPC npc;
private float pathfindingRange = Setting.DEFAULT_PATHFINDING_RANGE.asFloat();
private float speed = -1;
private float speed = UNINITIALISED_SPEED;
public CitizensNavigator(CitizensNPC npc) {
this.npc = npc;
}
@ -73,8 +72,8 @@ public class CitizensNavigator implements Navigator {
}
public void onSpawn() {
if (speed == -1)
this.speed = NMSReflection.getSpeedFor(npc.getHandle());
if (speed == UNINITIALISED_SPEED)
speed = NMSReflection.getSpeedFor(npc.getHandle());
updatePathfindingRange();
}
@ -139,4 +138,6 @@ public class CitizensNavigator implements Navigator {
private void updatePathfindingRange() {
NMSReflection.updatePathfindingRange(npc, pathfindingRange);
}
private static int UNINITIALISED_SPEED = Integer.MIN_VALUE;
}

View File

@ -18,7 +18,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CitizensHumanNPC extends CitizensNPC implements Equipable {
public CitizensHumanNPC(int id, String name) {
super(id, name);
}

View File

@ -164,8 +164,8 @@ public class LinearWaypointProvider implements WaypointProvider {
if (currentGoal == null) {
currentGoal = new LinearWaypointGoal();
CitizensAPI.registerEvents(currentGoal);
npc.getDefaultGoalController().addGoal(currentGoal, 1);
}
npc.getDefaultGoalController().addGoal(currentGoal, 1);
}
@Override