Skip to content

Commit

Permalink
Version 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Falkirks committed Sep 20, 2014
1 parent 2268cd0 commit 6f0836d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
@@ -1,6 +1,6 @@
name: BuyCraft
main: buycraft\BuyCraft
version: 0.6.1
version: 0.7
author: Falk
api: [1.0.0]
load: POSTWORLD
Expand Down
8 changes: 1 addition & 7 deletions resources/README.md
Expand Up @@ -30,10 +30,4 @@ This port does not support recent payment signs.

Listed below are the permission nodes for the plugin:

buycraft.admin - Enables use of the "/buycraft <reload/forcecheck/secret>" commands


---- A FURTHER NOTE (This applies to Java Source and API) --------------------------------------------------------

Modifying the source code is allowed. You are not allowed to use the source code in another Bukkit plugin without prior permission.
Use of http://api.buycraft.net is only for this plugin and integrating Buycraft on to your own website. Any other use is not allowed.
buycraft.admin - Enables use of the "/buycraft <reload/forcecheck/secret>" commands
32 changes: 10 additions & 22 deletions src/buycraft/task/PendingPlayerCheckerTask.php
Expand Up @@ -5,40 +5,25 @@
use buycraft\api\ApiTask;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\scheduler\PluginTask;
use pocketmine\scheduler\TaskHandler;

/*
* Looks for players with commands pending
* Does NOT perform any API communication, uses another task.
*/
class PendingPlayerCheckerTask extends ApiTask implements Listener{
class PendingPlayerCheckerTask extends PluginTask implements Listener{
private $pendingPlayers = [];
/** @var TaskHandler */
private $handler;
public function onRun($tick, $manual = false){
if($this->getOwner()->getConfig()->get('commandChecker') || $manual){
$this->data["action"] = Actions::PENDING_PLAYERS;
$res = $this->send();
if($res !== false && is_array($res["payload"]["pendingPlayers"])){
$playersToFetch = [];
foreach($res["payload"]["pendingPlayers"] as $player){
$p = $this->getOwner()->getServer()->getPlayerExact($player);
if($p !== null && $p->isOnline()){
$playersToFetch[] = $p->getName();
}
else{
$this->pendingPlayers[] = $player;
}
}
if($res["payload"]["offlineCommands"] || count($playersToFetch) > 0){
$fetch = new CommandFetchTask($this->getOwner(), ["users" => $playersToFetch, "offlineCommands" => $res["payload"]["offlineCommands"]]);
$fetch->call();
}
}
$task = new PendingUsersTask($this->getOwner());
$task->call();
}
}
public function call(){
$this->getOwner()->getServer()->getPluginManager()->registerEvents($this, $this->getOwner());
$this->handler = $this->getScheduler()->scheduleRepeatingTask($this, 40);
$this->handler = $this->getOwner()->getServer()->getScheduler()->scheduleRepeatingTask($this, 40);
}
public function onPlayerJoin(PlayerJoinEvent $event){
if(isset($this->pendingPlayers[$event->getPlayer()->getName()])){
Expand All @@ -50,8 +35,11 @@ public function onPlayerJoin(PlayerJoinEvent $event){
public function resetPendingPlayers(){
$this->pendingPlayers = [];
}
public function addPendingPlayer($name){
$this->pendingPlayers[] = $name;
}
public function setUpdateInterval($interval){
$this->handler->cancel();
$this->handler = $this->getScheduler()->scheduleRepeatingTask($this, $interval);
$this->handler = $this->getOwner()->getServer()->getScheduler()->scheduleRepeatingTask($this, $interval);
}
}
41 changes: 41 additions & 0 deletions src/buycraft/task/PendingUsersTask.php
@@ -0,0 +1,41 @@
<?php
namespace buycraft\task;


use buycraft\api\Actions;
use buycraft\api\ApiAsyncTask;
use buycraft\BuyCraft;
use pocketmine\Player;
/*
* This is an Async task which allows PendingPlayerCheckerTask to
* send requests outside the main thread.
*/
class PendingUsersTask extends ApiAsyncTask{
public function onConfig(BuyCraft $plugin){
$data = $this->getData();
$data["action"] = Actions::PENDING_PLAYERS;
$this->setData($data);
}
public function onRun(){
$this->send();
}
public function onOutput(BuyCraft $main, Player $player = null){
$res = $this->getOutput();
if($res !== false && is_array($res["payload"]["pendingPlayers"])){
$playersToFetch = [];
foreach($res["payload"]["pendingPlayers"] as $player){
$p = $main->getServer()->getPlayerExact($player);
if($p !== null && $p->isOnline()){
$playersToFetch[] = $p->getName();
}
else{
$main->getPendingPlayerCheckerTask()->addPendingPlayer($player);
}
}
if($res["payload"]["offlineCommands"] || count($playersToFetch) > 0){
$fetch = new CommandFetchTask($main, ["users" => $playersToFetch, "offlineCommands" => $res["payload"]["offlineCommands"]]);
$fetch->call();
}
}
}
}

0 comments on commit 6f0836d

Please sign in to comment.