world component for MCPE

This commit is contained in:
Cheese 2015-07-05 15:13:18 +10:00
parent 514fe4a18a
commit 8d2b1650af
2 changed files with 211 additions and 1 deletions

View File

@ -31,7 +31,7 @@ public class BenefitManager extends MiniDbClientPlugin<BenefitData>
//_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)

View File

@ -0,0 +1,210 @@
<?php
/**
* Created by PhpStorm.
* User: C
* Date: 5/07/2015
* Time: 12:27 PM
*/
namespace mineplex\plugin\bench\game\components\world;
use mineplex\plugin\bench\arenas\Arena;
use pocketmine\event\Listener;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\Server;
//require_once __DIR__ . '\GameState.php';
class WorldComponent implements Listener
{
private $arena;
private $gameId;
private $gameFolder;
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;
public function __construct(Arena $arena)
{
$this->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
}
}