Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex

This commit is contained in:
Aaron Brock 2015-07-01 22:12:42 -04:00
commit 61d2247cee
5 changed files with 57 additions and 89 deletions

View File

@ -14,15 +14,22 @@ class UpdateEvent extends Event
{ {
public static $handlerList = null; public static $handlerList = null;
public $time; public $tick;
public $updateTypes;
public function __construct($time) public function __construct($tick, $updateTypes)
{ {
$this->time = $time; $this->tick = $tick;
$this->updateTypes = $updateTypes;
} }
public function getTime() public function getTick()
{ {
return $this->time; return $this->tick;
}
public function isTiming($type)
{
return in_array(type, $this->updateTypes);
} }
} }

View File

@ -11,22 +11,22 @@ namespace mineplex\plugin\core\updater;
class UpdateType class UpdateType
{ {
const MIN_64 = 3840000; const M64 = 3840000;
const MIN_32 = 1920000; conSt M32 = 1920000;
const MIN_16 = 960000; conSt M16 = 960000;
const MIN_08 = 480000; conSt M8 = 480000;
const MIN_04 = 240000; conSt M4 = 240000;
const MIN_02 = 120000; conSt M2 = 120000;
const MIN_01 = 60000; conSt M1 = 60000;
const SLOWEST = 32000; conSt S32 = 32000;
const SLOWER = 16000; conSt S16 = 16000;
const SLOW = 4000; conSt S8 = 8000;
const TWOSEC = 2000; conSt S4 = 4000;
const SEC = 1000; conSt S2 = 2000;
const FAST = 500; conSt S1 = 1000;
const FASTER = 250; conSt MS500 = 500;
const FASTEST = 125; conSt MS250 = 250;
const TICK = 49; conSt MS125 = 125;
public $time; public $time;

View File

@ -21,38 +21,44 @@ class Updater extends PluginTask
{ {
$this->plugin = $host; $this->plugin = $host;
$this->owner = $host; $this->owner = $host;
$this->plugin->getServer()->getScheduler()->scheduleRepeatingTask($this, 1); $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask($this, 1);
$this->updateTypes = array( $this->updateTypes = array(
new UpdateType(UpdateType::TICK) new UpdateType(UpdateType::MS125)
, new UpdateType(UpdateType::FASTEST) , new UpdateType(UpdateType::MS250)
, new UpdateType(UpdateType::FASTER) , new UpdateType(UpdateType::MS500)
, new UpdateType(UpdateType::FAST) , new UpdateType(UpdateType::S1)
, new UpdateType(UpdateType::SEC) , new UpdateType(UpdateType::S2)
, new UpdateType(UpdateType::TWOSEC) , new UpdateType(UpdateType::S4)
, new UpdateType(UpdateType::SLOW) , new UpdateType(UpdateType::S8)
, new UpdateType(UpdateType::SLOWER) , new UpdateType(UpdateType::S16)
, new UpdateType(UpdateType::SLOWEST) , new UpdateType(UpdateType::S32)
, new UpdateType(UpdateType::MIN_01) , new UpdateType(UpdateType::M1)
, new UpdateType(UpdateType::MIN_02) , new UpdateType(UpdateType::M2)
, new UpdateType(UpdateType::MIN_04) , new UpdateType(UpdateType::M4)
, new UpdateType(UpdateType::MIN_08) , new UpdateType(UpdateType::M8)
, new UpdateType(UpdateType::MIN_16) , new UpdateType(UpdateType::M16)
, new UpdateType(UpdateType::MIN_32) , new UpdateType(UpdateType::M32));
, new UpdateType(UpdateType::MIN_64));
} }
//Fires off an event each tick, containing a list of all updateTypes
public function onRun($currentTick) public function onRun($currentTick)
{ {
$updateTypes = array();
$timeSpent = round(microtime(true) * 1000) - $this->last; $timeSpent = round(microtime(true) * 1000) - $this->last;
$this->last = round(microtime(true) * 1000); $this->last = round(microtime(true) * 1000);
foreach ($this->updateTypes as &$updateType) foreach ($this->updateTypes as &$updateType)
{ {
if ($timeSpent >= $updateType->time) if ($timeSpent >= $updateType->time)
{ {
$this->plugin->getServer()->getPluginManager()->callEvent(new UpdateEvent($updateType->time)); array_push($updateTypes, $updateType);
} }
} }
//Call Event
$this->plugin->getServer()->getPluginManager()->callEvent(new UpdateEvent($currentTick, $updateTypes));
} }
} }

View File

@ -1,22 +0,0 @@
<?php
namespace mineplex\plugin\events;
use pocketmine\event\Event;
class TickEvent extends Event
{
public static $handlerList = null;
public $tick;
public function __construct($currentTick)
{
$this->tick = $currentTick;
}
public function getTick()
{
return $this->tick;
}
}

View File

@ -1,23 +0,0 @@
<?php
namespace mineplex\plugin\tasks;
use mineplex\plugin\events\TickEvent;
use mineplex\plugin\Main;
use pocketmine\scheduler\PluginTask;
class TickTask extends PluginTask
{
public $plugin;
public function __construct(Main $host)
{
$this->plugin = $host;
$this->owner = $host;
}
public function onRun($currentTick)
{
$this->plugin->getServer()->getPluginManager()->callEvent(new TickEvent($currentTick));
}
}