Browse Source

Fixing bugs....

master
Ad5001 4 years ago
parent
commit
0aac12eb77
9 changed files with 57 additions and 61 deletions
  1. +1
    -3
      config.yml
  2. +4
    -1
      plugin.yml
  3. +31
    -47
      src/Ad5001/UHC/Main.php
  4. +1
    -1
      src/Ad5001/UHC/UHCManager.php
  5. +1
    -1
      src/Ad5001/UHC/UHCWorld.php
  6. +4
    -1
      src/Ad5001/UHC/event/GameStartEvent.php
  7. +7
    -6
      src/Ad5001/UHC/event/GameStopEvent.php
  8. +4
    -0
      src/Ad5001/UHC/event/UHCEvent.php
  9. +4
    -1
      src/Ad5001/UHC/scenario/ScenarioManager.php

+ 1
- 3
config.yml View File

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

+ 4
- 1
plugin.yml View File

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

+ 31
- 47
src/Ad5001/UHC/Main.php View File

@@ -18,6 +18,7 @@ use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\item\Item;
use pocketmine\block\Block;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\Player;
@@ -38,7 +39,7 @@ class Main extends PluginBase implements Listener{
public function onLevelChange(EntityLevelChangeEvent $event) {
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) {
$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(){
$this->saveDefaultConfig();
mkdir($this->getDataFolder() . "scenarios");
@mkdir($this->getDataFolder() . "scenarios");
$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\GameStopEvent", $this, \pocketmine\plugin\EventPriority::NORMAL, new \pocketmine\plugin\MethodEventExecutor("onGameStop"), $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, true);
$this->UHCManager = new UHCManager($this);
$this->games = [];
$this->quit = [];
@@ -100,19 +84,19 @@ switch($cmd->getName()){
if(isset($args[0]) and $sender instanceof Player) {
switch($args[0]) {
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()}");
foreach($sender->getLevel()->getPlayers() as $player) {
$player->sendMessage(self::PREFIX . "Starting game...");
}
$this->UHCMananger->startUHC($sender->getLevel());
$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->UHCMananger->getStartedUHCs()[$sender->getLevel()->getName()])) {
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...");
@@ -128,13 +112,13 @@ switch($cmd->getName()){
break;
case "scenarios":
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]) {
case "add":
if(isset($args[1])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) {
if(!isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) {
$this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->addScenario($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]);
}
@@ -154,9 +138,9 @@ switch($cmd->getName()){
case "delete":
case "del":
if(isset($args[1])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios()[$args[1]])) {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()[$args[1]])) {
$this->UHCMananger->getLevels()[$sender->getLevel()->getName()]->scenarioManager->rmScenario($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->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]);
}
@@ -172,15 +156,15 @@ switch($cmd->getName()){
}
break;
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;
}
} else {
$sender->sendMessage(self::PREFIX . "You're not in a UHC world !")
$sender->sendMessage(self::PREFIX . "You're not in a UHC world !");
}
} else {
if(isset($this->UHCMananger->getLevels()[$sender->getLevel()->getName()]) and !isset($this->UHCMananger->getStartedGames()[$sender->getLevel()->getName()])) {
$sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $this->UHCManager[$sender->getLevel()->getName()]->scenarioManager->getUsedScenarios()))
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()));
}
}
break;
@@ -195,7 +179,7 @@ return false;

# 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;
if($event->getBlock()->getId() == Block::SIGN_POST or $event->getBlock()->getId() == Block::WALL_SIGN) {
$t = $event->getBlock()->getLevel()->getTile($event->getBlock());
@@ -359,17 +343,6 @@ return false;
$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) {
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()])) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onJoin($event->getPlayer());


+ 1
- 1
src/Ad5001/UHC/UHCManager.php View File

@@ -60,7 +60,7 @@ class UHCManager {

public function registerLevel(Level $level) {
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 {
$this->main->getLogger()->warning("{$level->getName()} is already registered.");
}


+ 1
- 1
src/Ad5001/UHC/UHCWorld.php View File

@@ -44,7 +44,7 @@ class UHCWorld {


public function getName() {
return $this->level->getName();
return $this->lvl->getName();
}




+ 4
- 1
src/Ad5001/UHC/event/GameStartEvent.php View File

@@ -14,10 +14,13 @@ use Ad5001\UHC\UHCWorld;


class GameStartEvent extends UHCEvent implements Cancellable {

public static $handlerList = null;

protected $game;
protected $world;
protected $players;
static $handlerList = null;
public function __construct($game, $world, $players) {
$this->game = $game;
$this->world = $world;


+ 7
- 6
src/Ad5001/UHC/event/GameStopEvent.php View File

@@ -7,17 +7,18 @@
# \____/|_| |_|\_____|
# The most customisable UHC plugin for Minecraft PE !
namespace Ad5001\UHC\event;
use pocketmine\event\Cancellable.php;
use pocketmine\event\Cancellable;
use Ad5001\UHC\event\UHCEvent;
use Ad5001\UHC\UHCGame;
use Ad5001\UHC\UHCWorld;

protected $game;
protected $world;
protected $winner;


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;
}

public function setWinner(Player $winner) {
$this->winner = $winner;
}

+ 4
- 0
src/Ad5001/UHC/event/UHCEvent.php View File

@@ -7,7 +7,11 @@
# \____/|_| |_|\_____|
# The most customisable UHC plugin for Minecraft PE !
namespace Ad5001\UHC\event;


use pocketmine\event\Event;


abstract class UHCEvent extends Event {




+ 4
- 1
src/Ad5001/UHC/scenario/ScenarioManager.php View File

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





Loading…
Cancel
Save