Solved Executing Commands Via InventoryClickEvent

Discussion in 'Plugin Development' started by rbrick, Nov 23, 2013.

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

    rbrick

    I am making a kitpvp selector GUI for my kitpvp plugin and i have got the main GUI but have no idea on how to make it execute commands. All of my commands are in the same class as the GUI(i started developing this before i found out how to connect classes/packages to one main class :p ) and the InventoryClickEvent does not seem to have a performCommand() function as with PlayerInteractEvent. And yes i did do event.getWhoClicked().
    Here is the snippet of code :
    Show Spoiler

    Code:java
    1.  
    2. @EventHandler
    3. public void onInventoryClick(InventoryClickEvent e){
    4. Player p = (Player)e.getWhoClicked();
    5. if(!e.getInventory().getName().equalsIgnoreCase(this.kitGui().getName())) return;
    6. if(e.getCurrentItem().getItemMeta() == null) return;
    7. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("PvP")){
    8. e.setCancelled(true);
    9.  
    10. }


    If anyone could give me even one tiny hint on how to do this it will be much appreciated!
     
  2. Offline

    Gater12

    rbrick Try:
    Code:java
    1.  
    2. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "COMMAND HERE");
    3.  
     
  3. Offline

    rbrick

    No doesn't work *sadface*. would there be a way to cast .getConsoleSender() to a player?
     
  4. Offline

    Gater12

    rbrick Maybe player.chat("/command"); ?
     
  5. Offline

    rbrick

    It works! geeze that was simpler than i thought xD thanks. SOLVED
     
    Gater12 likes this.
  6. Offline

    Conarnar

    Do what Gater12 did first. But change Bukkit.getConsoleSender() to e.getWhoClicked(). I don't know if you need to cast it or not. NINJA'D

    Is typing on an iPhone really that slow?
     
  7. Offline

    rbrick

    Most likely all the PHP and JavaScript processing on your phone is causing it to be slow :p i will try this method as well but Gater12's second method works perfectly.
     
  8. Offline

    Garris0n

    player.performCommand("command");
     
  9. Offline

    Conarnar

    By
    By slow I mean it takes about thirty seconds to type a sentence since I'm not a person who texts a lot.
     
  10. Offline

    rbrick

    ahh. hehe

    wtf. thanks it works but i could of sworn last time i tried this it wasnt a valid statement xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page