Bug Fixes about scenarios ... and a lot more stuff.
Starting the howtoplay
This commit is contained in:
parent
be870bc924
commit
6cd5bec03a
10 changed files with 102 additions and 65 deletions
|
@ -22,6 +22,8 @@ commands:
|
||||||
permission: uhc.command.scenarios
|
permission: uhc.command.scenarios
|
||||||
permissions:
|
permissions:
|
||||||
uhc.command.main:
|
uhc.command.main:
|
||||||
|
default: true
|
||||||
|
uhc.command.start&stop:
|
||||||
default: op
|
default: op
|
||||||
uhc.command.scenarios:
|
uhc.command.scenarios:
|
||||||
default: true
|
default: true
|
||||||
|
|
16
scenarios/Example.php
Normal file
16
scenarios/Example.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Ad5001\UHC\scenario\Scenario;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class ExampleScenario extends Scenario {
|
||||||
|
|
||||||
|
public function onStart() {
|
||||||
|
|
||||||
|
$this->getLogger()->info("Started !");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onJoin(Player $player) {
|
||||||
|
$player->sendMessage("Welcome to this example UHC Scenario !");
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,7 +65,6 @@ class Main extends PluginBase implements Listener{
|
||||||
$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\\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\\GameStopEvent", $this, \pocketmine\event\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $this, false);
|
||||||
$this->UHCManager = new UHCManager($this);
|
$this->UHCManager = new UHCManager($this);
|
||||||
$this->UHCManager->getStartedUHCs() = [];
|
|
||||||
$this->quit = [];
|
$this->quit = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +77,21 @@ class Main extends PluginBase implements Listener{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getClasses(string $file) {
|
||||||
|
$tokens = token_get_all($file);
|
||||||
|
$class_token = false;
|
||||||
|
foreach ($tokens as $token) {
|
||||||
|
if (is_array($token)) {
|
||||||
|
if ($token[0] == T_CLASS) {
|
||||||
|
$class_token = true;
|
||||||
|
} else if ($class_token && $token[0] == T_STRING) {
|
||||||
|
return $token[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
|
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
|
||||||
switch($cmd->getName()){
|
switch($cmd->getName()){
|
||||||
case "uhc":
|
case "uhc":
|
||||||
|
@ -112,7 +126,7 @@ switch($cmd->getName()){
|
||||||
break;
|
break;
|
||||||
case "scenarios":
|
case "scenarios":
|
||||||
if(isset($args[0]) and $sender instanceof Player and $sender->hasPermission("uhc.scenarios.modify")) {
|
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->getStartedGames()[$sender->getLevel()->getName()])) {
|
if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) {
|
||||||
switch($args[0]) {
|
switch($args[0]) {
|
||||||
case "add":
|
case "add":
|
||||||
if(isset($args[1])) {
|
if(isset($args[1])) {
|
||||||
|
@ -124,7 +138,7 @@ switch($cmd->getName()){
|
||||||
}
|
}
|
||||||
$sender->sendMessage(self::PREFIX . C::GREEN . " Succefully added scenario $args[1] !");
|
$sender->sendMessage(self::PREFIX . C::GREEN . " Succefully added scenario $args[1] !");
|
||||||
} else {
|
} else {
|
||||||
$sender->sendMessage(slef::PREFIX . C::DARK_RED . "Scenario $args[1] has already been added !");
|
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] has already been added !");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] does not exists !");
|
$sender->sendMessage(self::PREFIX . C::DARK_RED . "Scenario $args[1] does not exists !");
|
||||||
|
@ -138,7 +152,7 @@ switch($cmd->getName()){
|
||||||
case "delete":
|
case "delete":
|
||||||
case "del":
|
case "del":
|
||||||
if(isset($args[1])) {
|
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]])) {
|
||||||
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]);
|
$this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($args[1]);
|
||||||
foreach($sender->getLevel()->getPlayers() as $p) {
|
foreach($sender->getLevel()->getPlayers() as $p) {
|
||||||
|
@ -163,8 +177,9 @@ switch($cmd->getName()){
|
||||||
$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->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedGames()[$sender->getLevel()->getName()])) {
|
if(isset($this->UHCManager->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCManager->getStartedUHCs()[$sender->getLevel()->getName()])) {
|
||||||
$sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $this->UHCManager[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()));
|
$scs = $this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios();
|
||||||
|
$sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $scs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -180,28 +195,8 @@ return false;
|
||||||
# Event Listener !
|
# Event Listener !
|
||||||
|
|
||||||
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {
|
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {
|
||||||
// echo $event->getBlock()->getId() . "=/=" . Block::SIGN_POST ."=/=" . Block::WALL_SIGN;
|
|
||||||
if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) {
|
|
||||||
$t = $event->getBlock()->getLevel()->getTile($event->getBlock());
|
|
||||||
// echo "Sign.";
|
|
||||||
foreach($this->UHCManager->getLevels() as $class) {
|
|
||||||
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($class->getLevel()->getName() == $lvl) {
|
|
||||||
if($this->UHCManager->getLevels()[$lvl]->isStarted()) {
|
|
||||||
$event->getPlayer()->teleport($class->getLevel()->getSafeSpawn());
|
|
||||||
$event->getPlayer()->setGamemode(3);
|
|
||||||
} else {
|
|
||||||
$event->getPlayer()->teleport($class->getLevel()->getSafeSpawn());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onInteract($event);
|
$sc->onInteract($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,12 +205,12 @@ return false;
|
||||||
|
|
||||||
public function onEntityLevelChange(EntityLevelChangeEvent $event) {
|
public function onEntityLevelChange(EntityLevelChangeEvent $event) {
|
||||||
if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) {
|
if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) {
|
||||||
foreach($this->UHCManager->getLevels()[$event->getOrigin()->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->UHCManager->getLevels()[$event->getOrigin()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onQuit($event->getPlayer());
|
$sc->onQuit($event->getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isset($this->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) {
|
if(isset($this->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) {
|
||||||
foreach($this->UHCManager->getLevels()[$event->getTarget()->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->UHCManager->getLevels()[$event->getTarget()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onJoin($event->getEntity());
|
$sc->onJoin($event->getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,7 +219,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {
|
public function onPlayerChat(\pocketmine\event\player\PlayerChatEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerChat($event);
|
$sc->onPlayerChat($event);
|
||||||
$sc->onChat($event);
|
$sc->onChat($event);
|
||||||
}
|
}
|
||||||
|
@ -234,7 +229,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerCommandPreprocess(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
|
public function onPlayerCommandPreprocess(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerCommand($event);
|
$sc->onPlayerCommand($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,7 +238,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {
|
public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerDeath($event);
|
$sc->onPlayerDeath($event);
|
||||||
$sc->onDeath($event);
|
$sc->onDeath($event);
|
||||||
}
|
}
|
||||||
|
@ -253,7 +248,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) {
|
public function onPlayerDropItem(\pocketmine\event\player\PlayerDropItemEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerDropItem($event);
|
$sc->onPlayerDropItem($event);
|
||||||
$sc->onPlayerDropItem($event);
|
$sc->onPlayerDropItem($event);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +258,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {
|
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerMove($event);
|
$sc->onPlayerMove($event);
|
||||||
$sc->onMove($event);
|
$sc->onMove($event);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +268,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {
|
public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerItemConsume($event);
|
$sc->onPlayerItemConsume($event);
|
||||||
$sc->onItemConsume($event);
|
$sc->onItemConsume($event);
|
||||||
}
|
}
|
||||||
|
@ -283,7 +278,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {
|
public function onPlayerItemHeld(\pocketmine\event\player\PlayerItemHeldEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onPlayerItemHeld($event);
|
$sc->onPlayerItemHeld($event);
|
||||||
$sc->onItemHeld($event);
|
$sc->onItemHeld($event);
|
||||||
}
|
}
|
||||||
|
@ -293,7 +288,7 @@ return false;
|
||||||
|
|
||||||
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {
|
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onBlockBreak($event);
|
$sc->onBlockBreak($event);
|
||||||
$sc->onBreak($event);
|
$sc->onBreak($event);
|
||||||
}
|
}
|
||||||
|
@ -303,7 +298,7 @@ return false;
|
||||||
|
|
||||||
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
|
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onBlockPlace($event);
|
$sc->onBlockPlace($event);
|
||||||
$sc->onPlace($event);
|
$sc->onPlace($event);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +308,7 @@ return false;
|
||||||
|
|
||||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
|
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
|
||||||
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
||||||
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onEntityDamage($event);
|
$sc->onEntityDamage($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +317,7 @@ return false;
|
||||||
|
|
||||||
public function onProjectileLaunch(\pocketmine\event\entity\ProjectileLaunchEvent $event) {
|
public function onProjectileLaunch(\pocketmine\event\entity\ProjectileLaunchEvent $event) {
|
||||||
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
||||||
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onProjectileLaunch($event);
|
$sc->onProjectileLaunch($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +326,7 @@ return false;
|
||||||
|
|
||||||
public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) {
|
public function onProjectileHit(\pocketmine\event\entity\ProjectileHitEvent $event) {
|
||||||
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
if(isset($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()])) {
|
||||||
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->UHCManager->getLevels()[$event->getEntity()->getLevel()->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onProjectileHit($event);
|
$sc->onProjectileHit($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,7 +335,7 @@ return false;
|
||||||
|
|
||||||
public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) {
|
public function onDataPacketReceive(\pocketmine\event\server\DataPacketReceiveEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onDataPacketReceive($event);
|
$sc->onDataPacketReceive($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +344,7 @@ return false;
|
||||||
|
|
||||||
public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) {
|
public function onDataPacketSend(\pocketmine\event\server\DataPacketSendEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onDataPacketSend($event);
|
$sc->onDataPacketSend($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,7 +353,7 @@ return false;
|
||||||
|
|
||||||
public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {
|
public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {
|
||||||
foreach($this->UHCManager->getLevels() as $lvl => $world) {
|
foreach($this->UHCManager->getLevels() as $lvl => $world) {
|
||||||
foreach($world->scenarioManager->getScenarios() as $sc) {
|
foreach($world->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onServerCommand($event);
|
$sc->onServerCommand($event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +361,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) {
|
public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) {
|
||||||
if(!isset($this->ft)) {
|
if(!isset($this->ft)) {
|
||||||
$this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->UHCManager->getLevels()), 10);
|
$this->ft = $this->getServer()->getScheduler()->scheduleRepeatingTask(new FetchPlayersTask($this, $this->UHCManager->getStartedUHCs()), 10);
|
||||||
}
|
}
|
||||||
if(isset($this->quit[$event->getPlayer()->getName()])) {
|
if(isset($this->quit[$event->getPlayer()->getName()])) {
|
||||||
$quit = explode("/", $this->quit[$event->getPlayer()->getName()]);
|
$quit = explode("/", $this->quit[$event->getPlayer()->getName()]);
|
||||||
|
@ -377,7 +372,7 @@ return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onJoin($event->getPlayer());
|
$sc->onJoin($event->getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +381,7 @@ return false;
|
||||||
|
|
||||||
public function onPlayerQuit(\pocketmine\event\player\PlayerQuitEvent $event) {
|
public function onPlayerQuit(\pocketmine\event\player\PlayerQuitEvent $event) {
|
||||||
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->getUsedScenarios() as $sc) {
|
||||||
$sc->onQuit($event->getPlayers());
|
$sc->onQuit($event->getPlayers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ class UHCGame implements Listener{
|
||||||
public function onPlayerDeath(PlayerDeathEvent $event) {
|
public function onPlayerDeath(PlayerDeathEvent $event) {
|
||||||
if($event->getPlayer()->getLevel()->getName() === $this->world->getName() and !$this->cancelled) {
|
if($event->getPlayer()->getLevel()->getName() === $this->world->getName() and !$this->cancelled) {
|
||||||
foreach($event->getPlayer()->getLevel()->getPlayers() as $p) {
|
foreach($event->getPlayer()->getLevel()->getPlayers() as $p) {
|
||||||
$p->sendMessage(Main::PREFIX . C::YELLOW . $event->getPlayer()->getName() . " died. " . (count($this->world->getLevel()->getPlayers) - 2)) . " players left !");
|
$p->sendMessage(Main::PREFIX . C::YELLOW . $event->getPlayer()->getName() . " died. " . (count($this->world->getLevel()->getPlayers()) - 1) . " players left !");
|
||||||
}
|
}
|
||||||
$this->respawn[$event->getPlayer()->getName()] = true;
|
$this->respawn[$event->getPlayer()->getName()] = true;
|
||||||
$pls = [];
|
$pls = [];
|
||||||
|
|
|
@ -42,7 +42,7 @@ class UHCManager {
|
||||||
$ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this->main, $this->levels[$level->getName()]), 20);
|
$ft = $this->main->getServer()->getScheduler()->scheduleRepeatingTask($t = new StartGameTask($this->main, $this->levels[$level->getName()]), 20);
|
||||||
$t->setHandler($ft);
|
$t->setHandler($ft);
|
||||||
$this->startedgames[$level->getName()] = true;
|
$this->startedgames[$level->getName()] = true;
|
||||||
foreach($this->levels[$level->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->levels[$level->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onStart();
|
$sc->onStart();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -55,7 +55,7 @@ class UHCManager {
|
||||||
public function stopUHC(Level $level) {
|
public function stopUHC(Level $level) {
|
||||||
if(isset($this->startedgames[$level->getName()])) {
|
if(isset($this->startedgames[$level->getName()])) {
|
||||||
unset($this->startedgames[$level->getName()]);
|
unset($this->startedgames[$level->getName()]);
|
||||||
foreach($this->levels[$level->getName()]->scenarioManager->getScenarios() as $sc) {
|
foreach($this->levels[$level->getName()]->scenarioManager->getUsedScenarios() as $sc) {
|
||||||
$sc->onQuit();
|
$sc->onQuit();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,4 +82,10 @@ class UHCManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addStartedUHC(string $name, UHCGame $game) {
|
||||||
|
$this->startedgames[$name] = $game;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -39,6 +39,11 @@ class UHCWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function isStarted() {
|
||||||
|
return isset($this->p->UHCManager->getStartedUHCs()[$this->lvl->getName()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getPlayers() {
|
public function getPlayers() {
|
||||||
return $this->players;
|
return $this->players;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,12 @@ use pocketmine\command\Command;
|
||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\PluginIdentifiableCommand;
|
use pocketmine\command\PluginIdentifiableCommand;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
|
use pocketmine\Player;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
use Ad5001\UHC\scenario\ScenarioInt;
|
use Ad5001\UHC\scenario\ScenarioInt;
|
||||||
use Ad5001\UHC\Main;
|
use Ad5001\UHC\Main;
|
||||||
|
use Ad5001\UHC\UHCWorld;
|
||||||
|
|
||||||
abstract class Scenario implements ScenarioInt, Listener {
|
abstract class Scenario implements ScenarioInt, Listener {
|
||||||
|
|
||||||
|
@ -25,14 +27,13 @@ abstract class Scenario implements ScenarioInt, Listener {
|
||||||
|
|
||||||
private $level;
|
private $level;
|
||||||
|
|
||||||
public function __construct(Server $server, UHCGame $game, UHCWorld $level) {
|
public function __construct(Server $server, UHCWorld $level) {
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->game = $game;
|
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function onStart()
|
public function onStart() {}
|
||||||
|
|
||||||
|
|
||||||
public function onStop() {}
|
public function onStop() {}
|
||||||
|
@ -44,6 +45,19 @@ abstract class Scenario implements ScenarioInt, Listener {
|
||||||
public function onQuit(Player $player) {}
|
public function onQuit(Player $player) {}
|
||||||
|
|
||||||
|
|
||||||
|
public function getLevel() {
|
||||||
|
return $this->level;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getGame() {
|
||||||
|
if(isset($this->main->UHCManager->getStartedUHCs()[$this->level->getName()])) {
|
||||||
|
return $this->main->UHCManager->getStartedUHCs()[$this->level->getName()];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {}
|
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,6 +169,6 @@ abstract class Scenario implements ScenarioInt, Listener {
|
||||||
|
|
||||||
|
|
||||||
public function getScenarioFolder() {
|
public function getScenarioFolder() {
|
||||||
return realPath($this->getMain()->getDataFolder() . "scenarios/");
|
return $this->getMain()->getDataFolder() . "scenarios/";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,10 +8,12 @@
|
||||||
# The most customisable UHC plugin for Minecraft PE !
|
# The most customisable UHC plugin for Minecraft PE !
|
||||||
namespace Ad5001\UHC\scenario;
|
namespace Ad5001\UHC\scenario;
|
||||||
use pocketmine\command\CommandExecutor;
|
use pocketmine\command\CommandExecutor;
|
||||||
|
use pocketmine\command\Command;
|
||||||
|
use pocketmine\command\CommandSender;
|
||||||
|
|
||||||
interface ScenarioInt extends CommandExecutor {
|
interface ScenarioInt {
|
||||||
/* When the scenario is activating */
|
/* When the scenario is activating */
|
||||||
public function onEnable();
|
public function onStart();
|
||||||
|
|
||||||
|
|
||||||
/* When the scenario is stoping (end of UHC) */
|
/* When the scenario is stoping (end of UHC) */
|
||||||
|
@ -27,12 +29,7 @@ interface ScenarioInt extends CommandExecutor {
|
||||||
|
|
||||||
|
|
||||||
/* Save the config */
|
/* Save the config */
|
||||||
public function saveConfig();
|
public function saveConfig($cfg);
|
||||||
|
|
||||||
|
|
||||||
/* Test when an event is throwed */
|
|
||||||
public function onPlayerEvent(\pocketmine\event\player\PlayerEvent $event);
|
|
||||||
public function onEvent(\pocketmine\event\Event $event);
|
|
||||||
|
|
||||||
|
|
||||||
/* Get the scenario folder */
|
/* Get the scenario folder */
|
||||||
|
@ -41,4 +38,6 @@ interface ScenarioInt extends CommandExecutor {
|
||||||
|
|
||||||
/* Reload the config */
|
/* Reload the config */
|
||||||
public function reloadConfig();
|
public function reloadConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -48,7 +48,7 @@ class ScenarioManager {
|
||||||
|
|
||||||
public function addScenario(string $name) {
|
public function addScenario(string $name) {
|
||||||
if(!isset($this->usedscenarios[$name]) and !$this->level->isStarted()) {
|
if(!isset($this->usedscenarios[$name]) and !$this->level->isStarted()) {
|
||||||
$this->usedscenarios[$name] = new $name($this->main, $this->level);
|
$this->usedscenarios[$name] = new $name($this->server, $this->level);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -86,7 +86,7 @@ class StartGameTask extends PluginTask {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
$this->main->games[$this->world->getLevel()->getName()] = new UHCGame($this->main, $this->world);
|
$this->main->UHCManager->addStartedUHC($this->world->getLevel()->getName(), new UHCGame($this->main, $this->world));
|
||||||
$this->close();
|
$this->close();
|
||||||
$this->seconds = -1;
|
$this->seconds = -1;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue