Cleaned up Firework util.
This commit is contained in:
parent
46cc2576dd
commit
d129f722a3
@ -1,69 +1,28 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftEntity;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilFirework
|
||||
{
|
||||
private static Method world_getHandle = null;
|
||||
private static Method nms_world_broadcastEntityEffect = null;
|
||||
private static Method firework_getHandle = null;
|
||||
|
||||
public static void playFirework(Location loc, FireworkEffect fe)
|
||||
{
|
||||
try
|
||||
{
|
||||
Firework fw = (Firework) loc.getWorld().spawn(loc, Firework.class);
|
||||
Firework firework = (Firework) loc.getWorld().spawn(loc, Firework.class);
|
||||
|
||||
Object nms_world = null;
|
||||
Object nms_firework = null;
|
||||
|
||||
|
||||
if(world_getHandle == null)
|
||||
{
|
||||
world_getHandle = getMethod(loc.getWorld().getClass(), "getHandle");
|
||||
firework_getHandle = getMethod(fw.getClass(), "getHandle");
|
||||
}
|
||||
|
||||
nms_world = world_getHandle.invoke(loc.getWorld(), (Object[]) null);
|
||||
nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
|
||||
|
||||
if(nms_world_broadcastEntityEffect == null)
|
||||
{
|
||||
nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
|
||||
}
|
||||
|
||||
FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
|
||||
FireworkMeta data = (FireworkMeta) firework.getFireworkMeta();
|
||||
data.clearEffects();
|
||||
data.setPower(1);
|
||||
data.addEffect(fe);
|
||||
fw.setFireworkMeta(data);
|
||||
firework.setFireworkMeta(data);
|
||||
|
||||
nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
|
||||
((CraftWorld)loc.getWorld()).getHandle().broadcastEntityEffect(((CraftEntity)firework).getHandle(), (byte)17);
|
||||
|
||||
fw.remove();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getMethod(Class<?> cl, String method)
|
||||
{
|
||||
for(Method m : cl.getMethods())
|
||||
{
|
||||
if(m.getName().equals(method))
|
||||
{
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
firework.remove();
|
||||
}
|
||||
|
||||
public static Firework launchFirework(Location loc, FireworkEffect fe, Vector dir, int power)
|
||||
@ -91,35 +50,10 @@ public class UtilFirework
|
||||
return null;
|
||||
}
|
||||
|
||||
public void detonateFirework(Firework fw)
|
||||
public void detonateFirework(Firework firework)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object nms_world = null;
|
||||
Object nms_firework = null;
|
||||
((CraftWorld)firework.getWorld()).getHandle().broadcastEntityEffect(((CraftEntity)firework).getHandle(), (byte)17);
|
||||
|
||||
|
||||
if(world_getHandle == null)
|
||||
{
|
||||
world_getHandle = getMethod(fw.getWorld().getClass(), "getHandle");
|
||||
firework_getHandle = getMethod(fw.getClass(), "getHandle");
|
||||
}
|
||||
|
||||
nms_world = world_getHandle.invoke(fw.getWorld(), (Object[]) null);
|
||||
nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
|
||||
|
||||
if(nms_world_broadcastEntityEffect == null)
|
||||
{
|
||||
nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
|
||||
}
|
||||
|
||||
nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
|
||||
|
||||
fw.remove();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
firework.remove();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user