From 0c406ea760ed9c3d944fec8cd2ca3709e9d7091e Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Mon, 6 Jul 2015 19:45:28 -0400 Subject: [PATCH] Added STUFF AND THINGS!! Signed-off-by: Aaron Brock --- .../Mineplex/src/mineplex/plugin/Main.php | 5 - .../plugin/core/commen/ItemContainer.php | 38 ++++++ .../plugin/gameengine/arenas/Arena.php | 6 + .../gameengine/arenas/MultiGameArena.php | 11 ++ .../components/countdown/LobbyCountdown.php | 2 +- .../game/components/feature/Feature.php | 2 + .../components/feature/ListenerFeature.php | 57 ++++++++ .../game/components/feature/UtilFeature.php | 24 ++++ .../feature/features/DeathSpectate.php | 41 ++++++ .../feature/features/NoBlockBreak.php | 63 ++------- .../feature/features/NoBlockPlace.php | 43 ++++++ .../feature/features/NoDropItem.php | 42 ++++++ .../feature/features/NoMovement.php | 54 ++------ .../feature/features/NoPickUpItem.php | 56 ++++++++ .../GameStateFeatureManager.php | 54 +------- .../game/components/lobby/LobbyComponent.php | 83 +++++++----- .../game/components/spawn/SpawnComponent.php | 22 +++ .../spectate/GameModeSpectateComponent.php | 127 ++++++++++++++++++ .../components/spectate/SpectateComponent.php | 49 +++++++ .../spectate/events/DisableSpectateEvent.php | 32 +++++ .../spectate/events/EnableSpectateEvent.php | 32 +++++ .../game/games/sg/SurvivalGames.php | 36 +++-- .../src/mineplex/plugin/util/UtilArray.php | 33 +++++ 23 files changed, 719 insertions(+), 193 deletions(-) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/core/commen/ItemContainer.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/UtilFeature.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/DeathSpectate.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockPlace.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDropItem.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoPickUpItem.php rename Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/{ => managers}/GameStateFeatureManager.php (83%) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/GameModeSpectateComponent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/SpectateComponent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/events/DisableSpectateEvent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/events/EnableSpectateEvent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index 6e533b0f2..5ee8d91f6 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -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()); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/commen/ItemContainer.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/commen/ItemContainer.php new file mode 100644 index 000000000..485e63027 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/commen/ItemContainer.php @@ -0,0 +1,38 @@ +ids = array_flip($ids); + } + $this->black = $black; + } + + public function hasItem($id) + { + return ($this->black == UtilArray::hasKey($id, $this->ids)); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php index 4e008f4c6..1c4fd18c1 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/Arena.php @@ -25,6 +25,12 @@ interface Arena */ public function getPlayers(); + /** + * @param mixed $player + * @return bool + */ + public function hasPlayer($player); + /** * @return Plugin */ diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php index 30a017f48..30f7d0b69 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php @@ -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; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php index ce1c286c3..0ccf4200b 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/countdown/LobbyCountdown.php @@ -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; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/Feature.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/Feature.php index 4cdce7af7..e5d612c9f 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/Feature.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/Feature.php @@ -12,9 +12,11 @@ namespace mineplex\plugin\gameengine\game\components\feature; interface Feature { public function enable(); + public function disable(); /** * @return boolean */ public function isEnabled(); + } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php new file mode 100644 index 000000000..6446a631f --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/ListenerFeature.php @@ -0,0 +1,57 @@ +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; + } + +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/UtilFeature.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/UtilFeature.php new file mode 100644 index 000000000..3d888246d --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/UtilFeature.php @@ -0,0 +1,24 @@ +isEnabled()) + $feature->enable(); + } + + public static function disable(Feature $feature) + { + if ($feature->isEnabled()) + $feature->disable(); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/DeathSpectate.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/DeathSpectate.php new file mode 100644 index 000000000..fbd1b11b4 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/DeathSpectate.php @@ -0,0 +1,41 @@ +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!'); + } + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockBreak.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockBreak.php index 35e2c02db..0b9f8cf0a 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockBreak.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockBreak.php @@ -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; - } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockPlace.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockPlace.php new file mode 100644 index 000000000..69d24a50b --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoBlockPlace.php @@ -0,0 +1,43 @@ +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(); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDropItem.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDropItem.php new file mode 100644 index 000000000..6a44d0b0f --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoDropItem.php @@ -0,0 +1,42 @@ +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(); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoMovement.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoMovement.php index eb91e6d0c..c76489f69 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoMovement.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoMovement.php @@ -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; - } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoPickUpItem.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoPickUpItem.php new file mode 100644 index 000000000..b307f6912 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/features/NoPickUpItem.php @@ -0,0 +1,56 @@ +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!"); + + + } + + +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/GameStateFeatureManager.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php similarity index 83% rename from Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/GameStateFeatureManager.php rename to Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php index a414e94b9..539c16f95 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/GameStateFeatureManager.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php @@ -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; - } - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/lobby/LobbyComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/lobby/LobbyComponent.php index 8f07066a4..5f8af7070 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/lobby/LobbyComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/lobby/LobbyComponent.php @@ -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); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php new file mode 100644 index 000000000..5b70af098 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnComponent.php @@ -0,0 +1,22 @@ +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()); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/SpectateComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/SpectateComponent.php new file mode 100644 index 000000000..6ce90738e --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/SpectateComponent.php @@ -0,0 +1,49 @@ +player = $player; + } + + public function getPlayer() + { + return $this->player; + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/events/EnableSpectateEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/events/EnableSpectateEvent.php new file mode 100644 index 000000000..9c26c8136 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spectate/events/EnableSpectateEvent.php @@ -0,0 +1,32 @@ +player = $player; + } + + public function getPlayer() + { + return $this->player; + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php index fdf04488e..4ddf5d21a 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/games/sg/SurvivalGames.php @@ -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); + */ } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php new file mode 100644 index 000000000..a7dbcdf0b --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php @@ -0,0 +1,33 @@ +$b)?1:-1; + } +} \ No newline at end of file