Clear sleeping status on despawn, add some messages in /npc hurt for non-damageable entities

This commit is contained in:
fullwall 2022-11-12 21:51:15 +08:00
parent 85dd78e582
commit 06b1568e07
4 changed files with 19 additions and 1 deletions

View File

@ -1114,7 +1114,16 @@ public class NPCCommands {
min = 2,
max = 2,
permission = "citizens.npc.hurt")
public void hurt(CommandContext args, Player sender, NPC npc) {
public void hurt(CommandContext args, CommandSender sender, NPC npc) {
if (!(npc.getEntity() instanceof Damageable)) {
Messaging.sendErrorTr(sender, Messages.NPC_NOT_DAMAGEABLE,
Util.prettyEnum(npc.getOrAddTrait(MobType.class).getType()));
return;
}
if (npc.isProtected()) {
Messaging.sendErrorTr(sender, Messages.NPC_PROTECTED);
return;
}
((Damageable) npc.getEntity()).damage(args.getInteger(1));
}

View File

@ -21,6 +21,11 @@ public class SleepTrait extends Trait {
super("sleeptrait");
}
@Override
public void onDespawn() {
sleeping = false;
}
@Override
public void run() {
if (!npc.isSpawned())

View File

@ -249,8 +249,10 @@ public class Messages {
public static final String NPC_GOAT_HORNS_SET = "citizens.commands.npc.goat.horns-set";
public static final String NPC_NAME_TOO_LONG = "citizens.commands.npc.create.npc-name-too-long";
public static final String NPC_NOT_CONTROLLABLE = "citizens.commands.npc.controllable.not-controllable";
public static final String NPC_NOT_DAMAGEABLE = "citizens.commands.npc.hurt.not-damageable";
public static final String NPC_NOT_FOUND = "citizens.notifications.npc-not-found";
public static final String NPC_OWNER = "citizens.commands.npc.owner.owner";
public static final String NPC_PROTECTED = "citizens.commands.npc.hurt.protected";
public static final String NPC_REMOVED = "citizens.commands.npc.remove.removed";
public static final String NPC_RENAMED = "citizens.commands.npc.rename.renamed";
public static final String NPC_SPAWNED = "citizens.commands.npc.spawn.spawned";

View File

@ -129,6 +129,8 @@ citizens.commands.npc.horse.describe=The horse''s color is [[{0}]], the type is
citizens.commands.npc.horse.invalid-color=Invalid horse color given. Valid colors are: [[{0}]].
citizens.commands.npc.horse.invalid-type=Invalid horse type given. Valid types are: [[{0}]].
citizens.commands.npc.horse.invalid-style=Invalid horse style given. Valid styles are: [[{0}]].
citizens.commands.npc.hurt.not-damageable=NPC type [[{0}]] cannot be hurt.
citizens.commands.npc.hurt.protected=NPC is protected and cannot be hurt. <click:run_command:/npc vulnerable>[[Click to unprotect</click>
citizens.commands.npc.item.item-set=NPC item set to [[{0}]].
citizens.commands.npc.item.unknown-material=Unknown material given.
citizens.commands.npc.leashable.set=[[{0}]] is now leashable.