Switched to '/' to DIRECTORY_SEPARATOR

Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-11 02:54:27 -04:00
parent 361d090171
commit 7c571e20d4
6 changed files with 89 additions and 75 deletions

View File

@ -10,6 +10,7 @@ namespace mineplex\plugin\gameengine\arenas;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\factory\GameFactory;
use mineplex\plugin\util\UtilArray;
use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\event\player\PlayerJoinEvent;
@ -51,17 +52,20 @@ class MultiGameArena implements Arena, Listener
public function addPlayer(Player $player)
{
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaJoinEvent($this, $player));
array_push($this->players, $player);
if (!UtilArray::hasKey($player->getName(), $this->players))
{
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaJoinEvent($this, $player));
$this->players[$player->getName()] = $player;
}
}
public function removePlayer(Player $player)
{
if (($key = array_search($player, $this->players, true)) !== FALSE) {
unset($this->players[$key]);
if (UtilArray::hasKey($player->getName(), $this->players))
{
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaQuitEvent($this, $player));
unset($this->players[$player->getName()]);
}
Server::getInstance()->broadcastMessage("Calling ArenaQuitEvent");
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaQuitEvent($this, $player));
}
public function onQuit(PlayerQuitEvent $event)
@ -75,6 +79,7 @@ class MultiGameArena implements Arena, Listener
Server::getInstance()->broadcastMessage("Game Over!");
Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this));
$this->startGame();
}
private function startGame()

View File

@ -41,7 +41,7 @@ class LobbyCountdown implements Listener, BenchTask {
const COUNTDOWN_ID = "count";
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $worldComponent = null, $startGameState, $setGameState, $count, $minPlayers = 2)
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent = null, $startGameState, $setGameState, $count, $minPlayers = 2)
{
$this->arena = $arena;
$this->gameStateComponent = $gameStateComponent;
@ -61,11 +61,11 @@ class LobbyCountdown implements Listener, BenchTask {
/**
* @param bool $addOne
* @param int $offset
*/
function checkCountdown($addOne = false)
function checkCountdown($offset = 0)
{
$playerCount = (count($this->arena->getPlayers()) + $addOne);
$playerCount = (count($this->arena->getPlayers()) + $offset);
if ($this->gameStateComponent->getGameState() == $this->startGameState && ($this->worldComponent == null || $this->worldComponent->isWorldReady()) && $playerCount >= $this->minPlayers)
{
@ -76,20 +76,18 @@ class LobbyCountdown implements Listener, BenchTask {
BenchSchedule::runTaskTimerWithId($this, 1000, 1000, self::COUNTDOWN_ID);
}
}
else
else
{
$this->setWaiting($playerCount);
BenchSchedule::cancelTaskWithId($this, self::COUNTDOWN_ID);
}
}
public function onJoin(ArenaJoinEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$this->checkCountdown(true);
$this->checkCountdown(1);
$this->popup($event->getPlayer());
}
@ -98,14 +96,15 @@ class LobbyCountdown implements Listener, BenchTask {
if ($event->getArena() !== $this->arena)
return;
if ($this->gameStateComponent->getGameState() == $this->startGameState)
$this->checkCountdown();
$this->checkCountdown(-1);
}
public function onWorldCreation(WorldLoadSuccessEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$this->checkCountdown();
}
@ -155,7 +154,6 @@ class LobbyCountdown implements Listener, BenchTask {
}
$this->message = "§9Game starting in:§c $this->count";
$this->count--;
}
}

View File

@ -12,8 +12,10 @@ use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\feature\UtilFeature;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\util\UtilTeleport;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityShootBowEvent;
@ -23,6 +25,7 @@ use pocketmine\event\Listener;
use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;
@ -33,7 +36,7 @@ class LobbyComponent implements Listener
private $arena;
/** @var String */
public $worldName;
public $world;
private $duringLobbyGameState;
@ -48,18 +51,41 @@ class LobbyComponent implements Listener
$world->setTime(6000);
$world->stopTime();
$world->setSpawnLocation(new Vector3(0, 103, 0));
$this->worldName = $world->getName();
$this->world = $world;
$this->arena = $arena;
$this->duringLobbyGameState = new DuringLobbyGameState($arena, $world);
$this->duringLobbyGameState = new DuringLobbyGameState($this);
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
function sendToSpawn(Player $player)
{
$player->getInventory()->clearAll();
$player->removeAllEffects();
$player->setGamemode(Player::ADVENTURE);
$player->setHealth($player->getMaxHealth());
$player->resetFallDistance();
$pos = $this->world->getSpawnLocation()->add(rand(-4, 4), 0, rand(-4, 4));
UtilTeleport::teleport($player, new Position($pos->getX(), $pos->getY(), $pos->getZ(), $this->world));
}
public function onBlockBreak(BlockBreakEvent $event)
{
if ($event->getBlock()->getLevel()->getName() != $this->worldName)
if ($event->getBlock()->getLevel() != $this->world)
return;
$event->setCancelled();
}
function onDamage(EntityDamageEvent $event)
{
if (!$event->getEntity()->getLevel() == $this->world)
return;
$event->setCancelled();
}
@ -77,6 +103,11 @@ class LobbyComponent implements Listener
{
if (!$this->duringLobbyGameState->isEnabled())
{
foreach ($this->getArena()->getPlayers() as $player)
{
if ($player->getPosition()->getLevel() !== $this->world)
$this->sendToSpawn($player);
}
$this->duringLobbyGameState->enable();
}
}
@ -89,26 +120,34 @@ class LobbyComponent implements Listener
}
}
/**
* @priority HIGH
* @param ArenaEndEvent $event
*/
public function onGameEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
HandlerList::unregisterAll($this);
if ($this->duringLobbyGameState->isEnabled())
$this->duringLobbyGameState->disable();
}
function getArena()
{
return $this->arena;
}
}
class DuringLobbyGameState extends ListenerFeature
{
private $master;
private $spawn;
public function __construct(Arena $arena, Level $world)
public function __construct(LobbyComponent $master)
{
parent::__construct($arena);
$this->spawn = new Position(0, 103, 0, $world);
parent::__construct($master->getArena());
$this->master = $master;
}
/**
@ -117,9 +156,8 @@ class DuringLobbyGameState extends ListenerFeature
*/
function onDamage(EntityDamageEvent $event)
{
if (!in_array($event->getEntity(), $this->getArena()->getPlayers()))
if (!$this->getArena()->hasPlayer($event->getEntity()))
return;
$event->setCancelled();
}
@ -129,9 +167,8 @@ class DuringLobbyGameState extends ListenerFeature
*/
function onDrop(PlayerDropItemEvent $event)
{
if (!in_array($event->getPlayer(), $this->getArena()->getPlayers()))
if (!$this->getArena()->hasPlayer($event->getPlayer()))
return;
$event->setCancelled();
}
@ -141,9 +178,8 @@ class DuringLobbyGameState extends ListenerFeature
*/
function onPickUp(InventoryPickupItemEvent $event)
{
if (!in_array($event->getInventory()->getHolder(), $this->getArena()->getPlayers()))
if (!$this->getArena()->hasPlayer($event->getInventory()->getHolder()))
return;
$event->setCancelled();
}
@ -153,7 +189,7 @@ class DuringLobbyGameState extends ListenerFeature
*/
function onBowShoot(EntityShootBowEvent $event)
{
if (!in_array($event->getEntity(), $this->getArena()->getPlayers()))
if (!$this->getArena()->hasPlayer($event->getEntity()))
return;
$event->setCancelled();
@ -168,29 +204,6 @@ class DuringLobbyGameState extends ListenerFeature
if ($this->getArena() !== $event->getArena())
return;
$this->sendToSpawn($event->getPlayer());
}
function sendToSpawn(Player $player)
{
$player->getInventory()->clearAll();
$player->removeAllEffects();
$player->setGamemode(Player::ADVENTURE);
$player->setHealth($player->getMaxHealth());
$player->resetFallDistance();
$pos = $this->spawn->add(rand(-4, 4), 0, rand(-4, 4));
$player->teleport($pos);
}
function enable()
{
parent::enable();
foreach ($this->getArena()->getPlayers() as $player)
{
$this->sendToSpawn($player);
}
$this->master->sendToSpawn($event->getPlayer());
}
}

View File

@ -63,6 +63,7 @@ class GameModeSpectateComponent implements SpectateComponent, Listener {
{
if (!$this->isSpectating($player))
return false;
$event = new DisableSpectateEvent($this->arena, $player);
Server::getInstance()->getPluginManager()->callEvent($event);
@ -73,21 +74,22 @@ class GameModeSpectateComponent implements SpectateComponent, Listener {
if (($key = array_search($player, $this->spectators, true)) !== FALSE) {
unset($this->spectators[$key]);
}
return true;
}
//Low to keep consistency, so if someone listens ArenaQuitEvent then the player will be in neither the spectator list or the player list.
//HIGH so you can do isSpectating on ArenaQuitEvent
/**
* @priority LOW
* @priority HIGH
* @param ArenaQuitEvent $event
*/
public function onQuit(ArenaQuitEvent $event)
{
if ($this->arena !== $event->getArena())
return;
if (($key = array_search($event->getPlayer(), $this->spectators, true)) !== FALSE) {
unset($this->spectators[$key]);
if ($this->isSpectating($event->getPlayer()))
{
unset($this->spectators[$event->getPlayer()->getName()]);
}
}
@ -97,7 +99,7 @@ class GameModeSpectateComponent implements SpectateComponent, Listener {
*/
public function isSpectating(Player $player)
{
return in_array($player, $this->getSpectators());
return UtilArray::hasKey($player->getName(), $this->spectators);
}
/**
@ -106,7 +108,7 @@ class GameModeSpectateComponent implements SpectateComponent, Listener {
*/
public function isNotSpectating(Player $player)
{
return in_array($player, $this->arena->getPlayers()) && !$this->isSpectating($player);
return $this->arena->hasPlayer($player) && !$this->isSpectating($player);
}
/**

View File

@ -64,7 +64,6 @@ class LMSVictoryType implements Listener{
HandlerList::unregisterAll($this);
}
}
class DuringGame extends ListenerFeature implements BenchTask {
@ -93,9 +92,7 @@ class DuringGame extends ListenerFeature implements BenchTask {
$this->endPlayersAmount = $endPlayersAmount;
}
#On LOWEST so I can check if the player is spectating, as the player is removed from the spectating list on LOW
/**
* @priority LOWEST
* @param ArenaQuitEvent $event
*/
public function onLeave(ArenaQuitEvent $event)
@ -106,7 +103,7 @@ class DuringGame extends ListenerFeature implements BenchTask {
if (!$this->spectateComponent->isSpectating($event->getPlayer()))
array_push($this->rank, $event->getPlayer());
$this->checkEndGame();
BenchSchedule::runTaskLater($this, 0);
}
@ -117,7 +114,6 @@ class DuringGame extends ListenerFeature implements BenchTask {
array_push($this->rank, $event->getPlayer());
//Meh, don't like doing things this way, but I need it to call sendWinners after the player is added to spectating from spectating.
BenchSchedule::runTaskLater($this, 0);
}
@ -158,9 +154,9 @@ class DuringGame extends ListenerFeature implements BenchTask {
if ($counter >= 3)
break;
}
$this->arena->broadcast("");
$this->arena->broadcast("----------");
}
public function run(BenchTaskData $task)

View File

@ -73,14 +73,14 @@ class WorldComponent implements Listener
$this->arena->getPlugin()->getServer()->unloadLevel($this->world);
UtilFile::deleteDir('worlds/' . $this->worldNameFolder);
UtilFile::deleteDir('worlds' . DIRECTORY_SEPARATOR . $this->worldNameFolder);
print("Successfully Deleted: " . $this->worldNameFolder . "\n");
}
private function loadWorld($gameName)
{
$files = scandir('../update/maps/' . $gameName . '/');
$files = scandir('..' . DIRECTORY_SEPARATOR. '..' . DIRECTORY_SEPARATOR. 'update'. DIRECTORY_SEPARATOR .'maps' . DIRECTORY_SEPARATOR . $gameName . '/');
$maps = array();
@ -103,10 +103,10 @@ class WorldComponent implements Listener
//Unzip World
$zip = new ZipArchive;
$res = $zip->open('../update/maps/' . $gameName . '/' . $worldName . '.zip');
$res = $zip->open('..' . DIRECTORY_SEPARATOR. 'update' . DIRECTORY_SEPARATOR. 'maps' . DIRECTORY_SEPARATOR . $gameName . DIRECTORY_SEPARATOR . $worldName . '.zip');
if ($res === TRUE)
{
$zip->extractTo('worlds/' . $this->worldNameFolder . '/');
$zip->extractTo('worlds' . DIRECTORY_SEPARATOR . $this->worldNameFolder . '/');
$zip->close();
print("Successfully Extracted: " . $this->worldNameFolder . "\n");
}
@ -146,7 +146,7 @@ class WorldComponent implements Listener
public function loadWorldData()
{
$handle = fopen('worlds/' . $this->worldNameFolder . '/WorldConfig.dat', "r");
$handle = fopen('worlds' . DIRECTORY_SEPARATOR . $this->worldNameFolder . DIRECTORY_SEPARATOR. 'WorldConfig.dat', "r");
if ($handle)
{
//These store the array that data should be inserted into