From 4d1b3ee357adc789b6bb40f6580ad1a0ddfe6f53 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 11 Feb 2024 01:13:49 +0800 Subject: [PATCH] Remove STORAGE_TYPE setting, fix a few setting comments --- .../main/java/net/citizensnpcs/Citizens.java | 13 ++---------- .../main/java/net/citizensnpcs/Settings.java | 21 +++++++++---------- .../citizensnpcs/commands/NPCCommands.java | 7 +++++-- .../net/citizensnpcs/npc/CitizensNPC.java | 8 ++++--- .../net/citizensnpcs/trait/SneakTrait.java | 9 -------- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/Citizens.java b/main/src/main/java/net/citizensnpcs/Citizens.java index 5791873e4..6cc7925ac 100644 --- a/main/src/main/java/net/citizensnpcs/Citizens.java +++ b/main/src/main/java/net/citizensnpcs/Citizens.java @@ -60,7 +60,6 @@ import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitFactory; import net.citizensnpcs.api.trait.TraitInfo; import net.citizensnpcs.api.util.Messaging; -import net.citizensnpcs.api.util.NBTStorage; import net.citizensnpcs.api.util.Placeholders; import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.api.util.Storage; @@ -177,14 +176,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } private NPCDataStore createStorage(File folder) { - Storage saves = null; - String type = Setting.STORAGE_TYPE.asString(); - if (type.equalsIgnoreCase("nbt")) { - saves = new NBTStorage(new File(folder, Setting.STORAGE_FILE.asString()), "Citizens NPC Storage"); - } - if (saves == null) { - saves = new YamlStorage(new File(folder, Setting.STORAGE_FILE.asString()), "Citizens NPC Storage"); - } + Storage saves = new YamlStorage(new File(folder, Setting.STORAGE_FILE.asString()), "Citizens NPC Storage"); if (!saves.load()) return null; @@ -548,7 +540,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { return 0; return Iterables.size(npcRegistry); })); - metrics.addCustomChart(new Metrics.SimplePie("storage_type", () -> Setting.STORAGE_TYPE.asString())); metrics.addCustomChart(new Metrics.SingleLineChart("using_templates", () -> Math.min(1, Iterables.size(Template.getTemplates())))); metrics.addCustomChart(new Metrics.SimplePie("locale", () -> Locale.getDefault().getLanguage())); @@ -613,7 +604,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { Messaging.logTr(Messages.NUM_LOADED_NOTIFICATION, Iterables.size(npcRegistry), "?"); startMetrics(); - scheduleSaveTask(Setting.SAVE_TASK_DELAY.asTicks()); + scheduleSaveTask(Setting.SAVE_TASK_FREQUENCY.asTicks()); Bukkit.getPluginManager().callEvent(new CitizensEnableEvent()); new PlayerUpdateTask().runTaskTimer(Citizens.this, 0, 1); enabled = true; diff --git a/main/src/main/java/net/citizensnpcs/Settings.java b/main/src/main/java/net/citizensnpcs/Settings.java index 97781235d..a4d2d0620 100644 --- a/main/src/main/java/net/citizensnpcs/Settings.java +++ b/main/src/main/java/net/citizensnpcs/Settings.java @@ -140,7 +140,7 @@ public class Settings { "The distance in blocks where the NPC will switch to walking straight towards the target instead of pathfinding
Currently only for dynamic targets like entities", "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'", + "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", "none"), 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), @@ -167,7 +167,7 @@ public class Settings { "npc.pathfinding.disable-mc-fallback-navigation", true), DISABLE_TABLIST("Whether to remove NPCs from the tablist", "npc.tablist.disable", true), DISPLAY_ENTITY_HOLOGRAMS( - "Whether to use display entities for holograms by default. In theory more performant than armor stands. Requires 1.19.4 or above. Defaults to false", + "Whether to use display entities for holograms by default (in theory more performant than armor stands)
Requires 1.19.4 or above, defaults to false", "npc.hologram.use-display-entities", false), ENTITY_SPAWN_WAIT_DURATION( "Entities are no longer spawned until the chunks are loaded from disk
Wait for chunk loading for one second by default, increase if your disk is slow", @@ -176,7 +176,7 @@ public class Settings { FOLLOW_ACROSS_WORLDS("Whether /npc follow will teleport across worlds to follow its target", "npc.follow.teleport-across-worlds", false), HIGHLIGHT_COLOUR("general.color-scheme.message-highlight", "yellow"), - HOLOGRAM_ALWAYS_UPDATE_POSITION("Whether to always update the hologram position every tick.", + HOLOGRAM_ALWAYS_UPDATE_POSITION("Whether to always update the hologram position every tick", "npc.hologram.always-update-position", false), HOLOGRAM_UPDATE_RATE("How often to update hologram names (including placeholders)", "npc.hologram.update-rate-ticks", "npc.hologram.update-rate", "1s"), @@ -184,7 +184,7 @@ public class Settings { INITIAL_PLAYER_JOIN_SKIN_PACKET_DELAY("How long to wait before sending skins to joined players", "npc.skins.player-join-update-delay-ticks", "npc.skins.player-join-update-delay", "1s"), KEEP_CHUNKS_LOADED("Whether to keep NPC chunks loaded", "npc.chunks.always-keep-loaded", false), - LOCALE("Controls translation files - defaults to your system language, set to en if English required", + LOCALE("Controls translation files - defaults to your system language, set to 'en' if English required", "general.translation.locale", ""), MAX_CONTROLLABLE_FLIGHT_SPEED( "The maximum flying speed that controllable NPCs can reach, in Minecraft velocity units", @@ -228,7 +228,7 @@ public class Settings { "Please wait for {minutes} minutes and {seconds_over} seconds."), NPC_COST("The default cost to create an NPC", "economy.npc.cost", 100D), NPC_SKIN_FETCH_DEFAULT( - "Whether to try and look for the player skin for all new NPCs. If this is set to false and you create an NPC named Dinnerbone, the NPC will have the default (steve/alex/...) skin rather than trying to fetch the Dinnerbone skin.", + "Whether to try and look for the player skin for all new NPCs
If this is set to false and you create an NPC named Dinnerbone, the NPC will have the default (steve/alex/etc) skin rather than trying to fetch the Dinnerbone skin", "npc.skins.try-fetch-default-skin", true), NPC_SKIN_RETRY_DELAY("How long before retrying skin requests (typically due to Mojang rate limiting)", "npc.skins.retry-delay", "5s"), @@ -248,20 +248,19 @@ public class Settings { REMOVE_PLAYERS_FROM_PLAYER_LIST("Whether to remove NPCs from the Java list of players", "npc.player.remove-from-list", true), RESET_YAW_ON_SPAWN( - "Whether to reset NPC yaw on spawn. Currently this is implemented by an arm swing animation due to Minecraft limitations.", + "Whether to reset NPC yaw on spawn
Currently this is implemented by an arm swing animation due to Minecraft limitations", "npc.default.reset-yaw-on-spawn", true), RESOURCE_PACK_PATH("The resource pack path to save resource packs to", "general.resource-pack-path", "plugins/Citizens/resourcepack"), - SAVE_TASK_DELAY("How often to save NPCs to disk", "storage.save-task.delay", "1hr"), + SAVE_TASK_FREQUENCY("How often to save NPCs to disk", "storage.save-task.delay", "storage.save-task-frequency", + "1hr"), SELECTION_ITEM("The default item in hand to select an NPC", "npc.selection.item", "stick"), SELECTION_MESSAGE("npc.selection.message", "Selected [[]] (ID [[]])."), SERVER_OWNS_NPCS("Whether the server owns NPCs rather than individual players", "npc.server-ownership", false), SHOP_GLOBAL_VIEW_PERMISSION( - "The global view permission that players need to view any NPC shop. Defaults to empty (no permission required).", + "The global view permission that players need to view any NPC shop
Defaults to empty (no permission required).", "npc.shops.global-view-permission", ""), 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", "yaml"), TABLIST_REMOVE_PACKET_DELAY("How long to wait before sending the tablist remove packet", "npc.tablist.remove-packet-delay", "1t"), TALK_CLOSE_TO_NPCS("Whether to talk to NPCs (and therefore bystanders) as well as players", @@ -270,7 +269,7 @@ public class Settings { USE_BOAT_CONTROLS("Whether to change vehicle direction with movement instead of strafe controls", "npc.controllable.use-boat-controls", true), USE_NEW_PATHFINDER( - "Whether to use the Citizens pathfinder instead of the Minecraft pathfinder
Much more flexible, but may have different performance characteristics", + "Whether to use the Citizens pathfinder instead of the Minecraft pathfinder
Much more flexible, but may have different performance to Minecraft's pathfinder", "npc.pathfinding.use-new-finder", false), USE_SCOREBOARD_TEAMS("npc.scoreboard-teams.enable", true), WARN_ON_RELOAD("general.reload-warning-enabled", true),; diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 13d7b019c..a9c34bea8 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -339,7 +339,7 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "armorstand --visible [visible] --small [small] --gravity [gravity] --arms [arms] --baseplate [baseplate] --(body|leftarm|leftleg|rightarm|rightleg)pose [angle x,y,z]", + usage = "armorstand --visible [visible] --small [small] --marker [marker] --gravity [gravity] --arms [arms] --baseplate [baseplate] --(body|leftarm|leftleg|rightarm|rightleg)pose [angle x,y,z]", desc = "Edit armorstand properties", modifiers = { "armorstand" }, min = 1, @@ -349,7 +349,7 @@ public class NPCCommands { @Requirements(selected = true, ownership = true, types = EntityType.ARMOR_STAND) public void armorstand(CommandContext args, CommandSender sender, NPC npc, @Flag("visible") Boolean visible, @Flag("small") Boolean small, @Flag("gravity") Boolean gravity, @Flag("arms") Boolean arms, - @Flag("baseplate") Boolean baseplate) throws CommandException { + @Flag("marker") Boolean marker, @Flag("baseplate") Boolean baseplate) throws CommandException { ArmorStandTrait trait = npc.getOrAddTrait(ArmorStandTrait.class); if (visible != null) { trait.setVisible(visible); @@ -360,6 +360,9 @@ public class NPCCommands { if (gravity != null) { trait.setGravity(gravity); } + if (marker != null) { + trait.setMarker(marker); + } if (arms != null) { trait.setHasArms(arms); } diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index cefb23394..9aac7aa3b 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -275,6 +275,11 @@ public class CitizensNPC extends AbstractNPC { } } + @Override + public void setSneaking(boolean sneaking) { + getOrAddTrait(SneakTrait.class).setSneaking(sneaking); + } + @Override public boolean spawn(Location at) { return spawn(at, SpawnReason.PLUGIN); @@ -532,9 +537,6 @@ public class CitizensNPC extends AbstractNPC { } if (getEntity() instanceof Player) { updateUsingItemState((Player) getEntity()); - if (data().has(NPC.Metadata.SNEAKING) && !hasTrait(SneakTrait.class)) { - addTrait(SneakTrait.class); - } } } navigator.run(); diff --git a/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java b/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java index ccb727e81..05d53d9b8 100644 --- a/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java @@ -1,6 +1,5 @@ package net.citizensnpcs.trait; -import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; @@ -30,14 +29,6 @@ public class SneakTrait extends Trait { apply(); } - @Override - public void run() { - if (npc.data().has(NPC.Metadata.SNEAKING)) { - setSneaking(npc.data().get(NPC.Metadata.SNEAKING)); - npc.data().remove(NPC.Metadata.SNEAKING); - } - } - public void setSneaking(boolean sneak) { sneaking = sneak; apply();