mirror of
https://github.com/YouHaveTrouble/Stand-in.git
synced 2026-05-11 22:16:55 +00:00
allow editing mannequin description
This commit is contained in:
@@ -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<ArmorStan
|
||||
return from.getWorld().spawn(from.getLocation(), Mannequin.class, (mannequin -> {
|
||||
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());
|
||||
|
||||
@@ -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<Mannequin
|
||||
if (profileName != null && !profileName.isEmpty()) {
|
||||
pdc.set(EntityConverter.PLAYER_PROFILE_KEY, PersistentDataType.STRING, profileName);
|
||||
}
|
||||
String description = MannequinHandler.getRawDescription(from);
|
||||
if (description != null) {
|
||||
pdc.set(MannequinHandler.DESCRIPTION_KEY, PersistentDataType.STRING, description);
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
StandIn.getPlugin(StandIn.class).getSLF4JLogger().warn("Failed to spawn entity", e);
|
||||
|
||||
@@ -13,11 +13,14 @@ import me.youhavetrouble.standin.converter.MannequinToArmorStandConverter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickCallback;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Mannequin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Pose;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
@@ -28,6 +31,8 @@ import java.util.UUID;
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class MannequinHandler extends EntityHandler<Mannequin> {
|
||||
|
||||
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<Mannequin> {
|
||||
.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<Mannequin> {
|
||||
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<Mannequin> {
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user