[Tutorial] Utilizing the Boss Health Bar

Discussion in 'Resources' started by chasechocolate, Jul 5, 2013.

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

    DevRosemberg

    chasechocolate Chase im still trying to create the Mineplex Style Bar to be like:

    Code:java
    1. The Cosmos (colors change) - Message - The Cosmos (colors change acording to the first The Cosmos)


    But i dont get it to work. Please can you help me, ive asked you this through skype, PM and even here but you dont seem to reply to it.
     
  2. Offline

    DrJava

    DevRosemberg
    You could convert your string (message) into an array; every character is an item in the array. Every 3 ticks, get the next item in the array and change the colour; put the character behind it back to its default colour. Then, send the player the GUI message.
     
  3. Offline

    rickydaan

    chasechocolate

    The NMS packages seem not to be imported. I tried to download the latest IP but alot of things are still red underlined (Yes, I did replace YourPluginMain with my class extending JavaPlugin.)
     
  4. Offline

    DrJava

    You need craft bukkit for this if you're building against 1.7.2 as there is no reflection as of yet.
     
  5. Offline

    rickydaan

    DrJava
    Can I build upon both of them?

    PS: Nevermind, I already found out that's impossible and I fixed the bugs in my plugin

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

    ShearsSheep

    Nice!!! Chu have outdid yourself this time :D :D :D
     
  7. SoThatsIt
    Hey, I have a question do I add a Main class file? Cause I keep getting an error as I try using it
    here is the error:
    [20:14:01] [Server thread/ERROR]: Could not load 'plugins\Welcome.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassCastException: class com.sharrettcraft.wither.General
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184) ~[spigot.jar:git-Spigot-1172]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:306) ~[spigot.jar:git-Spigot-1172]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230) [spigot.jar:git-Spigot-1172]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:259) [spigot.jar:git-Spigot-1172]
    at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:133) [spigot.jar:git-Spigot-1172]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:426) [spigot.jar:git-Spigot-1172]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [spigot.jar:git-Spigot-1172]
    Caused by: java.lang.ClassCastException: class com.sharrettcraft.wither.General
    at java.lang.Class.asSubclass(Unknown Source) ~[?:1.7.0_25]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:174) ~[spigot.jar:git-Spigot-1172]
    ... 6 more
     
  8. Offline

    iZanax

    BarAPI is a really nice feature to display text to the screen.
    I just have one issue which cause some problems.
    This version is not compatible with player changing a world.
    I tried to figure it out by myself. but these packets (Packet24MobSpawn / Packet34EntityTeleport)
    does not seem to have a world declaration.
    So how can I make it world consistence?
    Thanks in advance!
     
  9. Offline

    Bart

    With a player changing world? If you need to update the message that shows on the screen when the player changes world, just listen for the event and update it with a new message set to only that player.
     
  10. Offline

    iZanax

    Bart
    PHP:
        public static void displayBar(Player playerString msgfloat percent){
            
    setMessage(playermsg);
            
    setPercent(playerpercent);
        }
    I call this method every second for a period of time.
    So this will indeed update the message/procent.
    But it will not pop up anymore if the player changed world.
    I gues the Bar is still in the other world, at the player coordinates.
     
  11. Offline

    Traks

    I know what 0, 6, 10 and 11 mean when invoking the 'a' method, but what do 7 and 8 mean?

    BTW, thanks for those 2 classes, they're very useful (especially reflection utils)!
     
  12. Offline

    SoThatsIt

    i may be wrong but off the top of my head i believe 7 is the potion effect colour as a BGR value but im not sure about 8
     
  13. Offline

    IanM_56

    chasechocolate What do I do about the particle effects and diming of the screen while displaying the bar?
     
  14. Offline

    DrJava

    What? There should be no particle effects or diming of the screen?
     
  15. Offline

    sgavster

    IanM_56 That's the mob spawning.. :/
     
  16. Offline

    Drkmaster83

    This is true, and when you attempt to spawn an Enderdragon, it's visible. When spawning a wither, you get a dim outlook as if you're in a despairing wasteland, and the smoke particles spawn wherever you travel.
     
  17. Offline

    DrJava

    Why use a wither? If so, why did he modify the location code? This spawns the mobs 200 blocks below the player.
     
  18. Offline

    sipsi133

    Does this work with Craftbukkit/Spigot 1.7.2 and 1.7.4?

    EDIT: It works but the bar disappears after few seconds.
     
  19. Offline

    HeavyMine13

  20. Offline

    Drkmaster83

    I believe that the mob spawns in your face, but is supposed to spawn with an invisible flag in the DataWatcher dataWatcher.a(0, "0x20");

    The bar disappears when you look away from the location that the mob was spawned on.
     
  21. Offline

    DrJava

    No, it actually spawns 200 blocks below you.
     
  22. Offline

    Drkmaster83

    Code:
    @SuppressWarnings("deprecation")
    public static PacketPlayOutSpawnEntityLiving getMobPacket(String text, Location loc) {
    PacketPlayOutSpawnEntityLiving mobPacket = new PacketPlayOutSpawnEntityLiving();
     
    try {
    Field a = getField(mobPacket.getClass(), "a");
    a.setAccessible(true);
    a.set(mobPacket, (int) ENTITY_ID);
     
    Field b = getField(mobPacket.getClass(), "b");
    b.setAccessible(true);
    b.set(mobPacket, (byte) EntityType.WITHER.getTypeId());
     
    Field c = getField(mobPacket.getClass(), "c");
    c.setAccessible(true);
    c.set(mobPacket, (int) Math.floor(loc.getBlockX() * 32.0D));
     
    Field d = getField(mobPacket.getClass(), "d");
    d.setAccessible(true);
    d.set(mobPacket, (int) Math.floor(loc.getBlockY() * 32.0D));
     
    Field e = getField(mobPacket.getClass(), "e");
    e.setAccessible(true);
    e.set(mobPacket, (int) Math.floor(loc.getBlockZ() * 32.0D));
     
    Field f = getField(mobPacket.getClass(), "f");
    f.setAccessible(true);
    f.set(mobPacket, (byte) 0);
     
    Field g = getField(mobPacket.getClass(), "g");
    g.setAccessible(true);
    g.set(mobPacket, (byte) 0);
     
    Field h = getField(mobPacket.getClass(), "h");
    h.setAccessible(true);
    h.set(mobPacket, (byte) 0);
     
    Field i = getField(mobPacket.getClass(), "i");
    i.setAccessible(true);
    i.set(mobPacket, (byte) 0);
     
    Field j = getField(mobPacket.getClass(), "j");
    j.setAccessible(true);
    j.set(mobPacket, (byte) 0);
     
    Field k = getField(mobPacket.getClass(), "k");
    k.setAccessible(true);
    k.set(mobPacket, (byte) 0);
     
    } catch (IllegalArgumentException e1) {
    e1.printStackTrace();
    } catch (IllegalAccessException e1) {
    e1.printStackTrace();
    }
     
    DataWatcher watcher = getWatcher(text, 300);
     
    try {
    Field t = PacketPlayOutSpawnEntityLiving.class.getDeclaredField("l");
    t.setAccessible(true);
    t.set(mobPacket, watcher);
    } catch(Exception ex) {
    ex.printStackTrace();
    }
     
    return mobPacket;
    }
    This? Field D?
     
  23. Offline

    DrJava

    Drkmaster83
    Derp. One of the older versions it did.
     
  24. Offline

    Drkmaster83

    So, should I perhaps modify field D to subtract 200? All that I know is that something might be defective with the DataWatcher.
     
  25. Offline

    DrJava

    Yes, set it to subtract 200.
     
  26. Offline

    SoThatsIt

    spawning 200 blocks below will only work with ender dragons as with withers you have to be looking at it for the bar to appear. If you use my version a few pages back it is already fixed with all of this and is updated for 1.7
     
    DrJava likes this.
  27. Offline

    mrpickles71

    So I Get This Error On PlayerJoinEvent... was wondering why

    Code:
    11.01 23:07:39 [Server] INFO ... 14 more
    11.01 23:07:39 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ~[craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_21]
    11.01 23:07:39 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
    11.01 23:07:39 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
    11.01 23:07:39 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_21]
    11.01 23:07:39 [Server] INFO at me.aryaservers.coldwar.ColdWarMain.onPlayerJoin(ColdWarMain.java:49) ~[?:?]
    11.01 23:07:39 [Server] INFO at me.aryaservers.coldwar.BarAPI.displayLoadingBar(BarAPI.java:278) ~[?:?]
    11.01 23:07:39 [Server] INFO Caused by: java.lang.ArithmeticException: / by zero
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) ~[craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:39 [Server] INFO org.bukkit.event.EventException
    11.01 23:07:39 [Server] ERROR Could not pass event PlayerJoinEvent to ColdWar v1.0
    11.01 23:07:39 [Multicraft] mrpickles71 ran command Message of the Day
    11.01 23:07:39 [Connect] User mrpickles71, IP 71.246.9.184
    11.01 23:07:39 [Server] INFO UUID of player mrpickles71 is 4c6201208bf5428c984d2157fb93b273
    11.01 23:07:36 [Server] INFO mrpickles71 left the game.
    11.01 23:07:36 [Disconnect] User mrpickles71 has disconnected, reason: Disconnected
    11.01 23:07:34 [Server] WARN No compatible nms block class found.
    11.01 23:07:25 [Server] INFO ... 14 more
    11.01 23:07:25 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ~[craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_21]
    11.01 23:07:25 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
    11.01 23:07:25 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
    11.01 23:07:25 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_21]
    11.01 23:07:25 [Server] INFO at me.aryaservers.coldwar.ColdWarMain.onPlayerJoin(ColdWarMain.java:49) ~[?:?]
    11.01 23:07:25 [Server] INFO at me.aryaservers.coldwar.BarAPI.displayLoadingBar(BarAPI.java:278) ~[?:?]
    11.01 23:07:25 [Server] INFO Caused by: java.lang.ArithmeticException: / by zero
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) ~[craftbukkit_beta_2974.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    11.01 23:07:25 [Server] INFO org.bukkit.event.EventException
    11.01 23:07:25 [Server] ERROR Could not pass event PlayerJoinEvent to ColdWar v1.0
    11.01 23:07:25 [Multicraft] mrpickles71 ran command Message of the Day
    11.01 23:07:25 [Connect] User mrpickles71, IP 71.246.9.184
    With This Code

    Code:java
    1. package me.aryaservers.coldwar;
    2.  
    3. import java.lang.reflect.Field;
    4. import java.util.HashMap;
    5.  
    6. import net.minecraft.server.v1_7_R1.DataWatcher;
    7. import net.minecraft.server.v1_7_R1.EntityPlayer;
    8. import net.minecraft.server.v1_7_R1.Packet;
    9. import net.minecraft.server.v1_7_R1.PacketPlayInClientCommand;
    10. import net.minecraft.server.v1_7_R1.PacketPlayOutEntityDestroy;
    11. import net.minecraft.server.v1_7_R1.PacketPlayOutEntityMetadata;
    12. import net.minecraft.server.v1_7_R1.PacketPlayOutSpawnEntityLiving;
    13.  
    14. import org.bukkit.Location;
    15. import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
    16. import org.bukkit.entity.EntityType;
    17. import org.bukkit.entity.Player;
    18. import org.bukkit.plugin.Plugin;
    19. import org.bukkit.scheduler.BukkitRunnable;
    20.  
    21. // IMPORTANT
    22. // Remember to change "yourMainClass" to your plugin's main class and "yourPackage" to your package's name
    23. // Original code by chasechocolate
    24. // Modified by ftbastler for Minecraft 1.7
    25.  
    26. public class BarAPI {
    27. public static final int ENTITY_ID = 1234;
    28.  
    29. private static ColdWarMain pl;
    30.  
    31. private static HashMap<String, Boolean> hasHealthBar = new HashMap<String, Boolean>();
    32.  
    33. public static void sendPacket(Player player, Packet packet) {
    34. EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    35.  
    36. entityPlayer.playerConnection.sendPacket(packet);
    37. }
    38.  
    39. public static Field getField(Class<?> cl, String field_name) {
    40. try {
    41. Field field = cl.getDeclaredField(field_name);
    42. return field;
    43. } catch (SecurityException e) {
    44. e.printStackTrace();
    45. } catch (NoSuchFieldException e) {
    46. e.printStackTrace();
    47. }
    48. return null;
    49. }
    50.  
    51. // Accessing packets
    52. @SuppressWarnings("deprecation")
    53. public static PacketPlayOutSpawnEntityLiving getMobPacket(String text,
    54. Location loc) {
    55. PacketPlayOutSpawnEntityLiving mobPacket = new PacketPlayOutSpawnEntityLiving();
    56.  
    57. try {
    58. Field a = getField(mobPacket.getClass(), "a");
    59. a.setAccessible(true);
    60. a.set(mobPacket, (int) ENTITY_ID);
    61.  
    62. Field b = getField(mobPacket.getClass(), "b");
    63. b.setAccessible(true);
    64. b.set(mobPacket, (byte) EntityType.WITHER.getTypeId());
    65.  
    66. Field c = getField(mobPacket.getClass(), "c");
    67. c.setAccessible(true);
    68. c.set(mobPacket, (int) Math.floor(loc.getBlockX() * 32.0D));
    69.  
    70. Field d = getField(mobPacket.getClass(), "d");
    71. d.setAccessible(true);
    72. d.set(mobPacket, (int) Math.floor(loc.getBlockY() * 32.0D));
    73.  
    74. Field e = getField(mobPacket.getClass(), "e");
    75. e.setAccessible(true);
    76. e.set(mobPacket, (int) Math.floor(loc.getBlockZ() * 32.0D));
    77.  
    78. Field f = getField(mobPacket.getClass(), "f");
    79. f.setAccessible(true);
    80. f.set(mobPacket, (byte) 0);
    81.  
    82. Field g = getField(mobPacket.getClass(), "g");
    83. g.setAccessible(true);
    84. g.set(mobPacket, (byte) 0);
    85.  
    86. Field h = getField(mobPacket.getClass(), "h");
    87. h.setAccessible(true);
    88. h.set(mobPacket, (byte) 0);
    89.  
    90. Field i = getField(mobPacket.getClass(), "i");
    91. i.setAccessible(true);
    92. i.set(mobPacket, (byte) 0);
    93.  
    94. Field j = getField(mobPacket.getClass(), "j");
    95. j.setAccessible(true);
    96. j.set(mobPacket, (byte) 0);
    97.  
    98. Field k = getField(mobPacket.getClass(), "k");
    99. k.setAccessible(true);
    100. k.set(mobPacket, (byte) 0);
    101.  
    102. // TODO Auto-generated catch block
    103. e1.printStackTrace();
    104. } catch (IllegalAccessException e1) {
    105. // TODO Auto-generated catch block
    106. e1.printStackTrace();
    107. }
    108.  
    109. DataWatcher watcher = getWatcher(text, 300);
    110.  
    111. try {
    112. Field t = PacketPlayOutSpawnEntityLiving.class
    113. .getDeclaredField("l");
    114. t.setAccessible(true);
    115. t.set(mobPacket, watcher);
    116. } catch (Exception ex) {
    117. ex.printStackTrace();
    118. }
    119.  
    120. return mobPacket;
    121. }
    122.  
    123. public static PacketPlayOutEntityDestroy getDestroyEntityPacket() {
    124. PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy();
    125.  
    126. Field a = getField(packet.getClass(), "a");
    127. a.setAccessible(true);
    128. try {
    129. a.set(packet, new int[] { ENTITY_ID });
    130. e.printStackTrace();
    131. e.printStackTrace();
    132. }
    133.  
    134. return packet;
    135. }
    136.  
    137. public static PacketPlayOutEntityMetadata getMetadataPacket(
    138. DataWatcher watcher) {
    139. PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata();
    140.  
    141. Field a = getField(metaPacket.getClass(), "a");
    142. a.setAccessible(true);
    143. try {
    144. a.set(metaPacket, (int) ENTITY_ID);
    145. e1.printStackTrace();
    146. } catch (IllegalAccessException e1) {
    147. e1.printStackTrace();
    148. }
    149.  
    150. try {
    151. Field b = PacketPlayOutEntityMetadata.class.getDeclaredField("b");
    152. b.setAccessible(true);
    153. b.set(metaPacket, watcher.c());
    154. } catch (Exception e) {
    155. e.printStackTrace();
    156. }
    157.  
    158. return metaPacket;
    159. }
    160.  
    161. public static PacketPlayInClientCommand getRespawnPacket() {
    162. PacketPlayInClientCommand packet = new PacketPlayInClientCommand();
    163.  
    164. Field a = getField(packet.getClass(), "a");
    165. a.setAccessible(true);
    166. try {
    167. a.set(packet, (int) 1);
    168. e.printStackTrace();
    169. e.printStackTrace();
    170. }
    171.  
    172. return packet;
    173. }
    174.  
    175. public static DataWatcher getWatcher(String text, int health) {
    176. DataWatcher watcher = new DataWatcher(null);
    177.  
    178. watcher.a(0, (Byte) (byte) 0x20); // Flags, 0x20 = invisible
    179. watcher.a(6, (Float) (float) health);
    180. watcher.a(10, (String) text); // Entity name
    181. watcher.a(11, (Byte) (byte) 1); // Show name, 1 = show, 0 = don't show
    182. // watcher.a(16, (Integer) (int) health); //Wither health, 300 = full
    183. // health
    184.  
    185. return watcher;
    186. }
    187.  
    188. // Other methods
    189. public static void displayTextBar(String text, final Player player) {
    190. PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text,
    191. player.getLocation());
    192.  
    193. sendPacket(player, mobPacket);
    194. hasHealthBar.put(player.getName(), true);
    195.  
    196. new BukkitRunnable() {
    197. @Override
    198. public void run() {
    199. PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
    200.  
    201. sendPacket(player, destroyEntityPacket);
    202. hasHealthBar.put(player.getName(), false);
    203. }
    204. }.runTaskLater(pl, 120L);
    205. }
    206.  
    207. public static void displayLoadingBar(final String text,
    208. final String completeText, final Player player,
    209. final int healthAdd, final long delay, final boolean loadUp) {
    210. PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(text,
    211. player.getLocation());
    212.  
    213. sendPacket(player, mobPacket);
    214. hasHealthBar.put(player.getName(), true);
    215.  
    216. new BukkitRunnable() {
    217. int health = (loadUp ? 0 : 300);
    218.  
    219. @Override
    220. public void run() {
    221. if ((loadUp ? health < 300 : health > 0)) {
    222. DataWatcher watcher = getWatcher(text, health);
    223. PacketPlayOutEntityMetadata metaPacket = getMetadataPacket(watcher);
    224.  
    225. sendPacket(player, metaPacket);
    226.  
    227. if (loadUp) {
    228. health += healthAdd;
    229. } else {
    230. health -= healthAdd;
    231. }
    232. } else {
    233. DataWatcher watcher = getWatcher(text, (loadUp ? 300 : 0));
    234. PacketPlayOutEntityMetadata metaPacket = getMetadataPacket(watcher);
    235. PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
    236.  
    237. sendPacket(player, metaPacket);
    238. sendPacket(player, destroyEntityPacket);
    239. hasHealthBar.put(player.getName(), false);
    240.  
    241. // Complete text
    242. PacketPlayOutSpawnEntityLiving mobPacket = getMobPacket(
    243. completeText, player.getLocation());
    244.  
    245. sendPacket(player, mobPacket);
    246. hasHealthBar.put(player.getName(), true);
    247.  
    248. DataWatcher watcher2 = getWatcher(completeText, 300);
    249. PacketPlayOutEntityMetadata metaPacket2 = getMetadataPacket(watcher2);
    250.  
    251. sendPacket(player, metaPacket2);
    252.  
    253. new BukkitRunnable() {
    254. @Override
    255. public void run() {
    256. PacketPlayOutEntityDestroy destroyEntityPacket = getDestroyEntityPacket();
    257.  
    258. sendPacket(player, destroyEntityPacket);
    259. hasHealthBar.put(player.getName(), false);
    260. }
    261. }.runTaskLater(pl, 40L);
    262.  
    263. this.cancel();
    264. }
    265. }
    266. }.runTaskTimer(pl, delay, delay);
    267. }
    268.  
    269. public static void displayLoadingBar(final String text,
    270. final String completeText, final Player player,
    271. final int secondsDelay, final boolean loadUp) {
    272. final int healthChangePerSecond = 300 / secondsDelay;
    273.  
    274. displayLoadingBar(text, completeText, player, healthChangePerSecond,
    275. 20L, loadUp);
    276. }
    277. }
     
  28. Offline

    AnomalousRei

    When I use the 1.7 code, it seems to continuously spawn smoke and it disappears if you walk too far away. Any mistakes I've done here?
     
  29. Offline

    Drkmaster83

    Okay, that's fixed... just one thing: The dragon isn't invisible.
     
  30. Offline

    SoThatsIt

    why do you use a wither version :F the only time i can think of when using a wither version would be useful is if you wanted to have different bars when you look at different objects, for example if you had class selection signs and then spawned a wither behind them so that when you looked at that selection sign it could display information about that class.
     
Thread Status:
Not open for further replies.

Share This Page