Edited some things
This commit is contained in:
parent
2c249e37b5
commit
bac505f2cd
@ -9,6 +9,8 @@ use mineplex\plugin\core\updater\Updater;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\event\player\PlayerJoinEvent;
|
||||
use pocketmine\event\player\PlayerLoginEvent;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use pocketmine\Server;
|
||||
@ -24,9 +26,7 @@ class Main extends PluginBase implements Listener
|
||||
$this->arena = new MultiGameArena($this, new TestGameFactory());
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this);
|
||||
|
||||
$this->test = new WorldComponent($this->arena);
|
||||
|
||||
//$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
//$this->test = new WorldComponent($this->arena);
|
||||
|
||||
new Updater($this);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace mineplex\plugin\bench\game\components\lobby;
|
||||
|
||||
use mineplex\plugin\bench\arenas\Arena;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\bench\arenas\events\ArenaJoinEvent;
|
||||
use mineplex\plugin\bench\game\components\feature\Feature;
|
||||
use mineplex\plugin\bench\game\components\gamestate\events\GameStateChangeEvent;
|
||||
use mineplex\plugin\bench\game\components\gamestate\GameState;
|
||||
@ -21,17 +22,20 @@ use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\inventory\InventoryPickupItemEvent;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\event\player\PlayerDropItemEvent;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class LobbyComponent implements Listener {
|
||||
class LobbyComponent implements Listener
|
||||
{
|
||||
|
||||
|
||||
/** @var Arena */
|
||||
private $arena;
|
||||
|
||||
/** @var String */
|
||||
private $worldName;
|
||||
public $worldName;
|
||||
|
||||
private $duringLobbyGameState;
|
||||
|
||||
@ -41,7 +45,6 @@ class LobbyComponent implements Listener {
|
||||
*/
|
||||
public function __construct(Arena $arena, $world = null)
|
||||
{
|
||||
|
||||
if ($world == null)
|
||||
$world = Server::getInstance()->getDefaultLevel();
|
||||
|
||||
@ -51,7 +54,7 @@ class LobbyComponent implements Listener {
|
||||
$this->worldName = $world->getName();
|
||||
|
||||
$this->arena = $arena;
|
||||
$this->duringLobbyGameState = new DuringLobbyGameState($arena);
|
||||
$this->duringLobbyGameState = new DuringLobbyGameState($arena, $world);
|
||||
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||
}
|
||||
@ -70,15 +73,11 @@ class LobbyComponent implements Listener {
|
||||
return;
|
||||
|
||||
if ($event->getToGameState() == GameState::LOBBY) {
|
||||
if (!$this->duringLobbyGameState->isEnabled())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -96,16 +95,20 @@ class LobbyComponent implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
class DuringLobbyGameState implements Feature, Listener {
|
||||
class DuringLobbyGameState implements Feature, Listener
|
||||
{
|
||||
|
||||
private $arena;
|
||||
|
||||
private $spawn;
|
||||
|
||||
/** @var bool */
|
||||
private $enabled = false;
|
||||
|
||||
public function __construct(Arena $arena)
|
||||
public function __construct(Arena $arena, Level $world)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
$this->spawn = new Position(0, 103, 0, $world);
|
||||
}
|
||||
|
||||
|
||||
@ -140,6 +143,28 @@ class DuringLobbyGameState implements Feature, Listener {
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
function onJoin(ArenaJoinEvent $event)
|
||||
{
|
||||
if ($this->arena !== $event->getArena())
|
||||
return;
|
||||
|
||||
$this->sendToSpawn($event->getPlayer());
|
||||
}
|
||||
|
||||
function sendToSpawn(Player $player)
|
||||
{
|
||||
$player->getInventory()->clearAll();
|
||||
$player->removeAllEffects();
|
||||
|
||||
$player->setHealth($player->getMaxHealth());
|
||||
$player->resetFallDistance();
|
||||
|
||||
$pos = $this->spawn->add(rand(-4, 4), 0, rand(-4, 4));
|
||||
|
||||
$player->teleport($pos);
|
||||
}
|
||||
|
||||
|
||||
function isEnabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
@ -147,14 +172,15 @@ class DuringLobbyGameState implements Feature, Listener {
|
||||
|
||||
function enable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Enabled!");
|
||||
foreach ($this->arena->getPlayers() as $player) {
|
||||
$this->sendToSpawn($player);
|
||||
}
|
||||
$this->enabled = true;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this->arena->getPlugin());
|
||||
}
|
||||
|
||||
function disable()
|
||||
{
|
||||
Server::getInstance()->broadcastMessage("Disabled!");
|
||||
$this->enabled = false;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use pocketmine\scheduler\PluginTask;
|
||||
class Updater extends PluginTask
|
||||
{
|
||||
private $plugin;
|
||||
/** @var UpdateType[] */
|
||||
private $updateTypes;
|
||||
|
||||
public function __construct(PluginBase $host)
|
||||
@ -51,7 +52,7 @@ class Updater extends PluginTask
|
||||
{
|
||||
if ($updateType->canTrigger())
|
||||
{
|
||||
$updateTypes[$updateType] = 1;
|
||||
$updateTypes[$updateType->time] = 1;
|
||||
}
|
||||
}
|
||||
//Call Event
|
||||
|
Loading…
Reference in New Issue
Block a user