Bug fixes ! The games start and stuff seems unbugged.

This commit is contained in:
Ad5001 2016-08-20 18:22:44 +03:00
parent 0aac12eb77
commit 8a940dfe58
5 changed files with 36 additions and 21 deletions

View file

@ -1,7 +1,4 @@
worlds: worlds:
world:
maxplayers: 8
radius: 1000
uhc: uhc:
maxplayers: 8 maxplayers: 8
radius: 1000 radius: 1000

View file

@ -40,13 +40,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->games[$world->getName()])) {
if(count($world->getLevel()->getPlayers) > $world->maxplayers) { if(count($world->getLevel()->getPlayers()) > $world->maxplayers) {
$event->setCancelled(); $event->setCancelled();
} }
} elseif($event->getLevel()->getName() === $world->getName() and isset($this->games[$world->getName()]) and !isset($this->quit[$event->getPlayer()])) { } elseif($event->getTarget()->getName() === $world->getName() and isset($this->games[$world->getName()]) and !isset($this->quit[$event->getEntity()])) {
$event->getPlayer()->setGamemode(3); $event->getPlayer()->setGamemode(3);
} elseif($event->getLevel()->getName() === $world->getName() and isset($this->games[$world->getName()]) and isset($this->quit[$event->getPlayer()])) { } elseif($event->getTarget()->getName() === $world->getName() and isset($this->games[$world->getName()]) and isset($this->quit[$event->getEntity()])) {
$quit = explode("/", $this->quit[$event->getPlayer()]); $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]));
foreach($world->getLevel()->getPlayers() as $player) { foreach($world->getLevel()->getPlayers() as $player) {
@ -210,13 +210,13 @@ return false;
public function onEntityLevelChange(EntityLevelChangeEvent $event) { public function onEntityLevelChange(EntityLevelChangeEvent $event) {
if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) { if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) { foreach($this->UHCManager->getLevels()[$event->getOrigin()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onQuit($event->getPlayer()); $sc->onQuit($event->getPlayer());
} }
} }
if(isset($this->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) { if(isset($this->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) { foreach($this->UHCManager->getLevels()[$event->getTarget()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onJoin($event->getPlayer()); $sc->onJoin($event->getEntity());
} }
} }
} }
@ -313,7 +313,7 @@ return false;
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) { public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) { foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onEntityDamage($event); $sc->onEntityDamage($event);
} }
} }
@ -321,7 +321,8 @@ return false;
public function onProjectileLaunch(\pocketmine\event\entity\ProjectileLaunchEvent $event) { public function onProjectileLaunch(\pocketmine\event\entity\ProjectileLaunchEvent $event) {
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) { if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onProjectileLaunch($event); $sc->onProjectileLaunch($event);
} }
} }
@ -330,7 +331,7 @@ return false;
public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) { public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) {
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) { foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onProjectileHit($event); $sc->onProjectileHit($event);
} }
} }
@ -390,4 +391,10 @@ return false;
} }
} }
} }
public function onGameStart(\Ad5001\UHC\event\GameStartEvent $event) {}
public function onGameStop(\Ad5001\UHC\event\GameStopEvent $event) {}
} }

View file

@ -56,7 +56,7 @@ class UHCGame implements Listener{
$effect->setAmplifier(99); $effect->setAmplifier(99);
$effect->setVisible(false); $effect->setVisible(false);
$player->addEffect($effect); $player->addEffect($effect);
$this->m->getServer()->getScheduler()->scheduleDelayedTask(new StopResTask($this, $this->world), 30*20); $this->m->getServer()->getScheduler()->scheduleDelayedTask(new StopResTask($this->m, $this->world->getPlayers()), 30*20);
$player->sendMessage(Main::PREFIX . C::GREEN . "Game started ! Good luck {$player->getName()} !"); $player->sendMessage(Main::PREFIX . C::GREEN . "Game started ! Good luck {$player->getName()} !");
} }
} }
@ -64,12 +64,18 @@ class UHCGame implements Listener{
public function onHeal(EntityRegainHealthEvent $event) { public function onHeal(EntityRegainHealthEvent $event) {
if($event->getEntity() instanceof Player and $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_SATURATION and $event->getEntity()->getLevel()->getName() === $world->getLevel()->getName()) { // if player is playing if($event->getEntity() instanceof Player and $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_SATURATION and $event->getEntity()->getLevel()->getName() === $this->world->getLevel()->getName()) { // if player is playing
$event->setCancelled(); $event->setCancelled();
} }
} }
public function onGameStart(\Ad5001\UHC\event\GameStartEvent $event) {}
public function onGameStop(\Ad5001\UHC\event\GameStopEvent $event) {}
public function onRespawn(PlayerRespawnEvent $event) { public function onRespawn(PlayerRespawnEvent $event) {
if(isset($this->respawn[$event->getPlayer()->getName()]) and !$this->cancelled) { if(isset($this->respawn[$event->getPlayer()->getName()]) and !$this->cancelled) {
$player->teleport($this->world->getLevel()); $player->teleport($this->world->getLevel());

View file

@ -13,6 +13,9 @@ use pocketmine\Player;
use pocketmine\level\Level; use pocketmine\level\Level;
use Ad5001\UHC\task\StartGameTask;
class UHCManager { class UHCManager {
@ -36,10 +39,12 @@ class UHCManager {
public function startUHC(Level $level) { public function startUHC(Level $level) {
if(isset($this->levels[$level->getName()]) and !isset($this->startedgames[$level->getName()])) { if(isset($this->levels[$level->getName()]) and !isset($this->startedgames[$level->getName()])) {
$ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this, $this->levels[$level->getName()]), 20); $ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this->main, $this->levels[$level->getName()]), 20);
$t->setHandler($ft); $t->setHandler($ft);
$this->startedgames[$level->getName()] = true; $this->startedgames[$level->getName()] = true;
$this->levels[$level->getName()]->onUHCStart(); foreach($this->levels[$level->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onStart();
}
return true; return true;
} }
return false; return false;
@ -50,7 +55,9 @@ class UHCManager {
public function stopUHC(Level $level) { public function stopUHC(Level $level) {
if(isset($this->startedgames[$level->getName()])) { if(isset($this->startedgames[$level->getName()])) {
unset($this->startedgames[$level->getName()]); unset($this->startedgames[$level->getName()]);
$this->levels[$level->getName()]->onUHCStop(); foreach($this->levels[$level->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onQuit();
}
return true; return true;
} }
return false; return false;
@ -61,8 +68,6 @@ class UHCManager {
public function registerLevel(Level $level) { public function registerLevel(Level $level) {
if(!array_key_exists($level->getName(), $this->levels)) { if(!array_key_exists($level->getName(), $this->levels)) {
$this->levels[$level->getName()] = new UHCWorld($this->main,$level,$this->main->getConfig()->get("worlds")[$level->getName()]["maxplayers"],$this->main->getConfig()->get("worlds")[$level->getName()]["radius"]); $this->levels[$level->getName()] = new UHCWorld($this->main,$level,$this->main->getConfig()->get("worlds")[$level->getName()]["maxplayers"],$this->main->getConfig()->get("worlds")[$level->getName()]["radius"]);
} else {
$this->main->getLogger()->warning("{$level->getName()} is already registered.");
} }
} }

View file

@ -22,7 +22,7 @@ use Ad5001\UHC\Main;
class StopResTask extends PluginTask { class StopResTask extends PluginTask {
public function __construct(Plugin $plugin, array $players) { public function __construct(Plugin $plugin, array $players) {
parent::__construct($this); parent::__construct($plugin);
$this->m = $plugin; $this->m = $plugin;
$this->players = $players; $this->players = $players;
} }