From b4c4386fe40a8400f0fabc793e77bebda0649600 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Sun, 14 Dec 2025 18:35:30 +0100 Subject: [PATCH] allow editing mannequin description --- .../ArmorStandToMannequinConverter.java | 2 + .../MannequinToArmorStandConverter.java | 6 +++ .../standin/entity/MannequinHandler.java | 37 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/main/java/me/youhavetrouble/standin/converter/ArmorStandToMannequinConverter.java b/src/main/java/me/youhavetrouble/standin/converter/ArmorStandToMannequinConverter.java index 34c0dcb..77ec726 100644 --- a/src/main/java/me/youhavetrouble/standin/converter/ArmorStandToMannequinConverter.java +++ b/src/main/java/me/youhavetrouble/standin/converter/ArmorStandToMannequinConverter.java @@ -2,6 +2,7 @@ package me.youhavetrouble.standin.converter; import io.papermc.paper.datacomponent.item.ResolvableProfile; import me.youhavetrouble.standin.StandIn; +import me.youhavetrouble.standin.entity.MannequinHandler; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Mannequin; @@ -29,6 +30,7 @@ public class ArmorStandToMannequinConverter implements EntityConverter { markAsTransformed(mannequin); EntityConverter.saveRawEntityName(mannequin, EntityConverter.getRawEntityName(from)); + MannequinHandler.saveRawDescription(mannequin, MannequinHandler.getRawDescription(from)); mannequin.customName(from.customName()); mannequin.setImmovable(!from.canMove()); mannequin.setGravity(from.hasGravity()); diff --git a/src/main/java/me/youhavetrouble/standin/converter/MannequinToArmorStandConverter.java b/src/main/java/me/youhavetrouble/standin/converter/MannequinToArmorStandConverter.java index f822984..821b8d4 100644 --- a/src/main/java/me/youhavetrouble/standin/converter/MannequinToArmorStandConverter.java +++ b/src/main/java/me/youhavetrouble/standin/converter/MannequinToArmorStandConverter.java @@ -1,6 +1,8 @@ package me.youhavetrouble.standin.converter; import me.youhavetrouble.standin.StandIn; +import me.youhavetrouble.standin.entity.ArmorStandHandler; +import me.youhavetrouble.standin.entity.MannequinHandler; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.entity.Mannequin; @@ -42,6 +44,10 @@ public class MannequinToArmorStandConverter implements EntityConverter { + public static final NamespacedKey DESCRIPTION_KEY = new NamespacedKey("standin", "mannequin_description"); + public MannequinHandler() { super(Mannequin.class); addConverter(new MannequinToArmorStandConverter()); @@ -52,6 +57,18 @@ public class MannequinHandler extends EntityHandler { .maxLength(1024) .build() ); + + String description = getRawDescription(mannequin); + if (description == null) { + description = ""; + } + inputs.add( + DialogInput.text("description", Component.text("Description")) + .initial(description) + .maxLength(1024) + .build() + ); + String profileName = ""; if (mannequin.getProfile().name() != null) { profileName = mannequin.getProfile().name(); @@ -104,6 +121,14 @@ public class MannequinHandler extends EntityHandler { mann.customName(null); } EntityConverter.saveRawEntityName(mann, newName); + String newDescription = view.getText("description"); + if (newDescription != null && !newDescription.isBlank()) { + mann.setDescription(MiniMessage.miniMessage().deserialize(newDescription)); + } else { + mann.setDescription(null); + } + saveRawDescription(mann, newDescription); + mann.setImmovable(Boolean.TRUE.equals(view.getBoolean("immovable"))); mann.setVelocity(mann.getVelocity().zero()); mann.setGravity(Boolean.TRUE.equals(view.getBoolean("gravity"))); @@ -160,4 +185,16 @@ public class MannequinHandler extends EntityHandler { ); } + public static String getRawDescription(@NotNull Entity entity) { + return entity.getPersistentDataContainer().get(DESCRIPTION_KEY, PersistentDataType.STRING); + } + + public static void saveRawDescription(@NotNull Mannequin mannequin, @Nullable String description) { + if (description == null) { + mannequin.getPersistentDataContainer().remove(DESCRIPTION_KEY); + return; + } + mannequin.getPersistentDataContainer().set(DESCRIPTION_KEY, PersistentDataType.STRING, description); + } + }