Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Cheese 2015-07-10 17:31:35 +10:00
commit 233d3f0144
18 changed files with 539 additions and 73 deletions

View File

@ -7,9 +7,6 @@
*/ */
$a1 = array(); $array = array();
$a2 = array($a1); array_push($array, $array);
print_r($array);
array_push($a1, $a2);
print_r($a1);

View File

@ -15,6 +15,7 @@ use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerLoginEvent; use pocketmine\event\player\PlayerLoginEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -40,9 +41,10 @@ class Main extends PluginBase implements Listener
$this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0)); $this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0));
} }
public function onLogin(PlayerLoginEvent $event) public function onLogin(PlayerLoginEvent $event)
{ {
UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat'); //UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat');
if ($this->arena->canJoin($event->getPlayer())) if ($this->arena->canJoin($event->getPlayer()))
return; return;

View File

@ -31,6 +31,12 @@ interface Arena
*/ */
public function hasPlayer($player); public function hasPlayer($player);
/**
* @param string $message
* @return void
*/
public function broadcast($message);
/** /**
* @return Plugin * @return Plugin
*/ */

View File

@ -72,6 +72,7 @@ class MultiGameArena implements Arena, Listener
public function endGame() public function endGame()
{ {
Server::getInstance()->broadcastMessage("Game Over!");
Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this)); Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this));
$this->startGame(); $this->startGame();
} }
@ -99,6 +100,14 @@ class MultiGameArena implements Arena, Listener
return in_array($player, $this->getPlayers()); return in_array($player, $this->getPlayers());
} }
public function broadcast($message)
{
foreach ($this->getPlayers() as $player)
{
$player->sendMessage($message);
}
}
public function getCurrentGame() public function getCurrentGame()
{ {
return $this->game; return $this->game;

View File

@ -11,13 +11,15 @@ namespace mineplex\plugin\gameengine\game\components\countdown;
use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent; use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\time\BenchSchedule; use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask; use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData; use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\event\HandlerList; use pocketmine\event\HandlerList;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\Server; use pocketmine\Server;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
class GameStateCountdown implements Listener, BenchTask { class GameStateCountdown implements Listener, BenchTask {
@ -69,17 +71,17 @@ class GameStateCountdown implements Listener, BenchTask {
public function run(BenchTaskData $data) public function run(BenchTaskData $data)
{ {
print "Count: $this->count"."\n"; //print "§$this->startGameState---"."\n";
$this->popup();
if ($this->count <= 0) if ($this->count <= 0)
{ {
$this->gameStateComponent->setGameState($this->setGameState); $this->gameStateComponent->setGameState($this->setGameState);
$data->end(); $data->end();
} }
else
$this->popup(); {
$this->count--; $this->count--;
}
} }

View File

@ -12,22 +12,17 @@ use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent; use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent; use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent; use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\time\BenchSchedule; use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask; use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData; use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\entity\Effect;
use pocketmine\event\HandlerList; use pocketmine\event\HandlerList;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\network\protocol\AnimatePacket;
use pocketmine\network\protocol\ContainerSetDataPacket;
use pocketmine\network\protocol\DropItemPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
class LobbyCountdown implements Listener, BenchTask { class LobbyCountdown implements Listener, BenchTask {
@ -42,13 +37,11 @@ class LobbyCountdown implements Listener, BenchTask {
private $message; private $message;
const WAITING_FOR_PLAYERS = "Waiting for players!";
const POPUP_ID = "popup"; const POPUP_ID = "popup";
const COUNTDOWN_ID = "count"; const COUNTDOWN_ID = "count";
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent, $startGameState, $setGameState, $count, $minPlayers = 2) public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $worldComponent = null, $startGameState, $setGameState, $count, $minPlayers = 2)
{ {
$this->arena = $arena; $this->arena = $arena;
$this->gameStateComponent = $gameStateComponent; $this->gameStateComponent = $gameStateComponent;
@ -61,9 +54,9 @@ class LobbyCountdown implements Listener, BenchTask {
$this->startGameState = $startGameState; $this->startGameState = $startGameState;
$this->setGameState = $setGameState; $this->setGameState = $setGameState;
$this->message = self::WAITING_FOR_PLAYERS;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
$this->checkCountdown();
} }
@ -74,7 +67,7 @@ class LobbyCountdown implements Listener, BenchTask {
{ {
$playerCount = (count($this->arena->getPlayers()) + $addOne); $playerCount = (count($this->arena->getPlayers()) + $addOne);
if ($this->gameStateComponent->getGameState() == $this->startGameState && $this->worldComponent->isWorldReady() && $playerCount >= $this->minPlayers) if ($this->gameStateComponent->getGameState() == $this->startGameState && ($this->worldComponent == null || $this->worldComponent->isWorldReady()) && $playerCount >= $this->minPlayers)
{ {
if (!BenchSchedule::isRunningWithId($this, self::COUNTDOWN_ID)) if (!BenchSchedule::isRunningWithId($this, self::COUNTDOWN_ID))
{ {
@ -104,6 +97,7 @@ class LobbyCountdown implements Listener, BenchTask {
{ {
if ($event->getArena() !== $this->arena) if ($event->getArena() !== $this->arena)
return; return;
if ($this->gameStateComponent->getGameState() == $this->startGameState)
$this->checkCountdown(); $this->checkCountdown();
} }
@ -192,6 +186,6 @@ class LobbyCountdown implements Listener, BenchTask {
private function popup(Player $player) private function popup(Player $player)
{ {
$player->sendTip($this->message); $player->sendPopup($this->message);
} }
} }

View File

@ -8,11 +8,9 @@
namespace mineplex\plugin\gameengine\game\components\feature; namespace mineplex\plugin\gameengine\game\components\feature;
use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\event\HandlerList; use pocketmine\event\HandlerList;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\Server; use pocketmine\Server;
class ListenerFeature implements Feature, Listener { class ListenerFeature implements Feature, Listener {
@ -39,11 +37,11 @@ class ListenerFeature implements Feature, Listener {
} }
/** /**
* @return boolean * @return bool
*/ */
public function isEnabled() public function isEnabled()
{ {
$this->enabled; return $this->enabled;
} }
/** /**

View File

@ -0,0 +1,87 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/9/2015
* Time: 10:07 PM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use pocketmine\entity\Effect;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\Player;
class FreezePlayers extends ListenerFeature {
private $spectateComponent;
function __construct(Arena $arena, SpectateComponent $spectateComponent = null)
{
parent::__construct($arena);
$this->spectateComponent = $spectateComponent;
}
function onMove(PlayerMoveEvent $event)
{
if (!$this->hasPlayer($event->getPlayer()))
return;
if ($event->getFrom()->getFloorX() != $event->getTo()->getFloorX() || $event->getFrom()->getFloorZ() != $event->getTo()->getFloorZ())
$event->setCancelled();
}
public function enable()
{
parent::enable();
$effect = new Effect(Effect::SLOWNESS, "Waiting till game start...", 0, 0, 0, true);
$effect->setVisible(false)->setAmplifier(9)->setDuration(PHP_INT_MAX);
print "Player Count: " . count($this->getPlayers()) . "\n";
foreach ($this->getPlayers() as $player)
{
print "Adding effect! \n";
$player->addEffect($effect);
}
}
public function disable()
{
parent::disable();
print "Player Count: " . count($this->getPlayers()) . "\n";
foreach ($this->getPlayers() as $player)
{
print "Adding effect! \n";
$player->removeEffect(Effect::SLOWNESS);
}
}
/**
* @return Player[]
*/
private function getPlayers()
{
if ($this->spectateComponent !== null)
return $this->spectateComponent->getNonSpectators();
else
return $this->getArena()->getPlayers();
}
/**
* @param Player $player
* @return bool
*/
private function hasPlayer(Player $player)
{
if ($this->spectateComponent !== null)
return $this->spectateComponent->isNotSpectating($player);
else
return $this->getArena()->hasPlayer($player);
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/8/2015
* Time: 12:42 AM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use pocketmine\Server;
class JoinSpectate extends ListenerFeature {
private $spectateComponent;
private $id;
function __construct(Arena $arena, SpectateComponent $spectateComponent)
{
parent::__construct($arena);
$this->spectateComponent = $spectateComponent;
$this->id = rand(0, 99999);
}
function onJoin(ArenaJoinEvent $event)
{
if ($this->getArena() !== $event->getArena())
return;
$this->spectateComponent->enableSpectate($event->getPlayer());
}
public function enable()
{
Server::getInstance()->broadcastMessage("JoinSpectate enable! : $this->id");
parent::enable();
print "JoinSpectate enable? " . ($this->isEnabled() ? 'true' : 'false') . "\n";
}
public function disable()
{
Server::getInstance()->broadcastMessage("JoinSpectate disable!");
parent::disable();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/8/2015
* Time: 12:46 AM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\Server;
class NoDamage extends ListenerFeature {
function __construct(Arena $arena)
{
parent::__construct($arena);
}
function onDamage(EntityDamageEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getEntity()))
return;
//Server::getInstance()->broadcastMessage("Stopped!");
$event->setCancelled();
}
}

View File

@ -40,7 +40,9 @@ class GameStateFeatureManager implements Listener {
foreach ($features as $key => $value) foreach ($features as $key => $value)
{ {
$this->features[$key] = UtilArray::getValuesRecursively($value); $this->features[$key] = UtilArray::getValuesRecursively($value);
print "$key: " . count($this->features[$key]) . "\n";
} }
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
@ -66,20 +68,55 @@ class GameStateFeatureManager implements Listener {
else else
$theseFeatures = []; $theseFeatures = [];
print "\nLast Count: ". count($lastFeatures);
print "\nThese Count: ". count($theseFeatures);
/** @var Feature[] $toEnable */ /** @var Feature[] $toEnable */
$toEnable = UtilArray::arrayDiff($theseFeatures, $lastFeatures); $toEnable = UtilArray::arrayDiff($theseFeatures, $lastFeatures);
print "\nEnable Count: ". count($toEnable);
/** @var Feature[] $toDisable */ /** @var Feature[] $toDisable */
$toDisable = UtilArray::arrayDiff($lastFeatures, $theseFeatures); $toDisable = UtilArray::arrayDiff($lastFeatures, $theseFeatures);
print "\nDisable Count: ". count($toDisable);
print "\n";
foreach ($toDisable as $feature)
{
if (in_array($feature, $theseFeatures))
print "An error has happened!!\n";
else
print "All good ^_^\n";
}
foreach ($toDisable as $feature) { foreach ($toDisable as $feature) {
if ($feature->isEnabled()) if ($feature->isEnabled())
{
print "Disable: " . get_class($feature) . spl_object_hash($feature) . "\n";
$feature->disable(); $feature->disable();
} }
else
{
print get_class($feature) . "\n" . "Is already disabled!" . "\n";
}
}
foreach ($toEnable as $feature) { foreach ($toEnable as $feature) {
if (!$feature->isEnabled()) if (!$feature->isEnabled())
{
print "Enable: " . get_class($feature) . spl_object_hash($feature) . "\n";
$feature->enable(); $feature->enable();
} }
else
{
print get_class($feature) . "\n" . "Is already enabled!" . "\n";
}
}
} }
public function onEnd(ArenaEndEvent $event) public function onEnd(ArenaEndEvent $event)
@ -87,7 +124,7 @@ class GameStateFeatureManager implements Listener {
if ($event->getArena() !== $this->arena) if ($event->getArena() !== $this->arena)
return; return;
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features)); $iterator = UtilArray::getValuesRecursively($this->features);
foreach ($iterator as $feature) { foreach ($iterator as $feature) {
if ($feature->isEnabled()) if ($feature->isEnabled())

View File

@ -15,6 +15,7 @@ use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent
use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\Main; use mineplex\plugin\Main;
use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilArray;
use mineplex\plugin\util\UtilTeleport;
use pocketmine\event\HandlerList; use pocketmine\event\HandlerList;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\level\Position; use pocketmine\level\Position;
@ -86,8 +87,8 @@ class SimpleSpawnComponent implements SpawnComponent, Listener {
//$pos = $pos->getLevel()->getSpawnLocation(); //$pos = $pos->getLevel()->getSpawnLocation();
print_r($pos); print_r($pos);
UtilTeleport::teleport($player, $pos);
$player->teleport($pos); //$player->teleport($pos);
$player->sendMessage("After:"); $player->sendMessage("After:");
Main::sendLoc($player); Main::sendLoc($player);

View File

@ -0,0 +1,183 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/7/2015
* Time: 9:19 PM
*/
namespace mineplex\plugin\gameengine\game\components\victorytype;
use pocketmine\Player;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use pocketmine\event\Listener;
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
use mineplex\plugin\gameengine\game\components\spectate\events\EnableSpectateEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTaskData;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use pocketmine\Server;
use mineplex\plugin\gameengine\game\components\feature\UtilFeature;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use pocketmine\event\HandlerList;
class LMSVictoryType implements Listener{
private $arena;
private $duringGame;
function __construct(Arena $arena, SpectateComponent $spectateComponent, GameStateComponent $gameStateComponent, $endPlayersAmount = 1)
{
$this->arena = $arena;
$this->duringGame = new DuringGame($arena, $spectateComponent, $gameStateComponent, $endPlayersAmount);
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function gameStateChange(GameStateChangeEvent $event)
{
if ($this->arena !== $event->getArena())
return;
if ($event->getToGameState() == GameState::GAME)
{
UtilFeature::enable($this->duringGame);
}
elseif ($event->getFromGameState() == GameState::GAME)
{
UtilFeature::disable($this->duringGame);
}
}
public function onEnd(ArenaEndEvent $event)
{
if ($this->arena !== $event->getArena())
return;
UtilFeature::disable($this->duringGame);
HandlerList::unregisterAll($this);
}
}
class DuringGame extends ListenerFeature implements BenchTask {
/** @var Player[] */
private $rank = [];
/** @var Arena */
private $arena;
/** @var SpectateComponent */
private $spectateComponent;
/** @var GameStateComponent */
private $gameStateComponent;
/** @var int */
private $endPlayersAmount;
function __construct(Arena $arena, SpectateComponent $spectateComponent, GameStateComponent $gameStateComponent, $endPlayersAmount = 1)
{
parent::__construct($arena);
$this->arena = $arena;
$this->spectateComponent = $spectateComponent;
$this->gameStateComponent = $gameStateComponent;
$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)
{
if ($this->arena !== $event->getArena())
return;
if (!$this->spectateComponent->isSpectating($event->getPlayer()))
array_push($this->rank, $event->getPlayer());
$this->checkEndGame();
}
public function onSpectate(EnableSpectateEvent $event)
{
if ($this->arena !== $event->getArena())
return;
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);
}
public function checkEndGame($subtract = false)
{
if ($this->gameStateComponent->getGameState() != GameState::GAME)
{
if ($this->isEnabled())
$this->disable();
return;
}
$count = count($this->spectateComponent->getNonSpectators()) - $subtract;
if ($count <= $this->endPlayersAmount)
{
$this->gameStateComponent->setGameState(GameState::POST_GAME);
}
}
private function sendWinners()
{
foreach ($this->spectateComponent->getNonSpectators() as $player)
{
array_push($this->rank, $player);
}
/** @var Player[] $rank */
$rank = array_reverse($this->rank);
$counter = 0;
$this->arena->broadcast("----------");
$this->arena->broadcast("");
foreach ($rank as $player)
{
$counter++;
$this->arena->broadcast("$counter. §e" . $player->getName());
if ($counter >= 3)
break;
}
$this->arena->broadcast("");
$this->arena->broadcast("----------");
}
public function run(BenchTaskData $task)
{
$this->checkEndGame();
}
public function enable()
{
BenchSchedule::runTaskLater($this, 0);
parent::enable();
}
public function disable()
{
$this->sendWinners();
BenchSchedule::cancelTask($this);
parent::disable();
}
}

View File

@ -18,6 +18,7 @@ use mineplex\plugin\util\UtilString;
use mineplex\plugin\util\UtilFile; use mineplex\plugin\util\UtilFile;
use pocketmine\event\HandlerList; use pocketmine\event\HandlerList;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server; use pocketmine\Server;

View File

@ -8,11 +8,14 @@
namespace mineplex\plugin\gameengine\game\games\sg; namespace mineplex\plugin\gameengine\game\games\sg;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\countdown\GameStateCountdown; use mineplex\plugin\gameengine\game\components\countdown\GameStateCountdown;
use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown;
use mineplex\plugin\gameengine\game\components\feature\features\DeathSpectate; use mineplex\plugin\gameengine\game\components\feature\features\DeathSpectate;
use mineplex\plugin\gameengine\game\components\feature\features\FreezePlayers;
use mineplex\plugin\gameengine\game\components\feature\features\JoinSpectate;
use mineplex\plugin\gameengine\game\components\feature\features\NoBlockBreak; use mineplex\plugin\gameengine\game\components\feature\features\NoBlockBreak;
use mineplex\plugin\gameengine\game\components\feature\features\NoBlockPlace; use mineplex\plugin\gameengine\game\components\feature\features\NoBlockPlace;
use mineplex\plugin\gameengine\game\components\feature\features\NoDamage;
use mineplex\plugin\gameengine\game\components\feature\features\NoDropItem; use mineplex\plugin\gameengine\game\components\feature\features\NoDropItem;
use mineplex\plugin\gameengine\game\components\feature\features\NoPickUpItem; use mineplex\plugin\gameengine\game\components\feature\features\NoPickUpItem;
use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager; use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager;
@ -24,52 +27,55 @@ use mineplex\plugin\gameengine\game\components\spawn\SpawnAt;
use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent; use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\game\Game; use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown;
use mineplex\plugin\gameengine\game\components\feature\Feature; use mineplex\plugin\gameengine\game\components\feature\Feature;
use mineplex\plugin\gameengine\time\BenchSchedule; use mineplex\plugin\gameengine\game\components\victorytype\LMSVictoryType;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\item\Item;
class SurvivalGames implements Game { class SurvivalGames implements Game {
/** @var Arena */
private $arena;
function start(Arena $arena) function start(Arena $arena)
{ {
$this->arena = $arena;
$gameStateComponent = new GameStateComponent($arena); $gameStateComponent = new GameStateComponent($arena);
//$spectateComponent = new GameModeSpectateComponent($arena); $spectateComponent = new GameModeSpectateComponent($arena);
//Init features
//$noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true);
//$pack = array(new NoBlockBreak($arena, [Item::GRASS]), new NoBlockPlace($arena, [Item::WOOD], true),new NoDropItem($arena, [Item::APPLE], true));
/** @var Feature[][] $features */
//$features = array(
// GameState::LOBBY => array($noPickUpItem, $pack)
//);
//new GameStateFeatureManager($arena, $features);
//new LobbyComponent($arena);
$worldComponent = new WorldComponent($arena); $worldComponent = new WorldComponent($arena);
$spawnComponent = new SimpleSpawnComponent($arena, $worldComponent); new LobbyComponent($arena);
new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]); //Features start----
$noDamage = new NoDamage($arena);
$joinSpectate = new JoinSpectate($arena, $spectateComponent);
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1); $stopEveryThing = array(new NoBlockBreak($arena), new NoBlockPlace($arena),new NoDropItem($arena), new NoPickUpItem($arena));
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME); /** @var Feature[][] $features */
$features = array(
//new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME); GameState::PRE_GAME => array( $stopEveryThing, $noDamage, $joinSpectate, new FreezePlayers($arena, $spectateComponent)),
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); GameState::GAME => array( $stopEveryThing, $joinSpectate , new DeathSpectate($arena, $spectateComponent)),
GameState::POST_GAME => array($stopEveryThing, $noDamage, $joinSpectate),
);
new GameStateFeatureManager($arena, $features);
//Features end---
new SpawnAt($arena, new SimpleSpawnComponent($arena, $worldComponent), [GameState::PRE_GAME]);
new LobbyCountdown( $arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 2);
//new GameStateCountdown($arena, $gameStateComponent, 5, GameState::LOBBY, GameState::PRE_GAME);
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::PRE_GAME, GameState::GAME);
//new GameStateCountdown($arena, $gameStateComponent, 5, GameState::GAME, GameState::POST_GAME);
new LMSVictoryType( $arena, $spectateComponent, $gameStateComponent);
new GameStateCountdown($arena, $gameStateComponent, 5, GameState::POST_GAME, GameState::RESTARTING);
} }
} }

View File

@ -18,7 +18,17 @@ class UtilArray {
public static function arrayDiff(array $array, array $subtract) public static function arrayDiff(array $array, array $subtract)
{ {
return array_udiff($array, $subtract, ['mineplex\plugin\util\UtilArray', 'comp']); //THIS IS TEMP FIX LATER!!
$return = [];
foreach ($array as $value)
{
if (!in_array($value, $subtract))
array_push($return, $value);
}
return $return;
//return array_udiff($array, $subtract, ['mineplex\plugin\util\UtilArray', 'comp']);
} }
@ -52,3 +62,11 @@ class UtilArray {
} }
} }
/*
$obj1 = new \stdClass();
$a1=array("a"=>$obj1,"b"=>"green","c"=>"blue");
$a2=array("d"=>$obj1,"b"=>"black","e"=>"blue");
$result=UtilArray::arrayDiff($a1,$a2);
print_r($result);
print "hi";
*/

View File

@ -8,24 +8,21 @@ class UtilFile
{ {
if (! is_dir($dirPath)) if (! is_dir($dirPath))
{ {
throw new InvalidArgumentException("$dirPath must be a directory"); unlink($dirPath);
return;
} }
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
{ {
$dirPath .= '/'; $dirPath .= '/';
} }
$files = glob($dirPath . '*', GLOB_MARK); $files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) foreach ($files as $file)
{
if (is_dir($file))
{ {
self::deleteDir($file); self::deleteDir($file);
} }
else
{
unlink($file);
}
}
rmdir($dirPath); rmdir($dirPath);
} }
} }

View File

@ -0,0 +1,47 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/7/2015
* Time: 2:31 PM
*/
namespace mineplex\plugin\util;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\RespawnPacket;
use pocketmine\network\protocol\SetSpawnPositionPacket;
use pocketmine\network\protocol\StartGamePacket;
use pocketmine\Player;
use pocketmine\network\protocol\UpdateBlockPacket;
class UtilTeleport {
public static function teleport(Player $player, Position $position) {
$current = $player->getPosition();
//
// This CRAZY HACK is to remove Tile entities that seem to linger
// whenever you teleport!
//
if ($current->getLevel() != $position->getLevel()) {
$player->noDamageTicks = 20;
foreach ($current->getLevel()->getTiles() as $tile) {
$pk = new UpdateBlockPacket();
$pk->x = $tile->x;
$pk->y = $tile->y;
$pk->z = $tile->z;
$pk->block = 0;
$pk->meta = 0;
$player->dataPacket($pk);
}
}
$player->teleport($position); // Start the teleport
return true;
}
}