Last active
October 22, 2020 07:28
-
-
Save jasonw4331/69acd21fd4878c502de9651d25b68199 to your computer and use it in GitHub Desktop.
A temporary plugin to allow the changing of plot borders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* @name MyPlotBorders | |
* @main jasonwynn10\MyPlotBorders\Main | |
* @version 0.1.0 | |
* @api 3.0.0 | |
* @description A plugin script which allows players to set the block of the plot border via form | |
* @author jasonwynn10 | |
* @depend FormAPI | |
* @softdepend MyPlot | |
*/ | |
namespace jasonwynn10\MyPlotBorders { | |
use jojoe77777\FormAPI\SimpleForm; | |
use MyPlot\Commands; | |
use MyPlot\MyPlot; | |
use MyPlot\Plot; | |
use MyPlot\subcommand\SubCommand; | |
use pocketmine\block\Block; | |
use pocketmine\block\BlockFactory; | |
use pocketmine\command\CommandSender; | |
use pocketmine\math\Vector3; | |
use pocketmine\Player; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\scheduler\Task; | |
use pocketmine\utils\TextFormat; | |
class Main extends PluginBase { | |
/** @var string[] $blocks */ | |
public static $blocks = []; | |
/** @var self|null $instance */ | |
private static $instance = null; | |
/** | |
* @return self|null | |
*/ | |
public static function getInstance() : ?self { | |
return self::$instance; | |
} | |
public function onEnable() { | |
self::$instance = $this; | |
$blocks = ["44:0", "44:1", "44:2", "44:3", "44:4", "44:5", "44:6", "44:7", "158:0", "158:1", "158:2", "158:3", "158:4", "158:5", "0:0", "120:0", "122:0", "138:0"]; | |
foreach($blocks as $string) { | |
$arr = explode(":", $string); | |
$id = (int) $arr[0]; | |
$damage = (int) ($arr[1] ?? 0); | |
$block = BlockFactory::get($id, $damage); | |
self::$blocks[$string] = $block->getName(); | |
} | |
/** @var Commands $commands */ | |
$commands = $this->getServer()->getCommandMap()->getCommand("plot"); | |
if(version_compare(MyPlot::getInstance()->getDescription()->getVersion(), "1.5.3", ">=")) { | |
$command = new class(MyPlot::getInstance(), "border") extends SubCommand { | |
public function getName() : string { | |
return "border"; | |
} | |
public function getAlias() : string { | |
return "b"; | |
} | |
public function canUse(CommandSender $sender) : bool { | |
return ($sender instanceof Player) and $sender->hasPermission("myplot.command.border"); | |
} | |
/** | |
* @param Player $sender | |
* @param array $args | |
* | |
* @return bool | |
*/ | |
public function execute(CommandSender $sender, array $args) : bool { | |
$plot = $this->getPlugin()->getPlotByPosition($sender); | |
if($plot === null) { | |
$sender->sendMessage(TextFormat::RED . $this->getPlugin()->getLanguage()->translateString("notinplot")); | |
return true; | |
} | |
if($plot->owner !== $sender->getName() and !$sender->hasPermission("border.command.admin")) { | |
$sender->sendMessage(TextFormat::RED . $this->getPlugin()->getLanguage()->translateString("notowner")); | |
return true; | |
} | |
$sender->sendForm(new class(function($player, $data) use ($plot) { | |
if($data === null) | |
return; // form cancelled. do nothing | |
$arr = explode(":", $data); | |
$id = (int) $arr[0]; | |
$damage = (int) $arr[1]; | |
$block = BlockFactory::get($id, $damage); | |
Main::getInstance()->setPlotBorderBlocks($plot, $block); | |
}) extends SimpleForm { | |
public function __construct(?callable $callable) { | |
$this->setTitle("Plot Border"); | |
foreach(Main::$blocks as $id => $name) { | |
$this->addButton($name); | |
} | |
parent::__construct($callable); | |
} | |
public function processData(&$data) : void { | |
$i = 0; | |
foreach(Main::$blocks as $id => $name) { | |
if($i === $data) { | |
$data = $id; | |
return; | |
} | |
$i++; | |
} | |
} | |
}); | |
return true; | |
} | |
}; | |
$commands->loadSubCommand($command); | |
$this->getLogger()->debug("SubCommand loaded"); | |
}else{ | |
$command = new class(MyPlot::getInstance(), "border") extends SubCommand { | |
public function canUse(CommandSender $sender) : bool { | |
return ($sender instanceof Player) and $sender->hasPermission("myplot.command.border"); | |
} | |
/** | |
* @param Player $sender | |
* @param array $args | |
* | |
* @return bool | |
*/ | |
public function execute(CommandSender $sender, array $args) : bool { | |
$plot = $this->getPlugin()->getPlotByPosition($sender); | |
if($plot === null) { | |
$sender->sendMessage(TextFormat::RED . $this->getPlugin()->getLanguage()->translateString("notinplot")); | |
return true; | |
} | |
if($plot->owner !== $sender->getName() and !$sender->hasPermission("border.command.admin")) { | |
$sender->sendMessage(TextFormat::RED . $this->getPlugin()->getLanguage()->translateString("notowner")); | |
return true; | |
} | |
$sender->sendForm(new class(function($player, $data) use ($plot) { | |
if($data === null) | |
return; // form cancelled. do nothing | |
$arr = explode(":", $data); | |
$id = (int) $arr[0]; | |
$damage = (int) $arr[1]; | |
$block = BlockFactory::get($id, $damage); | |
Main::getInstance()->setPlotBorderBlocks($plot, $block); | |
}) extends SimpleForm { | |
public function __construct(?callable $callable) { | |
$this->setTitle("Plot Border"); | |
foreach(Main::$blocks as $id => $name) { | |
$this->addButton($name); | |
} | |
parent::__construct($callable); | |
} | |
public function processData(&$data) : void { | |
$i = 0; | |
foreach(Main::$blocks as $id => $name) { | |
if($i === $data) { | |
$data = $id; | |
return; | |
} | |
$i++; | |
} | |
} | |
}); | |
return true; | |
} | |
}; | |
$refObject = new \ReflectionClass($commands); | |
$refProperty = $refObject->getProperty("subCommands"); | |
$refProperty->setAccessible(true); | |
$val = $refProperty->getValue($commands); | |
$val["border"] = $command; | |
$refProperty->setValue($commands, $val); | |
$refObject = new \ReflectionClass($commands); | |
$refProperty = $refObject->getProperty("aliasSubCommands"); | |
$refProperty->setAccessible(true); | |
$val = $refProperty->getValue($commands); | |
$val["b"] = $command; | |
$refProperty->setValue($commands, $val); | |
} | |
} | |
public function setPlotBorderBlocks(Plot $plot, Block $block) { | |
$this->getScheduler()->scheduleTask(new class(MyPlot::getInstance(), $plot, $block) extends Task { | |
private $plot, $level, $height, $plotWallBlock, $plotBeginPos, $xMax, $zMax; | |
public function __construct(MyPlot $plugin, Plot $plot, Block $block) { | |
$this->plot = $plot; | |
$this->plotBeginPos = $plugin->getPlotPosition($plot); | |
$this->level = $this->plotBeginPos->getLevel(); | |
$this->plotBeginPos = $this->plotBeginPos->subtract(1,0,1); | |
$plotLevel = $plugin->getLevelSettings($plot->levelName); | |
$plotSize = $plotLevel->plotSize; | |
$this->xMax = $this->plotBeginPos->x + $plotSize + 1; | |
$this->zMax = $this->plotBeginPos->z + $plotSize + 1; | |
$this->height = $plotLevel->groundHeight; | |
$this->plotWallBlock = $block; | |
} | |
public function onRun(int $currentTick) : void { | |
for($x = $this->plotBeginPos->x; $x <= $this->xMax; $x++) { | |
$this->level->setBlock(new Vector3($x, $this->height + 1, $this->plotBeginPos->z), $this->plotWallBlock, false, false); | |
$this->level->setBlock(new Vector3($x, $this->height + 1, $this->zMax), $this->plotWallBlock, false, false); | |
} | |
for($z = $this->plotBeginPos->z; $z <= $this->zMax; $z++) { | |
$this->level->setBlock(new Vector3($this->plotBeginPos->x, $this->height + 1, $z), $this->plotWallBlock, false, false); | |
$this->level->setBlock(new Vector3($this->xMax, $this->height + 1, $z), $this->plotWallBlock, false, false); | |
} | |
} | |
}); | |
} | |
} | |
} |
How To download on mobile?
What permissions?
Permissions is mot working for this
the player who has no rights or something can dismantle the beacon and everything except the end portal and dragon egg
Deactive EditBorderBlocks in MyPlot Config!
Hiili8283
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I get in .phar ??