Working ! Just need to test scenarios (and a small bug fix to resolve.)

This commit is contained in:
Ad5001 2016-08-20 19:41:20 +03:00
parent 6273371f06
commit 419b3a29ca
3 changed files with 12 additions and 7 deletions

View file

@ -19,7 +19,12 @@ commands:
scenarios: scenarios:
description: Manage UHC scenarios description: Manage UHC scenarios
usage: "/scenarios [add | remove | list] [scenario]" usage: "/scenarios [add | remove | list] [scenario]"
permission: uhc.command.scenarios
permissions: permissions:
uhc.command.main: uhc.command.main:
default: op default: op
uhc.command.scenarios:
default: true
uhc.scenarios.modify:
default: op
... ...

View file

@ -39,13 +39,13 @@ class Main extends PluginBase implements Listener{
public function onLevelChange(EntityLevelChangeEvent $event) { public function onLevelChange(EntityLevelChangeEvent $event) {
foreach($this->UHCManager->getLevels() as $world) { foreach($this->UHCManager->getLevels() as $world) {
if($event->getTarget()->getName() === $world->getName() and !isset($this->games[$world->getName()])) { if($event->getTarget()->getName() === $world->getName() and !isset($this->UHCManager->getStartedUHCs()[$world->getName()])) {
if(count($world->getLevel()->getPlayers()) > $world->maxplayers) { if(count($world->getLevel()->getPlayers()) > $world->maxplayers) {
$event->setCancelled(); $event->setCancelled();
} }
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->games[$world->getName()]) and !isset($this->quit[$event->getEntity()])) { } elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and !isset($this->quit[$event->getEntity()])) {
$event->getPlayer()->setGamemode(3); $event->getPlayer()->setGamemode(3);
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->games[$world->getName()]) and isset($this->quit[$event->getEntity()])) { } elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and isset($this->quit[$event->getEntity()])) {
$quit = explode("/", $this->quit[$event->getEntity()]); $quit = explode("/", $this->quit[$event->getEntity()]);
if($quit[3] === $world->getName()) { if($quit[3] === $world->getName()) {
$event->getPlayer()->teleport(new Vector3($quit[0], $quit[1], $quit[2])); $event->getPlayer()->teleport(new Vector3($quit[0], $quit[1], $quit[2]));
@ -65,7 +65,7 @@ class Main extends PluginBase implements Listener{
$this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStartEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStart"), $this, true); $this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStartEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStart"), $this, true);
$this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStopEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, false); $this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStopEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, false);
$this->UHCManager = new UHCManager($this); $this->UHCManager = new UHCManager($this);
$this->games = []; $this->UHCManager->getStartedUHCs() = [];
$this->quit = []; $this->quit = [];
} }
@ -111,7 +111,7 @@ switch($cmd->getName()){
} }
break; break;
case "scenarios": case "scenarios":
if(isset($args[0]) and $sender instanceof Player) { if(isset($args[0]) and $sender instanceof Player and $sender->hasPermission("uhc.scenarios.modify")) {
if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedGames()[$sender->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedGames()[$sender->getLevel()->getName()])) {
switch($args[0]) { switch($args[0]) {
case "add": case "add":

View file

@ -96,7 +96,7 @@ class UHCGame implements Listener{
public function onPlayerDeath(PlayerDeathEvent $event) { public function onPlayerDeath(PlayerDeathEvent $event) {
if($event->getPlayer()->getLevel()->getName() === $this->world->getName() and !$this->cancelled) { if($event->getPlayer()->getLevel()->getName() === $this->world->getName() and !$this->cancelled) {
foreach($event->getPlayer()->getLevel()->getPlayers() as $p) { foreach($event->getPlayer()->getLevel()->getPlayers() as $p) {
$p->sendMessage(Main::PREFIX . C::YELLOW . $event->getPlayer()->getName() . " died."); $p->sendMessage(Main::PREFIX . C::YELLOW . $event->getPlayer()->getName() . " died. " . (count($this->world->getLevel()->getPlayers) - 2)) . " players left !");
} }
$this->respawn[$event->getPlayer()->getName()] = true; $this->respawn[$event->getPlayer()->getName()] = true;
$pls = []; $pls = [];
@ -138,7 +138,7 @@ class UHCGame implements Listener{
$this->m->getServer()->getPluginManager()->callEvent($event = new GameStopEvent($this, $this->world, $winner)); $this->m->getServer()->getPluginManager()->callEvent($event = new GameStopEvent($this, $this->world, $winner));
if(!$event->isCancelled()) { if(!$event->isCancelled()) {
foreach($this->players as $player) { foreach($this->players as $player) {
$player->sendMessage(Main::PREFIX . C::YELLOW . $winner->getName()); $player->sendMessage(Main::PREFIX . C::YELLOW . $winner->getName() . " won the game ! Teleporting back to lobby...");
$player->teleport($this->m->getServer()->getLevelByName($this->m->getConfig()->get("LobbyWorld"))->getSafeSpawn()); $player->teleport($this->m->getServer()->getLevelByName($this->m->getConfig()->get("LobbyWorld"))->getSafeSpawn());
} }
} }