Fixing bugs....

This commit is contained in:
Ad5001 2016-08-20 15:44:28 +03:00
parent 0df1413a31
commit 0aac12eb77
9 changed files with 57 additions and 61 deletions

View file

@ -1,9 +1,7 @@
worlds: worlds:
world: world:
name: world
maxplayers: 8 maxplayers: 8
radius: 1000 radius: 1000
nether: uhc:
name: nether
maxplayers: 8 maxplayers: 8
radius: 1000 radius: 1000

View file

@ -14,8 +14,11 @@ main: Ad5001\UHC\Main
commands: commands:
uhc: uhc:
description: Main UHC command description: Main UHC command
usage: /uhc <sub-command> [params] usage: "/uhc <sub-command> [params]"
permission: uhc.command.main permission: uhc.command.main
scenarios:
description: Manage UHC scenarios
usage: "/scenarios [add | remove | list] [scenario]"
permissions: permissions:
uhc.command.main: uhc.command.main:
default: op default: op

View file

@ -18,6 +18,7 @@ use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerRespawnEvent; use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\block\Block;
use pocketmine\plugin\PluginBase; use pocketmine\plugin\PluginBase;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\Player; use pocketmine\Player;
@ -38,7 +39,7 @@ class Main extends PluginBase implements Listener{
public function onLevelChange(EntityLevelChangeEvent $event) { public function onLevelChange(EntityLevelChangeEvent $event) {
foreach($this->UHCManager->getLevels() as $world) { foreach($this->UHCManager->getLevels() as $world) {
if($event->getLevel()->getName() === $world->getName() and !isset($this->games[$world->getName()])) { if($event->getTarget()->getName() === $world->getName() and !isset($this->games[$world->getName()])) {
if(count($world->getLevel()->getPlayers) > $world->maxplayers) { if(count($world->getLevel()->getPlayers) > $world->maxplayers) {
$event->setCancelled(); $event->setCancelled();
} }
@ -57,29 +58,12 @@ 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);
}
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) {
$player->sendMessage(self::PREFIX . C::GREEN . "{$event->getPlayer()->getName()} back to game !");
}
}
}
public function onEnable(){ public function onEnable(){
$this->saveDefaultConfig(); $this->saveDefaultConfig();
mkdir($this->getDataFolder() . "scenarios"); @mkdir($this->getDataFolder() . "scenarios");
$this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->getServer()->getPluginManager()->registerEvent("\Ad5001\UHC\event\GameStartEvent", $this, \pocketmine\plugin\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStart"), $this, true); $this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStartEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStart"), $this, true);
$this->getServer()->getPluginManager()->registerEvent("\Ad5001\UHC\event\GameStopEvent", $this, \pocketmine\plugin\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, true); $this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStopEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, true);
$this->UHCManager = new UHCManager($this); $this->UHCManager = new UHCManager($this);
$this->games = []; $this->games = [];
$this->quit = []; $this->quit = [];
@ -100,19 +84,19 @@ switch($cmd->getName()){
if(isset($args[0]) and $sender instanceof Player) { if(isset($args[0]) and $sender instanceof Player) {
switch($args[0]) { switch($args[0]) {
case "start": case "start":
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedUHCs()[$sender->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) {
$this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); $this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}");
foreach($sender->getLevel()->getPlayers() as $player) { foreach($sender->getLevel()->getPlayers() as $player) {
$player->sendMessage(self::PREFIX . "Starting game..."); $player->sendMessage(self::PREFIX . "Starting game...");
} }
$this->UHCMananger->startUHC($sender->getLevel()); $this->UHCManager->startUHC($sender->getLevel());
} else { } else {
$sender->sendMessage("You are not in a UHC world or UHC is already started"); $sender->sendMessage("You are not in a UHC world or UHC is already started");
} }
return true; return true;
break; break;
case "stop": case "stop":
if(isset($this->UHCMananger->getStartedUHCs()[$sender->getLevel()->getName()])) { if(isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) {
$this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); $this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}");
foreach($sender->getLevel()->getPlayers() as $player) { foreach($sender->getLevel()->getPlayers() as $player) {
$player->sendMessage(self::PREFIX . "Starting game..."); $player->sendMessage(self::PREFIX . "Starting game...");
@ -128,13 +112,13 @@ switch($cmd->getName()){
break; break;
case "scenarios": case "scenarios":
if(isset($args[0]) and $sender instanceof Player) { if(isset($args[0]) and $sender instanceof Player) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedGames()[$sender->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedGames()[$sender->getLevel()->getName()])) {
switch($args[0]) { switch($args[0]) {
case "add": case "add":
if(isset($args[1])) { if(isset($args[1])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) {
if(!isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { if(!isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) {
$this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->addScenario($args[1]); $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->addScenario($args[1]);
foreach($sender->getLevel()->getPlayers() as $p) { foreach($sender->getLevel()->getPlayers() as $p) {
$p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]); $p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]);
} }
@ -154,9 +138,9 @@ switch($cmd->getName()){
case "delete": case "delete":
case "del": case "del":
if(isset($args[1])) { if(isset($args[1])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) {
$this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($args[1]); $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($args[1]);
foreach($sender->getLevel()->getPlayers() as $p) { foreach($sender->getLevel()->getPlayers() as $p) {
$p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]); $p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]);
} }
@ -172,15 +156,15 @@ switch($cmd->getName()){
} }
break; break;
case "list": case "list":
$sender->sendMessage(self::PREFIX . "Current server's scenarios: " . implode(", " $this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios())); $sender->sendMessage(self::PREFIX . "Current server's scenarios: " . implode(", ", $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()));
break; break;
} }
} else { } else {
$sender->sendMessage(self::PREFIX . "You're not in a UHC world !") $sender->sendMessage(self::PREFIX . "You're not in a UHC world !");
} }
} else { } else {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedGames()[$sender->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedGames()[$sender->getLevel()->getName()])) {
$sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $this->UHCManager[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios())) $sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $this->UHCManager[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()));
} }
} }
break; break;
@ -195,7 +179,7 @@ return false;
# Event Listener ! # Event Listener !
public function onInteract(PlayerInteractEvent $event) { public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {
// echo $event->getBlock()->getId() . "=/=" . Block::SIGN_POST ."=/=" . Block::WALL_SIGN; // echo $event->getBlock()->getId() . "=/=" . Block::SIGN_POST ."=/=" . Block::WALL_SIGN;
if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) { if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) {
$t = $event->getBlock()->getLevel()->getTile($event->getBlock()); $t = $event->getBlock()->getLevel()->getTile($event->getBlock());
@ -359,17 +343,6 @@ return false;
$sc->onDataPacketReceive($event); $sc->onDataPacketReceive($event);
} }
} }
if($event->getPacket() instanceof \pocketmine\network\protocol\UseItemPacket) {
if($event->getPlayer()->getInventory()->getItemInHand()->getId() == Item::GOLD_APPLE and !$ev->isCancelled()) { // Golden apple
$e = \pocketmine\entity\Effect::getEffectByName("ABSORBTION");
$e->setDuration(120000);
$event->getPlayer()->addEffect($e);
$e = \pocketmine\entity\Effect::getEffectByName("REGENERATION");
$e->setDuration(5000);
$e->setAmplifier(2);
$event->getPlayer()->addEffect($e);
}
}
} }
@ -391,6 +364,17 @@ return false;
} }
public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) { public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) {
if(!isset($this->ft)) {
$this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->UHCManager->getLevels()), 10);
}
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($this->getServer()->getLevelByName($quit[4])->getLevel()->getPlayers() as $player) {
$player->sendMessage(self::PREFIX . C::GREEN . "{$event->getPlayer()->getName()} back to game !");
}
}
if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) { foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onJoin($event->getPlayer()); $sc->onJoin($event->getPlayer());

View file

@ -60,7 +60,7 @@ class UHCManager {
public function registerLevel(Level $level) { public function registerLevel(Level $level) {
if(!array_key_exists($level->getName(), $this->levels)) { if(!array_key_exists($level->getName(), $this->levels)) {
$this->levels[$level->getName()] = new UHCWorld($this->m,$level,$this->main->getConfig()->get("worlds")[$level->getName()]["maxplayers"],$this->main->getConfig()->get("worlds")[$level->getName()]["radius"]); $this->levels[$level->getName()] = new UHCWorld($this->main,$level,$this->main->getConfig()->get("worlds")[$level->getName()]["maxplayers"],$this->main->getConfig()->get("worlds")[$level->getName()]["radius"]);
} else { } else {
$this->main->getLogger()->warning("{$level->getName()} is already registered."); $this->main->getLogger()->warning("{$level->getName()} is already registered.");
} }

View file

@ -44,7 +44,7 @@ class UHCWorld {
public function getName() { public function getName() {
return $this->level->getName(); return $this->lvl->getName();
} }

View file

@ -14,10 +14,13 @@ use Ad5001\UHC\UHCWorld;
class GameStartEvent extends UHCEvent implements Cancellable { class GameStartEvent extends UHCEvent implements Cancellable {
public static $handlerList = null;
protected $game; protected $game;
protected $world; protected $world;
protected $players; protected $players;
static $handlerList = null;
public function __construct($game, $world, $players) { public function __construct($game, $world, $players) {
$this->game = $game; $this->game = $game;
$this->world = $world; $this->world = $world;

View file

@ -7,17 +7,18 @@
# \____/|_| |_|\_____| # \____/|_| |_|\_____|
# The most customisable UHC plugin for Minecraft PE ! # The most customisable UHC plugin for Minecraft PE !
namespace Ad5001\UHC\event; namespace Ad5001\UHC\event;
use pocketmine\event\Cancellable.php; use pocketmine\event\Cancellable;
use Ad5001\UHC\event\UHCEvent; use Ad5001\UHC\event\UHCEvent;
use Ad5001\UHC\UHCGame; use Ad5001\UHC\UHCGame;
use Ad5001\UHC\UHCWorld; use Ad5001\UHC\UHCWorld;
protected $game;
protected $world;
protected $winner;
class GameStopEvent extends UHCEvent implements Cancellable { class GameStopEvent extends UHCEvent implements Cancellable {
protected $game;
protected $world;
protected $winner;
public static $handlerList = null;
@ -42,7 +43,7 @@ class GameStopEvent extends UHCEvent implements Cancellable {
return $this->winner; return $this->winner;
} }
public function setWinner(Player $winner) { public function setWinner(Player $winner) {
$this->winner = $winner; $this->winner = $winner;
} }

View file

@ -7,7 +7,11 @@
# \____/|_| |_|\_____| # \____/|_| |_|\_____|
# The most customisable UHC plugin for Minecraft PE ! # The most customisable UHC plugin for Minecraft PE !
namespace Ad5001\UHC\event; namespace Ad5001\UHC\event;
use pocketmine\event\Event; use pocketmine\event\Event;
abstract class UHCEvent extends Event { abstract class UHCEvent extends Event {

View file

@ -1,5 +1,5 @@
<?php <?php
namespace Ad5001\UHC; namespace Ad5001\UHC\scenario;
# _ _ _ _ _____ # _ _ _ _ _____
# | | | | | | |/ ____| # | | | | | | |/ ____|
# | | | | |__| | | # | | | | |__| | |
@ -11,6 +11,9 @@ namespace Ad5001\UHC;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\level\Level; use pocketmine\level\Level;
use Ad5001\UHC\Main;
use Ad5001\UHC\UHCWorld;
use Ad5001\UHC\UHCGame;