Block Handlers
Block Handlers can be used to display info for the blocks that the player is looking at.
Adding a Block Handler
Make a class which will hold our handler funtion.
Make a function which will be the handler.
private static boolean handleMyBlock(Block block, Player player) { // Check if this block belongs to your blocks if (/* your condition */) { // Add your logic WITAPI.updateBar(yourInfo, player); // `yourInfo` is the string shown on the boss bar. // `player` is the one received by the handler from the plugin. return true; // Block successfully handled } return false; // Not your block, skip it }Now that you have made a handler, you must register the handler so it's actually used by WIT, this can be done by:
WITAPI.addBlockHandler(YourClass::handleMyBlock);That's it! you have now successfully made a Block Handler!
A complete example of a block handler (this uses the internal [WAILAManager]):
package me.darksoul.whatIsThat.compatibility; import com.MT.xxxtrigger50xxx.API.MTAPI; import com.MT.xxxtrigger50xxx.Devices.Device; import com.MT.xxxtrigger50xxx.Devices.Mover; import me.darksoul.whatIsThat.Information; import me.darksoul.whatIsThat.WAILAListener; import me.darksoul.whatIsThat.display.WAILAManager; import me.darksoul.whatIsThat.WhatIsThat; import org.bukkit.block.Block; 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 MinetorioCompat { private static boolean isInstalled; private static final List<Function<Block, String>> prefixBlock = new ArrayList<>(); private static final List<Function<Block, String>> suffixBlock = new ArrayList<>(); public static void setup() { prefixBlock.clear(); suffixBlock.clear(); if (WAILAListener.getConfig().getBoolean("minetorio.containerinfo", true)) { prefixBlock.add(Information::default_getTotalItemsInContainer); } if (WAILAListener.getConfig().getBoolean("minetorio.powerinfo", true)) { suffixBlock.add(Information::minetorio_getPower); } if (WAILAListener.getConfig().getBoolean("minetorio.smeltinfo", true)) { suffixBlock.add(Information::default_getRemainingSmeltTime); } } public static void hook() { Plugin pl = WhatIsThat.getInstance().getServer().getPluginManager().getPlugin("Minetorio"); isInstalled = pl != null && pl.isEnabled(); if (isInstalled) { setup(); WhatIsThat.getInstance().getLogger().info("Hooked into Minetorio"); } else { WhatIsThat.getInstance().getLogger().info("Minetorio not found, skipping hook"); } } public static boolean getIsInstalled() { return MinetorioCompat.isInstalled; } public static boolean handleBlock(Block block, Player player) { Device device = MTAPI.getDevice(block.getLocation()); Mover mover = Mover.getMover(block.getLocation()); String deviceName; if (device != null || mover != null) { if (mover != null) { deviceName = "Mover"; } else { deviceName = device.getName(); } StringBuilder MTBlockSInfo = new StringBuilder(); StringBuilder MTBlockPInfo = new StringBuilder(); StringBuilder info = new StringBuilder(); for (Function<Block, String> func : suffixBlock) { MTBlockSInfo.append(func.apply(block)); } for (Function<Block, String> func : prefixBlock) { MTBlockPInfo.append(func.apply(block)); } if (!MTBlockPInfo.isEmpty()) { info.append(MTBlockPInfo).append(Information.getValuesFile().getString("SPLITTER", " §f| ")); } info.append(deviceName); if (!MTBlockSInfo.isEmpty()) { info.append(Information.getValuesFile().getString("SPLITTER", " §f| ")).append(MTBlockSInfo); } WAILAListener.setLookingAt(player, deviceName); WAILAListener.setLookingAtPrefix(player, MTBlockPInfo.toString()); WAILAListener.setLookingAtSuffix(player, MTBlockSInfo.toString()); WAILAListener.setLookingAtInfo(player, info.toString()); WAILAManager.setBar(player, info.toString()); return true; } return false; } }
Removing a Block Handler
Removing a block handler is a one-liner!:
WITAPI.removeBlockHandler(YourClass::BlockHandlerFunc)
Last modified: 02 February 2025