From aa072d7f5897cdc83aa78e713d540a05d3fd898d Mon Sep 17 00:00:00 2001 From: Cheese Date: Thu, 2 Jul 2015 12:05:48 +1000 Subject: [PATCH] improved updateevent --- .../plugin/core/updater/UpdateEvent.php | 17 ++++-- .../plugin/core/updater/UpdateType.php | 32 ++++++------ .../mineplex/plugin/core/updater/Updater.php | 52 +++++++++++-------- .../src/mineplex/plugin/events/TickEvent.php | 22 -------- .../src/mineplex/plugin/tasks/TickTask.php | 23 -------- 5 files changed, 57 insertions(+), 89 deletions(-) delete mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/events/TickEvent.php delete mode 100644 Pocket/plugins/Mineplex/src/mineplex/plugin/tasks/TickTask.php diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php index 5d9b4b5c1..d8d552dc4 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateEvent.php @@ -14,15 +14,22 @@ class UpdateEvent extends Event { 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); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php index 7f7349dfd..ad92a0389 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/UpdateType.php @@ -11,22 +11,22 @@ namespace mineplex\plugin\core\updater; class UpdateType { - const MIN_64 = 3840000; - const MIN_32 = 1920000; - const MIN_16 = 960000; - const MIN_08 = 480000; - const MIN_04 = 240000; - const MIN_02 = 120000; - const MIN_01 = 60000; - const SLOWEST = 32000; - const SLOWER = 16000; - const SLOW = 4000; - const TWOSEC = 2000; - const SEC = 1000; - const FAST = 500; - const FASTER = 250; - const FASTEST = 125; - const TICK = 49; + const M64 = 3840000; + conSt M32 = 1920000; + conSt M16 = 960000; + conSt M8 = 480000; + conSt M4 = 240000; + conSt M2 = 120000; + conSt M1 = 60000; + conSt S32 = 32000; + conSt S16 = 16000; + conSt S8 = 8000; + conSt S4 = 4000; + conSt S2 = 2000; + conSt S1 = 1000; + conSt MS500 = 500; + conSt MS250 = 250; + conSt MS125 = 125; public $time; diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php index 4d833ed2e..e219e179c 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/core/updater/Updater.php @@ -21,38 +21,44 @@ class Updater extends PluginTask { $this->plugin = $host; $this->owner = $host; + $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask($this, 1); $this->updateTypes = array( - new UpdateType(UpdateType::TICK) - , new UpdateType(UpdateType::FASTEST) - , new UpdateType(UpdateType::FASTER) - , new UpdateType(UpdateType::FAST) - , new UpdateType(UpdateType::SEC) - , new UpdateType(UpdateType::TWOSEC) - , new UpdateType(UpdateType::SLOW) - , new UpdateType(UpdateType::SLOWER) - , new UpdateType(UpdateType::SLOWEST) - , new UpdateType(UpdateType::MIN_01) - , new UpdateType(UpdateType::MIN_02) - , new UpdateType(UpdateType::MIN_04) - , new UpdateType(UpdateType::MIN_08) - , new UpdateType(UpdateType::MIN_16) - , new UpdateType(UpdateType::MIN_32) - , new UpdateType(UpdateType::MIN_64)); + new UpdateType(UpdateType::MS125) + , new UpdateType(UpdateType::MS250) + , new UpdateType(UpdateType::MS500) + , new UpdateType(UpdateType::S1) + , new UpdateType(UpdateType::S2) + , new UpdateType(UpdateType::S4) + , new UpdateType(UpdateType::S8) + , new UpdateType(UpdateType::S16) + , new UpdateType(UpdateType::S32) + , new UpdateType(UpdateType::M1) + , new UpdateType(UpdateType::M2) + , new UpdateType(UpdateType::M4) + , new UpdateType(UpdateType::M8) + , new UpdateType(UpdateType::M16) + , new UpdateType(UpdateType::M32)); } + //Fires off an event each tick, containing a list of all updateTypes public function onRun($currentTick) { + $updateTypes = array(); + $timeSpent = round(microtime(true) * 1000) - $this->last; $this->last = round(microtime(true) * 1000); - foreach ($this->updateTypes as &$updateType) - { - if ($timeSpent >= $updateType->time) - { - $this->plugin->getServer()->getPluginManager()->callEvent(new UpdateEvent($updateType->time)); - } - } + foreach ($this->updateTypes as &$updateType) + { + if ($timeSpent >= $updateType->time) + { + array_push($updateTypes, $updateType); + } + } + + //Call Event + $this->plugin->getServer()->getPluginManager()->callEvent(new UpdateEvent($currentTick, $updateTypes)); } } \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/events/TickEvent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/events/TickEvent.php deleted file mode 100644 index acdb410e3..000000000 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/events/TickEvent.php +++ /dev/null @@ -1,22 +0,0 @@ -tick = $currentTick; - } - - public function getTick() - { - return $this->tick; - } -} \ No newline at end of file diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/tasks/TickTask.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/tasks/TickTask.php deleted file mode 100644 index 39905d1f5..000000000 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/tasks/TickTask.php +++ /dev/null @@ -1,23 +0,0 @@ -plugin = $host; - $this->owner = $host; - } - - public function onRun($currentTick) - { - $this->plugin->getServer()->getPluginManager()->callEvent(new TickEvent($currentTick)); - } -} \ No newline at end of file