API - HimmelKreis4865/BetterAC GitHub Wiki
Welcome to the overview of how BetterAC's API works.
It's not finished yet, but you can already see some basics here.
Change Config values while the server is running
Therefore you can access a property of BetterAC.php:
<?php
use HimmelKreis4865\BetterAC;
class TestClass
{
public function changeValues()
{
// This would change the number of maximal warns until punishment starts to 6, but only as long as the server is running!
BetterAC::getInstance()->configManager->maxWarnsForPunish = 6;
}
}
to see all possible properties, you can look at ConfigSettingsManager.php
Write a message to players when they got warned or stop warning if they are op!
use pocketmine\event\Listener;
use HimmelKreis4865\BetterAC\Events\PlayerWarnEvent;
class EventListener implements Listener
{
public function onWarn(PlayerWarnEvent $event)
{
if ($event->getPlayer()->isOp()) {
$event->setCancelled(); // checked if the player is op, if so the event will be cancelled
return; // exit here, because we go on with other stuff
}
if ($event->getCause() === PlayerWarnEvent::CAUSE_CUSTOM) {
$event->setCancelled(); // checked if the the reason is custom = no reason sent by BetterAC & then cancel the event!
return; // exit here, because we go on with sending a message
}
// PlayerWarnEvent::getCauseString($cause) will return a string with the name of module.
$event->getPlayer()->sendMessage("§cStop hacking! You got warned for usage of §7" . PlayerWarnEvent::getCauseString($event->getCause()) . "§c!");
}
}
Get Device type of any player via command
-> This is just a very simple command without permissions & much messages
public function execute(CommandSender $sender, string $commandLabel, array $args)
{
if (!isset($args[0])) return; // there should be an argument for the playername
if (($target = Server::getInstance()->getPlayer($args[0]) === null) return; // just getting the Player $target via Server->getPlayer() check & also testing if player is not online
$sender->sendMessage("§6Device of §7" . $target->getName() . " §6is: §7" . BetterAC::getInstance()->getDeviceName($target->getName());
}
So the basic methods are:
BetterAC::getInstance()->getDeviceName($playername)
which will return unknown
, if the player was not registered what should never happen! mobile
for phone / tablet / ..., computer
for computers and console
for example ps4
BetterAC::getInstance()->getDeviceOS($playername)
will return -1
if the player was not registered, 0
if it's mobile, 1
if its computer (pc) and 2
for a console player.