Entity Handlers
Entity handlers can be used to display info about the entity the player is looking at.
Adding an Entity Handler
Make a class which will hold our Handler.
Make a function which will be our handler.
private static boolean handleMyEntity(Entity entity, Player player) { if (/* your condition */) { // Your logic here WITAPI.updateBar(yourInfo, player); return true; // Successfully handled the entity } return false; // Not your entity, skip it }Now that you have made the Handler, you must register it.
WITAPI.addEntityHandler(YourClass::handleMyEntity);That's it, you have made you entity handler!
A complete example of an entity handler (this uses the internal [WAILAManager]):
package me.darksoul.whatIsThat.compatibility; import com.magmaguy.elitemobs.entitytracker.EntityTracker; import com.magmaguy.elitemobs.mobconstructor.EliteEntity; import me.darksoul.whatIsThat.Information; import me.darksoul.whatIsThat.WAILAListener; import me.darksoul.whatIsThat.display.WAILAManager; import me.darksoul.whatIsThat.WhatIsThat; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class EliteMobsCompat { private static final List<Function<EliteEntity, String>> suffixEntity = new ArrayList<>(); private static boolean isInstalled; public static void setup() { suffixEntity.clear(); if (WAILAListener.getConfig().getBoolean("elitemobs.healthinfo", true)) { suffixEntity.add(Information::eliteMobs_getHealth); } } public static void hook() { Plugin pl = WhatIsThat.getInstance().getServer().getPluginManager().getPlugin("EliteMobs"); isInstalled = pl != null && pl.isEnabled(); if (isInstalled) { setup(); WhatIsThat.getInstance().getLogger().info("Hooked into EliteMobs"); } else { WhatIsThat.getInstance().getLogger().info("EliteMobs not found, skipping hook"); } } public static boolean getIsInstalled() { return isInstalled; } public static boolean handleEntity(Entity entity, Player player) { EliteEntity eliteEntity = EntityTracker.getEliteMobEntity(entity); if (eliteEntity != null) { String name = eliteEntity.getName(); StringBuilder EMEntitySInfo = new StringBuilder(); String EMEntityPInfo = ""; StringBuilder info = new StringBuilder(); for (Function<EliteEntity, String> func : suffixEntity) { EMEntitySInfo.append(func.apply(eliteEntity)); } info.append(EMEntityPInfo).append(name); if (!EMEntitySInfo.isEmpty()) { info.append(Information.getValuesFile().getString("SPLITTER", " §f| ")) .append(EMEntitySInfo); } WAILAListener.setLookingAt(player, name); WAILAListener.setLookingAtPrefix(player, EMEntityPInfo); WAILAListener.setLookingAtSuffix(player, EMEntitySInfo.toString()); WAILAListener.setLookingAtInfo(player, info.toString()); WAILAManager.setBar(player, info.toString()); return true; } return false; } }
Last modified: 02 February 2025