Package com.forgeessentials.data.api

Examples of com.forgeessentials.data.api.TypeData


    }

    @Override
    public TypeData getDataForType(ClassContainer type)
    {
        return new TypeData(type);
    }
View Full Code Here


    @Override
    public TypeData getDataForObject(ClassContainer container, Object obj)
    {
        ITypeInfo info = getInfoForType(container);
        TypeData data = info.getTypeDataFromObject(obj);

        ITypeInfo tempInfo;
        for (Entry<String, Object> e : data.getAllFields())
        {
            if (e.getValue() != null && !(e.getValue() instanceof TypeData) && StorageManager.isTypeComplex(e.getValue().getClass()))
            {
                tempInfo = info.getInfoForField(e.getKey());
                data.putField(e.getKey(), DataStorageManager.getDataForObject(tempInfo.getTypeOfField(e.getKey()), e.getValue()));
            }
        }

        return data;
    }
View Full Code Here

    }

    @Override
    public TypeData getTypeDataFromObject(ItemStack stack)
    {
        TypeData data = DataStorageManager.getDataForType(new ClassContainer(ItemStack.class));

        data.putField(SIZE, stack.stackSize);
        data.putField(ITEM, GameData.getItemRegistry().getNameForObject(stack.getItem()));
        data.putField(DAMAGE, stack.getItemDamage());
        data.putField(COMPOUND, stack.getTagCompound());

        return data;
    }
View Full Code Here

    @Override
    public TypeData getTypeDataFromObject(T obj)
    {
        Class<?> c = obj.getClass();
        TypeData data = DataStorageManager.getDataForType(container);
        Field f;
        Object temp;

        // do Unique key stuff
        try
        {
            if (isUniqueKeyField && hasUniqueKey)
            {
                f = c.getDeclaredField(uniqueKey);
                f.setAccessible(true);
                data.setUniqueKey(f.get(obj).toString());
            }
            else if (hasUniqueKey)
            {
                Method m;
                m = c.getDeclaredMethod(uniqueKey, new Class[] { });
                m.setAccessible(true);
                Object val = m.invoke(obj, new Object[] { });
                data.setUniqueKey(val.toString());

            }
            else
            {
                data.setUniqueKey(obj.toString());
            }
        }
        catch (Exception e)
        {
            OutputHandler.exception(Level.SEVERE,
                    "Reflection error trying to get UniqueLoadingKey from " + obj.getClass() + ". FE will continue without saving this.", e);
        }

        String[] keys = fields.keySet().toArray(new String[fields.size()]);
        Class<?> currentClass = c;
        // Iterate over the object grabbing the fields we want to examine.
        for (int i = 0; i < keys.length; ++i)
        {
            try
            {
                f = currentClass.getDeclaredField(keys[i]);
                f.setAccessible(true);
                temp = f.get(obj);

                if (temp != null)
                {
                    if (StorageManager.isTypeComplex(temp.getClass()))
                    {
                        // This object is not a primitive. Call this function on the appropriate TypeTagger.
                        temp = DataStorageManager.getDataForObject(fields.get(keys[i]), temp);
                    }
                    data.putField(keys[i], temp);
                }
                // Ensure we reset the currentClass after trying this. It may have been altered by a previous attempt.
                currentClass = c;
            }
            catch (NoSuchFieldException e)
View Full Code Here

        HashSet<TypeData> datas = new HashSet<TypeData>();

        Object[] array = (Object[]) obj;

        int i = 0;
        TypeData data;
        for (Object element : array)
        {
            if (element == null)
            {
                continue;
            }

            data = getEntryData();
            data.putField(POS, i);
            data.putField(ELEMENT, element);
            datas.add(data);
        }

        return datas;
    }
View Full Code Here

        Set set = (Set) obj;

        Iterator itt = set.iterator();

        TypeData data;
        int i = 0;
        Object temp;
        while (itt.hasNext())
        {
            temp = itt.next();
            data = getEntryData();
            data.putField(POS, i);
            data.putField(ELEMENT, temp);
            datas.add(data);
            i++;
        }

        return datas;
View Full Code Here

        NBTTagList nbt = (NBTTagList) obj;

        int count = nbt.tagCount();
        int type = nbt.func_150303_d();

        TypeData data;
        for (int i = 0;i<count;++i)
        {
            data = getEntryData();
            data.putField(TYPE,type);

            switch(type){
                case 5 :
                    data.putField(PRIMITIVE, String.valueOf(nbt.func_150308_e(i)));
                    break;
                case 6 :
                    data.putField(PRIMITIVE, String.valueOf(nbt.func_150309_d(i)));
                    break;
                case 8 :
                    data.putField(PRIMITIVE, nbt.getStringTagAt(i));
                    break;
                case 10:
                    data.putField(COMPOUND, nbt.getCompoundTagAt(i));
                    break;
                case 11:
                    NBTTagIntArray intArray = new NBTTagIntArray(nbt.func_150306_c(i));
                    data.putField(I_ARRAY, intArray);
                    break;
            }
            datas.add(data);
        }
View Full Code Here

    }

    @Override
    protected TypeData loadData(ClassContainer type, String uniqueKey)
    {
        TypeData reconstructed = DataStorageManager.getDataForType(type);
        ITypeInfo info = DataStorageManager.getInfoForType(type);

        try
        {
            Statement s = getDbConnection().createStatement();
View Full Code Here

        try
        {
            Statement s = getDbConnection().createStatement();
            ResultSet result = s.executeQuery(createSelectAllStatement(type));
            TypeData temp;

            while (result.next())
            {
                temp = DataStorageManager.getDataForType(type);
View Full Code Here

    }

    private void createTaggedClassFromResult(HashMap<String, Object> result, ITypeInfo info, TypeData data) throws SQLException
    {
        ITypeInfo infoCursor;
        TypeData dataCursor = null;
        ClassContainer tmpClass;
        Object tempVal;

        for (Entry<String, Object> entry : result.entrySet())
        {
            dataCursor = data;
            infoCursor = info;

            if (entry.getKey().equalsIgnoreCase(UNIQUE))
            {
                data.setUniqueKey(entry.getValue().toString());
                continue;
            }

            String[] fieldHeiarchy = entry.getKey().split(SEPERATOR);
            if (fieldHeiarchy != null)
            {
                // Iterate over the list of items in the hierarchy to rebuild the
                // TaggedClass.
                for (int i = 0; i < fieldHeiarchy.length; ++i)
                {
                    String name = fieldHeiarchy[i];

                    // Grab the next item
                    tmpClass = infoCursor.getTypeOfField(name);

                    // if its not the last one.
                    if (fieldHeiarchy.length > i + 1)
                    {
                        // An object lives here. Add a new taggedClass of this type.
                        tempVal = dataCursor.getFieldValue(name);

                        if (tempVal == null)
                        {
                            tempVal = DataStorageManager.getDataForType(tmpClass);
                        }

                        dataCursor.putField(name, tempVal);

                        // change the cursor to the new object.
                        dataCursor = (TypeData) tempVal;
                        infoCursor = infoCursor.getInfoForField(name);
                    }
                    else
                    {
                        // account for multivals.
                        if (name.contains(MULTI_MARKER))
                        {
                            name = name.replace("_" + MULTI_MARKER, "");
                            // get tmpClass again with new name.
                            tmpClass = infoCursor.getTypeOfField(name);
                        }

                        // Primitive type.
                        tempVal = valueToField(tmpClass, entry.getValue());
                        dataCursor.putField(name, tempVal);
                    }
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.forgeessentials.data.api.TypeData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.