Signs and starting events !
This commit is contained in:
parent
2b4ef28d99
commit
3c989e043c
3 changed files with 35 additions and 4 deletions
|
@ -61,10 +61,13 @@ abstract class Game {
|
|||
public function onQuit(Player $player) {}
|
||||
|
||||
|
||||
public function onBlockBreak(Player $player, Block $block) {}
|
||||
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {}
|
||||
|
||||
|
||||
public function onBlockPlace(Player $player, Block $block) {}
|
||||
public function onBlockPlace(\pocketmine\event\entity\EntityDamageEvent $event) {}
|
||||
|
||||
|
||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {}
|
||||
|
||||
|
||||
public function getConfig() {
|
||||
|
@ -73,7 +76,7 @@ abstract class Game {
|
|||
|
||||
|
||||
public function saveDefaultConfig() {
|
||||
$this->main->saveResource("/games/$this->name/config.yml");
|
||||
file_put_contents($this->main->getDataFolder() . "games/$this->name", "");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,13 +3,14 @@ namespace Ad5001\GameManager;
|
|||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\event\player\PlayerInteractEvent;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use Ad5001\GameManager\GameManager;
|
||||
|
||||
|
||||
class Main extends PluginBase{
|
||||
class Main extends PluginBase implements Listener {
|
||||
|
||||
|
||||
protected $manager;
|
||||
|
@ -20,7 +21,27 @@ class Main extends PluginBase{
|
|||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
@mkdir($this->getServer()->getFilePath() . "worldsBackups/");
|
||||
$this->manager = new GameManager($this);
|
||||
}
|
||||
|
||||
|
||||
public function onInteract(PlayerInteractEvent $event) {
|
||||
if($event->getBlock() instanceof \pocketmine\block\SignPost and $event->getBlock() instanceof \pocketmine\block\WallSign) {
|
||||
$t = $event->getBlock()->getLevel()->getTile($block);
|
||||
if(str_ireplace("{game}", $class->getName(), $this->getConfig()->get("Game1")) == $t->getText()[0]) {
|
||||
$lvlex = explode("{level}", $this->getConfig()->get("Game2"));
|
||||
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
|
||||
$lvl = str_ireplace($lvlex[1], "", $lvl);
|
||||
if($name == $lvl) {
|
||||
if($this->gameManager->getLevels()[$lvl->getName()]->isStarted()) {
|
||||
$event->getPlayer()->teleport($lvl->getDefaultSpawn());
|
||||
$event->getPlayer()->setGamemode(3);
|
||||
} else {
|
||||
$event->getPlayer()->teleport($lvl->getDefaultSpawn());
|
||||
$this->gameManager->getLevels()[$lvl->getName()]->onJoin($event->getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,13 @@ class SignReloadTask extends PluginTask {
|
|||
foreach($level->getTiles() as $t) {
|
||||
if($t instanceof \pocketmine\tile\Sign) {
|
||||
foreach($this->gameManager->getLevels() as $name => $class) {
|
||||
if($t->getText()[0] == "[GAME]" and $class->getLevel()->getName() == $t->getText()[1]) {
|
||||
$texts = $t->getText();
|
||||
foreach($texts as $key => $text) {
|
||||
$texts[$key] = str_ireplace("{players}", count($class->getLevel()->getPlayers()), str_ireplace("{max}", $class->getMaxPlayers(), str_ireplace("{game}", $class->getName(), str_ireplace("{level}", $class->getLevel()->getName(), ))))
|
||||
}
|
||||
$t->setText($texts[0], $texts[1], $texts[2], $texts[3]);
|
||||
}
|
||||
if(str_ireplace("{game}", $class->getName(), $this->cfg->get("Game1")) == $t->getText()[0]) {
|
||||
$lvlex = explode("{level}", $this->cfg->get("Game2"));
|
||||
$lvl = str_ireplace($lvlex[0], "", $t->getText()[1]);
|
||||
|
|
Loading…
Reference in a new issue