From 8d2b1650afd7d97b34c0df37c3633b07ebf672d6 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sun, 5 Jul 2015 15:13:18 +1000 Subject: [PATCH 1/7] world component for MCPE --- .../mineplex/core/benefit/BenefitManager.java | 2 +- .../game/components/world/WorldComponent.php | 210 ++++++++++++++++++ 2 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php diff --git a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java index 2b4a94e96..973950020 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java @@ -31,7 +31,7 @@ public class BenefitManager extends MiniDbClientPlugin //_benefits.add(new Christmas2014(plugin, _repository, inventoryManager)); //_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager)); - _benefits.add(new Players40k(this, _repository, inventoryManager)); + //_benefits.add(new Players40k(this, _repository, inventoryManager)); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php new file mode 100644 index 000000000..72aefb56a --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php @@ -0,0 +1,210 @@ +arena = $arena; + + $this->gameId = getNewGameId(); + $this->gameFolder = "Game" . $this->gameId . "_" . $this->worldName; + + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + private function loadWorld($worldName) + { + $this-$worldName = $worldName; + + //Do this Async? + if ($this->arena->getPlugin()->getServer()->loadLevel($worldName)) + { + $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($worldName); + + loadWorldData(); + } + else + { + print("ERROR LOADING WORLD: " + $worldName); + } + } + + public function loadWorldData($world) + { + $handle = fopen("WorldConfig.dat", "r"); + if ($handle) + { + //These store the array that data should be inserted into + + $currentTeamName = null; + $currentDataName = null; + + while (($line = fgets($handle)) !== false) + { + $tokens = explode(":", $line); + + if (count($tokens) < 2 || strlen($tokens[0]) == 0) + { + continue; + } + + //Name & Author + if (strcmp($tokens[0], "MAP_NAME") === 0) + { + $this->mapName = $tokens[1]; + } + else if (strcmp($tokens[0], "MAP_AUTHOR") === 0) + { + $this->mapAuthor = $tokens[1]; + } + + //Map Boundaries + else if (strcmp($tokens[0], "MIN_X") === 0) + { + $this->minX = $tokens[1]; + } + else if (strcmp($tokens[0], "MAX_X") === 0) + { + $this->maxX = $tokens[1]; + } + else if (strcmp($tokens[0], "MIN_Y") === 0) + { + $this->minY = $tokens[1]; + } + else if (strcmp($tokens[0], "MAX_Y") === 0) + { + $this->maxY = $tokens[1]; + } + else if (strcmp($tokens[0], "MIN_Z") === 0) + { + $this->minZ = $tokens[1]; + } + else if (strcmp($tokens[0], "MAX_Z") === 0) + { + $this->maxZ = $tokens[1]; + } + + //Team Spawns + else if (strcmp($tokens[0], "TEAM_NAME") === 0) + { + $currentTeamName = $tokens[1]; + } + else if (strcmp($tokens[0], "TEAM_SPAWNS") === 0) + { + $positions = array(); + + foreach ($tokens as $token) + { + $position = strToPos($token); + + if (is_null($position)) + continue; + + array_push($positions, $position); + } + + $this->mapTeams[$currentTeamName] = $positions; + } + + //Data + else if (strcmp($tokens[0], "DATA_NAME") === 0) + { + $currentDataName = $tokens[1]; + } + else if (strcmp($tokens[0], "DATA_LOCS") === 0) + { + $positions = array(); + + foreach ($tokens as $token) + { + $position = strToPos($token); + + if (is_null($position)) + continue; + + array_push($positions, $position); + } + + $this->mapData[$currentDataName] = $positions; + } + } + + fclose($handle); + } + else + { + print("Error Opening File"); + } + } + + public function getTeams() + { + return $this->mapTeams; + } + + public function getData($key) + { + return $this->worldData[$key]; + } + + protected function strToLoc($str) + { + $tokens = explode(",", $str); + + try + { + return new Position($tokens[0], $tokens[1], $tokens[2], $this->world); + } + catch (Exception $e) + { + print("World Data Read Error: Invalid Position String [" . $str . "]"); + } + + return null; + } + + //This will return a UID for the game + public function getNewGameId() +{ + return rand(0, 999999); //Make this acutally unique +} +} + From bde58fcad93e8be0fb88acf8a639433550d6a274 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sun, 5 Jul 2015 15:14:24 +1000 Subject: [PATCH 2/7] debug file --- Pocket/WorldConfig.dat | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Pocket/WorldConfig.dat diff --git a/Pocket/WorldConfig.dat b/Pocket/WorldConfig.dat new file mode 100644 index 000000000..a0fa54ce4 --- /dev/null +++ b/Pocket/WorldConfig.dat @@ -0,0 +1,28 @@ +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 e24890d292790b0a821fac115113762dfb134c69 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sun, 5 Jul 2015 15:26:56 +1000 Subject: [PATCH 3/7] fixed some buggies --- .../game/components/world/WorldComponent.php | 62 +++++++------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php index 72aefb56a..22daaf0fa 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php @@ -26,19 +26,13 @@ class WorldComponent implements Listener private $world; private $worldName; - private $mapName; private $mapAuthor; private $mapTeams = array(); private $mapData = array(); - private $minX = -256; - private $maxX = 256; - private $minY = -256; - private $maxY = 256; - private $minZ = -256; - private $maxZ = 256; + private $mapSettings = array(); public function __construct(Arena $arena) { @@ -91,43 +85,28 @@ class WorldComponent implements Listener { $this->mapName = $tokens[1]; } - else if (strcmp($tokens[0], "MAP_AUTHOR") === 0) + elseif (strcmp($tokens[0], "MAP_AUTHOR") === 0) { $this->mapAuthor = $tokens[1]; } //Map Boundaries - else if (strcmp($tokens[0], "MIN_X") === 0) + elseif (strcmp($tokens[0], "MIN_X") === 0 || + strcmp($tokens[0], "MAX_X") === 0 || + strcmp($tokens[0], "MIN_Y") === 0 || + strcmp($tokens[0], "MAX_Y") === 0 || + strcmp($tokens[0], "MIN_Z") === 0 || + strcmp($tokens[0], "MAX_Z") === 0) { - $this->minX = $tokens[1]; - } - else if (strcmp($tokens[0], "MAX_X") === 0) - { - $this->maxX = $tokens[1]; - } - else if (strcmp($tokens[0], "MIN_Y") === 0) - { - $this->minY = $tokens[1]; - } - else if (strcmp($tokens[0], "MAX_Y") === 0) - { - $this->maxY = $tokens[1]; - } - else if (strcmp($tokens[0], "MIN_Z") === 0) - { - $this->minZ = $tokens[1]; - } - else if (strcmp($tokens[0], "MAX_Z") === 0) - { - $this->maxZ = $tokens[1]; + $this->mapSettings[$tokens[0]] = $tokens[1]; } //Team Spawns - else if (strcmp($tokens[0], "TEAM_NAME") === 0) + elseif (strcmp($tokens[0], "TEAM_NAME") === 0) { $currentTeamName = $tokens[1]; } - else if (strcmp($tokens[0], "TEAM_SPAWNS") === 0) + elseif (strcmp($tokens[0], "TEAM_SPAWNS") === 0) { $positions = array(); @@ -145,11 +124,11 @@ class WorldComponent implements Listener } //Data - else if (strcmp($tokens[0], "DATA_NAME") === 0) + elseif (strcmp($tokens[0], "DATA_NAME") === 0) { $currentDataName = $tokens[1]; } - else if (strcmp($tokens[0], "DATA_LOCS") === 0) + elseif (strcmp($tokens[0], "DATA_LOCS") === 0) { $positions = array(); @@ -180,9 +159,14 @@ class WorldComponent implements Listener return $this->mapTeams; } + public function getSetting($key) + { + return $this->mapSettings[$key]; + } + public function getData($key) { - return $this->worldData[$key]; + return $this->mapData[$key]; } protected function strToLoc($str) @@ -199,12 +183,12 @@ class WorldComponent implements Listener } return null; - } + } //This will return a UID for the game public function getNewGameId() -{ - return rand(0, 999999); //Make this acutally unique -} + { + return rand(0, 999999); //Make this acutally unique + } } From c7d758c8d8df020c608fa666ac3d7c7cb1723c28 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sun, 5 Jul 2015 17:50:18 +1000 Subject: [PATCH 4/7] fixed UpdateEvent added WorldComponent --- .../Mineplex/src/mineplex/plugin/Main.php | 12 +- .../game/components/world/WorldComponent.php | 123 +++++++++++++++--- .../plugin/core/updater/UpdateEvent.php | 10 +- .../plugin/core/updater/UpdateType.php | 49 ++++--- .../mineplex/plugin/core/updater/Updater.php | 17 ++- 5 files changed, 160 insertions(+), 51 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index fec53f2c5..b7992596c 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -3,11 +3,12 @@ namespace mineplex\plugin; use mineplex\plugin\bench\arenas\MultiGameArena; +use mineplex\plugin\bench\game\components\world\WorldComponent; use mineplex\plugin\bench\game\factory\TestGameFactory; +use mineplex\plugin\core\updater\Updater; use pocketmine\event\Listener; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerLoginEvent; -use pocketmine\event\player\PlayerQuitEvent; use pocketmine\plugin\PluginBase; use mineplex\plugin\bench\arenas\Arena; use pocketmine\Server; @@ -16,23 +17,24 @@ class Main extends PluginBase implements Listener { /** @var Arena */ private $arena; + private $test; public function onEnable() { - $this->arena = new MultiGameArena($this, new TestGameFactory()); Server::getInstance()->getPluginManager()->registerEvents($this, $this); - //$this->getServer()->getScheduler()->scheduleRepeatingTask(new TickTask($this), 1); + $this->test = new WorldComponent($this->arena); //$this->getServer()->getPluginManager()->registerEvents($this, $this); - //new Updater($this); + + new Updater($this); } public function onLogin(PlayerLoginEvent $event) { if ($this->arena->canJoin($event->getPlayer())) - retun; + return; $event->setKickMessage("Unable to join game!"); $event->setCancelled(); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php index 22daaf0fa..0fbf814ee 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/world/WorldComponent.php @@ -9,12 +9,20 @@ namespace mineplex\plugin\bench\game\components\world; use mineplex\plugin\bench\arenas\Arena; +use mineplex\plugin\bench\game\components\world\event\WorldLoadFailEvent; +use mineplex\plugin\bench\game\components\world\event\WorldLoadSuccessEvent; +use mineplex\plugin\util\UtilString; +use mineplex\plugin\core\updater\UpdateEvent; +use mineplex\plugin\core\updater\UpdateType; +use pocketmine\event\level\LevelUnloadEvent; +use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\Listener; use pocketmine\level\Position; -use pocketmine\math\Vector3; use pocketmine\Server; +use pocketmine\Player; -//require_once __DIR__ . '\GameState.php'; +use ZipArchive; +use Exception; class WorldComponent implements Listener { @@ -24,44 +32,106 @@ class WorldComponent implements Listener private $gameFolder; private $world; - private $worldName; private $mapName; private $mapAuthor; private $mapTeams = array(); private $mapData = array(); - private $mapSettings = array(); + private $posTest = null; + private $player = null; + public function __construct(Arena $arena) { $this->arena = $arena; - $this->gameId = getNewGameId(); - $this->gameFolder = "Game" . $this->gameId . "_" . $this->worldName; + $this->gameId = $this->getNewGameId(); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + + $this->loadWorld("Super Smash Mobs"); } - private function loadWorld($worldName) + //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; +// } +// } + + private function loadWorld($gameName) { - $this-$worldName = $worldName; + $files = scandir('../update/maps/' . $gameName . '/'); - //Do this Async? - if ($this->arena->getPlugin()->getServer()->loadLevel($worldName)) + $maps = array(); + + foreach ($files as $file) { - $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($worldName); + if (UtilString::endsWith($file, ".zip")) + { + array_push($maps, $file); + } + } - loadWorldData(); + $worldName = $maps[rand(0, count($maps) - 1)]; + + //Trim .zip + $worldName = substr($worldName, 0, strlen($worldName) - 4); + + print_r($worldName . "\n"); + + $this->gameFolder = "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->close(); + print("Successfully Extracted: " . $this->gameFolder . "\n"); } else { - print("ERROR LOADING WORLD: " + $worldName); + print("Error Extracting: " . $this->gameFolder . "\n"); + } + + //Load World + if ($this->arena->getPlugin()->getServer()->loadLevel($this->gameFolder)) + { + $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->gameFolder); + + $this->loadWorldData(); + + print("Successfully Loaded World: " . $this->gameFolder . "\n"); + + Server::getInstance()->getPluginManager()->callEvent(new WorldLoadSuccessEvent($this->arena)); + } + else + { + print("Error Loading World: " . $this->gameFolder . "\n"); + + Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena)); } } - public function loadWorldData($world) + public function loadWorldData() { $handle = fopen("WorldConfig.dat", "r"); if ($handle) @@ -110,13 +180,15 @@ class WorldComponent implements Listener { $positions = array(); - foreach ($tokens as $token) + for ($x=1 ; $xstrToPos($tokens[$x]); if (is_null($position)) continue; + $this->posTest = $position; + array_push($positions, $position); } @@ -132,9 +204,9 @@ class WorldComponent implements Listener { $positions = array(); - foreach ($tokens as $token) + for ($x=1 ; $xstrToPos($tokens[$x]); if (is_null($position)) continue; @@ -150,7 +222,7 @@ class WorldComponent implements Listener } else { - print("Error Opening File"); + print("Error Opening File."); } } @@ -169,8 +241,17 @@ class WorldComponent implements Listener return $this->mapData[$key]; } - protected function strToLoc($str) + public function getPosition() { + return $this->getTeams()[0][0]; + } + + + protected function strToPos($str) + { + if (strlen($str) < 5) + return null; + $tokens = explode(",", $str); try @@ -179,7 +260,7 @@ class WorldComponent implements Listener } catch (Exception $e) { - print("World Data Read Error: Invalid Position String [" . $str . "]"); + print("World Data Read Error: Invalid Position String [" . $str . "]\n"); } return null; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php index d8d552dc4..f45e103d6 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php @@ -30,6 +30,14 @@ class UpdateEvent extends Event public function isTiming($type) { - return in_array(type, $this->updateTypes); + foreach ($this->updateTypes as $updateType) + { + if ($updateType->isTiming($type)) + { + return true; + } + } + + return false; } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php index ad92a0389..06c92c160 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php @@ -12,26 +12,45 @@ namespace mineplex\plugin\core\updater; class UpdateType { const M64 = 3840000; - conSt M32 = 1920000; - conSt M16 = 960000; - conSt M8 = 480000; - conSt M4 = 240000; - conSt M2 = 120000; - conSt M1 = 60000; - conSt S32 = 32000; - conSt S16 = 16000; - conSt S8 = 8000; - conSt S4 = 4000; - conSt S2 = 2000; - conSt S1 = 1000; - conSt MS500 = 500; - conSt MS250 = 250; - conSt MS125 = 125; + const M32 = 1920000; + const M16 = 960000; + const M8 = 480000; + const M4 = 240000; + const M2 = 120000; + const M1 = 60000; + const S32 = 32000; + const S16 = 16000; + const S8 = 8000; + const S4 = 4000; + const S2 = 2000; + const S1 = 1000; + const MS500 = 500; + const MS250 = 250; + const MS125 = 125; public $time; + private $lastTrigger = 0; + public function __construct($time=0) { $this->time = $time; } + + public function canTrigger() + { + if (round(microtime(true) * 1000) - $this->lastTrigger > $this->time) + { + $this->lastTrigger = round(microtime(true) * 1000); + return true; + } + + return false; + } + + public function isTiming($timing) + { + return $this->time === $timing; + } + } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php index 57089225b..9fd2d4735 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php @@ -8,13 +8,13 @@ namespace mineplex\plugin\core\updater; +use mineplex\plugin\core\updater\UpdateType; use pocketmine\plugin\PluginBase; use pocketmine\scheduler\PluginTask; class Updater extends PluginTask { private $plugin; - private $last; private $updateTypes; public function __construct(PluginBase $host) @@ -47,14 +47,13 @@ class Updater extends PluginTask { $updateTypes = array(); - $timeSpent = round(microtime(true) * 1000) - $this->last; - $this->last = round(microtime(true) * 1000); - - foreach ($this->updateTypes as &$updateType) { - if ($timeSpent >= $updateType->time) { - array_push($updateTypes, $updateType); - } - } + foreach ($this->updateTypes as &$updateType) + { + if ($updateType->canTrigger()) + { + array_push($updateTypes, $updateType); + } + } //Call Event $this->plugin->getServer()->getPluginManager()->callEvent(new UpdateEvent($currentTick, $updateTypes)); } From b8b12d7f170c3feece3bb140270596b00b83b1e3 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Sun, 5 Jul 2015 03:52:35 -0400 Subject: [PATCH 5/7] LobbyComponent.php added Signed-off-by: Aaron Brock --- .../Mineplex/src/mineplex/plugin/Main.php | 2 +- .../feature/GameStateFeatureManager.php | 11 +- .../feature/features/NoBlockBreak.php | 6 +- .../game/components/lobby/LobbyComponent.php | 161 ++++++++++++++++++ .../bench/game/games/sg/SurvivalGames.php | 9 +- 5 files changed, 176 insertions(+), 13 deletions(-) create mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php index fec53f2c5..4e8305fa4 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/Main.php @@ -32,7 +32,7 @@ class Main extends PluginBase implements Listener public function onLogin(PlayerLoginEvent $event) { if ($this->arena->canJoin($event->getPlayer())) - retun; + return; $event->setKickMessage("Unable to join game!"); $event->setCancelled(); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php index 6564c99fb..8bd247929 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/GameStateFeatureManager.php @@ -61,23 +61,20 @@ class GameStateFeatureManager implements Listener { else $theseFeatures = []; - - /** @var Feature[] $toEnable */ $toEnable = array_udiff($theseFeatures, $lastFeatures, array($this, 'comp')); /** @var Feature[] $toDisable */ $toDisable = array_udiff($lastFeatures, $theseFeatures, array($this, 'comp')); - foreach ($toEnable as $feature) { - if (!$feature->isEnabled()) - $feature->enable(); - } - foreach ($toDisable as $feature) { if ($feature->isEnabled()) $feature->disable(); } + foreach ($toEnable as $feature) { + if (!$feature->isEnabled()) + $feature->enable(); + } } public function onEnd(ArenaEndEvent $event) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php index 15344a34e..ed7398b0d 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/feature/features/NoBlockBreak.php @@ -17,13 +17,13 @@ use pocketmine\Server; class NoBlockBreak implements Feature, Listener { - /** @var Arena */ + /** @var Arena */ private $arena; - /** @var int[] */ + /** @var int[] */ private $ids = []; - /** @var bool */ + /** @var bool */ private $black; /** @var bool */ diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php new file mode 100644 index 000000000..044279afd --- /dev/null +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php @@ -0,0 +1,161 @@ +getDefaultLevel(); + + $world->setTime(6000); + $world->stopTime(); + + $this->worldName = $world->getName(); + + $this->arena = $arena; + $this->duringLobbyGameState = new DuringLobbyGameState($arena); + + Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); + } + + public function onBlockBreak(BlockBreakEvent $event) + { + if ($event->getBlock()->getLevel()->getName() != $this->worldName) + return; + $event->setCancelled(); + } + + + public function gameStateChange(GameStateChangeEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + + if ($event->getToGameState() == GameState::LOBBY) { + if (!$this->duringLobbyGameState->isEnabled()) + { + $this->duringLobbyGameState->enable(); + } + } + elseif ($event->getFromGameState() == GameState::LOBBY) + { + if ($this->duringLobbyGameState->isEnabled()) + { + $this->duringLobbyGameState->disable(); + } + } + + } + + public function onGameEnd(ArenaEndEvent $event) + { + if ($event->getArena() !== $this->arena) + return; + + HandlerList::unregisterAll($this); + if ($this->duringLobbyGameState->isEnabled()) + $this->duringLobbyGameState->disable(); + } +} + +class DuringLobbyGameState implements Feature, Listener { + + private $arena; + + /** @var bool */ + private $enabled = false; + + public function __construct(Arena $arena) + { + $this->arena = $arena; + } + + + function onDamage(EntityDamageEvent $event) + { + if (!in_array($event->getEntity(), $this->arena->getPlayers())) + return; + + $event->setCancelled(); + } + + function onDrop(PlayerDropItemEvent $event) + { + if (!in_array($event->getPlayer(), $this->arena->getPlayers())) + return; + $event->setCancelled(); + } + + function onPickUp(InventoryPickupItemEvent $event) + { + if (!in_array($event->getInventory()->getHolder(), $this->arena->getPlayers())) + return; + + $event->setCancelled(); + } + + function onBowShoot(EntityShootBowEvent $event) + { + if (!in_array($event->getEntity(), $this->arena->getPlayers())) + return; + + $event->setCancelled(); + } + + function isEnabled() + { + return $this->enabled; + } + + function enable() + { + Server::getInstance()->broadcastMessage("Enabled!"); + $this->enabled = true; + Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin()); + } + + function disable() + { + Server::getInstance()->broadcastMessage("Disabled!"); + $this->enabled = false; + HandlerList::unregisterAll($this); + } +} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php index 21066e32d..1f28552e1 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/games/sg/SurvivalGames.php @@ -13,6 +13,7 @@ use mineplex\plugin\bench\game\components\feature\features\NoBlockBreak; use mineplex\plugin\bench\game\components\feature\GameStateFeatureManager; use mineplex\plugin\bench\game\components\gamestate\GameState; use mineplex\plugin\bench\game\components\gamestate\GameStateComponent; +use mineplex\plugin\bench\game\components\lobby\LobbyComponent; use mineplex\plugin\bench\game\Game; use mineplex\plugin\bench\arenas\Arena; use mineplex\plugin\bench\game\components\feature\Feature; @@ -24,16 +25,20 @@ class SurvivalGames implements Game { { $gameStateComponent = new GameStateComponent($arena); - $noBlockBreak = new NoBlockBreak($arena, array(Item::GRASS)); + $noBlockBreak = new NoBlockBreak($arena); + $someBlockBreak = new NoBlockBreak($arena, array(Item::GRASS)); /** @var Feature[][] $features */ $features = array( GameState::LOBBY => array($noBlockBreak), GameState::PRE_GAME => array($noBlockBreak), + GameState::GAME => array($someBlockBreak), GameState::POST_GAME => array($noBlockBreak) ); - new GameStateFeatureManager($arena, $features); + new LobbyComponent($arena); + + //new GameStateFeatureManager($arena, $features); new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME); From 7b73f73561b7abbe85530a2abb35a2968f879139 Mon Sep 17 00:00:00 2001 From: Aaron Brock Date: Sun, 5 Jul 2015 03:58:46 -0400 Subject: [PATCH 6/7] Switched updateTypes to use the key instead of the value. Signed-off-by: Aaron Brock --- .../bench/game/components/lobby/LobbyComponent.php | 2 +- .../src/mineplex/plugin/core/updater/UpdateEvent.php | 10 +--------- .../src/mineplex/plugin/core/updater/Updater.php | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php index 044279afd..43a3941a4 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/bench/game/components/lobby/LobbyComponent.php @@ -41,7 +41,7 @@ class LobbyComponent implements Listener { */ public function __construct(Arena $arena, $world = null) { - + if ($world == null) $world = Server::getInstance()->getDefaultLevel(); diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php index f45e103d6..942455136 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php @@ -30,14 +30,6 @@ class UpdateEvent extends Event public function isTiming($type) { - foreach ($this->updateTypes as $updateType) - { - if ($updateType->isTiming($type)) - { - return true; - } - } - - return false; + return (isset($this->updateTypes[$type]) || array_key_exists($type, $this->updateTypes)); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php index 9fd2d4735..d843920fc 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php @@ -51,7 +51,7 @@ class Updater extends PluginTask { if ($updateType->canTrigger()) { - array_push($updateTypes, $updateType); + $updateTypes[$updateType] = 1; } } //Call Event From abaa0ddee88c35f299fe8a341d4912858170ba0b Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sun, 5 Jul 2015 13:30:16 -0500 Subject: [PATCH 7/7] Level for Bobby --- Plugins/.idea/compiler.xml | 1 + .../src/mineplex/core/achievement/AchievementManager.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Plugins/.idea/compiler.xml b/Plugins/.idea/compiler.xml index ccd5607c1..2e4d3e99b 100644 --- a/Plugins/.idea/compiler.xml +++ b/Plugins/.idea/compiler.xml @@ -4,6 +4,7 @@