Skip to content

Commit

Permalink
Major update. New format sign yml file!
Browse files Browse the repository at this point in the history
  • Loading branch information
xpyctum committed Dec 19, 2015
1 parent 5cce780 commit 7f7e0ea
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 98 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SignStatus
main: SignStatus\SignStatus
version: 2.1.1
version: 3.0.0
author: xpyctum
api: [1.0.0]
load: POSTWORLD
Expand Down
8 changes: 8 additions & 0 deletions resources/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#You can use this params:
#{ONLINE} {MAX_ONLINE} {WORLD_NAME}
#{TPS] [SERVER_LOAD]
format:
1: "[STATUS]"
2: "{ONLINE}/{MAX_ONLINE}"
3: "TPS: {TPS}"
4: "LOAD: {SERVER_LOAD}%"
95 changes: 29 additions & 66 deletions src/SignStatus/SignStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
namespace SignStatus;

use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\SignChangeEvent;
use pocketmine\event\Listener;
use pocketmine\item\Item;
use pocketmine\utils\Config;
use pocketmine\plugin\PluginBase;
use pocketmine\tile\Sign;
use pocketmine\event\block\SignChangeEvent;
use pocketmine\tile\Tile;
use pocketmine\utils\Config;
use pocketmine\utils\TextFormat as F;

/*
Expand Down Expand Up @@ -35,6 +36,9 @@ class SignStatus extends PluginBase implements Listener{
/** @var Config config */
public $config;

/** @var Config config */
public $format;

/** @var string */
public $prefix = "§4[§2SignStatus§4]§6 ";

Expand All @@ -47,10 +51,12 @@ public function onEnable(){
$this->saveResource("sign.yml");
$this->saveResource("translations.yml");
$this->saveResource("config.yml");
$this->saveResource("format.yml");

$this->sign = new Config($this->getDataFolder()."sign.yml", Config::YAML); //FIXED !
$this->translation = new Config($this->getDataFolder()."translations.yml",Config::YAML);
$this->config = new Config($this->getDataFolder()."config.yml",Config::YAML);
$this->format = new Config($this->getDataFolder()."format.yml",Config::YAML);
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$time = $this->config->get("time");
if(!(is_numeric($time))){
Expand All @@ -66,69 +72,31 @@ public function onDisable(){
$this->getLogger()->notice(F::RED."SignStatus disabled");
}

/**
* @deprecated
* @return mixed
*/
public function enabled(){
return $this->sign->get("sign")['enabled'];
}
/**
* @deprecated
* @return mixed
*/
public function level(){
return $this->sign->get("sign")['level'];
}
/**
* @deprecated
* @return mixed
*/
public function getThisSignX(){
return $this->sign->get("sign")['x'];
}
/**
* @deprecated
* @return mixed
*/
public function getThisSignY(){
return $this->sign->get("sign")['y'];
}
/**
* @deprecated
* @return mixed
*/
public function getThisSignZ(){
return $this->sign->get("sign")['z'];
}


/**
* @param SignChangeEvent $event
*/
public function onSignChange(SignChangeEvent $event){
$player = $event->getPlayer();
if(strtolower(trim($event->getLine(0))) == "status" || strtolower(trim($event->getLine(0))) == "[status]"){
if($player->hasPermission("signstatus")){
if($player->hasPermission("signstatus") or $player->hasPermission("signstatus.create")){
$tps = $this->getServer()->getTicksPerSecond();
$p = count($this->getServer()->getOnlinePlayers());
$level = $event->getBlock()->getLevel()->getName();
$full = $this->getServer()->getMaxPlayers();
$event->setText(F::GREEN."[STATUS]",F::YELLOW."TPS: [$tps]",F::AQUA."ONLINE: "..F::GREEN.$p.F::WHITE."/".F::RED.$full",F::GOLD."******");
/*
$event->setLine(0,F::GREEN."[STATUS]");
$event->setLine(1,F::YELLOW."TPS: [".$tps."]");
$event->setLine(2,F::AQUA."ONLINE: ".F::GREEN.$p.F::WHITE."/".F::RED.$full."");
$event->setLine(3,F::GOLD."******");
*/

$this->sign->setNested("sign.x", $event->getBlock()->getX());
$this->sign->setNested("sign.y", $event->getBlock()->getY());
$this->sign->setNested("sign.z", $event->getBlock()->getZ());
$this->sign->setNested("sign.enabled", true);
$this->sign->setNested("sign.level", $level);
$this->sign->save();
$this->sign->reload();
$load = $this->getServer()->getTickUsage();
$format = $this->format->getAll();

for ($x = 0; $x <= 3; $x++) {
$v = $format["format"][$x+1];
$v = str_replace("{ONLINE}", $p, $v);
$v = str_replace("{MAX_ONLINE}", $full, $v);
$v = str_replace("{WORLD_NAME}", $level, $v);
$v = str_replace("{TPS}", $tps, $v);
$v = str_replace("{SERVER_LOAD}", $load, $v);
$event->setLine($x,$v);
}
//$event->setText(F::GREEN."[STATUS]",F::YELLOW."TPS: [$tps]",F::AQUA."ONLINE: ".F::GREEN.$p.F::WHITE."/".F::RED.$full.",".F::GOLD."******");
$event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_created"));
}else{
$player->sendMessage($this->prefix.$this->translation->get("sign_no_perms"));
Expand All @@ -146,18 +114,13 @@ public function onPlayerBreakBlock(BlockBreakEvent $event){
if (($tile = $signt->getLevel()->getTile($signt))){
if($tile instanceof Sign) {
if ($event->getBlock()->getX() == $this->sign->getNested("sign.x") && $event->getBlock()->getY() == $this->sign->getNested("sign.y") && $event->getBlock()->getZ() == $this->sign->getNested("sign.z")) {
if($event->getPlayer()->hasPermission("signstatus.break")) {
$this->sign->setNested("sign.x", $event->getBlock()->getX());
$this->sign->setNested("sign.y", $event->getBlock()->getY());
$this->sign->setNested("sign.z", $event->getBlock()->getZ());
$this->sign->setNested("sign.enabled", false);
$this->sign->setNested("sign.level", "world");
$this->sign->save();
$this->sign->reload();
$event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_destroyed"));
}else{
$event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_no_perms"));
$event->setCancelled();
if($tile->getText()[0] == strtolower($this->format->getAll()["format"][1])) {
if ($event->getPlayer()->hasPermission("signstatus.break")) {
$event->getPlayer()->sendMessage($this->prefix . $this->translation->get("sign_destroyed"));
} else {
$event->getPlayer()->sendMessage($this->prefix . $this->translation->get("sign_no_perms"));
$event->setCancelled();
}
}
}
}
Expand Down
72 changes: 41 additions & 31 deletions src/SignStatus/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,49 @@

namespace SignStatus;

use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\String;
use pocketmine\scheduler\PluginTask;
use pocketmine\Server;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\tile\Sign;
use pocketmine\utils\TextFormat as F;

class Task extends PluginTask{
private $plugin;
private $countable;
public function __construct(SignStatus $plugin){
parent::__construct($plugin);
$this->plugin = $plugin;
$this->countable = 0;
}
class Task extends PluginTask
{
private $plugin;
private $countable;

public function onRun($currentTick){
$val = $this->plugin->sign->get("sign")["enabled"];
if($val == "true" || $val == true){
foreach($this->plugin->getServer()->getLevels() as $levels){
foreach($levels->getTiles() as $tile){
if($tile instanceof Sign){
if($tile->getText()[0] == F::GREEN."[STATUS]"){
$tps = $this->plugin->getServer()->getTicksPerSecond();
$p = count($this->plugin->getServer()->getOnlinePlayers());
$full = $this->plugin->getServer()->getMaxPlayers();
$count = $this->countable++; //For debug
$load = $this->plugin->getServer()->getTickUsage();
$tile->setText(F::GREEN."[STATUS]", F::YELLOW."TPS: [".$tps."]", F::AQUA."ONLINE: ".F::GREEN.$p.F::WHITE."/".F::RED.$full."", F::GOLD."LOAD: ".F::DARK_BLUE.$load. " %");
}
}
}
}
}
}
public function __construct(SignStatus $plugin)
{
parent::__construct($plugin);
$this->plugin = $plugin;
$this->countable = 0;
}

public function onRun($currentTick){
$format = $this->plugin->format->getAll();
foreach ($this->plugin->getServer()->getLevels() as $levels) {
foreach ($levels->getTiles() as $tile) {
if ($tile instanceof Sign) {
if (strtolower($tile->getText()[0]) == strtolower($this->plugin->format->getAll()["format"][1])) {
$tps = $this->plugin->getServer()->getTicksPerSecond();
$p = count($this->plugin->getServer()->getOnlinePlayers());
$full = $this->plugin->getServer()->getMaxPlayers();
$count = $this->countable++; //For debug
$load = $this->plugin->getServer()->getTickUsage();
$level = $tile->getLevel()->getName();
$index = [];
for ($x = 0; $x <= 3; $x++) {
$v = $format["format"][$x + 1];
$v = str_replace("{ONLINE}", $p, $v);
$v = str_replace("{MAX_ONLINE}", $full, $v);
$v = str_replace("{WORLD_NAME}", $level, $v);
$v = str_replace("{TPS}", $tps, $v);
$v = str_replace("{SERVER_LOAD}", $load, $v);
$index[$x] = $v;
}
$tile->setText($index[0],$index[1],$index[2],$index[3]);
}
}
}
}
}
}

0 comments on commit 7f7e0ea

Please sign in to comment.