Inheritance: extends PlayerEvent, implements pocketmine\event\Cancellable
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
 /**
  * @param PlayerGameModeChangeEvent $event
  */
 public function onGameModeChange(PlayerGameModeChangeEvent $event)
 {
     $player = $event->getPlayer();
     $newGamemode = $event->getNewGamemode();
     switch ($newGamemode) {
         case 0:
             $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new GISPluginTask($this->plugin, "loadArmorContents", array($player)), 15);
             $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new GISPluginTask($this->plugin, "loadContents", array($player)), 15);
             break;
         case 1:
             $this->plugin->saveArmorContents($player);
             $this->plugin->saveContents($player);
             break;
         default:
             break;
     }
 }
Ejemplo n.º 3
0
 public function onGmChange(PlayerGameModeChangeEvent $ev)
 {
     $player = $ev->getPlayer();
     $newgm = $ev->getNewGamemode();
     $oldgm = $player->getGamemode();
     if (($newgm == 1 || $newgm == 3) && ($oldgm == 0 || $oldgm == 2)) {
         // We need to save inventory
         $this->saveInv($player);
     }
     if (($newgm == 0 || $newgm == 2) && ($oldgm == 1 || $oldgm == 3)) {
         // Need to restore inventory (but later!)
         $inv = $this->getState($player, null);
         if ($inv == null) {
             return;
         }
         // No inventory on file!
         $this->owner->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this->owner, [$this, "loadInv"], [$player]), self::TICKS);
     }
 }
Ejemplo n.º 4
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.º 5
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.º 6
0
 /**
  *
  * @param PlayerGameModeChangeEvent $event        	
  */
 public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event)
 {
     $this->showGameMode($event->getPlayer());
 }
Ejemplo n.º 7
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.º 8
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;
 }
 /** 
  * @param PlayerGameModeChangeEvent $event 
  * @priority HIGHEST
  * @ignoreCancelled true
  */
 public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event)
 {
     if (!$this->plugin->getStorage()->getShield($event->getPlayer()->getLevel())->isAllowed(Shield::GAMEMODE_CHANGING)) {
         $event->setCancelled(true);
         $event->getPlayer()->sendTip($this->plugin->getConfig()->get("gamemodeChangeNotAllowed"));
     }
 }
Ejemplo n.º 10
0
 public function PlayerGameModeChangeEvent(PlayerGameModeChangeEvent $event)
 {
     $event->getPlayer()->getInventory()->addItem(Item::get(1, 0, 1));
     $event->getPlayer()->getInventory()->clearAll();
 }
Ejemplo n.º 11
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.º 12
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;
 }
Ejemplo n.º 13
0
 public function onGameModeChange(PlayerGameModeChangeEvent $event)
 {
     $playerName = $event->getPlayer()->getName();
     //$chunkX=131;
     //$chunkZ=132;
     foreach ($this->joinedplayers as $key => $value) {
         if ($key == $playerName) {
             $event->getPlayer()->sendMessage("What are you going to do?=_=Be good buys!");
             $event->setCancelled();
             //$rere=new SimpleChunk($chunkX,$chunkZ);
         }
     }
 }
Ejemplo n.º 14
-1
 public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event)
 {
     $Player = $event->getPlayer();
     $Level = $Player->getLevel();
     if (!$this->plugin->game || $this->plugin->game->level_name != $Level->getFolderName()) {
         return;
     }
     $event->setCancelled(!in_array($event->getNewGamemode(), [0, 3]));
 }