From 769eed2f463f8d520750b00b415eec40a585f6b4 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Thu, 27 Jul 2023 19:21:46 +0530 Subject: [PATCH] fixed skin property showing in property remove command --- .../pyr/znpcsplus/api/entity/EntityProperty.java | 1 + .../commands/property/PropertyRemoveCommand.java | 3 ++- .../pyr/znpcsplus/entity/EntityPropertyImpl.java | 10 ++++++++++ .../entity/EntityPropertyRegistryImpl.java | 2 +- .../znpcsplus/entity/properties/DummyProperty.java | 14 ++++++++++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java b/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java index 7ae66cb..69db24e 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/entity/EntityProperty.java @@ -3,4 +3,5 @@ package lol.pyr.znpcsplus.api.entity; public interface EntityProperty { T getDefaultValue(); String getName(); + boolean isPlayerModifiable(); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java index 0fc8b23..b517d74 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertyRemoveCommand.java @@ -28,6 +28,7 @@ public class PropertyRemoveCommand implements CommandHandler { NpcImpl npc = entry.getNpc(); EntityPropertyImpl property = context.parse(EntityPropertyImpl.class); if (!npc.hasProperty(property)) context.halt(Component.text("This npc doesn't have the " + property.getName() + " property set", NamedTextColor.RED)); + if (!property.isPlayerModifiable()) context.halt(Component.text("This property is not modifiable by players", NamedTextColor.RED)); npc.setProperty(property, null); context.send(Component.text("Removed property " + property.getName() + " from NPC " + entry.getId(), NamedTextColor.GREEN)); } @@ -36,7 +37,7 @@ public class PropertyRemoveCommand implements CommandHandler { public List suggest(CommandContext context) throws CommandExecutionException { if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(0, NpcEntryImpl.class) - .getNpc().getAppliedProperties().stream().map(EntityProperty::getName)); + .getNpc().getAppliedProperties().stream().filter(EntityProperty::isPlayerModifiable).map(EntityProperty::getName)); return Collections.emptyList(); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java index 9842fbb..53b4392 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyImpl.java @@ -15,6 +15,7 @@ public abstract class EntityPropertyImpl implements EntityProperty { private final T defaultValue; private final Class clazz; private final List> dependencies = new ArrayList<>(); + private boolean playerModifiable = true; protected EntityPropertyImpl(String name, T defaultValue, Class clazz) { this.name = name.toLowerCase(); @@ -32,6 +33,15 @@ public abstract class EntityPropertyImpl implements EntityProperty { return defaultValue; } + @Override + public boolean isPlayerModifiable() { + return playerModifiable; + } + + public void setPlayerModifiable(boolean playerModifiable) { + this.playerModifiable = playerModifiable; + } + public Class getType() { return clazz; } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index b8a33f5..bea8614 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -249,7 +249,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new NameProperty()); register(new DummyProperty<>("look", false)); - register(new DummyProperty<>("skin", SkinDescriptor.class)); + register(new DummyProperty<>("skin", SkinDescriptor.class, false)); register(new GlowProperty(packetFactory)); register(new EffectsProperty("fire", 0x01)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java index 9e1306e..eba69a5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/DummyProperty.java @@ -8,13 +8,23 @@ import org.bukkit.entity.Player; import java.util.Map; public class DummyProperty extends EntityPropertyImpl { - @SuppressWarnings("unchecked") public DummyProperty(String name, T defaultValue) { - super(name, defaultValue, (Class) defaultValue.getClass()); + this(name, defaultValue, true); } public DummyProperty(String name, Class clazz) { + this(name, clazz, true); + } + + @SuppressWarnings("unchecked") + public DummyProperty(String name, T defaultValue, boolean playerModifiable) { + super(name, defaultValue, (Class) defaultValue.getClass()); + setPlayerModifiable(playerModifiable); + } + + public DummyProperty(String name, Class clazz, boolean playerModifiable) { super(name, null, clazz); + setPlayerModifiable(playerModifiable); } @Override