mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 20:17:50 +01:00
Implement new parameter, default USE_NEW_PATHFINDER to true
This commit is contained in:
parent
01ede533f8
commit
65bb8f202a
@ -106,7 +106,7 @@ public class Settings {
|
|||||||
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10),
|
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10),
|
||||||
TALK_ITEM("npc.text.talk-item", "340"),
|
TALK_ITEM("npc.text.talk-item", "340"),
|
||||||
USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true),
|
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 String path;
|
||||||
protected Object value;
|
protected Object value;
|
||||||
|
@ -26,10 +26,7 @@ import net.citizensnpcs.api.trait.trait.Owner;
|
|||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.api.trait.trait.Speech;
|
import net.citizensnpcs.api.trait.trait.Speech;
|
||||||
import net.citizensnpcs.api.util.Colorizer;
|
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.api.util.Messaging;
|
||||||
import net.citizensnpcs.npc.CitizensNPC;
|
|
||||||
import net.citizensnpcs.npc.NPCSelector;
|
import net.citizensnpcs.npc.NPCSelector;
|
||||||
import net.citizensnpcs.npc.Template;
|
import net.citizensnpcs.npc.Template;
|
||||||
import net.citizensnpcs.trait.Age;
|
import net.citizensnpcs.trait.Age;
|
||||||
@ -232,25 +229,19 @@ public class NPCCommands {
|
|||||||
max = 1,
|
max = 1,
|
||||||
permission = "citizens.npc.copy")
|
permission = "citizens.npc.copy")
|
||||||
public void copy(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
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());
|
String name = args.getFlag("name", npc.getFullName());
|
||||||
CitizensNPC copy = (CitizensNPC) npcRegistry.createNPC(type, name);
|
NPC copy = npc.clone();
|
||||||
CitizensNPC from = (CitizensNPC) npc;
|
if (!copy.getFullName().equals(name)) {
|
||||||
|
copy.setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
DataKey key = new MemoryDataKey();
|
if (copy.isSpawned() && args.getSenderLocation() != null) {
|
||||||
from.save(key);
|
|
||||||
copy.load(key);
|
|
||||||
|
|
||||||
if (from.isSpawned() && args.getSenderLocation() != null) {
|
|
||||||
Location location = args.getSenderLocation();
|
Location location = args.getSenderLocation();
|
||||||
location.getChunk().load();
|
location.getChunk().load();
|
||||||
copy.getBukkitEntity().teleport(location);
|
copy.getBukkitEntity().teleport(location);
|
||||||
copy.getTrait(CurrentLocation.class).setLocation(location);
|
copy.getTrait(CurrentLocation.class).setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Trait trait : copy.getTraits())
|
|
||||||
trait.onCopy();
|
|
||||||
|
|
||||||
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy)
|
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy)
|
||||||
: new CommandSenderCreateNPCEvent(sender, copy);
|
: new CommandSenderCreateNPCEvent(sender, copy);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
@ -169,8 +169,9 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
despawn(DespawnReason.PENDING_RESPAWN);
|
despawn(DespawnReason.PENDING_RESPAWN);
|
||||||
}
|
}
|
||||||
entityController = newController;
|
entityController = newController;
|
||||||
if (wasSpawned)
|
if (wasSpawned) {
|
||||||
spawn(prev);
|
spawn(prev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -161,10 +161,11 @@ public class CitizensNavigator implements Navigator, Runnable {
|
|||||||
}
|
}
|
||||||
localParams = defaultParams.clone();
|
localParams = defaultParams.clone();
|
||||||
PathStrategy newStrategy;
|
PathStrategy newStrategy;
|
||||||
if (Setting.USE_NEW_PATHFINDER.asBoolean()) {
|
if (Setting.USE_NEW_PATHFINDER.asBoolean() || localParams.useNewPathfinder()) {
|
||||||
newStrategy = new AStarNavigationStrategy(npc, target, localParams);
|
newStrategy = new AStarNavigationStrategy(npc, target, localParams);
|
||||||
} else
|
} else {
|
||||||
newStrategy = new MCNavigationStrategy(npc, target, localParams);
|
newStrategy = new MCNavigationStrategy(npc, target, localParams);
|
||||||
|
}
|
||||||
switchStrategyTo(newStrategy);
|
switchStrategyTo(newStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
|||||||
this.handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
|
this.handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
|
||||||
this.target = ((CraftEntity) target).getHandle();
|
this.target = ((CraftEntity) target).getHandle();
|
||||||
Navigation nav = NMS.getNavigation(this.handle);
|
Navigation nav = NMS.getNavigation(this.handle);
|
||||||
this.targetNavigator = nav != null && !Setting.USE_NEW_PATHFINDER.asBoolean() ? new NavigationFieldWrapper(nav)
|
this.targetNavigator = nav != null && !Setting.USE_NEW_PATHFINDER.asBoolean() && !params.useNewPathfinder() ? new NavigationFieldWrapper(
|
||||||
: new AStarTargeter();
|
nav) : new AStarTargeter();
|
||||||
this.aggro = aggro;
|
this.aggro = aggro;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
int editingSlot = waypoints.size() - 1;
|
int editingSlot = waypoints.size() - 1;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private boolean showPath;
|
private boolean showPath;
|
||||||
Map<Waypoint, Entity> waypointMarkers = Maps.newHashMap();
|
private final Map<Waypoint, Entity> waypointMarkers = Maps.newHashMap();
|
||||||
|
|
||||||
private LinearWaypointEditor(Player player) {
|
private LinearWaypointEditor(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -150,13 +150,15 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createWaypointMarkers() {
|
private void createWaypointMarkers() {
|
||||||
for (int i = 0; i < waypoints.size(); i++)
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
createWaypointMarker(i, waypoints.get(i));
|
createWaypointMarker(i, waypoints.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void destroyWaypointMarkers() {
|
private void destroyWaypointMarkers() {
|
||||||
for (Entity entity : waypointMarkers.values())
|
for (Entity entity : waypointMarkers.values()) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
|
}
|
||||||
waypointMarkers.clear();
|
waypointMarkers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,8 +182,9 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Waypoint getCurrentWaypoint() {
|
public Waypoint getCurrentWaypoint() {
|
||||||
if (waypoints.size() == 0 || !editing)
|
if (waypoints.size() == 0 || !editing) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
normaliseEditingSlot();
|
normaliseEditingSlot();
|
||||||
return waypoints.get(editingSlot);
|
return waypoints.get(editingSlot);
|
||||||
}
|
}
|
||||||
@ -189,8 +192,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
private Location getPreviousWaypoint(int fromSlot) {
|
private Location getPreviousWaypoint(int fromSlot) {
|
||||||
if (waypoints.size() <= 1)
|
if (waypoints.size() <= 1)
|
||||||
return null;
|
return null;
|
||||||
fromSlot--;
|
if (--fromSlot < 0)
|
||||||
if (fromSlot < 0)
|
|
||||||
fromSlot = waypoints.size() - 1;
|
fromSlot = waypoints.size() - 1;
|
||||||
return waypoints.get(fromSlot).getLocation();
|
return waypoints.get(fromSlot).getLocation();
|
||||||
}
|
}
|
||||||
@ -201,14 +203,16 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onNPCDespawn(NPCDespawnEvent event) {
|
public void onNPCDespawn(NPCDespawnEvent event) {
|
||||||
if (event.getNPC().equals(npc))
|
if (event.getNPC().equals(npc)) {
|
||||||
Editor.leave(player);
|
Editor.leave(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onNPCRemove(NPCRemoveEvent event) {
|
public void onNPCRemove(NPCRemoveEvent event) {
|
||||||
if (event.getNPC().equals(npc))
|
if (event.getNPC().equals(npc)) {
|
||||||
Editor.leave(player);
|
Editor.leave(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
@ -217,21 +221,21 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
return;
|
return;
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
if (message.equalsIgnoreCase("triggers")) {
|
if (message.equalsIgnoreCase("triggers")) {
|
||||||
|
event.setCancelled(true);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
} else if (message.equalsIgnoreCase("clear")) {
|
} else if (message.equalsIgnoreCase("clear")) {
|
||||||
|
event.setCancelled(true);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
clearWaypoints();
|
clearWaypoints();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
} else if (message.equalsIgnoreCase("toggle path")) {
|
} else if (message.equalsIgnoreCase("toggle path")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
@ -241,7 +245,6 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
togglePath();
|
togglePath();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,6 +308,7 @@ public class NMS {
|
|||||||
Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage());
|
Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
|
||||||
handle.addEntity(entity);
|
handle.addEntity(entity);
|
||||||
entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
|
entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
|
||||||
return entity.getBukkitEntity();
|
return entity.getBukkitEntity();
|
||||||
|
Loading…
Reference in New Issue
Block a user