Skip to content

Instantly share code, notes, and snippets.

@jasonw4331
Last active May 15, 2022 08:43
Show Gist options
  • Save jasonw4331/8ea725774fb11bc947e32ca347bc4ab4 to your computer and use it in GitHub Desktop.
Save jasonw4331/8ea725774fb11bc947e32ca347bc4ab4 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
/**
* @name MyPlotPlotHomes
* @main jasonwynn10\MyPlotPlotHomes\Main
* @version 0.1.0
* @api 3.0.0
* @description A plugin script which changes the home subcommand parameters and actions
* @author jasonwynn10
* @depend MyPlot
*/
namespace jasonwynn10\MyPlotPlotHomes {
use MyPlot\Commands;
use MyPlot\MyPlot;
use MyPlot\Plot;
use MyPlot\subcommand\HomeSubCommand;
use pocketmine\command\CommandSender;
use pocketmine\OfflinePlayer;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;
class Main extends PluginBase {
/** @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;
$command = new class(MyPlot::getInstance(), "home") extends HomeSubCommand {
public function getUsage() : string {
return "/p home [player: string] [number: int] [world: string]";
}
/**
* @param Player $sender
* @param array $args
*
* @return bool
*/
public function execute(CommandSender $sender, array $args) : bool {
$selected = null;
if(empty($args)) {
$selected = $sender;
$selectedName = $sender->getName();
$plotNumber = 1;
}elseif(isset($args[0])) {
$selected = $this->getPlugin()->getServer()->getPlayer($args[0]) ?? $this->getPlugin()->getServer()->getOfflinePlayer($args[0]);
$selectedName = $selected->getName();
$plotNumber = (int) ($args[1] ?? 1);
}else{
return false;
}
if($selected instanceof OfflinePlayer and !isset($args[2])) {
$sender->sendMessage(TextFormat::RED . $this->translateString("home.error"));
return true;
}
$levelName = $args[2] ?? $selected->getLevel()->getFolderName();
$plots = $this->getPlugin()->getPlotsOfPlayer($selectedName, $levelName);
if(empty($plots)) {
$sender->sendMessage(TextFormat::RED . "No plots found in world");
return true;
}
if(!isset($plots[$plotNumber - 1])) {
$sender->sendMessage(TextFormat::RED . $this->translateString("home.notexist", [$plotNumber]));
return true;
}
usort($plots, function(Plot $plot1, Plot $plot2) {
if($plot1->levelName == $plot2->levelName) {
return 0;
}
return ($plot1->levelName < $plot2->levelName) ? -1 : 1;
});
$plot = $plots[$plotNumber - 1];
if($this->getPlugin()->teleportPlayerToPlot($sender, $plot)) {
$sender->sendMessage($this->translateString("home.success", [$plot, $plot->levelName]));
}else{
$sender->sendMessage(TextFormat::RED . $this->translateString("home.error"));
}
return true;
}
};
/** @var Commands $commands */
$commands = $this->getServer()->getCommandMap()->getCommand("plot");
$commands->unloadSubCommand("home");
$commands->loadSubCommand($command);
$this->getLogger()->debug("SubCommand loaded");
}
}
}
@jasonw4331
Copy link
Author

The description of this script is the description from the Border script xD

shh no its not

@1-23a
Copy link

1-23a commented Aug 2, 2021

Ich brauche ein plugin wo man/p h (spielername) machen kann es ist ein Bug das es nicht geht aber kannst du bitte so ein plugin machen bitte

@supercrafter333
Copy link

Ich brauche ein plugin wo man/p h (spielername) machen kann es ist ein Bug das es nicht geht aber kannst du bitte so ein plugin machen bitte

Bro, auf GitHub und Gist schreibt an in Englisch!

@1-23a
Copy link

1-23a commented Aug 3, 2021

I need a plugin where you can make/p h (player name) it is a bug that it does not work but can you please make such a plugin please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment