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

How can I cancel placing block

Discussion in 'Development' started by xXNiceAssassinlo YT, Mar 31, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    how can I cancel placing block in special Area
    Like in
    x: 123
    y: 123
    z: 123
     
  2. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Well, for a block at exactly 123.123.123 it's:
    PHP:
    public function onBlockPlace(BlockPlaceEvent $event) {
        if (
    $event->getBlock()->=== 123 && $event->getBlock()->=== 123 && $event->getBlock()->=== 123) {
            
    $event->setCancelled();
        }
    }
    But for an area you would have to check for its borders, that is if block's x is greater than area's minX and smaller than area's maxX, etc.
     
    Last edited: Mar 31, 2018
  3. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    $event->setCancelled(true);* please use min() and max()
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    public function onPlace(BlockPlaceEvent $event) {
        if (
    $event->getBlock()->=== 123 && $event->getBlock()->=== 123 && $event->getBlock()->=== 123) {
            
    $event->setCancelled(true);
        }
    }
     
  5. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Oh yeah, 'setCancelled'. Thanks.
     
    Marabou likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    How is min() related?
     
  7. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    The OP ask to make an area he can thus use min and max and of other method. I prefere the method of the min and max.
     
  8. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    I should say that you are just being really vague in your explanations.
     
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    How do I use min() and max()
     
  10. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    I believe he meant you can use those functions for calculating lowest and highest borders of your area, when player chooses two points like this:
    [​IMG]
     
    Last edited: Apr 1, 2018
    Muqsit likes this.
  11. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Can I get example I tried not working
     
  12. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    One.
    Two.
    These are old plugins and won't work as they are right now, but they show the concept.
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You know, it's like someone asks you how to make a cake, and you answer "you may need some water".
     
    Muqsit and Tee7even like this.
  14. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    PHP:
     /**
         * @param Vector3 $area_pos
         * @param Player $p
         * @return bool
         */
        
    public function area(Vector3 $area_posPlayer $p)
        {

            if (
    min($area_pos->0.5$area_pos->0.5) <= $p->getX() && max($area_pos->0.5$area_pos->0.5) >= $p->getX() && min($area_pos->0.5$area_pos->0.5) <= $p->getY() && max($area_pos->0.5$area_pos->0.5) >= $p->getY() && min($area_pos->0.5$area_pos->0.5) <= $p->getZ() && max($area_pos->0.5$area_pos->0.5) >= $p->getZ()) {
                return 
    true;
            }
            return 
    false;
        }
    Oh Sorry I didn't know that Seriously ?? :D Please when you understand nothing in English and you put your explanations as if I did not know, to look at my code subject of min and max I think that you have a lot to learn.
     
    Last edited: Apr 1, 2018
  15. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    I believe you have to learn English first before accusing someone of not understanding it.
     
  16. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Please Read Again your english is horrible too.
     
  17. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Yeah, I agree. But at least I try to be understood.

    And a question to everyone else in this thread: whose English you can understand better - mine or his? Vote now on your phones.
     
  18. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    No one will answer your drama. you will be banished.
     
  19. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Why are you so sure? You are trying hard to make this personal, boi.
     
  20. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Go do your hero !! that the staff and the person here does not like that :p and avoid spam, because I answer you in each post made a new post (OFF-Topic) talk about your life. ;).
     
  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.