EnderDragon health bar message

Discussion in 'Plugin Development' started by bman7842, Dec 4, 2013.

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

    bman7842

    Hello, I have been recently working on a lobby plugin and I want it to have a boss health bar message at the top. I tried one tutorial but it used the Wither's bar and that made the map darken and had many issues. Basically, I need help, or possibly a tutorial on how I would make this thing. I guess this kinda should be in plugin request so feel free to move it but basically all I need is someone to help me/make me a plugin that makes a ender dragon health bar appear on your screen and you can change the message kinda like ChaseChocolate's. I know that it will involve spawning enderdragons and other stuff but I really don't know how to do it so if someone can make one for me so I can use that for help that would be great! Also, I do not want any configs made or anything. I just want it all changeable in the script, I will add that other stuff by myself! Thanks guys!
    My skype: bman7842
     
  2. Offline

    malandrix_bunny

  3. Offline

    bman7842

    malandrix_bunny I thought his tutorial was only on making a Wither boss message.

    Still need help guys! If anyone knows a good plugin I can look at the code that would be nice, I need help!

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

    iiHeroo


    Bump once every 24h, but the 'Boss' is the Ender Dragon.
     
  5. Offline

    bman7842

    iiHeroo What do you mean the Boss is the EnderDragon?
     
  6. Offline

    iiHeroo


    His tutorial is for the EnderDragon.
     
  7. Offline

    bman7842

    iiHeroo oh it is? I can never get his tutorial to work ...
     
  8. Offline

    iiHeroo


    Just Tahg him and I'm sure he'll be glad to help you :D!
     
  9. Offline

    bman7842

    chasechocolate I need help with your boss message thing and tons of errors are showing. Lets start with the PacketUtils file. I have it in a package just like yours: com.chasechocolate.example
    Here is PacketUtils class:
    Code:java
    1. package com.chasechocolate.example;
    2.  
    3. import java.lang.reflect.Field;
    4. import java.util.HashMap;
    5.  
    6. import net.minecraft.server.v1_6_R2.DataWatcher;
    7. import net.minecraft.server.v1_6_R2.EntityPlayer;
    8. import net.minecraft.server.v1_6_R2.Packet;
    9. import net.minecraft.server.v1_6_R2.Packet205ClientCommand;
    10. import net.minecraft.server.v1_6_R2.Packet24MobSpawn;
    11. import net.minecraft.server.v1_6_R2.Packet29DestroyEntity;
    12. import net.minecraft.server.v1_6_R2.Packet40EntityMetadata;
    13.  
    14. import org.bukkit.Location;
    15. import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
    16. import org.bukkit.entity.EntityType;
    17. import org.bukkit.entity.Player;
    18. import org.bukkit.scheduler.BukkitRunnable;
    19.  
    20. public class PacketUtils {
    21. public static final int ENTITY_ID = 1234;
    22.  
    23. private static HashMap<String, Boolean> hasHealthBar = new HashMap<String, Boolean>();
    24.  
    25. public static void sendPacket(Player player, Packet packet){
    26. EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    27.  
    28. entityPlayer.playerConnection.sendPacket(packet);
    29. }
    30.  
    31. //Accessing packets
    32. public static Packet24MobSpawn getMobPacket(String text, Location loc){
    33. Packet24MobSpawn mobPacket = new Packet24MobSpawn();
    34.  
    35. mobPacket.a = (int) ENTITY_ID; //Entity ID
    36. mobPacket.b = (byte) EntityType.WITHER.getTypeId(); //Mob type (ID: 64)
    37. mobPacket.c = (int) Math.floor(loc.getBlockX() * 32.0D); //X position
    38. mobPacket.d = (int) Math.floor(loc.getBlockY() * 32.0D); //Y position
    39. mobPacket.e = (int) Math.floor(loc.getBlockZ() * 32.0D); //Z position
    40. mobPacket.f = (byte) 0; //Pitch
    41. mobPacket.g = (byte) 0; //Head Pitch
    42. mobPacket.h = (byte) 0; //Yaw
    43. mobPacket.i = (short) 0; //X velocity
    44. mobPacket.j = (short) 0; //Y velocity
    45. mobPacket.k = (short) 0; //Z velocity
    46.  
    47. DataWatcher watcher = getWatcher(text, 300);
    48.  
    49. try{
    50. Field t = Packet24MobSpawn.class.getDeclaredField("t");
    51.  
    52. t.setAccessible(true);
    53. t.set(mobPacket, watcher);
    54. } catch(Exception e){
    55. e.printStackTrace();
    56. }
    57.  
    58. return mobPacket;
    59. }
    60.  
    61. public static Packet29DestroyEntity getDestroyEntityPacket(){
    62. Packet29DestroyEntity packet = new Packet29DestroyEntity();
    63.  
    64. packet.a = new int[]{ENTITY_ID};
    65.  
    66. return packet;
    67. }
    68.  
    69. public static Packet40EntityMetadata getMetadataPacket(DataWatcher watcher){
    70. Packet40EntityMetadata metaPacket = new Packet40EntityMetadata();
    71.  
    72. metaPacket.a = (int) ENTITY_ID;
    73.  
    74. try{
    75. Field b = Packet40EntityMetadata.class.getDeclaredField("b");
    76.  
    77. b.setAccessible(true);
    78. b.set(metaPacket, watcher.c());
    79. } catch(Exception e){
    80. e.printStackTrace();
    81. }
    82.  
    83. return metaPacket;
    84. }
    85.  
    86. public static Packet205ClientCommand getRespawnPacket(){
    87. Packet205ClientCommand packet = new Packet205ClientCommand();
    88.  
    89. packet.a = (int) 1;
    90.  
    91. return packet;
    92. }
    93.  
    94. public static DataWatcher getWatcher(String text, int health){
    95. DataWatcher watcher = new DataWatcher();
    96.  
    97. watcher.a(0, (Byte) (byte) 0x20); //Flags, 0x20 = invisible
    98. watcher.a(6, (Float) (float) health);
    99. watcher.a(10, (String) text); //Entity name
    100. watcher.a(11, (Byte) (byte) 1); //Show name, 1 = show, 0 = don't show
    101. //watcher.a(16, (Integer) (int) health); //Wither health, 300 = full health
    102.  
    103. return watcher;
    104. }
    105.  
    106. //Other methods
    107. public static void displayTextBar(String text, final Player player){
    108. Packet24MobSpawn mobPacket = getMobPacket(text, player.getLocation());
    109.  
    110. sendPacket(player, mobPacket);
    111. hasHealthBar.put(player.getName(), true);
    112.  
    113. new BukkitRunnable(){
    114. @Override
    115. public void run(){
    116. Packet29DestroyEntity destroyEntityPacket = getDestroyEntityPacket();
    117.  
    118. sendPacket(player, destroyEntityPacket);
    119. hasHealthBar.put(player.getName(), false);
    120. }
    121. }.runTaskLater(announcer.getInstance(), 120L);
    122. }
    123.  
    124. public static void displayLoadingBar(final String text, final String completeText, final Player player, final int healthAdd, final long delay, final boolean loadUp){
    125. Packet24MobSpawn mobPacket = getMobPacket(text, player.getLocation());
    126.  
    127. sendPacket(player, mobPacket);
    128. hasHealthBar.put(player.getName(), true);
    129.  
    130. new BukkitRunnable(){
    131. int health = (loadUp ? 0 : 300);
    132.  
    133. @Override
    134. public void run(){
    135. if((loadUp ? health < 300 : health > 0)){
    136. DataWatcher watcher = getWatcher(text, health);
    137. Packet40EntityMetadata metaPacket = getMetadataPacket(watcher);
    138.  
    139. sendPacket(player, metaPacket);
    140.  
    141. if(loadUp){
    142. health += healthAdd;
    143. } else {
    144. health -= healthAdd;
    145. }
    146. } else {
    147. DataWatcher watcher = getWatcher(text, (loadUp ? 300 : 0));
    148. Packet40EntityMetadata metaPacket = getMetadataPacket(watcher);
    149. Packet29DestroyEntity destroyEntityPacket = getDestroyEntityPacket();
    150.  
    151. sendPacket(player, metaPacket);
    152. sendPacket(player, destroyEntityPacket);
    153. hasHealthBar.put(player.getName(), false);
    154.  
    155. //Complete text
    156. Packet24MobSpawn mobPacket = getMobPacket(completeText, player.getLocation());
    157.  
    158. sendPacket(player, mobPacket);
    159. hasHealthBar.put(player.getName(), true);
    160.  
    161. DataWatcher watcher2 = getWatcher(completeText, 300);
    162. Packet40EntityMetadata metaPacket2 = getMetadataPacket(watcher2);
    163.  
    164. sendPacket(player, metaPacket2);
    165.  
    166. new BukkitRunnable(){
    167. @Override
    168. public void run(){
    169. Packet29DestroyEntity destroyEntityPacket = getDestroyEntityPacket();
    170.  
    171. sendPacket(player, destroyEntityPacket);
    172. hasHealthBar.put(player.getName(), false);
    173. }
    174. }.runTaskLater(announcer.getInstance(), 40L);
    175.  
    176. this.cancel();
    177. }
    178. }
    179. }.runTaskTimer(announcer.getInstance(), delay, delay);
    180. }
    181.  
    182. public static void displayLoadingBar(final String text, final String completeText, final Player player, final int secondsDelay, final boolean loadUp){
    183. final int healthChangePerSecond = 300 / secondsDelay;
    184.  
    185. displayLoadingBar(text, completeText, player, healthChangePerSecond, 20L, loadUp);
    186. }
    187. }

    In my other class called announcer located in the package: me.bman7842.importantmessage
    Here is the code for announcer class:
    Code:java
    1. package me.bman7842.importantmessage;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. import com.chasechocolate.example.PacketUtils;
    11.  
    12. public class announcer extends JavaPlugin implements Listener {
    13.  
    14. @EventHandler
    15. public void onPlayerJoin(PlayerJoinEvent e) {
    16. BarAPI.displayBar(player, "Some message", 75.0F, 3, true);
    17. }
    18.  
    19. public void onEnable() {
    20. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    21. }
    22. }

    I tried following your tutorial and I used at least I think the latest version since version 2 is still not out on the thread. And I used the latest way of displaying it but it still will not work. I also changed all the MinecraftFPS things to the class announcer like you said. I just don't know what else I am suppose to do. Please help! Thanks.
     
Thread Status:
Not open for further replies.

Share This Page