Created
January 28, 2021 22:01
-
-
Save TheNewHEROBRINEX/fc01eceb0a6cabb068814343e344d14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* @name SetKeepXpTest | |
* @main TheNewHEROBRINE\SetKeepXpTest\SetKeepXpTest | |
* @api 4.0.0 | |
* @version 1.0.0 | |
* @author TheNewHEROBRINE | |
*/ | |
namespace TheNewHEROBRINE\SetKeepXpTest { | |
use pocketmine\command\Command; | |
use pocketmine\command\CommandSender; | |
use pocketmine\command\utils\InvalidCommandSyntaxException; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerDeathEvent; | |
use pocketmine\plugin\Plugin; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\plugin\PluginOwned; | |
use pocketmine\utils\TextFormat; | |
use function count; | |
class SetKeepXpTest extends PluginBase implements Listener{ | |
public bool $keepXp = false; | |
public function onEnable() : void{ | |
$this->getServer()->getCommandMap()->register($this->getName(), new KeepXpCommand($this)); | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function onPlayerDeath(PlayerDeathEvent $event) : void{ | |
if($this->keepXp){ | |
$event->setKeepXp(true); | |
} | |
} | |
} | |
class KeepXpCommand extends Command implements PluginOwned{ | |
private SetKeepXpTest $plugin; | |
public function __construct(SetKeepXpTest $plugin){ | |
parent::__construct("keepxp", "Manage experience keeping on player death", "/keepxp <status|toggle>"); | |
$this->plugin = $plugin; | |
} | |
public function execute(CommandSender $sender, string $commandLabel, array $args) : void{ | |
if(count($args) !== 1){ | |
throw new InvalidCommandSyntaxException(); | |
} | |
switch($args[0]){ | |
case "status": | |
if($this->plugin->keepXp){ | |
$sender->sendMessage("Experience keeping is currently " . TextFormat::GREEN . "enabled"); | |
}else{ | |
$sender->sendMessage("Experience keeping is currently " . TextFormat::RED . "disabled"); | |
} | |
break; | |
case "toggle": | |
$this->plugin->keepXp = !$this->plugin->keepXp; | |
if($this->plugin->keepXp){ | |
$sender->sendMessage("Experience keeping has been " . TextFormat::GREEN . "enabled"); | |
}else{ | |
$sender->sendMessage("Experience keeping has been disabled " . TextFormat::RED . "disabled"); | |
} | |
break; | |
default: | |
throw new InvalidCommandSyntaxException(); | |
} | |
} | |
public function getOwningPlugin() : Plugin{ | |
return $this->plugin; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment