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 do I import that into my Server? @jasonwynn10
Just upload this file 😉
How to upload this?
@jasonwynn10
click the "raw" button
ctrl + s to save the file
note: make sure it is a .php
file. not .txt
Umm how i can get this in .phar because .php i cant use at minehub8
i dont know spiele seit tage auf mein server nicht wegen schule
Am Sa., 18. Jan. 2020 um 18:30 Uhr schrieb DerSchlumpfNiko <
[email protected]>:
… Wie downloade ich das?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/69acd21fd4878c502de9651d25b68199?email_source=notifications&email_token=AOFI3KAOSYXTN6KF2XONP7LQ6M4DJA5CNFSM4HI6QM3KYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF72VE#gistcomment-3142994>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOFI3KGX25PMJJTLMHQTUVLQ6M4DJANCNFSM4HI6QM3A>
.
Permissions?
How do I get in .phar ??
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 can i get this in a .phar data