Rewards API - Wertzui123/Rewards GitHub Wiki
Rewards comes with a simple but powerful API:
API Methods
Main::getWaitTime(Player $player): int
This method returns how long a player has to wait until they can claim their rewards again. It returns an integer which is the time to wait in seconds. Sourcecode:
/**
* @api
* Returns how long a player still has to wait until they can claim their rewards again
* @param Player $player
* @return int
*/
public function getWaitTime(Player $player){
return $this->playerDataFile->get(strtolower($player->getName()), ["last" => time(), "streak" => 0])["last"] + $this->getConfig()->getNested('wait_time.' . $this->getPermissionGroup($player));
}
Main::getStreak(Player $player): int
This method returns how big the streak of a player is. It returns an integer. Sourcecode:
/**
* @api
* Returns the given players reward streak
* @param Player $player
* @return int
*/
public function getStreak(Player $player){
return $this->playerDataFile->get(strtolower($player->getName()), ["last" => time(), "streak" => 0])["streak"];
}
Main::getPermissionGroup(Player $player): string
This method returns the given players permission group. It returns a string. Sourcecode:
/**
* @api
* Returns the permission group for a player
* @param Player $player
* @return string
*/
public function getPermissionGroup(Player $player){
foreach ($this->getConfig()->get('permission_groups') as $group){
if($player->hasPermission("rewards.permissions." . $group)){
return $group;
}
}
return "default";
}
Events
RewardClaimEvent
This is called when someone claims their rewards. You can cancell it. Sourcecode:
<?php
namespace Wertzui123\Rewards\events;
use pocketmine\event\Cancellable;
use pocketmine\event\player\PlayerEvent;
use pocketmine\Player;
class RewardClaimEvent extends PlayerEvent implements Cancellable
{
/** @var string[] */
private $commands;
/** @var int */
private $streak;
/**
* RewardClaimEvent constructor.
* @param Player $player
* @param string[] $commands
* @param int $streak
*/
public function __construct(Player $player, array $commands, $streak)
{
$this->player = $player;
$this->commands = $commands;
$this->streak = $streak;
}
/**
* Returns the commands to execute
* @return string[]
*/
public function getCommands(){
return $this->commands;
}
/**
* Updates the commands to execute
* @param string[] $commands
*/
public function setCommands(array $commands){
$this->commands = $commands;
}
/**
* Returns the reward streak of the player
* @return int
*/
public function getStreak(){
return $this->streak;
}
}