Some game stuff I don't know why this no work!

Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-01 02:03:28 -04:00
parent e3b0ee9ae3
commit 7d55221515
10 changed files with 400 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 1:35 PM
*/
namespace mineplex\plugin\bench\arenas;
use pocketmine\plugin\Plugin;
use pocketmine\Player;
interface Arena
{
public function getCurrentGame();
/**
* @return Player[]
*/
public function getPlayers();
/**
* @return Plugin
*/
public function getPlugin();
public function endGame();
}

View File

@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:06 PM
*/
namespace mineplex\plugin\bench\arenas;
use pocketmine\event\Event;
class ArenaEvent extends Event
{
private $arena;
public function __construct(Arena $arena)
{
$this->arena = $arena;
}
public function getArena()
{
return $this->arena;
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: Bench
* Date: 6/30/2015
* Time: 1:37 PM
*/
namespace mineplex\plugin\bench\arenas;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\Player;
use pocketmine\Server;
use mineplex\plugin\bench\game\Game;
use mineplex\plugin\bench\arenas\events\ArenaCanJoinEvent;
use mineplex\plugin\bench\arenas\events\ArenaJoinEvent;
use mineplex\plugin\bench\arenas\events\ArenaQuitEvent;
class SingleGameArena implements Arena, Listener {
//I really have no idea if there is a better way to store players... but this is what I'm using for now.
/** @var Player[] */
private $players = array();
private $game;
private $plugin;
public function __construct(Plugin $plugin, Game $game)
{
print 'SimpleGameArena Created!';
Server::getInstance()->getPluginManager()->registerEvents($this, $plugin);
$this->game = $game;
$this->plugin = $plugin;
$this->getCurrentGame()->start($this);
}
public function canJoin(Player $player)
{
$event = new ArenaCanJoinEvent($this, $player);
$this->plugin->getServer()->getPluginManager()->callEvent($event);
return !$event->isCancelled();
}
public function addPlayer(Player $player)
{
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaJoinEvent($this, $player));
array_push($this->players, $player);
}
public function removePlayer(Player $player)
{
if(($key = array_search($player, $this->players, true)) !== FALSE) {
unset($this->players[$key]);
}
Server::getInstance()->broadcastMessage("Calling ArenaQuitEvent");
$this->plugin->getServer()->getPluginManager()->callEvent(new ArenaQuitEvent($this, $player));
}
public function onJoin(PlayerJoinEvent $event)
{
if ($this->canJoin($event->getPlayer()))
{
$this->addPlayer($event->getPlayer());
}
}
public function onQuit(PlayerQuitEvent $event)
{
$this->removePlayer($event->getPlayer());
}
public function getPlayers()
{
return $this->players;
}
public function getCurrentGame()
{
return $this->game;
}
public function getPlugin()
{
return $this->plugin;
}
public function endGame()
{
Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this));
Server::getInstance()->broadcastMessage("MooCount: ".(string)count($this->players));
foreach ($this->players as $player)
{
Server::getInstance()->broadcastMessage((string)$player->getName());
$player->kick('Game Over...');
}
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:22 PM
*/
namespace mineplex\plugin\bench\arenas\events;
use pocketmine\event\Cancellable;
use pocketmine\Player;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
class ArenaCanJoinEvent extends ArenaEvent implements Cancellable {
public static $handlerList = null;
private $player;
public function __construct(Arena $arena, Player $player)
{
parent::__construct($arena);
$this->player = $player;
}
public function getPlayer()
{
return $this->player;
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 10:12 PM
*/
namespace mineplex\plugin\bench\arenas\events;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
class ArenaEndEvent extends ArenaEvent{
public static $handlerList = null;
public function __construct(Arena $arena)
{
parent::__construct($arena);
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:22 PM
*/
namespace mineplex\plugin\bench\arenas\events;
use pocketmine\Player;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
class ArenaJoinEvent extends ArenaEvent {
public static $handlerList = null;
private $player;
public function __construct(Arena $arena, Player $player)
{
parent::__construct($arena);
$this->player = $player;
}
public function getPlayer()
{
return $this->player;
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:22 PM
*/
namespace mineplex\plugin\bench\arenas\events;
use pocketmine\Player;
use mineplex\plugin\bench\arenas\ArenaEvent;
use mineplex\plugin\bench\arenas\Arena;
class ArenaQuitEvent extends ArenaEvent {
public static $handlerList = null;
private $player;
public function __construct(Arena $arena, Player $player)
{
parent::__construct($arena);
$this->player = $player;
}
public function getPlayer()
{
return $this->player;
}
}

View File

@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:04 PM
*/
namespace mineplex\plugin\bench\game;
use mineplex\plugin\bench\arenas\Arena;
interface Game {
public function start(Arena $arena);
}

View File

@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 9:18 PM
*/
namespace mineplex\plugin\bench\game\games\pvp;
use pocketmine\event\Listener;
use mineplex\plugin\bench\game\Game;
use mineplex\plugin\bench\arenas\Arena;
class Pvp implements Game, Listener {
public function start(Arena $arena)
{
new PvpComponent($arena);
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 6/30/2015
* Time: 10:15 PM
*/
namespace mineplex\plugin\bench\game\games\pvp;
use pocketmine\event\Listener;
use pocketmine\Server;
use pocketmine\event\HandlerList;
use pocketmine\event\player\PlayerDeathEvent;
use mineplex\plugin\bench\arenas\events\ArenaQuitEvent;
use mineplex\plugin\bench\arenas\events\ArenaJoinEvent;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\bench\arenas\Arena;
class PvpComponent implements Listener {
private $arena;
public function __construct(Arena $arena)
{
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
$this->arena = $arena;
}
public function onJoin(ArenaJoinEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
$event->getPlayer()->sendMessage("Welcome to the arena");
$players = $this->arena->getPlayers();
array_push($players, $event->getPlayer());
Server::getInstance()->broadcastMessage("JoinCount: ".(string)count($players));
if (count($this->arena->getPlayers()) >= 2)
{
foreach ($this->arena->getPlayers() as $player)
{
$player->sendPopup("Game started! Try to kill everyone else.");
}
}
}
public function onDeath(PlayerDeathEvent $event)
{
if (in_array($event->getEntity(), $this->arena->getPlayers()))
$event->getEntity()->kick('You done got yourself keeled!');
}
public function onQuit(ArenaQuitEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
Server::getInstance()->broadcastMessage(" has quit.");
$this->checkEnd();
}
public function onEnd(ArenaEndEvent $event)
{
if ($event->getArena() !== $this->arena)
return;
Server::getInstance()->broadcastMessage("Unregistered!");
HandlerList::unregisterAll($this);
}
public function checkEnd()
{
Server::getInstance()->broadcastMessage("Count: ".(string)(count($this->arena->getPlayers()) <= 1) ? 'true' : 'false');
if (count($this->arena->getPlayers()) <= 1)
{
Server::getInstance()->broadcastMessage('game ending...');
$this->arena->endGame();
}
}
}