forked from Ad5001/UHC
Starting scenario implementation
This commit is contained in:
parent
26a4c28ea1
commit
2d183661e9
8 changed files with 98 additions and 38 deletions
|
@ -6,4 +6,4 @@ worlds:
|
|||
nether:
|
||||
name: nether
|
||||
maxplayers: 8
|
||||
raduis: 1000
|
||||
radius: 1000
|
|
@ -12,14 +12,21 @@ use pocketmine\command\Command;
|
|||
use pocketmine\event\Listener;
|
||||
use pocketmine\event\level\LevelLoadEvent;
|
||||
use pocketmine\event\player\PlayerJoinEvent;
|
||||
use pocketmine\event\player\PlayerDeathEvent;
|
||||
use pocketmine\event\player\PlayerChatEvent;
|
||||
use pocketmine\event\player\PlayerQuitEvent;
|
||||
use pocketmine\event\player\PlayerRespawnEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\event\entity\EntityLevelChangeEvent;
|
||||
use pocketmine\utils\TextFormat as C;
|
||||
|
||||
use Ad5001\UHC\UHCWorld;
|
||||
use Ad5001\UHC\UHCGame;
|
||||
use Ad5001\UHC\task\FetchPlayersTask;
|
||||
use Ad5001\UHC\task\StartGameTask;
|
||||
use Ad5001\UHC\event\GameStartEvent;
|
||||
use Ad5001\UHC\event\GameFinishEvent;
|
||||
class Main extends PluginBase implements Listener{
|
||||
|
@ -28,12 +35,13 @@ class Main extends PluginBase implements Listener{
|
|||
|
||||
|
||||
public function startGame(UHCWorld $world) {
|
||||
$this->games[$world->getName()] = new UHCGame($this, $world);
|
||||
$ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new StartGameTask($this, $world), 20);
|
||||
// $this->games[$world->getName()] = new UHCGame($this, $world);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function onLevelChange(\pocketmine\event\entity\EntityLevelChangeEvent $event) {
|
||||
public function onLevelChange(EntityLevelChangeEvent $event) {
|
||||
foreach($this->worlds as $world) {
|
||||
if($event->getLevel()->getName() === $world->getName() and !isset($this->games[$world->getName()])) {
|
||||
if(count($world->getLevel()->getPlayers) > $world->maxplayers) {
|
||||
|
@ -59,9 +67,13 @@ class Main extends PluginBase implements Listener{
|
|||
public function onPlayerJoin(PlayerJoinEvent $event) {
|
||||
if(!isset($this->ft)) {
|
||||
$this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->worlds), 10);
|
||||
foreach($this->getConfig()->get("worlds") as $lvl) {
|
||||
$this->worlds[$lvl["name"]] = new UHCWorld($this, $this->getServer()->getLevelByName($lvl["name"]), $lvl["name"], $lvl["maxplayers"], $lvl["radius"]);
|
||||
$this->getLogger()->debug("Processing {$lvl["name"]}");
|
||||
}
|
||||
} elseif(isset($this->quit[$event->getPlayer()])) {
|
||||
$quit = explode("/", $this->quit[$event->getPlayer()]);
|
||||
}
|
||||
if(isset($this->quit[$event->getPlayer()->getName()])) {
|
||||
$quit = explode("/", $this->quit[$event->getPlayer()->getName()]);
|
||||
$event->getPlayer()->teleport($this->getServer()->getLevelByName($quit[4]));
|
||||
$event->getPlayer()->teleport(new Vector3($quit[0], $quit[1], $quit[2]));
|
||||
foreach($world->getLevel()->getPlayers() as $player) {
|
||||
|
@ -73,15 +85,6 @@ class Main extends PluginBase implements Listener{
|
|||
|
||||
|
||||
|
||||
public function onLevelLoad(LevelLoadEvent $event) {
|
||||
foreach($this->getConfig()->get("worlds") as $lvl) {
|
||||
$this->getLogger()->debug("Processing $lvl");
|
||||
if($event->getLevel()->getName() === $lvl["name"]) {
|
||||
$this->world[$lvl["name"]] = new UHCWorld($this, $this->getServer()->getLevelByName($lvl), $lvl["name"], $lvl["maxplayers"], $lvl["radius"]);
|
||||
$this->getLogger()->debug("Processing $lvl = {$event->getLevel()->getName()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
public function onEnable(){
|
||||
$this->reloadConfig();
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
|
@ -98,7 +101,29 @@ $this->reloadConfig();
|
|||
$this->saveDefaultConfig();
|
||||
}
|
||||
|
||||
public function onRespawn(PlayerRespawnEvent $event) {
|
||||
foreach($this->games as $game) {
|
||||
$game->onRespawn($event);
|
||||
}
|
||||
}
|
||||
|
||||
public function onPlayerQuit(PlayerQuitEvent $event) {
|
||||
foreach($this->games as $game) {
|
||||
$game->onPlayerQuit($event);
|
||||
}
|
||||
}
|
||||
|
||||
public function onPlayerDeath(PlayerDeathEvent $event) {
|
||||
foreach($this->games as $game) {
|
||||
$game->onPlayerDeath($event);
|
||||
}
|
||||
}
|
||||
|
||||
public function onHeal(EntityRegainHealthEvent $event) {
|
||||
foreach($this->games as $game) {
|
||||
$game->onHeal($event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
|
||||
|
@ -108,7 +133,7 @@ switch($cmd->getName()){
|
|||
switch($args[0]) {
|
||||
case "start":
|
||||
if(isset($this->worlds[$sender->getLevel()->getName()]) and !isset($this->games[$sender->getLevel()->getName()])) {
|
||||
$this->getLogger()->debug("Starting game {$this->worlds[$sender->getLevel()->getName()]}");
|
||||
$this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}");
|
||||
foreach($sender->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(self::PREFIX . "Starting game...");
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ use pocketmine\command\CommandSender;
|
|||
use pocketmine\command\Command;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\event\player\PlayerDeathEvent;
|
||||
use pocketmine\event\player\PlayerChatEvent;
|
||||
use pocketmine\event\player\PlayerQuitEvent;
|
||||
use pocketmine\event\player\PlayerRespawnEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\utils\TextFormat as C;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
@ -36,8 +36,9 @@ class UHCGame implements Listener{
|
|||
public function __construct(Plugin $plugin, UHCWorld $world) {
|
||||
$this->m = $plugin;
|
||||
$this->world = $world;
|
||||
$this->players = $world->getPlayers();
|
||||
$event = $this->getServer()->getPluginManager()->callEvent(new GameStartEvent($this, $world, $this->players));
|
||||
$this->players = $world->getLevel()->getPlayers();
|
||||
$event = new GameStartEvent($this, $world, $this->players);
|
||||
$this->m->getServer()->getPluginManager()->callEvent($event);
|
||||
$this->cancelled = false;
|
||||
$this->kills = [];
|
||||
if($event->isCancelled()) {
|
||||
|
@ -45,20 +46,19 @@ class UHCGame implements Listener{
|
|||
} else {
|
||||
$radius = $world->radius;
|
||||
foreach($this->players as $player) {
|
||||
$x = rand($radius + $world->getLevel()->getDefaultSpawn(), $world->getLevel()->getDefaultSpawn() - $radius);
|
||||
$z = rand($radius + $world->getLevel()->getDefaultSpawn(), $world->getLevel()->getDefaultSpawn() - $radius);
|
||||
$x = rand($radius + $world->getLevel()->getSpawnLocation()->x, $world->getLevel()->getSpawnLocation()->x - $radius);
|
||||
$z = rand($radius + $world->getLevel()->getSpawnLocation()->z, $world->getLevel()->getSpawnLocation()->z - $radius);
|
||||
$pos = new Vector3($x, 128, $z);
|
||||
$player->teleport($pos);
|
||||
$effect = \pocketmine\entity\Effect::getEffect(11);
|
||||
$effect->setDuration(30);
|
||||
$effect->setDuration(30*20);
|
||||
$effect->setAmplifier(99);
|
||||
$effect->setVisible(false);
|
||||
$player->addEffect($effect);
|
||||
$this->m->getServer()->getScheduler()->scheduleDelayedTask(new StopResTask($this, $this->worlds), 30*20);
|
||||
$this->m->getServer()->getScheduler()->scheduleDelayedTask(new StopResTask($this, $this->world), 30*20);
|
||||
$player->sendMessage(Main::PREFIX . C::GREEN . "Game started ! Good luck {$player->getName()} !");
|
||||
}
|
||||
}
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,11 +146,20 @@ class UHCGame implements Listener{
|
|||
|
||||
public function onPlayerChat(PlayerChatEvent $event) {
|
||||
if($event->getPlayer()->getLevel()->getName() === $this->world->getLevel()->getName() and $event->getPlayer()->getGamemode() === 3) {
|
||||
foreach($this->world->getLevel()->getPlayer())
|
||||
if($event->getPlayer()->isSpectator()) {
|
||||
foreach($this->world->getLevel()->getPlayer() as $player) {
|
||||
$player->sendMessage(C::GRAY . "[SPECTATOR] {$event->getPlayer()->getName()} > " . $event->getMessage());
|
||||
|
||||
}
|
||||
$event->setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Will be useful for scenarios:
|
||||
@param player
|
||||
*/
|
||||
public function getKills(Player $player) {
|
||||
if(isset($this->kills[$player->getName()])) {
|
||||
return $this->kills[$player->getName()];
|
||||
|
|
|
@ -30,7 +30,7 @@ class UHCWorld {
|
|||
$this->radius = $radius;
|
||||
}
|
||||
public function getLevel() {
|
||||
return $this->level;
|
||||
return $this->lvl;
|
||||
}
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
|
@ -53,6 +53,7 @@ class UHCWorld {
|
|||
if(!in_array($player, $players)){
|
||||
foreach($this->players as $pl) {
|
||||
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} joined the game.");
|
||||
$part = new TextParticle(new FloatingTextParticle(new Vector3($this->x, $this->y, $this->z), C::GREEN . "Welcome to the UHC {$player->getName()} !\n" . C::GREEN . "To get help about the plugin , please type command /uhc howtoplay .", C::YELLOW . "-=<UHC>=-"), $this->level, $player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
# | |__| | | | | |____
|
||||
# \____/|_| |_|\_____|
|
||||
# The most customisable UHC plugin for Minecraft PE !
|
||||
namespace Ad5001\UHC\events;
|
||||
namespace Ad5001\UHC\event;
|
||||
use pocketmine\event\Cancellable.php;
|
||||
use Ad5001\UHC\events\UHCEvent;
|
||||
use Ad5001\UHC\event\UHCEvent;
|
||||
use Ad5001\UHC\UHCGame;
|
||||
use Ad5001\UHC\UHCWorld;
|
||||
|
|
@ -6,16 +6,18 @@
|
|||
# | |__| | | | | |____
|
||||
# \____/|_| |_|\_____|
|
||||
# The most customisable UHC plugin for Minecraft PE !
|
||||
namespace Ad5001\UHC\events;
|
||||
use pocketmine\event\Cancellable.php;
|
||||
use Ad5001\UHC\events\UHCEvent;
|
||||
namespace Ad5001\UHC\event;
|
||||
use pocketmine\event\Cancellable;
|
||||
use Ad5001\UHC\event\UHCEvent;
|
||||
use Ad5001\UHC\UHCGame;
|
||||
use Ad5001\UHC\UHCWorld;
|
||||
|
||||
protected $game;
|
||||
protected $world;
|
||||
protected $players;
|
||||
|
||||
class GameStartEvent extends UHCEvent implements Cancellable {
|
||||
protected $game;
|
||||
protected $world;
|
||||
protected $players;
|
||||
static $handlerList = null;
|
||||
public function __construct($game, $world, $players) {
|
||||
$this->game = $game;
|
||||
$this->world = $world;
|
|
@ -6,7 +6,7 @@
|
|||
# | |__| | | | | |____
|
||||
# \____/|_| |_|\_____|
|
||||
# The most customisable UHC plugin for Minecraft PE !
|
||||
namespace Ad5001\UHC\events;
|
||||
namespace Ad5001\UHC\event;
|
||||
use pocketmine\event\Event;
|
||||
abstract class UHCEvent extends Event {
|
||||
public function getGame() {
|
|
@ -26,15 +26,35 @@ class StartGameTask extends PluginTask {
|
|||
parent::__construct($main);
|
||||
$this->main = $main;
|
||||
$this->world = $world;
|
||||
$this->seconds = 0;
|
||||
$this->seconds = 30;
|
||||
$this->close = false;
|
||||
}
|
||||
|
||||
|
||||
public function close() {
|
||||
$this->close = true;
|
||||
}
|
||||
|
||||
|
||||
public function onRun($tick) {
|
||||
if(!$this->close) {
|
||||
$this->main->getLogger()->debug($this->seconds);
|
||||
switch($this->seconds) {
|
||||
case 30:
|
||||
foreach($this->world->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(Main::PREFIX . C::YELLOW . "30 seconds before the game starts");
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
foreach($this->world->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(Main::PREFIX . C::YELLOW . "20 seconds before the game starts");
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
foreach($this->world->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(Main::PREFIX . C::YELLOW . "15 seconds before the game starts");
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
foreach($this->world->getLevel()->getPlayers() as $player) {
|
||||
$player->sendMessage(Main::PREFIX . C::YELLOW . "10 seconds before the game starts");
|
||||
|
@ -67,8 +87,11 @@ class StartGameTask extends PluginTask {
|
|||
break;
|
||||
case 0:
|
||||
$this->main->games[$this->world->getLevel()->getName()] = new UHCGame($this->main, $this->world);
|
||||
$this->close();
|
||||
$this->seconds = -1;
|
||||
break;
|
||||
}
|
||||
$this->seconds--;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue