mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-23 16:41:43 +01:00
Add --distance argument
This commit is contained in:
parent
a61befbdcc
commit
504a38317c
@ -1166,7 +1166,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "homeloc --location [loc] --delay [delay] -h(ere) -p(athfind) -t(eleport)",
|
||||
usage = "homeloc --location [loc] --delay [delay] --distance [distance] -h(ere) -p(athfind) -t(eleport)",
|
||||
desc = "Controls home location",
|
||||
modifiers = { "home" },
|
||||
min = 1,
|
||||
@ -1175,7 +1175,7 @@ public class NPCCommands {
|
||||
permission = "citizens.npc.home")
|
||||
@Requirements(ownership = true, selected = true)
|
||||
public void home(CommandContext args, CommandSender sender, NPC npc, @Flag("location") Location loc,
|
||||
@Flag("delay") Integer delay) throws CommandException {
|
||||
@Flag("delay") Integer delay, @Flag("distance") Double distance) throws CommandException {
|
||||
HomeTrait trait = npc.getOrAddTrait(HomeTrait.class);
|
||||
String output = "";
|
||||
if (args.hasFlag('h')) {
|
||||
@ -1186,22 +1186,27 @@ public class NPCCommands {
|
||||
}
|
||||
if (loc != null) {
|
||||
trait.setHomeLocation(loc);
|
||||
output += Messaging.tr(Messages.HOME_TRAIT_LOCATION_SET, Util.prettyPrintLocation(trait.getHomeLocation()));
|
||||
output += " "
|
||||
+ Messaging.tr(Messages.HOME_TRAIT_LOCATION_SET, Util.prettyPrintLocation(trait.getHomeLocation()));
|
||||
}
|
||||
if (distance != null) {
|
||||
trait.setDistanceBlocks(distance);
|
||||
output += " " + Messaging.tr(Messages.HOME_TRAIT_DISTANCE_SET, trait.getDistanceBlocks());
|
||||
}
|
||||
if (args.hasFlag('p')) {
|
||||
trait.setReturnStrategy(HomeTrait.ReturnStrategy.PATHFIND);
|
||||
output += Messaging.tr(Messages.HOME_TRAIT_PATHFIND_SET, npc.getName());
|
||||
output += " " + Messaging.tr(Messages.HOME_TRAIT_PATHFIND_SET, npc.getName());
|
||||
}
|
||||
if (args.hasFlag('t')) {
|
||||
trait.setReturnStrategy(HomeTrait.ReturnStrategy.TELEPORT);
|
||||
output += Messaging.tr(Messages.HOME_TRAIT_TELEPORT_SET, npc.getName());
|
||||
output += " " + Messaging.tr(Messages.HOME_TRAIT_TELEPORT_SET, npc.getName());
|
||||
}
|
||||
if (delay != null) {
|
||||
trait.setDelayTicks(delay);
|
||||
output += Messaging.tr(Messages.HOME_TRAIT_DELAY_SET, delay);
|
||||
output += " " + Messaging.tr(Messages.HOME_TRAIT_DELAY_SET, delay);
|
||||
}
|
||||
if (!output.isEmpty()) {
|
||||
Messaging.send(sender, output);
|
||||
Messaging.send(sender, output.trim());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ public class HomeTrait extends Trait {
|
||||
@Persist
|
||||
private int delay = -1;
|
||||
@Persist
|
||||
private double distance = -1;
|
||||
@Persist
|
||||
private Location location;
|
||||
@Persist
|
||||
private ReturnStrategy strategy = ReturnStrategy.TELEPORT;
|
||||
@ -25,6 +27,10 @@ public class HomeTrait extends Trait {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public double getDistanceBlocks() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public Location getHomeLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
@ -42,12 +48,14 @@ public class HomeTrait extends Trait {
|
||||
}
|
||||
t++;
|
||||
if (t > delay || delay == -1) {
|
||||
if (strategy == ReturnStrategy.TELEPORT) {
|
||||
npc.teleport(location, TeleportCause.PLUGIN);
|
||||
} else if (strategy == ReturnStrategy.PATHFIND) {
|
||||
npc.getNavigator().setTarget(location);
|
||||
npc.getNavigator().getLocalParameters().distanceMargin(0.9).pathDistanceMargin(0)
|
||||
.destinationTeleportMargin(1);
|
||||
if (distance == -1 || npc.getStoredLocation().distance(location) >= distance) {
|
||||
if (strategy == ReturnStrategy.TELEPORT) {
|
||||
npc.teleport(location, TeleportCause.PLUGIN);
|
||||
} else if (strategy == ReturnStrategy.PATHFIND) {
|
||||
npc.getNavigator().setTarget(location);
|
||||
npc.getNavigator().getLocalParameters().distanceMargin(0.9).pathDistanceMargin(0)
|
||||
.destinationTeleportMargin(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,6 +64,10 @@ public class HomeTrait extends Trait {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public void setDistanceBlocks(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public void setHomeLocation(Location location) {
|
||||
this.location = location.clone();
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ public class Messages {
|
||||
public static final String HOLOGRAM_TEXT_MISSING = "citizens.commands.npc.hologram.text-missing";
|
||||
public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed";
|
||||
public static final String HOME_TRAIT_DELAY_SET = "citizens.commands.npc.home.delay-set";
|
||||
public static final String HOME_TRAIT_DISTANCE_SET = "citizens.commands.npc.home.distance-set";
|
||||
public static final String HOME_TRAIT_LOCATION_SET = "citizens.commands.npc.home.home-set";
|
||||
public static final String HOME_TRAIT_PATHFIND_SET = "citizens.commands.npc.home.pathfind-set";
|
||||
public static final String HOME_TRAIT_TELEPORT_SET = "citizens.commands.npc.home.teleport-set";
|
||||
|
@ -126,6 +126,7 @@ citizens.commands.npc.hologram.direction-set=Direction set to [[{0}]].
|
||||
citizens.commands.npc.hologram.line-add=Added a new hologram line: [[{0}]].
|
||||
citizens.commands.npc.hologram.cleared=Hologram lines cleared.
|
||||
citizens.commands.npc.home.home-set=Home set to [[{0}]].
|
||||
citizens.commands.npc.home.distance-set=Distance before returning home set to [[{0}]] blocks.
|
||||
citizens.commands.npc.home.teleport-set=[[{0}]] will now teleport home.
|
||||
citizens.commands.npc.home.pathfind-set=[[{0}]] will now try to pathfind home.
|
||||
citizens.commands.npc.home.delay-set=Delay before returning home set to [[{0}]] ticks.
|
||||
|
Loading…
Reference in New Issue
Block a user