Skip to content

Commit

Permalink
Ooops...
Browse files Browse the repository at this point in the history
use import from api 2.0.0 :)
  • Loading branch information
xpyctum committed Dec 19, 2015
1 parent 7f7e0ea commit e768a0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
50 changes: 26 additions & 24 deletions src/SignStatus/SignStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use pocketmine\item\Item;
use pocketmine\plugin\PluginBase;
use pocketmine\tile\Sign;
use pocketmine\tile\Tile;
use pocketmine\utils\Config;
use pocketmine\utils\TextFormat as F;

Expand All @@ -24,8 +23,9 @@
─███──█──────█───█──█──█──█─█─█───█
██─██─█──────█───████──█──███─█───█
*/
//TODO: Make configurable format of sign
class SignStatus extends PluginBase implements Listener{

class SignStatus extends PluginBase implements Listener
{

/** @var Config sign */
public $sign;
Expand All @@ -39,11 +39,11 @@ class SignStatus extends PluginBase implements Listener{
/** @var Config config */
public $format;

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

public function onEnable(){
if(!is_dir($this->getDataFolder())){
if (!is_dir($this->getDataFolder())) {
@mkdir($this->getDataFolder());
//Use default, not PM.
}
Expand All @@ -53,23 +53,25 @@ public function onEnable(){
$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->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))){
if (!(is_numeric($time))) {
$time = 20;
$this->getLogger()->alert("Can't read time for update sign! Please, check your config file! Default: ".F::AQUA." 1 ".F::WHITE." second");
}else{ $time = $time * 20; }
$this->getLogger()->alert("Can't read time for update sign! Please, check your config file! Default: " . F::AQUA . " 1 " . F::WHITE . " second");
} else {
$time = $time * 20;
}
$this->getServer()->getScheduler()->scheduleRepeatingTask(new Task($this), $time);
$this->getLogger()->notice(F::GREEN."SignStatus loaded");
$this->getLogger()->notice(F::GREEN . "SignStatus loaded");

}

public function onDisable(){
$this->getLogger()->notice(F::RED."SignStatus disabled");
$this->getLogger()->notice(F::RED . "SignStatus disabled");
}


Expand All @@ -78,8 +80,8 @@ public function onDisable(){
*/
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") or $player->hasPermission("signstatus.create")){
if (strtolower(trim($event->getLine(0))) == "status" || strtolower(trim($event->getLine(0))) == "[status]") {
if ($player->hasPermission("signstatus") or $player->hasPermission("signstatus.create")) {
$tps = $this->getServer()->getTicksPerSecond();
$p = count($this->getServer()->getOnlinePlayers());
$level = $event->getBlock()->getLevel()->getName();
Expand All @@ -88,18 +90,18 @@ public function onSignChange(SignChangeEvent $event){
$format = $this->format->getAll();

for ($x = 0; $x <= 3; $x++) {
$v = $format["format"][$x+1];
$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->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"));
$event->getPlayer()->sendMessage($this->prefix . $this->translation->get("sign_created"));
} else {
$player->sendMessage($this->prefix . $this->translation->get("sign_no_perms"));
$event->setCancelled();
}
}
Expand All @@ -111,10 +113,10 @@ public function onSignChange(SignChangeEvent $event){
public function onPlayerBreakBlock(BlockBreakEvent $event){
if ($event->getBlock()->getID() == Item::SIGN || $event->getBlock()->getID() == Item::WALL_SIGN || $event->getBlock()->getID() == Item::SIGN_POST) {
$signt = $event->getBlock();
if (($tile = $signt->getLevel()->getTile($signt))){
if($tile instanceof Sign) {
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($tile->getText()[0] == strtolower($this->format->getAll()["format"][1])) {
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 {
Expand Down
9 changes: 3 additions & 6 deletions src/SignStatus/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

namespace SignStatus;

use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\String;
use pocketmine\scheduler\PluginTask;
use pocketmine\tile\Sign;

class Task extends PluginTask
{
class Task extends PluginTask{
private $plugin;
private $countable;

public function __construct(SignStatus $plugin)
{
public function __construct(SignStatus $plugin){
parent::__construct($plugin);
$this->plugin = $plugin;
$this->countable = 0;
Expand Down Expand Up @@ -41,7 +38,7 @@ public function onRun($currentTick){
$v = str_replace("{SERVER_LOAD}", $load, $v);
$index[$x] = $v;
}
$tile->setText($index[0],$index[1],$index[2],$index[3]);
$tile->setText($index[0], $index[1], $index[2], $index[3]);
}
}
}
Expand Down

0 comments on commit e768a0f

Please sign in to comment.