properties suggestions
This commit is contained in:
parent
d572f9a28a
commit
ca94951b63
5 changed files with 22 additions and 5 deletions
|
@ -22,7 +22,6 @@ public class PropertiesCommand implements CommandHandler {
|
|||
|
||||
if (!npc.getType().getAllowedProperties().contains(property)) context.halt(Component.text("Property " + property.getName() + " not allowed for npc type " + npc.getType().getName()));
|
||||
|
||||
// TODO: implement all the parsers for the types used in EntityPropertyImpl
|
||||
Object value = context.parse(property.getType());
|
||||
npc.UNSAFE_setProperty(property, value);
|
||||
context.send(Component.text("Set property " + property.getName() + " for NPC " + entry.getId() + " to " + value.toString(), NamedTextColor.GREEN));
|
||||
|
@ -33,6 +32,12 @@ public class PropertiesCommand implements CommandHandler {
|
|||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestStream(context.suggestionParse(0, NpcEntryImpl.class)
|
||||
.getNpc().getType().getAllowedProperties().stream().map(EntityPropertyImpl::getName));
|
||||
if (context.argSize() == 3) {
|
||||
EntityPropertyImpl<?> property = context.suggestionParse(1, EntityPropertyImpl.class);
|
||||
Class<?> type = property.getType();
|
||||
if (type == Boolean.class) return context.suggestLiteral("true", "false");
|
||||
if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,11 +91,12 @@ public class EntityPropertyImpl<T> implements EntityProperty<T> {
|
|||
private final static PropertySerializer<SkinDescriptor> DESCRIPTOR_SERIALIZER = descriptor -> ((BaseSkinDescriptor) descriptor).serialize();
|
||||
private final static PropertyDeserializer<SkinDescriptor> DESCRIPTOR_DESERIALIZER = BaseSkinDescriptor::deserialize;
|
||||
|
||||
public static EntityPropertyImpl<Boolean> SKIN_LAYERS = new EntityPropertyImpl<>("skin_layers", true, BOOLEAN_SERIALIZER, BOOLEAN_DESERIALIZER);
|
||||
public static EntityPropertyImpl<SkinDescriptor> SKIN = new EntityPropertyImpl<>("skin", SkinDescriptor.class, DESCRIPTOR_SERIALIZER, DESCRIPTOR_DESERIALIZER);
|
||||
public static EntityPropertyImpl<NamedTextColor> GLOW = new EntityPropertyImpl<>("glow", NamedTextColor.class, COLOR_SERIALIZER, COLOR_DESERIALIZER);
|
||||
public static EntityPropertyImpl<Boolean> SKIN_LAYERS = new EntityPropertyImpl<>("skin_layers", true, BOOLEAN_SERIALIZER, BOOLEAN_DESERIALIZER);
|
||||
public static EntityPropertyImpl<Boolean> FIRE = new EntityPropertyImpl<>("fire", false, BOOLEAN_SERIALIZER, BOOLEAN_DESERIALIZER);
|
||||
public static EntityPropertyImpl<Boolean> INVISIBLE = new EntityPropertyImpl<>("invisible", false, BOOLEAN_SERIALIZER, BOOLEAN_DESERIALIZER);
|
||||
public static EntityPropertyImpl<Boolean> SILENT = new EntityPropertyImpl<>("silent", false, BOOLEAN_SERIALIZER, BOOLEAN_DESERIALIZER);
|
||||
|
||||
public static EntityPropertyImpl<SkinDescriptor> SKIN = new EntityPropertyImpl<>("skin", SkinDescriptor.class, DESCRIPTOR_SERIALIZER, DESCRIPTOR_DESERIALIZER);
|
||||
public static EntityPropertyImpl<Component> NAME = new EntityPropertyImpl<>("name", Component.class, COMPONENT_SERIALIZER, COMPONENT_DESERIALIZER);
|
||||
}
|
|
@ -62,6 +62,11 @@ public class PacketEntity {
|
|||
PacketFactory.get().sendAllMetadata(player, this, properties);
|
||||
}
|
||||
|
||||
public void remakeTeam(Player player) {
|
||||
PacketFactory.get().removeTeam(player, this);
|
||||
PacketFactory.get().createTeam(player, this, properties);
|
||||
}
|
||||
|
||||
private static int reserveEntityID() {
|
||||
if (VersionUtil.isNewerThan(14)) return Reflections.ATOMIC_ENTITY_ID_FIELD.get().incrementAndGet();
|
||||
else {
|
||||
|
|
|
@ -95,6 +95,10 @@ public class NpcImpl extends Viewable implements Npc {
|
|||
for (Player viewer : getViewers()) entity.refreshMeta(viewer);
|
||||
}
|
||||
|
||||
private void _remakeTeam() {
|
||||
for (Player viewer : getViewers()) entity.remakeTeam(viewer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getProperty(EntityProperty<T> key) {
|
||||
return hasProperty(key) ? (T) propertyMap.get((EntityPropertyImpl<?>) key) : key.getDefaultValue();
|
||||
|
@ -108,6 +112,7 @@ public class NpcImpl extends Viewable implements Npc {
|
|||
if (value.equals(key.getDefaultValue())) removeProperty(key);
|
||||
else propertyMap.put(key, value);
|
||||
_refreshMeta();
|
||||
if (key == EntityPropertyImpl.GLOW) _remakeTeam();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -118,6 +123,7 @@ public class NpcImpl extends Viewable implements Npc {
|
|||
public void removeProperty(EntityPropertyImpl<?> key) {
|
||||
propertyMap.remove(key);
|
||||
_refreshMeta();
|
||||
if (key == EntityPropertyImpl.GLOW) _remakeTeam();
|
||||
}
|
||||
|
||||
public Set<EntityPropertyImpl<?>> getAppliedProperties() {
|
||||
|
|
|
@ -34,7 +34,7 @@ public abstract class ReflectionLazyLoader<T> {
|
|||
if (eval == null) throw new RuntimeException("Returned value is null");
|
||||
} catch (Throwable throwable) {
|
||||
if (strict) {
|
||||
warn(" ----- REFLECTION FAILURE DEBUG INFORMATION, REPORT THIS ON OUR GITHUB ----- ");
|
||||
warn(" ----- REFLECTION FAILURE DEBUG INFORMATION, REPORT THIS ON THE ZNPCSPLUS GITHUB ----- ");
|
||||
warn(getClass().getSimpleName() + " failed!");
|
||||
warn("Class Names: " + possibleClassNames);
|
||||
warn("Reflection Type: " + getClass().getCanonicalName());
|
||||
|
@ -42,7 +42,7 @@ public abstract class ReflectionLazyLoader<T> {
|
|||
printDebugInfo(this::warn);
|
||||
warn("Exception:");
|
||||
throwable.printStackTrace();
|
||||
warn(" ----- REFLECTION FAILURE DEBUG INFORMATION, REPORT THIS ON OUR GITHUB ----- ");
|
||||
warn(" ----- REFLECTION FAILURE DEBUG INFORMATION, REPORT THIS ON THE ZNPCSPLUS GITHUB ----- ");
|
||||
}
|
||||
}
|
||||
this.loaded = true;
|
||||
|
|
Loading…
Reference in a new issue