Possible Challenge - Using IChatBaseComponent in PlayerDeathEvent

Discussion in 'Plugin Development' started by JRL1004, Dec 28, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    JRL1004

    So, I am making a plugin where I call the PlayerDeathEvent myself using this constructor
    Code:
    PlayerDeathEvent(Player player, List<ItemStack> drops, int droppedExp, String deathMessage) 
    I would like to make it so that players can hover part of my custom death messages to reveal information. Here is an example of how I want it come out:
    Example (open)
    "%Player2 was slain by %Player1% using a(n) %ItemName%"
    Player2 will show the player's balance, uuid, in-game level, etc
    Player1 will do the same as player2
    ItemName will show the item type (e.g. "Bow"), how much damage was dealt in X hits, enchants on the weapons, and (if a bow) distance at which player1 was slain

    Note: I can fill in all of this information, I just don't know how I would use an IChatBaseComponent


    Using this code:[​IMG]
    I get the text "This is a test death message" but there is no hover event.

    EDIT: I am running CraftBukkit 1.10.2
     
    Last edited: Dec 29, 2016
  2. Offline

    Zombie_Striker

    @JRL1004
    First, don't call events that you have not made. Not only can this affect other plugins using the same plugin, but unless you handle everything (scoreboards, nbt data, along with all the actual effects like sending the messages and actually killing the player) you should just let bukkit handle it.

    Now, for your actual problem, what you want to do cancel the message (by setting the message to null) and create a json message following the tutorial here:
    https://bukkit.org/threads/json-chat-lib-easily-create-and-send-json-messages-to-players.188165/
     
  3. @Zombie_Striker
    His method works too (just that it's version-dependent, so the json method is better).

    @JRL1004
    The problem is that when you do "icbc.getChatModifier()", and use the setChatHoverable() method, the ChatModifier in the IChatBaseComponent isn't actually modified. If you create a new ChatModifier, and then use the setChatHoverable on that, and then pass it into the setChatModifier method, it'll work. Something like this:
    Code:java
    1. ChatModifier cm = new ChatModifier..
    2. cm.setChatHoverable(..)
    3. icbc.setChatModifier(cm)
     
Thread Status:
Not open for further replies.

Share This Page