mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
Reformat project
This commit is contained in:
parent
8d6b56daa2
commit
b9a08d609a
File diff suppressed because it is too large
Load Diff
@ -82,7 +82,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||
for (Trait t : npc.getTraits()) {
|
||||
HandlerList.unregisterAll(t);
|
||||
t.onRemove();
|
||||
}
|
||||
}
|
||||
itr.remove();
|
||||
if (saves != null) {
|
||||
saves.clearData(npc);
|
||||
|
@ -17,13 +17,11 @@ public enum ProfileFetchResult {
|
||||
*/
|
||||
FAILED,
|
||||
/**
|
||||
* The profile request failed because the profile
|
||||
* was not found.
|
||||
* The profile request failed because the profile was not found.
|
||||
*/
|
||||
NOT_FOUND,
|
||||
/**
|
||||
* The profile request failed because too many requests
|
||||
* were sent.
|
||||
* The profile request failed because too many requests were sent.
|
||||
*/
|
||||
TOO_MANY_REQUESTS
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ public class CommandTrait extends Trait {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a brief description of the current state of the trait to the supplied
|
||||
* {@link CommandSender}.
|
||||
* Send a brief description of the current state of the trait to the supplied {@link CommandSender}.
|
||||
*/
|
||||
public void describe(CommandSender sender) {
|
||||
List<NPCCommand> left = Lists.newArrayList();
|
||||
@ -96,7 +95,9 @@ public class CommandTrait extends Trait {
|
||||
}
|
||||
|
||||
public static enum Hand {
|
||||
BOTH, LEFT, RIGHT;
|
||||
BOTH,
|
||||
LEFT,
|
||||
RIGHT;
|
||||
}
|
||||
|
||||
private static class NPCCommand {
|
||||
|
@ -15,42 +15,42 @@ import net.citizensnpcs.util.NMS;
|
||||
*/
|
||||
@TraitName("ocelotmodifiers")
|
||||
public class OcelotModifiers extends Trait {
|
||||
@Persist("sitting")
|
||||
private boolean sitting;
|
||||
@Persist("type")
|
||||
private Ocelot.Type type = Ocelot.Type.WILD_OCELOT;
|
||||
@Persist("sitting")
|
||||
private boolean sitting;
|
||||
@Persist("type")
|
||||
private Ocelot.Type type = Ocelot.Type.WILD_OCELOT;
|
||||
|
||||
public OcelotModifiers() {
|
||||
super("ocelotmodifiers");
|
||||
}
|
||||
public OcelotModifiers() {
|
||||
super("ocelotmodifiers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
updateModifiers();
|
||||
}
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
updateModifiers();
|
||||
}
|
||||
|
||||
public void setSitting(boolean sit) {
|
||||
this.sitting = sit;
|
||||
updateModifiers();
|
||||
}
|
||||
public void setSitting(boolean sit) {
|
||||
this.sitting = sit;
|
||||
updateModifiers();
|
||||
}
|
||||
|
||||
public void setType(Ocelot.Type type) {
|
||||
this.type = type;
|
||||
updateModifiers();
|
||||
}
|
||||
public void setType(Ocelot.Type type) {
|
||||
this.type = type;
|
||||
updateModifiers();
|
||||
}
|
||||
|
||||
private void updateModifiers() {
|
||||
if (npc.getEntity() instanceof Ocelot) {
|
||||
Ocelot ocelot = (Ocelot) npc.getEntity();
|
||||
try {
|
||||
ocelot.setCatType(type);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
npc.getTrait(CatTrait.class).setSitting(sitting);
|
||||
npc.getTrait(CatTrait.class).setType(type);
|
||||
npc.removeTrait(OcelotModifiers.class);
|
||||
return;
|
||||
}
|
||||
NMS.setSitting(ocelot, sitting);
|
||||
}
|
||||
}
|
||||
private void updateModifiers() {
|
||||
if (npc.getEntity() instanceof Ocelot) {
|
||||
Ocelot ocelot = (Ocelot) npc.getEntity();
|
||||
try {
|
||||
ocelot.setCatType(type);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
npc.getTrait(CatTrait.class).setSitting(sitting);
|
||||
npc.getTrait(CatTrait.class).setType(type);
|
||||
npc.removeTrait(OcelotModifiers.class);
|
||||
return;
|
||||
}
|
||||
NMS.setSitting(ocelot, sitting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ public class Powered extends Trait implements Toggleable {
|
||||
((Creeper) npc.getEntity()).setPowered(powered);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isPowered() {
|
||||
return powered;
|
||||
return powered;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,69 +11,69 @@ import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
|
||||
public class TextStartPrompt extends StringPrompt {
|
||||
private final Text text;
|
||||
private final Text text;
|
||||
|
||||
public TextStartPrompt(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
public TextStartPrompt(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String original) {
|
||||
String[] parts = ChatColor.stripColor(original.trim()).split(" ");
|
||||
String input = parts[0];
|
||||
CommandSender sender = (CommandSender) context.getForWhom();
|
||||
if (input.equalsIgnoreCase("add"))
|
||||
return new TextAddPrompt(text);
|
||||
else if (input.equalsIgnoreCase("edit"))
|
||||
return new TextEditStartPrompt(text);
|
||||
else if (input.equalsIgnoreCase("remove"))
|
||||
return new TextRemovePrompt(text);
|
||||
else if (input.equalsIgnoreCase("delay")) {
|
||||
try {
|
||||
int delay = Integer.parseInt(parts[1]);
|
||||
text.setDelay(delay);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("random"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
|
||||
else if (input.equalsIgnoreCase("realistic looking"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());
|
||||
else if (input.equalsIgnoreCase("close") || input.equalsIgnoreCase("talk-close"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle());
|
||||
else if (input.equalsIgnoreCase("range")) {
|
||||
try {
|
||||
double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble());
|
||||
text.setRange(range);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("item")) {
|
||||
if (parts.length > 1) {
|
||||
text.setItemInHandPattern(parts[1]);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_SET_ITEM, parts[1]);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("help")) {
|
||||
context.setSessionData("said-text", false);
|
||||
Messaging.send(sender, getPromptText(context));
|
||||
} else
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE);
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String original) {
|
||||
String[] parts = ChatColor.stripColor(original.trim()).split(" ");
|
||||
String input = parts[0];
|
||||
CommandSender sender = (CommandSender) context.getForWhom();
|
||||
if (input.equalsIgnoreCase("add"))
|
||||
return new TextAddPrompt(text);
|
||||
else if (input.equalsIgnoreCase("edit"))
|
||||
return new TextEditStartPrompt(text);
|
||||
else if (input.equalsIgnoreCase("remove"))
|
||||
return new TextRemovePrompt(text);
|
||||
else if (input.equalsIgnoreCase("delay")) {
|
||||
try {
|
||||
int delay = Integer.parseInt(parts[1]);
|
||||
text.setDelay(delay);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("random"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
|
||||
else if (input.equalsIgnoreCase("realistic looking"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());
|
||||
else if (input.equalsIgnoreCase("close") || input.equalsIgnoreCase("talk-close"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle());
|
||||
else if (input.equalsIgnoreCase("range")) {
|
||||
try {
|
||||
double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble());
|
||||
text.setRange(range);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("item")) {
|
||||
if (parts.length > 1) {
|
||||
text.setItemInHandPattern(parts[1]);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_SET_ITEM, parts[1]);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("help")) {
|
||||
context.setSessionData("said-text", false);
|
||||
Messaging.send(sender, getPromptText(context));
|
||||
} else
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE);
|
||||
|
||||
return new TextStartPrompt(text);
|
||||
}
|
||||
return new TextStartPrompt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
if (context.getSessionData("said-text") == Boolean.TRUE)
|
||||
return "";
|
||||
String text = Messaging.tr(Messages.TEXT_EDITOR_START_PROMPT);
|
||||
context.setSessionData("said-text", Boolean.TRUE);
|
||||
return text;
|
||||
}
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
if (context.getSessionData("said-text") == Boolean.TRUE)
|
||||
return "";
|
||||
String text = Messaging.tr(Messages.TEXT_EDITOR_START_PROMPT);
|
||||
context.setSessionData("said-text", Boolean.TRUE);
|
||||
return text;
|
||||
}
|
||||
}
|
@ -11,66 +11,66 @@ import net.citizensnpcs.util.NMS;
|
||||
|
||||
@TraitName("cattrait")
|
||||
public class CatTrait extends Trait {
|
||||
@Persist
|
||||
private DyeColor collarColor = null;
|
||||
@Persist
|
||||
private boolean lying = false;
|
||||
@Persist
|
||||
private boolean sitting = false;
|
||||
@Persist
|
||||
private Cat.Type type = Cat.Type.BLACK;
|
||||
@Persist
|
||||
private DyeColor collarColor = null;
|
||||
@Persist
|
||||
private boolean lying = false;
|
||||
@Persist
|
||||
private boolean sitting = false;
|
||||
@Persist
|
||||
private Cat.Type type = Cat.Type.BLACK;
|
||||
|
||||
public CatTrait() {
|
||||
super("cattrait");
|
||||
}
|
||||
public CatTrait() {
|
||||
super("cattrait");
|
||||
}
|
||||
|
||||
public boolean isLyingDown() {
|
||||
return lying;
|
||||
}
|
||||
public boolean isLyingDown() {
|
||||
return lying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (npc.isSpawned() && npc.getEntity() instanceof Cat) {
|
||||
Cat cat = (Cat) npc.getEntity();
|
||||
cat.setSitting(sitting);
|
||||
cat.setCatType(type);
|
||||
if (collarColor != null) {
|
||||
cat.setCollarColor(collarColor);
|
||||
}
|
||||
NMS.setLyingDown(cat, lying);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
if (npc.isSpawned() && npc.getEntity() instanceof Cat) {
|
||||
Cat cat = (Cat) npc.getEntity();
|
||||
cat.setSitting(sitting);
|
||||
cat.setCatType(type);
|
||||
if (collarColor != null) {
|
||||
cat.setCollarColor(collarColor);
|
||||
}
|
||||
NMS.setLyingDown(cat, lying);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCollarColor(DyeColor color) {
|
||||
this.collarColor = color;
|
||||
}
|
||||
public void setCollarColor(DyeColor color) {
|
||||
this.collarColor = color;
|
||||
}
|
||||
|
||||
public void setLyingDown(boolean lying) {
|
||||
this.lying = lying;
|
||||
}
|
||||
public void setLyingDown(boolean lying) {
|
||||
this.lying = lying;
|
||||
}
|
||||
|
||||
public void setSitting(boolean sitting) {
|
||||
this.sitting = sitting;
|
||||
}
|
||||
public void setSitting(boolean sitting) {
|
||||
this.sitting = sitting;
|
||||
}
|
||||
|
||||
public void setType(Cat.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
public void setType(Cat.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setType(Type type2) {
|
||||
switch (type2) {
|
||||
case WILD_OCELOT:
|
||||
this.type = Cat.Type.CALICO;
|
||||
break;
|
||||
case BLACK_CAT:
|
||||
this.type = Cat.Type.BLACK;
|
||||
break;
|
||||
case RED_CAT:
|
||||
this.type = Cat.Type.RED;
|
||||
break;
|
||||
case SIAMESE_CAT:
|
||||
this.type = Cat.Type.SIAMESE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void setType(Type type2) {
|
||||
switch (type2) {
|
||||
case WILD_OCELOT:
|
||||
this.type = Cat.Type.CALICO;
|
||||
break;
|
||||
case BLACK_CAT:
|
||||
this.type = Cat.Type.BLACK;
|
||||
break;
|
||||
case RED_CAT:
|
||||
this.type = Cat.Type.RED;
|
||||
break;
|
||||
case SIAMESE_CAT:
|
||||
this.type = Cat.Type.SIAMESE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,458 +44,458 @@ import net.citizensnpcs.util.Util;
|
||||
* An ordered list of {@link Waypoint}s to walk between.
|
||||
*/
|
||||
public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
||||
private LinearWaypointGoal currentGoal;
|
||||
private NPC npc;
|
||||
private final List<Waypoint> waypoints = Lists.newArrayList();
|
||||
private LinearWaypointGoal currentGoal;
|
||||
private NPC npc;
|
||||
private final List<Waypoint> waypoints = Lists.newArrayList();
|
||||
|
||||
public LinearWaypointProvider() {
|
||||
}
|
||||
public LinearWaypointProvider() {
|
||||
}
|
||||
|
||||
public LinearWaypointProvider(NPC npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
public LinearWaypointProvider(NPC npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaypointEditor createEditor(CommandSender sender, CommandContext args) {
|
||||
if (args.hasFlag('h')) {
|
||||
try {
|
||||
if (args.getSenderLocation() != null) {
|
||||
waypoints.add(new Waypoint(args.getSenderLocation()));
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
Messaging.sendError(sender, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
} else if (args.hasValueFlag("at")) {
|
||||
try {
|
||||
Location location = CommandContext.parseLocation(args.getSenderLocation(), args.getFlag("at"));
|
||||
if (location != null) {
|
||||
waypoints.add(new Waypoint(location));
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
Messaging.sendError(sender, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
} else if (args.hasFlag('c')) {
|
||||
waypoints.clear();
|
||||
return null;
|
||||
} else if (args.hasFlag('l')) {
|
||||
if (waypoints.size() > 0) {
|
||||
waypoints.remove(waypoints.size() - 1);
|
||||
}
|
||||
return null;
|
||||
} else if (args.hasFlag('p')) {
|
||||
setPaused(!isPaused());
|
||||
return null;
|
||||
} else if (!(sender instanceof Player)) {
|
||||
Messaging.sendErrorTr(sender, Messages.COMMAND_MUST_BE_INGAME);
|
||||
return null;
|
||||
}
|
||||
return new LinearWaypointEditor((Player) sender);
|
||||
}
|
||||
@Override
|
||||
public WaypointEditor createEditor(CommandSender sender, CommandContext args) {
|
||||
if (args.hasFlag('h')) {
|
||||
try {
|
||||
if (args.getSenderLocation() != null) {
|
||||
waypoints.add(new Waypoint(args.getSenderLocation()));
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
Messaging.sendError(sender, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
} else if (args.hasValueFlag("at")) {
|
||||
try {
|
||||
Location location = CommandContext.parseLocation(args.getSenderLocation(), args.getFlag("at"));
|
||||
if (location != null) {
|
||||
waypoints.add(new Waypoint(location));
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
Messaging.sendError(sender, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
} else if (args.hasFlag('c')) {
|
||||
waypoints.clear();
|
||||
return null;
|
||||
} else if (args.hasFlag('l')) {
|
||||
if (waypoints.size() > 0) {
|
||||
waypoints.remove(waypoints.size() - 1);
|
||||
}
|
||||
return null;
|
||||
} else if (args.hasFlag('p')) {
|
||||
setPaused(!isPaused());
|
||||
return null;
|
||||
} else if (!(sender instanceof Player)) {
|
||||
Messaging.sendErrorTr(sender, Messages.COMMAND_MUST_BE_INGAME);
|
||||
return null;
|
||||
}
|
||||
return new LinearWaypointEditor((Player) sender);
|
||||
}
|
||||
|
||||
public Waypoint getCurrentWaypoint() {
|
||||
if (currentGoal != null && currentGoal.currentDestination != null) {
|
||||
return currentGoal.currentDestination;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Waypoint getCurrentWaypoint() {
|
||||
if (currentGoal != null && currentGoal.currentDestination != null) {
|
||||
return currentGoal.currentDestination;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaused() {
|
||||
return currentGoal == null ? false : currentGoal.isPaused();
|
||||
}
|
||||
@Override
|
||||
public boolean isPaused() {
|
||||
return currentGoal == null ? false : currentGoal.isPaused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) {
|
||||
for (DataKey root : key.getRelative("points").getIntegerSubKeys()) {
|
||||
Waypoint waypoint = PersistenceLoader.load(Waypoint.class, root);
|
||||
if (waypoint == null)
|
||||
continue;
|
||||
waypoints.add(waypoint);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void load(DataKey key) {
|
||||
for (DataKey root : key.getRelative("points").getIntegerSubKeys()) {
|
||||
Waypoint waypoint = PersistenceLoader.load(Waypoint.class, root);
|
||||
if (waypoint == null)
|
||||
continue;
|
||||
waypoints.add(waypoint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {
|
||||
if (currentGoal != null) {
|
||||
npc.getDefaultGoalController().removeGoal(currentGoal);
|
||||
currentGoal = null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onRemove() {
|
||||
if (currentGoal != null) {
|
||||
npc.getDefaultGoalController().removeGoal(currentGoal);
|
||||
currentGoal = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
if (currentGoal == null) {
|
||||
currentGoal = new LinearWaypointGoal();
|
||||
npc.getDefaultGoalController().addGoal(currentGoal, 1);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
if (currentGoal == null) {
|
||||
currentGoal = new LinearWaypointGoal();
|
||||
npc.getDefaultGoalController().addGoal(currentGoal, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.removeKey("points");
|
||||
key = key.getRelative("points");
|
||||
for (int i = 0; i < waypoints.size(); ++i) {
|
||||
PersistenceLoader.save(waypoints.get(i), key.getRelative(i));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
key.removeKey("points");
|
||||
key = key.getRelative("points");
|
||||
for (int i = 0; i < waypoints.size(); ++i) {
|
||||
PersistenceLoader.save(waypoints.get(i), key.getRelative(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaused(boolean paused) {
|
||||
if (currentGoal != null) {
|
||||
currentGoal.setPaused(paused);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setPaused(boolean paused) {
|
||||
if (currentGoal != null) {
|
||||
currentGoal.setPaused(paused);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modifiable list of waypoints.
|
||||
*/
|
||||
@Override
|
||||
public Iterable<Waypoint> waypoints() {
|
||||
return waypoints;
|
||||
}
|
||||
/**
|
||||
* Returns the modifiable list of waypoints.
|
||||
*/
|
||||
@Override
|
||||
public Iterable<Waypoint> waypoints() {
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
private final class LinearWaypointEditor extends WaypointEditor {
|
||||
Conversation conversation;
|
||||
boolean editing = true;
|
||||
int editingSlot = waypoints.size() - 1;
|
||||
EntityMarkers<Waypoint> markers;
|
||||
private final Player player;
|
||||
private boolean showPath;
|
||||
private final class LinearWaypointEditor extends WaypointEditor {
|
||||
Conversation conversation;
|
||||
boolean editing = true;
|
||||
int editingSlot = waypoints.size() - 1;
|
||||
EntityMarkers<Waypoint> markers;
|
||||
private final Player player;
|
||||
private boolean showPath;
|
||||
|
||||
private LinearWaypointEditor(Player player) {
|
||||
this.player = player;
|
||||
this.markers = new EntityMarkers<Waypoint>();
|
||||
}
|
||||
private LinearWaypointEditor(Player player) {
|
||||
this.player = player;
|
||||
this.markers = new EntityMarkers<Waypoint>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_BEGIN);
|
||||
}
|
||||
@Override
|
||||
public void begin() {
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_BEGIN);
|
||||
}
|
||||
|
||||
private void clearWaypoints() {
|
||||
editingSlot = 0;
|
||||
waypoints.clear();
|
||||
onWaypointsModified();
|
||||
markers.destroyMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_WAYPOINTS_CLEARED);
|
||||
}
|
||||
private void clearWaypoints() {
|
||||
editingSlot = 0;
|
||||
waypoints.clear();
|
||||
onWaypointsModified();
|
||||
markers.destroyMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_WAYPOINTS_CLEARED);
|
||||
}
|
||||
|
||||
private void createWaypointMarkers() {
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
markers.createMarker(waypoints.get(i), waypoints.get(i).getLocation().clone().add(0, 1, 0));
|
||||
}
|
||||
}
|
||||
private void createWaypointMarkers() {
|
||||
for (int i = 0; i < waypoints.size(); i++) {
|
||||
markers.createMarker(waypoints.get(i), waypoints.get(i).getLocation().clone().add(0, 1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
if (!editing)
|
||||
return;
|
||||
if (conversation != null) {
|
||||
conversation.abandon();
|
||||
}
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_END);
|
||||
editing = false;
|
||||
if (!showPath)
|
||||
return;
|
||||
markers.destroyMarkers();
|
||||
}
|
||||
@Override
|
||||
public void end() {
|
||||
if (!editing)
|
||||
return;
|
||||
if (conversation != null) {
|
||||
conversation.abandon();
|
||||
}
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_END);
|
||||
editing = false;
|
||||
if (!showPath)
|
||||
return;
|
||||
markers.destroyMarkers();
|
||||
}
|
||||
|
||||
private String formatLoc(Location location) {
|
||||
return String.format("[[%d]], [[%d]], [[%d]]", location.getBlockX(), location.getBlockY(),
|
||||
location.getBlockZ());
|
||||
}
|
||||
private String formatLoc(Location location) {
|
||||
return String.format("[[%d]], [[%d]], [[%d]]", location.getBlockX(), location.getBlockY(),
|
||||
location.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Waypoint getCurrentWaypoint() {
|
||||
if (waypoints.size() == 0 || !editing) {
|
||||
return null;
|
||||
}
|
||||
normaliseEditingSlot();
|
||||
return waypoints.get(editingSlot);
|
||||
}
|
||||
@Override
|
||||
public Waypoint getCurrentWaypoint() {
|
||||
if (waypoints.size() == 0 || !editing) {
|
||||
return null;
|
||||
}
|
||||
normaliseEditingSlot();
|
||||
return waypoints.get(editingSlot);
|
||||
}
|
||||
|
||||
private Location getPreviousWaypoint(int fromSlot) {
|
||||
if (waypoints.size() <= 1)
|
||||
return null;
|
||||
if (--fromSlot < 0)
|
||||
fromSlot = waypoints.size() - 1;
|
||||
return waypoints.get(fromSlot).getLocation();
|
||||
}
|
||||
private Location getPreviousWaypoint(int fromSlot) {
|
||||
if (waypoints.size() <= 1)
|
||||
return null;
|
||||
if (--fromSlot < 0)
|
||||
fromSlot = waypoints.size() - 1;
|
||||
return waypoints.get(fromSlot).getLocation();
|
||||
}
|
||||
|
||||
private void normaliseEditingSlot() {
|
||||
editingSlot = Math.max(0, Math.min(waypoints.size() - 1, editingSlot));
|
||||
}
|
||||
private void normaliseEditingSlot() {
|
||||
editingSlot = Math.max(0, Math.min(waypoints.size() - 1, editingSlot));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNPCDespawn(NPCDespawnEvent event) {
|
||||
if (event.getNPC().equals(npc)) {
|
||||
Editor.leave(player);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onNPCDespawn(NPCDespawnEvent event) {
|
||||
if (event.getNPC().equals(npc)) {
|
||||
Editor.leave(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNPCRemove(NPCRemoveEvent event) {
|
||||
if (event.getNPC().equals(npc)) {
|
||||
Editor.leave(player);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onNPCRemove(NPCRemoveEvent event) {
|
||||
if (event.getNPC().equals(npc)) {
|
||||
Editor.leave(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (!event.getPlayer().equals(player))
|
||||
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);
|
||||
}
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("clear")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clearWaypoints();
|
||||
}
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("toggle path")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// we need to spawn entities on the main thread.
|
||||
togglePath();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (!event.getPlayer().equals(player))
|
||||
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);
|
||||
}
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("clear")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clearWaypoints();
|
||||
}
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("toggle path")) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// we need to spawn entities on the main thread.
|
||||
togglePath();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL || !npc.isSpawned()
|
||||
|| event.getPlayer().getWorld() != npc.getEntity().getWorld() || Util.isOffHand(event))
|
||||
return;
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (event.getClickedBlock() == null)
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
Location at = event.getClickedBlock().getLocation();
|
||||
Location prev = getPreviousWaypoint(editingSlot);
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL || !npc.isSpawned()
|
||||
|| event.getPlayer().getWorld() != npc.getEntity().getWorld() || Util.isOffHand(event))
|
||||
return;
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (event.getClickedBlock() == null)
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
Location at = event.getClickedBlock().getLocation();
|
||||
Location prev = getPreviousWaypoint(editingSlot);
|
||||
|
||||
if (prev != null && prev.getWorld() == at.getWorld()) {
|
||||
double distance = at.distanceSquared(prev);
|
||||
double maxDistance = Math.pow(npc.getNavigator().getDefaultParameters().range(), 2);
|
||||
if (distance > maxDistance) {
|
||||
Messaging.sendErrorTr(player, Messages.LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED,
|
||||
Math.sqrt(distance), Math.sqrt(maxDistance), ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (prev != null && prev.getWorld() == at.getWorld()) {
|
||||
double distance = at.distanceSquared(prev);
|
||||
double maxDistance = Math.pow(npc.getNavigator().getDefaultParameters().range(), 2);
|
||||
if (distance > maxDistance) {
|
||||
Messaging.sendErrorTr(player, Messages.LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED,
|
||||
Math.sqrt(distance), Math.sqrt(maxDistance), ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Waypoint element = new Waypoint(at);
|
||||
normaliseEditingSlot();
|
||||
waypoints.add(editingSlot, element);
|
||||
if (showPath) {
|
||||
markers.createMarker(element, element.getLocation().clone().add(0, 1, 0));
|
||||
}
|
||||
editingSlot = Math.min(editingSlot + 1, waypoints.size());
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), editingSlot + 1,
|
||||
waypoints.size());
|
||||
} else if (waypoints.size() > 0) {
|
||||
event.setCancelled(true);
|
||||
normaliseEditingSlot();
|
||||
Waypoint waypoint = waypoints.remove(editingSlot);
|
||||
if (showPath) {
|
||||
markers.removeMarker(waypoint);
|
||||
}
|
||||
editingSlot = Math.max(0, editingSlot - 1);
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size(),
|
||||
editingSlot + 1);
|
||||
}
|
||||
onWaypointsModified();
|
||||
}
|
||||
Waypoint element = new Waypoint(at);
|
||||
normaliseEditingSlot();
|
||||
waypoints.add(editingSlot, element);
|
||||
if (showPath) {
|
||||
markers.createMarker(element, element.getLocation().clone().add(0, 1, 0));
|
||||
}
|
||||
editingSlot = Math.min(editingSlot + 1, waypoints.size());
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), editingSlot + 1,
|
||||
waypoints.size());
|
||||
} else if (waypoints.size() > 0) {
|
||||
event.setCancelled(true);
|
||||
normaliseEditingSlot();
|
||||
Waypoint waypoint = waypoints.remove(editingSlot);
|
||||
if (showPath) {
|
||||
markers.removeMarker(waypoint);
|
||||
}
|
||||
editingSlot = Math.max(0, editingSlot - 1);
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size(),
|
||||
editingSlot + 1);
|
||||
}
|
||||
onWaypointsModified();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!player.equals(event.getPlayer()) || !showPath || Util.isOffHand(event))
|
||||
return;
|
||||
if (!event.getRightClicked().hasMetadata("waypointindex"))
|
||||
return;
|
||||
editingSlot = event.getRightClicked().getMetadata("waypointindex").get(0).asInt();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
|
||||
formatLoc(waypoints.get(editingSlot).getLocation()));
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!player.equals(event.getPlayer()) || !showPath || Util.isOffHand(event))
|
||||
return;
|
||||
if (!event.getRightClicked().hasMetadata("waypointindex"))
|
||||
return;
|
||||
editingSlot = event.getRightClicked().getMetadata("waypointindex").get(0).asInt();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
|
||||
formatLoc(waypoints.get(editingSlot).getLocation()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeldChange(PlayerItemHeldEvent event) {
|
||||
if (!event.getPlayer().equals(player) || waypoints.size() == 0)
|
||||
return;
|
||||
int previousSlot = event.getPreviousSlot(), newSlot = event.getNewSlot();
|
||||
// handle wrap-arounds
|
||||
if (previousSlot == 0 && newSlot == LARGEST_SLOT) {
|
||||
editingSlot--;
|
||||
} else if (previousSlot == LARGEST_SLOT && newSlot == 0) {
|
||||
editingSlot++;
|
||||
} else {
|
||||
int diff = newSlot - previousSlot;
|
||||
if (Math.abs(diff) != 1)
|
||||
return; // the player isn't scrolling
|
||||
editingSlot += diff > 0 ? 1 : -1;
|
||||
}
|
||||
normaliseEditingSlot();
|
||||
if (conversation != null) {
|
||||
getCurrentWaypoint().describeTriggers(player);
|
||||
}
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
|
||||
formatLoc(waypoints.get(editingSlot).getLocation()));
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerItemHeldChange(PlayerItemHeldEvent event) {
|
||||
if (!event.getPlayer().equals(player) || waypoints.size() == 0)
|
||||
return;
|
||||
int previousSlot = event.getPreviousSlot(), newSlot = event.getNewSlot();
|
||||
// handle wrap-arounds
|
||||
if (previousSlot == 0 && newSlot == LARGEST_SLOT) {
|
||||
editingSlot--;
|
||||
} else if (previousSlot == LARGEST_SLOT && newSlot == 0) {
|
||||
editingSlot++;
|
||||
} else {
|
||||
int diff = newSlot - previousSlot;
|
||||
if (Math.abs(diff) != 1)
|
||||
return; // the player isn't scrolling
|
||||
editingSlot += diff > 0 ? 1 : -1;
|
||||
}
|
||||
normaliseEditingSlot();
|
||||
if (conversation != null) {
|
||||
getCurrentWaypoint().describeTriggers(player);
|
||||
}
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
|
||||
formatLoc(waypoints.get(editingSlot).getLocation()));
|
||||
}
|
||||
|
||||
private void onWaypointsModified() {
|
||||
if (currentGoal != null) {
|
||||
currentGoal.onProviderChanged();
|
||||
}
|
||||
if (conversation != null) {
|
||||
getCurrentWaypoint().describeTriggers(player);
|
||||
}
|
||||
}
|
||||
private void onWaypointsModified() {
|
||||
if (currentGoal != null) {
|
||||
currentGoal.onProviderChanged();
|
||||
}
|
||||
if (conversation != null) {
|
||||
getCurrentWaypoint().describeTriggers(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void togglePath() {
|
||||
showPath = !showPath;
|
||||
if (showPath) {
|
||||
createWaypointMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS);
|
||||
} else {
|
||||
markers.destroyMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS);
|
||||
}
|
||||
}
|
||||
private void togglePath() {
|
||||
showPath = !showPath;
|
||||
if (showPath) {
|
||||
createWaypointMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS);
|
||||
} else {
|
||||
markers.destroyMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int LARGEST_SLOT = 8;
|
||||
}
|
||||
private static final int LARGEST_SLOT = 8;
|
||||
}
|
||||
|
||||
private class LinearWaypointGoal implements Goal {
|
||||
private final Location cachedLocation = new Location(null, 0, 0, 0);
|
||||
private Waypoint currentDestination;
|
||||
private Iterator<Waypoint> itr;
|
||||
private boolean paused;
|
||||
private GoalSelector selector;
|
||||
private class LinearWaypointGoal implements Goal {
|
||||
private final Location cachedLocation = new Location(null, 0, 0, 0);
|
||||
private Waypoint currentDestination;
|
||||
private Iterator<Waypoint> itr;
|
||||
private boolean paused;
|
||||
private GoalSelector selector;
|
||||
|
||||
private void ensureItr() {
|
||||
if (itr == null) {
|
||||
itr = getUnsafeIterator();
|
||||
} else if (!itr.hasNext()) {
|
||||
itr = getNewIterator();
|
||||
}
|
||||
}
|
||||
private void ensureItr() {
|
||||
if (itr == null) {
|
||||
itr = getUnsafeIterator();
|
||||
} else if (!itr.hasNext()) {
|
||||
itr = getNewIterator();
|
||||
}
|
||||
}
|
||||
|
||||
private Navigator getNavigator() {
|
||||
return npc.getNavigator();
|
||||
}
|
||||
private Navigator getNavigator() {
|
||||
return npc.getNavigator();
|
||||
}
|
||||
|
||||
private Iterator<Waypoint> getNewIterator() {
|
||||
LinearWaypointsCompleteEvent event = new LinearWaypointsCompleteEvent(LinearWaypointProvider.this,
|
||||
getUnsafeIterator());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
Iterator<Waypoint> next = event.getNextWaypoints();
|
||||
return next;
|
||||
}
|
||||
private Iterator<Waypoint> getNewIterator() {
|
||||
LinearWaypointsCompleteEvent event = new LinearWaypointsCompleteEvent(LinearWaypointProvider.this,
|
||||
getUnsafeIterator());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
Iterator<Waypoint> next = event.getNextWaypoints();
|
||||
return next;
|
||||
}
|
||||
|
||||
private Iterator<Waypoint> getUnsafeIterator() {
|
||||
return new Iterator<Waypoint>() {
|
||||
int idx = 0;
|
||||
private Iterator<Waypoint> getUnsafeIterator() {
|
||||
return new Iterator<Waypoint>() {
|
||||
int idx = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return idx < waypoints.size();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return idx < waypoints.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Waypoint next() {
|
||||
return waypoints.get(idx++);
|
||||
}
|
||||
@Override
|
||||
public Waypoint next() {
|
||||
return waypoints.get(idx++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
waypoints.remove(Math.max(0, idx - 1));
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
waypoints.remove(Math.max(0, idx - 1));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
public void onProviderChanged() {
|
||||
itr = getUnsafeIterator();
|
||||
if (currentDestination != null) {
|
||||
if (selector != null) {
|
||||
selector.finish();
|
||||
}
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onProviderChanged() {
|
||||
itr = getUnsafeIterator();
|
||||
if (currentDestination != null) {
|
||||
if (selector != null) {
|
||||
selector.finish();
|
||||
}
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
currentDestination = null;
|
||||
selector = null;
|
||||
}
|
||||
@Override
|
||||
public void reset() {
|
||||
currentDestination = null;
|
||||
selector = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GoalSelector selector) {
|
||||
if (!getNavigator().isNavigating()) {
|
||||
selector.finish();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run(GoalSelector selector) {
|
||||
if (!getNavigator().isNavigating()) {
|
||||
selector.finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPaused(boolean pause) {
|
||||
if (pause && currentDestination != null) {
|
||||
selector.finish();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
paused = pause;
|
||||
}
|
||||
public void setPaused(boolean pause) {
|
||||
if (pause && currentDestination != null) {
|
||||
selector.finish();
|
||||
if (npc != null && npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().cancelNavigation();
|
||||
}
|
||||
}
|
||||
paused = pause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute(final GoalSelector selector) {
|
||||
if (paused || currentDestination != null || !npc.isSpawned() || getNavigator().isNavigating()) {
|
||||
return false;
|
||||
}
|
||||
ensureItr();
|
||||
boolean shouldExecute = itr.hasNext();
|
||||
if (!shouldExecute) {
|
||||
return false;
|
||||
}
|
||||
this.selector = selector;
|
||||
Waypoint next = itr.next();
|
||||
Location npcLoc = npc.getEntity().getLocation(cachedLocation);
|
||||
if (npcLoc.getWorld() != next.getLocation().getWorld() || npcLoc.distanceSquared(next.getLocation()) < npc
|
||||
.getNavigator().getLocalParameters().distanceMargin()) {
|
||||
return false;
|
||||
}
|
||||
currentDestination = next;
|
||||
getNavigator().setTarget(currentDestination.getLocation());
|
||||
getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
|
||||
@Override
|
||||
public void onCompletion(@Nullable CancelReason cancelReason) {
|
||||
if (npc.isSpawned() && currentDestination != null
|
||||
&& Util.locationWithinRange(npc.getStoredLocation(), currentDestination.getLocation(), 2)) {
|
||||
currentDestination.onReach(npc);
|
||||
}
|
||||
selector.finish();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean shouldExecute(final GoalSelector selector) {
|
||||
if (paused || currentDestination != null || !npc.isSpawned() || getNavigator().isNavigating()) {
|
||||
return false;
|
||||
}
|
||||
ensureItr();
|
||||
boolean shouldExecute = itr.hasNext();
|
||||
if (!shouldExecute) {
|
||||
return false;
|
||||
}
|
||||
this.selector = selector;
|
||||
Waypoint next = itr.next();
|
||||
Location npcLoc = npc.getEntity().getLocation(cachedLocation);
|
||||
if (npcLoc.getWorld() != next.getLocation().getWorld() || npcLoc.distanceSquared(next.getLocation()) < npc
|
||||
.getNavigator().getLocalParameters().distanceMargin()) {
|
||||
return false;
|
||||
}
|
||||
currentDestination = next;
|
||||
getNavigator().setTarget(currentDestination.getLocation());
|
||||
getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
|
||||
@Override
|
||||
public void onCompletion(@Nullable CancelReason cancelReason) {
|
||||
if (npc.isSpawned() && currentDestination != null
|
||||
&& Util.locationWithinRange(npc.getStoredLocation(), currentDestination.getLocation(), 2)) {
|
||||
currentDestination.onReach(npc);
|
||||
}
|
||||
selector.finish();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,124 +20,125 @@ import net.citizensnpcs.util.StringHelper;
|
||||
|
||||
@TraitName("waypoints")
|
||||
public class Waypoints extends Trait {
|
||||
private WaypointProvider provider;
|
||||
private String providerName = "linear";
|
||||
private WaypointProvider provider;
|
||||
private String providerName = "linear";
|
||||
|
||||
public Waypoints() {
|
||||
super("waypoints");
|
||||
}
|
||||
public Waypoints() {
|
||||
super("waypoints");
|
||||
}
|
||||
|
||||
private WaypointProvider create(Class<? extends WaypointProvider> clazz) {
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private WaypointProvider create(Class<? extends WaypointProvider> clazz) {
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void onAttach() {
|
||||
provider = new LinearWaypointProvider(npc);
|
||||
}
|
||||
public void onAttach() {
|
||||
provider = new LinearWaypointProvider(npc);
|
||||
}
|
||||
|
||||
public void describeProviders(CommandSender sender) {
|
||||
Messaging.sendTr(sender, Messages.AVAILABLE_WAYPOINT_PROVIDERS);
|
||||
for (String name : PROVIDERS.keySet()) {
|
||||
Messaging.send(sender, " - " + StringHelper.wrap(name));
|
||||
}
|
||||
}
|
||||
public void describeProviders(CommandSender sender) {
|
||||
Messaging.sendTr(sender, Messages.AVAILABLE_WAYPOINT_PROVIDERS);
|
||||
for (String name : PROVIDERS.keySet()) {
|
||||
Messaging.send(sender, " - " + StringHelper.wrap(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link WaypointProvider}. May be null during
|
||||
* initialisation.
|
||||
*
|
||||
* @return The current provider
|
||||
*/
|
||||
public WaypointProvider getCurrentProvider() {
|
||||
return provider;
|
||||
}
|
||||
/**
|
||||
* Returns the current {@link WaypointProvider}. May be null during initialisation.
|
||||
*
|
||||
* @return The current provider
|
||||
*/
|
||||
public WaypointProvider getCurrentProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current provider name
|
||||
*/
|
||||
public String getCurrentProviderName() {
|
||||
return providerName;
|
||||
}
|
||||
/**
|
||||
* @return The current provider name
|
||||
*/
|
||||
public String getCurrentProviderName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
public Editor getEditor(CommandSender player, CommandContext args) {
|
||||
return provider.createEditor(player, args);
|
||||
}
|
||||
public Editor getEditor(CommandSender player, CommandContext args) {
|
||||
return provider.createEditor(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
provider = null;
|
||||
providerName = key.getString("provider", "linear");
|
||||
for (Entry<String, Class<? extends WaypointProvider>> entry : PROVIDERS.entrySet()) {
|
||||
if (entry.getKey().equals(providerName)) {
|
||||
provider = create(entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (provider == null)
|
||||
return;
|
||||
if (npc != null) {
|
||||
provider.onSpawn(npc);
|
||||
}
|
||||
PersistenceLoader.load(provider, key.getRelative(providerName));
|
||||
}
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
provider = null;
|
||||
providerName = key.getString("provider", "linear");
|
||||
for (Entry<String, Class<? extends WaypointProvider>> entry : PROVIDERS.entrySet()) {
|
||||
if (entry.getKey().equals(providerName)) {
|
||||
provider = create(entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (provider == null)
|
||||
return;
|
||||
if (npc != null) {
|
||||
provider.onSpawn(npc);
|
||||
}
|
||||
PersistenceLoader.load(provider, key.getRelative(providerName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (provider != null) {
|
||||
provider.onSpawn(getNPC());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (provider != null) {
|
||||
provider.onSpawn(getNPC());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
if (provider == null)
|
||||
return;
|
||||
PersistenceLoader.save(provider, key.getRelative(providerName));
|
||||
key.setString("provider", providerName);
|
||||
}
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
if (provider == null)
|
||||
return;
|
||||
PersistenceLoader.save(provider, key.getRelative(providerName));
|
||||
key.setString("provider", providerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current {@link WaypointProvider} using the given name.
|
||||
*
|
||||
* @param name The name of the waypoint provider, registered using
|
||||
* {@link #registerWaypointProvider(Class, String)}
|
||||
* @return Whether the operation succeeded
|
||||
*/
|
||||
public boolean setWaypointProvider(String name) {
|
||||
name = name.toLowerCase();
|
||||
Class<? extends WaypointProvider> clazz = PROVIDERS.get(name);
|
||||
if (provider != null) {
|
||||
provider.onRemove();
|
||||
}
|
||||
if (clazz == null || (provider = create(clazz)) == null)
|
||||
return false;
|
||||
providerName = name;
|
||||
if (npc != null && npc.isSpawned()) {
|
||||
provider.onSpawn(npc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Sets the current {@link WaypointProvider} using the given name.
|
||||
*
|
||||
* @param name
|
||||
* The name of the waypoint provider, registered using {@link #registerWaypointProvider(Class, String)}
|
||||
* @return Whether the operation succeeded
|
||||
*/
|
||||
public boolean setWaypointProvider(String name) {
|
||||
name = name.toLowerCase();
|
||||
Class<? extends WaypointProvider> clazz = PROVIDERS.get(name);
|
||||
if (provider != null) {
|
||||
provider.onRemove();
|
||||
}
|
||||
if (clazz == null || (provider = create(clazz)) == null)
|
||||
return false;
|
||||
providerName = name;
|
||||
if (npc != null && npc.isSpawned()) {
|
||||
provider.onSpawn(npc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link WaypointProvider}, which can be subsequently used by NPCs.
|
||||
*
|
||||
* @param clazz The class of the waypoint provider
|
||||
* @param name The name of the waypoint provider
|
||||
*/
|
||||
public static void registerWaypointProvider(Class<? extends WaypointProvider> clazz, String name) {
|
||||
PROVIDERS.put(name, clazz);
|
||||
}
|
||||
/**
|
||||
* Registers a {@link WaypointProvider}, which can be subsequently used by NPCs.
|
||||
*
|
||||
* @param clazz
|
||||
* The class of the waypoint provider
|
||||
* @param name
|
||||
* The name of the waypoint provider
|
||||
*/
|
||||
public static void registerWaypointProvider(Class<? extends WaypointProvider> clazz, String name) {
|
||||
PROVIDERS.put(name, clazz);
|
||||
}
|
||||
|
||||
private static final Map<String, Class<? extends WaypointProvider>> PROVIDERS = Maps.newHashMap();
|
||||
private static final Map<String, Class<? extends WaypointProvider>> PROVIDERS = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
PROVIDERS.put("linear", LinearWaypointProvider.class);
|
||||
PROVIDERS.put("wander", WanderWaypointProvider.class);
|
||||
PROVIDERS.put("guided", GuidedWaypointProvider.class);
|
||||
}
|
||||
static {
|
||||
PROVIDERS.put("linear", LinearWaypointProvider.class);
|
||||
PROVIDERS.put("wander", WanderWaypointProvider.class);
|
||||
PROVIDERS.put("guided", GuidedWaypointProvider.class);
|
||||
}
|
||||
}
|
@ -103,14 +103,14 @@ public class Util {
|
||||
// 1.8.8 compatibility
|
||||
return true;
|
||||
switch (type) {
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case WITHER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case WITHER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,8 @@ public class CreeperController extends MobEntityController {
|
||||
@Override
|
||||
protected boolean a(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack) {
|
||||
return npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)
|
||||
? super.a(entityhuman, enumhand, itemstack) : false;
|
||||
? super.a(entityhuman, enumhand, itemstack)
|
||||
: false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,8 +93,7 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user