Skip to content

Instantly share code, notes, and snippets.

@Limeth
Last active August 29, 2015 14:13
Show Gist options
  • Save Limeth/5e0d766ab9e2569265c5 to your computer and use it in GitHub Desktop.
Save Limeth/5e0d766ab9e2569265c5 to your computer and use it in GitHub Desktop.
Is this correct?
package cz.projectsurvive.limeth.hitboxbind.frames;
import cz.projectsurvive.limeth.hitboxbind.HitboxFrameParseException;
import cz.projectsurvive.limeth.hitboxbind.HitboxMedia;
import cz.projectsurvive.limeth.hitboxbind.util.ReadOnlyBinding;
import de.howaner.FramePicture.util.Frame;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.lang.reflect.Constructor;
import java.util.function.Function;
public static <T extends HitboxFrame> T construct(Class<T> frameClass, int id, ReadOnlyBinding<HitboxMedia> media, Location location, BlockFace facing)
{
Constructor<? extends T> constructor;
try
{
constructor = frameClass.getConstructor(Integer.TYPE, Class.class, ReadOnlyBinding.class, Location.class, BlockFace.class);
}
catch(NoSuchMethodException e)
{
throw new HitboxFrameParseException("HitboxFrame class '" + frameClass.getCanonicalName() +
"' is missing the HitboxFrame(int, Class<? extends HitboxFrame>, " +
"ReadOnlyBinding<LiveStreamData>, Location, BlockFace) constructor.");
}
try
{
return constructor.newInstance(id, frameClass, media, location, facing);
}
catch(Exception e)
{
throw new HitboxFrameParseException("Cannot instantiate HitboxFrame class '" + frameClass.getCanonicalName() + "'.", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment