WIT Help

Block Handlers

Block Handlers can be used to display info for the blocks that the player is looking at.

Adding a Block Handler

  1. Make a class which will hold our handler funtion.

  2. 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 Info 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 }
  3. 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);
  4. That's it! you have now successfully made a Block Handler!

  5. A complete example of a block handler (this uses the internal [WAILAManager]):

    public static boolean handleBlock(Block block, Player player) { Info info = new Info(); Device device = MTAPI.getDevice(block.getLocation()); Mover mover = Mover.getMover(block.getLocation()); String deviceName; float progress = 0; if (WITMinetorio.CONFIG.getBoolean("block-progress")) { if (Events.progressMap.containsKey(block)) { progress = Events.progressMap.get(block); } } if (device != null || mover != null) { if (mover != null) { deviceName = "Mover"; } else { deviceName = device.getName(); } for (Function<Block, Component> func : suffixBlock) { info.addSuffix(func.apply(block)); } for (Function<Block, Component> func : prefixBlock) { info.addPrefix(func.apply(block)); } if (!((TextComponent) info.getPrefix()).content().isEmpty()) { info.addPrefix(mm.deserialize(Information.getValuesFile().getString("SPLITTER", " §f| "))); } info.setName(Component.text(deviceName)); if (!((TextComponent) info.getSuffix()).content().isEmpty()) { info.suffixSplit(mm.deserialize(Information.getValuesFile().getString("SPLITTER", " §f| "))); } API.updateBar(info, 1 - progress, player); return true; } return false; }

Removing a Block Handler

  • Removing a block handler is a one-liner!:

    WITAPI.removeBlockHandler(YourClass::BlockHandlerFunc)
16 May 2025