Sending a message in the item name above hotbar

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

iKiltMyslef

Member
Sep 19, 2023
1
0
1
31
Looking to do something like this as a way to have, in effect, an action bar message that can be two lines. There's a few ways to go about doing this, but I would like to try to stay away from changing a held item's name and changing it back to its original name (which also wouldn't work if the player is holding nothing).

Below is what I've tried, and I'm getting a single error when attempting to run, even though the Skript loads fine without any issues.

Code:
import:
    # ProtocolLib
    com.comphenix.protocol.PacketType
    com.comphenix.protocol.ProtocolLibrary
    com.comphenix.protocol.events.PacketEvent
    com.comphenix.protocol.events.PacketContainer

    # Bukkit
    org.bukkit.Bukkit
    org.bukkit.inventory.ItemFlag
    org.bukkit.entity.Player
    org.bukkit.inventory.ItemStack
    org.bukkit.inventory.meta.ItemMeta
    org.bukkit.scheduler.BukkitRunnable


preimport:
    me.desht.dhutils.ItemMessage


# Original Java source: https://www.spigotmc.org/threads/itemmessagereloaded-popup-message-packet.304903/#post-2919253
public skript class me.desht.dhutils.ItemMessage:
    public and static void send(Player player, String message):
        set {_slot} to {_player}.getInventory().getHeldItemSlot()
        set {_stack0} to {_player}.getInventory().getItem({_slot})
        set {_stack} to new ItemStack({_stack0}.getType(), {_stack0}.getAmount(), {_stack0}.getDurability())
        set {_meta} to Bukkit.getItemFactory().getItemMeta({_stack}.getType())

        # fool the client into thinking the item name has changed, so it actually (re)displays it
        set {_meta} to {_meta}.setDisplayName({_message})
        {_stack}.setItemMeta({_meta})
        set {_setSlot} to new PacketContainer(PacketType.Play.Server.SET_SLOT)
       
        # int field 0: window id (0 = player inventory)
        # int field 1: slot number (36 - 44 for player hotbar)
        {_setSlot}.getIntegers().write(0, 0).write(1, {_slot} + 36)
        {_setSlot}.getItemModifier().write(0, {_stack})
        ProtocolLibrary.getProtocolManager().sendServerPacket({_player}, {_setSlot})

on region enter:
    if "%event-region%" contains "myhome":
        new ItemMessage(player, "test")

Error:
[15:24:30 INFO]: [Skript] No matching static constructor: ItemMessage.<init> called with (KiltMyself (CraftPlayer), test (String))

Can anyone tell what I'm missing here or doing wrong that would be causing this error?

Minecraft Server:
- Paper 1.20.1
Skript Version:
- 2.7.0
Installed Addons:
- PermSk v1.1.1
- Skellett v2.0.9
- skript-yaml v1.5
- skript-reflect v2.3
- skUtilities v0.9.2
- Lusk v1.0.3
- Hippo v1.0
- SkQuery v4.1.10
- SkBee v2.17.0
 
Unfortunately not a lot for of people here know java, I would suggest posting on spigot mc forums