Add /npc chunkload

This commit is contained in:
fullwall 2021-05-07 01:46:59 +08:00
parent c24ce1e1ed
commit 3d85ad4ea8
4 changed files with 20 additions and 1 deletions

View File

@ -302,6 +302,21 @@ public class NPCCommands {
}
}
@Command(
aliases = { "npc" },
usage = "chunkload",
desc = "Toggle the NPC forcing chunks to stay loaded",
modifiers = { "chunkload", "cload" },
min = 1,
max = 1,
permission = "citizens.npc.chunkload")
@Requirements(selected = true, ownership = true)
public void chunkload(CommandContext args, CommandSender sender, NPC npc) {
boolean enabled = !npc.data().get(NPC.KEEP_CHUNK_LOADED_METADATA, Setting.KEEP_CHUNKS_LOADED.asBoolean());
npc.data().set(NPC.KEEP_CHUNK_LOADED_METADATA, enabled);
Messaging.sendTr(sender, enabled ? Messages.CHUNKLOAD_SET : Messages.CHUNKLOAD_UNSET, npc.getName());
}
@Command(
aliases = { "npc" },
usage = "collidable",

View File

@ -74,7 +74,7 @@ public class CitizensNPC extends AbstractNPC {
}
NPCDespawnEvent event = new NPCDespawnEvent(this, reason);
if (reason == DespawnReason.CHUNK_UNLOAD) {
event.setCancelled(Setting.KEEP_CHUNKS_LOADED.asBoolean());
event.setCancelled(data().get(NPC.KEEP_CHUNK_LOADED_METADATA, Setting.KEEP_CHUNKS_LOADED.asBoolean()));
}
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled() && reason != DespawnReason.DEATH) {

View File

@ -36,6 +36,8 @@ public class Messages {
public static final String CHAT_TRIGGER_MESSAGE_ADDED = "citizens.editors.waypoints.triggers.chat.message-added";
public static final String CHAT_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.chat.prompt";
public static final String CHAT_TRIGGER_RADIUS_SET = "citizens.editors.waypoints.triggers.chat.radius-set";
public static final String CHUNKLOAD_SET = "citizens.commands.npc.chunkload.set";
public static final String CHUNKLOAD_UNSET = "citizens.commands.npc.chunkload.unset";
public static final String CITIZENS_IMPLEMENTATION_DISABLED = "citizens.changed-implementation";
public static final String CITIZENS_INCOMPATIBLE = "citizens.notifications.incompatible-version";
public static final String CITIZENS_INVALID_COMMAND_CLASS = "citizens.commands.invalid.class";

View File

@ -41,6 +41,8 @@ citizens.commands.npc.cat.sitting-stop=[[{0}]] stopped sitting.
citizens.commands.npc.cat.lying-start=[[{0}]] started lying down.
citizens.commands.npc.cat.lying-stop=[[{0}]] stopped lying down.
citizens.commands.npc.cat.type-set=Type set to [[{0}]].
citizens.commands.npc.chunkload.set=[[{0}]] will now force chunks to be loaded.
citizens.commands.npc.chunkload.unset=[[{0}]] will no longer force chunks to be loaded.
citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities.
citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities.
citizens.commands.npc.command.none-added=No commands have been added.