[Tutorial] Utilizing the Boss Health Bar

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

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

    Stevenpcc

    I've been using the BarAPI implementation of this, and have come across a problem. The dragon is spawned at Y -200. A bunch of explosion effects can be seen there (the dragon). These effects move up the map and eventually cause severe lag on the client side. The only way to stop this lag is to send the destroy packet (or relog). The lag only affects the person receiving the initial mob packets.

    I have tried running a task to send the teleport entity packet, but this has no effect on the movement of the explosion animation. I've checked the BarAPI source code to make sure the mob velocity is set to zero. I've tried tweaking various things but no luck.

    Here is a video of it happening. You can see it starting to lag near the end. Eventually I would drop down to rates of around 7 fps
     
  2. Offline

    super292

    I'm not sure I understand this ( Rather New to java :/ ) If my main class is called TextPlugin, and I have this line of code: " public static TextPlugin plugin; " Does that mean I replace the MinecraftFPS.getInstance() with "plugin" or make it plugin.getInstance(). Pretty confused :(
     
  3. Offline

    kreashenz

    When using this code
    Code:java
    1. sendAll("§6" + pName + " §7is sexually slaughtering everyone with a §6100 §7killstreak!", 80);
    Everyone on the server gets kicked.. I haven't been online at the times it's happened, but it has been happening.
    The sendAll method is
    Code:java
    1. private void sendAll(String msg, int time){
    2. for(Player ps : Bukkit.getOnlinePlayers()){
    3. BossBar.displayTextBar(plugin, msg, ps, time);
    4. }
    5. }

    Is there like.. a character limit on the bar or something on the bar?
     
  4. Offline

    confuserr

    Yes, anything more than 64 characters (including colour code characters) will cause the player to leave.
     
    kreashenz likes this.
  5. Offline

    soulofw0lf

    chasechocolate I have a problem using this where it is spawning particles around all players, everything else about it is great but is there a way to stop those particles from spawning?

    Edit: nvm they're client side.
     
  6. Offline

    mactown21

    Replace MinecraftFPS With what? And if you have a plugin already made like this may i please have it! Thanks, Im still not quite understanding how this works!
     
  7. Offline

    chasechocolate

    mactown21 the instance of your main class.
     
  8. Offline

    mactown21

    Do you have a plugin that is already made that is like this? and if not do i do this

    instance of my main class.getInstance?
     
  9. Offline

    mattrick

    On the getInstance() method, do I just return null?
     
  10. Offline

    mactown21

    Do you already have this plugin made? and how would i make the main class?
     
  11. Offline

    Ultimate_n00b

    Honestly -_- go learn some java first, and learn how to pass instances to other classes.
     
  12. Offline

    mattrick

    No I don't.
    Were you talking to him or me? I tried returning "this", but the return must be static..... I do know Java, just a question ....
     
  13. Offline

    CraftBang

    Sometimes I look at some certain points and than it won't show up ?
    I use a timer every 5 ticks. and if I look somewhere else it does works.
    Can someone explain me please?
    It's just ONLY when I'm looking at a certain point FROM a certain point.
     
  14. Offline

    DevRosemberg

    chasechocolate What if i want to do something which says:

    Minereach - Welcome to the Network - Minereach

    with the Minereach colors changing?
     
  15. Offline

    chasechocolate

    DevRosemberg something like Mineplex? Just make a repeating task that constantly changes the withers name.
     
  16. Offline

    DevRosemberg

    chasechocolate Yea something like Mineplex. I just tried but it failed, it didnt change the colors. Can you show me how you would do it chase?

    chasechocolate Please, i need this for a Game im working on.

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

    chasechocolate

    DevRosemberg I made a kit in my KitPVP server which does something similar when the kit ability is used. I altered the boss health bar code a bit, I may upload it when I fix some bugs. Here it is so far:
    Code:java
    1. final List<ChatColor> colors = Arrays.asList(ChatColor.RED, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.AQUA, ChatColor.LIGHT_PURPLE);
    2. final String msg = ChatColor.BOLD + "Woo! Colors :D";
    3.  
    4. BarUtils.displayLoadingBar(player, colors.get(0) + msg, ChatColor.WHITE + "" + ChatColor.BOLD + "No more colors D:", time, false);
    5.  
    6. new BukkitRunnable(){
    7. int colorIndex = 0;
    8.  
    9. @Override
    10. public void run(){
    11. if(pornStarMode.contains(player.getName())){
    12. if(colorIndex == colors.size()){
    13. colorIndex = 0;
    14. }
    15.  
    16. ChatColor color = colors.get(colorIndex);
    17.  
    18. BarUtils.setMessage(player, color + msg, true);
    19. } else {
    20. this.cancel();
    21. return;
    22. }
    23. }
    24. }.runTaskTimer(KitPVP.getInstance(), 0L, 4L);

    I'm sure you are capable of altering it a bit to suit my version in the OP. Reply if you need any help :)
     
  18. Offline

    DevRosemberg

    chasechocolate What i just need is to do:

    Minereach (Colors change) - Message - Minereach (Colors change)

    And btw, i have you in skype but you never reply.
     
  19. Offline

    thecrystalflame

    pornstarmode :confused:?
     
  20. Offline

    HeavyMine13

    I made this: (Where to put the message?)

    Code:java
    1. package me.HeavyMine13.hi;
    2. import java.lang.reflect.Field;
    3. import java.util.HashMap;
    4.  
    5. import net.minecraft.server.v1_6_R3.DataWatcher;
    6. import net.minecraft.server.v1_6_R3.EntityPlayer;
    7. import net.minecraft.server.v1_6_R3.Packet205ClientCommand;
    8. import net.minecraft.server.v1_6_R3.Packet24MobSpawn;
    9. import net.minecraft.server.v1_6_R3.Packet29DestroyEntity;
    10. import net.minecraft.server.v1_6_R3.Packet40EntityMetadata;
    11.  
    12. import org.bukkit.Location;
    13. import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
    14. import org.bukkit.entity.EntityType;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.plugin.Plugin;
    17. import org.bukkit.scheduler.BukkitRunnable;
    18.  
    19. public class hi {
    20. public static final int ENTITY_ID = 1234;
    21. private static HashMap<String, Boolean> hasHealthBar = new HashMap<String, Boolean>();
    22. public static void sendPacket(Player player, net.minecraft.server.v1_6_R3.Packet packet){
    23. EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    24. entityPlayer.playerConnection.sendPacket(packet);
    25. }
    26. //Accessing packets
    27. @SuppressWarnings("deprecation")
    28. public static Packet24MobSpawn getMobPacket(String text, Location loc){
    29. Packet24MobSpawn mobPacket = new Packet24MobSpawn();
    30. mobPacket.a = (int) ENTITY_ID; //Entity ID
    31. mobPacket.b = (byte) EntityType.WITHER.getTypeId(); //Mob type (ID: 64)
    32. mobPacket.c = (int) Math.floor(loc.getBlockX() * 32.0D); //X position
    33. mobPacket.d = (int) Math.floor(loc.getBlockY() * 32.0D); //Y position
    34. mobPacket.e = (int) Math.floor(loc.getBlockZ() * 32.0D); //Z position
    35. mobPacket.f = (byte) 0; //Pitch
    36. mobPacket.g = (byte) 0; //Head Pitch
    37. mobPacket.h = (byte) 0; //Yawn
    38. mobPacket.i = (short) 0; //X velocity
    39. mobPacket.j = (short) 0; //Y velocity
    40. mobPacket.k = (short) 0; //Z velocity
    41. DataWatcher watcher = getWatcher(text, 300);
    42. try{
    43. Field t = Packet24MobSpawn.class.getDeclaredField("t");
    44. t.setAccessible(true);
    45. t.set(mobPacket, watcher);
    46. } catch(Exception e){
    47. e.printStackTrace();
    48. }
    49. return mobPacket;
    50. }
    51. public static Packet29DestroyEntity getDestroyEntityPacket(){
    52. Packet29DestroyEntity packet = new Packet29DestroyEntity();
    53. packet.a = new int[]{ENTITY_ID};
    54. return packet;
    55. }
    56. public static Packet40EntityMetadata getMetadataPacket(DataWatcher watcher){
    57. Packet40EntityMetadata metaPacket = new Packet40EntityMetadata();
    58. metaPacket.a = (int) ENTITY_ID;
    59. try{
    60. Field b = Packet40EntityMetadata.class.getDeclaredField("b");
    61. b.setAccessible(true);
    62. b.set(metaPacket, watcher.c());
    63. } catch(Exception e){
    64. e.printStackTrace();
    65. }
    66. return metaPacket;
    67. }
    68. public static Packet205ClientCommand getRespawnPacket(){
    69. Packet205ClientCommand packet = new Packet205ClientCommand();
    70. packet.a = (int) 1;
    71. return packet;
    72. }
    73. public static DataWatcher getWatcher(String text, int health){
    74. DataWatcher watcher = new DataWatcher();
    75. watcher.a(0, (Byte) (byte) 0x20); //Flags, 0x20 = invisible
    76. watcher.a(6, (Float) (float) health);
    77. watcher.a(10, (String) text); //Entity name
    78. watcher.a(11, (Byte) (byte) 1); //Show name, 1 = show, 0 = don't show
    79. //watcher.a(16, (Integer) (int) health); //Wither health, 300 = full health
    80. return watcher;
    81. }
    82. //Other methods
    83. public static void displayTextBar(String text, final Player player){
    84. Packet24MobSpawn mobPacket = getMobPacket(text, player.getLocation());
    85. sendPacket(player, mobPacket);
    86. hasHealthBar.put(player.getName(), true);
    87. new BukkitRunnable(){
    88. @Override
    89. public void run(){
    90. Packet29DestroyEntity destroyEntityPacket = getDestroyEntityPacket();
    91. sendPacket(player, destroyEntityPacket);
    92. hasHealthBar.put(player.getName(), false);
    93. }
    94. }.runTaskLater(hi.getInstance(), 120L);
    95. }
    96. public static void displayLoadingBar(final String text, final String completeText, final Player player, final int healthAdd, final long delay, final boolean loadUp){
    97. Packet24MobSpawn mobPacket = getMobPacket(text, player.getLocation());
    98. sendPacket(player, mobPacket);
    99. hasHealthBar.put(player.getName(), true);
    100. new BukkitRunnable(){
    101. int health = (loadUp ? 0 : 300);
    102. @Override
    103. public void run(){
    104. if((loadUp ? health < 300 : health > 0)){
    105. DataWatcher watcher = getWatcher(text, health);
    106. Packet40EntityMetadata metaPacket = getMetadataPacket(watcher);
    107. sendPacket(player, metaPacket);
    108. if(loadUp){
    109. health += healthAdd;
    110. } else {
    111. health -= healthAdd;
    112. }
    113. } else {
    114. DataWatcher watcher = getWatcher(text, (loadUp ? 300 : 0));
    115. Packet40EntityMetadata metaPacket = getMetadataPacket(watcher);
    116. Packet29DestroyEntity destroyEntityPacket = getDestroyEntityPacket();
    117. sendPacket(player, metaPacket);
    118. sendPacket(player, destroyEntityPacket);
    119. hasHealthBar.put(player.getName(), false);
    120. //Complete text
    121. Packet24MobSpawn mobPacket = getMobPacket(completeText, player.getLocation());
    122. sendPacket(player, mobPacket);
    123. hasHealthBar.put(player.getName(), true);
    124. DataWatcher watcher2 = getWatcher(completeText, 300);
    125. Packet40EntityMetadata metaPacket2 = getMetadataPacket(watcher2);
    126. sendPacket(player, metaPacket2);
    127. new BukkitRunnable(){
    128. @Override
    129. public void run(){
    130. Packet29DestroyEntity destroyEntityPacket = getDestroyEntityPacket();
    131. sendPacket(player, destroyEntityPacket);
    132. hasHealthBar.put(player.getName(), false);
    133. }
    134. }.runTaskLater(hi.getInstance(), 40L);
    135. this.cancel();
    136. }
    137. }
    138. }.runTaskTimer(hi.getInstance(), delay, delay);
    139. }
    140. protected static Plugin getInstance() {
    141. // TODO Auto-generated method stub
    142. return null;
    143. }
    144. public static void displayLoadingBar(final String text, final String completeText, final Player player, final int secondsDelay, final boolean loadUp){
    145. final int healthChangePerSecond = 300 / secondsDelay;
    146. displayLoadingBar(text, completeText, player, healthChangePerSecond, 20L, loadUp);
    147. }
    148. }


    Where Can I set the Text I want?

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

    DarkBladee12

    HeavyMine13 Why don't you try to read the first post in this thread for usage description?
     
  22. Offline

    HeavyMine13

    Last edited by a moderator: Jun 3, 2016
  23. Offline

    RyanTheLeach

    At a guess I'd assume this happens because you have set the health to 0, try setting the health to either max or 1 point left.
     
  24. Offline

    Ape101

    So i'm getting an error here?
    Code:java
    1. public static void sendPacket(Player player, Packet packet){
    2. EntityPlayer entityPlayer = (ERROR START)((CraftPlayer) player)(ERROR END).getHandle();

    CraftPlayer cannot be resolved to a type

    chasechocolate
     
  25. Offline

    chasechocolate

    Ape101 yeah, it's because you have to build against CraftBukkit. I'll update it to a reflection-using class when I get a chance.
     
  26. Offline

    Ape101

    So, for the moment, this is unusable?
     
  27. Offline

    Wout_

    It is usable... (I can use it) but if you don't look at the smoke the bar will dissapear. Verry weird.
     
  28. Offline

    chasechocolate

    CaptainBern and DSH105 like this.
  29. Offline

    darkness1999

    I always get some excetpions on using BarAPI.displayBar(p, chosenbossbarmessage, 100, 10, false);

    What could I have done wrong? I'm using v2. Here are my exceptions:

     
  30. Offline

    chasechocolate

    darkness1999 thanks, I'll look into it.

    //EDIT: Fixed :) check the gist again.
     
Thread Status:
Not open for further replies.

Share This Page