Exemplo n.º 1
0
 public function onProjectileHit(ProjectileHitEvent $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof Arrow) {
         $theX = $entity->getX();
         $theY = $entity->getY();
         $theZ = $entity->getZ();
         $level = $entity->getLevel();
         $thePosition = new Position($theX, $theY, $theZ, $level);
         $theExplosion = new Explosion($thePosition, 5, NULL);
         $theExplosion->explode();
         $level->remove($entity);
     }
 }
Exemplo n.º 2
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($this->getLevel()->getDimension() == Level::DIMENSION_NETHER) {
         $explosion = new Explosion($this, 6, $this);
         $explosion->explode();
         return true;
     }
     $time = $this->getLevel()->getTime() % Level::TIME_FULL;
     $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
     if ($player instanceof Player and !$isNight) {
         $player->sendMessage(TextFormat::GRAY . "You can only sleep at night");
         return true;
     }
     $blockNorth = $this->getSide(2);
     //Gets the blocks around them
     $blockSouth = $this->getSide(3);
     $blockEast = $this->getSide(5);
     $blockWest = $this->getSide(4);
     if (($this->meta & 0x8) === 0x8) {
         //This is the Top part of bed
         $b = $this;
     } else {
         //Bottom Part of Bed
         if ($blockNorth->getId() === $this->id and ($blockNorth->meta & 0x8) === 0x8) {
             $b = $blockNorth;
         } elseif ($blockSouth->getId() === $this->id and ($blockSouth->meta & 0x8) === 0x8) {
             $b = $blockSouth;
         } elseif ($blockEast->getId() === $this->id and ($blockEast->meta & 0x8) === 0x8) {
             $b = $blockEast;
         } elseif ($blockWest->getId() === $this->id and ($blockWest->meta & 0x8) === 0x8) {
             $b = $blockWest;
         } else {
             if ($player instanceof Player) {
                 $player->sendMessage(TextFormat::GRAY . "This bed is incomplete");
             }
             return true;
         }
     }
     if ($player instanceof Player and $player->sleepOn($b) === false) {
         $player->sendMessage(TextFormat::GRAY . "This bed is occupied");
     }
     return true;
 }
Exemplo n.º 3
0
 public function MobRandomWalk()
 {
     $ann = $this->animals;
     $filter_res = array_filter($ann);
     if (!empty($filter_res)) {
         foreach ($this->animals as $animal) {
             if (in_array($animal['type'], $this->nighttype)) {
                 $level = $this->getServer()->getLevelByName($animal['level']);
                 $zo = $level->getEntity($animal['ID']);
                 if ($zo != "") {
                     $zom =& $this->animals[$zo->getId()];
                     if ($zom['IsStop'] != "1") {
                         $zom['yup'] = $zom['yup'] - 1;
                         $h_r = $this->hatred_r;
                         //仇恨半径
                         $pos = new Vector3($zo->getX(), $zo->getY(), $zo->getZ());
                         $hatred = false;
                         foreach ($zo->getViewers() as $p) {
                             //获取附近玩家
                             if ($p->distance($pos) <= $h_r) {
                                 //玩家在仇恨半径内
                                 if ($hatred === false) {
                                     $hatred = $p;
                                 } elseif ($hatred instanceof Player) {
                                     if ($p->distance($pos) <= $hatred->distance($pos)) {
                                         //比上一个更近
                                         $hatred = $p;
                                     }
                                 }
                             }
                         }
                         //echo ($zom['IsChasing']."\n");
                         if ($hatred == false or $this->dif == 0) {
                             $zom['IsChasing'] = false;
                         } else {
                             $zom['IsChasing'] = $hatred->getName();
                         }
                         //echo ($zom['IsChasing']."\n");
                         if ($zom['IsChasing'] !== false) {
                             //echo ("是属于仇恨模式\n");
                             $p = $this->getServer()->getPlayer($zom['IsChasing']);
                             if ($p instanceof Player === false) {
                                 $zom['IsChasing'] = false;
                                 //取消仇恨模式
                             } else {
                                 /*
                                 $xxx = 0.07;
                                 $zzz = 0.07;
                                 $posz1 = new Vector3 ($zo->getX() + $xxx, $zo->getY(), $zo->getZ());
                                     if($p->distance($pos) > $p->distance($posz1)){
                                     $xxx = 0.07;
                                     }
                                     if($p->distance($pos) == $p->distance($posz1)){
                                     $xxx = 0;
                                     }
                                     if($p->distance($pos) < $p->distance($posz1)){
                                     $xxx = -0.07;
                                     }
                                 $posz2 = new Vector3 ($zo->getX()+ $xxx, $zo->getY(), $zo->getZ() + $zzz);
                                     if($p->distance($pos) < $p->distance($posz2)){
                                     $zzz = -0.07;
                                     }
                                     if($p->distance($pos) == $p->distance($posz2)){
                                     $zzz = 0;
                                     }
                                     if($p->distance($pos) > $p->distance($posz2)){
                                     $zzz = 0.07;
                                     }
                                 */
                                 //还不如用旧算法了。。
                                 /*
                                 $zx =floor($zo->getX());
                                 $zZ = floor($zo->getZ());
                                 $xxx = 0.07;
                                 $zzz = 0.07;
                                 */
                                 $x1 = $zo->getX() - $p->getX();
                                 //$jumpy = $zo->getY() - 1;
                                 if ($x1 >= -0.5 and $x1 <= 0.5) {
                                     //直行
                                     //$zx = $zo->getX();
                                     $xxx = 0;
                                 } elseif ($x1 < 0) {
                                     //$zx = $zo->getX() +0.07;
                                     $xxx = 0.07000000000000001;
                                 } else {
                                     //$zx = $zo->getX() -0.07;
                                     $xxx = -0.07000000000000001;
                                 }
                                 $z1 = $zo->getZ() - $p->getZ();
                                 if ($z1 >= -0.5 and $z1 <= 0.5) {
                                     //直行
                                     //$zZ = $zo->getZ();
                                     $zzz = 0;
                                 } elseif ($z1 < 0) {
                                     //$zZ = $zo->getZ() +0.07;
                                     $zzz = 0.07000000000000001;
                                 } else {
                                     //$zZ = $zo->getZ() -0.07;
                                     $zzz = -0.07000000000000001;
                                 }
                                 if ($xxx == 0 and $zzz == 0) {
                                     $xxx = 0.1;
                                 }
                                 $zom['xxx'] = $xxx * 10;
                                 $zom['zzz'] = $zzz * 10;
                                 //计算y轴
                                 //$width = $this->width;
                                 $pos0 = new Vector3($zo->getX(), $zo->getY() + 1, $zo->getZ());
                                 //原坐标
                                 $pos = new Vector3($zo->getX() + $xxx, $zo->getY() + 1, $zo->getZ() + $zzz);
                                 //目标坐标
                                 $zy = $this->ifjump($zo->getLevel(), $pos, true);
                                 if ($zy === false) {
                                     //前方不可前进
                                     //伪自由落体
                                     if ($this->ifjump($zo->getLevel(), $pos0, true) === false) {
                                         //原坐标依然是悬空
                                         $pos2 = new Vector3($zo->getX(), $zo->getY() - 2, $zo->getZ());
                                         //下降
                                         $zom['up'] = 1;
                                         $zom['yup'] = 0;
                                         //var_dump("2");
                                     } else {
                                         if ($this->whatBlock($level, $pos0) == "climb") {
                                             //梯子
                                             $zy = $pos0->y + 0.07000000000000001;
                                             $pos2 = new Vector3($zo->getX(), $zy - 1, $zo->getZ());
                                             //目标坐标
                                         } elseif ($xxx != 0 and $zzz != 0) {
                                             //走向最近距离
                                             if ($this->ifjump($zo->getLevel(), new Vector3($zo->getX() + $xxx, $zo->getY() + 1, $zo->getZ()), true) !== false) {
                                                 $pos2 = new Vector3($zo->getX() + $xxx, floor($zo->getY()), $zo->getZ());
                                                 //目标坐标
                                             } elseif ($this->ifjump($zo->getLevel(), new Vector3($zo->getX(), $zo->getY() + 1, $zo->getZ() + $zzz), true) !== false) {
                                                 $pos2 = new Vector3($zo->getX(), floor($zo->getY()), $zo->getZ() + $zzz);
                                                 //目标坐标
                                             } else {
                                                 $pos2 = new Vector3($zo->getX() - $xxx, floor($zo->getY()), $zo->getZ() - $zzz);
                                                 //目标坐标
                                                 //转向180度,向身后走
                                                 $zom['up'] = 0;
                                             }
                                         } else {
                                             $pos2 = new Vector3($zo->getX() - $xxx, floor($zo->getY()), $zo->getZ() - $zzz);
                                             //目标坐标
                                             //转向180度,向身后走
                                             $zom['up'] = 0;
                                         }
                                     }
                                 } else {
                                     $pos2 = new Vector3($zo->getX() + $xxx, $zy - 1, $zo->getZ() + $zzz);
                                     //目标坐标
                                     //echo $zy;
                                     $zom['up'] = 0;
                                     if ($this->whatBlock($level, $pos2) == "water") {
                                         $zom['swim'] += 1;
                                         if ($zom['swim'] >= 20) {
                                             $zom['swim'] = 0;
                                         }
                                     } else {
                                         $zom['swim'] = 0;
                                     }
                                     //var_dump("目标:".($zy - 1) );
                                     //var_dump("原先:".$zo->getY());
                                     if (abs($zy - 1 - floor($zo->getY())) == 1) {
                                         //var_dump("跳");
                                         $zom['jump'] = 0.5;
                                     } else {
                                         if ($zom['jump'] > 0.01) {
                                             $zom['jump'] -= 0.1;
                                         } else {
                                             $zom['jump'] = 0.01;
                                         }
                                     }
                                 }
                                 $zo->setPosition($pos2);
                                 $v3 = new Vector3($zo->getX(), $zo->getY() + 2, $zo->getZ());
                                 $yaw = $this->getyaw($xxx, $zzz);
                                 $pos3 = $pos2;
                                 $pos3->y = $pos3->y + 2.62;
                                 $ppos = $p->getLocation();
                                 $ppos->y = $ppos->y + $p->getEyeHeight();
                                 $pitch = $this->getpitch($pos3, $ppos);
                                 $zom['x'] = $zo->getX();
                                 $zom['y'] = $zo->getY();
                                 $zom['z'] = $zo->getZ();
                                 $zom['yaw'] = $yaw;
                                 $zom['pitch'] = $pitch;
                                 $pk3 = new SetEntityMotionPacket();
                                 $pk3->entities = [[$zo->getID(), $xxx, -$zom['swim'] / 100 + $zom['jump'], $zzz]];
                                 foreach ($zo->getViewers() as $pl) {
                                     $pl->dataPacket($pk3);
                                 }
                                 if ($zom['type'] == "34") {
                                     //$zom['type'] = "skeleton";
                                     if ($zom['hurt'] >= 10) {
                                         $zom['hurt'] = $zom['hurt'] - 1;
                                     } else {
                                         $chunk = $level->getChunk($v3->x >> 4, $v3->z >> 4, true);
                                         $nbt = $this->getNBT($v3);
                                         $posnn = new Vector3($zo->getX(), $p->getY(), $zo->getZ());
                                         $my = $p->getY() - $zo->getY();
                                         $d = $p->distance($posnn);
                                         $pitch = $this->getmypitch($my, $d);
                                         $nbt2 = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $zo->getX()), new Double("", $zo->getY()), new Double("", $zo->getZ())]), "Motion" => new Enum("Motion", [new Double("", -\sin($zom['yaw']) * \cos($pitch / 180 * M_PI)), new Double("", -\sin($pitch / 180 * M_PI)), new Double("", \cos($zom['yaw'] / 180 * M_PI) * \cos($pitch / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $zom['yaw']), new Float("", $pitch)])]);
                                         $f = 1.5;
                                         //$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this), $f);
                                         //$ev = new EntityShootBowEvent($zo, new ITEM(262,0), Entity::createEntity("Arrow", $chunk, $nbt2, $p), $f);
                                         //var_dump("shoot|".-$zom['pitch']."|".$zom['yaw']);
                                         //var_dump(233333);
                                         $arrow = new Arrow($chunk, $nbt2);
                                         $arrow->setPosition($v3);
                                         $arrow->spawnToAll();
                                         //$p = $this->getServer()->getPlayer($zom['IsChasing']);
                                         //$d = $p->distance($v3);
                                         //$d = $d/1.2;
                                         //var_dump($d);
                                         if (!isset($this->arrow[$arrow->getId()])) {
                                             $this->addarrow($arrow->getId(), $zom['yaw'], $arrow->getLevel()->getName(), $arrow->getX(), $arrow->getY(), $arrow->getZ(), $p->getX(), $p->getY(), $p->getZ());
                                         }
                                         $zom['hurt'] = 20;
                                     }
                                 }
                                 if (0 <= $p->distance($pos) and $p->distance($pos) <= 1.5) {
                                     if ($zom['type'] == "33") {
                                         //$zom['type'] = "FiringCreeper";
                                         $zom['IsStop'] = 1;
                                         $zom['time'] = 30;
                                     }
                                     if ($zom['type'] == "32") {
                                         //$zom['type'] = "Zombie";
                                         if ($zom['hurt'] >= 0) {
                                             $zom['hurt'] = $zom['hurt'] - 1;
                                         } else {
                                             $p->knockBack($zo, 0, $xxx, $zzz, 0.4);
                                             if ($p->isSurvival()) {
                                                 $p->sethealth($p->gethealth() - $this->dif * 2);
                                             }
                                             $zom['hurt'] = 10;
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($zom['IsChasing'] === false) {
                                 if ($zom['up'] == 1) {
                                     if ($zom['yup'] <= 10) {
                                         $pk3 = new SetEntityMotionPacket();
                                         $pk3->entities = [[$zo->getID(), $zom['motionx'] / 10, $zom['motiony'] / 10, $zom['motionz'] / 10]];
                                         foreach ($zo->getViewers() as $pl) {
                                             $pl->dataPacket($pk3);
                                         }
                                     } else {
                                         $pk3 = new SetEntityMotionPacket();
                                         $pk3->entities = [[$zo->getID(), $zom['motionx'] / 10 - $zom['motiony'] / 10, $zom['motionz'] / 10]];
                                         foreach ($zo->getViewers() as $pl) {
                                             $pl->dataPacket($pk3);
                                         }
                                     }
                                 } else {
                                     $pk3 = new SetEntityMotionPacket();
                                     $pk3->entities = [[$zo->getID(), $zom['motionx'] / 10, -$zom['motiony'] / 10, $zom['motionz'] / 10]];
                                     foreach ($zo->getViewers() as $pl) {
                                         $pl->dataPacket($pk3);
                                     }
                                 }
                             }
                         }
                     } else {
                         $zom['time'] = $zom['time'] - 1;
                         if ($zom['time'] <= 0) {
                             //$zo->sethealth(0);
                             unset($this->animals[$zo->getId()]);
                             $level->removeEntity($level->getEntity($zo->getId()));
                             $e = new Explosion(new Position($zo->getX(), $zo->getY(), $zo->getZ(), $level), $this->bomb);
                             $e->explode();
                             //$pos = new Vector3($zo->getX(), $zo->getY(), $zo->getZ());
                         }
                     }
                 } else {
                     unset($this->animals[$animal['ID']]);
                 }
             }
         }
     }
     unset($zo);
 }
Exemplo n.º 4
0
 /**
  * 高密集型发包计时器
  * - 发送数据包
  * - 计算自由落体相关数据
  * 循环间隔:1 tick
  */
 public function CreeperRandomWalk()
 {
     foreach ($this->plugin->getServer()->getLevels() as $level) {
         foreach ($level->getEntities() as $zo) {
             if ($zo instanceof Creeper) {
                 if (isset($this->plugin->Creeper[$zo->getId()])) {
                     $zom =& $this->plugin->Creeper[$zo->getId()];
                     if ($zom['canAttack'] != 0) {
                         $zom['canAttack'] -= 1;
                     }
                     $pos = $zo->getLocation();
                     //echo ($zom['IsChasing']."\n");
                     if ($zom['boom'] == false) {
                         //真正的自由落体 by boybook
                         if ($zom['drop'] !== false) {
                             $olddrop = $zom['drop'];
                             $zom['drop'] += 0.5;
                             $drop = $zom['drop'];
                             //echo $drop."\n";
                             $dropy = $zo->getY() - ($olddrop * 0.05 + 0.0125);
                             $posd0 = new Vector3(floor($zo->getX()), floor($dropy), floor($zo->getZ()));
                             $posd = new Vector3($zo->getX(), $dropy, $zo->getZ());
                             if ($this->plugin->whatBlock($zo->getLevel(), $posd0) == "air") {
                                 $zo->setPosition($posd);
                                 //下降
                             } else {
                                 for ($i = 1; $i <= $drop; $i++) {
                                     $posd0->y++;
                                     if ($this->plugin->whatBlock($zo->getLevel(), $posd0) != "block") {
                                         $posd->y = $posd0->y;
                                         //$zo->setPosition($posd);  //下降完成
                                         $h = $zom['drop'] * $zom['drop'] / 20;
                                         $damage = $h - 3;
                                         //echo($h . ": " . $damage . "\n");
                                         if ($damage > 0) {
                                             //$zo->attack($damage, EntityDamageEvent::CAUSE_FALL);
                                             $zo->setHealth($zo->getHealth() - $damage);
                                         }
                                         $zom['drop'] = false;
                                         break;
                                     }
                                 }
                             }
                         } else {
                             $drop = 0;
                         }
                         if ($zom['IsChasing'] !== false) {
                             //var_dump($zom['IsChasing']);
                             if (!$zom['knockBack']) {
                                 //echo $zy;
                                 $zom['up'] = 0;
                                 if ($this->plugin->whatBlock($level, $pos) == "water") {
                                     $zom['swim'] += 1;
                                     if ($zom['swim'] >= 20) {
                                         $zom['swim'] = 0;
                                     }
                                 } else {
                                     $zom['swim'] = 0;
                                 }
                                 //echo("目标:".$zo->getY()." ");
                                 //echo("原先:".$zom['oldv3']->y."\n");
                                 if (abs($zo->getY() - $zom['oldv3']->y) == 1 and $zom['canjump'] === true) {
                                     //var_dump("跳");
                                     $zom['canjump'] = false;
                                     $zom['jump'] = 0.5;
                                 } else {
                                     if ($zom['jump'] > 0.01) {
                                         $zom['jump'] -= 0.1;
                                     } else {
                                         $zom['jump'] = 0.01;
                                     }
                                 }
                                 $pk3 = new SetEntityMotionPacket();
                                 $pk3->entities = [[$zo->getID(), $zom['xxx'] / 10, -$zom['swim'] / 100 + $zom['jump'] - $drop, $zom['zzz'] / 10]];
                                 foreach ($zo->getViewers() as $pl) {
                                     $pl->dataPacket($pk3);
                                 }
                                 $p = $this->plugin->getServer()->getPlayer($zom['IsChasing']);
                                 if ($p instanceof Player) {
                                     if ($p->distance($pos) <= 1.3) {
                                         //苦力怕的火焰点燃人类
                                         // if ($zo->fireTicks > 0) {
                                         //   $p->setOnFire(5);
                                         // }
                                     }
                                     if ($p->distance($pos) <= 2) {
                                         //boom
                                         $zom['boom'] = 5;
                                     }
                                     if ($p->distance($pos) <= 1.5) {
                                         if ($zom['canAttack'] == 0) {
                                             $zom['canAttack'] = 20;
                                             @$p->knockBack($zo, 0, $zom['xxx'] / 10, $zom['zzz'] / 10);
                                             if ($p->isSurvival()) {
                                                 $damage = 0;
                                                 //echo $zoDamage."-".$damage."\n";
                                                 //$p->attack($damage);
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             //echo ".";
                             $pk3 = new SetEntityMotionPacket();
                             $pk3->entities = [[$zo->getID(), $zom['motionx'] / 10, 0, $zom['motionz'] / 10]];
                             foreach ($zo->getViewers() as $pl) {
                                 $pl->dataPacket($pk3);
                             }
                         }
                     } else {
                         $zom['boom'] = $zom['boom'] - 1;
                         if ($zom['boom'] <= 0) {
                             unset($this->plugin->Creeper[$zo->getId()]);
                             $level->removeEntity($level->getEntity($zo->getId()));
                             $e = new Explosion(new Position($zo->getX(), $zo->getY(), $zo->getZ(), $level), $this->bomb);
                             $e->explode();
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 public function onCommand(CommandSender $issuer, Command $cmd, $label, array $args)
 {
     switch ($cmd->getName()) {
         case "adminfun":
             if (isset($args[0])) {
                 switch ($args[0]) {
                     case "announce":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.announce")) {
                             if (count($args) > 1) {
                                 unset($args[0]);
                                 $msg = implode(" ", $args);
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%msg%"), array("§", $msg), $this->getPlugin()->getConfig()->get("announce-format")));
                                 return true;
                             } else {
                                 $issuer->sendMessage("Usage: /af announce <msg>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "bgod":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.bgod")) {
                             if (count($args) > 1) {
                                 unset($args[0]);
                                 $msg = implode(" ", $args);
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%msg%"), array("§", $msg), $this->getPlugin()->getConfig()->get("bgod-format")));
                                 return true;
                             } else {
                                 $issuer->sendMessage("Usage: /af bgod <msg>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "bherobrine":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.bherobrine")) {
                             if (count($args) > 1) {
                                 unset($args[0]);
                                 $msg = implode(" ", $args);
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%msg%"), array("§", $msg), $this->getPlugin()->getConfig()->get("bherobrine-format")));
                                 return true;
                             } else {
                                 $issuer->sendMessage("Usage: /af bherobrine <msg>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "broadcast":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.broadcast")) {
                             if (count($args) > 1) {
                                 unset($args[0]);
                                 $msg = implode(" ", $args);
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace("&", "§", $msg));
                                 return true;
                             } else {
                                 $issuer->sendMessage("Usage: /af broadcast <msg..>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "burn":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.burn")) {
                             if (isset($args[1]) && isset($args[2])) {
                                 $target = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 if ($target !== null) {
                                     if (is_numeric($args[2])) {
                                         $target->setOnFire($args[2]);
                                         $issuer->sendMessage("§a" . $target->getName() . " has catched on fire!");
                                         $target->sendMessage("§eNeed an extinguisher? §m§blol");
                                         return true;
                                     } else {
                                         $issuer->sendMessage("§cInvalid time!");
                                         return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("Invalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af burn <player> <seconds>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "confuse":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.confuse")) {
                             if (isset($args[1])) {
                                 $target = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 if ($target !== null) {
                                     if ($this->getPlugin()->isConfused($target) !== true) {
                                         $this->getPlugin()->confuse($target);
                                         $issuer->sendMessage("§aYou confused " . $target->getName() . "!");
                                         return true;
                                     } else {
                                         $this->getPlugin()->unConfuse($target);
                                         $issuer->sendMessage("§aYou unconfused " . $target->getName() . "!");
                                         return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("§cInvalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af confuse <player>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "console":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.console")) {
                             if (count($args) > 1) {
                                 unset($args[0]);
                                 $msg = implode(" ", $args);
                                 $this->getPlugin()->getServer()->broadcastMessage("§o§7[CONSOLE: " . $msg . "§7]");
                                 return true;
                             } else {
                                 $issuer->sendMessage("Usage: /af console <msg>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "explode":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.explode")) {
                             if ($issuer instanceof Player) {
                                 if (isset($args[1])) {
                                     if (is_numeric($args[1])) {
                                         if (isset($args[2])) {
                                             $target = $this->getPlugin()->getServer()->getPlayer($args[2]);
                                             if ($target !== null) {
                                                 $explosion = new Explosion(new Position($target->x, $target->y, $target->z, $target->getLevel()), $args[1]);
                                                 $explosion->explode();
                                                 $issuer->sendMessage("§e§lEXPLODE!!");
                                                 return true;
                                             } else {
                                                 $issuer->sendMessage("§cInvalid target!");
                                                 return true;
                                             }
                                         } else {
                                             $explosion = new Explosion(new Position($issuer->x, $issuer->y, $issuer->z, $issuer->getLevel()), $args[1]);
                                             $explosion->explode();
                                             $issuer->sendMessage("§e§lEXPLODE!!");
                                             return true;
                                         }
                                     } else {
                                         $issuer->sendMessage("§cInvalid radius!");
                                         return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("Usage: /af explode <radius> <player>");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("§cCommand only works in-game!");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "fakejoin":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.fakejoin")) {
                             if (isset($args[1])) {
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%name%"), array("§", $args[1]), $this->getPlugin()->getConfig()->get("fakejoin-format")));
                                 return true;
                             } else {
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%name%"), array("§", $issuer->getName()), $this->getPlugin()->getConfig()->get("fakejoin-format")));
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "fakeop":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.fakeop")) {
                             if (isset($args[1])) {
                                 $target = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 if ($target !== null) {
                                     $target->sendMessage("§7You are now op!");
                                     $issuer->sendMessage("§3You fakeopped " . $target->getName() . "!");
                                     return true;
                                 } else {
                                     $issuer->sendMessage("Invalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af fakeop <player>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "fakequit":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.fakequit")) {
                             if (isset($args[1])) {
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%name%"), array("§", $args[1]), $this->getPlugin()->getConfig()->get("fakequit-format")));
                                 return true;
                             } else {
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%name%"), array("§", $issuer->getName()), $this->getPlugin()->getConfig()->get("fakequit-format")));
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "help":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.help")) {
                             if (!isset($args[1])) {
                                 $issuer->sendMessage("§2Showing help page §6(1/3)");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun announce <msg..>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun bgod <msg..>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun bherobrine <msg..>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun broadcast <msg..>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun burn <player> <seconds>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun confuse <player>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun console <msg..>");
                                 $issuer->sendMessage("§l§b- §r§f/adminfun explode <player> <radius>");
                                 return true;
                             } else {
                                 if (is_numeric($args[1])) {
                                     switch ($args[1]) {
                                         case 1:
                                             $this->getPlugin()->getServer()->dispatchCommand($issuer, "af help");
                                             return true;
                                             break;
                                         case 2:
                                             $issuer->sendMessage("§aShowing help page §6(2/3)");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun fakejoin <name>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun fakeop <player>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun fakequit <name>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun freeze <player>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun help <1|2|3>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun maxhealth <hearts>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun playerchat <player> <msg..>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun randomtp <troll/safe> <player>");
                                             return true;
                                             break;
                                         case 3:
                                             $issuer->sendMessage("§aShowing help page §6(3/3)");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun reload");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun rocket <player>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun spamcast <msg..>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun swap <player1> <player2>");
                                             $issuer->sendMessage("§l§b- §r§f/adminfun void <player>");
                                             return true;
                                             break;
                                     }
                                 } else {
                                     $this->getPlugin()->getServer()->dispatchCommand($issuer, "af help");
                                     return true;
                                 }
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "freeze":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.freeze")) {
                             if (isset($args[1])) {
                                 $target = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 if ($target !== null) {
                                     if ($this->getPlugin()->isFrozen($target) !== true) {
                                         $this->getPlugin()->freeze($target);
                                         $issuer->sendMessage($target->getName() . " §ahas been frozen!");
                                         $target->sendMessage("§eYou have been §bfrozen§e!");
                                         return true;
                                     } else {
                                         $this->getPlugin()->unfreeze($target);
                                         $issuer->sendMessage($target->getName() . " §ahas been unfrozen!");
                                         $target->sendMessage("§eYou have been §cunfrozen§e!");
                                         return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("§cInvalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af freeze <player>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "maxhealth":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.morehealth")) {
                             if ($issuer instanceof Player) {
                                 if (isset($args[1])) {
                                     if (is_numeric($args[1])) {
                                         $issuer->setMaxHealth($args[1] * 2);
                                         $issuer->setHealth($issuer->getMaxHealth());
                                         $issuer->sendMessage("§aSet " . $args[1] . " hearts as your max health!\n§a+ Healed you!");
                                         return true;
                                     } else {
                                         $issuer->sendMessage("§cInvalid numbers of hearts!");
                                         return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("Usage: /af maxhealth <hearts>");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("§cCommand only works in-game!");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "playerchat":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.playerchat")) {
                             if (isset($args[1]) && count($args) > 2) {
                                 $target = str_replace("&", "§", $args[1]);
                                 unset($args[1]);
                                 unset($args[0]);
                                 $msg = implode(" ", $args);
                                 $this->getPlugin()->getServer()->broadcastMessage(str_replace(array("&", "%name%", "%msg%"), array("§", $target, $msg), $this->getPlugin()->getConfig()->get("playerchat-format")));
                                 return true;
                             } else {
                                 $issuer->sendMessage("Usage: /af playerchat <player> <msg..>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "randomtp":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.randomtp")) {
                             if ($issuer instanceof Player) {
                                 if (isset($args[1])) {
                                     switch ($args[1]) {
                                         case "troll":
                                             if (isset($args[2])) {
                                                 $target = $this->getPlugin()->getServer()->getPlayer($args[2]);
                                                 if ($target !== null) {
                                                     $target->setGamemode(0);
                                                     $target->teleport(new Position(rand(0, 255), rand(0, 255), rand(0, 255), $target->getLevel()));
                                                     $issuer->sendMessage("§aYou teleported " . $target->getName() . " to a random location!");
                                                     $target->sendMessage("§l§eLOL");
                                                     return true;
                                                 } else {
                                                     $issuer->sendMessage("§cInvalid target!");
                                                     return true;
                                                 }
                                             } else {
                                                 $issuer->sendMessage("§cIf you choose 'troll', you must enter the target's name!  You won't troll yourself right..?");
                                                 return true;
                                             }
                                             break;
                                         case "safe":
                                             if (isset($args[2])) {
                                                 $target = $this->getPlugin()->getServer()->getPlayer($args[2]);
                                                 if ($target !== null) {
                                                     $x = rand(0, 255);
                                                     $z = rand(0, 255);
                                                     $y = rand(0, 200);
                                                     $target->teleport($target->getLevel()->getSafeSpawn(new Vector3($x, $y, $z)));
                                                     $issuer->sendMessage("§aTeleported " . $target->getName() . " to a safe random location");
                                                     return true;
                                                 } else {
                                                     $issuer->sendMessage("§cInvalid target!");
                                                     return true;
                                                 }
                                             } else {
                                                 $x = rand(0, 255);
                                                 $z = rand(0, 255);
                                                 $y = rand(0, 200);
                                                 $issuer->teleport($issuer->getLevel()->getSafeSpawn(new Vector3($x, $y, $z)));
                                                 $issuer->sendMessage("§aTeleported to a safe random location");
                                                 return true;
                                             }
                                             break;
                                         default:
                                             $issuer->sendMessage("§cInvalid args[1]");
                                             return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("Usage: /af randomtp troll|safe <player>");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Command only works in-game!");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "reload":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.reload")) {
                             $this->getPlugin()->saveDefaultConfig();
                             $this->getPlugin()->reloadConfig();
                             $issuer->sendMessage("§bAdminFun §ahas been reloaded!");
                             return true;
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "rocket":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.rocket")) {
                             if (isset($args[1])) {
                                 $target = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 if ($target !== null) {
                                     $target->getLevel()->addSound(new LaunchSound($target));
                                     $motion = new Vector3($target->motionX, $target->motionY, $target->motionZ);
                                     $motion->y = 20;
                                     $target->setMotion($motion);
                                     $target->sendMessage("§b§lYou turned into a rocket!");
                                     $issuer->sendMessage("§aYou turned " . $target->getName() . " into a rocket!");
                                     return true;
                                 } else {
                                     $issuer->sendMessage("§cInvalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af rocket <player>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "spamcast":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.spamcast")) {
                             if (count($args) > 1) {
                                 foreach ($this->getPlugin()->getServer()->getOnlinePlayers() as $p) {
                                     unset($args[0]);
                                     $msg = implode(" ", $args);
                                     for ($i = 0; $i < 20; $i++) {
                                         $p->sendMessage("§l[SpamCast] §3" . $msg);
                                     }
                                     $issuer->sendMessage("§aMessage has been spammed!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af spamcast <msg..>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "swap":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.swap")) {
                             if (isset($args[1]) && isset($args[2])) {
                                 $player1 = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 $player2 = $this->getPlugin()->getServer()->getPlayer($args[2]);
                                 if ($player1 !== null && $player2 !== null) {
                                     if ($player1->getName() != $player2->getName()) {
                                         $x1 = $player1->x;
                                         $y1 = $player1->y;
                                         $z1 = $player1->z;
                                         $w1 = $player1->getLevel();
                                         $x2 = $player2->x;
                                         $y2 = $player2->y;
                                         $z2 = $player2->z;
                                         $w2 = $player2->getLevel();
                                         $player2->teleport(new Position($x1, $y1, $z1, $w1));
                                         $player1->teleport(new Position($x2, $y2, $z2, $w2));
                                         $issuer->sendMessage(TextFormat::GREEN . "You swap " . $player1->getName() . "'s and " . $player2->getName() . "'s position!");
                                         return true;
                                     } else {
                                         $issuer->sendMessage("§cYou cannot swap between the same person!");
                                         return true;
                                     }
                                 } else {
                                     $issuer->sendMessage("§cInvalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af swap <player1> <player2>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                     case "void":
                         if ($issuer->hasPermission("adminfun.command") || $issuer->hasPermission("adminfun.command.void")) {
                             if (isset($args[1])) {
                                 $target = $this->getPlugin()->getServer()->getPlayer($args[1]);
                                 if ($target !== null) {
                                     $target->teleport(new Position($target->x, 0, $target->z, $target->getLevel()));
                                     $target->sendMessage("§l§aWelcome to the void!");
                                     $issuer->sendMessage("§aYou teleported " . $target->getName() . " to the void!");
                                     return true;
                                 } else {
                                     $issuer->sendMessage("§cInvalid target!");
                                     return true;
                                 }
                             } else {
                                 $issuer->sendMessage("Usage: /af void <player>");
                                 return true;
                             }
                         } else {
                             $issuer->sendMessage("§cYou don't have permission for this!");
                             return true;
                         }
                         break;
                 }
             } else {
                 return false;
             }
             break;
     }
 }
Exemplo n.º 6
0
 public function onBlockBreak(BlockBreakEvent $event)
 {
     $player = $event->getPlayer()->getName();
     if (in_array($player, $this->blockexplode)) {
         $explosion = new Explosion(new Position($event->getBlock()->getX(), $event->getBlock()->getY(), $event->getBlock()->getZ(), $event->getPlayer()->getLevel()), 6);
         $explosion->explode();
     } elseif (in_array($player, $this->lavablock)) {
         $x = $event->getBlock()->getX();
         $y = $event->getBlock()->getY();
         $z = $event->getBlock()->getZ();
         $level = $event->getPlayer()->getLevel();
         $this->getServer()->getLevel($level)->setBlock(new Vector3($x, $y, $z), Block::get(9, 0));
     }
 }