Search in sources :

Example 91 with Constructor

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

the class ItemsNBT method hasKey.

public Boolean hasKey(String key) {
    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.hasKey(key);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
        return false;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 92 with Constructor

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

the class ItemsNBT method setString.

public ItemStack setString(String name, String 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 93 with Constructor

use of java.lang.reflect.Constructor in project Glowstone by GlowstoneMC.

the class GlowWorld method spawn.

public GlowEntity spawn(Location location, Class<? extends GlowEntity> clazz, SpawnReason reason) throws IllegalArgumentException {
    GlowEntity entity = null;
    if (TNTPrimed.class.isAssignableFrom(clazz)) {
        entity = new GlowTNTPrimed(location, null);
    }
    if (entity == null) {
        try {
            Constructor<? extends GlowEntity> constructor = clazz.getConstructor(Location.class);
            entity = constructor.newInstance(location);
            GlowEntity impl = entity;
            // function.accept(entity); TODO: work on type mismatches
            EntitySpawnEvent spawnEvent;
            if (entity instanceof LivingEntity) {
                spawnEvent = EventFactory.callEvent(new CreatureSpawnEvent((LivingEntity) entity, reason));
            } else {
                spawnEvent = EventFactory.callEvent(new EntitySpawnEvent(entity));
            }
            if (!spawnEvent.isCancelled()) {
                List<Message> spawnMessage = entity.createSpawnMessage();
                getRawPlayers().stream().filter(player -> player.canSeeEntity(impl)).forEach(player -> player.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
            } else {
                // TODO: separate spawning and construction for better event cancellation
                entity.remove();
            }
        } catch (NoSuchMethodException e) {
            GlowServer.logger.log(Level.WARNING, "Invalid entity spawn: ", e);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
            GlowServer.logger.log(Level.SEVERE, "Unable to spawn entity: ", e);
        }
    }
    if (entity != null) {
        return entity;
    }
    throw new UnsupportedOperationException("Not supported yet.");
}
Also used : Plugin(org.bukkit.plugin.Plugin) GlowBlock(net.glowstone.block.GlowBlock) BlockType(net.glowstone.block.blocktype.BlockType) ItemTable(net.glowstone.block.ItemTable) GameRuleManager(net.glowstone.util.GameRuleManager) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent) Biome(org.bukkit.block.Biome) ChunkGenerator(org.bukkit.generator.ChunkGenerator) MaterialData(org.bukkit.material.MaterialData) org.bukkit(org.bukkit) AnvilWorldStorageProvider(net.glowstone.io.anvil.AnvilWorldStorageProvider) Block(org.bukkit.block.Block) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) ToString(lombok.ToString) WorldConfig(net.glowstone.util.config.WorldConfig) BoundingBox(net.glowstone.entity.physics.BoundingBox) org.bukkit.entity(org.bukkit.entity) LightningStrikeEvent(org.bukkit.event.weather.LightningStrikeEvent) BlockPopulator(org.bukkit.generator.BlockPopulator) WorldStorageProvider(net.glowstone.io.WorldStorageProvider) ConcurrentSet(net.glowstone.util.collection.ConcurrentSet) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) GlowChunk(net.glowstone.chunk.GlowChunk) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) WorldFinalValues(net.glowstone.io.WorldMetadataService.WorldFinalValues) MetadataValue(org.bukkit.metadata.MetadataValue) ChunkLock(net.glowstone.chunk.ChunkManager.ChunkLock) Key(net.glowstone.chunk.GlowChunk.Key) GlowFallingBlock(net.glowstone.entity.objects.GlowFallingBlock) GlowStructure(net.glowstone.generator.structures.GlowStructure) EmptySnapshot(net.glowstone.chunk.GlowChunkSnapshot.EmptySnapshot) Setter(lombok.Setter) ThunderChangeEvent(org.bukkit.event.weather.ThunderChangeEvent) java.util(java.util) Getter(lombok.Getter) Message(com.flowpowered.network.Message) WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent) Constructor(java.lang.reflect.Constructor) Level(java.util.logging.Level) Consumer(org.bukkit.util.Consumer) ServerDifficultyMessage(net.glowstone.net.message.play.player.ServerDifficultyMessage) RayUtil(net.glowstone.util.RayUtil) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GlowItem(net.glowstone.entity.objects.GlowItem) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) org.bukkit.event.world(org.bukkit.event.world) MetadataStore(org.bukkit.metadata.MetadataStore) ChunkSection(net.glowstone.chunk.ChunkSection) StandardMessenger(org.bukkit.plugin.messaging.StandardMessenger) BlockState(org.bukkit.block.BlockState) IOException(java.io.IOException) File(java.io.File) Vector(org.bukkit.util.Vector) net.glowstone.constants(net.glowstone.constants) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) ChunkManager(net.glowstone.chunk.ChunkManager) MetadataStoreBase(org.bukkit.metadata.MetadataStoreBase) net.glowstone.entity(net.glowstone.entity) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) Message(com.flowpowered.network.Message) ServerDifficultyMessage(net.glowstone.net.message.play.player.ServerDifficultyMessage) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent)

Example 94 with Constructor

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

the class Title method sendSubTitle.

@Override
public void sendSubTitle(Player player, String text) {
    try {
        Class e = Class.forName("org.anhcraft.spaciouslib.Server.Title.Title_" + GameVersion.getVersion().toString().replace("v", ""));
        Constructor c = e.getConstructor();
        TitleWarpper i = (TitleWarpper) c.newInstance();
        i.sendSubTitle(player, text);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException x) {
        x.printStackTrace();
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 95 with Constructor

use of java.lang.reflect.Constructor in project adempiere by adempiere.

the class RequestAnalyzer method getProcClass.

public org.compiere.cm.Extend getProcClass() {
    if (m_procClassName == null)
        return null;
    try {
        Class thisProcClass = Class.forName(m_procClassName);
        boolean errorLogged = false;
        try {
            Constructor constructor = thisProcClass.getDeclaredConstructor(new Class[] { HttpServletRequest.class, Properties.class });
            Extend procClass = (Extend) constructor.newInstance(new Object[] { m_request, m_ctx });
            return procClass;
        } catch (Exception e) {
        }
        return null;
    } catch (Exception e) {
    }
    return null;
}
Also used : Extend(org.compiere.cm.Extend) Constructor(java.lang.reflect.Constructor) MalformedURLException(java.net.MalformedURLException)

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