Correcting a bug + removing unsed comment

This commit is contained in:
Ad5001 2016-07-26 10:33:44 +03:00
parent e2ce2f79ba
commit 411b782412

View file

@ -36,9 +36,7 @@ class Main extends PluginBase implements Listener{
public function test(Player $p, int $id) { public function test(Player $p, int $id) {
// $this->getLogger()->info("Item : " . $id . ". Is spectator : " . $this->isSpectator($p));
if($this->isSpectator($p) and $id == 345) { if($this->isSpectator($p) and $id == 345) {
// if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) {
$founds = []; $founds = [];
foreach($p->getLevel()->getPlayers() as $player) { foreach($p->getLevel()->getPlayers() as $player) {
if(!$this->isSpectator($player)) { if(!$this->isSpectator($player)) {
@ -67,16 +65,13 @@ class Main extends PluginBase implements Listener{
} }
} }
} }
// }
} elseif($this->isSpectator($p) and $id == 355) { } elseif($this->isSpectator($p) and $id == 355) {
// if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) {
$p->getInventory()->clearAll(); $p->getInventory()->clearAll();
$p->setGamemode(2); $p->setGamemode(2);
$p->setGamemode(0); $p->setGamemode(0);
$p->teleport($this->getServer()->getLevelByName($this->getConfig()->get("LobbyWorld"))->getSpawnLocation()); $p->teleport($this->getServer()->getLevelByName($this->getConfig()->get("LobbyWorld"))->getSpawnLocation());
$p->sendTip(str_ireplace("{lobby}", $this->getConfig()->get("LobbyWorld"), str_ireplace("{player}", $p->getName(), $this->getConfig()->get("LobbyMessage")))); $p->sendTip(str_ireplace("{lobby}", $this->getConfig()->get("LobbyWorld"), str_ireplace("{player}", $p->getName(), $this->getConfig()->get("LobbyMessage"))));
$this->teleportTask->remove($p); $this->teleportTask->remove($p);
// }
} elseif($this->isSpectator($p) and $id == Item::FEATHER) { } elseif($this->isSpectator($p) and $id == Item::FEATHER) {
$this->teleportTask->remove($p); $this->teleportTask->remove($p);
$item = Item::get(Item::FEATHER, 0, 1); $item = Item::get(Item::FEATHER, 0, 1);
@ -135,7 +130,6 @@ class Main extends PluginBase implements Listener{
public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event) { public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event) {
// print_r($this->players);
if($event->getNewGamemode() == 3) { // Testing if spectator. if($event->getNewGamemode() == 3) { // Testing if spectator.
$player = $event->getPlayer(); $player = $event->getPlayer();
$this->players[$player->getName()] = []; $this->players[$player->getName()] = [];
@ -146,8 +140,9 @@ class Main extends PluginBase implements Listener{
unset($this->players[$event->getPlayer()->getName()]); unset($this->players[$event->getPlayer()->getName()]);
$event->getPlayer()->setAllowFlight(false); $event->getPlayer()->setAllowFlight(false);
$event->getPlayer()->getInventory()->clearAll(); $event->getPlayer()->getInventory()->clearAll();
// $this->lastPlayer = null; $this->teleportTask->remove($event->getPlayer());
$event->getPlayer()->setDisplayName($event->getPlayer()->getName()); $event->getPlayer()->setDisplayName($event->getPlayer()->getName());
$event->getPlayer()->getInventory()->clearAll();
} elseif($this->lastPlayer == $event->getPlayer()->getName()) { } elseif($this->lastPlayer == $event->getPlayer()->getName()) {
$this->lastPlayer = null; $this->lastPlayer = null;
} }
@ -200,7 +195,6 @@ class setGamemodeTask extends \pocketmine\scheduler\PluginTask {
public function onRun($tick) { public function onRun($tick) {
foreach($this->main->players as $playername => $tped) { foreach($this->main->players as $playername => $tped) {
$player = $this->main->getServer()->getPlayer($playername); $player = $this->main->getServer()->getPlayer($playername);
// $this->main->getLogger()->info($player->getGamemode() . "/" . $player->isSpectator());
if($player->isSpectator()) { if($player->isSpectator()) {
$player->setGamemode(0); $player->setGamemode(0);
$compass = Item::get(345, 0, 1); $compass = Item::get(345, 0, 1);
@ -235,7 +229,6 @@ class teleportTask extends \pocketmine\scheduler\PluginTask {
foreach($this->players as $pname => $tpname) { foreach($this->players as $pname => $tpname) {
$p = $this->main->getServer()->getPlayer($pname); $p = $this->main->getServer()->getPlayer($pname);
$tp = $p->getLevel()->getEntity($tpname); $tp = $p->getLevel()->getEntity($tpname);
// $this->main->getLogger()->info("Processing $pname and $tpname");
if($p instanceof Player) { if($p instanceof Player) {
$tp = $p->getLevel()->getEntity($tpname); $tp = $p->getLevel()->getEntity($tpname);
if($tp instanceof Entity) { if($tp instanceof Entity) {
@ -253,6 +246,7 @@ class teleportTask extends \pocketmine\scheduler\PluginTask {
$item->setNamedTag(NBT::parseJSON('{display:{Name:"§r' . $this->main->getConfig()->get("EscapeViewName") . '"}}')); $item->setNamedTag(NBT::parseJSON('{display:{Name:"§r' . $this->main->getConfig()->get("EscapeViewName") . '"}}'));
$player->getInventory()->addItem($item); $player->getInventory()->addItem($item);
$e = \pocketmine\entity\Effect::getEffectByName("INVISIBILITY"); $e = \pocketmine\entity\Effect::getEffectByName("INVISIBILITY");
$e->setAmbient(true);
$e->setVisible(false); $e->setVisible(false);
$player->addEffect($e); $player->addEffect($e);
} }