Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-09 01:30:28 -04:00
parent 35ccb04ea0
commit d6fd7f4dd9
17 changed files with 473 additions and 67 deletions

View File

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

View File

@ -15,6 +15,7 @@ use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerLoginEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
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));
}
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()))
return;

View File

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

View File

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

View File

@ -69,7 +69,7 @@ class GameStateCountdown implements Listener, BenchTask {
public function run(BenchTaskData $data)
{
print "Count: $this->count"."\n";
print "§$this->startGameState---"."\n";
if ($this->count <= 0)
{

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\ArenaJoinEvent;
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\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\entity\Effect;
use pocketmine\event\HandlerList;
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\Server;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
class LobbyCountdown implements Listener, BenchTask {
@ -42,13 +37,11 @@ class LobbyCountdown implements Listener, BenchTask {
private $message;
const WAITING_FOR_PLAYERS = "Waiting for players!";
const POPUP_ID = "popup";
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->gameStateComponent = $gameStateComponent;
@ -61,9 +54,9 @@ class LobbyCountdown implements Listener, BenchTask {
$this->startGameState = $startGameState;
$this->setGameState = $setGameState;
$this->message = self::WAITING_FOR_PLAYERS;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
$this->checkCountdown();
}
@ -74,7 +67,7 @@ class LobbyCountdown implements Listener, BenchTask {
{
$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))
{
@ -104,7 +97,8 @@ class LobbyCountdown implements Listener, BenchTask {
{
if ($event->getArena() !== $this->arena)
return;
$this->checkCountdown();
if ($this->gameStateComponent->getGameState() == $this->startGameState)
$this->checkCountdown();
}
public function onWorldCreation(WorldLoadSuccessEvent $event)
@ -192,6 +186,6 @@ class LobbyCountdown implements Listener, BenchTask {
private function popup(Player $player)
{
$player->sendTip($this->message);
$player->sendPopup($this->message);
}
}

View File

@ -39,11 +39,11 @@ class ListenerFeature implements Feature, Listener {
}
/**
* @return boolean
* @return bool
*/
public function isEnabled()
{
$this->enabled;
return $this->enabled;
}
/**

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,46 @@
<?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\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\Server;
class NoDamage extends ListenerFeature {
function __construct(Arena $arena)
{
parent::__construct($arena);
}
function onJoin(EntityDamageEvent $event)
{
if (!$this->getArena()->hasPlayer($event->getEntity()))
return;
$event->setCancelled();
}
public function enable()
{
Server::getInstance()->broadcastMessage("Death enable!");
parent::enable();
}
public function disable()
{
Server::getInstance()->broadcastMessage("Death disable!");
parent::disable();
}
}

View File

@ -40,7 +40,9 @@ class GameStateFeatureManager implements Listener {
foreach ($features as $key => $value)
{
$this->features[$key] = UtilArray::getValuesRecursively($value);
print "$key: " . count($this->features[$key]) . "\n";
}
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
@ -66,20 +68,55 @@ class GameStateFeatureManager implements Listener {
else
$theseFeatures = [];
print "\nLast Count: ". count($lastFeatures);
print "\nThese Count: ". count($theseFeatures);
/** @var Feature[] $toEnable */
$toEnable = UtilArray::arrayDiff($theseFeatures, $lastFeatures);
print "\nEnable Count: ". count($toEnable);
/** @var Feature[] $toDisable */
$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) {
if ($feature->isEnabled())
{
print "Disable: " . get_class($feature) . spl_object_hash($feature) . "\n";
$feature->disable();
}
else
{
print get_class($feature) . "\n" . "Is already disabled!" . "\n";
}
}
foreach ($toEnable as $feature) {
if (!$feature->isEnabled())
{
print "Enable: " . get_class($feature) . spl_object_hash($feature) . "\n";
$feature->enable();
}
else
{
print get_class($feature) . "\n" . "Is already enabled!" . "\n";
}
}
}
public function onEnd(ArenaEndEvent $event)
@ -87,7 +124,7 @@ class GameStateFeatureManager implements Listener {
if ($event->getArena() !== $this->arena)
return;
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features));
$iterator = UtilArray::getValuesRecursively($this->features);
foreach ($iterator as $feature) {
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\Main;
use mineplex\plugin\util\UtilArray;
use mineplex\plugin\util\UtilTeleport;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\level\Position;
@ -86,8 +87,8 @@ class SimpleSpawnComponent implements SpawnComponent, Listener {
//$pos = $pos->getLevel()->getSpawnLocation();
print_r($pos);
$player->teleport($pos);
UtilTeleport::teleport($player, $pos);
//$player->teleport($pos);
$player->sendMessage("After:");
Main::sendLoc($player);

View File

@ -0,0 +1,180 @@
<?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());
}
public function onSpectate(EnableSpectateEvent $event)
{
if ($this->arena !== $event->getArena())
return;
array_push($this->rank, $event->getPlayer());
$this->checkEndGame(true);
}
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 pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\Server;

View File

@ -8,68 +8,62 @@
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\LobbyCountdown;
use mineplex\plugin\gameengine\game\components\feature\features\DeathSpectate;
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\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\NoPickUpItem;
use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager;
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
use mineplex\plugin\gameengine\game\components\lobby\LobbyComponent;
use mineplex\plugin\gameengine\game\components\spawn\SimpleSpawnComponent;
use mineplex\plugin\gameengine\game\components\spawn\SpawnAt;
use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\feature\Feature;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use pocketmine\item\Item;
class SurvivalGames implements Game {
/** @var Arena */
private $arena;
function start(Arena $arena)
{
$this->arena = $arena;
$gameStateComponent = new GameStateComponent($arena);
//$spectateComponent = new GameModeSpectateComponent($arena);
$spectateComponent = new GameModeSpectateComponent($arena);
//Init features
//$noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true);
$noDamage = new NoDamage($arena);
$joinSpectate = new JoinSpectate($arena, $spectateComponent);
//$pack = array(new NoBlockBreak($arena, [Item::GRASS]), new NoBlockPlace($arena, [Item::WOOD], true),new NoDropItem($arena, [Item::APPLE], true));
$stopEveryThing = array(new NoBlockBreak($arena), new NoBlockPlace($arena),new NoDropItem($arena), new NoPickUpItem($arena));
/** @var Feature[][] $features */
//$features = array(
// GameState::LOBBY => array($noPickUpItem, $pack)
//);
$features = array(
//new GameStateFeatureManager($arena, $features);
//Just here cause I'm not using LobbyComponent atm
GameState::LOBBY => array( $stopEveryThing, $noDamage, ),
//new LobbyComponent($arena);
GameState::PRE_GAME => array( $stopEveryThing, $noDamage, $joinSpectate),
$worldComponent = new WorldComponent($arena);
GameState::GAME => array( $stopEveryThing, $joinSpectate , new DeathSpectate($arena, $spectateComponent)),
$spawnComponent = new SimpleSpawnComponent($arena, $worldComponent);
GameState::POST_GAME => array($stopEveryThing, $noDamage, $joinSpectate),
new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]);
);
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1);
new GameStateFeatureManager($arena, $features);
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
//new LobbyCountdown( $arena, $gameStateComponent, null, GameState::LOBBY, GameState::PRE_GAME, 10, 2);
//new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME);
new GameStateCountdown($arena, $gameStateComponent, 5, GameState::LOBBY, GameState::PRE_GAME);
//new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
new GameStateCountdown($arena, $gameStateComponent, 5, 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

@ -51,4 +51,12 @@ class UtilArray {
return $returnArray;
}
}
}
/*
$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,23 +8,20 @@ class UtilFile
{
if (! is_dir($dirPath))
{
throw new InvalidArgumentException("$dirPath must be a directory");
unlink($dirPath);
return;
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
{
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file)
{
if (is_dir($file))
{
self::deleteDir($file);
}
else
{
unlink($file);
}
self::deleteDir($file);
}
rmdir($dirPath);
}

View File

@ -0,0 +1,84 @@
<?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 $pos)
{
$player->noDamageTicks = 20;
//$player->teleport($pos);
$current = $player->getLevel();
if ($current->getName() != $pos->getLevel()) {
foreach ($pos->getLevel()->getTiles() as $tile)
{
$pk = new UpdateBlockPacket();
$pk->x = $tile->x;
$pk->y = $tile->y;
$pk->z = $tile->z;
$pk->block = $tile->getBlock();
$pk->meta = $tile->metadata;
Packet
$player->dataPacket($pk);
}
/*
foreach ($current->getTiles() as $tile) {
$pk = new UpdateBlockPacket();
$thereTile = $pos->getLevel()->getTile(new Vector3($tile->x, $tile->y, $tile->z));
$pk->x = $tile->x;
$pk->y = $tile->y;
$pk->z = $tile->z;
if ($thereTile !== null)
{
print "There tile is not null!";
$pk->block = $thereTile->getBlock();
$pk->meta = $thereTile->metadata;
}
else
{
print "null!";
$pk->block = 0;
$pk->meta = 0;
}
$player->dataPacket($pk);
}
*/
}
//$player->sendChunk()
$player->teleport($pos);
}
}