[ParticleEffects] Failure!

Discussion in 'Plugin Development' started by HeavyMine13, Jan 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    HeavyMine13

    Hey! I made this code, so it will play hearts all time while im on the server! But, it is sending the console spammingly this:
    [ParticleEffect] Failed to create a particle packet!

    Hj (Main class):
    Code:java
    1. package me.HeavyMine13.hj;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public final class Hj extends JavaPlugin {
    6.  
    7. @Override
    8. public void onEnable(){
    9. getLogger().info("RUN has been enabled,what a noob!");
    10. getServer().getPluginManager().registerEvents(new listeners(this), this);
    11. }
    12.  
    13. @Override
    14. public void onDisable() {
    15. getLogger().info("RUN has been disabled,u noob!");
    16. }
    17. }
    18.  


    listeners:
    Code:java
    1. package me.HeavyMine13.hj;
    2.  
    3.  
    4. import me.HeavyMine13.hj.ParticleEffect;
    5.  
    6.  
    7.  
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.EventPriority;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerLoginEvent;
    14. import org.bukkit.scheduler.BukkitScheduler;
    15.  
    16. public class listeners implements Listener {
    17. Hj plugin;
    18.  
    19. public listeners(Hj instance){
    20. plugin = instance;
    21. }
    22. @EventHandler (priority = EventPriority.HIGH)
    23. public void onPlayerLogin(final PlayerLoginEvent event) {
    24. if(event.getPlayer().getName().equalsIgnoreCase("heavymine13")){
    25. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    26. scheduler.scheduleSyncRepeatingTask (plugin, new Runnable() {
    27. public void run() {
    28. ParticleEffect.HEART.display(event.getPlayer().getLocation(), 0.0f, 0.0f, 0.0f, 1.0f, 30);
    29. }
    30. }, 20L, 0);
    31. }
    32. }
    33. }
    34.  
    35.  


    ParticleEffect:
    Code:java
    1. package me.HeavyMine13.hj;
    2.  
    3. import java.lang.reflect.Constructor;
    4. import java.util.ArrayList;
    5. import java.util.Arrays;
    6. import java.util.Collection;
    7. import java.util.HashMap;
    8. import java.util.List;
    9. import java.util.Map;
    10. import java.util.Map.Entry;
    11.  
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.Location;
    14. import org.bukkit.entity.Player;
    15.  
    16. import me.HeavyMine13.hj.ReflectionUtil;
    17. import me.HeavyMine13.hj.ReflectionUtil.DynamicPackage;
    18. import me.HeavyMine13.hj.ReflectionUtil.FieldEntry;
    19.  
    20. /**
    21. * ParticleEffect Library v1.2
    22. *
    23. * This library was created by [USER=90640105]DarkBlade12[/USER] based on content related to particles of [USER=90705652]microgeek[/USER] (names and packet values) and allows you to display all Minecraft particle effects on a Bukkit server
    24. *
    25. * You are welcome to use it, modify it and redistribute it under the following conditions:
    26. * 1. Credit us if you publish a plugin that uses this library
    27. * 2. Don't remove this text
    28. *
    29. * @author DarkBlade12
    30. */
    31. public enum ParticleEffect {
    32.  
    33. HUGE_EXPLOSION("hugeexplosion", 0),
    34. LARGE_EXPLODE("largeexplode", 1),
    35. FIREWORKS_SPARK("fireworksSpark", 2),
    36. BUBBLE("bubble", 3),
    37. SUSPEND("suspend", 4),
    38. DEPTH_SUSPEND("depthSuspend", 5),
    39. TOWN_AURA("townaura", 6),
    40. CRIT("crit", 7),
    41. MAGIC_CRIT("magicCrit", 8),
    42. MOB_SPELL("mobSpell", 9),
    43. MOB_SPELL_AMBIENT("mobSpellAmbient", 10),
    44. SPELL("spell", 11),
    45. INSTANT_SPELL("instantSpell", 12),
    46. WITCH_MAGIC("witchMagic", 13),
    47. NOTE("note", 14),
    48. PORTAL("portal", 15),
    49. ENCHANTMENT_TABLE("enchantmenttable", 16),
    50. EXPLODE("explode", 17),
    51. FLAME("flame", 18),
    52. LAVA("lava", 19),
    53. FOOTSTEP("footstep", 20),
    54. SPLASH("splash", 21),
    55. LARGE_SMOKE("largesmoke", 22),
    56. CLOUD("cloud", 23),
    57. RED_DUST("reddust", 24),
    58. SNOWBALL_POOF("snowballpoof", 25),
    59. DRIP_WATER("dripWater", 26),
    60. DRIP_LAVA("dripLava", 27),
    61. SNOW_SHOVEL("snowshovel", 28),
    62. SLIME("slime", 29),
    63. HEART("heart", 30),
    64. ANGRY_VILLAGER("angryVillager", 31),
    65. HAPPY_VILLAGER("happyVillager", 32);
    66.  
    67. private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<String, ParticleEffect>();
    68. private static final Map<Integer, ParticleEffect> ID_MAP = new HashMap<Integer, ParticleEffect>();
    69. private static final double MAX_RANGE = 20.0D;
    70. private static Constructor<?> PARTICLE_PACKET_CONSTRUCTOR;
    71.  
    72. static {
    73. for (ParticleEffect effect : values()) {
    74. NAME_MAP.put(effect.name, effect);
    75. ID_MAP.put(effect.id, effect);
    76. }
    77. try {
    78. PARTICLE_PACKET_CONSTRUCTOR = ReflectionUtil.getConstructor(ReflectionUtil.getClass("PacketPlayOutWorldParticles", DynamicPackage.MINECRAFT_SERVER));
    79. } catch (Exception e) {
    80. e.printStackTrace();
    81. }
    82. }
    83.  
    84. private String name;
    85. private int id;
    86.  
    87. ParticleEffect(String name, int id) {
    88. this.name = name;
    89. this.id = id;
    90. }
    91.  
    92. public String getName() {
    93. return name;
    94. }
    95.  
    96. public int getId() {
    97. return id;
    98. }
    99.  
    100. public static ParticleEffect fromName(String name) {
    101. if (name != null)
    102. for (Entry<String, ParticleEffect> e : NAME_MAP.entrySet())
    103. if (e.getKey().equalsIgnoreCase(name))
    104. return e.getValue();
    105. return null;
    106. }
    107.  
    108. public static ParticleEffect fromId(int id) {
    109. return ID_MAP.get(id);
    110. }
    111.  
    112. private static List<Player> getPlayersInRange(Location loc, double range) {
    113. List<Player> players = new ArrayList<Player>();
    114. double sqr = range * range;
    115. for (Player p : loc.getWorld().getPlayers())
    116. if (p.getLocation().distanceSquared(loc) <= sqr)
    117. players.add(p);
    118. return players;
    119. }
    120.  
    121. private static Object createPacket(String name, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    122. if (amount <= 0)
    123. throw new IllegalArgumentException("Amount of particles has to be greater than 0");
    124. try {
    125. Object p = PARTICLE_PACKET_CONSTRUCTOR.newInstance();
    126. ReflectionUtil.setValues(p, new FieldEntry("a", name), new FieldEntry("b", (float) loc.getX()), new FieldEntry("c", (float) loc.getY()), new FieldEntry("d", (float) loc.getZ()), new FieldEntry("e",
    127. offsetX), new FieldEntry("f", offsetY), new FieldEntry("g", offsetZ), new FieldEntry("h", speed), new FieldEntry("i", amount));
    128. return p;
    129. } catch (Exception e) {
    130. Bukkit.getLogger().warning("[ParticleEffect] Failed to create a particle packet!");
    131. return null;
    132. }
    133. }
    134.  
    135. private Object createPacket(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    136. return createPacket(this.getName(), loc, offsetX, offsetY, offsetZ, speed, amount);
    137. }
    138.  
    139. private static Object createIconCrackPacket(int id, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    140. return createPacket("iconcrack_" + id, loc, offsetX, offsetY, offsetZ, speed, amount);
    141. }
    142.  
    143. private static Object createBlockCrackPacket(int id, byte data, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    144. return createPacket("blockcrack_" + id + "_" + data, loc, offsetX, offsetY, offsetZ, speed, amount);
    145. }
    146.  
    147. private static Object createBlockDustPacket(int id, byte data, Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    148. return createPacket("blockdust_" + id + "_" + data, loc, offsetX, offsetY, offsetZ, speed, amount);
    149. }
    150.  
    151. private static void sendPacket(Player p, Object packet) {
    152. if (packet != null)
    153. try {
    154. Object entityPlayer = ReflectionUtil.invokeMethod("getHandle", p.getClass(), p);
    155. Object playerConnection = ReflectionUtil.getValue("playerConnection", entityPlayer);
    156. ReflectionUtil.invokeMethod("sendPacket", playerConnection.getClass(), playerConnection, packet);
    157. } catch (Exception e) {
    158. Bukkit.getLogger().warning("[ParticleEffect] Failed to send a particle packet to " + p.getName() + "!");
    159. }
    160. }
    161.  
    162. private static void sendPacket(Collection<Player> players, Object packet) {
    163. for (Player p : players)
    164. sendPacket(p, packet);
    165. }
    166.  
    167. /**
    168. * Displays a particle effect which is only visible for specific players
    169. */
    170. public void display(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    171. sendPacket(Arrays.asList(players), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
    172. }
    173.  
    174. /**
    175. * Displays a particle effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    176. */
    177. public void display(Location loc, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    178. display(loc, MAX_RANGE, offsetX, offsetY, offsetZ, speed, amount);
    179. }
    180.  
    181. /**
    182. * Displays a particle effect which is visible for all players whitin a certain range in the the world of @param loc
    183. */
    184. public void display(Location loc, double range, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    185. if (range > MAX_RANGE)
    186. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    187. sendPacket(getPlayersInRange(loc, range), createPacket(loc, offsetX, offsetY, offsetZ, speed, amount));
    188. }
    189.  
    190. /**
    191. * Displays an icon crack (item break) effect which is only visible for specific players
    192. */
    193. public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    194. sendPacket(Arrays.asList(players), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
    195. }
    196.  
    197. /**
    198. * Displays an icon crack (item break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    199. */
    200. public static void displayIconCrack(Location loc, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    201. displayIconCrack(loc, MAX_RANGE, id, offsetX, offsetY, offsetZ, speed, amount);
    202. }
    203.  
    204. /**
    205. * Displays an icon crack (item break) effect which is visible for all players whitin a certain range in the the world of @param loc
    206. */
    207. public static void displayIconCrack(Location loc, double range, int id, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    208. if (range > MAX_RANGE)
    209. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    210. sendPacket(getPlayersInRange(loc, range), createIconCrackPacket(id, loc, offsetX, offsetY, offsetZ, speed, amount));
    211. }
    212.  
    213. /**
    214. * Displays a block crack (block break) effect which is only visible for specific players
    215. */
    216. public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    217. sendPacket(Arrays.asList(players), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    218. }
    219.  
    220. /**
    221. * Displays a block crack (block break) effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    222. */
    223. public static void displayBlockCrack(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    224. displayBlockCrack(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
    225. }
    226.  
    227. /**
    228. * Displays a block crack (block break) effect which is visible for all players whitin a certain range in the the world of @param loc
    229. */
    230. public static void displayBlockCrack(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    231. if (range > MAX_RANGE)
    232. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    233. sendPacket(getPlayersInRange(loc, range), createBlockCrackPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    234. }
    235.  
    236. /**
    237. * Displays a block dust effect which is only visible for specific players
    238. */
    239. public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Player... players) {
    240. sendPacket(Arrays.asList(players), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    241. }
    242.  
    243. /**
    244. * Displays a block dust effect which is visible for all players whitin the maximum range of 20 blocks in the world of @param loc
    245. */
    246. public static void displayBlockDust(Location loc, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    247. displayBlockDust(loc, MAX_RANGE, id, data, offsetX, offsetY, offsetZ, speed, amount);
    248. }
    249.  
    250. /**
    251. * Displays a block dust effect which is visible for all players whitin a certain range in the the world of @param loc
    252. */
    253. public static void displayBlockDust(Location loc, double range, int id, byte data, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
    254. if (range > MAX_RANGE)
    255. throw new IllegalArgumentException("Range has to be lower/equal the maximum of 20");
    256. sendPacket(getPlayersInRange(loc, range), createBlockDustPacket(id, data, loc, offsetX, offsetY, offsetZ, speed, amount));
    257. }
    258. }
    259.  
    260.  
    261.  


    RefelctionUtil:
    Code:java
    1. package me.HeavyMine13.hj;
    2. import java.lang.reflect.Constructor;
    3. import java.lang.reflect.Field;
    4. import java.lang.reflect.Method;
    5. import java.util.HashMap;
    6. import java.util.Map;
    7.  
    8. import org.bukkit.Bukkit;
    9.  
    10. /**
    11. * ReflectionUtil v1.1
    12. *
    13. * You are welcome to use it, modify it and redistribute it under the condition to not claim this class as your own
    14. *
    15. * @author DarkBlade12
    16. */
    17. public abstract class ReflectionUtil {
    18. private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<Class<?>, Class<?>>();
    19.  
    20. static {
    21. CORRESPONDING_TYPES.put(Byte.class, byte.class);
    22. CORRESPONDING_TYPES.put(Short.class, short.class);
    23. CORRESPONDING_TYPES.put(Integer.class, int.class);
    24. CORRESPONDING_TYPES.put(Long.class, long.class);
    25. CORRESPONDING_TYPES.put(Character.class, char.class);
    26. CORRESPONDING_TYPES.put(Float.class, float.class);
    27. CORRESPONDING_TYPES.put(Double.class, double.class);
    28. CORRESPONDING_TYPES.put(Boolean.class, boolean.class);
    29. }
    30.  
    31. public enum DynamicPackage {
    32. MINECRAFT_SERVER {
    33. @Override
    34. public String toString() {
    35. return "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().substring(23, 30);
    36. }
    37. },
    38. CRAFTBUKKIT {
    39. @Override
    40. public String toString() {
    41. return Bukkit.getServer().getClass().getPackage().getName();
    42. }
    43. };
    44. }
    45.  
    46. public static class FieldEntry {
    47. String key;
    48. Object value;
    49.  
    50. public FieldEntry(String key, Object value) {
    51. this.key = key;
    52. this.value = value;
    53. }
    54.  
    55. public String getKey() {
    56. return this.key;
    57. }
    58.  
    59. public Object getValue() {
    60. return this.value;
    61. }
    62. }
    63.  
    64. private static Class<?> getPrimitiveType(Class<?> clazz) {
    65. return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
    66. }
    67.  
    68. private static Class<?>[] toPrimitiveTypeArray(Object[] objects) {
    69. int a = objects != null ? objects.length : 0;
    70. Class<?>[] types = new Class<?>[a];
    71. for (int i = 0; i < a; i++)
    72. types[I] = getPrimitiveType(objects[I].getClass());[/I][/I]
    73.  
    74. [I][I] return types;[/I][/I]
    75. [I][I] }[/I][/I]
    76.  
    77. [I][I] private static Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {[/I][/I]
    78. [I][I] int a = classes != null ? classes.length : 0;[/I][/I]
    79. [I][I] Class<?>[] types = new Class<?>[a];[/I][/I]
    80. [I][I] for (int i = 0; i < a; i++)[/I][/I]
    81. [I][I] types[I] = getPrimitiveType(classes[I]);[/I][/I][/I][/I]
    82.  
    83. [I][I] return types;[/I][/I]
    84. [I][I] }[/I][/I]
    85.  
    86. [I][I] private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {[/I][/I]
    87. [I][I] if (a.length != o.length)[/I][/I]
    88. [I][I] return false;[/I][/I]
    89. [I][I] for (int i = 0; i < a.length; i++)[/I][/I]
    90. [I][I] if (!a[I].equals(o[I]) && !a[I].isAssignableFrom(o[I]))[/I][/I][/I][/I][/I][/I]
    91.  
    92. [I][I] return false;[/I][/I]
    93. [I][I] return true;[/I][/I]
    94. [I][I] }[/I][/I]
    95.  
    96. [I][I] public static Class<?> getClass(String name, DynamicPackage pack, String subPackage) throws Exception {[/I][/I]
    97. [I][I] return Class.forName(pack + (subPackage != null && subPackage.length() > 0 ? "." + subPackage : "") + "." + name);[/I][/I]
    98. [I][I] }[/I][/I]
    99.  
    100. [I][I] public static Class<?> getClass(String name, DynamicPackage pack) throws Exception {[/I][/I]
    101. [I][I] return getClass(name, pack, null);[/I][/I]
    102. [I][I] }[/I][/I]
    103.  
    104. [I][I] public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... paramTypes) {[/I][/I]
    105. [I][I] Class<?>[] t = toPrimitiveTypeArray(paramTypes);[/I][/I]
    106. [I][I] for (Constructor<?> c : clazz.getConstructors()) {[/I][/I]
    107. [I][I] Class<?>[] types = toPrimitiveTypeArray(c.getParameterTypes());[/I][/I]
    108. [I][I] if (equalsTypeArray(types, t))[/I][/I]
    109. [I][I] return c;[/I][/I]
    110. [I][I] }[/I][/I]
    111. [I][I] return null;[/I][/I]
    112. [I][I] }[/I][/I]
    113.  
    114. [I][I] public static Object newInstance(Class<?> clazz, Object... args) throws Exception {[/I][/I]
    115. [I][I] return getConstructor(clazz, toPrimitiveTypeArray(args)).newInstance(args);[/I][/I]
    116. [I][I] }[/I][/I]
    117.  
    118. [I][I] public static Object newInstance(String name, DynamicPackage pack, String subPackage, Object... args) throws Exception {[/I][/I]
    119. [I][I] return newInstance(getClass(name, pack, subPackage), args);[/I][/I]
    120. [I][I] }[/I][/I]
    121.  
    122. [I][I] public static Object newInstance(String name, DynamicPackage pack, Object... args) throws Exception {[/I][/I]
    123. [I][I] return newInstance(getClass(name, pack, null), args);[/I][/I]
    124. [I][I] }[/I][/I]
    125.  
    126. [I][I] public static Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {[/I][/I]
    127. [I][I] Class<?>[] t = toPrimitiveTypeArray(paramTypes);[/I][/I]
    128. [I][I] for (Method m : clazz.getMethods()) {[/I][/I]
    129. [I][I] Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());[/I][/I]
    130. [I][I] if (m.getName().equals(name) && equalsTypeArray(types, t))[/I][/I]
    131. [I][I] return m;[/I][/I]
    132. [I][I] }[/I][/I]
    133. [I][I] return null;[/I][/I]
    134. [I][I] }[/I][/I]
    135.  
    136. [I][I] public static Object invokeMethod(String name, Class<?> clazz, Object obj, Object... args) throws Exception {[/I][/I]
    137. [I][I] return getMethod(name, clazz, toPrimitiveTypeArray(args)).invoke(obj, args);[/I][/I]
    138. [I][I] }[/I][/I]
    139.  
    140. [I][I] public static Field getField(String name, Class<?> clazz) throws Exception {[/I][/I]
    141. [I][I] return clazz.getDeclaredField(name);[/I][/I]
    142. [I][I] }[/I][/I]
    143.  
    144. [I][I] public static Object getValue(String name, Object obj) throws Exception {[/I][/I]
    145. [I][I] Field f = getField(name, obj.getClass());[/I][/I]
    146. [I][I] f.setAccessible(true);[/I][/I]
    147. [I][I] return f.get(obj);[/I][/I]
    148. [I][I] }[/I][/I]
    149.  
    150. [I][I] public static void setValue(Object obj, FieldEntry entry) throws Exception {[/I][/I]
    151. [I][I] Field f = getField(entry.getKey(), obj.getClass());[/I][/I]
    152. [I][I] f.setAccessible(true);[/I][/I]
    153. [I][I] f.set(obj, entry.getValue());[/I][/I]
    154. [I][I] }[/I][/I]
    155.  
    156. [I][I] public static void setValues(Object obj, FieldEntry... entrys) throws Exception {[/I][/I]
    157. [I][I] for (FieldEntry f : entrys)[/I][/I]
    158. [I][I] setValue(obj, f);[/I][/I]
    159. [I][I] }[/I][/I]
    160. [I][I] }[/I][/I]
    161.  
    162.  
    163. [I][I][/I][/I]


    Bump! No one wanna help? D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    NoLiver92

    Dont bump within 24 hours. someone will help you when they can. dont be impatient
     
  3. Offline

    HeavyMine13

    Ok i didnt know that sorry D:
     
  4. Offline

    NoLiver92

    you should because ive told you several times
     
  5. Offline

    DarkBladee12

    HeavyMine13 Are you running your plugin on a 1.7 Bukkit server?
     
  6. Offline

    HeavyMine13

    Nope, 1.6.4

    DarkBladee12 What shall I do now?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    DarkBladee12

    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page