Search in sources :

Example 86 with Constructor

use of java.lang.reflect.Constructor in project SpaciousLib by anhcraft.

the class ItemsNBT method getFloat.

public float getFloat(String name) {
    try {
        Class<?> e = Class.forName("org.anhcraft.spaciouslib.Inventory.ItemNBT.NBTCompound_" + GameVersion.getVersion().toString().replace("v", ""));
        Constructor c = e.getConstructor();
        NBTCompoundWarpper i = (NBTCompoundWarpper) c.newInstance();
        i.importFromItem(item);
        return i.getFloat(name);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
        return 0;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 87 with Constructor

use of java.lang.reflect.Constructor in project SpaciousLib by anhcraft.

the class ItemsNBT method getLong.

public long getLong(String name) {
    try {
        Class<?> e = Class.forName("org.anhcraft.spaciouslib.Inventory.ItemNBT.NBTCompound_" + GameVersion.getVersion().toString().replace("v", ""));
        Constructor c = e.getConstructor();
        NBTCompoundWarpper i = (NBTCompoundWarpper) c.newInstance();
        i.importFromItem(item);
        return i.getLong(name);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
        return 0;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 88 with Constructor

use of java.lang.reflect.Constructor in project SpaciousLib by anhcraft.

the class ItemsNBT method setBoolean.

public ItemStack setBoolean(String name, Boolean value) {
    try {
        Class<?> e = Class.forName("org.anhcraft.spaciouslib.Inventory.ItemNBT.NBTCompound_" + GameVersion.getVersion().toString().replace("v", ""));
        Constructor c = e.getConstructor();
        NBTCompoundWarpper i = (NBTCompoundWarpper) c.newInstance();
        i.importFromItem(item);
        i.set(name, value);
        return i.exportToItem(item);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
        return null;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 89 with Constructor

use of java.lang.reflect.Constructor in project SpaciousLib by anhcraft.

the class ItemsNBT method getAllTags.

public LinkedHashMap<String, Object> getAllTags() {
    try {
        Class<?> e = Class.forName("org.anhcraft.spaciouslib.Inventory.ItemNBT.NBTCompound_" + GameVersion.getVersion().toString().replace("v", ""));
        Constructor c = e.getConstructor();
        NBTCompoundWarpper i = (NBTCompoundWarpper) c.newInstance();
        i.importFromItem(item);
        return i.getAllTags();
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
        return null;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 90 with Constructor

use of java.lang.reflect.Constructor in project SpaciousLib by anhcraft.

the class ItemsNBT method getList.

public List<NBTCompoundWarpper> getList(String name) {
    try {
        Class<?> e = Class.forName("org.anhcraft.spaciouslib.Inventory.ItemNBT.NBTCompound_" + GameVersion.getVersion().toString().replace("v", ""));
        Constructor c = e.getConstructor();
        NBTCompoundWarpper i = (NBTCompoundWarpper) c.newInstance();
        i.importFromItem(item);
        return i.getList(name);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
        return null;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Constructor (java.lang.reflect.Constructor)1314 InvocationTargetException (java.lang.reflect.InvocationTargetException)283 Method (java.lang.reflect.Method)253 IOException (java.io.IOException)128 Field (java.lang.reflect.Field)112 ArrayList (java.util.ArrayList)106 Test (org.junit.Test)92 DOMTestDocumentBuilderFactory (org.w3c.domts.DOMTestDocumentBuilderFactory)74 JUnitTestSuiteAdapter (org.w3c.domts.JUnitTestSuiteAdapter)73 List (java.util.List)61 JAXPDOMTestDocumentBuilderFactory (org.w3c.domts.JAXPDOMTestDocumentBuilderFactory)58 Map (java.util.Map)50 Type (java.lang.reflect.Type)39 Annotation (java.lang.annotation.Annotation)38 HashMap (java.util.HashMap)38 HashSet (java.util.HashSet)31 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)31 ParameterizedType (java.lang.reflect.ParameterizedType)30 File (java.io.File)20 URL (java.net.URL)20