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;
}
}
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;
}
}
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.");
}
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();
}
}
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;
}
Aggregations