Added STUFF AND THINGS!!
Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
parent
844aa44dc4
commit
0c406ea760
@ -41,11 +41,6 @@ class Main extends PluginBase implements Listener
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
public function onDeath(PlayerDeathEvent $event)
|
||||
{
|
||||
$event->getEntity()->setHealth($event->getEntity()->getMaxHealth());
|
||||
}
|
||||
|
||||
public function onJoin(PlayerJoinEvent $event)
|
||||
{
|
||||
$this->arena->addPlayer($event->getPlayer());
|
||||
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 6:12 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\core\commen;
|
||||
|
||||
use mineplex\plugin\util\UtilArray;
|
||||
|
||||
class ItemContainer {
|
||||
|
||||
/** @var int[] */
|
||||
private $ids = [];
|
||||
|
||||
/** @var bool */
|
||||
private $black;
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
* @param bool $black
|
||||
*/
|
||||
public function __construct(array $ids = null, $black = false)
|
||||
{
|
||||
if ($ids != null)
|
||||
{
|
||||
$this->ids = array_flip($ids);
|
||||
}
|
||||
$this->black = $black;
|
||||
}
|
||||
|
||||
public function hasItem($id)
|
||||
{
|
||||
return ($this->black == UtilArray::hasKey($id, $this->ids));
|
||||
}
|
||||
}
|
@ -25,6 +25,12 @@ interface Arena
|
||||
*/
|
||||
public function getPlayers();
|
||||
|
||||
/**
|
||||
* @param mixed $player
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlayer($player);
|
||||
|
||||
/**
|
||||
* @return Plugin
|
||||
*/
|
||||
|
@ -89,6 +89,17 @@ class MultiGameArena implements Arena, Listener
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $player
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlayer($player)
|
||||
{
|
||||
if (!($player instanceof Player))
|
||||
return false;
|
||||
return in_array($player, $this->getPlayers());
|
||||
}
|
||||
|
||||
public function getCurrentGame()
|
||||
{
|
||||
return $this->game;
|
||||
|
@ -48,7 +48,7 @@ class LobbyCountdown implements Listener, BenchTask {
|
||||
const COUNTDOWN_ID = "count";
|
||||
|
||||
|
||||
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent, $startGameState, $setGameState, $count, $minPlayers = 1)
|
||||
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent, $startGameState, $setGameState, $count, $minPlayers = 2)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
$this->gameStateComponent = $gameStateComponent;
|
||||
|
@ -12,9 +12,11 @@ namespace mineplex\plugin\gameengine\game\components\feature;
|
||||
interface Feature {
|
||||
|
||||
public function enable();
|
||||
|
||||
public function disable();
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled();
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 1:03 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\feature;
|
||||
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\Server;
|
||||
|
||||
class ListenerFeature implements Feature, Listener {
|
||||
|
||||
/** @var bool */
|
||||
private $enabled = false;
|
||||
private $arena;
|
||||
|
||||
function __construct(Arena $arena)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
}
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->getArena()->getPlugin());
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
$this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Arena
|
||||
*/
|
||||
public function getArena()
|
||||
{
|
||||
return $this->arena;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 12:55 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\feature;
|
||||
|
||||
|
||||
class UtilFeature {
|
||||
public static function enable(Feature $feature)
|
||||
{
|
||||
if (!$feature->isEnabled())
|
||||
$feature->enable();
|
||||
}
|
||||
|
||||
public static function disable(Feature $feature)
|
||||
{
|
||||
if ($feature->isEnabled())
|
||||
$feature->disable();
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 2:38 AM
|
||||
*/
|
||||
|
||||
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\event\player\PlayerDeathEvent;
|
||||
|
||||
class DeathSpectate extends ListenerFeature {
|
||||
|
||||
private $spectateComponent;
|
||||
|
||||
function __construct(Arena $arena, SpectateComponent $spectateComponent)
|
||||
{
|
||||
parent::__construct($arena);
|
||||
$this->spectateComponent = $spectateComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param PlayerDeathEvent $event
|
||||
*/
|
||||
function onDeath(PlayerDeathEvent $event)
|
||||
{
|
||||
if (!$this->getArena()->hasPlayer($event->getEntity()))
|
||||
return;
|
||||
|
||||
if ($this->spectateComponent->enableSpectate($event->getEntity()))
|
||||
{
|
||||
//Do death stuff
|
||||
$event->getEntity()->sendTip('§4§lYOU DIED!');
|
||||
}
|
||||
}
|
||||
}
|
@ -8,26 +8,14 @@
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\feature\features;
|
||||
|
||||
use mineplex\plugin\core\commen\ItemContainer;
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\game\components\feature\Feature;
|
||||
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
|
||||
use pocketmine\event\block\BlockBreakEvent;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Server;
|
||||
|
||||
class NoBlockBreak implements Feature, Listener {
|
||||
class NoBlockBreak extends ListenerFeature {
|
||||
|
||||
/** @var Arena */
|
||||
private $arena;
|
||||
|
||||
/** @var int[] */
|
||||
private $ids = [];
|
||||
|
||||
/** @var bool */
|
||||
private $black;
|
||||
|
||||
/** @var bool */
|
||||
private $enabled = false;
|
||||
private $itemContainer;
|
||||
|
||||
/**
|
||||
* @param Arena $arena
|
||||
@ -36,47 +24,20 @@ class NoBlockBreak implements Feature, Listener {
|
||||
*/
|
||||
public function __construct(Arena $arena, array $ids = null, $black = false)
|
||||
{
|
||||
if ($ids != null) {
|
||||
$this->ids = array_flip($ids);
|
||||
foreach ($this->ids as $key => $value)
|
||||
{
|
||||
print "Key:" . $key;
|
||||
}
|
||||
}
|
||||
print "\n" . "Black: " . (($black) ? 'true' : 'false') . "\n";
|
||||
|
||||
$this->black = $black;
|
||||
|
||||
print "\n" . "SetBlackList: " . (($this->black) ? 'true' : 'false') . "\n";
|
||||
|
||||
$this->arena = $arena;
|
||||
parent::__construct($arena, $ids, $black);
|
||||
$this->itemContainer = new ItemContainer($ids, $black);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param BlockBreakEvent $event
|
||||
*/
|
||||
public function onBlockBreak(BlockBreakEvent $event)
|
||||
{
|
||||
if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
|
||||
if (!$this->getArena()->hasPlayer($event->getPlayer()))
|
||||
return;
|
||||
|
||||
if ($this->black == (isset($this->ids[$event->getBlock()->getId()]) || array_key_exists($event->getBlock()->getId(), $this->ids)))
|
||||
if ($this->itemContainer->hasItem($event->getBlock()->getId()))
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
public function enable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Enabled!");
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Disabled!");
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: TheMineBench
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:20 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\feature\features;
|
||||
|
||||
use mineplex\plugin\core\commen\ItemContainer;
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
|
||||
use pocketmine\event\block\BlockPlaceEvent;
|
||||
|
||||
class NoBlockPlace extends ListenerFeature {
|
||||
|
||||
private $itemContainer;
|
||||
|
||||
/**
|
||||
* @param Arena $arena
|
||||
* @param int[] $ids
|
||||
* @param bool $black
|
||||
*/
|
||||
public function __construct(Arena $arena, array $ids = null, $black = false)
|
||||
{
|
||||
parent::__construct($arena, $ids, $black);
|
||||
$this->itemContainer = new ItemContainer($ids, $black);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param BlockPlaceEvent $event
|
||||
*/
|
||||
public function onPlace(BlockPlaceEvent $event)
|
||||
{
|
||||
if (!$this->getArena()->hasPlayer($event->getPlayer()))
|
||||
return;
|
||||
|
||||
if ($this->itemContainer->hasItem($event->getBlock()->getId()))
|
||||
$event->setCancelled();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: TheMineBench
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:20 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\core\commen\ItemContainer;use pocketmine\event\player\PlayerDropItemEvent;
|
||||
|
||||
class NoDropItem extends ListenerFeature {
|
||||
|
||||
private $itemContainer;
|
||||
|
||||
/**
|
||||
* @param Arena $arena
|
||||
* @param int[] $ids
|
||||
* @param bool $black
|
||||
*/
|
||||
public function __construct(Arena $arena, array $ids = null, $black = false)
|
||||
{
|
||||
parent::__construct($arena, $ids, $black);
|
||||
$this->itemContainer = new ItemContainer($ids, $black);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param PlayerDropItemEvent $event
|
||||
*/
|
||||
public function onDrop(PlayerDropItemEvent $event)
|
||||
{
|
||||
if (!$this->getArena()->hasPlayer($event->getPlayer()))
|
||||
return;
|
||||
|
||||
if ($this->itemContainer->hasItem($event->getItem()->getId()))
|
||||
$event->setCancelled();
|
||||
}
|
||||
}
|
@ -9,55 +9,27 @@
|
||||
namespace mineplex\plugin\gameengine\game\components\feature\features;
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\game\components\feature\Feature;
|
||||
use pocketmine\entity\Effect;
|
||||
use pocketmine\event\block\BlockBreakEvent;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class NoMovement implements Feature, Listener {
|
||||
|
||||
private $arena;
|
||||
private $enabled = false;
|
||||
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
|
||||
use pocketmine\event\player\PlayerMoveEvent;
|
||||
|
||||
class NoMovement extends ListenerFeature {
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
parent::__construct($arena);
|
||||
}
|
||||
|
||||
public function onBlockBreak(BlockBreakEvent $event)
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param PlayerMoveEvent $event
|
||||
*/
|
||||
public function onMove(PlayerMoveEvent $event)
|
||||
{
|
||||
if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
|
||||
if (!$this->getArena()->hasPlayer($event->getPlayer()))
|
||||
return;
|
||||
|
||||
|
||||
|
||||
$event->setCancelled(true);
|
||||
|
||||
|
||||
|
||||
if (($event->getFrom()->getX() == $event->getTo()->getX()) && ($event->getFrom()->getY() == $event->getTo()->getY()) && ($event->getFrom()->getZ() == $event->getTo()->getZ()))
|
||||
return;
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Disabled!");
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: TheMineBench
|
||||
* Date: 7/1/2015
|
||||
* Time: 10:20 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\core\commen\ItemContainer;
|
||||
use pocketmine\event\inventory\InventoryPickupItemEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Server;
|
||||
|
||||
class NoPickUpItem extends ListenerFeature {
|
||||
|
||||
private $itemContainer;
|
||||
|
||||
/**
|
||||
* @param Arena $arena
|
||||
* @param int[] $ids
|
||||
* @param bool $black
|
||||
*/
|
||||
public function __construct(Arena $arena, array $ids = null, $black = false)
|
||||
{
|
||||
parent::__construct($arena, $ids, $black);
|
||||
$this->itemContainer = new ItemContainer($ids, $black);
|
||||
}
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param InventoryPickupItemEvent $event
|
||||
*/
|
||||
public function onPickUp(InventoryPickupItemEvent $event)
|
||||
{
|
||||
if (!$this->getArena()->hasPlayer($event->getInventory()->getHolder())) {
|
||||
Server::getInstance()->broadcastMessage("You're not in the arena!");
|
||||
return;
|
||||
}
|
||||
|
||||
Server::getInstance()->broadcastMessage("Grass: " . Item::GRASS);
|
||||
Server::getInstance()->broadcastMessage("Item: " . $event->getItem()->getItem()->getId());
|
||||
|
||||
if ($this->itemContainer->hasItem($event->getItem()->getItem()->getId())) {
|
||||
$event->setCancelled();
|
||||
Server::getInstance()->broadcastMessage("Stopped!");
|
||||
} else
|
||||
Server::getInstance()->broadcastMessage("Not Stopped!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -6,29 +6,31 @@
|
||||
* Time: 12:44 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\feature;
|
||||
namespace mineplex\plugin\gameengine\game\components\feature\managers;
|
||||
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
|
||||
use mineplex\plugin\util\UtilArray;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Server;
|
||||
use RecursiveArrayIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use mineplex\plugin\gameengine\game\components\feature\Feature;
|
||||
|
||||
class GameStateFeatureManager implements Listener {
|
||||
|
||||
private $arena;
|
||||
|
||||
/** @var feature[][] */
|
||||
/** @var Feature[][] */
|
||||
private $features;
|
||||
|
||||
/**
|
||||
* @param Arena $arena
|
||||
* @param feature[][] $features
|
||||
* @param Feature[][] $features
|
||||
*/
|
||||
public function __construct(Arena $arena, array $features)
|
||||
{
|
||||
@ -62,10 +64,10 @@ class GameStateFeatureManager implements Listener {
|
||||
$theseFeatures = [];
|
||||
|
||||
/** @var Feature[] $toEnable */
|
||||
$toEnable = array_udiff($theseFeatures, $lastFeatures, array($this, 'comp'));
|
||||
$toEnable = UtilArray::arrayDiff($theseFeatures, $lastFeatures);
|
||||
|
||||
/** @var Feature[] $toDisable */
|
||||
$toDisable = array_udiff($lastFeatures, $theseFeatures, array($this, 'comp'));
|
||||
$toDisable = UtilArray::arrayDiff($lastFeatures, $theseFeatures);
|
||||
|
||||
foreach ($toDisable as $feature) {
|
||||
if ($feature->isEnabled())
|
||||
@ -82,7 +84,6 @@ class GameStateFeatureManager implements Listener {
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features));
|
||||
|
||||
foreach ($iterator as $feature) {
|
||||
@ -93,47 +94,6 @@ class GameStateFeatureManager implements Listener {
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
||||
function comp($a,$b)
|
||||
{
|
||||
if ($a===$b)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ($a>$b)?1:-1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -8,11 +8,10 @@
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\lobby;
|
||||
|
||||
|
||||
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\Feature;
|
||||
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
|
||||
use pocketmine\event\block\BlockBreakEvent;
|
||||
@ -30,7 +29,6 @@ use pocketmine\Server;
|
||||
class LobbyComponent implements Listener
|
||||
{
|
||||
|
||||
|
||||
/** @var Arena */
|
||||
private $arena;
|
||||
|
||||
@ -66,22 +64,29 @@ class LobbyComponent implements Listener
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @priority LOW
|
||||
* @param GameStateChangeEvent $event
|
||||
*/
|
||||
public function gameStateChange(GameStateChangeEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
|
||||
if ($event->getToGameState() == GameState::LOBBY) {
|
||||
if (!$this->duringLobbyGameState->isEnabled()) {
|
||||
if ($event->getToGameState() == GameState::LOBBY)
|
||||
{
|
||||
if (!$this->duringLobbyGameState->isEnabled())
|
||||
{
|
||||
$this->duringLobbyGameState->enable();
|
||||
}
|
||||
} elseif ($event->getFromGameState() == GameState::LOBBY) {
|
||||
if ($this->duringLobbyGameState->isEnabled()) {
|
||||
}
|
||||
elseif ($event->getFromGameState() == GameState::LOBBY)
|
||||
{
|
||||
if ($this->duringLobbyGameState->isEnabled())
|
||||
{
|
||||
$this->duringLobbyGameState->disable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function onGameEnd(ArenaEndEvent $event)
|
||||
@ -95,57 +100,72 @@ class LobbyComponent implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
class DuringLobbyGameState implements Feature, Listener
|
||||
class DuringLobbyGameState extends ListenerFeature
|
||||
{
|
||||
|
||||
private $arena;
|
||||
|
||||
private $spawn;
|
||||
|
||||
/** @var bool */
|
||||
private $enabled = false;
|
||||
|
||||
public function __construct(Arena $arena, Level $world)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
parent::__construct($arena);
|
||||
$this->spawn = new Position(0, 103, 0, $world);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param EntityDamageEvent $event
|
||||
*/
|
||||
function onDamage(EntityDamageEvent $event)
|
||||
{
|
||||
if (!in_array($event->getEntity(), $this->arena->getPlayers()))
|
||||
if (!in_array($event->getEntity(), $this->getArena()->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param PlayerDropItemEvent $event
|
||||
*/
|
||||
function onDrop(PlayerDropItemEvent $event)
|
||||
{
|
||||
if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
|
||||
if (!in_array($event->getPlayer(), $this->getArena()->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param InventoryPickupItemEvent $event
|
||||
*/
|
||||
function onPickUp(InventoryPickupItemEvent $event)
|
||||
{
|
||||
if (!in_array($event->getInventory()->getHolder(), $this->arena->getPlayers()))
|
||||
if (!in_array($event->getInventory()->getHolder(), $this->getArena()->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param EntityShootBowEvent $event
|
||||
*/
|
||||
function onBowShoot(EntityShootBowEvent $event)
|
||||
{
|
||||
if (!in_array($event->getEntity(), $this->arena->getPlayers()))
|
||||
if (!in_array($event->getEntity(), $this->getArena()->getPlayers()))
|
||||
return;
|
||||
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignoreCancelled true
|
||||
* @param ArenaJoinEvent $event
|
||||
*/
|
||||
function onJoin(ArenaJoinEvent $event)
|
||||
{
|
||||
if ($this->arena !== $event->getArena())
|
||||
if ($this->getArena() !== $event->getArena())
|
||||
return;
|
||||
|
||||
$this->sendToSpawn($event->getPlayer());
|
||||
@ -155,6 +175,7 @@ class DuringLobbyGameState implements Feature, Listener
|
||||
{
|
||||
$player->getInventory()->clearAll();
|
||||
$player->removeAllEffects();
|
||||
$player->setGamemode(Player::ADVENTURE);
|
||||
|
||||
$player->setHealth($player->getMaxHealth());
|
||||
$player->resetFallDistance();
|
||||
@ -164,24 +185,12 @@ class DuringLobbyGameState implements Feature, Listener
|
||||
$player->teleport($pos);
|
||||
}
|
||||
|
||||
|
||||
function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
function enable()
|
||||
{
|
||||
foreach ($this->arena->getPlayers() as $player) {
|
||||
parent::enable();
|
||||
foreach ($this->getArena()->getPlayers() as $player)
|
||||
{
|
||||
$this->sendToSpawn($player);
|
||||
}
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
function disable()
|
||||
{
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 2:06 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spawn;
|
||||
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\Player;
|
||||
|
||||
interface SpawnComponent {
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return Position
|
||||
*/
|
||||
function respawn(Player $player);
|
||||
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 12:53 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spectate;
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\arenas\events\ArenaQuitEvent;
|
||||
use mineplex\plugin\gameengine\game\components\spectate\events\DisableSpectateEvent;
|
||||
use mineplex\plugin\gameengine\game\components\spectate\events\EnableSpectateEvent;
|
||||
use mineplex\plugin\util\UtilArray;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class GameModeSpectateComponent implements SpectateComponent, Listener {
|
||||
|
||||
/** @var Player[] */
|
||||
private $spectators = [];
|
||||
|
||||
private $arena;
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function enableSpectate(Player $player)
|
||||
{
|
||||
if ($this->isSpectating($player))
|
||||
return false;
|
||||
$event = new EnableSpectateEvent($this->arena, $player);
|
||||
|
||||
Server::getInstance()->getPluginManager()->callEvent($event);
|
||||
|
||||
if ($event->isCancelled())
|
||||
return false;
|
||||
|
||||
$player->getInventory()->clearAll();
|
||||
$player->removeAllEffects();
|
||||
|
||||
$player->setHealth($player->getMaxHealth());
|
||||
$player->resetFallDistance();
|
||||
|
||||
$player->setGamemode(Player::SPECTATOR);
|
||||
array_push($this->spectators, $player);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function disableSpectate(Player $player)
|
||||
{
|
||||
if (!$this->isSpectating($player))
|
||||
return false;
|
||||
$event = new DisableSpectateEvent($this->arena, $player);
|
||||
|
||||
Server::getInstance()->getPluginManager()->callEvent($event);
|
||||
|
||||
if ($event->isCancelled())
|
||||
return false;
|
||||
|
||||
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.
|
||||
/**
|
||||
* @priority LOW
|
||||
* @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]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function isSpectating(Player $player)
|
||||
{
|
||||
return in_array($player, $this->getSpectators());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotSpectating(Player $player)
|
||||
{
|
||||
return in_array($player, $this->arena->getPlayers()) && !$this->isSpectating($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getSpectators()
|
||||
{
|
||||
return $this->spectators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getNonSpectators()
|
||||
{
|
||||
return UtilArray::arrayDiff($this->arena->getPlayers(), $this->getSpectators());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/5/2015
|
||||
* Time: 11:52 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spectate;
|
||||
|
||||
|
||||
use pocketmine\Player;
|
||||
|
||||
interface SpectateComponent {
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function enableSpectate(Player $player);
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function disableSpectate(Player $player);
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function isSpectating(Player $player);
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotSpectating(Player $player);
|
||||
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getSpectators();
|
||||
|
||||
/**
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getNonSpectators();
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 1:27 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spectate\events;
|
||||
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\ArenaEvent;
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Player;
|
||||
|
||||
class DisableSpectateEvent extends ArenaEvent implements Cancellable {
|
||||
public static $handlerList = null;
|
||||
|
||||
private $player;
|
||||
|
||||
public function __construct(Arena $arena, Player $player)
|
||||
{
|
||||
parent::__construct($arena);
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
public function getPlayer()
|
||||
{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 1:27 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spectate\events;
|
||||
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\ArenaEvent;
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Player;
|
||||
|
||||
class EnableSpectateEvent extends ArenaEvent implements Cancellable {
|
||||
public static $handlerList = null;
|
||||
|
||||
private $player;
|
||||
|
||||
public function __construct(Arena $arena, Player $player)
|
||||
{
|
||||
parent::__construct($arena);
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
public function getPlayer()
|
||||
{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
@ -10,11 +10,16 @@ namespace mineplex\plugin\gameengine\game\games\sg;
|
||||
|
||||
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\NoBlockBreak;
|
||||
use mineplex\plugin\gameengine\game\components\feature\GameStateFeatureManager;
|
||||
use mineplex\plugin\gameengine\game\components\feature\features\NoBlockPlace;
|
||||
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\spectate\GameModeSpectateComponent;
|
||||
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
|
||||
use mineplex\plugin\gameengine\game\Game;
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
@ -27,29 +32,38 @@ class SurvivalGames implements Game {
|
||||
{
|
||||
$gameStateComponent = new GameStateComponent($arena);
|
||||
|
||||
$noBlockBreak = new NoBlockBreak($arena);
|
||||
$someBlockBreak = new NoBlockBreak($arena, array(Item::GRASS));
|
||||
$spectateComponent = new GameModeSpectateComponent($arena);
|
||||
|
||||
//Init features
|
||||
|
||||
$noBlockBreak = new NoBlockBreak($arena, [Item::GRASS]);
|
||||
|
||||
$noBlockPlace = new NoBlockPlace($arena, [Item::WOOD], true);
|
||||
|
||||
$noDropItem = new NoDropItem($arena, [Item::APPLE], true);
|
||||
|
||||
$noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true);
|
||||
|
||||
/** @var Feature[][] $features */
|
||||
$features = array(
|
||||
GameState::LOBBY => array($noBlockBreak),
|
||||
GameState::PRE_GAME => array($noBlockBreak),
|
||||
GameState::GAME => array($someBlockBreak),
|
||||
GameState::POST_GAME => array($noBlockBreak)
|
||||
GameState::LOBBY => array($noBlockBreak, $noBlockPlace, $noDropItem, $noPickUpItem)
|
||||
);
|
||||
|
||||
new LobbyComponent($arena);
|
||||
|
||||
//new GameStateFeatureManager($arena, $features);
|
||||
new GameStateFeatureManager($arena, $features);
|
||||
|
||||
//new LobbyComponent($arena);
|
||||
|
||||
/*
|
||||
$worldComponent = new WorldComponent($arena);
|
||||
|
||||
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 50);
|
||||
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 50, 1);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME);
|
||||
new GameStateCountdown($arena, $gameStateComponent, 60, GameState::GAME, GameState::POST_GAME);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
|
||||
*/
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 1:07 AM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\util;
|
||||
|
||||
|
||||
class UtilArray {
|
||||
|
||||
public static function hasKey($key, array $array)
|
||||
{
|
||||
return (isset($array[$key]) || array_key_exists($key, $array));
|
||||
}
|
||||
|
||||
public static function arrayDiff(array $array, array $subtract)
|
||||
{
|
||||
return array_udiff($array, $subtract, ['mineplex\plugin\util\UtilArray', 'comp']);
|
||||
}
|
||||
|
||||
|
||||
static function comp($a,$b)
|
||||
{
|
||||
if ($a===$b)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ($a>$b)?1:-1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user