Implement new parameter, default USE_NEW_PATHFINDER to true

This commit is contained in:
fullwall 2013-07-06 12:02:17 +08:00
parent 01ede533f8
commit 65bb8f202a
7 changed files with 28 additions and 31 deletions

View File

@ -106,7 +106,7 @@ public class Settings {
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10),
TALK_ITEM("npc.text.talk-item", "340"),
USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true),
USE_NEW_PATHFINDER("npc.pathfinding.use-new-finder", false);
USE_NEW_PATHFINDER("npc.pathfinding.use-new-finder", true);
protected String path;
protected Object value;

View File

@ -26,10 +26,7 @@ import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.api.trait.trait.Speech;
import net.citizensnpcs.api.util.Colorizer;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.util.MemoryDataKey;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.NPCSelector;
import net.citizensnpcs.npc.Template;
import net.citizensnpcs.trait.Age;
@ -232,25 +229,19 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.copy")
public void copy(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
EntityType type = npc.getTrait(MobType.class).getType();
String name = args.getFlag("name", npc.getFullName());
CitizensNPC copy = (CitizensNPC) npcRegistry.createNPC(type, name);
CitizensNPC from = (CitizensNPC) npc;
NPC copy = npc.clone();
if (!copy.getFullName().equals(name)) {
copy.setName(name);
}
DataKey key = new MemoryDataKey();
from.save(key);
copy.load(key);
if (from.isSpawned() && args.getSenderLocation() != null) {
if (copy.isSpawned() && args.getSenderLocation() != null) {
Location location = args.getSenderLocation();
location.getChunk().load();
copy.getBukkitEntity().teleport(location);
copy.getTrait(CurrentLocation.class).setLocation(location);
}
for (Trait trait : copy.getTraits())
trait.onCopy();
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy)
: new CommandSenderCreateNPCEvent(sender, copy);
Bukkit.getPluginManager().callEvent(event);

View File

@ -169,8 +169,9 @@ public class CitizensNPC extends AbstractNPC {
despawn(DespawnReason.PENDING_RESPAWN);
}
entityController = newController;
if (wasSpawned)
if (wasSpawned) {
spawn(prev);
}
}
@Override

View File

@ -161,10 +161,11 @@ public class CitizensNavigator implements Navigator, Runnable {
}
localParams = defaultParams.clone();
PathStrategy newStrategy;
if (Setting.USE_NEW_PATHFINDER.asBoolean()) {
if (Setting.USE_NEW_PATHFINDER.asBoolean() || localParams.useNewPathfinder()) {
newStrategy = new AStarNavigationStrategy(npc, target, localParams);
} else
} else {
newStrategy = new MCNavigationStrategy(npc, target, localParams);
}
switchStrategyTo(newStrategy);
}

View File

@ -40,8 +40,8 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
this.handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
this.target = ((CraftEntity) target).getHandle();
Navigation nav = NMS.getNavigation(this.handle);
this.targetNavigator = nav != null && !Setting.USE_NEW_PATHFINDER.asBoolean() ? new NavigationFieldWrapper(nav)
: new AStarTargeter();
this.targetNavigator = nav != null && !Setting.USE_NEW_PATHFINDER.asBoolean() && !params.useNewPathfinder() ? new NavigationFieldWrapper(
nav) : new AStarTargeter();
this.aggro = aggro;
}

View File

@ -122,7 +122,7 @@ public class LinearWaypointProvider implements WaypointProvider {
int editingSlot = waypoints.size() - 1;
private final Player player;
private boolean showPath;
Map<Waypoint, Entity> waypointMarkers = Maps.newHashMap();
private final Map<Waypoint, Entity> waypointMarkers = Maps.newHashMap();
private LinearWaypointEditor(Player player) {
this.player = player;
@ -150,13 +150,15 @@ public class LinearWaypointProvider implements WaypointProvider {
}
private void createWaypointMarkers() {
for (int i = 0; i < waypoints.size(); i++)
for (int i = 0; i < waypoints.size(); i++) {
createWaypointMarker(i, waypoints.get(i));
}
}
private void destroyWaypointMarkers() {
for (Entity entity : waypointMarkers.values())
for (Entity entity : waypointMarkers.values()) {
entity.remove();
}
waypointMarkers.clear();
}
@ -180,8 +182,9 @@ public class LinearWaypointProvider implements WaypointProvider {
@Override
public Waypoint getCurrentWaypoint() {
if (waypoints.size() == 0 || !editing)
if (waypoints.size() == 0 || !editing) {
return null;
}
normaliseEditingSlot();
return waypoints.get(editingSlot);
}
@ -189,8 +192,7 @@ public class LinearWaypointProvider implements WaypointProvider {
private Location getPreviousWaypoint(int fromSlot) {
if (waypoints.size() <= 1)
return null;
fromSlot--;
if (fromSlot < 0)
if (--fromSlot < 0)
fromSlot = waypoints.size() - 1;
return waypoints.get(fromSlot).getLocation();
}
@ -201,14 +203,16 @@ public class LinearWaypointProvider implements WaypointProvider {
@EventHandler
public void onNPCDespawn(NPCDespawnEvent event) {
if (event.getNPC().equals(npc))
if (event.getNPC().equals(npc)) {
Editor.leave(player);
}
}
@EventHandler
public void onNPCRemove(NPCRemoveEvent event) {
if (event.getNPC().equals(npc))
if (event.getNPC().equals(npc)) {
Editor.leave(player);
}
}
@EventHandler(ignoreCancelled = true)
@ -217,21 +221,21 @@ public class LinearWaypointProvider implements WaypointProvider {
return;
String message = event.getMessage();
if (message.equalsIgnoreCase("triggers")) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
}
});
return;
} else if (message.equalsIgnoreCase("clear")) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
clearWaypoints();
}
});
return;
} else if (message.equalsIgnoreCase("toggle path")) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@ -241,7 +245,6 @@ public class LinearWaypointProvider implements WaypointProvider {
togglePath();
}
});
return;
}
}

View File

@ -308,6 +308,7 @@ public class NMS {
Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage());
return null;
}
entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
handle.addEntity(entity);
entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
return entity.getBukkitEntity();