1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to use HotBar Items to run command

Discussion in 'Facepalm' started by iTzAnTiFTW, Aug 15, 2017.

  1. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    Ok, this probably sounds dumb to some people, but how do you make a command run when you attempt to mine with the item in your hand? I know a few servers that have this feature. (Ex. LifeBoat)
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You can create a new Listener, and add a handler for BlockBreakEvent. You then check if the ID and meta of the held item are the desired ones, using Player->getInventory()->getItemInHand(), and execute the code/command you want to, if the event meets those requirements.
     
  3. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    Thanks
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I think you want PlayerInteractEvent(action=LEFT_CLICK_BLOCK) instead.
     
  5. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    Hmm, but is there a way I can add multiple items to the hotbar & have the item be removed from their inventory completely after excuting the command?
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What exactly do you want to do?
     
  7. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    run a command on the event of a player attempting to mine a block.
     
    Last edited: Aug 18, 2017
  8. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    Code:
    public function whenMine(WhenPlayerStartToMineABlockEvent $event){
    
     $player = $event->getPlayer();
     
     }
     // Enjoy??

    Anyhow, use PlayerInteractEvent, or BlockBreakEvent. Just like @SOFe said.
     
  9. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PlayerAction packet, action start mine
     
  10. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    i already know this. I only reopened this to figure out how to give the player the item (appear in there hotbar) and then removing the item from there invetory entirely after they use the action. (Also, maybe submenus with item start to mine event)
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I know that. I just want to know why you would want that to happen.
    Do you want to make the item show as something like a "status" icon when he is mining, and disappear when the finger leaves the screen? Or do you just want it because the command you run requires the player to have that item in the hotbar, etc.?
     
    jasonwynn10 likes this.
  12. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    I want to give them items, I like the way the hotbar works. Also I am intrested in having multiple items appear in there hotbar & have submenus with more items in there hotbars (kits)
     
  13. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    UPDATE: I am trying achive a hotbar menu, as seen on LifeBoat BedWars shop, you press a item (such as a snowball) and it brings you to a new menu with more items (options) to choose from to execute a command. I am attempting to use this same method to create a plugin for kits. When you do /kit this sub menu will appear. I have been working recently on trying to make this function but I can't get it to function properly.
     
  14. iTzAnTiFTW

    iTzAnTiFTW Spider Jockey

    Messages:
    36
    GitHub:
    itzantiftw
    Really? Facepalming this? Why dont you solve the help me solve issue before moving the thread....
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.