I'm working on a Railgun plugin which means, clicking a hoe will shoot fireworks and if it hits/goes very close to an entity it will kill them. Does anybody have an idea on how I would be able to accomplish this? Code:java package me.Jaaakee224.RailGun; import java.lang.reflect.Method;import java.util.Random; import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.Sound;import org.bukkit.block.Block;import org.bukkit.entity.Firework;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.plugin.java.JavaPlugin; public class RailGun extends JavaPlugin implements Listener { int timer,id = 0;Random gen = new Random();public void onEnable(){this.getServer().getPluginManager().registerEvents(this, this);} @SuppressWarnings("deprecation")@EventHandlerpublic void onPlayerInteract(PlayerInteractEvent event) {if ((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getPlayer().getItemInHand().equals(Material.WOOD_HOE))) {// event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLAZE_DEATH, 1, 9);event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLAZE_HIT, 2, 50);try {for(Block loc:event.getPlayer().getLineOfSight(null, 100)) {playFirework(loc.getLocation()); }} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}} private Object[] dataStore = new Object[5];public void playFirework(Location loc) throws Exception {Firework fw = (Firework) loc.getWorld().spawn(loc, Firework.class);if(dataStore[0] == null) dataStore[0] = getMethod(loc.getWorld().getClass(), "getHandle");if(dataStore[2] == null) dataStore[2] = getMethod(fw.getClass(), "getHandle");dataStore[3] = ((Method) dataStore[0]).invoke(loc.getWorld(), (Object[]) null);dataStore[4] = ((Method) dataStore[2]).invoke(fw, (Object[]) null);if(dataStore[1] == null) dataStore[1] = getMethod(dataStore[3].getClass(), "addParticle");((Method) dataStore[1]).invoke(dataStore[3], new Object[] {"fireworksSpark", loc.getX(),loc.getY(),loc.getZ(),gen.nextGaussian() * 0.05D, -(loc.getZ()* 1.15D) * 0.5D, gen.nextGaussian() * 0.05D});fw.remove();}private Method getMethod(Class<?> cl, String method) {for(Method m : cl.getMethods()) if(m.getName().equals(method)) return m;return null;}} All help is appreciated
Jaaakee224 already looked at the quake plugin? Jaaakee224 Maybe this: The particle effects when you right click (shooting)(not the firework) Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code:java package com.Geekpower14.Quake.Utils; import java.lang.reflect.Field;import java.lang.reflect.Method;import org.bukkit.Location;import org.bukkit.entity.Player; public enum ParticleEffects{HUGE_EXPLOSION("hugeexplosion"), LARGE_EXPLODE("largeexplode"), FIREWORKS_SPARK("fireworksSpark"), BUBBLE("bubble"), SUSPEND("suspend"), DEPTH_SUSPEND("depthSuspend"), TOWN_AURA("townaura"), CRIT("crit"), MAGIC_CRIT("magicCrit"), MOB_SPELL("mobSpell"), MOB_SPELL_AMBIENT("mobSpellAmbient"), SPELL("spell"), INSTANT_SPELL("instantSpell"), WITCH_MAGIC("witchMagic"), NOTE("note"), PORTAL("portal"), ENCHANTMENT_TABLE("enchantmenttable"), EXPLODE("explode"), FLAME("flame"), LAVA("lava"), FOOTSTEP("footstep"), SPLASH("splash"), LARGE_SMOKE("largesmoke"), CLOUD("cloud"), RED_DUST("reddust"), SNOWBALL_POOF("snowballpoof"), DRIP_WATER("dripWater"), DRIP_LAVA("dripLava"), SNOW_SHOVEL("snowshovel"), SLIME("slime"), HEART("heart"), ANGRY_VILLAGER("angryVillager"), HAPPY_VILLAGER("happerVillager"), ICONCRACK("iconcrack_"), ICONCRASH("iconcrack_0sqd"), TILECRACK("tilecrack_"); private Class<?> nmsPacketPlayOutWorldParticles = Reflection.getNMSClass("PacketPlayOutWorldParticles");private static Method getEntityHandle;private static Field getPlayerConnection;private static Method sendPacket;private String particleName; static{try{getEntityHandle = Reflection.getOBCClass("entity.CraftPlayer").getMethod("getHandle", new Class[0]);getPlayerConnection = Reflection.getNMSClass("EntityPlayer").getDeclaredField("playerConnection");sendPacket = Reflection.getNMSClass("PlayerConnection").getMethod("sendPacket", new Class[] { Reflection.getNMSClass("Packet") });}catch (Exception e){e.printStackTrace();}} private ParticleEffects(String particleName){this.particleName = particleName;} public void sendToPlayer(Player player, Location location, float offsetX, float offsetY, float offsetZ, float speed, int count)throws Exception{Object packet = this.nmsPacketPlayOutWorldParticles.newInstance();ReflectionUtilities.setValue(packet, "a", this.particleName);ReflectionUtilities.setValue(packet, "b", Float.valueOf((float)location.getX()));ReflectionUtilities.setValue(packet, "c", Float.valueOf((float)location.getY()));ReflectionUtilities.setValue(packet, "d", Float.valueOf((float)location.getZ()));ReflectionUtilities.setValue(packet, "e", Float.valueOf(offsetX));ReflectionUtilities.setValue(packet, "f", Float.valueOf(offsetY));ReflectionUtilities.setValue(packet, "g", Float.valueOf(offsetZ));ReflectionUtilities.setValue(packet, "h", Float.valueOf(speed));ReflectionUtilities.setValue(packet, "i", Integer.valueOf(count));sendPacket(packet, player);} public static void sendPacket(Object packet, Player player){try{Object nms_player = getEntityHandle.invoke(player, new Object[0]);Object nms_connection = getPlayerConnection.get(nms_player);sendPacket.invoke(nms_connection, new Object[] { packet });}catch (Exception e){e.printStackTrace();}} public static class ReflectionUtilities{public static void setValue(Object instance, String fieldName, Object value)throws Exception{Field field = instance.getClass().getDeclaredField(fieldName);field.setAccessible(true);field.set(instance, value);} public static Object getValue(Object instance, String fieldName)throws Exception{Field field = instance.getClass().getDeclaredField(fieldName);field.setAccessible(true);return field.get(instance);}}} The FireworkEffect on player: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code:java package com.Geekpower14.Quake.Utils; import com.Geekpower14.Quake.Quake;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import org.bukkit.FireworkEffect;import org.bukkit.Location;import org.bukkit.World;import org.bukkit.entity.Firework;import org.bukkit.inventory.meta.FireworkMeta; public class FireworkEffectPlayer{public Quake plugin; public FireworkEffectPlayer(Quake pl){this.plugin = pl;} private Method world_getHandle = null;private Method nms_world_broadcastEntityEffect = null;private Method firework_getHandle = null; public void playFirework(World world, Location loc, FireworkEffect fe)throws Exception{Firework fw = (Firework)world.spawn(loc, Firework.class); Object nms_world = null;Object nms_firework = null;if (this.world_getHandle == null){this.world_getHandle = getMethod(world.getClass(), "getHandle");this.firework_getHandle = getMethod(fw.getClass(), "getHandle");}nms_world = this.world_getHandle.invoke(world, null);nms_firework = this.firework_getHandle.invoke(fw, null);if (this.nms_world_broadcastEntityEffect == null) {this.nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");}FireworkMeta data = fw.getFireworkMeta(); data.clearEffects(); data.setPower(1); data.addEffect(fe); fw.setFireworkMeta(data); this.nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] { nms_firework, Byte.valueOf(17) }); fw.remove();} public void playFirework(World world, Location loc)throws Exception{Firework fw = (Firework)world.spawn(loc, Firework.class);if (this.world_getHandle == null){this.world_getHandle = getMethod(world.getClass(), "getHandle");this.firework_getHandle = getMethod(fw.getClass(), "getHandle");}Object nms_world = this.world_getHandle.invoke(world, null);Object nms_firework = this.firework_getHandle.invoke(fw, null);if (this.nms_world_broadcastEntityEffect == null) {this.nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");}FireworkMeta data = fw.getFireworkMeta(); data.clearEffects(); data.setPower(1); fw.setFireworkMeta(data);try{this.nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] { nms_firework, Byte.valueOf(17) });}catch (IllegalAccessException e){e.printStackTrace();}catch (IllegalArgumentException e){e.printStackTrace();}catch (InvocationTargetException e){e.printStackTrace();}fw.remove();} private static Method getMethod(Class<?> cl, String method){for (Method m : cl.getMethods()) {if (m.getName().equals(method)) {return m;}}return null;}} Thats what i got from the quake plugin EDIT by Moderator: merged posts, please use the edit button instead of double posting.
JordyPwner The code I gave is already working, meaning it shoots the line of effects exactly like Hypixel's. I don't want to copy from another plugin on Bukkit. bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Jaaakee224 Wait 24 hours to bump. Also, you've already copied the entire idea from another plugin, what's a little code? That being said, you can check every so often if a firework is near an entity, and if it is, kill it.
mythbusterma This isn't going into anything minigame related and this plugin won't be released. I'm just doing this for good practice.
Jaaakee224 I never said anything about a minigame or releasing this? Look at the solution I gave you.
mythbusterma Once I get home I will test this out. Sorry for the confusion last reply. Only reason I am copying this is to see if I can even do it. Challenging myself