DavideBlade / HealthBar-Reloaded

Cool health bars above mobs' and players' heads, a must-have for RPG and PvP servers!
https://www.spigotmc.org/resources/healthbar-reloaded.104616/
GNU General Public License v3.0
6 stars 2 forks source link

Add LevelledMobs 4 API Integration for Compatibility #3

Closed lokka30 closed 3 months ago

lokka30 commented 1 year ago

DavideBlade and I are currently discussing in a SpigotMC direct message in how we can collaborate to add LevelledMobs compatibility to HealthBar. I have opened this issue so we remember to solve it at some point. 🙂

UnbeatableSquirrel commented 1 year ago

was asked to comment abiut this very same thing but here is the link to plugin in question! https://www.spigotmc.org/resources/levelledmobs.74304/

hiiamken commented 4 months ago

bump, i need it too

Raidware commented 4 months ago

@stumper66

stumper66 commented 4 months ago

@Raidware

Please explain what is requested from us on this issue regarding LevelledMobs. Do you just want LM mob detection similar to Mythic Mobs?

# Compatibility with other plugins
hooks:
  # If you have MythicMobs, enable this to hide health on mobs of the plugin
  MythicMobs: false

  LevelledMobs: false # ?
Raidware commented 4 months ago

@Raidware

Please explain what is requested from us on this issue regarding LevelledMobs. Do you just want LM mob detection similar to Mythic Mobs?

# Compatibility with other plugins
hooks:
  # If you have MythicMobs, enable this to hide health on mobs of the plugin
  MythicMobs: false

  LevelledMobs: false # ?

YEs

lokka30 commented 4 months ago

@DavideBlade LM4 released some time ago and has an API you can use to get the level of a levelled mob.

If you want to add a boolean option as mentioned just above, to hide the health bar on LM mobs, it's easy - if the mob has a level, then it's a levelled mob. One-liner null check.

If you want to incorporate the mob's level in the health bar, simply use the level integer in that too.

@Raidware ^^ FYI.

DavideBlade commented 4 months ago

If you want to add a boolean option as mentioned just above, to hide the health bar on LM mobs, it's easy - if the mob has a level, then it's a levelled mob. One-liner null check. FYI.

@lokka30 If you remember the conversation from a lifetime ago, the problem was not only that of recognizing mobs with a level so that the health bar plugins could not set a health bar of them (now solved), but that it was not possible to use a health bar plugin on LM mobs as well.

If you want to incorporate the mob's level in the health bar, simply use the level integer in that too.

For this we would need an API that would tell LM “don't set a nametag on this mob” or “use this nametag on your mobs” since LM uses packets in a way that overrides whatever bar is set on the mob. From what I can see from the source code, this is not yet possible. Am I wrong? Am I missing something?

lokka30 commented 4 months ago

@stumper66 ^^ FYI

stumper66 commented 4 months ago

Yeah I'm aware as I get notifications for any updates here. Will be updating the API for this functionality soon.

stumper66 commented 4 months ago

Turns out this has been kind of there this whole time going back to the early 3.x days. There is a MobPreLevelEvent you can subscribe to and it has several methods including one called #showLMNametag. When setting this to false it will prevent LM from sending nametag packets to the mob. However I had forgot this feature existed and it basically doesn't do anything at the moment.

I've fixed this with LevelledMob 4.0.3 which I will be releasing soon as I fix a few issues. Once released I will also post the java (kotlin) docs to make things easier. Here is how it can be accomplished as seen in my tester app:

// must register the listener with Bukkit

public class Listeners implements Listener {
    @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
    private void onMobPreLevelEvent(final MobPreLevelEvent event){
        if (event.getEntity().getType() == EntityType.ZOMBIE){
            Bukkit.getLogger().info("Cancelling nametag for Zombie");
            event.setShowLMNametag(false);
        }
    }
}

Result: image

DavideBlade commented 4 months ago

@Raidware @hiiamken @UnbeatableSquirrel

From version 2.0.3.5 the hooks section of the config will look like this:

hooks:
  # If you are using MythicMobs, enable this to hide the health bar of HealthBar-Reloaded on MythicMobs mobs.
  MythicMobs: false
  # If you are using LevelledMobs, choose which bar ('HealthBar' or 'LevelledMobs') to use on LevelledMobs mobs.
  LevelledMobs: LevelledMobs

It will work as follows:

Wiki and Spigot page are already updated with this information.

stumper66 commented 4 months ago

I have uploaded LevelledMobs 4.0.3.1. It's currently available on https://central.sonatype.com/artifact/io.github.arcaneplugins/levelledmobs-plugin but will make it's way to https://mvnrepository.com/artifact/io.github.arcaneplugins/levelledmobs-plugin at some point.

I've uploaded the kotlin docs here that shows the event you would need to use to cancel the LM nametag: https://arcaneplugins.github.io/LevelledMobs/4.0.3.1/levelledmobs-plugin/io.github.arcaneplugins.levelledmobs.events/-mob-pre-level-event/index.html

Raidware commented 3 months ago

@Raidware @hiiamken @UnbeatableSquirrel

From version 2.0.3.5 the hooks section of the config will look like this:

hooks:
  # If you are using MythicMobs, enable this to hide the health bar of HealthBar-Reloaded on MythicMobs mobs.
  MythicMobs: false
  # If you are using LevelledMobs, choose which bar ('HealthBar' or 'LevelledMobs') to use on LevelledMobs mobs.
  LevelledMobs: LevelledMobs

It will work as follows:

  • If LevelledMobs is not detected, the setting is ignored
  • If LevelledMobs is enabled correctly:

    • LevelledMobs will tell HealthBar-Reloaded to ignore LevelledMobs mobs (i.e., the bar will be the native one set by LevelledMobs)
    • HealthBar will set the health bar configured in HealthBar-Reloaded also to the LevelledMobs mobs

Wiki and Spigot page are already updated with this information.

Very Good! Thanks.