From 48873ce539bb217372b33d3f6128156d5b4a50aa Mon Sep 17 00:00:00 2001 From: artulloss <35859316+artulloss@users.noreply.github.com> Date: Wed, 21 Nov 2018 18:44:32 -0500 Subject: [PATCH 1/2] Fixed This is so poorly written :thumbsdown: --- plugin.yml | 10 - src/Ad5001/UHC/Actions.php | 250 +++++++++++++ src/Ad5001/UHC/Main.php | 408 ++------------------- src/Ad5001/UHC/UHCGame.php | 6 +- src/Ad5001/UHC/UHCManager.php | 4 +- src/Ad5001/UHC/UHCWorld.php | 17 +- src/Ad5001/UHC/command/ScenarioCommand.php | 102 ++++++ src/Ad5001/UHC/command/UHCCommand.php | 101 +++++ src/Ad5001/UHC/event/GameStartEvent.php | 2 +- src/Ad5001/UHC/event/GameStopEvent.php | 2 +- src/Ad5001/UHC/event/UHCEvent.php | 4 +- src/Ad5001/UHC/scenario/Scenario.php | 78 ++-- src/Ad5001/UHC/task/FetchPlayersTask.php | 18 +- src/Ad5001/UHC/task/StartGameTask.php | 21 +- src/Ad5001/UHC/task/StopResTask.php | 19 +- 15 files changed, 586 insertions(+), 456 deletions(-) create mode 100644 src/Ad5001/UHC/Actions.php create mode 100644 src/Ad5001/UHC/command/ScenarioCommand.php create mode 100644 src/Ad5001/UHC/command/UHCCommand.php diff --git a/plugin.yml b/plugin.yml index 9ff6dae..8ab474d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -11,16 +11,6 @@ author: Ad5001 version: 1.0 api: [2.0.0] main: Ad5001\UHC\Main -commands: - uhc: - description: Main UHC command - usage: "/uhc [params]" - permission: uhc.command.main - scenarios: - description: Manage UHC scenarios - usage: "/scenarios [add | remove | list] [scenario]" - permission: uhc.command.scenarios - aliases: [scs] permissions: uhc.command.main: default: true diff --git a/src/Ad5001/UHC/Actions.php b/src/Ad5001/UHC/Actions.php new file mode 100644 index 0000000..dc2fcad --- /dev/null +++ b/src/Ad5001/UHC/Actions.php @@ -0,0 +1,250 @@ +main = $plugin; + self::$instance = $this; + } + + public static $instance; + + static function getInstance() { + return self::$instance; + } + + public function onLevelLoad(LevelLoadEvent $event) { + if(isset($this->main->getConfig()->get("worlds")[$event->getLevel()->getName()])) { + $this->main->UHCManager->registerLevel($event->getLevel()); + } + } + + public function onInteract(PlayerInteractEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onInteract($event); + } + } + } + + + public function onEntityLevelChange(EntityLevelChangeEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) { + $this->main->quit[$event->getEntity()->getName()] = $event->getEntity()->x . "/" . $event->getEntity()->y . "/" . $event->getEntity()->z. "/" . $event->getOrigin()->getName(); + foreach($this->main->UHCManager->getLevels()[$event->getOrigin()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onQuit($event->getEntity()); + } + } + if(isset($this->main->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) { + foreach($this->main->UHCManager->getLevels()[$event->getTarget()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onJoin($event->getEntity()); + } + } + } + + + public function onPlayerChat(PlayerChatEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerChat($event); + $sc->onChat($event); + } + } + } + + + public function onPlayerCommandPreprocess(PlayerCommandPreprocessEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerCommand($event); + } + } + } + + + public function onPlayerDeath(PlayerDeathEvent $event) { + + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerDeath($event); + $sc->onDeath($event); + } + } + } + + + public function onPlayerDropItem(PlayerDropItemEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerDropItem($event); + } + } + } + + + public function onPlayerMove(PlayerMoveEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerMove($event); + $sc->onMove($event); + } + } + } + + + public function onPlayerItemConsume(PlayerItemConsumeEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerItemConsume($event); + $sc->onItemConsume($event); + } + } + } + + + public function onPlayerItemHeld(PlayerItemHeldEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onPlayerItemHeld($event); + $sc->onItemHeld($event); + } + } + } + + + public function onBlockBreak(BlockBreakEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onBlockBreak($event); + $sc->onBreak($event); + } + } + } + + + public function onBlockPlace(BlockPlaceEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onBlockPlace($event); + $sc->onPlace($event); + } + } + } + + + public function onEntityDamage(EntityDamageEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onEntityDamage($event); + } + } + } + + + public function onProjectileLaunch(ProjectileLaunchEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onProjectileLaunch($event); + } + } + } + + + public function onProjectileHit(ProjectileHitEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onProjectileHit($event); + } + } + } + + + public function onDataPacketReceive(DataPacketReceiveEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onDataPacketReceive($event); + } + } + } + + + public function onDataPacketSend(DataPacketSendEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onDataPacketSend($event); + } + } + } + + + public function onServerCommand(CommandEvent $event) { + foreach($this->main->UHCManager->getLevels() as $lvl => $world) { + foreach($world->scenarioManager->getUsedScenarios() as $sc) { + $sc->onServerCommand($event); + } + } + } + + public function onPlayerJoin(PlayerJoinEvent $event) { + if(!isset($this->main->ft)) { + $this->main->ft = $this->main->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this->main, $this->main->UHCManager->getStartedUHCs()), 10); + } + if(isset($this->main->quit[$event->getPlayer()->getName()]) and $event->getPlayer()->getLevel()->getName() == $this->main->quit[3]) { + $this->main->quit = explode("/", $this->main->quit[$event->getPlayer()->getName()]); + $event->getPlayer()->teleport($this->main->getServer()->getLevelByName($this->main->quit[3])); + $event->getPlayer()->teleport(new Vector3($this->main->quit[0], $this->main->quit[1], $this->main->quit[2])); + foreach($this->main->getServer()->getLevelByName($this->main->quit[3])->getLevel()->getPlayers() as $player) { + $player->sendMessage(self::PREFIX . TextFormat::GREEN . "{$event->getPlayer()->getName()} back to game !"); + } + } + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onJoin($event->getPlayer()); + } + } + + } + + public function onPlayerQuit(PlayerQuitEvent $event) { + if(isset($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { + $this->main->quit[$event->getPlayer()->getName()] = $event->getPlayer()->x . "/" . $event->getPlayer()->y . "/" . $event->getPlayer()->z. "/" . $event->getPlayer()->getLevel()->getName(); + foreach($this->main->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { + $sc->onQuit($event->getPlayer()); + } + } + } + + + +} \ No newline at end of file diff --git a/src/Ad5001/UHC/Main.php b/src/Ad5001/UHC/Main.php index 998b545..115ddb1 100644 --- a/src/Ad5001/UHC/Main.php +++ b/src/Ad5001/UHC/Main.php @@ -6,37 +6,32 @@ # | |__| | | | | |____ # \____/|_| |_|\_____| # The most customisable UHC plugin for Minecraft PE! -namespace Ad5001\UHC ; -use pocketmine\command\CommandSender; -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\item\Item; -use pocketmine\block\Block; +namespace Ad5001\UHC; +use Ad5001\UHC\event\GameStartEvent; +use Ad5001\UHC\event\GameStopEvent; +use pocketmine\event\EventPriority; +use pocketmine\level\Location; +use pocketmine\plugin\MethodEventExecutor; 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; + +use Ad5001\UHC\command\UHCCommand; +use Ad5001\UHC\command\ScenarioCommand; + +use pocketmine\utils\TextFormat; +use pocketmine\event\Listener; class Main extends PluginBase implements Listener{ - const PREFIX = C::GOLD . "[" . C::DARK_RED . "UHC" . C::GOLD . "] ". C::RESET . C::WHITE; - - - + public const PREFIX = TextFormat::GOLD . "[" . TextFormat::DARK_RED . "UHC" . TextFormat::GOLD . "] ". TextFormat::RESET . TextFormat::WHITE; + + public $UHCManager; + public $quit; + + public $ft; + + public const COMMAND_UHC = "uhc"; + public const COMMAND_SCENARIO = "scenario"; + public function onLevelChange(EntityLevelChangeEvent $event) { foreach($this->UHCManager->getLevels() as $world) { if($event->getTarget()->getName() == $world->getName() and !isset($this->UHCManager->getStartedUHCs()[$world->getName()])) { @@ -48,9 +43,9 @@ public function onLevelChange(EntityLevelChangeEvent $event) { } elseif($event->getTarget()->getName() == $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and isset($this->quit[$event->getEntity()->getName()])) { $this->quit = explode("/", $this->quit[$event->getEntity()->getName()]); if($this->quit[3] === $world->getName()) { - $event->getEntity()->teleport(new \pocketmine\level\Location($this->quit[0], $this->quit[1], $this->quit[2], $event->getTarget())); + $event->getEntity()->teleport(new Location($this->quit[0], $this->quit[1], $this->quit[2], $event->getTarget())); foreach($world->getLevel()->getPlayers() as $player) { - $player->sendMessage(self::PREFIX . C::GREEN . "{$event->getPlayer()->getName()} back to game !"); + $player->sendMessage(self::PREFIX . TextFormat::GREEN . "{$event->getPlayer()->getName()} back to game !"); } $event->setCancelled(); } else { @@ -63,23 +58,22 @@ public function onLevelChange(EntityLevelChangeEvent $event) { public function onEnable(){ $this->saveDefaultConfig(); - @mkdir($this->getDataFolder() . "scenarios"); - $this->getServer()->getPluginManager()->registerEvents($this, $this); - $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\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, false); + $this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStartEvent", $this, EventPriority::NORMAL, new MethodEventExecutor("onGameStart"), $this, true); + $this->getServer()->getPluginManager()->registerEvent("Ad5001\\UHC\\event\\GameStopEvent", $this, EventPriority::NORMAL, new MethodEventExecutor("onGameStop"), $this, false); + $this->UHCManager = new UHCManager($this); - $this->quit = []; - } + $this->getServer()->getPluginManager()->registerEvents(new Actions($this), $this); + $this->getServer()->getCommandMap()->registerAll("uhc", [ + new UHCCommand(self::COMMAND_UHC, $this), + new ScenarioCommand(self::COMMAND_SCENARIO, $this) + ]); + + $this->quit = []; - public function onLevelLoad(\pocketmine\event\level\LevelLoadEvent $event) { - if(isset($this->getConfig()->get("worlds")[$event->getLevel()->getName()])) { - $this->UHCManager->registerLevel($event->getLevel()); - } } - - + public function getClasses(string $file) { $tokens = token_get_all($file); $class_token = false; @@ -88,344 +82,20 @@ public function getClasses(string $file) { if ($token[0] == T_CLASS) { $class_token = true; } else if ($class_token && $token[0] == T_STRING) { - return $token[1]; - } - } - } - } + var_dump($token[1]); - public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ - switch($cmd->getName()){ - case "uhc": - if(isset($args[0]) and $sender instanceof Player) { - switch($args[0]) { - case "start": - if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { - $this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); - foreach($sender->getLevel()->getPlayers() as $player) { - $player->sendMessage(self::PREFIX . "Starting game..."); - } - $this->UHCManager->startUHC($sender->getLevel()); - } else { - $sender->sendMessage("You are not in a UHC world or UHC is already started"); - } - return true; - break; - case "stop": - if(isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { - $this->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); - foreach($sender->getLevel()->getPlayers() as $player) { - $player->sendMessage(self::PREFIX . "Starting game..."); - } - $this->UHCManager->stopUHC($sender->getLevel()); - } else { - $sender->sendMessage("You are not in a UHC world or UHC is already started"); - } - return true; - break; - case "howtoplay": - case "?": - case "help": - if(!isset($args[1])) { - $sender->sendMessage(self::PREFIX . "Welcome to UHC's help ! WHat do you want to know about UHC?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n" . self::PREFIX . "- The scenarios (/uhc howtoplay scenarios)\n"); - } else { - switch(strtolower($args[1])) { - case "game": - $sender->sendMessage(self::PREFIX . "UHC (aka Ultra HardCord) is a new difficulty where it's hardcord but with no health regen exept for golden apples and potions and only 1 life. The most popular 'UHC' Game is a PvP (Player versus Player) game where you're in this mode and you need to kill other players.\n" . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n" . self::PREFIX . "- The scenarios (/uhc howtoplay scenarios)\n"); - break; - case "commands": - $sender->sendMessage(self::PREFIX . "This UHC Plugin have special commands. For players: /scenarios will give you the list of the current enabled scenarios. " . ($sender->isOp() ? "For OP: '/uhc start' start the uhc. '/uhc stop' finish it. '/scenarios add ' adds a scenario. '/scenario rm ' remove a scenario. '/scenarios list' gives you the list of installed scenarios.\n" : "\n") . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The scenarios (/uhc howtoplay scenarios)"); - break; - case "scenarios": - $sender->sendMessage(self::PREFIX . "Scenarios are 'addons' to the UHC that modify some mechanics or some parts of the game. You can download them or create them yourself. Look at ccommands if you want to know how to add a scenario to a game and look at https://github.com/Ad5001/UHC/wiki/What-are-Scenarios%3F. If you want to know more about a scenario, use /uhc howtoplay .\n" . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n"); - break; - default: - if(in_array($args[1], $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios())) { - $sender->sendMessage(self::PREFIX . "Help for $args[1]. " . $args[1]::help()); - } else { - $sender->sendMessage(self::PREFIX . "No help for $args[1]"); - } - break; - + return $token[1]; } } - return true; - break; } } - break; - case "scenarios": - if(isset($args[0]) and $sender instanceof Player and $sender->hasPermission("uhc.scenarios.modify")) { - if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { - switch($args[0]) { - case "add": - if(isset($args[1])) { - if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) { - if(!isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { - $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->addScenario($args[1]); - foreach($sender->getLevel()->getPlayers() as $p) { - $p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]); - } - $sender->sendMessage(self::PREFIX . C::GREEN . " Succefully added scenario $args[1] !"); - } else { - $sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] has already been added !"); - } - } else { - $sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] does not exists !"); - } - } else { - $sender->sendMessage(self::PREFIX . C::DARK_RED . "Usage: /scenarios add "); - } - break; - case "remove": - case "rm": - case "delete": - case "del": - if(isset($args[1])) { - if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { - if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { - $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($args[1]); - foreach($sender->getLevel()->getPlayers() as $p) { - $p->sendTip(C::GOLD . C::BOLD . "Scenario added !" . PHP_EOL . C::RESET . C::GREEN . C::ITALIC . "+ " . $args[1]); - } - $sender->sendMessage(self::PREFIX . C::GREEN . " Succefully removed scenario $args[1] !"); - } else { - $sender->sendMessage(slef::PREFIX . C::DARK_RED . "Scenario $args[1] hasn't been added yet !"); - } - } else { - $sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] does not exists !"); - } - } else { - $sender->sendMessage(self::PREFIX . C::DARK_RED . "Usage: /scenarios rm "); - } - break; - case "list": - $sender->sendMessage(self::PREFIX . "Current server's scenarios: " . implode(", ", $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios())); - break; - } - } else { - $sender->sendMessage(self::PREFIX . "You're not in a UHC world !"); - } - } else { - if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { - $scs = $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios(); - $sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $scs)); - } - } - return true; - break; -} -return false; - } - - - - - - - # Event Listener ! - - public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onInteract($event); - } - } - } - - - public function onEntityLevelChange(EntityLevelChangeEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) { - $this->quit[$event->getEntity()->getName()] = $event->getEntity()->x . "/" . $event->getEntity()->y . "/" . $event->getEntity()->z. "/" . $event->getOrigin()->getName(); - foreach($this->UHCManager->getLevels()[$event->getOrigin()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onQuit($event->getEntity()); - } - } - if(isset($this->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) { - foreach($this->UHCManager->getLevels()[$event->getTarget()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onJoin($event->getEntity()); - } - } - } - - - public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerChat($event); - $sc->onChat($event); - } - } - } - - - public function onPlayerCommandPreprocess(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerCommand($event); - } - } - } - - - public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerDeath($event); - $sc->onDeath($event); - } - } - } - - - public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerDropItem($event); - $sc->onPlayerDropItem($event); - } - } - } - - - public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerMove($event); - $sc->onMove($event); - } - } - } - - - public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerItemConsume($event); - $sc->onItemConsume($event); - } - } - } - - - public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onPlayerItemHeld($event); - $sc->onItemHeld($event); - } - } - } - - - public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onBlockBreak($event); - $sc->onBreak($event); - } - } - } - - - public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onBlockPlace($event); - $sc->onPlace($event); - } - } - } - - - public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onEntityDamage($event); - } - } - } - - - public function onProjectileLaunch(\pocketmine\event\entity\ProjectileLaunchEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onProjectileLaunch($event); - } - } - } - - - public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onProjectileHit($event); - } - } - } - - - public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onDataPacketReceive($event); - } - } - } - - - public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onDataPacketSend($event); - } - } - } - - - public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) { - foreach($this->UHCManager->getLevels() as $lvl => $world) { - foreach($world->scenarioManager->getUsedScenarios() as $sc) { - $sc->onServerCommand($event); - } - } - } - - public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) { - if(!isset($this->ft)) { - $this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->UHCManager->getStartedUHCs()), 10); - } - if(isset($this->quit[$event->getPlayer()->getName()]) and $event->getPlayer()->getLevel()->getName() == $this->quit[3]) { - $this->quit = explode("/", $this->quit[$event->getPlayer()->getName()]); - $event->getPlayer()->teleport($this->getServer()->getLevelByName($this->quit[3])); - $event->getPlayer()->teleport(new Vector3($this->quit[0], $this->quit[1], $this->quit[2])); - foreach($this->getServer()->getLevelByName($this->quit[3])->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()])) { - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onJoin($event->getPlayer()); - } - } - - } - - public function onPlayerQuit(\pocketmine\event\player\PlayerQuitEvent $event) { - if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) { - $this->quit[$event->getPlayer()->getName()] = $event->getPlayer()->x . "/" . $event->getPlayer()->y . "/" . $event->getPlayer()->z. "/" . $event->getPlayer()->getLevel()->getName(); - foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) { - $sc->onQuit($event->getPlayer()); - } - } - } - public function onGameStart(\Ad5001\UHC\event\GameStartEvent $event) {} + public function onGameStart(GameStartEvent $event) {} - public function onGameStop(\Ad5001\UHC\event\GameStopEvent $event) {} + public function onGameStop(GameStopEvent $event) {} } diff --git a/src/Ad5001/UHC/UHCGame.php b/src/Ad5001/UHC/UHCGame.php index e315ff6..9a34659 100644 --- a/src/Ad5001/UHC/UHCGame.php +++ b/src/Ad5001/UHC/UHCGame.php @@ -9,6 +9,8 @@ namespace Ad5001\UHC ; use pocketmine\command\CommandSender; use pocketmine\command\Command; +use pocketmine\entity\Effect; +use pocketmine\entity\EffectInstance; use pocketmine\event\Listener; use pocketmine\Server; use pocketmine\event\player\PlayerDeathEvent; @@ -55,12 +57,12 @@ public function __construct(Plugin $plugin, UHCWorld $world) { $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 = new EffectInstance(Effect::getEffect(Effect::DAMAGE_RESISTANCE)); $effect->setDuration(30*20); $effect->setAmplifier(99); $effect->setVisible(false); $player->addEffect($effect); - $this->m->getServer()->getScheduler()->scheduleDelayedTask(new StopResTask($this->m, $this->world->getPlayers()), 30*20); + $this->m->getScheduler()->scheduleDelayedTask(new StopResTask($this->m, $this->world->getPlayers()), 30*20); $player->sendMessage(Main::PREFIX . C::GREEN . "Game started ! Good luck {$player->getName()} !"); } } diff --git a/src/Ad5001/UHC/UHCManager.php b/src/Ad5001/UHC/UHCManager.php index c8f72bb..4b8917d 100644 --- a/src/Ad5001/UHC/UHCManager.php +++ b/src/Ad5001/UHC/UHCManager.php @@ -39,7 +39,7 @@ public function __construct(Main $main) { public function startUHC(Level $level) { if(isset($this->levels[$level->getName()]) and !isset($this->startedgames[$level->getName()])) { - $ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this->main, $this->levels[$level->getName()]), 20); + $ft = $this->main->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this->main, $this->levels[$level->getName()]), 20); $t->setHandler($ft); $this->startedgames[$level->getName()] = true; foreach($this->levels[$level->getName()]->scenarioManager->getUsedScenarios() as $sc) { @@ -64,7 +64,7 @@ public function stopUHC(Level $level, Player $player) { } } $this->startedgames = $started; - $this->main->getLogger()->info("Game " . $level->getName() . " stoped"); + $this->main->getLogger()->info("Game " . $level->getName() . " stopped"); return true; } return false; diff --git a/src/Ad5001/UHC/UHCWorld.php b/src/Ad5001/UHC/UHCWorld.php index f7b7add..d32d638 100644 --- a/src/Ad5001/UHC/UHCWorld.php +++ b/src/Ad5001/UHC/UHCWorld.php @@ -9,6 +9,9 @@ namespace Ad5001\UHC ; use pocketmine\command\CommandSender; use pocketmine\command\Command; +use pocketmine\event\block\BlockBreakEvent; +use pocketmine\event\block\BlockPlaceEvent; +use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\Listener; use pocketmine\Server; use pocketmine\level\Level; @@ -23,6 +26,14 @@ class UHCWorld implements Listener { + + public $lvl; + public $maxplayers; + public $players; + public $radius; + public $cfg; + public $scenarioManager; + public function __construct(Plugin $main, Level $level, int $maxplayers, int $radius) { $this->p = $main; $this->lvl = $level; @@ -45,14 +56,14 @@ public function isStarted() { } - public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) { + public function onEntityDamage(EntityDamageEvent $event) { if(!$this->isStarted()) { $event->setCancelled(); } } - public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) { + public function onBlockBreak(BlockBreakEvent $event) { if(!$this->isStarted()) { if(!$event->getPlayer()->isCreative()) { $event->setCancelled(); @@ -61,7 +72,7 @@ public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) { } - public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) { + public function onBlockPlace(BlockPlaceEvent $event) { if(!$this->isStarted()) { if(!$event->getPlayer()->isCreative()) { $event->setCancelled(); diff --git a/src/Ad5001/UHC/command/ScenarioCommand.php b/src/Ad5001/UHC/command/ScenarioCommand.php new file mode 100644 index 0000000..bda2494 --- /dev/null +++ b/src/Ad5001/UHC/command/ScenarioCommand.php @@ -0,0 +1,102 @@ +main = $uhc; + parent::__construct($name); + } + + public function getPlugin(): Plugin + { + return $this->main; + } + + public function execute(CommandSender $sender, string $commandLabel, array $args): bool + { + + if (!isset($args[0]) || !$sender instanceof Player || !$sender->hasPermission("uhc.scenarios.modify")) { + $sender->sendMessage(Main::PREFIX . "Error, make sure you have permission to use this command and are using the correct arguments"); + return false; + } + + if (isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->main->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { + switch ($args[0]) { + case "add": + if (isset($args[1])) { + if (isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) { + if (!isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { + $this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->addScenario($args[1]); + foreach ($sender->getLevel()->getPlayers() as $p) { + $p->sendTip(TextFormat::GOLD . TextFormat::BOLD . "Scenario added !" . PHP_EOL . TextFormat::RESET . TextFormat::GREEN . TextFormat::ITALIC . "+ " . $args[1]); + } + $sender->sendMessage(Main::PREFIX . TextFormat::GREEN . " Successfully added scenario $args[1] !"); + } else { + $sender->sendMessage(Main::PREFIX . TextFormat::DARK_RED . "Scenario $args[1] has already been added !"); + } + } else { + $sender->sendMessage(Main::PREFIX . TextFormat::DARK_RED . "Scenario $args[1] does not exists !"); + } + } else { + $sender->sendMessage(Main::PREFIX . TextFormat::DARK_RED . "Usage: /scenarios add "); + } + break; + case "remove": + case "rm": + case "delete": + case "del": + if (isset($args[1])) { + if (isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { + if (isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) { + $this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($args[1]); + foreach ($sender->getLevel()->getPlayers() as $p) { + $p->sendTip(TextFormat::GOLD . TextFormat::BOLD . "Scenario added !" . PHP_EOL . TextFormat::RESET . TextFormat::GREEN . TextFormat::ITALIC . "+ " . $args[1]); + } + $sender->sendMessage(Main::PREFIX . TextFormat::GREEN . " Successfully removed scenario $args[1] !"); + } else { + $sender->sendMessage(Main::PREFIX . TextFormat::DARK_RED . "Scenario $args[1] hasn't been added yet !"); + } + } else { + $sender->sendMessage(Main::PREFIX . TextFormat::DARK_RED . "Scenario $args[1] does not exists !"); + } + } else { + $sender->sendMessage(Main::PREFIX . TextFormat::DARK_RED . "Usage: /scenarios rm "); + } + break; + case "list": + $sender->sendMessage(Main::PREFIX . "Current server's scenarios: " . implode(", ", $this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios())); + break; + } + } else { + $sender->sendMessage(Main::PREFIX . "You're not in a UHC world !"); + } + + if (isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->main->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { + $scs = $this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios(); + $sender->sendMessage(Main::PREFIX . "Current enabled scenarios : " . implode(", ", $scs)); + } + + return true; + + } +} \ No newline at end of file diff --git a/src/Ad5001/UHC/command/UHCCommand.php b/src/Ad5001/UHC/command/UHCCommand.php new file mode 100644 index 0000000..e8d90e2 --- /dev/null +++ b/src/Ad5001/UHC/command/UHCCommand.php @@ -0,0 +1,101 @@ +main = $uhc; + parent::__construct($name); + } + + public function getPlugin(): Plugin + { + return $this->main; + } + + public function execute(CommandSender $sender, string $commandLabel, array $args) : bool { + if (!isset($args[0]) || !$sender instanceof Player) { + $sender->sendMessage(Main::PREFIX . "Missing argument, please type /uhc help for help!"); + return false; + } + switch (strtolower($args[0])) { + case "start": + if (isset($this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->main->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { + $this->main->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); + + foreach ($sender->getLevel()->getPlayers() as $player) { + $player->sendMessage(Main::PREFIX . "Starting game..."); + } + + $this->main->UHCManager->startUHC($sender->getLevel()); + + } else + $sender->sendMessage("You are not in a UHC world or UHC is already started"); + + return true; + + case "stop": + + if (isset($this->main->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) { + + $this->main->getLogger()->debug("Starting game {$sender->getLevel()->getName()}"); + + foreach ($sender->getLevel()->getPlayers() as $player) { + $player->sendMessage(Main::PREFIX . "Starting game..."); + } + + $this->main->UHCManager->stopUHC($sender->getLevel()); + + } else + $sender->sendMessage("You are not in a UHC world or UHC is already started"); + + return true; + + case "howtoplay": + case "?": + case "help": + + if (!isset($args[1])) { + $sender->sendMessage(Main::PREFIX . "Welcome to UHC help ! What would you like to know about UHC?\n" . Main::PREFIX . "- The game (/uhc howtoplay game)\n" . Main::PREFIX . "- The commands (/uhc howtoplay commands)\n" . Main::PREFIX . "- The scenarios (/uhc howtoplay scenarios)\n"); + } else { + switch (strtolower($args[1])) { + case "game": + $sender->sendMessage(Main::PREFIX . "UHC (aka Ultra Hardcore) is a new difficulty where it's hardcore but with no health regen except for golden apples and potions and only 1 life. The most popular 'UHC' Game is a PvP (Player versus Player) game where you're in this mode and you need to kill other players.\n" . Main::PREFIX . "What do you want to know next?\n" . Main::PREFIX . "- The commands (/uhc howtoplay commands)\n" . Main::PREFIX . "- The scenarios (/uhc howtoplay scenarios)\n"); + break; + case "commands": + $sender->sendMessage(Main::PREFIX . "This UHC Plugin has special commands. For players: /scenarios will give you the list of the current enabled scenarios. " . ($sender->isOp() ? "For OP: '/uhc start' start the uhc. '/uhc stop' finish it. '/scenarios add ' adds a scenario. '/scenario rm ' remove a scenario. '/scenarios list' gives you the list of installed scenarios.\n" : "\n") . Main::PREFIX . "What do you want to know next?\n" . Main::PREFIX . "- The game (/uhc howtoplay game)\n" . Main::PREFIX . "- The scenarios (/uhc howtoplay scenarios)"); + break; + case "scenarios": + $sender->sendMessage(Main::PREFIX . "Scenarios are 'addons' to the UHC that modify some mechanics or some parts of the game. You can download them or create them yourself. Look at ccommands if you want to know how to add a scenario to a game and look at https://github.com/Ad5001/UHC/wiki/What-are-Scenarios%3F. If you want to know more about a scenario, use /uhc howtoplay .\n" . Main::PREFIX . "What do you want to know next?\n" . Main::PREFIX . "- The game (/uhc howtoplay game)\n" . Main::PREFIX . "- The commands (/uhc howtoplay commands)\n"); + break; + default: + if (in_array($args[1], $this->main->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios())) + $sender->sendMessage(Main::PREFIX . "Help for $args[1]. " . $args[1]::help()); + else + $sender->sendMessage(Main::PREFIX . "No help for $args[1]"); + } + } + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/src/Ad5001/UHC/event/GameStartEvent.php b/src/Ad5001/UHC/event/GameStartEvent.php index 3216c72..f2f9be7 100644 --- a/src/Ad5001/UHC/event/GameStartEvent.php +++ b/src/Ad5001/UHC/event/GameStartEvent.php @@ -17,7 +17,7 @@ class GameStartEvent extends UHCEvent implements Cancellable { public static $handlerList = null; - protected $game; + public $game; protected $world; protected $players; diff --git a/src/Ad5001/UHC/event/GameStopEvent.php b/src/Ad5001/UHC/event/GameStopEvent.php index ef06a4b..b3e9c74 100644 --- a/src/Ad5001/UHC/event/GameStopEvent.php +++ b/src/Ad5001/UHC/event/GameStopEvent.php @@ -14,7 +14,7 @@ class GameStopEvent extends UHCEvent implements Cancellable { - protected $game; + public $game; protected $world; protected $winner; diff --git a/src/Ad5001/UHC/event/UHCEvent.php b/src/Ad5001/UHC/event/UHCEvent.php index 8a8ad57..ac91bbc 100644 --- a/src/Ad5001/UHC/event/UHCEvent.php +++ b/src/Ad5001/UHC/event/UHCEvent.php @@ -14,10 +14,10 @@ abstract class UHCEvent extends Event { + public $game; - public function getGame() { + public function getGame() { return $this->game; } - } \ No newline at end of file diff --git a/src/Ad5001/UHC/scenario/Scenario.php b/src/Ad5001/UHC/scenario/Scenario.php index ed5834a..e9c38c6 100644 --- a/src/Ad5001/UHC/scenario/Scenario.php +++ b/src/Ad5001/UHC/scenario/Scenario.php @@ -11,6 +11,21 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\PluginIdentifiableCommand; +use pocketmine\event\block\BlockBreakEvent; +use pocketmine\event\block\BlockPlaceEvent; +use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\event\entity\ProjectileHitEvent; +use pocketmine\event\entity\ProjectileLaunchEvent; +use pocketmine\event\player\PlayerChatEvent; +use pocketmine\event\player\PlayerCommandPreprocessEvent; +use pocketmine\event\player\PlayerDeathEvent; +use pocketmine\event\player\PlayerDropItemEvent; +use pocketmine\event\player\PlayerInteractEvent; +use pocketmine\event\player\PlayerItemConsumeEvent; +use pocketmine\event\player\PlayerItemHeldEvent; +use pocketmine\event\player\PlayerMoveEvent; +use pocketmine\event\server\DataPacketReceiveEvent; +use pocketmine\plugin\Plugin; use pocketmine\Server; use pocketmine\Player; use pocketmine\event\Listener; @@ -23,9 +38,11 @@ abstract class Scenario implements ScenarioInt, Listener { private $server; - private $game; + public $game; private $level; + + private $name; public function __construct(Server $server, UHCWorld $level) { $this->server = $server; @@ -58,94 +75,91 @@ public function getGame() { } - public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {} - - - public function onChat(\pocketmine\event\player\PlayerChatEvent $event) {} + public function onInteract(PlayerInteractEvent $event) {} - public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {} + public function onChat(PlayerChatEvent $event) {} - public function onPlayerCommand(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {} + public function onPlayerChat(PlayerChatEvent $event) {} - public function onDeath(\pocketmine\event\player\PlayerDeathEvent $event) {} + public function onPlayerCommand(PlayerCommandPreprocessEvent $event) {} - public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {} + public function onDeath(PlayerDeathEvent $event) {} - public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) {} + public function onPlayerDeath(PlayerDeathEvent $event) {} - public function onDrop(\pocketmine\event\player\PlayerDropItemEvent $event) {} + public function onPlayerDropItem(PlayerDropItemEvent $event) {} - public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {} + public function onDrop(PlayerDropItemEvent $event) {} - public function onMove(\pocketmine\event\player\PlayerMoveEvent $event) {} + public function onPlayerMove(PlayerMoveEvent $event) {} - public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {} + public function onMove(PlayerMoveEvent $event) {} - public function onItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {} + public function onPlayerItemConsume(PlayerItemConsumeEvent $event) {} - public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {} + public function onItemConsume(PlayerItemConsumeEvent $event) {} - public function onItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {} + public function onPlayerItemHeld(PlayerItemHeldEvent $event) {} - public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) {} + public function onItemHeld(PlayerItemHeldEvent $event) {} - public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) {} + public function onDataPacketReceive(DataPacketReceiveEvent $event) {} - public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {} + public function onDataPacketSend(DataPacketReceiveEvent $event) {} - public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {} + public function onBlockBreak(BlockBreakEvent$event) {} - public function onBreak(\pocketmine\event\block\BlockBreakEvent $event) {} + public function onBreak(BlockBreakEvent$event) {} - public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {} + public function onBlockPlace(BlockPlaceEvent $event) {} - public function onPlace(\pocketmine\event\block\BlockPlaceEvent $event) {} + public function onPlace(BlockPlaceEvent $event) {} - public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {} + public function onEntityDamage(EntityDamageEvent $event) {} - public function onProjectileLaunch(\pocketmine\event\entity\ProjectileLauchEvent $event) {} + public function onProjectileLaunch(ProjectileLaunchEvent $event) {} - public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) {} + public function onProjectileHit(ProjectileHitEvent $event) {} - public function getMain() { + public function getMain() : Plugin { return $this->server->getPluginManager()->getPlugin("UHC"); } - public function getServer() { + public function getServer() : Server { return $this->getMain()->getServer(); } - public static function help() { + public static function help() : string { return "This scenario does not purpose help."; } - public function getLogger() { + public function getLogger() : \Logger { return $this->getMain()->getLogger(); } @@ -168,7 +182,7 @@ public function saveConfig($cfg) { $scenarios = $this->getMain()->getConfig()->get("Scenarios"); $scenarios[$this->name] = $cfg; $this->getMain()->getConfig()->set("Scenarios", $scenarios); - return $this->getMain()->getConfig->save(); + return $this->getMain()->getConfig()->save(); } diff --git a/src/Ad5001/UHC/task/FetchPlayersTask.php b/src/Ad5001/UHC/task/FetchPlayersTask.php index 08aa9b8..348d959 100644 --- a/src/Ad5001/UHC/task/FetchPlayersTask.php +++ b/src/Ad5001/UHC/task/FetchPlayersTask.php @@ -6,23 +6,19 @@ # | |__| | | | | |____ # \____/|_| |_|\_____| # The most customisable UHC plugin for Minecraft PE ! -namespace Ad5001\UHC\task; -use pocketmine\command\CommandSender; -use pocketmine\command\Command; -use pocketmine\event\Listener; -use pocketmine\Server; -use pocketmine\level\Level; +namespace Ad5001\UHC\task; use pocketmine\plugin\Plugin; -use pocketmine\utils\TextFormat as C; -use pocketmine\scheduler\PluginTask; -use pocketmine\Player; +use pocketmine\scheduler\Task; use Ad5001\UHC\UHCWorld; use Ad5001\UHC\Main; -class FetchPlayersTask extends PluginTask { +class FetchPlayersTask extends Task { + + public $m; + public $worlds; + public function __construct(Plugin $plugin, array $worlds) { - parent::__construct($plugin); $this->m = $plugin; $this->worlds = $worlds; } diff --git a/src/Ad5001/UHC/task/StartGameTask.php b/src/Ad5001/UHC/task/StartGameTask.php index 3512238..abf5daa 100644 --- a/src/Ad5001/UHC/task/StartGameTask.php +++ b/src/Ad5001/UHC/task/StartGameTask.php @@ -6,24 +6,22 @@ # | |__| | | | | |____ # \____/|_| |_|\_____| # The most customisable UHC plugin for Minecraft PE ! -namespace Ad5001\UHC\task; -use pocketmine\command\CommandSender; -use pocketmine\command\Command; -use pocketmine\event\Listener; -use pocketmine\Server; -use pocketmine\level\Level; +namespace Ad5001\UHC\task; use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat as C; -use pocketmine\scheduler\PluginTask; -use pocketmine\Player; - +use pocketmine\scheduler\Task; use Ad5001\UHC\UHCWorld; use Ad5001\UHC\UHCGame; use Ad5001\UHC\Main; -class StartGameTask extends PluginTask { +class StartGameTask extends Task { + + public $main; + public $world; + public $seconds; + public $close; + public function __construct(Plugin $main, UHCWorld $world) { - parent::__construct($main); $this->main = $main; $this->world = $world; $this->seconds = 30; @@ -89,7 +87,6 @@ public function onRun($tick) { $this->main->UHCManager->addStartedUHC($this->world->getLevel()->getName(), new UHCGame($this->main, $this->world)); $this->close(); $this->seconds = -1; - break; } $this->seconds--; } diff --git a/src/Ad5001/UHC/task/StopResTask.php b/src/Ad5001/UHC/task/StopResTask.php index 21001fe..acdc318 100644 --- a/src/Ad5001/UHC/task/StopResTask.php +++ b/src/Ad5001/UHC/task/StopResTask.php @@ -6,26 +6,23 @@ # | |__| | | | | |____ # \____/|_| |_|\_____| # The most customisable UHC plugin for Minecraft PE ! -namespace Ad5001\UHC\task; -use pocketmine\command\CommandSender; -use pocketmine\command\Command; -use pocketmine\event\Listener; -use pocketmine\Server; -use pocketmine\level\Level; +namespace Ad5001\UHC\task; use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat as C; -use pocketmine\scheduler\PluginTask; -use pocketmine\Player; +use pocketmine\scheduler\Task; -use Ad5001\UHC\UHCWorld; use Ad5001\UHC\Main; -class StopResTask extends PluginTask { +class StopResTask extends Task { + + public $m; + public $players; + public function __construct(Plugin $plugin, array $players) { - parent::__construct($plugin); $this->m = $plugin; $this->players = $players; } + public function onRun($tick) { foreach($this->players as $player) { $player->sendMessage(Main::PREFIX . C::RED . "You can now take damage."); From 86a741b44da020bf006c80c8e46f23a8f16b0cda Mon Sep 17 00:00:00 2001 From: Adam <35859316+artulloss@users.noreply.github.com> Date: Wed, 21 Nov 2018 19:58:14 -0500 Subject: [PATCH 2/2] remove singleton :v --- src/Ad5001/UHC/Actions.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Ad5001/UHC/Actions.php b/src/Ad5001/UHC/Actions.php index dc2fcad..cd94a0c 100644 --- a/src/Ad5001/UHC/Actions.php +++ b/src/Ad5001/UHC/Actions.php @@ -35,13 +35,6 @@ class Actions implements Listener { public function __construct(Plugin $plugin) { $this->main = $plugin; - self::$instance = $this; - } - - public static $instance; - - static function getInstance() { - return self::$instance; } public function onLevelLoad(LevelLoadEvent $event) { @@ -247,4 +240,4 @@ public function onPlayerQuit(PlayerQuitEvent $event) { -} \ No newline at end of file +}