UHC/src/Ad5001/UHC/UHCWorld.php

111 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2016-06-10 05:19:40 +00:00
<?php
# _ _ _ _ _____
# | | | | | | |/ ____|
# | | | | |__| | |
# | | | | __ | |
# | |__| | | | | |____
# \____/|_| |_|\_____|
2016-06-10 20:49:35 +00:00
# The most customisable UHC plugin for Minecraft PE!
2016-06-10 05:19:40 +00:00
namespace Ad5001\UHC ;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\event\Listener;
use pocketmine\Server;
use pocketmine\level\Level;
use pocketmine\plugin\Plugin;
use pocketmine\level\particle\FloatingTextParticle;
use pocketmine\Player;
use pocketmine\utils\TextFormat as C;
2016-08-20 16:24:35 +00:00
use pocketmine\math\Vector3;
2016-06-10 05:19:40 +00:00
use Ad5001\UHC\Main;
2016-08-20 05:15:03 +00:00
use Ad5001\UHC\scenario\ScenarioManager;
2016-08-21 13:48:29 +00:00
class UHCWorld implements Listener {
2016-08-20 05:15:03 +00:00
public function __construct(Plugin $main, Level $level, int $maxplayers, int $radius) {
2016-06-10 05:19:40 +00:00
$this->p = $main;
$this->lvl = $level;
$this->maxplayers = $maxplayers;
$this->players = [];
$this->cfg = $main->getConfig();
$this->radius = $radius;
2016-08-21 13:48:29 +00:00
$main->getServer()->getPluginManager()->registerEvents($this, $main);
2016-08-20 05:15:03 +00:00
$this->scenarioManager = new ScenarioManager($this->p, $this);
2016-06-10 05:19:40 +00:00
}
2016-08-20 05:15:03 +00:00
2016-06-10 05:19:40 +00:00
public function getLevel() {
2016-06-10 14:00:18 +00:00
return $this->lvl;
2016-06-10 05:19:40 +00:00
}
public function isStarted() {
return isset($this->p->UHCManager->getStartedUHCs()[$this->lvl->getName()]);
}
2016-08-21 13:48:29 +00:00
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
if(!$this->isStarted()) {
$event->setCancelled();
}
}
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {
if(!$this->isStarted()) {
if(!$event->getPlayer()->isCreative()) {
$event->setCancelled();
}
}
}
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
if(!$this->isStarted()) {
if(!$event->getPlayer()->isCreative()) {
$event->setCancelled();
}
}
}
2016-08-20 05:15:03 +00:00
2016-06-10 05:19:40 +00:00
public function getPlayers() {
return $this->players;
}
2016-08-20 05:15:03 +00:00
public function getName() {
2016-08-20 12:44:28 +00:00
return $this->lvl->getName();
}
2016-06-10 05:19:40 +00:00
public function getMaxPlayers() {
return $this->maxplayers;
}
2016-08-20 05:15:03 +00:00
2016-06-10 05:19:40 +00:00
public function setPlayers(array $players) {
2016-08-21 13:48:29 +00:00
foreach($this->players as $key => $player) {
2016-06-10 05:19:40 +00:00
if(!in_array($player, $this->players)){
2016-08-21 13:48:29 +00:00
$player->sendMessage(Main::PREFIX . C::YELLOW . "You joined the game.");
2016-06-10 05:19:40 +00:00
foreach($this->players as $pl) {
2016-08-21 13:48:29 +00:00
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} joined the game.");
$this->getLevel()->addParticle($part = new FloatingTextParticle(new Vector3($this->getLevel()->getSafeSpawn()->x, $this->getLevel()->getSafeSpawn()->y, $this->getLevel()->getSafeSpawn()->z), C::GREEN . "Welcome to the UHC game, {$player->getName()}!\n" . C::GREEN . "Need help? Use /uhc howtoplay.", C::YELLOW . "-=<UHC>=-"), [$player]);
2016-06-10 05:19:40 +00:00
}
2016-08-21 13:48:29 +00:00
2016-06-10 05:19:40 +00:00
}
}
2016-08-21 13:48:29 +00:00
foreach($players as $player) {
2016-06-10 05:19:40 +00:00
if(!in_array($player, $players)){
2016-08-21 13:48:29 +00:00
$player->sendMessage(Main::PREFIX . C::YELLOW . "You left the game.");
2016-06-10 05:19:40 +00:00
foreach($this->players as $pl) {
2016-08-21 13:48:29 +00:00
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} left the game.");
2016-06-10 05:19:40 +00:00
}
}
}
$this->players = $players;
return true;
}
2016-06-10 20:49:35 +00:00
}