InventoryClickEvent NOT WORK

Discussion in 'Spigot Discussion' started by Pengueno, Dec 1, 2019.

  1. package sk.dev;


    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.md_5.bungee.api.ChatColor;


    public class Main extends JavaPlugin implements Listener {


    public void onEnable() {

    System.out.print(" MAIN ABILITATO");
    getServer().getPluginManager().registerEvents(this, this);
    }
    public void onDisable() {
    System.out.print(" MAIN DISABILITATO");
    saveConfig();



    }


    @EventHandler
    public void BlockBreakEvent(BlockBreakEvent e) {
    Player player = e.getPlayer();
    Block block = e.getBlock();
    Material material = block.getType();
    String name = player.getName();
    Bukkit.getServer().broadcastMessage(name + " Ha appena rotto un blocco di " + material);
    }


    public boolean onCommand(CommandSender sender, Command cmd, String str, String[] args) {

    if(cmd.getName().equalsIgnoreCase("vip")) {
    Player player = (Player) sender;
    Inventory inv = Bukkit.createInventory(null, 18, ChatColor.RED + "BHO");
    saveConfig();
    ItemStack survival = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta survivalMeta = survival.getItemMeta();

    ItemStack creative = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta creativeMeta = creative.getItemMeta();

    ItemStack vip3 = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta vip3eMeta = creative.getItemMeta();

    ItemStack vip4 = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta vip4Meta = creative.getItemMeta();

    survivalMeta.setDisplayName("BHO");
    survival.setItemMeta(survivalMeta);
    creativeMeta.setDisplayName("BHO");
    creative.setItemMeta(creativeMeta);

    inv.setItem(1, survival);
    inv.setItem(2, creative);
    inv.setItem(3, vip3);
    inv.setItem(4, vip4);
    player.openInventory(inv);



    }

    return false;


    }
    @EventHandler
    public void onPlayerClickInventory(InventoryClickEvent e){
    if(e.getCurrentItem()!= null){
    return;
    }
    if(e.getClickedInventory().getTitle().equals("vip")) {
    e.setCancelled(true);


    }


    }






    }
     
  2. You're returning if they're clicking something and next time use a code block.
    Code (Java):
    package sk.dev;


    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.md_5.bungee.api.ChatColor;


    public class Main extends JavaPlugin implements Listener {


    public void onEnable() {

    System.out.print(" MAIN ABILITATO");
    getServer().getPluginManager().registerEvents(this, this);
    }
    public void onDisable() {
    System.out.print(" MAIN DISABILITATO");
    saveConfig();



    }


    @EventHandler
    public void BlockBreakEvent(BlockBreakEvent e) {
    Player player = e.getPlayer();
    Block block = e.getBlock();
    Material material = block.getType();
    String name = player.getName();
    Bukkit.getServer().broadcastMessage(name + " Ha appena rotto un blocco di " + material);
    }


    public boolean onCommand(CommandSender sender, Command cmd, String str, String[] args) {

    if(cmd.getName().equalsIgnoreCase("vip")) {
    Player player = (Player) sender;
    Inventory inv = Bukkit.createInventory(null, 18, ChatColor.RED + "BHO");
    saveConfig();
    ItemStack survival = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta survivalMeta = survival.getItemMeta();

    ItemStack creative = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta creativeMeta = creative.getItemMeta();

    ItemStack vip3 = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta vip3eMeta = creative.getItemMeta();

    ItemStack vip4 = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta vip4Meta = creative.getItemMeta();

    survivalMeta.setDisplayName("BHO");
    survival.setItemMeta(survivalMeta);
    creativeMeta.setDisplayName("BHO");
    creative.setItemMeta(creativeMeta);

    inv.setItem(1, survival);
    inv.setItem(2, creative);
    inv.setItem(3, vip3);
    inv.setItem(4, vip4);
    player.openInventory(inv);



    }

    return false;


    }
    @EventHandler
    public void onPlayerClickInventory(InventoryClickEvent e){
    if(e.getCurrentItem()!= null){
    if(e.getClickedInventory().getTitle().equals("vip")) {
    e.setCancelled(true);
    }
    } else {
    returning;
    }


    }






    }