Last active
May 2, 2017 17:32
-
-
Save jasonw4331/d2ec16f2fcb2ee07c986744b5e4abe2b to your computer and use it in GitHub Desktop.
A PocketMine Plugin script which allows players to teleport across worlds
This file contains 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 | |
/** | |
* @name WorldShift | |
* @main jasonwynn10\WorldShift\MainClass | |
* @version 0.1.0 | |
* @api 3.0.0-ALPHA5 | |
* @description A script to allow teleportation across worlds | |
* @author jasonwynn10 | |
*/ | |
namespace jasonwynn10\WorldShift{ | |
use pocketmine\command\PluginCommand; | |
use pocketmine\plugin\PluginBase; | |
class MainClass extends PluginBase{ | |
public function onEnable() { | |
$this->getServer()->getCommandMap()->register(WorldCommand::class, new WorldCommand($this)); | |
$this->getServer()->getCommandMap()->register(WorldsCommand::class, new WorldsCommand($this)); | |
} | |
public function onCommand(CommandSender $sender, Command $command, $label, array $args) { | |
if(strtolower($command) == "world") { | |
if($sender instanceof Player) { | |
if(count($args) >= 1) { | |
if($this->getServer()->loadLevel($args[0])) { | |
if(($l = $this->getServer()->getLevelByName($args[0])) != null and isset($args[1])) { | |
if(($p = $this->getServer()->getPlayer($args[1])) instanceof Player) { | |
if($p->hasPermission("world.".strtolower($args[0]))) { | |
$p->teleport($l->getSpawnLocation()); | |
return true; | |
} | |
}else{ | |
$this->getLogger()->error("Player isn't a player"); | |
return true; | |
} | |
}elseif(($l = $this->getServer()->getLevelByName($args[0])) != null) { | |
$sender->teleport($l->getSpawnLocation()); | |
return true; | |
} | |
} | |
$this->getLogger()->error("Level isn't a level"); | |
return true; | |
}else{ | |
return false; | |
} | |
}else{ | |
if(count($args) >= 2) { | |
if($this->getServer()->loadLevel($args[0])) { | |
if(($l = $this->getServer()->getLevelByName($args[0])) != null and isset($args[1])) { | |
if(($p = $this->getServer()->getPlayer($args[1])) instanceof Player) { | |
if($p->hasPermission("world.".strtolower($args[0]))) { | |
$p->teleport($l->getSpawnLocation()); | |
return true; | |
} | |
}else{ | |
$this->getLogger()->error("Player isn't a player"); | |
return true; | |
} | |
} | |
} | |
$this->getLogger()->error("Level isn't a level"); | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} | |
} | |
if(strtolower($command) == "worlds") { | |
$sender->sendMessage(TF::YELLOW."---+---Worlds---+---"); | |
foreach ($this->getServer()->getLevels() as $level) { | |
$sender->sendMessage(TF::YELLOW.$level->getName()); | |
} | |
return true; | |
} | |
return true; | |
} | |
class WorldCommand extends PluginCommand { | |
public function __construct(MainClass $plugin) { | |
parent::__construct("world",$plugin); | |
$this->setPermission("world.cmd"); | |
$this->setAliases(["w"]); | |
$this->setDescription("Teleports the player between worlds"); | |
$this->setUsage("/world <world> [player]"); | |
} | |
public function execute(CommandSender $sender, $alias, array $args) { | |
if($sender instanceof Player) { | |
if(count($args) >= 1) { | |
if($this->getPlugin()->getServer()->loadLevel($args[0])) { | |
if(($l = $this->getPlugin()->getServer()->getLevelByName($args[0])) != null and isset($args[1])) { | |
if(($p = $this->getPlugin()->getServer()->getPlayer($args[1])) instanceof Player) { | |
if($p->hasPermission("world.".strtolower($args[0]))) { | |
$p->teleport($l->getSpawnLocation()); | |
return true; | |
} | |
}else{ | |
$this->getPlugin()->getLogger()->error("Player isn't a player"); | |
return true; | |
} | |
}elseif(($l = $this->getPlugin()->getServer()->getLevelByName($args[0])) != null) { | |
$sender->teleport($l->getSpawnLocation()); | |
return true; | |
} | |
} | |
$this->getPlugin()->getLogger()->error("Level isn't a level"); | |
return true; | |
}else{ | |
return false; | |
} | |
}else{ | |
if(count($args) >= 2) { | |
if($this->getPlugin()->getServer()->loadLevel($args[0])) { | |
if(($l = $this->getPlugin()->getServer()->getLevelByName($args[0])) != null and isset($args[1])) { | |
if(($p = $this->getPlugin()->getServer()->getPlayer($args[1])) instanceof Player) { | |
if($p->hasPermission("world.".strtolower($args[0]))) { | |
$p->teleport($l->getSpawnLocation()); | |
return true; | |
} | |
}else{ | |
$this->getPlugin()->getLogger()->error("Player isn't a player"); | |
return true; | |
} | |
} | |
} | |
$this->getPlugin()->getLogger()->error("Level isn't a level"); | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} | |
} | |
class WorldsCommand extends PluginCommand { | |
public function __construct(MainClass $plugin) { | |
parent::__construct("worlds",$plugin); | |
$this->setPermission("worlds.cmd"); | |
$this->setDescription("List all available worlds"); | |
$this->setUsage("/world <world> [player]"); | |
} | |
public function execute(CommandSender $sender, $alias, array $args) { | |
$sender->sendMessage(TF::YELLOW."---+---Worlds---+---"); | |
foreach ($this->getPlugin()->getServer()->getLevels() as $level) { | |
$sender->sendMessage(TF::YELLOW.$level->getName()); | |
} | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment