Skip to content

Commit

Permalink
Add /npc chunkload
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 6, 2021
1 parent c24ce1e commit 3d85ad4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -302,6 +302,21 @@ public void armorstand(CommandContext args, CommandSender sender, NPC npc) throw
}
}

@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",
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Expand Up @@ -74,7 +74,7 @@ public boolean despawn(DespawnReason reason) {
}
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) {
Expand Down
2 changes: 2 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions main/src/main/resources/messages_en.properties
Expand Up @@ -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.
Expand Down

0 comments on commit 3d85ad4

Please sign in to comment.