fixed skin property showing in property remove command

This commit is contained in:
D3v1s0m 2023-07-27 19:21:46 +05:30
parent 52f083583b
commit 769eed2f46
No known key found for this signature in database
GPG Key ID: FA1F770C7B1D40C1
5 changed files with 26 additions and 4 deletions

@ -3,4 +3,5 @@ package lol.pyr.znpcsplus.api.entity;
public interface EntityProperty<T> { public interface EntityProperty<T> {
T getDefaultValue(); T getDefaultValue();
String getName(); String getName();
boolean isPlayerModifiable();
} }

@ -28,6 +28,7 @@ public class PropertyRemoveCommand implements CommandHandler {
NpcImpl npc = entry.getNpc(); NpcImpl npc = entry.getNpc();
EntityPropertyImpl<?> property = context.parse(EntityPropertyImpl.class); 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 (!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); npc.setProperty(property, null);
context.send(Component.text("Removed property " + property.getName() + " from NPC " + entry.getId(), NamedTextColor.GREEN)); 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<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds()); if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(0, NpcEntryImpl.class) 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(); return Collections.emptyList();
} }
} }

@ -15,6 +15,7 @@ public abstract class EntityPropertyImpl<T> implements EntityProperty<T> {
private final T defaultValue; private final T defaultValue;
private final Class<T> clazz; private final Class<T> clazz;
private final List<EntityPropertyImpl<?>> dependencies = new ArrayList<>(); private final List<EntityPropertyImpl<?>> dependencies = new ArrayList<>();
private boolean playerModifiable = true;
protected EntityPropertyImpl(String name, T defaultValue, Class<T> clazz) { protected EntityPropertyImpl(String name, T defaultValue, Class<T> clazz) {
this.name = name.toLowerCase(); this.name = name.toLowerCase();
@ -32,6 +33,15 @@ public abstract class EntityPropertyImpl<T> implements EntityProperty<T> {
return defaultValue; return defaultValue;
} }
@Override
public boolean isPlayerModifiable() {
return playerModifiable;
}
public void setPlayerModifiable(boolean playerModifiable) {
this.playerModifiable = playerModifiable;
}
public Class<T> getType() { public Class<T> getType() {
return clazz; return clazz;
} }

@ -249,7 +249,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
register(new NameProperty()); register(new NameProperty());
register(new DummyProperty<>("look", false)); register(new DummyProperty<>("look", false));
register(new DummyProperty<>("skin", SkinDescriptor.class)); register(new DummyProperty<>("skin", SkinDescriptor.class, false));
register(new GlowProperty(packetFactory)); register(new GlowProperty(packetFactory));
register(new EffectsProperty("fire", 0x01)); register(new EffectsProperty("fire", 0x01));

@ -8,13 +8,23 @@ import org.bukkit.entity.Player;
import java.util.Map; import java.util.Map;
public class DummyProperty<T> extends EntityPropertyImpl<T> { public class DummyProperty<T> extends EntityPropertyImpl<T> {
@SuppressWarnings("unchecked")
public DummyProperty(String name, T defaultValue) { public DummyProperty(String name, T defaultValue) {
super(name, defaultValue, (Class<T>) defaultValue.getClass()); this(name, defaultValue, true);
} }
public DummyProperty(String name, Class<T> clazz) { public DummyProperty(String name, Class<T> clazz) {
this(name, clazz, true);
}
@SuppressWarnings("unchecked")
public DummyProperty(String name, T defaultValue, boolean playerModifiable) {
super(name, defaultValue, (Class<T>) defaultValue.getClass());
setPlayerModifiable(playerModifiable);
}
public DummyProperty(String name, Class<T> clazz, boolean playerModifiable) {
super(name, null, clazz); super(name, null, clazz);
setPlayerModifiable(playerModifiable);
} }
@Override @Override