Added some stuff.

Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
Aaron Brock 2015-07-04 20:59:15 -04:00
parent 00b5c6f3d4
commit 514fe4a18a
20 changed files with 268 additions and 88 deletions

View File

@ -2,24 +2,26 @@
namespace mineplex\plugin; namespace mineplex\plugin;
use mineplex\plugin\bench\arenas\MultiGameArena;
use mineplex\plugin\bench\arenas\SingleGameArena; use mineplex\plugin\bench\game\factory\TestGameFactory;
use mineplex\plugin\core\updater\UpdateEvent;
use mineplex\plugin\bench\game\games\pvp\Pvp;
use mineplex\plugin\packets\StrangePacket;
use mineplex\plugin\util\UtilString;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerLoginEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\plugin\PluginBase; use pocketmine\plugin\PluginBase;
use mineplex\plugin\bench\arenas\Arena;
use pocketmine\Server; use pocketmine\Server;
class Main extends PluginBase implements Listener class Main extends PluginBase implements Listener
{ {
/** @var Arena */
private $arena;
public function onEnable() public function onEnable()
{ {
new SingleGameArena($this, new Pvp());
$this->arena = new MultiGameArena($this, new TestGameFactory());
Server::getInstance()->getPluginManager()->registerEvents($this, $this);
//$this->getServer()->getScheduler()->scheduleRepeatingTask(new TickTask($this), 1); //$this->getServer()->getScheduler()->scheduleRepeatingTask(new TickTask($this), 1);
@ -27,64 +29,17 @@ class Main extends PluginBase implements Listener
//new Updater($this); //new Updater($this);
} }
public function onDisable() public function onLogin(PlayerLoginEvent $event)
{ {
if ($this->arena->canJoin($event->getPlayer()))
retun;
$event->setKickMessage("Unable to join game!");
$event->setCancelled();
} }
public function joinMessage(PlayerJoinEvent $event) public function onJoin(PlayerJoinEvent $event)
{ {
$name = $event->getPlayer()->getName(); $this->arena->addPlayer($event->getPlayer());
$player = Server::getInstance()->getPlayer($name);
$event->setJoinMessage($player->getName());
}
public function onPlayerJoin(PlayerJoinEvent $event)
{
$event->getPlayer()->sendMessage("Welcome to the server " . $event->getPlayer()->getName() . "!");
$this->getLogger()->info($event->getPlayer()->getName() . " UID: " . $event->getPlayer()->getUniqueId());
if (UtilString::startsWith( $event->getPlayer()->getName(), "chissling"))
{
$event->getPlayer()->setNameTag("// chiss //");
$event->getPlayer()->setDisplayName("// chiss //");
}
}
public function onPlayerCommand(PlayerCommandPreprocessEvent $event)
{
if (UtilString::startsWith($event->getMessage(), "/mineplex"))
{
$event->setCancelled(true);
$event->getPlayer()->sendMessage("Sending you to: MINEPLEX");
$packet = new StrangePacket();
$packet->address = "69.175.104.154";
$event->getPlayer()->directDataPacket($packet);
}
if (UtilString::startsWith($event->getMessage(), "/ip "))
{
$event->setCancelled(true);
$ip = substr($event->getMessage(), 4, strlen($event->getMessage()));
$event->getPlayer()->sendMessage("Sending you to: " . $ip);
$packet = new StrangePacket();
$packet->address = $ip;
$event->getPlayer()->directDataPacket($packet);
}
}
public function onTick(UpdateEvent $event)
{
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 1:35 PM * Time: 1:35 PM
*/ */
@ -12,7 +12,13 @@ use pocketmine\Player;
interface Arena interface Arena
{ {
public function getCurrentGame(); /**
* @param Player $player
* @return bool
*/
public function canJoin(Player $player);
public function addPlayer(Player $player);
public function removePlayer(Player $player);
/** /**
* @return Player[] * @return Player[]

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 9:06 PM * Time: 9:06 PM
*/ */

View File

@ -0,0 +1,102 @@
<?php
/**
* Created by PhpStorm.
* User: Bench
* Date: 7/4/2015
* Time: 12:14 PM
*/
namespace mineplex\plugin\bench\arenas;
use mineplex\plugin\bench\arenas\events\ArenaEndEvent;
use mineplex\plugin\bench\game\factory\GameFactory;
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;
use mineplex\plugin\bench\arenas\events\ArenaStartEvent;
class MultiGameArena implements Arena, Listener
{
/** @var Player[] */
private $players = array();
private $plugin;
private $gameFactory;
private $game;
public function __construct(Plugin $plugin, GameFactory $gameFactory)
{
Server::getInstance()->getPluginManager()->registerEvents($this, $plugin);
$this->gameFactory = $gameFactory;
$this->plugin = $plugin;
$this->startGame();
}
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 onQuit(PlayerQuitEvent $event)
{
$this->removePlayer($event->getPlayer());
}
public function endGame()
{
Server::getInstance()->getPluginManager()->callEvent(new ArenaEndEvent($this));
$this->startGame();
}
private function startGame()
{
$this->game = $this->gameFactory->getGame();
$this->game->start($this);
Server::getInstance()->getPluginManager()->callEvent(new ArenaStartEvent($this));
}
public function getPlayers()
{
return $this->players;
}
public function getCurrentGame()
{
return $this->game;
}
public function getPlugin()
{
return $this->plugin;
}
}

View File

@ -31,7 +31,6 @@ class SingleGameArena implements Arena, Listener {
public function __construct(Plugin $plugin, Game $game) public function __construct(Plugin $plugin, Game $game)
{ {
print 'SimpleGameArena Created!';
Server::getInstance()->getPluginManager()->registerEvents($this, $plugin); Server::getInstance()->getPluginManager()->registerEvents($this, $plugin);
$this->game = $game; $this->game = $game;
$this->plugin = $plugin; $this->plugin = $plugin;
@ -100,7 +99,7 @@ class SingleGameArena implements Arena, Listener {
foreach ($this->players as $player) foreach ($this->players as $player)
{ {
Server::getInstance()->broadcastMessage((string)$player->getName()); Server::getInstance()->broadcastMessage((string)$player->getName());
$player->kick('Game Over...'); $player->kick('Game Over...', false);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 9:22 PM * Time: 9:22 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 10:12 PM * Time: 10:12 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 9:22 PM * Time: 9:22 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 9:22 PM * Time: 9:22 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: Bench
* Date: 6/30/2015 * Date: 6/30/2015
* Time: 10:12 PM * Time: 10:12 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: TheMineBench
* Date: 7/1/2015 * Date: 7/1/2015
* Time: 5:52 PM * Time: 5:52 PM
*/ */
@ -71,15 +71,17 @@ class GameStateCountdown implements Listener, BenchTask {
{ {
print "Count: $this->count"."\n"; print "Count: $this->count"."\n";
$this->popup();
$this->count--;
if ($this->count <= 0) if ($this->count <= 0)
{ {
$this->gameStateComponent->setGameState($this->setGameState); $this->gameStateComponent->setGameState($this->setGameState);
$data->end(); $data->end();
} }
$this->popup();
$this->count--;
} }
public function popup() public function popup()

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: TheMineBench
* Date: 7/1/2015 * Date: 7/1/2015
* Time: 10:18 PM * Time: 10:18 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: TheMineBench
* Date: 7/2/2015 * Date: 7/2/2015
* Time: 12:44 AM * Time: 12:44 AM
*/ */
@ -16,6 +16,8 @@ use mineplex\plugin\bench\game\components\gamestate\GameState;
use pocketmine\event\HandlerList; use pocketmine\event\HandlerList;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\Server; use pocketmine\Server;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;
class GameStateFeatureManager implements Listener { class GameStateFeatureManager implements Listener {
@ -83,7 +85,7 @@ class GameStateFeatureManager implements Listener {
if ($event->getArena() !== $this->arena) if ($event->getArena() !== $this->arena)
return; return;
/** @var Feature[] $iterator */
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features)); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->features));
foreach ($iterator as $feature) { foreach ($iterator as $feature) {

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: TheMineBench
* Date: 7/1/2015 * Date: 7/1/2015
* Time: 10:20 PM * Time: 10:20 PM
*/ */
@ -17,12 +17,38 @@ use pocketmine\Server;
class NoBlockBreak implements Feature, Listener { class NoBlockBreak implements Feature, Listener {
/** @var Arena */
private $arena; private $arena;
/** @var int[] */
private $ids = [];
/** @var bool */
private $black;
/** @var bool */
private $enabled = false; private $enabled = false;
/**
public function __construct(Arena $arena) * @param Arena $arena
* @param int[] $ids
* @param bool $black
*/
public function __construct(Arena $arena, array $ids = null, $black = false)
{ {
if ($ids != null) {
$this->ids = array_flip($ids);
foreach ($this->ids as $key => $value)
{
print "Key:" . $key;
}
}
print "\n" . "Black: " . (($black) ? 'true' : 'false') . "\n";
$this->black = $black;
print "\n" . "SetBlackList: " . (($this->black) ? 'true' : 'false') . "\n";
$this->arena = $arena; $this->arena = $arena;
} }
@ -30,7 +56,9 @@ class NoBlockBreak implements Feature, Listener {
{ {
if (!in_array($event->getPlayer(), $this->arena->getPlayers())) if (!in_array($event->getPlayer(), $this->arena->getPlayers()))
return; return;
$event->setCancelled(true);
if ($this->black == (isset($this->ids[$event->getBlock()->getId()]) || array_key_exists($event->getBlock()->getId(), $this->ids)))
$event->setCancelled();
} }
public function enable() public function enable()

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: TheMineBench
* Date: 7/1/2015 * Date: 7/1/2015
* Time: 10:20 PM * Time: 10:20 PM
*/ */

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Exerosis * User: TheMineBench
* Date: 7/1/2015 * Date: 7/1/2015
* Time: 10:33 AM * Time: 10:33 AM
*/ */

View File

@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 1:12 PM
*/
namespace mineplex\plugin\bench\game\factory;
use mineplex\plugin\bench\game\Game;
interface GameFactory {
/**
* @return Game
*/
public function getGame();
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 3:03 PM
*/
namespace mineplex\plugin\bench\game\factory;
use mineplex\plugin\bench\game\games\sg\SurvivalGames;
class TestGameFactory implements GameFactory {
function getGame()
{
return new SurvivalGames();
}
}

View File

@ -16,6 +16,7 @@ use pocketmine\event\Listener;
use mineplex\plugin\bench\game\Game; use mineplex\plugin\bench\game\Game;
use mineplex\plugin\bench\arenas\Arena; use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\bench\game\components\feature\Feature; use mineplex\plugin\bench\game\components\feature\Feature;
use pocketmine\item\Item;
class Pvp implements Game, Listener { class Pvp implements Game, Listener {
@ -23,13 +24,14 @@ class Pvp implements Game, Listener {
{ {
$gameStateComponent = new GameStateComponent($arena); $gameStateComponent = new GameStateComponent($arena);
$noBlockBreak = new NoBlockBreak($arena); $noBlockBreak = new NoBlockBreak($arena, array(Item::GRASS));
/** @var Feature[][] $features */ /** @var Feature[][] $features */
$features = array( $features = array(
GameState::LOBBY => array($noBlockBreak), GameState::LOBBY => array($noBlockBreak),
GameState::PRE_GAME => array($noBlockBreak), GameState::PRE_GAME => array($noBlockBreak),
GameState::POST_GAME => array($noBlockBreak), GameState::GAME => array($noBlockBreak),
GameState::POST_GAME => array($noBlockBreak)
); );
new GameStateFeatureManager($arena, $features); new GameStateFeatureManager($arena, $features);

View File

@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: Exerosis
* Date: 7/4/2015
* Time: 3:09 PM
*/
namespace mineplex\plugin\bench\game\games\sg;
use mineplex\plugin\bench\game\components\countdown\GameStateCountdown;
use mineplex\plugin\bench\game\components\feature\features\NoBlockBreak;
use mineplex\plugin\bench\game\components\feature\GameStateFeatureManager;
use mineplex\plugin\bench\game\components\gamestate\GameState;
use mineplex\plugin\bench\game\components\gamestate\GameStateComponent;
use mineplex\plugin\bench\game\Game;
use mineplex\plugin\bench\arenas\Arena;
use mineplex\plugin\bench\game\components\feature\Feature;
use pocketmine\item\Item;
class SurvivalGames implements Game {
function start(Arena $arena)
{
$gameStateComponent = new GameStateComponent($arena);
$noBlockBreak = new NoBlockBreak($arena, array(Item::GRASS));
/** @var Feature[][] $features */
$features = array(
GameState::LOBBY => array($noBlockBreak),
GameState::PRE_GAME => array($noBlockBreak),
GameState::POST_GAME => array($noBlockBreak)
);
new GameStateFeatureManager($arena, $features);
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::LOBBY, GameState::PRE_GAME);
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
new GameStateCountdown($arena, $gameStateComponent, 30, GameState::GAME, GameState::POST_GAME);
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
}
}