Ejemplo n.º 1
0
 public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event)
 {
     if ($event->isCancelled()) {
         return;
     }
     $p = $event->getPlayer();
     if (!$p->hasPermission("debe.worldinventory.change")) {
         return;
     }
     $n = strtolower($p->getName());
     $g = $event->getNewGamemode();
     $wn = strtolower($p->getLevel()->getFolderName());
     $this->createInv($p, $wn);
     $wiw = $this->wi[$n]["Worlds"][$wn];
     $g = $event->getNewGamemode();
     if ($g == 1) {
         $inv = $p->getInventory();
         foreach ($inv->getContents() as $i) {
             if ($i->getID() !== 0 and $i->getCount() > 0) {
                 $wiw[] = $i->getID() . ":" . $i->getDamage() . ":" . $i->getCount();
             }
         }
         $inv->clearAll();
     } else {
         $this->gmc[$n] = $wiw;
         $wiw = [];
     }
     $this->wi[$n]["Worlds"][$wn] = $wiw;
     $this->saveYml();
     $p->sendMessage("[WorldInventory] " . ($this->isKorean() ? "인벤토리가 교체되었습니다." : "Inventory is change ") . " : GameModeChange");
 }
Ejemplo n.º 2
0
 /**
  * Sets the gamemode, and if needed, kicks the Player.
  *
  * @param int $gm
  *
  * @return bool
  */
 public function setGamemode($gm)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->gamemode = $gm;
     $this->allowFlight = $this->isCreative();
     if ($this->isSpectator()) {
         $this->despawnFromAll();
     } else {
         $this->spawnToAll();
     }
     $this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
     $spawnPosition = $this->getSpawn();
     $pk = new SetPlayerGameTypePacket();
     $pk->gamemode = $this->gamemode & 0x1;
     $this->dataPacket($pk);
     $this->sendSettings();
     $this->inventory->clearAll();
     //SurvivalInventory Clear
     if ($this->gamemode === Player::SPECTATOR) {
         $pk = new ContainerSetContentPacket();
         $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
         $this->dataPacket($pk);
     } else {
         $pk = new ContainerSetContentPacket();
         $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
         foreach (Item::getCreativeItems() as $item) {
             $pk->slots[] = clone $item;
         }
         $this->dataPacket($pk);
     }
     $this->inventory->sendContents($this);
     $this->inventory->sendContents($this->getViewers());
     $this->inventory->sendHeldItem($this->hasSpawned);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Sets the gamemode, and if needed, kicks the Player.
  *
  * @param int $gm
  *
  * @return bool
  */
 public function setGamemode(int $gm)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     if ($this->server->autoClearInv) {
         $this->inventory->clearAll();
     }
     $this->gamemode = $gm;
     $this->allowFlight = $this->isCreative();
     if ($this->isSpectator()) {
         $this->despawnFromAll();
     } else {
         $this->spawnToAll();
     }
     $this->namedtag->playerGameType = new IntTag("playerGameType", $this->gamemode);
     /*$spawnPosition = $this->getSpawn();
     
     		$pk = new StartGamePacket();
     		$pk->seed = -1;
     		$pk->x = $this->x;
     		$pk->y = $this->y;
     		$pk->z = $this->z;
     		$pk->spawnX = (int)$spawnPosition->x;
     		$pk->spawnY = (int)$spawnPosition->y;
     		$pk->spawnZ = (int)$spawnPosition->z;
     		$pk->generator = 1; //0 old, 1 infinite, 2 flat
     		$pk->gamemode = $this->gamemode & 0x01;
     		$pk->eid = 0;*/
     $pk = new SetPlayerGameTypePacket();
     $pk->gamemode = $this->gamemode & 0x1;
     $this->dataPacket($pk);
     $this->sendSettings();
     if ($this->gamemode === Player::SPECTATOR) {
         $pk = new ContainerSetContentPacket();
         $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
         $this->dataPacket($pk);
     } else {
         $pk = new ContainerSetContentPacket();
         $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
         foreach (Item::getCreativeItems() as $item) {
             $pk->slots[] = clone $item;
         }
         $this->dataPacket($pk);
     }
     $this->inventory->sendContents($this);
     $this->inventory->sendContents($this->getViewers());
     $this->inventory->sendHeldItem($this->hasSpawned);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Sets the gamemode, and if needed, kicks the player
  * TODO: Check if Mojang adds the ability to change gamemode without kicking players
  *
  * @param int $gm
  *
  * @return bool
  */
 public function setGamemode($gm)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     if (($this->gamemode & 0x1) === ($gm & 0x1)) {
         $this->gamemode = $gm;
         $this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n");
     } else {
         $this->gamemode = $gm;
         $this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n");
         $this->inventory->clearAll();
         $this->inventory->sendContents($this->getViewers());
         $this->inventory->sendHeldItem($this->hasSpawned);
     }
     $this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
     $spawnPosition = $this->getSpawn();
     $pk = new StartGamePacket();
     $pk->seed = $this->level->getSeed();
     $pk->x = $this->x;
     $pk->y = $this->y + $this->getEyeHeight();
     $pk->z = $this->z;
     $pk->spawnX = (int) $spawnPosition->x;
     $pk->spawnY = (int) $spawnPosition->y;
     $pk->spawnZ = (int) $spawnPosition->z;
     $pk->generator = 1;
     //0 old, 1 infinite, 2 flat
     $pk->gamemode = $this->gamemode & 0x1;
     $pk->eid = 0;
     //Always use EntityID as zero for the actual player
     $this->dataPacket($pk);
     $this->sendSettings();
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Sets the gamemode, and if needed, kicks the Player.
  *
  * @param int  $gm
  * @param bool $client if the client made this change in their GUI
  *
  * @return bool
  */
 public function setGamemode(int $gm, bool $client = false)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
     if ($ev->isCancelled()) {
         if ($client) {
             //gamemode change by client in the GUI
             $pk = new SetPlayerGameTypePacket();
             $pk->gamemode = $this->gamemode & 0x1;
             $this->dataPacket($pk);
             $this->sendSettings();
         }
         return false;
     }
     $this->gamemode = $gm;
     $this->allowFlight = $this->isCreative();
     if ($this->isSpectator()) {
         $this->flying = true;
         $this->despawnFromAll();
         // Client automatically turns off flight controls when on the ground.
         // A combination of this hack and a new AdventureSettings flag FINALLY
         // fixes spectator flight controls. Thank @robske110 for this hack.
         $this->teleport($this->temporalVector->setComponents($this->x, $this->y + 0.1, $this->z));
     } else {
         if ($this->isSurvival()) {
             $this->flying = false;
         }
         $this->spawnToAll();
     }
     $this->resetFallDistance();
     $this->namedtag->playerGameType = new IntTag("playerGameType", $this->gamemode);
     if (!$client) {
         //Gamemode changed by server, do not send for client changes
         $pk = new SetPlayerGameTypePacket();
         $pk->gamemode = $this->gamemode & 0x1;
         $this->dataPacket($pk);
         $this->sendSettings();
     } else {
         Command::broadcastCommandMessage($this, new TranslationContainer("commands.gamemode.success.self", [Server::getGamemodeString($gm)]));
     }
     $this->inventory->sendContents($this);
     $this->inventory->sendContents($this->getViewers());
     $this->inventory->sendHeldItem($this->hasSpawned);
     if ($this->isCreative()) {
         $this->inventory->sendCreativeContents();
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Sets the gamemode, and if needed, kicks the player
  * TODO: Check if Mojang adds the ability to change gamemode without kicking players
  *
  * @param int $gm
  *
  * @return bool
  */
 public function setGamemode($gm)
 {
     if ($gm < 0 or $gm > 3 or $this->gamemode === $gm) {
         return false;
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     if (($this->gamemode & 0x1) === ($gm & 0x1)) {
         $this->gamemode = $gm;
     } else {
         $this->gamemode = $gm;
         $this->inventory->clearAll();
         $this->inventory->sendContents($this);
         $this->inventory->sendContents($this->getViewers());
         $this->inventory->sendHeldItem($this->hasSpawned);
     }
     $this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
     $spawnPosition = $this->getSpawn();
     $pk = new StartGamePacket();
     $pk->seed = -1;
     $pk->x = $this->x;
     $pk->y = $this->y;
     $pk->z = $this->z;
     $pk->spawnX = (int) $spawnPosition->x;
     $pk->spawnY = (int) $spawnPosition->y;
     $pk->spawnZ = (int) $spawnPosition->z;
     $pk->generator = 1;
     //0 old, 1 infinite, 2 flat
     $pk->gamemode = $this->gamemode & 0x1;
     $pk->eid = $this->getId();
     $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     $this->sendSettings();
     if ($this->gamemode === Player::SPECTATOR) {
         $pk = new ContainerSetContentPacket();
         $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
         $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     } else {
         $pk = new ContainerSetContentPacket();
         $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
         foreach (Item::getCreativeItems() as $item) {
             $pk->slots[] = clone $item;
         }
         $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
     return true;
 }
Ejemplo n.º 7
0
 public function setGamemode(Player $player, $gm)
 {
     if ($gm < 0 or $gm > 3 or $player->gamemode === $gm) {
         return \false;
     }
     $player->getServer()->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($player, (int) $gm));
     if ($ev->isCancelled()) {
         return false;
     }
     if (($player->gamemode & 0x1) === ($gm & 0x1)) {
         $player->gamemode = $gm;
         $player->sendMessage(TextFormat::DARK_AQUA . "게임모드가 변경되었습니다, " . Server::getGamemodeString($player->getGamemode()) . ".\n");
     } else {
         $player->gamemode = $gm;
         $player->sendMessage(TextFormat::DARK_AQUA . "게임모드가 변경되었습니다, " . Server::getGamemodeString($player->getGamemode()) . ".\n");
         $player->getInventory()->clearAll();
         $player->getInventory()->sendContents($player->getViewers());
         $player->getInventory()->sendHeldItem($player->getViewers());
     }
     $player->namedtag->playerGameType = new Int("playerGameType", $player->gamemode);
     $player->sendMessage(TextFormat::DARK_AQUA . "새 게임모드 적용을 위해 서버에서 킥처리됩니다.");
     $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "Kick"], [$player]), 50);
     return true;
 }