BarAPI
BarAPI
Server Owners
This plugin does nothing on its own. It is simply an API for other plugins to implement with.
Developers
Simply add BarAPI.jar to your project build path.
This plugin makes use of reflection and therefore "shouldn't" break on craftbukkit updates.
Limitations
The message can not be more than 64 characters. If it is more, BarAPI will automatically cut it to 64 characters to prevent the client from crashing.
This is a client limitation and cannot be changed.
Examples
BarAPI.setMessage(Player player, String message)
Set a message for the player. It will remain there until the player logs off or another plugin overrides it.
BarAPI.setMessage(Player player, String message, float percent)
Same as above except you can set the % of the health bar. 100 shows the entire health bar, 50 shows half the health bar and so on.
BarAPI.setMessage(final Player player, String message, int seconds)
Sets a timed message for the player. It will remain until the timer runs out. The health automatically reduces based on how long the timer is.
BarAPI.hasBar(Player player)
Pretty self explanatory, returns a boolean.
BarAPI.removeBar(Player player)
Also pretty self explanatory.
BarAPI.setHealth(Player player, float percent)
Allows you to modify the health of an existing bar. If the player has no bar, this does nothing.
Tutorials
Source
Maven
<repositories> <repository> <id>confuser-repo</id> <url>http://ci.frostcast.net/plugin/repository/everything</url> </repository> </repositories> <dependencies> <dependency> <groupId>me.confuser</groupId> <artifactId>BarAPI</artifactId> <version>3.0</version> </dependency> </dependencies>
Developer Builds
These builds have not been approved by BukkitDev staff, therefore, use at your own risk.
Updater
This plugin contains an auto updater which is enabled by default. If you do not wish to automatically download new updates, edit BarAPI/config.yml and set autoUpdate to false.
To Dos
- Scroll messages if string is greater than 64 characters.
Plugins Using BarAPI
Metrics
To determine popularity and usage of BarAPI, plugin installs are automatically tracked by the Metrics plugin tracking system. Your Java version, OS, player count, server country location and plugin & server versions are collected. This is used to determine what environments are using the plugin to ensure full compatibility. This collection is anonymous. If you don't want this tracking, edit plugins/PluginMetrics/config.yml and set opt-out to true.
Hi!
Is there a function to update the Text in the Bar?
Greetz, HiFiGamer
Awesome plugin!
I will use it in my tntrun plugin.
I'll release a new version once I've added the scrolling messages.
@ronbof
Fixed in the repo. It's to do with teleporting worlds and respawning. The bar will now remain persistent.
@confuser
Fixed the HP bar disappearing problem after freakin' forever (probably like 70 minutes on this one thing).
Still not sure exactly what went wrong, so you can feel free to try to figure it out yourself o_o
But I just needed to add something like this
<<code java>>
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {public void run() { HPBar.removeBar(e2.getPlayer()); plugin.getPD(e2.getPlayer()).updateHealth(); } }, 10); <</code>>
in my PlayerRespawnEvent Listener. Hope this helps if you decide to figure out what's wrong!
@abalabahaha
Good idea.
@Raemis
Strange, I'll take a look into that this weekend as well.
add scrolling message(ticker) when message is longer than 64 chars?
I'm having a slight issue, when I am using a bar as a phase timer for a mini-game I'm developing. The phase itself is lasting exactly X seconds. The bar at the top never makes it to 0% though, it always gets to around 5% by the time it should be hitting 0%. I'm not sure why, as the bar goes all the way to zero when counting down, it just isn't being precise when another time is running.
@ronbof
Thank you, that will be helpful for when I debug.
@confuser
Thanks, look forward to what you find!
Got some more info on the problem in case you want it: Problem has nothing to do with the FakeDragon reaching 0 health - I made it unable to fall under 1/3 health and it still disappeared when I died. As far as I can tell this is triggered solely by player respawn. I removed all usage of your API except ONE setMessage() called ONCE through a command. Once the command was used, the bar appeared. I used /suicide (health bar thus remained full), and died. Health bar disappeared 4-5 sec after respawn, as always :(. Bar only disappears after the Respawn button is clicked, not just the death itself
The player is NOT removed from the players HashMap (thus, removeBar() is never called)
So basically it's definitely caused by a player dying and then respawning. Whether it's something to do with packets or something that the PlayerRespawnEvent does, I can't say for sure.
@ronbof
Hmm I'll take a look this weekend.
Hi! I'm having an issue with the bar staying there after player death. I'm using the boss bar to display a player's health. When he dies, the bar becomes empty since it has reached 0. But, when the player respawns, after 4 seconds (I counted out 4 seconds every time when I was retrying this), the bar disappears entirely. During those 4 seconds, the bar does not update, and remains at 0 HP. The player's real HP is reset to full as it should be on respawn, but the bar still shows 0 HP. I am calling my updateBar() method, which uses BarAPI.setMessage(), in my listener for PlayerRespawnEvent. updateBar() is also scheduled as a repeating task, and the task is still being called, which means that BarAPI.setMessage() is still being called even though the bar doesn't show up at all. Using BarAPI.hasBar(player) returns true, but the bar does not show. If I use /reload, the bar appears again, but upon another death the bar disappears again. Any idea what's wrong?
Also, I just tried using /suicide to test. Upon death, the health bar displayed full HP, since I didn't really take any damage. But the same thing happened - after a couple seconds, the bar disappeared.
I also just tried respawning, and then quickly taking damage after respawning but before the bar disappears. My actual HP drops, but the bar does not update, and then just disappears.
It might be worth noting that I am using a custom HP system based on raw numbers rather than hearts, but I don't think that's the issue here.
Hey, is this plugin compiled with Java 6, or 7. I'm getting an error indicating that it's Java 7, while many servers only run Java 6. Here's the log.
Edit: Submitted a pull request on Github. I tested the code with just changing the compiler version, and it works like a charm.
@confuser
Check out this video of what happens
https://www.youtube.com/watch?v=VME9EZ5CzcA
@Stevenpcc
Strange, I use this on our HG server with 200+ players and no one has complained of lag before.
@Stevenpcc
Did some more looking into it. There is an explosion effect that movies up from -200. The further up it goes the more it lags. I compiled my own version of BarAPI and messed around with the starting y value. -50 made the lag happen sooner. Higher values like 250 and 500 eventually started to lag, but then stopped (the bar also disappeared along with the lag). It's like the dragon is flying away and causing a bunch of lag in the process.
Found a bug with this. Over time it will cause serious client lag (a few minutes is all it takes). The lag just gets worse and worse until the removebar method is called.
Would be very epic if anyone could make like a visibility & thirst system, using the boss bar (BarAPI)... I understand if you don't have time/don't want to, and I'm not going to beg.
Parkour will be using this in next version :)
Thanks for sharing, we use this and your ban management plugin on all our servers!