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

border issues

Discussion in 'Development' started by Teamblocket, Jun 26, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    so i made a border plugin and it works great but the border doesn't work once you join and move the border is trigged for some reason
    Code
    PHP:
    <?php
    namespace TB\Border;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\utils\Config;
    class 
    Main extends PluginBase implements Listener {
        public function 
    onEnable(){
            
    $this->getServer()->getLogger()->info("World Border Plugin Made by TB!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
        }
        
        public function 
    retrieveData($data){
            return 
    $this->getConfig()->get($data);
        }
        public function 
    onMove(PlayerMoveEvent $ev){
            
    $x $ev->getPlayer()->x;
            
    $z $ev->getPlayer()->z;
            
    $minZ $this->retrieveData("minZ");
            
    $maxZ $this->retrieveData("maxZ");
            
            
    $minX $this->retrieveData("minX");
            
    $maxX $this->retrieveData("maxX");
            if(
    $minX <= $x and $x <= $maxX and $minZ <= $z and $z <= $maxZ){
                
    $ev->setCancelled(true);
                
    $message = array($this->retrieveData("Message1"), $this->retrieveData("Message2"));
                
    $ev->getPlayer()->addTitle($message[0], $message[1], 904090);
                
    $this->getServer()->getLogger()->warning($minX " " $maxX " / " $minZ " " $maxZ);
            }
        }
    }
    Config:
    Code:
    maxX: 1000
    minX: -1000
    maxZ: 1000
    minZ: -1000
    Message1: "World Border"
    Message2: "You Reached The World Border"
     
  2. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    PHP:
    $x >= $minX and $x <= $maxX and $z <= $minZ and $z <= $maxZ
    // Player inside border
    //else
    // Player outside border
    //Cancel the event
     
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    thanks
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    doeesnt work :(
    PHP:
            if($x >= $minX and $x <= $maxX and $z <= $minZ and $z <= $maxZ){
                
    $ev->setCancelled(false);
            } else {
                
    $message = array($this->retrieveData("Message1"), $this->retrieveData("Message2"));
                
    $ev->getPlayer()->addTitle($message[0], $message[1], 904090);
                
    $ev->setCancelled(true);
            }
        }
    }
    https://github.com/Teamblocket/Border/blob/master/src/TB/Border/Main.php
     
  5. You could try making a task to check the border
     
  6. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
  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.