Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex

This commit is contained in:
libraryaddict 2015-07-08 10:24:59 +12:00
commit 2ad2c20aaf
13 changed files with 349 additions and 103 deletions

View File

@ -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:

View File

@ -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);
print_r($a1);

View File

@ -6,12 +6,18 @@ 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;
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;
@ -30,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;
@ -45,4 +55,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());
}
}

View File

@ -83,7 +83,6 @@ class MultiGameArena implements Arena, Listener
Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this));
}
public function getPlayers()
{
return $this->players;

View File

@ -48,7 +48,7 @@ class NoPickUpItem extends ListenerFeature {
Server::getInstance()->broadcastMessage("Stopped!");
} else
Server::getInstance()->broadcastMessage("Not Stopped!");
}

View File

@ -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());
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 10:32 PM
*/
namespace mineplex\plugin\gameengine\game\components\spawn;
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\Player;
use pocketmine\Server;
class SimpleSpawnComponent implements SpawnComponent, Listener {
private $arena;
private $worldComponent;
private $gameMode;
/** @var Position[] */
private $spawns = [];
function __construct(Arena $arena, WorldComponent $worldComponent, $gameMode = Player::SURVIVAL)
{
$this->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 = $this->worldComponent->getTeams()['Green'];
// $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");
}
/**
* @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());
*/
$player->sendMessage("Before:");
Main::sendLoc($player);
$pos = $this->spawns[array_rand($this->spawns)];
//$pos = $pos->getLevel()->getSpawnLocation();
print_r($pos);
$player->teleport($pos);
$player->sendMessage("After:");
Main::sendLoc($player);
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);
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/6/2015
* Time: 10:47 PM
*/
namespace mineplex\plugin\gameengine\game\components\spawn;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
class SpawnAt implements Listener {
private $spawnComponent;
private $arena;
private $gameStates;
function __construct(Arena $arena, SpawnComponent $spawnComponent, array $gameStates)
{
$this->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);
}
}

View File

@ -19,4 +19,6 @@ interface SpawnComponent {
*/
function respawn(Player $player);
function respawnAll();
}

View File

@ -9,9 +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;
@ -25,8 +30,9 @@ class WorldComponent implements Listener
private $arena;
private $gameId;
private $gameFolder;
private $worldNameFolder;
/** @var \pocketmine\level\Level */
private $world;
private $mapName;
@ -45,30 +51,31 @@ class WorldComponent implements Listener
$this->gameId = $this->getNewGameId();
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function onStart(ArenaStartEvent $event)
{
if ($this->arena !== $event->getArena())
return;
$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;
// }
// }
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)
{
@ -91,20 +98,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));
@ -112,23 +119,23 @@ 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));
$this->world->setTime(6000);
$this->loadWorldData();
$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));
@ -138,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
@ -148,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)
{
@ -231,27 +240,35 @@ 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];
public function getPosition()
{
return $this->getTeams()[0][0];
return [];
}
protected function strToPos($str)
{
if (strlen($str) < 5)
@ -281,5 +298,12 @@ class WorldComponent implements Listener
{
return $this->ready;
}
public function onEnd(ArenaEndEvent $event)
{
if ($this->arena !== $event->getArena())
return;
HandlerList::unregisterAll($this);
}
}

View File

@ -19,51 +19,57 @@ 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;
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);
$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)
);
//$features = array(
// GameState::LOBBY => array($noPickUpItem, $pack)
//);
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, 1);
$spawnComponent = new SimpleSpawnComponent($arena, $worldComponent);
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]);
new GameStateCountdown($arena, $gameStateComponent, 60, GameState::GAME, GameState::POST_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, 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);
*/
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace mineplex\plugin\util;
class UtilFile
{
public static function deleteDir($dirPath)
{
if (! is_dir($dirPath))
{
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
{
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file)
{
if (is_dir($file))
{
self::deleteDir($file);
}
else
{
unlink($file);
}
}
rmdir($dirPath);
}
}