Adding spec private chat + Blocks not breaking and placing

This commit is contained in:
Ad5001 2016-07-25 15:37:01 +03:00
parent 9d4e564699
commit f6dd631497
2 changed files with 16 additions and 10 deletions

View file

@ -13,6 +13,8 @@ TPCompassName: Find player
BedBackName: Back to lobby BedBackName: Back to lobby
# Name of the lobby world # Name of the lobby world
LobbyWorld: LobbyWorld: world
# Does the spectators have a private chat (true) or speak to everyone (false)
PrivateSpecChat: true
... ...

View file

@ -21,6 +21,7 @@ class Main extends PluginBase implements Listener{
public function onEnable(){ public function onEnable(){
$this->saveDefaultConfig();
$this->reloadConfig(); $this->reloadConfig();
$this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->getServer()->getScheduler()->scheduleRepeatingTask(new setGamemodeTask($this), 5); $this->getServer()->getScheduler()->scheduleRepeatingTask(new setGamemodeTask($this), 5);
@ -29,11 +30,6 @@ class Main extends PluginBase implements Listener{
} }
public function onLoad(){
$this->saveDefaultConfig();
}
public function test(Player $p, int $id) { public function test(Player $p, int $id) {
$this->getLogger()->info("Item : " . $id . ". Is spectator : " . $this->isSpectator($p)); $this->getLogger()->info("Item : " . $id . ". Is spectator : " . $this->isSpectator($p));
if($this->isSpectator($p) and $id == 345) { if($this->isSpectator($p) and $id == 345) {
@ -65,10 +61,10 @@ class Main extends PluginBase implements Listener{
} }
} }
// } // }
} elseif($this->isSpectator($event->getPlayer()) and $id == 355) { } elseif($this->isSpectator($p) and $id == 355) {
// if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) { // if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) {
$p->getInventory()->clearAll(); $p->getInventory()->clearAll();
$p->teleport($this->getServer()->getLevelByName($this->getConfig()->get("LobbyWorld"))->getDefaultSpawn()); $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"))));
// } // }
} }
@ -80,10 +76,16 @@ class Main extends PluginBase implements Listener{
public function onBlockPlace(BlockPlaceEvent $event) { public function onBlockPlace(BlockPlaceEvent $event) {
$this->test($event->getPlayer(), $event->getBlock()->getId()); $this->test($event->getPlayer(), $event->getBlock()->getId());
if($this->isSpectator($event->getPlayer())) {
$event->setCancelled();
}
} }
public function onBlockBreak(BlockBreakEvent $event) { public function onBlockBreak(BlockBreakEvent $event) {
$this->test($event->getPlayer(), $event->getPlayer()->getInventory()->getItemInHand()->getId()); $this->test($event->getPlayer(), $event->getPlayer()->getInventory()->getItemInHand()->getId());
if($this->isSpectator($event->getPlayer())) {
$event->setCancelled();
}
} }
public function onEntityDamage(EntityDamageEvent $event) { public function onEntityDamage(EntityDamageEvent $event) {
@ -106,7 +108,7 @@ class Main extends PluginBase implements Listener{
if($this->getConfig()->get("PrivateSpecChat") == "true") { if($this->getConfig()->get("PrivateSpecChat") == "true") {
foreach($event->getPlayer()->getLevel()->getPlayers() as $p) { foreach($event->getPlayer()->getLevel()->getPlayers() as $p) {
if($this->isSpectator($p)) { if($this->isSpectator($p)) {
$p->sendMessage $p->sendMessage(\pocketmine\utils\TextFormat::GRAY . "[SPEC] " . $event->getPlayer()->getName() . " > " . $event->getMessage());
} }
} }
$event->setCancelled(); $event->setCancelled();
@ -119,9 +121,11 @@ class Main extends PluginBase implements Listener{
$player = $event->getPlayer(); $player = $event->getPlayer();
$this->players[$player->getName()] = []; $this->players[$player->getName()] = [];
$this->lastPlayer = $player; $this->lastPlayer = $player;
} elseif($this->lastPlayer !== $player and isset($this->players[$event->getPlayer()->getName()])) { } elseif($this->lastPlayer !== $event->getPlayer() and isset($this->players[$event->getPlayer()->getName()])) {
unset($this->players[$event->getPlayer()->getName()]); unset($this->players[$event->getPlayer()->getName()]);
$event->getPlayer()->setAllowFlight(false); $event->getPlayer()->setAllowFlight(false);
$event->getPlayer()->getInventory()->clearAll();
$this->lastPlayer = null;
} }
} }