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

[Solved] Block breaking blocks at worlds in array doesnt work

Discussion in 'Facepalm' started by Harviy11, Dec 23, 2016.

  1. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Hello everyone my code to get worlds in array doesnt work help me please
    here is my code

    PHP:
    public function getArenas() {
            array (
    "GD1""GD2""GD3""GDHub");
        }


        public function 
    onBreak(BlockBreakEvent $e) {
        
    $p $e->getPlayer();
        if(
    $p->getLevel()->getName() == $this->getArenas()) {
            
    $e->setCancelled("");
            
    $p->sendMessage(Color::GREEN "You can not break blocks!");
        }
    }
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Try:
    PHP:
    if(in_array($p->getLevel()->getName(), $this->getArenas())) {
     
    Harviy11 likes this.
  3. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Dont work
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    What doesn't work? Please provide any errors.
     
    SOFe likes this.
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Oh nevermind I already found out. You just make an array with the function getArenas, but you don't return it. Make the function do this:
    PHP:
    return array(/*blablabla*/);
     
  6. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Do not work:(
    PHP:
    public function getArenas()
    {
        return array(
    "GD1""GD2""GD3""GDHub");
    }


    public function 
    onBreak(BlockBreakEvent $e)
    {
        
    $p $e->getPlayer();
        if (
    in_array($p->getLevel()->getName(), $this->getArenas())) {
            
    $e->setCancelled();
            
    $p->sendMessage(Color::GREEN "You can not break blocks!");
        }
    }
     
  7. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    This should work:

    PHP:
    public function onBreak(BlockBreakEvent $event) {
            
    $player $event->getPlayer();
            
    $world $player->getLevel()->getFolderName();

            if (
    in_array($world$this->worlds)) {
                    
    $event->setCancelled(TRUE);
            }
        }
    *Create a public array with your worlds
    PHP:
    public $worlds = array();
     
  8. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    no it doesnt work
     
  9. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Error?
     
  10. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    No
     
  11. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    PHP:
    ...
    class 
    Main extends PluginBase implements Listener{  
        public 
    $worlds = array("1""world2"...);

        public function 
    onEnable() {
    ...
    public function 
    onBreak(BlockBreakEvent $event) {
            
    $player $event->getPlayer();
            
    $world $player->getLevel()->getFolderName();

            if (
    in_array($world$this->worlds)) {
                    
    $event->setCancelled(TRUE);
            }
        }
     
  12. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    PHP:
    ...
    class 
    Main extends PluginBase implements Listener{  
        public 
    $worlds = array("1""world2"...);

        public function 
    onEnable() {
    ...
    public function 
    onBreak(BlockBreakEvent $event) {
            
    $player $event->getPlayer();
            
    $world $player->getLevel()->getFolderName();

            if (
    in_array($world$this->worlds)) {
                    
    $event->setCancelled(TRUE);
            }
        }
    [
    QUOTE="VentroxStudio, post: 5952, member: 349"][PHP]
    ...
    class 
    Main extends PluginBase implements Listener
        public 
    $worlds = array("1""world2"...);

        public function 
    onEnable() {
    ...
    public function 
    onBreak(BlockBreakEvent $event) {
            
    $player $event->getPlayer();
            
    $world $player->getLevel()->getFolderName();

            if (
    in_array($world$this->worlds)) {
                    
    $event->setCancelled(TRUE);
            }
        }
    [/QUOTE]
    Do you used it like this?
     
    Harviy11 likes this.
  13. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    yes i used this do not work
     
  14. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Do you used it like this?[/QUOTE]
    Show pls me your code
     
  15. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    PHP:


    public function onBreak(BlockBreakEvent $e)
    {
        
    $p $e->getPlayer();
        
    $world $p->getLevel()->getFolderName();
        
    //if (in_array($p->getLevel()->getName(), $this->getArenas())) {
        
    if (in_array($world$this->worlds)) {
            
    $e->setCancelled();
            
    $p->sendMessage(Color::GREEN "You can not break blocks!");
        }
    }
     
  16. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Show me your worlds array
     
  17. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    PHP:
    public $worlds = array("GD1""world2");
     
  18. BFM

    BFM Creeper

    Messages:
    1
    registerEvents??
     
  19. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    used
     
  20. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Solved i give return; to end of blockbreakevent
     
  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.