Пример #1
0
 public function getMaskLocation(Player $player)
 {
     // always return player current location if there is an error
     if (!$this->maskLoc) {
         return $player->getLocation();
     }
     if (!preg_match('#^((\\?spawn\\?)|((\\-)?[0-9]+,(\\-)?[0-9]+,(\\-)?[0-9]+))@([^/\\\\]+)$#', $this->maskLocPos, $match)) {
         return $player->getLocation();
     }
     $pos = $match[1];
     $world = $match[7];
     $level = $player->getLevel();
     if ($world === "?default?") {
         $level = $player->getServer()->getDefaultLevel();
     } elseif ($world !== "?current?") {
         $level = $player->getServer()->getLevelByName($world);
         if (!$level instanceof Level) {
             $level = $player->getLevel();
         }
     }
     if ($pos === "?spawn?") {
         $position = $level->getSpawnLocation();
     } else {
         list($x, $y, $z) = explode(",", $pos);
         $position = new Position((int) $x, (int) $y, (int) $z, $level);
     }
     return $position;
 }
Пример #2
0
 public function spawnDiscourager()
 {
     $dir = $this->player->getDirectionVector();
     if ($this->player->pitch > 45 or $this->player->pitch < -45) {
         $face = 0;
         // y
     } else {
         $face = self::$conversionTable[$this->player->getDirection()];
     }
     $center = $this->player->subtract($dir->multiply($this->main->getDistance()))->add(0, $this->player->eyeHeight)->floor();
     $l = $this->player->getLevel();
     if ($face === self::Y) {
         $this->overridenBlocks = [$l->getBlock($center->add(1, 0, 1)), $l->getBlock($center->add(1, 0, 0)), $l->getBlock($center->add(1, 0, -1)), $l->getBlock($center->add(0, 0, 1)), $l->getBlock($center), $l->getBlock($center->add(0, 0, -1)), $l->getBlock($center->add(-1, 0, 1)), $l->getBlock($center->add(-1, 0, 0)), $l->getBlock($center->add(-1, 0, -1))];
     } elseif ($face === self::X) {
         $this->overridenBlocks = [$l->getBlock($center->add(0, 1, 1)), $l->getBlock($center->add(0, 1, 0)), $l->getBlock($center->add(0, 1, -1)), $l->getBlock($center->add(0, 0, 1)), $l->getBlock($center), $l->getBlock($center->add(0, 0, -1)), $l->getBlock($center->add(0, -1, 1)), $l->getBlock($center->add(0, -1, 0)), $l->getBlock($center->add(0, -1, -1))];
     } elseif ($face === self::Z) {
         $this->overridenBlocks = [$l->getBlock($center->add(1, 1, 0)), $l->getBlock($center->add(1, 0, 0)), $l->getBlock($center->add(1, -1, 0)), $l->getBlock($center->add(0, 1, 0)), $l->getBlock($center), $l->getBlock($center->add(0, -1, 0)), $l->getBlock($center->add(-1, 1, 0)), $l->getBlock($center->add(-1, 0, 0)), $l->getBlock($center->add(-1, -1, 0))];
     }
     foreach ($this->overridenBlocks as $b) {
         $pk = new UpdateBlockPacket();
         $pk->x = $b->x;
         $pk->y = $b->y;
         $pk->z = $b->z;
         $pk->block = $this->main->getBlockType()->getId();
         $pk->meta = $this->main->getBlockType()->getDamage();
         $this->player->dataPacket($pk);
     }
 }
Пример #3
0
 public function CritParticle(Player $player)
 {
     $x = $player->x;
     $y = $player->y;
     $z = $player->z;
     $player->getLevel()->addParticle(new CriticalParticle(new Vector3($x, $y + 1, $z - 1)));
     $player->getLevel()->addParticle(new CriticalParticle(new Vector3($x, $y + 1, $z - 0.9)));
     $player->getLevel()->addParticle(new CriticalParticle(new Vector3($x, $y + 1, $z - 1.1)));
 }
Пример #4
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) {
         $faces = [2 => 0, 3 => 2, 4 => 1, 5 => 3];
         $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]];
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = ["x" => $target->x, "y" => $target->y + 0.4, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
         $nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new EnumTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]);
         $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt);
         $painting->spawnToAll();
         if ($player->isSurvival()) {
             $item = $player->getInventory()->getItemInHand();
             $count = $item->getCount();
             if (--$count <= 0) {
                 $player->getInventory()->setItemInHand(Item::get(Item::AIR));
                 return;
             }
             $item->setCount($count);
             $player->getInventory()->setItemInHand($item);
         }
         //TODO
         //$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
         //$e->spawnToAll();
         /*if(($player->gamemode & 0x01) === 0x00){
         			$player->removeItem(Item::get($this->getId(), $this->getDamage(), 1));
         		}*/
         return true;
     }
     return false;
 }
Пример #5
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($player === null or $player->isSurvival() !== true) {
         return false;
     }
     if ($target->getId() === Block::STILL_WATER or $target->getId() === Block::WATER) {
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerGlassBottleEvent($player, $target, $this));
         if ($ev->isCancelled()) {
             return false;
         } else {
             if ($this->count <= 1) {
                 $player->getInventory()->setItemInHand(Item::get(Item::POTION, 0, 1));
                 return true;
             } else {
                 $this->count--;
                 $player->getInventory()->setItemInHand($this);
             }
             if ($player->getInventory()->canAddItem(Item::get(Item::POTION, 0, 1)) === true) {
                 $player->getInventory()->AddItem(Item::get(Item::POTION, 0, 1));
             } else {
                 $motion = $player->getDirectionVector()->multiply(0.4);
                 $position = clone $player->getPosition();
                 $player->getLevel()->dropItem($position->add(0, 0.5, 0), Item::get(Item::POTION, 0, 1), $motion, 40);
             }
             return true;
         }
     }
     return false;
 }
Пример #6
0
 private function handle($cmd, $args, Player $player, CommandSender $issuer)
 {
     switch ($cmd) {
         case "getping":
             $issuer->sendMessage("Ping of " . $player->getName() . ": unknown ms");
             return true;
         case "seearmor":
             $issuer->sendMessage("Armor of " . $player->getName() . ":");
             $issuer->sendMessage("Helmet: " . $this->formatItem($player->getInventory()->getArmorItem(0)));
             $issuer->sendMessage("Chestplate: " . $this->formatItem($player->getInventory()->getArmorItem(1)));
             $issuer->sendMessage("Leggings: " . $this->formatItem($player->getInventory()->getArmorItem(2)));
             $issuer->sendMessage("Boots: " . $this->formatItem($player->getInventory()->getArmorItem(3)));
             return true;
         case "seegm":
             $issuer->sendMessage("Gamemode of " . $player->getName() . ": " . $this->formatGamemode($player->getGamemode()));
             return true;
         case "getpos":
             $issuer->sendMessage($player->getName() . " is at (" . TextFormat::YELLOW . $player->x . ", " . TextFormat::GREEN . $player->y . ", " . TextFormat::AQUA . $player->z . ") in world " . TextFormat::RED . $player->getLevel()->getName() . ".");
             return true;
         case "setarmor":
             // TODO
             break;
         case "rmarmor":
             // TODO
             break;
         case "sessions":
             // TODO
             break;
     }
     return false;
 }
Пример #7
0
 public function execute(Player $player)
 {
     $command = $this->compiledCommand;
     $type = $this->executionMode;
     $command = str_replace("%p", $player->getName(), $command);
     $command = str_replace("%x", $player->getX(), $command);
     $command = str_replace("%y", $player->getY(), $command);
     $command = str_replace("%z", $player->getZ(), $command);
     $command = str_replace("%l", $player->getLevel()->getName(), $command);
     $command = str_replace("%ip", $player->getAddress(), $command);
     $command = str_replace("%n", $player->getDisplayName(), $command);
     if ($type === Command::AS_OP_TYPE && $player->isOp()) {
         $type = Command::AS_PLAYER_TYPE;
     }
     switch ($type) {
         case Command::AS_CONSOLE_TYPE:
             $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
             break;
         case Command::AS_OP_TYPE:
             $player->setOp(true);
             $this->plugin->getServer()->dispatchCommand($player, $command);
             $player->setOp(false);
             break;
         case Command::AS_PLAYER_TYPE:
             $this->plugin->getServer()->dispatchCommand($player, $command);
             break;
     }
 }
Пример #8
0
 public function onRun($currentTick)
 {
     if ($this->firstTick === -1) {
         $flags = (int) $this->target->getDataProperty(Player::DATA_FLAGS);
         $flags ^= 1 << Player::DATA_FLAG_ONFIRE;
         $dataProperty = [Player::DATA_FLAGS => [Player::DATA_TYPE_BYTE, $flags]];
         $pk = new SetEntityDataPacket();
         $pk->eid = $this->target->getId();
         $pk->metadata = $dataProperty;
         Server::broadcastPacket($this->whose->getLevel()->getPlayers(), $pk);
         $this->firstTick = $currentTick;
     }
     if ($this->firstTick - $this->tick <= 0) {
         $this->getHandler()->cancel();
     }
     $this->target->attack(2, new EntityDamageByEntityEvent($this->whose, $this->target, EntityDamageByEntityEvent::CAUSE_FIRE_TICK, 2, 0));
 }
Пример #9
0
 public function onRun(array $args, Player $player)
 {
     if (!isset($args[0])) {
         return self::WRONG_USE;
     }
     $center = $player->floor();
     $level = $player->getLevel();
     $radius = floatval(array_shift($args));
     $height = (int) array_shift($args);
     $axis = WorldEditArt::directionNumber2Array($player->getDirection());
     while (count($args) > 0) {
         $arg = array_shift($args);
         switch ($arg) {
             case "a":
             case "anchor":
                 $anchor = $this->getMain()->getAnchor($player);
                 if (!$anchor instanceof Position) {
                     return self::NO_ANCHOR;
                 }
                 $center = $anchor->floor();
                 break;
             case "d":
                 $d = array_shift($args);
                 switch (strtolower($d)) {
                     case "m":
                     case "me":
                         break;
                     case "u":
                     case "up":
                         $axis = [CylinderSpace::Y, CylinderSpace::PLUS];
                         break;
                     case "d":
                     case "down":
                         $axis = [CylinderSpace::Y, CylinderSpace::MINUS];
                         break;
                     case "l":
                     case "left":
                         $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 3));
                         break;
                     case "r":
                     case "right":
                         $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 1));
                         break;
                     case "b":
                     case "back":
                         $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 2));
                         break;
                 }
                 break;
         }
     }
     $center = Position::fromObject($center, $level);
     $space = new CylinderSpace($axis[0], $radius, $center, $height * $axis[1]);
     $this->getMain()->setSelection($player, $space);
     return "Your selection is now {$space}.";
 }
Пример #10
0
 public function onActivate(Level $level, Player $player, $block, $target, $face, $fx, $fy, $fz)
 {
     foreach ($player->getLevel()->getEntities() as $entity) {
         if ($entity instanceof FishingHook) {
             if ($entity->shootingEntity === $player) {
                 $entity->reelLine();
             }
         }
     }
 }
Пример #11
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $target->getSide($face)->add(0.5, 0.4, 0.5);
     $camera = new TripoidCamera($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $realPos->getX()), new DoubleTag("", $realPos->getY()), new DoubleTag("", $realPos->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $camera->spawnToAll();
     if ($player->isSurvival()) {
         --$this->count;
     }
     return true;
 }
Пример #12
0
 public function onActivate(Item $item, Player $player = \null)
 {
     $this->note++;
     if ($this->note > 24) {
         $this->note = 0;
     }
     $particle = new NoteParticle(new Vector3($this->x + 0.5, $this->y + 1, $this->z + 0.5));
     $player->getLevel()->addParticle($particle);
     $this->PlaySound(200 + $this->note * 60, $player);
     return true;
 }
Пример #13
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (!in_array($target->getId(), array(Block::RAIL, Block::ACTIVATOR_RAIL, Block::DETECTOR_RAIL, Block::POWERED_RAIL))) {
         return false;
     }
     $realPos = $target->add(0.5, 0, 0.5);
     $cart = new MinecartHopperEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $realPos->getX()), new DoubleTag("", $realPos->getY()), new DoubleTag("", $realPos->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $cart->spawnToAll();
     if ($player->isSurvival()) {
         --$this->count;
     }
     return true;
 }
Пример #14
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $block->getSide($face);
     $boat = Entity::createEntity("Boat", $player->getLevel()->getChunk($realPos->x >> 4, $realPos->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->x), new Double("", $realPos->y), new Double("", $realPos->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $boat->spawnToAll();
     --$this->count;
     if ($this->count <= 0) {
         $player->getInventory()->setItemInHand(Item::get(Item::AIR));
         return true;
     }
     $player->getInventory()->setItemInHand($this);
     return true;
 }
Пример #15
0
 public function spawnTo(Player $player)
 {
     if ($player->getLevel() === $this->pos->getLevel()) {
         $pk = new AddItemEntityPacket();
         $pk->eid = $this->eid;
         $pk->item = $this->item;
         $pk->x = $this->pos->x + 0.5;
         $pk->y = $this->pos->y;
         $pk->z = $this->pos->z + 0.5;
         $pk->speedX = $pk->speedY = $pk->speedZ = 0;
         $player->dataPacket($pk);
     }
 }
Пример #16
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $bucketContents = Block::get($this->meta);
     if ($bucketContents instanceof Air) {
         // Bucket Empty so pick up block
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             if ($target instanceof StillWater) {
                 $toStore = Block::WATER;
             } elseif ($target instanceof StillLava) {
                 $toStore = Block::LAVA;
             } else {
                 return false;
             }
             $result->setDamage($toStore);
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem(), $player);
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($bucketContents instanceof Liquid) {
         // Bucket Full, so empty
         $result = clone $this;
         $result->setDamage(0);
         if ($bucketContents instanceof Water) {
             $toCreate = Block::STILL_WATER;
         } elseif ($bucketContents instanceof Lava) {
             $toCreate = Block::STILL_LAVA;
         } else {
             return false;
         }
         $bucketContents = Block::get($toCreate);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             $player->getLevel()->setBlock($block, $bucketContents, true, true);
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem(), $player);
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Пример #17
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $block->getSide($face);
     $boat = new BoatEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $boat->spawnToAll();
     $item = $player->getInventory()->getItemInHand();
     $count = $item->getCount();
     if (--$count <= 0) {
         $player->getInventory()->setItemInHand(Item::get(Item::AIR));
         return;
     }
     $item->setCount($count);
     $player->getInventory()->setItemInHand($item);
     return true;
 }
Пример #18
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 0.8), new DoubleTag("", $block->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return true;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Пример #19
0
 public function illuminate(Player $player)
 {
     if ($player == null) {
         return;
     }
     if ($player->getLevel()->getBlockIdAt($player->x, $player->y + 1, $player->z) == Block::AIR) {
         $this->pk->x = $player->x;
         $this->pk->y = $player->y + 1;
         $this->pk->z = $player->z;
         $this->pk->block = Item::TORCH;
         $this->pk->meta = 0;
         $player->dataPacket($this->pk);
         $this->pk->block = Item::AIR;
         $player->dataPacket($this->pk);
     }
 }
Пример #20
0
 public function getFormattedMessage(Player $player, $message)
 {
     $format = $this->getConfiguration()->getChatFormat();
     $group = $this->getUser($player->getName())->getUserGroup($player->getLevel());
     $prefix = $group->getGroupPrefix();
     $suffix = $group->getGroupSuffix();
     $format = str_replace("{USER_NAME}", $player->getName(), $format);
     $format = str_replace("{MESSAGE}", $message, $format);
     if ($prefix != null) {
         $format = str_replace("{PREFIX}", $prefix, $format);
     } else {
         if ($suffix != null) {
             $format = str_replace("{SUFFIX}", $suffix, $format);
         }
     }
     return $format;
 }
Пример #21
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $targetBlock = Block::get($this->meta);
     if ($targetBlock instanceof Air) {
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             $id = $target->getId();
             if ($id == self::STILL_WATER) {
                 $id = self::WATER;
             }
             if ($id == self::STILL_LAVA) {
                 $id = self::LAVA;
             }
             $result->setDamage($id);
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem());
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($targetBlock instanceof Liquid) {
         $result = clone $this;
         $result->setDamage(0);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             //Only disallow water placement in the Nether, allow other liquids to be placed
             //In vanilla, water buckets are emptied when used in the Nether, but no water placed.
             if (!($player->getLevel()->getDimension() === Level::DIMENSION_NETHER and $targetBlock->getID() === self::WATER)) {
                 $player->getLevel()->setBlock($block, $targetBlock, true, true);
             }
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem());
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Пример #22
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return;
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY() + 1), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Пример #23
0
 public function grantKit($name, Player $player)
 {
     $kit = $this->getPlugin()->getKitStore()->getKit($name);
     if ($kit !== false) {
         if ($player->hasPermission("battlekits.use.{$name}")) {
             if ($kit->isActiveIn($player->getLevel())) {
                 if ($this->getPlugin()->getKitHistoryStore()->canUse($player)) {
                     if (!$kit->isFree()) {
                         if ($this->getPlugin()->isLinkedToEconomy()) {
                             if ($this->getPlugin()->getEconomy()->take($kit->getCost(), $player)) {
                                 $kit->applyTo($player);
                                 $this->getPlugin()->getKitHistoryStore()->kitUsed($player);
                                 return true;
                             } else {
                                 $player->sendMessage("{$name} can't be purchased.");
                                 return false;
                             }
                         } else {
                             $player->sendMessage("{$name} can't be purchased at this time.");
                             return false;
                         }
                     } else {
                         $kit->applyTo($player);
                         $this->getPlugin()->getKitHistoryStore()->kitUsed($player);
                         return true;
                     }
                 } else {
                     $player->sendMessage("You can only use one kit per life.");
                     return false;
                 }
             } else {
                 $player->sendMessage("{$name} is not available in this world.");
                 return false;
             }
         } else {
             $player->sendMessage("You don't have permission to use {$name}.");
             return false;
         }
     } else {
         $player->sendMessage("{$name} doesn't exist.");
         return false;
     }
 }
Пример #24
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $block->getSide(Vector3::SIDE_UP);
     if (!$block instanceof RailBlock) {
         return false;
     }
     $cart = new MinecartEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $cart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Пример #25
0
 public function h_onDamage(EntityDamageEvent $event)
 {
     if ($event->getCause() === EntityDamageEvent::CAUSE_VOID) {
         $event->setCancelled();
         $this->player->teleport($this->player->getLevel()->getSpawnLocation());
     }
     if (!$this->isLoggedIn()) {
         $event->setCancelled();
         $this->disableTpListener = true;
         $this->teleport($this->spawningPosition);
         $this->disableTpListener = false;
     }
     /*if($event instanceof EntityDamageByEntityEvent){
     			$target = $this->getPlayer();
     			$hitter = $event->getDamager();
     			if(!($hitter instanceof Player)){
     				return;
     			}
     			if((pow($hitter->x - $target->x, 2) + pow($hitter->z - $target->z, 2)) <= 2.25){
     				return;
     			}
     			$dir = $hitter
     //				->add(0, $hitter->getEyeHeight(), 0)
     				->subtract(
     					$target
     //						->add(0, $target->height / 2, 0)
     				);
     			$yaw = rad2deg(atan2($dir->z, $dir->x)) + 90;
     //			if(($len = $dir->length()) === 0){
     //				$len = 1;
     //			}
     //			$pitch = rad2deg(asin($dir->y / $len));
     			if((180 - abs(abs($hitter->yaw - $yaw) - 180)) > 90
     //				or (180 - abs(abs($hitter->pitch - $pitch) - 180)) > 60
     			){
     				$event->setCancelled();
     				$hitter->sendMessage("You can't attack players behind you!");
     			}
     		}*/
 }
Пример #26
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($player instanceof Player) {
         $this->meta = ((int) $player->getDirection() + 5) % 4;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     if ($player != null) {
         $firstBlock = $this->getLevel()->getBlock($block->add(0, -1, 0));
         $secondBlock = $this->getLevel()->getBlock($block->add(0, -2, 0));
         $thirdBlock = $this->getLevel()->getBlock($block->add(0, -1, -1));
         $fourthBlock = $this->getLevel()->getBlock($block->add(0, -1, 1));
         $fifthBlock = $this->getLevel()->getBlock($block->add(0, -2, -1));
         $sixthBlock = $this->getLevel()->getBlock($block->add(0, -2, 1));
         if ($firstBlock->getId() === Item::SNOW_BLOCK && $secondBlock->getId() === Item::SNOW_BLOCK) {
             //Block match snowgolem
             $this->getLevel()->setBlock($block, new Air());
             $this->getLevel()->setBlock($firstBlock, new Air());
             $this->getLevel()->setBlock($secondBlock, new Air());
             $snowGolem = new SnowGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x), new Double("", $this->y), new Double("", $this->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
             $snowGolem->spawnToAll();
         } elseif ($firstBlock->getId() === Item::IRON_BLOCK && $secondBlock->getId() === Item::IRON_BLOCK) {
             if ($thirdBlock->getId() === Item::IRON_BLOCK && $fourthBlock->getId() === Item::IRON_BLOCK && $fifthBlock->getId() === Item::AIR && $sixthBlock->getId() === Item::AIR) {
                 $this->getLevel()->setBlock($thirdBlock, new Air());
                 $this->getLevel()->setBlock($fourthBlock, new Air());
             } elseif ($fifthBlock->getId() === Item::IRON_BLOCK && $sixthBlock->getId() === Item::IRON_BLOCK && $thirdBlock->getId() === Item::AIR && $fourthBlock->getId() === Item::AIR) {
                 $this->getLevel()->setBlock($fifthBlock, new Air());
                 $this->getLevel()->setBlock($sixthBlock, new Air());
             } else {
                 return true;
             }
             $this->getLevel()->setBlock($block, new Air());
             $this->getLevel()->setBlock($firstBlock, new Air());
             $this->getLevel()->setBlock($secondBlock, new Air());
             $ironGolem = new IronGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x), new Double("", $this->y), new Double("", $this->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
             $ironGolem->spawnToAll();
         }
     }
     return true;
 }
Пример #27
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $targetBlock = Block::get($this->meta);
     if ($targetBlock instanceof Air) {
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             $result->setDamage($target->getId());
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem(), $player);
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($targetBlock instanceof Liquid) {
         $result = clone $this;
         $result->setDamage(0);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             $player->getLevel()->setBlock($block, $targetBlock, true, true);
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem(), $player);
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Пример #28
-1
 public function loadInventory(Player $player, Inventory $inv)
 {
     $n = trim(strtolower($player->getName()));
     if ($n === "") {
         return false;
     }
     $d = substr($n, 0, 1);
     $path = $this->getDataFolder() . $d . "/" . $n . ".yml";
     if (!is_file($path)) {
         return false;
     }
     $cfg = new Config($path, Config::YAML);
     $yaml = $cfg->getAll();
     if ($this->isGlobal) {
         $ln = "*";
     } else {
         $ln = trim(strtolower($player->getLevel()->getName()));
     }
     if (!isset($yaml[$ln])) {
         return false;
     }
     $inv->clearAll();
     foreach ($yaml[$ln] as $slot => $t) {
         list($id, $dam, $cnt) = explode(":", $t);
         $item = Item::get($id, $dam, $cnt);
         $inv->setItem($slot, $item);
     }
     return true;
 }
Пример #29
-2
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($player instanceof Player) {
         $this->meta = ((int) $player->getDirection() + 5) % 4;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     if ($player != null) {
         $level = $this->getLevel();
         if ($player->getServer()->allowSnowGolem) {
             $block0 = $level->getBlock($block->add(0, -1, 0));
             $block1 = $level->getBlock($block->add(0, -2, 0));
             if ($block0->getId() == Item::SNOW_BLOCK and $block1->getId() == Item::SNOW_BLOCK) {
                 $level->setBlock($block, new Air());
                 $level->setBlock($block0, new Air());
                 $level->setBlock($block1, new Air());
                 $golem = new SnowGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
                 $golem->spawnToAll();
             }
         }
         if ($player->getServer()->allowIronGolem) {
             $block0 = $level->getBlock($block->add(0, -1, 0));
             $block1 = $level->getBlock($block->add(0, -2, 0));
             $block2 = $level->getBlock($block->add(-1, -1, 0));
             $block3 = $level->getBlock($block->add(1, -1, 0));
             $block4 = $level->getBlock($block->add(0, -1, -1));
             $block5 = $level->getBlock($block->add(0, -1, 1));
             if ($block0->getId() == Item::IRON_BLOCK and $block1->getId() == Item::IRON_BLOCK) {
                 if ($block2->getId() == Item::IRON_BLOCK and $block3->getId() == Item::IRON_BLOCK and $block4->getId() == Item::AIR and $block5->getId() == Item::AIR) {
                     $level->setBlock($block2, new Air());
                     $level->setBlock($block3, new Air());
                 } elseif ($block4->getId() == Item::IRON_BLOCK and $block5->getId() == Item::IRON_BLOCK and $block2->getId() == Item::AIR and $block3->getId() == Item::AIR) {
                     $level->setBlock($block4, new Air());
                     $level->setBlock($block5, new Air());
                 } else {
                     return;
                 }
                 $level->setBlock($block, new Air());
                 $level->setBlock($block0, new Air());
                 $level->setBlock($block1, new Air());
                 $golem = new IronGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
                 $golem->spawnToAll();
             }
         }
     }
     return true;
 }
Пример #30
-2
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if(!$block instanceof RailBlock || !$block instanceof Rail) return false; in previuos version IM
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return; in previuos version Genisys
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", array("Pos" => new ListTag("Pos", array(new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 1), new DoubleTag("", $block->getZ()))), "Motion" => new ListTag("Motion", array(new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0))), "Rotation" => new ListTag("Rotation", array(new FloatTag("", 0), new FloatTag("", 0))))));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }