Search in sources :

Example 1 with ParamInfoParticle

use of me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle in project LibsDisguises by libraryaddict.

the class ParamInfoTypes method getParamInfos.

/**
 * Constructor values are listed here for continuity
 */
public List<ParamInfo> getParamInfos() {
    List<ParamInfo> paramInfos = new ArrayList<>();
    // Register enum types
    // paramInfos.add(new ParamInfoEnum(AnimalColor.class, "Animal Color",
    // "View all the colors you can use for an animal color"));
    paramInfos.add(new ParamInfoEnum(Art.class, "Art", "View all the paintings you can use for a painting disguise"));
    paramInfos.add(new ParamInfoEnum(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color"));
    paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession", "View all the professions you can set on a Villager and Zombie Villager"));
    if (NmsVersion.v1_14.isSupported()) {
        paramInfos.add(new ParamInfoEnum(Villager.Type.class, "Villager Biome", "View all the biomes you can set on a Villager and Zombie Villager"));
    }
    paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)", "View the directions usable on player setSleeping and shulker direction", Arrays.copyOf(BlockFace.values(), 6)));
    paramInfos.add(new ParamInfoEnum(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into"));
    paramInfos.add(new ParamInfoEnum(TreeSpecies.class, "Tree Species", "View the different types of tree species"));
    paramInfos.add(new ParamInfoEnum(MainHand.class, "Main Hand", "Set the main hand for an entity"));
    paramInfos.add(new ParamInfoEnum(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color"));
    paramInfos.add(new ParamInfoEnum(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be"));
    if (NmsVersion.v1_13.isSupported()) {
        paramInfos.add(new ParamInfoParticle(WrappedParticle.class, "Particle", "The different particles of Minecraft", Particle.values(), getMaterials()));
        paramInfos.add(new ParamInfoEnum(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish"));
        paramInfos.add(new ParamInfoBlockData(BlockData.class, "BlockData", "The block data states, barrel[facing=north,open=false] as example", getMaterials()));
    } else {
        paramInfos.add(new ParamInfoEnum(Particle.class, "Particle", "The different particles of Minecraft"));
    }
    paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors"));
    paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse"));
    if (NmsVersion.v1_14.isSupported()) {
        paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike"));
        paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat"));
        paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox"));
        paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type"));
        paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant", "The different variants for mushroom cows"));
        if (NmsVersion.v1_17.isSupported()) {
            paramInfos.add(new ParamInfoEnum(Axolotl.Variant.class, "Axolotl Variant", "The variant of Axolotl"));
        }
    } else {
        paramInfos.add(new ParamInfoEnum(Ocelot.Type.class, "Ocelot Type", "The type of ocelot"));
    }
    paramInfos.add(new ParamInfoEnum(DisguiseConfig.NotifyBar.class, "NotifyBar", "Where the disguised indicator should appear"));
    paramInfos.add(new ParamInfoEnum(BarColor.class, "BarColor", "The color of the boss bar"));
    paramInfos.add(new ParamInfoEnum(BarStyle.class, "BarStyle", "The style of the boss bar"));
    // Register custom types
    paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", "Set the X,Y,Z directions on an armorstand"));
    paramInfos.add(new ParamInfoColor(Color.class, "Color", "Colors that can also be defined through RGB", getColors()));
    paramInfos.add(new ParamInfoEnum(Material.class, "Material", "A material used for blocks and items", getMaterials()));
    paramInfos.add(new ParamInfoItemStack(ItemStack.class, "ItemStack", "ItemStack (Material,Amount?,Glow?)", "An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials()));
    paramInfos.add(new ParamInfoItemStackArray(ItemStack[].class, "ItemStack[]", "Four ItemStacks (Material:Amount?:Glow?,Material:Amount?:Glow?..)", "Four ItemStacks separated by a comma", getMaterials()));
    paramInfos.add(new ParamInfoPotionEffect(PotionEffectType.class, "Potion Effect", "View all the potion effects you can add", getPotions()));
    paramInfos.add(new ParamInfoBlockPosition(BlockPosition.class, "Block Position", "Block Position (num,num,num)", "Three numbers separated by a ,"));
    paramInfos.add(new ParamInfoGameProfile(WrappedGameProfile.class, "GameProfile", "Get the gameprofile here https://sessionserver.mojang" + ".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false"));
    paramInfos.add(new ParamInfoTime(long.class, "Expiry Time", "Set how long the disguise lasts, <Num><Time><Num>... where <Time> is (s/sec)(m/min)(h/hour)(d/day) " + "etc. 30m20secs = 30 minutes, 20 seconds"));
    paramInfos.add(new ParamInfoChatColor(ChatColor.class, "ChatColor", "A chat color"));
    paramInfos.add(new ParamInfoEnum(GolemCrack.class, "Golem Cracked", "The stage a golem has been cracked"));
    // Register base types
    Map<String, Object> booleanMap = new HashMap<>();
    booleanMap.put("true", true);
    booleanMap.put("false", false);
    paramInfos.add(new ParamInfoBoolean("Boolean", "True/False", "True or False", booleanMap));
    paramInfos.add(new ParamInfoString(String.class, "Text", "A line of text"));
    paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals"));
    paramInfos.add(new ParamInfoFloat("Number.0", "A number which can have decimal places"));
    paramInfos.add(new ParamInfoFloatNullable("Number.0", "A number which can have decimal places or be null"));
    paramInfos.add(new ParamInfoDouble("Number.0", "A number which can have decimal places"));
    paramInfos.add(new ParamInfoSoundGroup());
    return paramInfos;
}
Also used : HashMap(java.util.HashMap) BlockFace(org.bukkit.block.BlockFace) BarColor(org.bukkit.boss.BarColor) ArrayList(java.util.ArrayList) ParamInfoDouble(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoDouble) TreeSpecies(org.bukkit.TreeSpecies) ParamInfoEulerAngle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoEulerAngle) ParamInfoString(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoString) ParamInfoParticle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) Particle(org.bukkit.Particle) ParamInfoParticle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle) RabbitType(me.libraryaddict.disguise.disguisetypes.RabbitType) ParamInfoFloat(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoFloat) ParamInfoPotionEffect(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoPotionEffect) ParamInfoItemStackArray(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStackArray) ParamInfoEnum(me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum) ParamInfoColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoColor) PotionEffectType(org.bukkit.potion.PotionEffectType) ParamInfoSoundGroup(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoSoundGroup) BarColor(org.bukkit.boss.BarColor) ParamInfoColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoColor) ParamInfoChatColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoChatColor) Color(org.bukkit.Color) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) DyeColor(org.bukkit.DyeColor) ParamInfoTime(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoTime) WrappedGameProfile(com.comphenix.protocol.wrappers.WrappedGameProfile) ParamInfoGameProfile(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoGameProfile) MainHand(org.bukkit.inventory.MainHand) ParamInfoEulerAngle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoEulerAngle) EulerAngle(org.bukkit.util.EulerAngle) ItemStack(org.bukkit.inventory.ItemStack) ParamInfoItemStack(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStack) ParamInfoChatColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoChatColor) ChatColor(org.bukkit.ChatColor) Art(org.bukkit.Art) GolemCrack(me.libraryaddict.disguise.disguisetypes.GolemCrack) ParamInfoBlockData(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockData) ParamInfoFloatNullable(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoFloatNullable) BarStyle(org.bukkit.boss.BarStyle) ParamInfoBlockPosition(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockPosition) BlockData(org.bukkit.block.data.BlockData) ParamInfoBlockData(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockData) ParamInfoInteger(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoInteger) EntityPose(me.libraryaddict.disguise.disguisetypes.EntityPose) BarStyle(org.bukkit.boss.BarStyle) ParamInfoBlockPosition(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockPosition) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) ParamInfoBoolean(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoBoolean) Material(org.bukkit.Material) ParamInfoChatColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoChatColor) ParamInfoString(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoString) PotionEffectType(org.bukkit.potion.PotionEffectType) RabbitType(me.libraryaddict.disguise.disguisetypes.RabbitType) ParamInfoItemStack(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStack)

Example 2 with ParamInfoParticle

use of me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle in project LibsDisguises by libraryaddict.

the class SerializerFlagWatcher method correct.

private void correct(FlagWatcher watcher, Class<? extends FlagWatcher> flagWatcher, String name) throws NoSuchFieldException, IllegalAccessException, DisguiseParseException {
    Field field = FlagWatcher.class.getDeclaredField(name);
    field.setAccessible(true);
    HashMap<Integer, Object> map = (HashMap<Integer, Object>) field.get(watcher);
    int count = 0;
    for (Map.Entry<Integer, Object> entry : map.entrySet()) {
        MetaIndex index = MetaIndex.getMetaIndex(flagWatcher, entry.getKey());
        if (entry.getValue() instanceof Double) {
            Object def = index.getDefault();
            if (def instanceof Long) {
                entry.setValue(((Double) entry.getValue()).longValue());
            } else if (def instanceof Float) {
                entry.setValue(((Double) entry.getValue()).floatValue());
            } else if (def instanceof Integer) {
                entry.setValue(((Double) entry.getValue()).intValue());
            } else if (def instanceof Short) {
                entry.setValue(((Double) entry.getValue()).shortValue());
            } else if (def instanceof Byte) {
                entry.setValue(((Double) entry.getValue()).byteValue());
            }
        } else if (entry.getValue() instanceof String) {
            if (index.getDefault() instanceof WrappedParticle) {
                entry.setValue(((ParamInfoParticle) ParamInfoManager.getParamInfo(WrappedParticle.class)).fromString((String) entry.getValue()));
            } else if (index.getDefault() instanceof EntityPose) {
                entry.setValue(((ParamInfoEnum) ParamInfoManager.getParamInfo(EntityPose.class)).fromString((String) entry.getValue()));
            }
        } else if (entry.getValue() instanceof LinkedTreeMap) {
            // If the default value is not VillagerData
            if (index.getDefault() instanceof VillagerData) {
                entry.setValue(new Gson().fromJson(new Gson().toJson(entry.getValue()), VillagerData.class));
            } else if (index.getDefault() instanceof Optional) {
                for (Field f : MetaIndex.class.getFields()) {
                    try {
                        if (f.get(null) != index) {
                            continue;
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                    Type type = f.getGenericType();
                    Type opt = ((ParameterizedType) type).getActualTypeArguments()[0];
                    if (opt instanceof ParameterizedType) {
                        Type val = ((ParameterizedType) opt).getActualTypeArguments()[0];
                        Optional value;
                        if (((LinkedTreeMap) entry.getValue()).isEmpty()) {
                            value = Optional.empty();
                        } else {
                            value = Optional.of(gson.fromJson(gson.toJson(((LinkedTreeMap) entry.getValue()).get("value")), val));
                        }
                        entry.setValue(value);
                    }
                }
            } else if (index.getDefault() instanceof ItemStack) {
                entry.setValue(gson.fromJson(gson.toJson(entry.getValue()), ItemStack.class));
            }
        }
        // If the deserialized class is not the same class type as the default
        if (!index.getDefault().getClass().isInstance(entry.getValue())) {
            entry.setValue(index.getDefault());
            count++;
        }
    }
    if (count > 0) {
        DisguiseUtilities.getLogger().info("Fixed " + count + " incorrect disguise flags on saved disguise");
    }
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) MetaIndex(me.libraryaddict.disguise.disguisetypes.MetaIndex) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) ParamInfoParticle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle) EntityPose(me.libraryaddict.disguise.disguisetypes.EntityPose) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) Optional(java.util.Optional) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) DisguiseType(me.libraryaddict.disguise.disguisetypes.DisguiseType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) VillagerData(me.libraryaddict.disguise.disguisetypes.VillagerData) JsonObject(com.google.gson.JsonObject) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap)

Aggregations

WrappedParticle (com.comphenix.protocol.wrappers.WrappedParticle)2 HashMap (java.util.HashMap)2 EntityPose (me.libraryaddict.disguise.disguisetypes.EntityPose)2 ParamInfoParticle (me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle)2 ItemStack (org.bukkit.inventory.ItemStack)2 BlockPosition (com.comphenix.protocol.wrappers.BlockPosition)1 WrappedGameProfile (com.comphenix.protocol.wrappers.WrappedGameProfile)1 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Optional (java.util.Optional)1 DisguiseType (me.libraryaddict.disguise.disguisetypes.DisguiseType)1 GolemCrack (me.libraryaddict.disguise.disguisetypes.GolemCrack)1 MetaIndex (me.libraryaddict.disguise.disguisetypes.MetaIndex)1 RabbitType (me.libraryaddict.disguise.disguisetypes.RabbitType)1