Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
Version 0.3.1
Browse files Browse the repository at this point in the history
This should fully work now, and it should be accepted by Poggit!
 * Fixed timer autodisable
 * Fixed server just completely NOT working
  • Loading branch information
AndreasHGK committed Mar 7, 2018
1 parent 108d24b commit 62428f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: AutoMineReset
main: AndreasHGK\AutoMineReset\Main
version: 0.3.0
version: 0.3.1
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10, 3.0.0-ALPHA11]
commands:
mr:
Expand Down
67 changes: 26 additions & 41 deletions src/AndreasHGK/AutoMineReset/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\command\Command;
use pocketmine\scheduler\PluginTask;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\utils\TextFormat as C;
class Main extends PluginBase{

public $paused = false;
public $sec = 0;
private $sec = 0;
public $autopaused = false;
public $interval = 600;
private $interval = 600;

public function onLoad(){
$this->getLogger()->notice(C::GREEN." Loading...");
Expand All @@ -30,17 +31,12 @@ public function onLoad(){
}

public function prepLoop(){
global $interval;
global $sec;
$sec = 1;
$interval = $this->getConfig()->get('reset-time');
$milliseconds = 1000;
$seconds=(int)$milliseconds/1000;
while(true)
{
$this->update();
sleep($seconds);
}
$this->sec = 1;
$this->interval = $this->getConfig()->get('reset-time');
$this->milliseconds = 1000;
$task = new Updater($this); // A class that extends pocketmine\scheduler\PluginTask
// The Task handler
$h = $this->getServer()->getScheduler()->scheduleRepeatingTask($task, 20);
}

public function onEnable(){
Expand All @@ -50,30 +46,26 @@ public function onEnable(){


public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool{
global $autopaused;
global $paused;
switch($command->getName()){
case mr:
if($sender->hasPermission("minereset.command.resetall")){
$this->resetAll();
$count = count($this->getApi()->getMineManager());
$sender->sendMessage("Queued reset for {$success}/{$count} mines.");
}
else{
$sender->sendMessage(TextFormat::RED . "You do not have permission to run this command." . TextFormat::RESET);
}

case autoreset:
if($sender->hasPermission("amr.autoreset")){
if($paused == true){
$paused = false;
if($this->paused == true){
$this->paused = false;
$sender->sendMessage(C::BOLD.C::GREEN."Autoreset enabled!");
$this->getLogger()->notice(C::GREEN." The timer has been enabled by ".$sender."!");
}else{
$paused = true;
$this->paused = true;
$sender->sendMessage(C::BOLD.C::GREEN."Autoreset disabled!");
$this->getLogger()->notice(C::GREEN." The timer has been disabled by ".$sender."!");
$autopaused = false;
$this->autopaused = false;
}
} else {
$sender->sendMessage(TextFormat::RED . "You do not have permission to run this command." . TextFormat::RESET);
Expand All @@ -82,23 +74,21 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar

public function autostop(){
static $y = false;
global $paused;
global $autopaused;
if($this->getConfig()->get('sleep-when-empty') == true){
if(count($this->getServer()->getOnlinePlayers()) < 0){
if($paused == false){
if(count($this->getServer()->getOnlinePlayers()) != 0){
if($this->paused == true){
if($y == true){
$paused = false;
$autopaused = false;
$this->paused = false;
$this->autopaused = false;
$y = false;
$this->getLogger()->notice(C::GREEN." The timer has been auto-enabled!");
}
}
} else {
if($y == false) {
$paused = true;
$this->paused = true;
$y = true;
$autopaused = true;
$this->autopaused = true;
$this->getLogger()->notice(C::GREEN." The timer has been auto-disabled!");
}
}
Expand All @@ -119,25 +109,20 @@ public function onDisable(){
public function update() {
$this->autostop();
$this->bettertimer();
global $sec;
global $interval;
if($sec >= $interval){
if($this->sec >= $this->interval){
$this->resetAll();
}
}

public function betterTimer() {
global $interval;
global $paused;
global $sec;
if($paused == false){
$sec++;
if($this->paused == false){
$this->sec++;
}
if($sec > $interval){
$sec = 1;
if($this->sec > $this->interval){
$this->sec = 1;
}
//$this->getLogger()->notice(C::GREEN." Debug says(sec): ".$sec);
//$this->getLogger()->notice(C::GREEN." Debug says(int): ".$interval);
//$this->getLogger()->notice(C::GREEN."Debug: ".$this->sec);
//$this->getLogger()->notice(C::GREEN."Debug: ".$this->interval);
}

}
16 changes: 16 additions & 0 deletions src/AndreasHGK/AutoMineReset/Updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace AndreasHGK\AutoMineReset;
use pocketmine\scheduler\PluginTask;
use AndreasHGK\AutoMineReset\Main as M;

class Updater extends PluginTask {

public function __construct(Main $plugin){
parent::__construct($plugin);
$this->plugin = $plugin;
}

public function onRun($tick) {
$this->plugin->update();
}
}

0 comments on commit 62428f2

Please sign in to comment.