From 0c406ea760ed9c3d944fec8cd2ca3709e9d7091e Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Mon, 6 Jul 2015 19:45:28 -0400 Subject: [PATCH 01/15] 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 From bff3897fab36faac74e210ee8d9e9e18f8d6832b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 7 Jul 2015 12:30:20 +1200 Subject: [PATCH 02/15] Perks and kits: Change priority for unregistering to high, add new method to Perk firing when perk listener is registered. --- .../src/nautilus/game/arcade/kit/Perk.java | 5 +++++ .../src/nautilus/game/arcade/managers/GameManager.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java index 5b8af51b1..aecdbf572 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java @@ -54,4 +54,9 @@ public abstract class Perk implements Listener { //Null Default } + + public void registeredEvents() + { + // When listener has been registered + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java index 561ebbb7f..119179fb8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java @@ -307,7 +307,7 @@ public class GameManager implements Listener event.GetGame().RegisterKits(); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void KitDeregister(GameStateChangeEvent event) { if (event.GetState() != GameState.Dead) From 804d6695135f76d460529a8eb5c46ebdb981efb5 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 10:44:24 +1000 Subject: [PATCH 03/15] return types --- .../game/components/world/WorldComponent.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index e1d69501b..45a2601a9 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -11,6 +11,7 @@ namespace mineplex\plugin\gameengine\game\components\world; use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; +use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilString; use pocketmine\event\Listener; use pocketmine\level\Position; @@ -231,19 +232,33 @@ class WorldComponent implements Listener } } + /** + * @return Position[][] + */ public function getTeams() { return $this->mapTeams; } + /** + * @param $key + * @return int + */ public function getSetting($key) { return $this->mapSettings[$key]; } + /** + * @param $key + * @return Position[] + */ public function getData($key) { - return $this->mapData[$key]; + if (UtilArray::hasKey($key, $this->mapData)) + return $this->mapData[$key]; + + return []; } public function getPosition() @@ -251,7 +266,6 @@ class WorldComponent implements Listener return $this->getTeams()[0][0]; } - protected function strToPos($str) { if (strlen($str) < 5) From 547d49685343561b172bb3e084dc2951c2bd79e8 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Mon, 6 Jul 2015 22:22:14 -0400 Subject: [PATCH 04/15] Moo Signed-off-by: Aaron Brock --- Pocket/plugins/Mineplex/src/Test.php | 16 ++++---------- .../gameengine/arenas/MultiGameArena.php | 1 - .../feature/features/NoPickUpItem.php | 2 +- .../managers/GameStateFeatureManager.php | 9 +++++--- .../game/games/sg/SurvivalGames.php | 10 +++------ .../src/mineplex/plugin/util/UtilArray.php | 21 +++++++++++++++++++ 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/Test.php b/Pocket/plugins/Mineplex/src/Test.php index 7775713b2..42337416e 100644 --- a/Pocket/plugins/Mineplex/src/Test.php +++ b/Pocket/plugins/Mineplex/src/Test.php @@ -7,17 +7,9 @@ */ -function myfunction($a,$b) -{ - if ($a===$b) - { - return 0; - } - return ($a>$b)?1:-1; -} +$a1 = array(); +$a2 = array($a1); -$a1=array(new stdClass(),"b"=>"green","c"=>"blue"); -$a2=array("a"=>"blue","b"=>"black","e"=>"blue"); +array_push($a1, $a2); -$result=array_udiff($a1,$a2,"myfunction"); -print_r($result); \ No newline at end of file +print_r($a1); \ No newline at end of file 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 30f7d0b69..5ae4372c3 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/arenas/MultiGameArena.php @@ -83,7 +83,6 @@ class MultiGameArena implements Arena, Listener Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this)); } - public function getPlayers() { return $this->players; 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 index b307f6912..230143fc7 100644 --- 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 @@ -48,7 +48,7 @@ class NoPickUpItem extends ListenerFeature { Server::getInstance()->broadcastMessage("Stopped!"); } else Server::getInstance()->broadcastMessage("Not Stopped!"); - + } diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php index 539c16f95..9d9cc03b9 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/feature/managers/GameStateFeatureManager.php @@ -26,11 +26,11 @@ class GameStateFeatureManager implements Listener { private $arena; /** @var Feature[][] */ - private $features; + private $features = []; /** * @param Arena $arena - * @param Feature[][] $features + * @param Feature[] $features */ public function __construct(Arena $arena, array $features) { @@ -38,7 +38,10 @@ class GameStateFeatureManager implements Listener { unset ($features[GameState::RESTARTING]); - $this->features = $features; + foreach ($features as $key => $value) + { + $this->features[$key] = UtilArray::getValuesRecursively($value); + } Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); } 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 4ddf5d21a..4832c2dca 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 @@ -36,17 +36,13 @@ class SurvivalGames implements Game { //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); + $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($noBlockBreak, $noBlockPlace, $noDropItem, $noPickUpItem) + GameState::LOBBY => array($noPickUpItem, $pack) ); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php index a7dbcdf0b..f630a6f37 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilArray.php @@ -30,4 +30,25 @@ class UtilArray { } return ($a>$b)?1:-1; } + + public static function getValuesRecursively($object) + { + if (!is_array($object)) + return [$object]; + + $returnArray = []; + foreach ($object as $value) + { + if (is_array($value)) + { + $returnArray = array_merge($returnArray, array_values(self::getValuesRecursively($value))); + } + else + { + array_push($returnArray, $value); + } + } + return $returnArray; + } + } \ No newline at end of file From 769d50f1c7481c493837399657f791ee7fb12bc5 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 12:22:37 +1000 Subject: [PATCH 05/15] removed test code --- .../gameengine/game/components/world/WorldComponent.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 45a2601a9..84d3caba1 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -261,11 +261,6 @@ class WorldComponent implements Listener return []; } - public function getPosition() - { - return $this->getTeams()[0][0]; - } - protected function strToPos($str) { if (strlen($str) < 5) From 02c5dd0dfa6894e2f1fef17adb286416fdad3c07 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 12:36:32 +1000 Subject: [PATCH 06/15] world deletion --- .../game/components/world/WorldComponent.php | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 84d3caba1..6a5395a26 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -13,6 +13,7 @@ use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilString; +use mineplex\plugin\util\UtilFile; use pocketmine\event\Listener; use pocketmine\level\Position; use pocketmine\math\Vector3; @@ -26,8 +27,9 @@ class WorldComponent implements Listener private $arena; private $gameId; - private $gameFolder; + private $worldNameFolder; + /** @var \pocketmine\level\Level */ private $world; private $mapName; @@ -71,6 +73,23 @@ class WorldComponent implements Listener // } // } + private function unloadWorld() + { + if (is_null($this->world) || !$this->arena->getPlugin()->getServer()->isLevelLoaded($this->worldNameFolder)) + return; + + foreach ($this->world->getPlayers() as $player) + { + $player->kick("Dead World"); + } + + $this->arena->getPlugin()->getServer()->unloadLevel($this->world); + + UtilFile::deleteDir('worlds/' . $this->worldNameFolder); + + print("Successfully Deleted: " . $this->worldNameFolder . "\n"); + } + private function loadWorld($gameName) { $files = scandir('../update/maps/' . $gameName . '/'); @@ -92,20 +111,20 @@ class WorldComponent implements Listener print_r($worldName . "\n"); - $this->gameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName; + $this->worldNameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName; //Unzip World $zip = new ZipArchive; $res = $zip->open('../update/maps/' . $gameName . '/' . $worldName . '.zip'); if ($res === TRUE) { - $zip->extractTo('worlds/' . $this->gameFolder . '/'); + $zip->extractTo('worlds/' . $this->worldNameFolder . '/'); $zip->close(); - print("Successfully Extracted: " . $this->gameFolder . "\n"); + print("Successfully Extracted: " . $this->worldNameFolder . "\n"); } else { - print("Error Extracting: " . $this->gameFolder . "\n"); + print("Error Extracting: " . $this->worldNameFolder . "\n"); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena)); @@ -113,9 +132,9 @@ class WorldComponent implements Listener } //Load World - if ($this->arena->getPlugin()->getServer()->loadLevel($this->gameFolder)) + if ($this->arena->getPlugin()->getServer()->loadLevel($this->worldNameFolder)) { - $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->gameFolder); + $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->worldNameFolder); $this->world->setSpawnLocation(new Vector3(0,200,0)); @@ -123,13 +142,13 @@ class WorldComponent implements Listener $this->ready = true; - print("Successfully Loaded World: " . $this->gameFolder . "\n"); + print("Successfully Loaded World: " . $this->worldNameFolder . "\n"); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadSuccessEvent($this->arena, $this->world)); } else { - print("Error Loading World: " . $this->gameFolder . "\n"); + print("Error Loading World: " . $this->worldNameFolder . "\n"); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena)); From af8d1bdc83413c8276638f850fe14885a3ccc8bf Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Tue, 7 Jul 2015 00:36:17 -0400 Subject: [PATCH 07/15] Moo Signed-off-by: Aaron Brock --- .../components/spawn/SimpleSpawnComponent.php | 110 ++++++++++++++++++ .../game/components/spawn/SpawnAt.php | 50 ++++++++ .../game/components/spawn/SpawnComponent.php | 2 + .../game/components/world/WorldComponent.php | 38 +++--- .../game/games/sg/SurvivalGames.php | 17 +-- 5 files changed, 188 insertions(+), 29 deletions(-) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php new file mode 100644 index 000000000..ae8d8c26c --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php @@ -0,0 +1,110 @@ +arena = $arena; + $this->worldComponent = $worldComponent; + $this->gameMode = $gameMode; + + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + public function onWorld(WorldLoadSuccessEvent $event) + { + print "WorldLoadSuccessEvent!"; + if ($event->getArena() !== $this->arena) + return; + $this->spawns = UtilArray::getValuesRecursively($this->worldComponent->getTeams()); + + foreach ($this->spawns as $key => $value) + { + if (!($value instanceof Position)) + unset($this->spawns[$key]); + $this->spawns[$key] = new Position($value->getX(), $value->getY(), $value->getZ(), $event->getLevel()); + } + + print (count($this->spawns) . " spawns Loaded"); + + $pos = $this->spawns[array_rand($this->spawns)]; + + print "\nX: " . $pos->getX(); + print "\nY: " . $pos->getY(); + print "\nZ: " . $pos->getZ(); + print "\nLevel: " . $pos->getLevel()->getName(); + + } + + /** + * @param Player $player + * @return Position + */ + function respawn(Player $player) + { + if (count($this->spawns) < 1) + { + print "no spawns!"; + + return; + } + + $player->getInventory()->clearAll(); + $player->removeAllEffects(); + $player->resetFallDistance(); + $player->setGamemode($this->gameMode); + $player->setHealth($player->getMaxHealth()); + + $pos = $this->spawns[array_rand($this->spawns)]; + + print "\nX: " . $pos->getX(); + print "\nY: " . $pos->getY(); + print "\nZ: " . $pos->getZ(); + print "\nLevel: " . $pos->getLevel()->getName(); + + $player->teleport($pos); + return $pos; + } + + function respawnAll() { + foreach ($this->arena->getPlayers() as $player) + { + $this->respawn($player); + } + } + + function onEnd(ArenaEndEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + HandlerList::unregisterAll($this); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php new file mode 100644 index 000000000..e0906aa60 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SpawnAt.php @@ -0,0 +1,50 @@ +arena = $arena; + $this->spawnComponent = $spawnComponent; + $this->gameStates = $gameStates; + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + public function onStateChange(GameStateChangeEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + if (in_array($event->getToGameState(), $this->gameStates)) { + $this->spawnComponent->respawnAll(); + print "called! \n"; + } + } + + public function onEnd(ArenaEndEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + 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 index 5b70af098..145be17e6 100644 --- 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 @@ -19,4 +19,6 @@ interface SpawnComponent { */ function respawn(Player $player); + function respawnAll(); + } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 6a5395a26..92a2ba152 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -9,11 +9,14 @@ namespace mineplex\plugin\gameengine\game\components\world; use mineplex\plugin\gameengine\arenas\Arena; +use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; +use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilString; use mineplex\plugin\util\UtilFile; +use pocketmine\event\HandlerList; use pocketmine\event\Listener; use pocketmine\level\Position; use pocketmine\math\Vector3; @@ -48,30 +51,14 @@ class WorldComponent implements Listener $this->gameId = $this->getNewGameId(); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); - - $this->loadWorld("Super Smash Mobs"); } -// This is just some wierd testiong. Ignore it :P -// public function onJoin(PlayerJoinEvent $event) -// { -// $this->player = $event->getPlayer(); -// } -// -// public function onEvent(UpdateEvent $event) -// { -// if (is_null($this->player)) -// return; -// -// if ($event->isTiming(UpdateType::S8)) -// { -// $this->player->teleport($this->posTest); -// -// print("Teleporting " . $this->player->getName() . " to...\n"); -// -// $this->player = null; -// } -// } + public function onStart(ArenaStartEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + $this->loadWorld("Super Smash Mobs"); + } private function unloadWorld() { @@ -309,5 +296,12 @@ class WorldComponent implements Listener { return $this->ready; } + + public function onEnd(ArenaEndEvent $event) + { + if ($this->arena !== $event->getArena()) + return; + HandlerList::unregisterAll($this); + } } 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 4832c2dca..5f84070d7 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 @@ -19,6 +19,8 @@ use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeature 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; @@ -35,7 +37,6 @@ class SurvivalGames implements Game { $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)); @@ -45,21 +46,23 @@ class SurvivalGames implements Game { GameState::LOBBY => array($noPickUpItem, $pack) ); - new GameStateFeatureManager($arena, $features); - //new LobbyComponent($arena); + new LobbyComponent($arena); - /* $worldComponent = new WorldComponent($arena); - new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 50, 1); + $spawnComponent = new SimpleSpawnComponent($arena, $worldComponent); + + new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]); + + new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1); new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME); - new GameStateCountdown($arena, $gameStateComponent, 60, GameState::GAME, GameState::POST_GAME); + new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME); new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); - */ + } } \ No newline at end of file From b65d75ab0d905235fd16ea4d284be17155b4f99e Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Tue, 7 Jul 2015 00:38:00 -0400 Subject: [PATCH 08/15] Moo --- .../gameengine/game/components/spawn/SimpleSpawnComponent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php index ae8d8c26c..5ef9eadfb 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php @@ -50,11 +50,11 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { { if (!($value instanceof Position)) unset($this->spawns[$key]); - $this->spawns[$key] = new Position($value->getX(), $value->getY(), $value->getZ(), $event->getLevel()); } - print (count($this->spawns) . " spawns Loaded"); + print (count($this->spawns) . " spawns Loaded\n"); + //Just testing to make sure it is a location. $pos = $this->spawns[array_rand($this->spawns)]; print "\nX: " . $pos->getX(); From b0bbbf506ab4636607e00e53df6a7a4af4a69a3b Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 16:51:57 +1000 Subject: [PATCH 09/15] utilfile --- .../src/mineplex/plugin/util/UtilFile.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php new file mode 100644 index 000000000..c0c4b9909 --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/util/UtilFile.php @@ -0,0 +1,31 @@ + Date: Tue, 7 Jul 2015 03:26:59 -0400 Subject: [PATCH 10/15] Moo Signed-off-by: Aaron Brock --- .../Mineplex/src/mineplex/plugin/Main.php | 31 +++++++++++++++++++ .../components/spawn/SimpleSpawnComponent.php | 20 ++++++------ .../game/games/sg/SurvivalGames.php | 29 ++++++++++------- 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index 5ee8d91f6..415f1150f 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -6,12 +6,17 @@ use mineplex\plugin\gameengine\arenas\MultiGameArena; use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\factory\TestGameFactory; use mineplex\plugin\core\updater\Updater; +use mineplex\plugin\util\UtilString; +use pocketmine\block\Block; use pocketmine\event\Listener; +use pocketmine\event\player\PlayerCommandPreprocessEvent; use pocketmine\event\player\PlayerDeathEvent; +use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerLoginEvent; use pocketmine\level\Position; use pocketmine\math\Vector3; +use pocketmine\Player; use pocketmine\plugin\PluginBase; use mineplex\plugin\gameengine\arenas\Arena; use pocketmine\Server; @@ -45,4 +50,30 @@ class Main extends PluginBase implements Listener { $this->arena->addPlayer($event->getPlayer()); } + + public function punch(PlayerInteractEvent $event) + { + if ($event->getAction() == PlayerInteractEvent::LEFT_CLICK_BLOCK || $event->getAction() == PlayerInteractEvent::RIGHT_CLICK_BLOCK) + { + $event->getPlayer()->sendMessage("Block: " . $event->getBlock()->getId() . ":" . $event->getBlock()->getDamage()); + } + } + + public function command(PlayerCommandPreprocessEvent $event) + { + if (UtilString::startsWith($event->getMessage(), "/pos")) + self::sendLoc($event->getPlayer()); + } + + public static function sendLoc(Player $player) + { + $pos = $player->getLocation(); + + $player->sendMessage("X: " . $pos->getX()); + $player->sendMessage("Y: " . $pos->getY()); + $player->sendMessage("Z: " . $pos->getZ()); + $player->sendMessage("Level: " . $pos->getLevel()->getName()); + + } + } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php index 5ef9eadfb..29a0ecf59 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php @@ -13,11 +13,11 @@ use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; 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 pocketmine\event\HandlerList; use pocketmine\event\Listener; use pocketmine\level\Position; -use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; @@ -54,14 +54,6 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { print (count($this->spawns) . " spawns Loaded\n"); - //Just testing to make sure it is a location. - $pos = $this->spawns[array_rand($this->spawns)]; - - print "\nX: " . $pos->getX(); - print "\nY: " . $pos->getY(); - print "\nZ: " . $pos->getZ(); - print "\nLevel: " . $pos->getLevel()->getName(); - } /** @@ -70,20 +62,25 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { */ function respawn(Player $player) { + if (count($this->spawns) < 1) { print "no spawns!"; - return; } + /* $player->getInventory()->clearAll(); $player->removeAllEffects(); $player->resetFallDistance(); $player->setGamemode($this->gameMode); $player->setHealth($player->getMaxHealth()); + */ + $player->sendMessage("Before:"); + Main::sendLoc($player); $pos = $this->spawns[array_rand($this->spawns)]; + $pos = $pos->getLevel()->getSpawnLocation(); print "\nX: " . $pos->getX(); print "\nY: " . $pos->getY(); @@ -91,6 +88,9 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { print "\nLevel: " . $pos->getLevel()->getName(); $player->teleport($pos); + + $player->sendMessage("After:"); + Main::sendLoc($player); return $pos; } 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 5f84070d7..77ed45aa2 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 @@ -26,29 +26,36 @@ 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); + //$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)); + //$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) - ); + //$features = array( + // GameState::LOBBY => array($noPickUpItem, $pack) + //); - new GameStateFeatureManager($arena, $features); + //new GameStateFeatureManager($arena, $features); - new LobbyComponent($arena); + //new LobbyComponent($arena); $worldComponent = new WorldComponent($arena); @@ -58,11 +65,11 @@ class SurvivalGames implements Game { new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1); - new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME); + //new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME); - new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME); + //new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME); - new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); + //new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING); } } \ No newline at end of file From f61d6fc69db2894ed1c514b1332fce887ea9c394 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Tue, 7 Jul 2015 03:28:14 -0400 Subject: [PATCH 11/15] Time to day! Signed-off-by: Aaron Brock --- .../gameengine/game/components/world/WorldComponent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 92a2ba152..9adf81edd 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -124,9 +124,9 @@ class WorldComponent implements Listener $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->worldNameFolder); $this->world->setSpawnLocation(new Vector3(0,200,0)); - + $this->world->setTime(6000); $this->loadWorldData(); - + $this->ready = true; print("Successfully Loaded World: " . $this->worldNameFolder . "\n"); From 8cd5d9f7d0dc903133d0de0dccd16a7eda8c2ce9 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 17:50:36 +1000 Subject: [PATCH 12/15] fixed worldconfig parsing --- .../components/spawn/SimpleSpawnComponent.php | 24 +++++++++---------- .../game/components/world/WorldComponent.php | 6 +++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php index 29a0ecf59..d9ab860a0 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/spawn/SimpleSpawnComponent.php @@ -44,15 +44,18 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { print "WorldLoadSuccessEvent!"; if ($event->getArena() !== $this->arena) return; - $this->spawns = UtilArray::getValuesRecursively($this->worldComponent->getTeams()); - foreach ($this->spawns as $key => $value) - { - if (!($value instanceof Position)) - unset($this->spawns[$key]); - } + $this->spawns = $this->worldComponent->getTeams()['Green']; - print (count($this->spawns) . " spawns Loaded\n"); +// $this->spawns = UtilArray::getValuesRecursively($this->worldComponent->getTeams()); +// +// foreach ($this->spawns as $key => $value) +// { +// if (!($value instanceof Position)) +// unset($this->spawns[$key]); +// } +// +// print (count($this->spawns) . " spawns Loaded\n"); } @@ -80,12 +83,9 @@ class SimpleSpawnComponent implements SpawnComponent, Listener { Main::sendLoc($player); $pos = $this->spawns[array_rand($this->spawns)]; - $pos = $pos->getLevel()->getSpawnLocation(); + //$pos = $pos->getLevel()->getSpawnLocation(); - print "\nX: " . $pos->getX(); - print "\nY: " . $pos->getY(); - print "\nZ: " . $pos->getZ(); - print "\nLevel: " . $pos->getLevel()->getName(); + print_r($pos); $player->teleport($pos); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 9adf81edd..093732b04 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -145,7 +145,7 @@ class WorldComponent implements Listener public function loadWorldData() { - $handle = fopen("WorldConfig.dat", "r"); + $handle = fopen('worlds/' . $this->worldNameFolder . '/WorldConfig.dat', "r"); if ($handle) { //These store the array that data should be inserted into @@ -155,7 +155,9 @@ class WorldComponent implements Listener while (($line = fgets($handle)) !== false) { - $tokens = explode(":", $line); + $trimmedLine = trim($line, "\n\r"); + + $tokens = explode(":", $trimmedLine); if (count($tokens) < 2 || strlen($tokens[0]) == 0) { From 35ccb04ea04ff83b482990be865337a6d4df8152 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 18:11:43 +1000 Subject: [PATCH 13/15] wipe player data on join --- Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index 415f1150f..03cc4a21e 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -6,6 +6,7 @@ use mineplex\plugin\gameengine\arenas\MultiGameArena; use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\factory\TestGameFactory; use mineplex\plugin\core\updater\Updater; +use mineplex\plugin\util\UtilFile; use mineplex\plugin\util\UtilString; use pocketmine\block\Block; use pocketmine\event\Listener; @@ -35,10 +36,14 @@ class Main extends PluginBase implements Listener //$this->test = new WorldComponent($this->arena); new Updater($this); + + $this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0)); } public function onLogin(PlayerLoginEvent $event) { + UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat'); + if ($this->arena->canJoin($event->getPlayer())) return; From 0bf96281956b88d6f21d026406227f2111a7f7d8 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 19:01:53 +1000 Subject: [PATCH 14/15] removed unneeded test file --- Pocket/WorldConfig.dat | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 Pocket/WorldConfig.dat diff --git a/Pocket/WorldConfig.dat b/Pocket/WorldConfig.dat deleted file mode 100644 index a0fa54ce4..000000000 --- a/Pocket/WorldConfig.dat +++ /dev/null @@ -1,28 +0,0 @@ -MAP_NAME:Cookie Town -MAP_AUTHOR:Mineplex Build Team - -MIN_X:-123 -MAX_X:58 -MIN_Z:-74 -MAX_Z:91 - -MIN_Y:0 -MAX_Y:26 - -TEAM_NAME:Blue -TEAM_SPAWNS:-2,4,-1:-2,4,0:-2,4,1:-2,4,2:-2,4,3:-2,4,4:-2,4,5:-2,4,6:-1,4,-1:-1,4,0:-1,4,1:-1,4,2:-1,4,3:-1,4,4:-1,4,5:-1,4,6:0,4,-1:0,4,0:0,4,1:0,4,2:0,4,3:0,4,4:0,4,5:0,4,6:1,4,-1:1,4,0:1,4,1:1,4,2:1,4,3:1,4,4:1,4,5:1,4,6:2,4,-1:2,4,0:2,4,1:2,4,2:2,4,3:2,4,4:2,4,5:2,4,6:3,4,-1:3,4,0:3,4,1:3,4,2:3,4,3:3,4,4:3,4,5:3,4,6:4,4,-1:4,4,0:4,4,1:4,4,2:4,4,3:4,4,4:4,4,5:4,4,6:5,4,-1:5,4,0:5,4,1:5,4,2:5,4,3:5,4,4:5,4,5:5,4,6: - -TEAM_NAME:Red -TEAM_SPAWNS:-94,2,-10:-94,2,-9:-94,2,-8:-94,2,-7:-94,2,-6:-94,2,-5:-94,2,-4:-94,2,-3:-94,2,-2:-93,2,-10:-93,2,-9:-93,2,-8:-93,2,-7:-93,2,-6:-93,2,-5:-93,2,-4:-93,2,-3:-93,2,-2:-92,2,-10:-92,2,-9:-92,2,-8:-92,2,-7:-92,2,-6:-92,2,-5:-92,2,-4:-92,2,-3:-92,2,-2: - -DATA_NAME:YELLOW -DATA_LOCS:-39,4,7:-39,4,8:-38,4,7:-38,4,8:-33,4,3:-33,4,4:-32,4,2:-32,4,3:-32,4,4:-14,4,-25:-13,4,-26:-13,4,-25:-12,4,-26:-12,4,-25:-11,4,-26:-11,4,-25:-10,4,-25:-8,4,55:-8,4,56:-8,4,57:-7,4,55:-7,4,56:-7,4,57:-7,4,58:-6,4,55:-6,4,56:-6,4,57:-6,4,58:-5,4,69:-5,4,70:-4,4,69:-4,4,70:-2,4,14:-2,4,15:-2,4,16:-1,4,14:-1,4,15:-1,4,16:0,4,14:0,4,15:0,4,16:6,4,-31:7,4,-31:8,4,-31:38,4,35:38,4,36:38,4,37:39,4,35:39,4,36:39,4,37: - -DATA_NAME:BLACK -DATA_LOCS:-94,4,-1:-94,4,0:-94,4,1:-93,4,-1:-93,4,0:-93,4,1:-92,4,-1:-92,4,0:-92,4,1: - -DATA_NAME:PINK -DATA_LOCS:-37,4,7:-37,4,8:-36,4,-16:-36,4,-15:-36,4,-14:-36,4,7:-36,4,8:-35,4,-16:-35,4,-15:-35,4,-14:-34,4,-16:-34,4,-15:-34,4,-14:-3,4,81:-3,4,82:-2,4,80:-2,4,81:-2,4,82:-2,4,83:-1,4,80:-1,4,81:-1,4,82:-1,4,83:0,4,43:1,4,43:2,4,43:3,4,43:3,4,47:3,4,48:4,4,43:4,4,47:4,4,48:6,4,-32:7,4,-32:7,4,-7:7,4,-6:8,4,-32:8,4,-7:8,4,-6:9,4,-8:9,4,-7:11,4,69:11,4,70:11,4,71:12,4,69:12,4,71:13,4,70:29,4,42:29,4,43:29,4,44:30,4,42:30,4,43:30,4,44:31,4,42:31,4,43:31,4,44: - -DATA_NAME:RED -DATA_LOCS:-96,5,4:-93,5,5:-90,5,4: \ No newline at end of file From 9eff5b7245ba9b20a8145eab71910168ad082bc9 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 8 Jul 2015 07:51:33 +1200 Subject: [PATCH 15/15] Perks: Forgot to include this in last commit, no harm done. --- .../src/nautilus/game/arcade/game/Game.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 4ae370d96..abe4d740c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -498,7 +498,11 @@ public abstract class Game implements Listener UtilServer.getServer().getPluginManager().registerEvents(kit, Manager.getPlugin()); for (Perk perk : kit.GetPerks()) - UtilServer.getServer().getPluginManager().registerEvents(perk, Manager.getPlugin()); + { + UtilServer.getServer().getPluginManager() + .registerEvents(perk, Manager.getPlugin()); + perk.registeredEvents(); + } } }