Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
declare(strict_types=1);
/**
* @name MyPlotPlotHomes
* @main jasonwynn10\MyPlotPlotHomes\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 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");
}
}
}
@ProxmaDev

This comment has been minimized.

Copy link

@ProxmaDev ProxmaDev commented Apr 9, 2019

There is a little problem:
I can't do /p h 2 for example. it just tells me "you couldn't teleported to your plot"
But i can do /p h and /p h name

@Wertzui123

This comment has been minimized.

Copy link

@Wertzui123 Wertzui123 commented Apr 15, 2019

That's no problem. He won't "fix" this, because it trys to go to 2 1. Plot

@ProxmaDev

This comment has been minimized.

Copy link

@ProxmaDev ProxmaDev commented Apr 16, 2019

Well, nvm I've fixed it for me.

@Kev2007kevin2007

This comment has been minimized.

Copy link

@Kev2007kevin2007 Kev2007kevin2007 commented Jun 17, 2019

Richtig GEIL

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Aug 21, 2019

@SchdoeNVIDIA hoe did you fixed it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.