Skip to content
Advertisement

Getting an the name of an item and getting the string value returns gibberish

I want to get the player whos name matches the name of the block which was placed and updated this players gamemode to survival. But this just gives me gibberish in the console:

@EventHandler
public void onPlace(BlockPlaceEvent blockPlaceEvent){
    //Player ded = Bukkit.getPlayer(String.valueOf(blockPlaceEvent.getItemInHand().displayName()));- not important
    //gives just the item name
    blockPlaceEvent.getPlayer().sendMessage(blockPlaceEvent.getItemInHand().displayName());
    //gibberish
    System.out.println(Bukkit.getPlayer(String.valueOf(blockPlaceEvent.getItemInHand().displayName())));


}
[19:15:09 INFO]: [Immortality] [STDOUT] TranslatableComponentImpl{key="chat.square_brackets", args=[TextComponentImpl{content="", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=true, color=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[TextComponentImpl{content="Windows_Paride", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}]}], style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=NamedTextColor{name="yellow", value="#ffff55"}, clickEvent=null, hoverEvent=HoverEvent{action=show_item, value=ShowItem{item=KeyImpl{namespace="minecraft", value="player_head"}, count=1, nbt={SkullOwner:{Id:[I;1311740293,1907444130,-1719123357,-1000482567],Name:"Windows_Paride",Properties:{textures:[{Signature:"x3tHAiXrUDBYofKatE+CaD46u0lyjkxlab+Xg+zKNEO1GMGnjPHXsfRSl9CVp9bBLJLu3aMcd8qI/bcm+E8mqJlbHRxjzRi/7W/JOTbsWWurf32i4fgO1VqxoSWsGb6PGbtCVKI7LXm0nPu+lreVHKWbgAqaw8koadUZIu+XhS8hTeqwpuNMLcrS5Wh7ODdf7hBK/BDT67RC3y6pjmDNeznrH6k8YEHQVZszJ/RCicP9AyQmbwCppjzjubYdwwIOi7r+jLmsCVL4r03svzOuugtGoMNgDFj/Gm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gIH0KICB9Cn0="}]}},Unbreakable:1b,display:{Name:'{"text":"Windows_Paride"}'}}}}, insertion=null, font=null}, children=[]}

I tried doing ComponentLike etc but it returned null when I did that.

Advertisement

Answer

As per the comments you’re trying to get h the name of the player.

Refer https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Player.html#getName() from the documentation.

First get the Player object and then fetch the name from the player object.

Player player = Bukkit.getPlayer(String.valueOf(blockPlaceEvent.getItemInHand().displayName()));

player.getName();
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement