Browse Source

Events

pull/6/head
Ad5001 4 years ago
parent
commit
6a533249ff
4 changed files with 216 additions and 1 deletions
  1. +208
    -0
      src/Ad5001/UHC/Main.php
  2. +6
    -0
      src/Ad5001/UHC/scenario/Scenario.php
  3. +1
    -1
      src/Ad5001/UHC/scenario/ScenarioManager.php
  4. +1
    -0
      src/Ad5001/UHC/task/FetchPlayersTask.php

+ 208
- 0
src/Ad5001/UHC/Main.php View File

@@ -162,4 +162,212 @@ switch($cmd->getName()){
}
return false;
}






# Event Listener !

public function onInteract(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()])) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onInteract($event);
}
}
}


public function onEntityLevelChange(EntityLevelChangeEvent $event) {
if(isset($this->UHCManager->getLevels()[$event->getOrigin()->getName()]) and $event->getEntity() instanceof Player) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onQuit($event->getPlayer());
}
}
if(isset($this->UHCManager->getLevels()[$event->getTarget()->getName()]) and $event->getEntity() instanceof Player) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onJoin($event->getPlayer());
}
}
}


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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getScenarios() 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->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() 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->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() 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->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() 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->getScenarios() 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->getScenarios() as $sc) {
$sc->onDataPacketSend($event);
}
}
}


public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {
foreach($this->UHCManager->getLevels() as $lvl => $world) {
foreach($world->scenarioManager->getScenarios() as $sc) {
$sc->onServerCommand($event);
}
}
}

public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) {
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());
}
}

}

public function onPlayerQuit(\pocketmine\event\player\PlayerQuitEvent $event) {
if(isset($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()])) {
foreach($this->UHCManager->getLevels()[$event->getPlayer()->getLevel()->getName()]->scenarioManager->getScenarios() as $sc) {
$sc->onQuit($event->getPlayers());
}
}
}
}

+ 6
- 0
src/Ad5001/UHC/scenario/Scenario.php View File

@@ -36,6 +36,12 @@ abstract class Scenario implements ScenarioInt, Listener {
public function onStop() {}


public function onJoin(Player $player) {}


public function onQuit(Player $player) {}

public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {}


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

@@ -64,7 +64,7 @@ class ScenarioManager {


public function getLevel() {
return $this->levels;
return $this->level;
}




+ 1
- 0
src/Ad5001/UHC/task/FetchPlayersTask.php View File

@@ -39,5 +39,6 @@ class FetchPlayersTask extends PluginTask {
$this->m->UHCManager->startGame($world);
}
}
$this->worlds = $this->m->UHCManager->getLevels();
}
}

Loading…
Cancel
Save