Solved "When clicking on a player head, the menu doesn't open.


New member
Dec 4, 2023
Hi, I'm a beginner developer, and I'm working on my own plugin. I've encountered an issue that I haven't been able to solve for around 1 day. When I click on a player head in Minecraft, specifically in the code BanGuiCommand.kt, nothing happens. The script BanGuiListener doesn't open the BanConfirm menu. Does anyone know how to fix it? Here are the scripts.
I'm using PAPER 1.20.2, Kotlin, and Maven.

package me.infinity.banplugin.commands

import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.Sound
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.SkullMeta

class BanGuiCommand : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, strings: Array<String>): Boolean {
if (sender is Player) {
val p = sender
val list = ArrayList(p.server.onlinePlayers)
val bangui = Bukkit.createInventory(p, 45, ChatColor.DARK_RED.toString() + "Choose Player to ban")

for (i in list.indices) {
val playerName =
val playerHead = getPlayerHead(list)

val meta = playerHead.itemMeta as SkullMeta


// Play the sound
p.playSound(p.location, Sound.BLOCK_NOTE_BLOCK_PLING, 1.0f, 1.0f)

return true

private fun getPlayerHead(player: Player): ItemStack {
val itemStack = ItemStack(Material.PLAYER_HEAD, 1)
val meta = itemStack.itemMeta as SkullMeta
meta.owningPlayer = player
itemStack.itemMeta = meta
return itemStack

package me.infinity.banplugin.listeners

import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.inventory.ItemStack

class BanGuiListener : Listener {
fun onMenuClick(e: InventoryClickEvent) {
if (e.whoClicked !is Player) {
val p = e.whoClicked as Player
val strippedTitle = ChatColor.stripColor(e.view.title)

if (strippedTitle.equals(ChatColor.DARK_RED.toString() + "Choose Player to ban", ignoreCase = true)) {
if (e.currentItem?.type == Material.PLAYER_HEAD) {
val whoToBan = ChatColor.stripColor(e.currentItem?.itemMeta?.displayName)
?.let { p.server.getPlayerExact(it) }

val confirmBanMenu = Bukkit.createInventory(p, 9, ChatColor.RED.toString() + "Ban This Player")

val ban = ItemStack(Material.WOODEN_AXE, 1)
val ban_meta = ban.itemMeta
ban_meta.setDisplayName(ChatColor.DARK_GREEN.toString() + "Ban This Player")
ban.itemMeta = ban_meta
confirmBanMenu.setItem(0, ban)

val playerHead = ItemStack(Material.PLAYER_HEAD, 1)
val player_meta = playerHead.itemMeta
playerHead.itemMeta = player_meta
confirmBanMenu.setItem(4, playerHead)

val cancel = ItemStack(Material.BARRIER, 1)
val cancel_meta = cancel.itemMeta
cancel_meta.setDisplayName(ChatColor.RED.toString() + "Go Back!")
cancel.itemMeta = cancel_meta
confirmBanMenu.setItem(8, cancel)

Last edited: