mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-15 12:41:20 +01:00
Implement /npc respawn command
This commit is contained in:
parent
e1e05c6728
commit
99c32d932f
@ -186,17 +186,31 @@ public class EventListen implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
NPC npc = npcRegistry.getNPC(event.getEntity());
|
||||
final NPC npc = npcRegistry.getNPC(event.getEntity());
|
||||
if (npc == null)
|
||||
return;
|
||||
Bukkit.getPluginManager().callEvent(new NPCDeathEvent(npc, event));
|
||||
final Location location = npc.getBukkitEntity().getLocation();
|
||||
npc.despawn(DespawnReason.DEATH);
|
||||
|
||||
if (npc.data().get(NPC.RESPAWN_DELAY_METADATA, -1) >= 0) {
|
||||
int delay = npc.data().get(NPC.RESPAWN_DELAY_METADATA, -1);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!npc.isSpawned()) {
|
||||
npc.spawn(location);
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntitySpawn(CreatureSpawnEvent event) {
|
||||
if (event.isCancelled() && npcRegistry.isNPC(event.getEntity()))
|
||||
if (event.isCancelled() && npcRegistry.isNPC(event.getEntity())) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -930,6 +930,25 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, Messages.NPC_RENAMED, oldName, newName);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "respawn [delay in ticks]",
|
||||
desc = "Sets an NPC's respawn delay in ticks",
|
||||
modifiers = { "respawn" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "citizens.npc.respawn")
|
||||
public void respawn(CommandContext args, CommandSender sender, NPC npc) {
|
||||
if (args.argsLength() > 1) {
|
||||
int delay = args.getInteger(1);
|
||||
npc.data().setPersistent(NPC.RESPAWN_DELAY_METADATA, delay);
|
||||
Messaging.sendTr(sender, Messages.RESPAWN_DELAY_SET, delay);
|
||||
} else {
|
||||
Messaging.sendTr(sender, Messages.RESPAWN_DELAY_DESCRIBE, npc.data().get(NPC.RESPAWN_DELAY_METADATA, -1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "select|sel [id|name] (--r range)",
|
||||
|
@ -92,10 +92,12 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
public void run() {
|
||||
if (!enabled || !npc.isSpawned() || npc.getNavigator().isNavigating())
|
||||
return;
|
||||
if (hasInvalidTarget())
|
||||
if (hasInvalidTarget()) {
|
||||
findNewTarget();
|
||||
if (lookingAt != null && canSeeTarget())
|
||||
}
|
||||
if (lookingAt != null && canSeeTarget()) {
|
||||
Util.faceEntity(npc.getBukkitEntity(), lookingAt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,6 +155,8 @@ public class Messages {
|
||||
public static final String REMOVE_INCORRECT_SYNTAX = "citizens.commands.npc.remove.incorrect-syntax";
|
||||
public static final String REMOVED_ALL_NPCS = "citizens.commands.npc.remove.removed-all";
|
||||
public static final String REMOVED_FROM_PLAYERLIST = "citizens.commands.npc.playerlist.removed";
|
||||
public static final String RESPAWN_DELAY_DESCRIBE = "citizens.commands.npc.respawn.describe";
|
||||
public static final String RESPAWN_DELAY_SET = "citizens.commands.npc.respawn.delay-set";
|
||||
public static final String SADDLED_SET = "citizens.editors.equipment.saddled-set";
|
||||
public static final String SADDLED_STOPPED = "citizens.editors.equipment.saddled-stopped";
|
||||
public static final String SCRIPT_COMPILED = "citizens.commands.script.compiled";
|
||||
|
@ -152,7 +152,7 @@ public class NMS {
|
||||
return DEFAULT_SPEED;
|
||||
// this is correct, but too slow. TODO: investigate
|
||||
// return (float)
|
||||
// NMS.getHandle(npc.getBukkitEntity()).a(GenericAttributes.d).b();
|
||||
// NMS.getHandle(npc.getBukkitEntity()).getAttributeInstance(GenericAttributes.d).getValue();
|
||||
return DEFAULT_SPEED;
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,8 @@ citizens.commands.npc.remove.incorrect-syntax=Incorrect syntax. /npc remove (all
|
||||
citizens.commands.npc.remove.removed-all=You permanently removed all NPCs.
|
||||
citizens.commands.npc.remove.removed=You permanently removed [[{0}]].
|
||||
citizens.commands.npc.rename.renamed=You renamed [[{0}]] to [[{1}]].
|
||||
citizens.commands.npc.respawn.delay-set=Respawn delay set to [[{0}]].
|
||||
citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]].
|
||||
citizens.commands.npc.select.already-selected=You already have that NPC selected.
|
||||
citizens.commands.npc.size.description={0}''s size is [[{1}]].
|
||||
citizens.commands.npc.size.set={0}''s size set to [[{1}]].
|
||||
|
Loading…
Reference in New Issue
Block a user