Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sub-command> [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
Expand Down
243 changes: 243 additions & 0 deletions src/Ad5001/UHC/Actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<?php

namespace Ad5001\UHC;

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\level\LevelLoadEvent;
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\PlayerJoinEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\server\CommandEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\server\DataPacketSendEvent;
use Ad5001\UHC\task\FetchPlayersTask;

use pocketmine\event\Listener;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat;

class Actions implements Listener {

public $main;

public function __construct(Plugin $plugin)
{
$this->main = $plugin;
}

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



}
Loading