-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAgentFlagsExample.php
More file actions
35 lines (27 loc) · 1003 Bytes
/
Copy pathAgentFlagsExample.php
File metadata and controls
35 lines (27 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace imperazim\easylibrary\examples\agent;
use imperazim\agent\api\AgentFlagsAPI;
use imperazim\agent\api\AgentRuntimeAPI;
use imperazim\agent\constant\AgentNetworkFlags;
use imperazim\agent\event\AgentNetworkFlagChangedEvent;
use pocketmine\event\Listener;
final class AgentFlagsExample implements Listener{
public function enableDoubleXp(int $seconds = 1800) : bool{
if(!AgentRuntimeAPI::isAvailable()){
return false;
}
$response = AgentFlagsAPI::set(AgentNetworkFlags::DOUBLE_XP, true, $seconds, 'Example booster');
return ($response['ok'] ?? false) === true;
}
public function onFlagChanged(AgentNetworkFlagChangedEvent $event) : void{
if($event->getFlag() !== AgentNetworkFlags::DOUBLE_XP){
return;
}
if($event->isActive()){
// Enable local multiplier/cache here.
return;
}
// Disable local multiplier/cache here.
}
}