Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-13 07:02:33 -04:00
parent 7377094e86
commit d5a144f377
20 changed files with 573 additions and 78 deletions

View File

@ -6,6 +6,9 @@ use mineplex\plugin\gameengine\arenas\MultiGameArena;
use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\game\factory\TestGameFactory; use mineplex\plugin\gameengine\game\factory\TestGameFactory;
use mineplex\plugin\core\updater\Updater; use mineplex\plugin\core\updater\Updater;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use mineplex\plugin\util\UtilFile; use mineplex\plugin\util\UtilFile;
use mineplex\plugin\util\UtilString; use mineplex\plugin\util\UtilString;
use pocketmine\block\Block; use pocketmine\block\Block;
@ -23,19 +26,16 @@ use pocketmine\plugin\PluginBase;
use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\Server; use pocketmine\Server;
class Main extends PluginBase implements Listener class Main extends PluginBase implements Listener, BenchTask
{ {
/** @var Arena */ /** @var Arena */
private $arena; private $arena;
private $test;
public function onEnable() public function onEnable()
{ {
$this->arena = new MultiGameArena($this, new TestGameFactory()); $this->arena = new MultiGameArena($this, new TestGameFactory());
Server::getInstance()->getPluginManager()->registerEvents($this, $this); Server::getInstance()->getPluginManager()->registerEvents($this, $this);
//$this->test = new WorldComponent($this->arena);
new Updater($this); new Updater($this);
$this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0)); $this->arena->getPlugin()->getServer()->getLevelByName("world")->setSpawnLocation(new Vector3(0, 200, 0));
@ -44,8 +44,6 @@ class Main extends PluginBase implements Listener
public function onLogin(PlayerLoginEvent $event) public function onLogin(PlayerLoginEvent $event)
{ {
//UtilFile::deleteDir('players/' . $event->getPlayer()->getName() . '.dat');
if ($this->arena->canJoin($event->getPlayer())) if ($this->arena->canJoin($event->getPlayer()))
return; return;
@ -53,34 +51,42 @@ class Main extends PluginBase implements Listener
$event->setCancelled(); $event->setCancelled();
} }
//This is a hack to allow people to teleport a player when the join... I know it's scurry D:
public function onJoin(PlayerJoinEvent $event) public function onJoin(PlayerJoinEvent $event)
{ {
$this->arena->addPlayer($event->getPlayer()); BenchSchedule::runTaskLaterWithId($this, 0, $event->getPlayer());
} }
public function punch(PlayerInteractEvent $event) function run(BenchTaskData $task)
{ {
if ($event->getAction() == PlayerInteractEvent::LEFT_CLICK_BLOCK || $event->getAction() == PlayerInteractEvent::RIGHT_CLICK_BLOCK) if (!($task->getId() instanceof Player))
{ return;
$event->getPlayer()->sendMessage("Block: " . $event->getBlock()->getId() . ":" . $event->getBlock()->getDamage());
} /** @var Player $player */
$player = $task->getId();
if (!$player->isConnected())
return;
$this->arena->addPlayer($player);
} }
public function command(PlayerCommandPreprocessEvent $event) public function command(PlayerCommandPreprocessEvent $event)
{ {
if (UtilString::startsWith($event->getMessage(), "/pos")) if (UtilString::startsWith($event->getMessage(), "/pos"))
self::sendLoc($event->getPlayer()); self::sendLoc($event->getPlayer());
} }
public static function sendLoc(Player $player) public static function sendLoc(Player $player, Position $pos = null)
{ {
$pos = $player->getLocation(); if ($pos == null)
$pos = $player->getLocation();
$player->sendMessage("X: " . $pos->getX()); $player->sendMessage("X: " . $pos->getX());
$player->sendMessage("Y: " . $pos->getY()); $player->sendMessage("Y: " . $pos->getY());
$player->sendMessage("Z: " . $pos->getZ()); $player->sendMessage("Z: " . $pos->getZ());
$player->sendMessage("Level: " . $pos->getLevel()->getName()); $player->sendMessage("Level: " . $pos->getLevel()->getName());
} }
} }

View File

@ -90,7 +90,7 @@ class GameStateCountdown implements Listener, BenchTask {
{ {
foreach ($this->arena->getPlayers() as $player) foreach ($this->arena->getPlayers() as $player)
{ {
$player->sendPopup("Countdown: $this->count"); $player->sendTip("Countdown: $this->count");
} }
} }

View File

@ -29,6 +29,7 @@ class LobbyCountdown implements Listener, BenchTask {
private $startCount; private $startCount;
private $count; private $count;
private $gameStateComponent; private $gameStateComponent;
/** @var WorldComponent */
private $worldComponent; private $worldComponent;
private $arena; private $arena;
private $startGameState; private $startGameState;
@ -41,7 +42,7 @@ class LobbyCountdown implements Listener, BenchTask {
const COUNTDOWN_ID = "count"; const COUNTDOWN_ID = "count";
public function __construct(Arena $arena, GameStateComponent $gameStateComponent, WorldComponent $worldComponent = null, $startGameState, $setGameState, $count, $minPlayers = 2) public function __construct(Arena $arena, GameStateComponent $gameStateComponent, $worldComponent = null, $startGameState, $setGameState, $count, $minPlayers = 2)
{ {
$this->arena = $arena; $this->arena = $arena;
$this->gameStateComponent = $gameStateComponent; $this->gameStateComponent = $gameStateComponent;
@ -184,6 +185,6 @@ class LobbyCountdown implements Listener, BenchTask {
private function popup(Player $player) private function popup(Player $player)
{ {
$player->sendPopup($this->message); $player->sendTip($this->message);
} }
} }

View File

@ -28,7 +28,6 @@ class FreezePlayers extends ListenerFeature {
function onMove(PlayerMoveEvent $event) function onMove(PlayerMoveEvent $event)
{ {
if (!$this->hasPlayer($event->getPlayer())) if (!$this->hasPlayer($event->getPlayer()))
return; return;
@ -41,13 +40,17 @@ class FreezePlayers extends ListenerFeature {
parent::enable(); parent::enable();
$effect = new Effect(Effect::SLOWNESS, "Waiting till game start...", 0, 0, 0, true); $effect = new Effect(Effect::SLOWNESS, "Waiting till game start...", 0, 0, 0, true);
$effect->setVisible(false)->setAmplifier(9)->setDuration(PHP_INT_MAX); //TODO fix the 429496729
$effect->setVisible(false)->setAmplifier(9)->setDuration(429496729);
print "Player Count: " . count($this->getPlayers()) . "\n"; print "Player Count: " . count($this->getPlayers()) . "\n";
foreach ($this->getPlayers() as $player) foreach ($this->getPlayers() as $player)
{ {
print "Adding effect! \n"; print "Adding effect!\n";
$player->addEffect($effect); $player->addEffect($effect);
} }
} }
public function disable() public function disable()
@ -56,7 +59,7 @@ class FreezePlayers extends ListenerFeature {
print "Player Count: " . count($this->getPlayers()) . "\n"; print "Player Count: " . count($this->getPlayers()) . "\n";
foreach ($this->getPlayers() as $player) foreach ($this->getPlayers() as $player)
{ {
print "Adding effect! \n"; print "Remove effect! \n";
$player->removeEffect(Effect::SLOWNESS); $player->removeEffect(Effect::SLOWNESS);
} }
} }

View File

@ -19,13 +19,10 @@ class JoinSpectate extends ListenerFeature {
private $spectateComponent; private $spectateComponent;
private $id;
function __construct(Arena $arena, SpectateComponent $spectateComponent) function __construct(Arena $arena, SpectateComponent $spectateComponent)
{ {
parent::__construct($arena); parent::__construct($arena);
$this->spectateComponent = $spectateComponent; $this->spectateComponent = $spectateComponent;
$this->id = rand(0, 99999);
} }
function onJoin(ArenaJoinEvent $event) function onJoin(ArenaJoinEvent $event)
@ -36,14 +33,11 @@ class JoinSpectate extends ListenerFeature {
} }
public function enable() public function enable()
{ {
Server::getInstance()->broadcastMessage("JoinSpectate enable! : $this->id");
parent::enable(); parent::enable();
print "JoinSpectate enable? " . ($this->isEnabled() ? 'true' : 'false') . "\n";
} }
public function disable() public function disable()
{ {
Server::getInstance()->broadcastMessage("JoinSpectate disable!");
parent::disable(); parent::disable();
} }

View File

@ -25,6 +25,7 @@ class NoDamage extends ListenerFeature {
{ {
if (!$this->getArena()->hasPlayer($event->getEntity())) if (!$this->getArena()->hasPlayer($event->getEntity()))
return; return;
//Server::getInstance()->broadcastMessage("Stopped!"); //Server::getInstance()->broadcastMessage("Stopped!");
$event->setCancelled(); $event->setCancelled();
} }

View File

@ -0,0 +1,56 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/12/2015
* Time: 12:41 AM
*/
namespace mineplex\plugin\gameengine\game\components\feature\features;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaJoinEvent;
use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\spectate\events\EnableSpectateEvent;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\util\UtilTeleport;
use pocketmine\block\Thin;
class SpectateInGameWorld extends ListenerFeature {
private $worldComponent;
/**
* @param Arena $arena
* @param WorldComponent $worldComponent
* @param SpectateComponent $spectateComponent just here to make sure that there is a SpectateComponent
*/
function __construct(Arena $arena, WorldComponent $worldComponent, SpectateComponent $spectateComponent)
{
parent::__construct($arena);
$this->worldComponent = $worldComponent;
}
function onJoin(EnableSpectateEvent $event)
{
if ($this->getArena() !== $event->getArena() || !$this->worldComponent->isWorldReady())
return;
if ($event->getPlayer()->getPosition()->getLevel() == $this->worldComponent->getWorld())
return;
UtilTeleport::teleport($event->getPlayer(), $this->worldComponent->getWorld()->getSpawnLocation());
}
public function enable()
{
parent::enable();
}
public function disable()
{
parent::disable();
}
}

View File

@ -15,6 +15,8 @@ use mineplex\plugin\gameengine\game\components\feature\ListenerFeature;
use mineplex\plugin\gameengine\game\components\feature\UtilFeature; use mineplex\plugin\gameengine\game\components\feature\UtilFeature;
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent; use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
use mineplex\plugin\gameengine\game\components\gamestate\GameState; use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\time\BenchTaskData;
use mineplex\plugin\Main;
use mineplex\plugin\util\UtilTeleport; use mineplex\plugin\util\UtilTeleport;
use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
@ -40,6 +42,7 @@ class LobbyComponent implements Listener
private $duringLobbyGameState; private $duringLobbyGameState;
private $spawn;
/** /**
* @param Arena $arena * @param Arena $arena
* @param Level $world * @param Level $world
@ -51,16 +54,18 @@ class LobbyComponent implements Listener
$world->setTime(6000); $world->setTime(6000);
$world->stopTime(); $world->stopTime();
$world->setSpawnLocation(new Vector3(0, 103, 0));
$this->world = $world; $this->world = $world;
$this->spawn = new Position(0, 103, 0, $world);
$this->arena = $arena; $this->arena = $arena;
$this->duringLobbyGameState = new DuringLobbyGameState($this); $this->duringLobbyGameState = new DuringLobbyGameState($this);
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
} }
function sendToSpawn(Player $player) function sendToSpawn(Player $player)
{ {
$player->getInventory()->clearAll(); $player->getInventory()->clearAll();
@ -70,9 +75,12 @@ class LobbyComponent implements Listener
$player->setHealth($player->getMaxHealth()); $player->setHealth($player->getMaxHealth());
$player->resetFallDistance(); $player->resetFallDistance();
$pos = $this->world->getSpawnLocation()->add(rand(-4, 4), 0, rand(-4, 4)); //Main::sendLoc($player, $this->world->getSpawnLocation());
$pos = $this->spawn->add(rand(-4, 4), 0, rand(-4, 4));
UtilTeleport::teleport($player, new Position($pos->getX(), $pos->getY(), $pos->getZ(), $this->world)); UtilTeleport::teleport($player, new Position($pos->getX(), $pos->getY(), $pos->getZ(), $this->world));
//Main::sendLoc($player);
} }
@ -85,7 +93,7 @@ class LobbyComponent implements Listener
function onDamage(EntityDamageEvent $event) function onDamage(EntityDamageEvent $event)
{ {
if (!$event->getEntity()->getLevel() == $this->world) if ($event->getEntity()->getLevel() !== $this->world)
return; return;
$event->setCancelled(); $event->setCancelled();
} }

View File

@ -11,6 +11,7 @@ namespace mineplex\plugin\gameengine\game\components\spawn;
use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent; use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\game\components\spectate\SpectateComponent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\Main; use mineplex\plugin\Main;
@ -27,15 +28,17 @@ class SimpleSpawnComponent implements SpawnComponent, Listener {
private $arena; private $arena;
private $worldComponent; private $worldComponent;
private $gameMode; private $gameMode;
private $spectateComponent;
/** @var Position[] */ /** @var Position[] */
private $spawns = []; private $spawns = [];
function __construct(Arena $arena, WorldComponent $worldComponent, $gameMode = Player::SURVIVAL) function __construct(Arena $arena, WorldComponent $worldComponent, SpectateComponent $spectateComponent = null, $gameMode = Player::SURVIVAL)
{ {
$this->arena = $arena; $this->arena = $arena;
$this->worldComponent = $worldComponent; $this->worldComponent = $worldComponent;
$this->gameMode = $gameMode; $this->gameMode = $gameMode;
$this->spectateComponent = $spectateComponent;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin()); Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
} }
@ -67,12 +70,6 @@ class SimpleSpawnComponent implements SpawnComponent, Listener {
function respawn(Player $player) function respawn(Player $player)
{ {
if (count($this->spawns) < 1)
{
print "no spawns!";
return;
}
/* /*
$player->getInventory()->clearAll(); $player->getInventory()->clearAll();
$player->removeAllEffects(); $player->removeAllEffects();
@ -80,21 +77,53 @@ class SimpleSpawnComponent implements SpawnComponent, Listener {
$player->setGamemode($this->gameMode); $player->setGamemode($this->gameMode);
$player->setHealth($player->getMaxHealth()); $player->setHealth($player->getMaxHealth());
*/ */
$player->sendMessage("Before:");
Main::sendLoc($player);
$pos = $this->spawns[array_rand($this->spawns)]; $pos = $this->getSpawn();
//$pos = $pos->getLevel()->getSpawnLocation();
print_r($pos);
UtilTeleport::teleport($player, $pos); UtilTeleport::teleport($player, $pos);
//$player->teleport($pos);
$player->sendMessage("After:");
Main::sendLoc($player);
return $pos; return $pos;
} }
/**
* @return null|Position
*/
function getSpawn()
{
if (count($this->spawns) < 1)
{
print "no spawns!";
return null;
}
/** @var Position $best */
$best = null;
$bestDist = 0;
foreach ($this->spawns as $spawn)
{
$closestPlayer = -1;
foreach ($this->getPlayers() as $player)
{
if ($player->getPosition()->getLevel() != $spawn->getLevel())
continue;
//distanceSquared is a cheaper method, and as long as its consistent it will be fine
$playerDist = $spawn->distanceSquared($player->getPosition());
if ($playerDist < $closestPlayer || $closestPlayer < 0)
{
$closestPlayer = $playerDist;
}
}
if ($best == null || $closestPlayer > $bestDist)
{
$best = $spawn;
$bestDist = $closestPlayer;
}
}
return $best;
}
function respawnAll() { function respawnAll() {
foreach ($this->arena->getPlayers() as $player) foreach ($this->arena->getPlayers() as $player)
{ {
@ -108,4 +137,13 @@ class SimpleSpawnComponent implements SpawnComponent, Listener {
return; return;
HandlerList::unregisterAll($this); HandlerList::unregisterAll($this);
} }
function getPlayers()
{
if ($this->spectateComponent != null)
return $this->spectateComponent->getNonSpectators();
else
return $this->arena->getPlayers();
}
} }

View File

@ -8,13 +8,13 @@
namespace mineplex\plugin\gameengine\game\components\spectate\events; namespace mineplex\plugin\gameengine\game\components\spectate\events;
use mineplex\plugin\gameengine\arenas\ArenaEvent; use mineplex\plugin\gameengine\arenas\ArenaEvent;
use mineplex\plugin\gameengine\arenas\Arena; use mineplex\plugin\gameengine\arenas\Arena;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
use pocketmine\Player; use pocketmine\Player;
class EnableSpectateEvent extends ArenaEvent implements Cancellable { class EnableSpectateEvent extends ArenaEvent implements Cancellable {
public static $handlerList = null; public static $handlerList = null;
private $player; private $player;

View File

@ -0,0 +1,78 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/13/2015
* Time: 5:55 AM
*/
namespace mineplex\plugin\gameengine\game\components\team;
use mineplex\plugin\util\UtilArray;
use pocketmine\Player;
class SimpleTeam implements Team {
/** @var Player[] */
private $players = [];
private $name;
private $color;
/**
* @param string $name
* @param string $color
*/
function __construct($name, $color)
{
$this->name = $name;
$this->color = $color;
}
function addPlayer_forUseByManagerOnly(Player $player)
{
$this->players[$player->getName()] = $player;
$player->sendMessage("$this->color You are now on the team $this->name!");
}
function removePlayer_forUseByManagerOnly(Player $player)
{
if ($this->hasPlayer($player))
unset ($this->players[$player->getName()]);
}
/**
* @return Player[]
*/
function getPlayers()
{
return $this->players;
}
/**
* @param Player $player
* @return bool
*/
function hasPlayer(Player $player)
{
return UtilArray::hasKey($player->getName(), $this->players);
}
/**
* @return string
*/
function getName()
{
$this->name;
}
/**
* @return string
*/
function getColor()
{
$this->color;
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/13/2015
* Time: 5:04 AM
*/
namespace mineplex\plugin\gameengine\game\components\team;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\util\UtilArray;
use pocketmine\Player;
use InvalidArgumentException;
class SimpleTeamManager implements TeamManager {
private $arena;
/** @var Team[] */
private $teams = [];
/**
* @param Arena $arena
* @param Team[] $teams
*/
function __construct(Arena $arena, array $teams = [])
{
$this->arena = $arena;
foreach ($teams as $team)
{
$this->addTeam($team);
}
}
function addTeam(Team $team)
{
$this->teams[$team->getName()] = $team;
}
/**
* @param String $name
* @return Team|null
*/
function getTeam($name)
{
if (UtilArray::hasKey($name, $this->teams))
{
return $this->teams[$name];
}
return null;
}
/**
* @return Team[]
*/
function getTeams()
{
return $this->teams;
}
/**
* @param Player $player
* @return Team|null
*/
function getPlayersTeam(Player $player)
{
foreach ($this->getTeams() as $team)
{
if ($team->hasPlayer($player))
return $team;
}
return null;
}
function setPlayersTeam(Player $player, Team $team)
{
$oldTeam = $this->getPlayersTeam($player);
if ($oldTeam != null)
{
$oldTeam->removePlayer_forUseByManagerOnly($player);
}
//Meh, why not?
if (!in_array($team, $this->teams))
{
throw new InvalidArgumentException('The team giving is not known by this manager!');
}
$team->addPlayer_forUseByManagerOnly($player);
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/13/2015
* Time: 3:56 AM
*/
namespace mineplex\plugin\gameengine\game\components\team;
use pocketmine\Player;
interface Team {
function addPlayer_forUseByManagerOnly(Player $player);
function removePlayer_forUseByManagerOnly(Player $player);
/**
* @return Player[]
*/
function getPlayers();
/**
* @param Player $player
* @return bool
*/
function hasPlayer(Player $player);
/**
* @return string
*/
function getName();
/**
* @return string
*/
function getColor();
}

View File

@ -0,0 +1,61 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/13/2015
* Time: 6:21 AM
*/
namespace mineplex\plugin\gameengine\game\components\team;
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 pocketmine\event\HandlerList;
use pocketmine\event\Listener;
use pocketmine\Server;
class TeamDealer implements Listener {
private $arena;
private $teamManager;
function __construct(Arena $arena, TeamManager $teamManager)
{
$this->arena = $arena;
$this->teamManager = $teamManager;
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
}
public function gameState(GameStateChangeEvent $event)
{
if ($event->getArena() != $this->arena)
return;
if ($event->getToGameState() == GameState::PRE_GAME)
$this->deal();
}
function deal()
{
$teams = array_values($this->teamManager->getTeams());
$counter = 0;
foreach ($this->arena->getPlayers() as $player)
{
Server::getInstance()->broadcastMessage($counter % count($teams));
$this->teamManager->setPlayersTeam($player, $teams[$counter % count($teams)]);
$counter++;
}
}
function gameEnd(ArenaEndEvent $event)
{
if ($event->getArena() != $this->arena)
return;
HandlerList::unregisterAll($this);
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/13/2015
* Time: 4:41 AM
*/
namespace mineplex\plugin\gameengine\game\components\team;
use pocketmine\Player;
interface TeamManager {
/**
* @param String $name
* @return Team|null
*/
function getTeam($name);
/**
* @return Team[]
*/
function getTeams();
/**
* @param Player $player
* @return Team|null
*/
function getPlayersTeam(Player $player);
function setPlayersTeam(Player $player, Team $team);
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/12/2015
* Time: 9:25 PM
*/
namespace mineplex\plugin\gameengine\game\components\world;
use mineplex\plugin\gameengine\arenas\Arena;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
//This is a simple fix for Chiss' allergies to Night time
class TimeComponent {
private $arena;
private $worldComponent;
private $time;
/**
* @param Arena $arena
* @param WorldComponent $worldComponent
* @param int $time
*/
function __construct(Arena $arena, WorldComponent $worldComponent, $time = 6000)
{
$this->arena = $arena;
$this->worldComponent = $worldComponent;
$this->time = $time;
}
public function onWorld(WorldLoadSuccessEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$event->getLevel()->setTime($this->time);
$event->getLevel()->stopTime();
}
}

View File

@ -13,6 +13,9 @@ use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent; use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent;
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
use mineplex\plugin\gameengine\time\BenchSchedule;
use mineplex\plugin\gameengine\time\BenchTask;
use mineplex\plugin\gameengine\time\BenchTaskData;
use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilArray;
use mineplex\plugin\util\UtilString; use mineplex\plugin\util\UtilString;
use mineplex\plugin\util\UtilFile; use mineplex\plugin\util\UtilFile;
@ -26,7 +29,7 @@ use pocketmine\Server;
use ZipArchive; use ZipArchive;
use Exception; use Exception;
class WorldComponent implements Listener class WorldComponent implements Listener, BenchTask
{ {
private $arena; private $arena;
@ -34,7 +37,7 @@ class WorldComponent implements Listener
private $worldNameFolder; private $worldNameFolder;
/** @var \pocketmine\level\Level */ /** @var \pocketmine\level\Level */
private $world; private $world = null;
private $mapName; private $mapName;
private $mapAuthor; private $mapAuthor;
@ -58,7 +61,7 @@ class WorldComponent implements Listener
{ {
if ($this->arena !== $event->getArena()) if ($this->arena !== $event->getArena())
return; return;
$this->loadWorld("Super Smash Mobs"); $this->loadWorld("Survival Games");
} }
private function unloadWorld() private function unloadWorld()
@ -305,6 +308,17 @@ class WorldComponent implements Listener
if ($this->arena !== $event->getArena()) if ($this->arena !== $event->getArena())
return; return;
HandlerList::unregisterAll($this); HandlerList::unregisterAll($this);
BenchSchedule::runTaskLater($this, (1000 * 10));
}
public function run(BenchTaskData $bench)
{
$this->unloadWorld();
}
public function getWorld()
{
return $this->world;
} }
} }

View File

@ -18,6 +18,7 @@ use mineplex\plugin\gameengine\game\components\feature\features\NoBlockPlace;
use mineplex\plugin\gameengine\game\components\feature\features\NoDamage; use mineplex\plugin\gameengine\game\components\feature\features\NoDamage;
use mineplex\plugin\gameengine\game\components\feature\features\NoDropItem; 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\features\NoPickUpItem;
use mineplex\plugin\gameengine\game\components\feature\features\SpectateInGameWorld;
use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager; use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeatureManager;
use mineplex\plugin\gameengine\game\components\gamestate\GameState; use mineplex\plugin\gameengine\game\components\gamestate\GameState;
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent; use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
@ -25,11 +26,16 @@ use mineplex\plugin\gameengine\game\components\lobby\LobbyComponent;
use mineplex\plugin\gameengine\game\components\spawn\SimpleSpawnComponent; use mineplex\plugin\gameengine\game\components\spawn\SimpleSpawnComponent;
use mineplex\plugin\gameengine\game\components\spawn\SpawnAt; use mineplex\plugin\gameengine\game\components\spawn\SpawnAt;
use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent; use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent;
use mineplex\plugin\gameengine\game\components\team\SimpleTeam;
use mineplex\plugin\gameengine\game\components\team\SimpleTeamManager;
use mineplex\plugin\gameengine\game\components\team\TeamDealer;
use mineplex\plugin\gameengine\game\components\world\TimeComponent;
use mineplex\plugin\gameengine\game\components\world\WorldComponent; use mineplex\plugin\gameengine\game\components\world\WorldComponent;
use mineplex\plugin\gameengine\game\Game; use mineplex\plugin\gameengine\game\Game;
use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown; use mineplex\plugin\gameengine\game\components\countdown\LobbyCountdown;
use mineplex\plugin\gameengine\game\components\feature\Feature; use mineplex\plugin\gameengine\game\components\feature\Feature;
use mineplex\plugin\gameengine\game\components\victorytype\LMSVictoryType; use mineplex\plugin\gameengine\game\components\victorytype\LMSVictoryType;
class SurvivalGames implements Game { class SurvivalGames implements Game {
function start(Arena $arena) function start(Arena $arena)
@ -40,11 +46,21 @@ class SurvivalGames implements Game {
$worldComponent = new WorldComponent($arena); $worldComponent = new WorldComponent($arena);
$teamManager = new SimpleTeamManager($arena, [new SimpleTeam('Bench', '§6'), new SimpleTeam('Not Bench', '§b')]);
new TeamDealer($arena, $teamManager);
new LobbyComponent($arena); new LobbyComponent($arena);
new TimeComponent($arena, $worldComponent);
//Features start---- //Features start----
$noDamage = new NoDamage($arena); $noDamage = new NoDamage($arena);
$joinSpectate = new JoinSpectate($arena, $spectateComponent);
$joinSpectate = [new JoinSpectate($arena, $spectateComponent), new SpectateInGameWorld($arena, $worldComponent, $spectateComponent)];
$stopEveryThing = array(new NoBlockBreak($arena), new NoBlockPlace($arena),new NoDropItem($arena), new NoPickUpItem($arena)); $stopEveryThing = array(new NoBlockBreak($arena), new NoBlockPlace($arena),new NoDropItem($arena), new NoPickUpItem($arena));
@ -68,11 +84,11 @@ class SurvivalGames implements Game {
new LobbyCountdown( $arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 2); new LobbyCountdown( $arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 2);
//new GameStateCountdown($arena, $gameStateComponent, 5, GameState::LOBBY, GameState::PRE_GAME);
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::PRE_GAME, GameState::GAME); new GameStateCountdown($arena, $gameStateComponent, 20, GameState::PRE_GAME, GameState::GAME);
//new GameStateCountdown($arena, $gameStateComponent, 5, GameState::GAME, GameState::POST_GAME);
new LMSVictoryType( $arena, $spectateComponent, $gameStateComponent); new LMSVictoryType( $arena, $spectateComponent, $gameStateComponent);
new GameStateCountdown($arena, $gameStateComponent, 5, GameState::POST_GAME, GameState::RESTARTING); new GameStateCountdown($arena, $gameStateComponent, 5, GameState::POST_GAME, GameState::RESTARTING);

View File

@ -20,28 +20,34 @@ use pocketmine\network\protocol\UpdateBlockPacket;
class UtilTeleport { class UtilTeleport {
public static function teleport(Player $player, Position $position) { /**
* @param Player $player
* @param Vector3|Position $pos
*/
public static function teleport(Player $player, Vector3 $pos)
{
if ($pos instanceof Position)
{
$current = $player->getPosition();
//
// This CRAZY HACK is to remove Tile entities that seem to linger
// whenever you teleport!
//
$current = $player->getPosition(); if ($current->getLevel() != $pos->getLevel()) {
$player->noDamageTicks = 20;
// foreach ($current->getLevel()->getTiles() as $tile) {
// This CRAZY HACK is to remove Tile entities that seem to linger $pk = new UpdateBlockPacket();
// whenever you teleport! $pk->x = $tile->x;
// $pk->y = $tile->y;
$pk->z = $tile->z;
if ($current->getLevel() != $position->getLevel()) { $pk->block = 0;
$player->noDamageTicks = 20; $pk->meta = 0;
foreach ($current->getLevel()->getTiles() as $tile) { $player->dataPacket($pk);
$pk = new UpdateBlockPacket(); }
$pk->x = $tile->x;
$pk->y = $tile->y;
$pk->z = $tile->z;
$pk->block = 0;
$pk->meta = 0;
$player->dataPacket($pk);
} }
} }
$player->teleport($position); // Start the teleport
return true; $player->teleport($pos);
} }
} }

View File

@ -1,6 +1,6 @@
#Properties Config file #Properties Config file
#Sat Jul 11 00:36:33 ACT 2015 #Mon Jul 13 05:54:15 ACT 2015
motd=Minecraft: PE Server motd=Box
server-port=19132 server-port=19132
memory-limit=-1 memory-limit=-1
white-list=off white-list=off
@ -13,7 +13,7 @@ spawn-mobs=off
gamemode=0 gamemode=0
force-gamemode=off force-gamemode=off
hardcore=off hardcore=off
pvp=off pvp=on
difficulty=1 difficulty=1
generator-settings= generator-settings=
level-name=world level-name=world