Need help binding commands to items in GUI

Discussion in 'Plugin Development' started by Glass_Eater84, Apr 13, 2014.

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

    Glass_Eater84

    Hello!

    I am in need of some help. I am trying to bind a command to said item in a GUI. However, this does not seem to be working. Whenever I try, I get an error. Is there anything wrong with the following code? This is the current code I have:

    Code:java
    1. {
    2. @EventHandler
    3.  
    4. case DIAMOND:
    5. Bukkit.dispatchCommand(player, "server survivalmodes");
    6. player.closeInventory();
    7. break;
    8. }


    I greatly appreciate any help. Thank you in advance!

    Regards,
    Glass
     
  2. Offline

    Shadowwolf97

    Could you post the entire class file? or if you don't want to share it you can PM it to me.
     
  3. Offline

    Gater12

  4. Offline

    chikenlitle99

    @Glass_Eater84
    No you want to achieve, but I use this on my menĂº
    Code:java
    1. if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Prueba2")) {
    2. //Get the name of the item
    3. e.setCancelled(true);
    4. //Prevents take the item
    5. e.getWhoClicked().getServer().dispatchCommand(Bukkit.getPlayer(""), "gamemode 0");
    6. //Runs a command, which puts the player in gamemode 2
    7. e.getWhoClicked().closeInventory();
    8. //Close the inventory


    @Glass_Eater84
    If you want to use BungeeCord that will not work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    Glass_Eater84

  6. Glass_Eater84

    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. Player player = (Player) event.getWhoClicked();
    4. ItemStack clicked = event.getCurrentItem();
    5. Inventory inventory = event.getInventory();
    6. if (inventory.getName().equals(TheNameOfYourInventory) {
    7. if (clicked.getType() == Material.WhateverBlockOrItemYouWant) {
    8. event.setCancelled(true);
    9. player.closeInventory();
    10. //do something
    11. }
    12. }
    13. }
     
  7. Offline

    chikenlitle99

  8. Offline

    Glass_Eater84

  9. Offline

    chikenlitle99

    No use Bungee Cord?, Then why you want to run a command to read / server
     
  10. Offline

    Glass_Eater84

    driver-e
    Thanks for the response. However, this did not work. This is what I have:
    Code:java
    1. Player p = (Player) ((InventoryInteractEvent) event).getWhoClicked();
    2. ItemStack clicked = ((InventoryClickEvent) event).getCurrentItem();
    3. Inventory inventory = ((HumanEntity) event).getInventory();
    4. if (inventory.getName().equals(inv)) {
    5. if (clicked.getType() == Material.WOOD_DOOR) {
    6. ((InventoryInteractEvent) event).setCancelled(true);
    7. p.closeInventory();
    8. //do something

    I had to change it because it did not accept the void.

    Regards,
    glass
     
  11. Glass_Eater84
    Hi. It NEEDS this:
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {

    and this neeeds to have the name of your custom inventory if it doesn't already.
    Code:java
    1. if (inventory.getName().equals(NAME OF YOUR CUSTOM INVENTORY)) {
     
Thread Status:
Not open for further replies.

Share This Page