Implemented potion color and potion ambient properties
This commit is contained in:
parent
16c48043b4
commit
6d4cd5199a
14 changed files with 134 additions and 1 deletions
31
api/src/main/java/lol/pyr/znpcsplus/util/PotionColor.java
Normal file
31
api/src/main/java/lol/pyr/znpcsplus/util/PotionColor.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package lol.pyr.znpcsplus.util;
|
||||
|
||||
public class PotionColor {
|
||||
|
||||
private final String color;
|
||||
|
||||
public static PotionColor DEFAULT = new PotionColor("0");
|
||||
|
||||
public PotionColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
if (color.startsWith("#")) {
|
||||
if (color.length() != 7)
|
||||
throw new IllegalArgumentException("Hex color must be 6 characters long");
|
||||
return Integer.parseInt(color.substring(1), 16);
|
||||
} else if (color.startsWith("0x")) {
|
||||
if (color.length() != 8)
|
||||
throw new IllegalArgumentException("Hex color must be 6 characters long");
|
||||
return Integer.parseInt(color.substring(2), 16);
|
||||
} else {
|
||||
return Integer.parseInt(color);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(color);
|
||||
}
|
||||
|
||||
}
|
|
@ -259,6 +259,7 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage));
|
||||
manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage));
|
||||
manager.registerParser(NpcPose.class, new NpcPoseParser(incorrectUsageMessage));
|
||||
manager.registerParser(PotionColor.class, new PotionColorParser(incorrectUsageMessage));
|
||||
|
||||
manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root"))
|
||||
.addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry))
|
||||
|
|
|
@ -11,6 +11,7 @@ import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
|||
import lol.pyr.znpcsplus.npc.NpcImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import lol.pyr.znpcsplus.util.NpcPose;
|
||||
import lol.pyr.znpcsplus.util.PotionColor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
|
@ -49,6 +50,10 @@ public class PropertyCommand implements CommandHandler {
|
|||
value = null;
|
||||
valueName = "NONE";
|
||||
}
|
||||
else if (type == PotionColor.class && context.argSize() < 1 && npc.getProperty(property) != null) {
|
||||
value = PotionColor.DEFAULT;
|
||||
valueName = "NONE";
|
||||
}
|
||||
else {
|
||||
value = context.parse(type);
|
||||
valueName = String.valueOf(value);
|
||||
|
@ -69,6 +74,7 @@ public class PropertyCommand implements CommandHandler {
|
|||
if (type == Boolean.class) return context.suggestLiteral("true", "false");
|
||||
if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys());
|
||||
if (type == NpcPose.class) return context.suggestEnum(NpcPose.values());
|
||||
if (property.getName().equals("potion_color")) return context.suggestLiteral("0x0F00FF", "#FFFFFF", "16711935");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import lol.pyr.znpcsplus.api.skin.SkinDescriptor;
|
|||
import lol.pyr.znpcsplus.entity.serializers.*;
|
||||
import lol.pyr.znpcsplus.skin.cache.SkinCache;
|
||||
import lol.pyr.znpcsplus.util.NpcPose;
|
||||
import lol.pyr.znpcsplus.util.PotionColor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
|
@ -28,6 +29,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
registerSerializer(new SkinDescriptorSerializer(skinCache));
|
||||
registerSerializer(new ItemStackPropertySerializer());
|
||||
registerSerializer(new NpcPosePropertySerializer());
|
||||
registerSerializer(new PotionColorPropertySerializer());
|
||||
|
||||
registerType("glow", NamedTextColor.class);
|
||||
registerType("fire", false);
|
||||
|
@ -46,7 +48,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
|||
registerType("offhand", ItemStack.class);
|
||||
|
||||
registerType("using_item", false); // TODO: Eating/Drinking/Blocking with sword/etc
|
||||
registerType("potion_color", 0xFFFFFF); // TODO
|
||||
registerType("potion_color", PotionColor.class); // TODO
|
||||
registerType("potion_ambient", false); // TODO
|
||||
registerType("shaking", false);
|
||||
registerType("baby", false); // TODO
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package lol.pyr.znpcsplus.entity.serializers;
|
||||
|
||||
import lol.pyr.znpcsplus.util.PotionColor;
|
||||
import lol.pyr.znpcsplus.entity.PropertySerializer;
|
||||
|
||||
public class PotionColorPropertySerializer implements PropertySerializer<PotionColor> {
|
||||
@Override
|
||||
public String serialize(PotionColor property) {
|
||||
return property.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionColor deserialize(String property) {
|
||||
return new PotionColor(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<PotionColor> getTypeClass() {
|
||||
return PotionColor.class;
|
||||
}
|
||||
}
|
|
@ -27,4 +27,6 @@ public interface MetadataFactory {
|
|||
EntityData noGravity();
|
||||
EntityData pose(EntityPose pose);
|
||||
EntityData shaking(boolean enabled);
|
||||
EntityData potionColor(int color);
|
||||
EntityData potionAmbient(boolean ambient);
|
||||
}
|
||||
|
|
|
@ -8,4 +8,14 @@ public class V1_10MetadataFactory extends V1_9MetadataFactory {
|
|||
public EntityData noGravity() {
|
||||
return newEntityData(5, EntityDataTypes.BOOLEAN, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionColor(int color) {
|
||||
return newEntityData(8, EntityDataTypes.INT, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionAmbient(boolean ambient) {
|
||||
return newEntityData(9, EntityDataTypes.BOOLEAN, ambient);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,14 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory {
|
|||
public EntityData pose(EntityPose pose) {
|
||||
return newEntityData(6, EntityDataTypes.ENTITY_POSE, pose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionColor(int color) {
|
||||
return newEntityData(9, EntityDataTypes.INT, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionAmbient(boolean ambient) {
|
||||
return newEntityData(10, EntityDataTypes.BOOLEAN, ambient);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,4 +18,14 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory {
|
|||
public EntityData shaking(boolean enabled) {
|
||||
return newEntityData(7, EntityDataTypes.INT, enabled ? 140 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionColor(int color) {
|
||||
return newEntityData(10, EntityDataTypes.INT, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionAmbient(boolean ambient) {
|
||||
return newEntityData(11, EntityDataTypes.BOOLEAN, ambient);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,16 @@ public class V1_8MetadataFactory implements MetadataFactory {
|
|||
throw new UnsupportedOperationException("The shaking entity data isn't supported on this version");
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionColor(int color) {
|
||||
return newEntityData(7, EntityDataTypes.INT, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionAmbient(boolean ambient) {
|
||||
return newEntityData(8, EntityDataTypes.BYTE, (byte) (ambient ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData silent(boolean enabled) {
|
||||
return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));
|
||||
|
|
|
@ -18,6 +18,11 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory {
|
|||
return newEntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0) | (usingElytra ? 0x80 : 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityData potionAmbient(boolean ambient) {
|
||||
return newEntityData(8, EntityDataTypes.BOOLEAN, ambient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<EntityData> name(Component name) {
|
||||
return list(
|
||||
|
|
|
@ -77,6 +77,8 @@ public class NpcTypeImpl implements NpcType {
|
|||
allowedProperties.add(propertyRegistry.getByName("silent"));
|
||||
allowedProperties.add(propertyRegistry.getByName("look"));
|
||||
allowedProperties.add(propertyRegistry.getByName("skin_cape"));
|
||||
allowedProperties.add(propertyRegistry.getByName("potion_color"));
|
||||
allowedProperties.add(propertyRegistry.getByName("potion_ambient"));
|
||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))
|
||||
allowedProperties.add(propertyRegistry.getByName("glow"));
|
||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14))
|
||||
|
|
|
@ -15,6 +15,7 @@ import lol.pyr.znpcsplus.api.skin.SkinDescriptor;
|
|||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||
import lol.pyr.znpcsplus.util.PotionColor;
|
||||
import lol.pyr.znpcsplus.metadata.MetadataFactory;
|
||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||
import lol.pyr.znpcsplus.skin.BaseSkinDescriptor;
|
||||
|
@ -142,6 +143,8 @@ public class V1_8PacketFactory implements PacketFactory {
|
|||
false)
|
||||
);
|
||||
add(data, metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class))));
|
||||
add(data, metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", PotionColor.class)).getColor()));
|
||||
add(data, metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class))));
|
||||
if (properties.hasProperty(propertyRegistry.getByName("name"))) addAll(data, metadataFactory.name(properties.getProperty(propertyRegistry.getByName("name", Component.class))));
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package lol.pyr.znpcsplus.parsers;
|
||||
|
||||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.parse.ParserType;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.director.common.message.Message;
|
||||
import lol.pyr.znpcsplus.util.PotionColor;
|
||||
|
||||
import java.util.Deque;
|
||||
|
||||
public class PotionColorParser extends ParserType<PotionColor> {
|
||||
public PotionColorParser(Message<CommandContext> message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionColor parse(Deque<String> deque) throws CommandExecutionException {
|
||||
return new PotionColor(deque.pop());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue