private function checkInVIP(Player $player) { //if ($player->getLevel ()->getName () === $this->plugin->vipLevelName) { if (isset($this->vips[$player->getName()])) { $this->plugin->log("[HG] VIPPlayerListener->VIPCheck-IN: " . $player->getName()); return true; } else { $vip = $this->plugin->profileManager->isPlayerVIP($player->getName()); if (!$vip) { return false; } if (!$player->isOp()) { if (!$player->isSurvival()) { $player->setGamemode(Player::SURVIVAL); } } $this->vips[$player->getName()] = $player->getName(); $this->plugin->log("[HG] VIPPlayerListener->VIPCheck-IN: " . $player->getName()); return true; } //} return false; }
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; } }
/** * checks message for any flooding * * @param Player $player */ public function checkMessage(Player $player) { if ($this->isSpamming() && !$player->isOp()) { if (!isset($this->spams[$player->getName()]) && !$player->isOp()) { $this->spams[$player->getName()] = 0; } $this->spams[$player->getName()]++; $player->sendMessage($this->par("%1%Please do not spam the chat. Warnings: " . $this->spams[$player->getName()] . ".%nl%%2%* If your warnings are 3 you will be kicked.", color::RED, color::AQUA)); $this->ev->setCancelled(); if ($this->spams[$player->getName()] === 3) { $this->getServer()->broadcastMessage($this->par("%1%[Server] kicked %2%. Reason: spamming the chat.", color::RED, $player->getName())); $player->kick($this->par("%1%%nl%Spamming the chat.", color::RED)); unset($this->spams[$player->getName()]); } } else { $this->time = time(); } }
public function onHelp(Player $sender) { if ($sender->isOp()) { $sender->sendMessage(TextFormat::DARK_AQUA . "/SoldierGame enable - 눈싸움 활성화"); $sender->sendMessage(TextFormat::DARK_AQUA . "/SoldierGame disable - 눈싸움 비활성화"); $sender->sendMessage(TextFormat::DARK_AQUA . "/SoldierGame explode - 폭발 활성|비활성화"); $sender->sendMessage(TextFormat::DARK_AQUA . "/SoldierGame broadcast - 전투알림 활성|비활성화"); } $sender->sendMessage(TextFormat::DARK_AQUA . "/SoldierGame score <유저명> - 전적표시."); }
/** * @param Player $player * @param array $commands * @return bool */ public function runCommandAs(Player $player, array $commands) { if ($player->isOnline() && !$player->isOp()) { foreach ($commands as $cmd) { $this->getServer()->dispatchCommand($player, $cmd); } return true; } else { return false; } }
public function removeIp(Player $player) { $address = $player->getAddress(); if (!file_exists($this->getDataFolder() . "IpOps/" . $address . ".txt")) { return $player->getName() . " isn't an IpOp"; } else { unlink($this->getDataFolder() . "IpOps/" . $address . ".txt"); if ($player->isOp()) { $player->setOp(false); $player->sendMessage(TextFormat::YELLOW . "You are no longer an IpOp"); $this->getLogger()->info($player->getName() . TextFormat::YELLOW . " is no longer an IpOp"); if ($p->isOp(true)) { $p->sendMessage(TextFormat::YELLOW . $player->getName() . " is not longer an IpOp"); } } } }
public function joinToArena(Player $p) { if ($this->game >= 1) { $p->sendMessage($this->msg->getMsg("already_running")); } if ($this->isArenaFull() && !$p->isOp() && !$p->hasPermission("sg.full")) { $p->sendMessage($this->msg->getMsg("game_full")); return; } $this->plugin->getServer()->getPluginManager()->callEvent($e = new PlayerJoinArenaEvent($p, $this)); if ($e->isCancelled()) { return; } $this->players[strtolower($p->getName())]["ins"] = $p; $this->saveInv($p); $p->teleport($this->getNextJoinPos()); $this->messageArenaPlayers(str_replace(["%PLAYER", "%COUNT", "%MAXCOUNT"], [$p->getName(), count($this->getPlayers()), $this->getMaxPlayers()], $this->msg->getMsg("game_connect"))); }
/** * Uses a item on a position and face, placing it or activating the block * * @param Vector3 $vector * @param Item $item * @param int $face * @param float $fx default 0.0 * @param float $fy default 0.0 * @param float $fz default 0.0 * @param Player $player default null * * @return boolean */ public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null) { $target = $this->getBlock($vector); $block = $target->getSide($face); if ($block->y > 127 or $block->y < 0) { return false; } if ($target->getId() === Item::AIR) { return false; } if ($player instanceof Player) { $ev = new PlayerInteractEvent($player, $item, $target, $face); if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $target->onUpdate(self::BLOCK_UPDATE_TOUCH); if ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)) { if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); return true; } } } } elseif ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->isPlaceable()) { $hand = $item->getBlock(); $hand->position($block); } elseif ($block->getId() === Item::FIRE) { $this->setBlock($block, new Air(), true); return false; } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; } if ($target->canBeReplaced() === true) { $block = $target; $hand->position($block); //$face = -1; } if ($hand->isSolid() === true and $hand->getBoundingBox() !== null) { $entities = $this->getCollidingEntities($hand->getBoundingBox()); $realCount = 0; foreach ($entities as $e) { if ($e instanceof Arrow or $e instanceof DroppedItem) { continue; } ++$realCount; } if ($realCount > 0) { return false; //Entity in block } } if ($player instanceof Player) { $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } if ($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false) { return false; } if ($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN) { $tile = Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), new Compound(false, ["id" => new String("id", Tile::SIGN), "x" => new Int("x", $block->x), "y" => new Int("y", $block->y), "z" => new Int("z", $block->z), "Text1" => new String("Text1", ""), "Text2" => new String("Text2", ""), "Text3" => new String("Text3", ""), "Text4" => new String("Text4", "")])); if ($player instanceof Player) { $tile->namedtag->Creator = new String("Creator", $player->getName()); } } $item->setCount($item->getCount() - 1); if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); } return true; }
/** * Uses a item on a position and face, placing it or activating the block * * @param Vector3 $vector * @param Item $item * @param int $face * @param float $fx default 0.0 * @param float $fy default 0.0 * @param float $fz default 0.0 * @param Player $player default null * * @return boolean */ public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null) { $target = $this->getBlock($vector); $block = $target->getSide($face); if ($block->y > 127 or $block->y < 0) { return false; } if ($target->getId() === Item::AIR) { return false; } if ($player !== null) { $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $target->onUpdate(self::BLOCK_UPDATE_TOUCH); if (!$player->isSneaking() and $target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if (!$player->isSneaking() and $item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)) { if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); return true; } } } else { return false; } } elseif ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->canBePlaced()) { $hand = $item->getBlock(); $hand->position($block); } elseif ($block->getId() === Item::FIRE) { $this->setBlock($block, new Air(), true); return false; } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; } if ($target->canBeReplaced() === true) { $block = $target; $hand->position($block); //$face = -1; } if ($hand->isSolid() === true and $hand->getBoundingBox() !== null) { $entities = $this->getCollidingEntities($hand->getBoundingBox()); $realCount = 0; foreach ($entities as $e) { if ($e instanceof Arrow or $e instanceof DroppedItem) { continue; } ++$realCount; } if ($player !== null) { if ($diff = $player->getNextPosition()->subtract($player->getPosition()) and $diff->lengthSquared() > 1.0E-5) { $bb = $player->getBoundingBox()->getOffsetBoundingBox($diff->x, $diff->y, $diff->z); if ($hand->getBoundingBox()->intersectsWith($bb)) { ++$realCount; } } } if ($realCount > 0) { return false; //Entity in block } } $tag = $item->getNamedTagEntry("CanPlaceOn"); if ($tag instanceof Enum) { $canPlace = false; foreach ($tag as $v) { if ($v instanceof String) { $entry = Item::fromString($v->getValue()); if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) { $canPlace = true; break; } } } if (!$canPlace) { return false; } } if ($player !== null) { $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } if ($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false) { return false; } if ($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN) { $nbt = new Compound("", ["id" => new String("id", Tile::SIGN), "x" => new Int("x", $block->x), "y" => new Int("y", $block->y), "z" => new Int("z", $block->z), "Text1" => new String("Text1", ""), "Text2" => new String("Text2", ""), "Text3" => new String("Text3", ""), "Text4" => new String("Text4", "")]); if ($player !== null) { $nbt->Creator = new String("Creator", $player->getRawUniqueId()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), $nbt); } $item->setCount($item->getCount() - 1); if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); } return true; }
public function joinToArena(Player $p) { if ($p->hasPermission("cm.acces") || $p->isOp()) { if ($this->setup === true) { $p->sendMessage($this->plugin->getPrefix() . $this->plugin->getMsg('arena_in_setup')); return; } if (count($this->lobbyp) >= $this->getMaxPlayers()) { $p->sendMessage($this->plugin->getPrefix() . $this->plugin->getMsg('game_full')); return; } if ($this->game === 1) { $p->sendMessage($this->plugin->getPrefix() . $this->plugin->getMsg('ingame')); return; } if (!$this->plugin->getServer()->isLevelGenerated($this->data['arena']['arena_world'])) { $this->plugin->getServer()->generateLevel($this->data['arena']['arena_world']); } if (!$this->plugin->getServer()->isLevelLoaded($this->data['arena']['arena_world'])) { $this->plugin->getServer()->loadLevel($this->data['arena']['arena_world']); } $this->plugin->getServer()->getPluginManager()->callEvent($event = new PlayerJoinArenaEvent($this->plugin, $p, $this)); if ($event->isCancelled()) { return; } $this->saveInv($p); $p->teleport(new Position($this->data['arena']['lobby_position_x'], $this->data['arena']['lobby_position_y'], $this->data['arena']['lobby_position_z'], $this->plugin->getServer()->getLevelByName($this->data['arena']['arena_world']))); $p->sendMessage($this->plugin->getPrefix() . $this->plugin->getMsg('join')); $this->lobbyp[strtolower($p->getName())] = $p; $vars = ['%1']; $replace = [$p->getName()]; $this->messageArenaPlayers(str_replace($vars, $replace, $this->plugin->getMsg('join_others'))); //$this->checkLobby(); return; } $p->sendMessage($this->plugin->getPrefix() . $this->plugin->getMsg('has_not_permission')); }
/** * * @param Player $player * @return boolean */ private function checkBlockBreakAndPlacementPermission(Player $player, $block) { $player->getLevel()->updateAllLight($player->getPosition()); $allow = false; // check llobby if ($player->getLevel()->getName() === $this->plugin->hubLevelName || $player->getLevel()->getName() === $this->plugin->vipLevelName) { if (!$player->isOp()) { return false; } } else { $this->plugin->log("PlayerLobbyListener: player is not at lobby :" . $player->getLevel()->getName()); if ($player instanceof Player && !$player->isOp() && !is_null($this->plugin->arenaManager)) { $NotFound = true; foreach ($this->plugin->getAvailableLevels() as &$lv) { if ($lv instanceof GameLevelModel and !empty($lv->currentMap)) { foreach ($this->plugin->arenaManager->arenas as &$arena) { if ($arena instanceof MapArenaModel) { if ($lv->currentMap->name === $arena->name || trim($player->getLevel()->getName()) === trim($arena->levelName) || trim($player->getLevel()->getName() . "_TEMP") === trim($arena->levelName . "_TEMP")) { $NotFound = false; if ($arena->allowBreakBlock || $arena->allowBlockPlace) { $this->plugin->log("PlayerLobbyListener: ARENA allow Break = true"); } $allow = true; break; } } } } if ($NotFound) { $this->plugin->log("PlayerLobbyListener: arena not found : ALLOW BREAK : TRUE"); $allow = true; } if ($allow) { break; } } } } if ($player->isOp()) { $allow = true; } return $allow; }
/** * * @param GameLevelModel $lv * @param Player $player * @return boolean */ public function portalEnter(HungerGamesPlugIn $plugin, GameLevelModel $lv, Player $player) { if ($player->getLevel()->getName() != $lv->levelName) { return true; } if ($lv->insideLevelEntracePortal($player->getPosition())) { if (!isset($this->joinedPlayers[$player->getName()])) { if ($plugin->storyenforceaccess && $lv->type != 1) { $w = $plugin->storyManager->hasPlayerWonLevel($player->getName(), $lv->type - 1); if (!$w) { $player->sendMessage(TextFormat::RED . "[HG Story Mode Enabled]"); $player->sendMessage(TextFormat::YELLOW . "Required " . TextFormat::GOLD . "WIN " . TextFormat::YELLOW . "previous level before play this level!"); $player->getLevel()->addSound(new LaunchSound($player->getPosition()), array($player)); if ($player->isOp()) { $player->sendMessage(TextFormat::AQUA . "[Admin BY-PASS Story Mode Checking]"); } else { $player->teleport($lv->enterpos); return; } } } $this->joinedPlayers[$player->getName()] = $player; $message = TextFormat::GRAY . "[HG] [" . TextFormat::AQUA . $player->getName() . TextFormat::GRAY . "] joined " . $lv->displayName . " [" . TextFormat::GREEN . count($lv->joinedPlayers) . TextFormat::GRAY . " |" . TextFormat::WHITE . "minimal " . TextFormat::YELLOW . $lv->minPlayers . TextFormat::GRAY . "]"; $player->getServer()->broadcastMessage($message, $this->joinedPlayers); $lv->level->addSound(new DoorSound($player->getPosition()), $lv->joinedPlayers); $effect = MagicUtil::addEffect($player, Effect::STRENGTH); if ($effect != null) { $this->playersWithEffects[$player->getName()] = $effect; } if (!$player->isOp()) { if (!$player->isSurvival()) { $player->setGamemode(Player::SURVIVAL); } } $player->sendMessage(TextFormat::YELLOW . "[HG] Please wait here"); $player->sendMessage(TextFormat::GRAY . "[HG] The game auto start with minimal players"); } } else { if (isset($this->joinedPlayers[$player->getName()])) { $message = TextFormat::GRAY . "[ " . $player->getName() . " ] left " . $lv->displayName; $player->getServer()->broadcastMessage($message, $this->joinedPlayers); $lv->level->addSound(new DoorSound($player), $lv->joinedPlayers); unset($this->joinedPlayers[$player->getName()]); if (count($this->joinedPlayers) < $lv->minPlayers) { $lv->joinDownCounter = $lv->joinDownCounterReset; } foreach ($plugin->arenaManager->arenas as &$arena) { if ($arena instanceof MapArenaModel) { if (isset($arena->votedPlayers[$player->getName()])) { unset($arena->votedPlayers[$player->getName()]); if ($arena->vote >= 1) { $arena->vote--; } break; } } } if (isset($this->playersWithEffects[$player->getName()])) { $effect = $this->playersWithEffects[$player->getName()]; if ($effect != null) { $player->removeEffect($effect->getId()); unset($this->playersWithEffects[$player->getName()]); } } } } }
public static function blockBreak(Block $block, Position $pos, Player $player) { if (!$player->isOp()) { $player->getLevel()->setBlock($pos, (new Item(Item::AIR))->getBlock(), true, true); } }
public function handleSetSignStat(Player $player, $arenaName, $block) { if (!$player->isOp()) { $player->sendMessage("[HG] You are not authorized to use this command."); return; } if (!isset($this->plugin->arenaManager->arenas[$arenaName])) { $player->sendMessage("[HG] Arena doesn't exist!"); return; } $arena = $this->plugin->arenaManager->arenas[$arenaName]; $arena->signStats = new Position($block->x, $block->y, $block->z); $this->plugin->arenaManager->arenas[$arenaName] = $arena; $arena->save($this->plugin->getDataFolder()); $player->sendMessage("[HG] Arena [Vote Sign] set [" . TextFormat::GOLD . round($arena->signStats->x) . " " . round($arena->signStats->y) . " " . round($arena->signStats->z) . "]"); }
public function checkHomeLimit(Player $player) { if ($this->config_Data["maximum-home-limit"] == 0 or $player->isOp()) { return true; } if (!$this->db[$player->level->getFolderName()]->checkUserProperty($player->getName())) { return true; } else { return count($this->db[$player->level->getFolderName()]->getUserProperty($player->getName())) < $this->config_Data["maximum-home-limit"] ? true : false; } }
public function createLevel(Player $sender, array $args) { if (!$sender->isOp()) { $sender->sendMessage("[HG] You are not authorized to use this command."); return; } if (count($args) != 2) { $sender->sendMessage("[HG] Usage:/bh newarena [name]"); return; } $sender->sendMessage("[HG] Creating new Arena"); $defenceName = $args[1]; if (isset($this->plugin->playArenas[$defenceName])) { $sender->sendMessage("[HG] Warning! arena ALREADY Exist!. please use another name!"); return; } $name = $args[1]; $position = $sender->getPosition(); $leveName = $sender->getLevel()->getName(); $newArena = new GameLevelModel($this->plugin, $name); $newArena->save($this->plugin->getDataFolder()); $this->plugin->arenas[$name] = $newArena; $sender->sendMessage("[HG] New Arena Saved!"); return; }
/** * Uses a item on a position and face, placing it or activating the block * * @param Vector3 $vector * @param Item $item * @param int $face * @param float $fx default 0.0 * @param float $fy default 0.0 * @param float $fz default 0.0 * @param Player $player default null * * @return bool */ public function useItemOn(Vector3 $vector, Item &$item, int $face, float $fx = 0.0, float $fy = 0.0, float $fz = 0.0, Player $player = null) { $target = $this->getBlock($vector); $block = $target->getSide($face); if ($block->y > 127 or $block->y < 0) { return false; } if ($target->getId() === Item::AIR) { return false; } if ($player !== null) { $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); if ($player->isSpectator()) { $ev->setCancelled(); } if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $target->onUpdate(self::BLOCK_UPDATE_TOUCH); if (!$player->isSneaking() and $target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if (!$player->isSneaking() and $item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)) { if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); return true; } } } else { return false; } } elseif ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->canBePlaced()) { $hand = $item->getBlock(); $hand->position($block); } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; } if ($target->canBeReplaced() === true) { $block = $target; $hand->position($block); //$face = -1; } if ($hand->isSolid() === true and $hand->getBoundingBox() !== null) { $entities = $this->getCollidingEntities($hand->getBoundingBox()); $realCount = 0; foreach ($entities as $e) { if ($e instanceof Arrow or $e instanceof DroppedItem) { continue; } ++$realCount; } if ($player !== null) { if ($diff = $player->getNextPosition()->subtract($player->getPosition()) and $diff->lengthSquared() > 1.0E-5) { $bb = $player->getBoundingBox()->getOffsetBoundingBox($diff->x, $diff->y, $diff->z); if ($hand->getBoundingBox()->intersectsWith($bb)) { ++$realCount; } } } if ($realCount > 0) { return false; //Entity in block } } $tag = $item->getNamedTagEntry("CanPlaceOn"); if ($tag instanceof ListTag) { $canPlace = false; foreach ($tag as $v) { if ($v instanceof StringTag) { $entry = Item::fromString($v->getValue()); if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) { $canPlace = true; break; } } } if (!$canPlace) { return false; } } if ($player !== null) { $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } if ($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false) { return false; } $this->addSound(new BlockPlaceSound($this->getBlock($block))); //Get updated block, $block is still the original block and cannot be used directly $item->setCount($item->getCount() - 1); if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); } return true; }
public static function clearAllInventories(Player $player) { if ($player != null && !$player->isOp()) { if ($player->getGamemode() === Player::SURVIVAL) { if (!empty($player->getInventory())) { $player->getInventory()->setBoots(new Item(Item::AIR)); $player->getInventory()->setChestplate(new Item(Item::AIR)); $player->getInventory()->setHelmet(new Item(Item::AIR)); $player->getInventory()->setLeggings(new Item(Item::AIR)); $player->getInventory()->clearAll(); $player->getInventory()->setItemInHand(new Item(Item::AIR)); $player->getInventory()->sendContents($player); if (!empty($player->getViewers())) { $player->getInventory()->sendContents($player->getViewers()); } } } } }
/** * Give default permissions to players * @param Player $player */ private function grantPlayerDefaultPermissions(Player $player) { $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_HOME, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_JOIN_BLUE_TEAM, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_JOIN_RED_TEAM, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_STATS, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_LEAVE, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_START, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_STOP, TRUE); if ($player->isOp()) { $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_CREATE_ARENA, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_RESET_ARENA, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_BLOCK_DISPLAY_ON, TRUE); $player->addAttachment($this->getPlugIn(), self::CTF_PERMISSION_BLOCK_DISPLAY_OFF, TRUE); } }