Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Plugin Help PVP protector

Comments in 'Plugin Development' started by MegaSamNinja, May 25, 2014.

  1. MegaSamNinja
    Offline

    MegaSamNinja Active Member

    Joined:
    Sep 13, 2013
    Posts:
    138
    Minecraft User:
    Bamuel
    I need help this plugin doesnt work for some reason
    well you need to set in sever properties Spawn protection 1 to make it work

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=PVPprotector
    description=Players cant damage in PVP zones
    version=π
    author=MegaSamNinja
    class=PVPprotector
    apiversion=9,10,11,12,13
    */


      
    class PVPprotector implements Plugin
      
    {
        private 
    $api$path$config;

        public function 
    __construct(ServerAPI $api$server false)
        {
          
    $this->api    $api;
          
    $this->server ServerAPI::request();
          
    $this->path   $this->api->plugin->createConfig($this, array());
          
    $this->config $this->api->plugin->readYAML($this->path "config.yml");
        }

        public function 
    init()
        {
          
    $this->api->addHandler("entity.health.change", array($this"eventHandler"));
          
    $this->api->console->register("pvpprotect""Set a no pvp zone.", array($this"commandH"));
        }

        public function 
    eventHandler($data)
        {
            
    $target $data['entity'];
            
    $t = new Vector2($target->x$target->z);
            
    $s = new Vector2($this->server->spawn->x$this->server->spawn->z);
            if(
    $t->distance($s) <= $this->api->getProperty('spawn-protection')){
                if(
    is_numeric($data['cause'])){
                    
    $e $this->api->entity->get($data['cause']);
                    if((
    $e !== false) and ($e->class === ENTITY_PLAYER)){
                        
    $e->player->sendChat('PvP is not allowed in this area');
    if(!isset(
    $target))return;
          if (
    $this->config[$target->level]['min'][0] <= $target->and $target-><= $this->config[$target->level]['max'][0]) {
            if (
    $this->config[$target->level]['min'][1] <= $target->and $target-><= $this->config[$target->level]['max'][1]) {
              if (
    $this->config[$target->level]['min'][2] <= $target->and $target-><= $this->config[$target->level]['max'][2]) {
                return 
    false;
              }
            }
          }
        }

        public function 
    commandH($cmd$params$issuer$alias)
        {
          
    $output "";
          switch (
    $cmd) {
            case 
    "pvpprotect":
              if (
    $issuer != "console") {
                
    $output .= "THIS IS AWESOME why dosent it work cause you need todo it ingame";
                break;
              }
              if (
    count($params) == 8) {
                
    $level array_shift($params);
                
    $pos1  = array(array_shift($params), array_shift($params), array_shift($params));
                
    $pos2  = array(array_shift($params), array_shift($params), array_shift($params));
                
    $minX  min($pos1[0], $pos2[0]);
                
    $maxX  max($pos1[0], $pos2[0]);
                
    $minY  min($pos1[1], $pos2[1]);
                
    $maxY  max($pos1[1], $pos2[1]);
                
    $minZ  min($pos1[2], $pos2[2]);
                
    $maxZ  max($pos1[2], $pos2[2]);
                
    $max   = array($maxX$maxY$maxZ);
                
    $min   = array($minX$minY$minZ);

                
    $this->config[$level] = array("pvp" => true"min" => $min"max" => $max);
                
    $this->writeConfig($this->config);
                
    $output .= "This area is now has NO PVP ($minX$minY$minZ)-($maxX$maxY$maxZ) : $level\n";
              } else {
                
    $output .= "usage pvpprotect x1 y1 z1 x2 y2 z2";
              }
              break;
          }
          return 
    $output;
        }

        public function 
    __destruct()
        {

        }

      }
    Kedyn Bolds likes this.
  2. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    you havent made your config file yet. thats why it doesnt save the coordinates as what ive see.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why are return false and hitter separated?
  4. MegaSamNinja
    Offline

    MegaSamNinja Active Member

    Joined:
    Sep 13, 2013
    Posts:
    138
    Minecraft User:
    Bamuel
    i have
    $this->path = $this->api->plugin->createConfig($this, array());
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But there are no contents in the config.
  6. MegaSamNinja
    Offline

    MegaSamNinja Active Member

    Joined:
    Sep 13, 2013
    Posts:
    138
    Minecraft User:
    Bamuel
    oh
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But about spawn-protectino? ....
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oh and there is no API 13.
  9. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    I did something like this, but used player.interact instead of that.
    PEMapModder likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But that would allow fire damage etc.
  11. MegaSamNinja
    Offline

    MegaSamNinja Active Member

    Joined:
    Sep 13, 2013
    Posts:
    138
    Minecraft User:
    Bamuel
    but mine will also make it only /op can grief that area
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is due to the vanilla protection.
    MegaSamNinja likes this.
  13. MegaSamNinja
    Offline

    MegaSamNinja Active Member

    Joined:
    Sep 13, 2013
    Posts:
    138
    Minecraft User:
    Bamuel
  14. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    Oh, I was trying to mimic williamtdrs ctf, cant hit your own team.

Share This Page

Advertisement