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

How to use BlockPlaceEvent

Discussion in 'Facepalm' started by Defications2po, Jun 10, 2017.

  1. Defications2po

    Defications2po Witch

    Messages:
    51
    can you show me how to use this.
     
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    facepalm*
     
  3. Defications2po

    Defications2po Witch

    Messages:
    51
    this just shows how the forums doesn't help at all *sigh*:facepalm:
    time to go to twitter.
    Thx for nothing anyways.
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    The forums help if you are clever enough to make a proper thread...
     
  5. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    And this:
    Just shows how little you tried before expecting us to print you out some code like a machine.
     
  6. [deleted]

    [deleted] Guest

    I think a IDE could be useful for you, The BlockPlaceEvent is called when a player places a block.

    PHP:
    public function onPlace(BlockPlaceEvent $event) { // save BlockPlaceEvent under $event
      // With $event you can do several things, eg: getting the player and sends him a message each time he places a block
      
    $event->getPlayer()->sendMessage("You placed a block");
     }
     
  7. Defications2po

    Defications2po Witch

    Messages:
    51
    i know but i want t to check if i placed a specific block like maybe dirt
     
  8. [deleted]

    [deleted] Guest

    Here you are
    PHP:
    public function onBlockPlace(BlockPlaceEvent $event)
    {
     
    $player $event->getPlayer();
     
    $inv $player->getInventory();
     
    $itemid 1// Itemid what should be cancelled to place
     
    if ($inv->getItemInHand()->getId() == $itemid)
     {
       
    // Happens if the Player places a block with the id in $itemid
       
    $event->setCancelled(); // Cancel BlockPlaceEvent
       
    $player->sendMessage("You cant place this Block");
     }
    }
     
  9. Defications2po

    Defications2po Witch

    Messages:
    51
    srry i hav not codded in a week but setCancled() means that the block is automatically removed removed if not can you show me how to?
     
  10. [deleted]

    [deleted] Guest

    Hi!
    If you use setCancelled() in the same case like I did above, the player can not place a block with the specified Itemid
     
  11. Defications2po

    Defications2po Witch

    Messages:
    51
    Oh ok I see. So what if I want it that when it places it automatically removes the block.
     
  12. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You cancel the event.
     
  13. Lowkey

    Lowkey Slime

    Messages:
    94
    #ReadTheDocs, wow. How can one be so ignorant?!
     
  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.