mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-28 15:17:43 +02:00
Rework /npc follow toggling
This commit is contained in:
parent
3bd406a742
commit
232f5247f1
@ -139,6 +139,9 @@ public class Settings {
|
|||||||
DEFAULT_STRAIGHT_LINE_TARGETING_DISTANCE(
|
DEFAULT_STRAIGHT_LINE_TARGETING_DISTANCE(
|
||||||
"The distance in blocks where the NPC will switch to walking straight towards the target instead of pathfinding<br>Currently only for dynamic targets like entities",
|
"The distance in blocks where the NPC will switch to walking straight towards the target instead of pathfinding<br>Currently only for dynamic targets like entities",
|
||||||
"npc.pathfinding.straight-line-targeting-distance", 5),
|
"npc.pathfinding.straight-line-targeting-distance", 5),
|
||||||
|
DEFAULT_STUCK_ACTION(
|
||||||
|
"The default action to perform when NPCs are unable to find a path or are stuck in the same block for too long. Supported options are: 'teleport to destination' or 'none'",
|
||||||
|
"npc.pathfinding.default-stuck-action", "teleport to destination"),
|
||||||
DEFAULT_TALK_CLOSE("npc.default.talk-close.enabled", false),
|
DEFAULT_TALK_CLOSE("npc.default.talk-close.enabled", false),
|
||||||
DEFAULT_TALK_CLOSE_RANGE("Default talk close range in blocks", "npc.default.talk-close.range", 5),
|
DEFAULT_TALK_CLOSE_RANGE("Default talk close range in blocks", "npc.default.talk-close.range", 5),
|
||||||
DEFAULT_TEXT("npc.default.talk-close.text.0", "Hi, I'm <npc>!") {
|
DEFAULT_TEXT("npc.default.talk-close.text.0", "Hi, I'm <npc>!") {
|
||||||
@ -168,7 +171,7 @@ public class Settings {
|
|||||||
"general.entity-spawn-wait-ticks", "general.wait-for-entity-spawn", "1s"),
|
"general.entity-spawn-wait-ticks", "general.wait-for-entity-spawn", "1s"),
|
||||||
ERROR_COLOUR("general.color-scheme.message-error", "<red>"),
|
ERROR_COLOUR("general.color-scheme.message-error", "<red>"),
|
||||||
FOLLOW_ACROSS_WORLDS("Whether /npc follow will teleport across worlds to follow its target",
|
FOLLOW_ACROSS_WORLDS("Whether /npc follow will teleport across worlds to follow its target",
|
||||||
"npc.follow.teleport-across-worlds", true),
|
"npc.follow.teleport-across-worlds", false),
|
||||||
HIGHLIGHT_COLOUR("general.color-scheme.message-highlight", "yellow"),
|
HIGHLIGHT_COLOUR("general.color-scheme.message-highlight", "yellow"),
|
||||||
HOLOGRAM_UPDATE_RATE("How often to update hologram names (including placeholders)",
|
HOLOGRAM_UPDATE_RATE("How often to update hologram names (including placeholders)",
|
||||||
"npc.hologram.update-rate-ticks", "npc.hologram.update-rate", "1s"),
|
"npc.hologram.update-rate-ticks", "npc.hologram.update-rate", "1s"),
|
||||||
@ -241,9 +244,6 @@ public class Settings {
|
|||||||
STORAGE_FILE("storage.file", "saves.yml"),
|
STORAGE_FILE("storage.file", "saves.yml"),
|
||||||
STORAGE_TYPE("Although technically Citizens can use NBT storage, it is not well tested and YAML is recommended",
|
STORAGE_TYPE("Although technically Citizens can use NBT storage, it is not well tested and YAML is recommended",
|
||||||
"storage.type", "yaml"),
|
"storage.type", "yaml"),
|
||||||
DEFAULT_STUCK_ACTION(
|
|
||||||
"The default action to perform when NPCs are unable to find a path or are stuck in the same block for too long. Supported options are: 'teleport to destination' or 'none'",
|
|
||||||
"npc.pathfinding.default-stuck-action", "teleport to destination"),
|
|
||||||
TABLIST_REMOVE_PACKET_DELAY("How long to wait before sending the tablist remove packet",
|
TABLIST_REMOVE_PACKET_DELAY("How long to wait before sending the tablist remove packet",
|
||||||
"npc.tablist.remove-packet-delay", "1t"),
|
"npc.tablist.remove-packet-delay", "1t"),
|
||||||
TALK_CLOSE_TO_NPCS("Whether to talk to NPCs (and therefore bystanders) as well as players",
|
TALK_CLOSE_TO_NPCS("Whether to talk to NPCs (and therefore bystanders) as well as players",
|
||||||
|
@ -959,6 +959,8 @@ public class NPCCommands {
|
|||||||
permission = "citizens.npc.follow")
|
permission = "citizens.npc.follow")
|
||||||
public void follow(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
public void follow(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||||
boolean protect = args.hasFlag('p');
|
boolean protect = args.hasFlag('p');
|
||||||
|
FollowTrait trait = npc.getOrAddTrait(FollowTrait.class);
|
||||||
|
trait.setProtect(protect);
|
||||||
String name = sender.getName();
|
String name = sender.getName();
|
||||||
if (args.argsLength() > 1) {
|
if (args.argsLength() > 1) {
|
||||||
name = args.getString(1);
|
name = args.getString(1);
|
||||||
@ -972,7 +974,8 @@ public class NPCCommands {
|
|||||||
if (!(sender instanceof ConsoleCommandSender)
|
if (!(sender instanceof ConsoleCommandSender)
|
||||||
&& !followingNPC.getOrAddTrait(Owner.class).isOwnedBy(sender))
|
&& !followingNPC.getOrAddTrait(Owner.class).isOwnedBy(sender))
|
||||||
throw new CommandException(CommandMessages.MUST_BE_OWNER);
|
throw new CommandException(CommandMessages.MUST_BE_OWNER);
|
||||||
boolean following = npc.getOrAddTrait(FollowTrait.class).toggle(followingNPC.getEntity(), protect);
|
boolean following = !trait.isEnabled();
|
||||||
|
trait.follow(following ? followingNPC.getEntity() : null);
|
||||||
Messaging.sendTr(sender, following ? Messages.FOLLOW_SET : Messages.FOLLOW_UNSET, npc.getName(),
|
Messaging.sendTr(sender, following ? Messages.FOLLOW_SET : Messages.FOLLOW_UNSET, npc.getName(),
|
||||||
followingNPC.getName());
|
followingNPC.getName());
|
||||||
};
|
};
|
||||||
@ -980,7 +983,8 @@ public class NPCCommands {
|
|||||||
args.getString(1));
|
args.getString(1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean following = npc.getOrAddTrait(FollowTrait.class).toggle(player.getPlayer(), protect);
|
boolean following = !trait.isEnabled();
|
||||||
|
trait.follow(following ? player.getPlayer() : null);
|
||||||
Messaging.sendTr(sender, following ? Messages.FOLLOW_SET : Messages.FOLLOW_UNSET, npc.getName(),
|
Messaging.sendTr(sender, following ? Messages.FOLLOW_SET : Messages.FOLLOW_UNSET, npc.getName(),
|
||||||
player.getName());
|
player.getName());
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,18 @@ public class FollowTrait extends Trait {
|
|||||||
super("followtrait");
|
super("followtrait");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link Entity} to follow
|
||||||
|
*/
|
||||||
|
public void follow(Entity entity) {
|
||||||
|
this.followingUUID = entity == null ? null : entity.getUniqueId();
|
||||||
|
if (npc.getNavigator().isNavigating() && this.entity != null && npc.getNavigator().getEntityTarget() != null
|
||||||
|
&& this.entity == npc.getNavigator().getEntityTarget().getTarget()) {
|
||||||
|
npc.getNavigator().cancelNavigation();
|
||||||
|
}
|
||||||
|
this.entity = null;
|
||||||
|
}
|
||||||
|
|
||||||
public Entity getFollowing() {
|
public Entity getFollowing() {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@ -103,25 +115,9 @@ public class FollowTrait extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles and/or sets the {@link Entity} to follow and whether to protect them (similar to wolves in Minecraft,
|
* Sets whether to protect the followed Entity (similar to wolves in Minecraft, attack whoever attacks the entity).
|
||||||
* attack whoever attacks the entity).
|
|
||||||
*
|
|
||||||
* Will toggle if the {@link Entity} is the entity currently being followed.
|
|
||||||
*
|
|
||||||
* @param entity
|
|
||||||
* the player to follow
|
|
||||||
* @param protect
|
|
||||||
* whether to protect the player
|
|
||||||
* @return whether the trait is enabled
|
|
||||||
*/
|
*/
|
||||||
public boolean toggle(Entity entity, boolean protect) {
|
public void setProtect(boolean protect) {
|
||||||
this.protect = protect;
|
this.protect = protect;
|
||||||
this.followingUUID = entity.getUniqueId().equals(followingUUID) ? null : entity.getUniqueId();
|
|
||||||
if (npc.getNavigator().isNavigating() && this.entity != null && npc.getNavigator().getEntityTarget() != null
|
|
||||||
&& this.entity == npc.getNavigator().getEntityTarget().getTarget()) {
|
|
||||||
npc.getNavigator().cancelNavigation();
|
|
||||||
}
|
|
||||||
this.entity = null;
|
|
||||||
return followingUUID != null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user