├── meta ├── simplewarp.png ├── simplewarp-1.png └── simplewarp-2.png ├── .gitignore ├── src └── falkirks │ └── simplewarp │ ├── store │ ├── Reloadable.php │ ├── Saveable.php │ ├── StandardStore.php │ ├── DataStore.php │ └── YAMLStore.php │ ├── event │ ├── WarpEvent.php │ ├── WarpCloseEvent.php │ ├── WarpAddEvent.php │ ├── WarpOpenEvent.php │ ├── WarpDeleteEvent.php │ └── PlayerWarpEvent.php │ ├── Version.php │ ├── command │ ├── SimpleWarpCommand.php │ ├── essentials │ │ ├── EssentialsWarpCommand.php │ │ └── EssentialsDelWarpCommand.php │ ├── DelWarpCommand.php │ ├── OpenWarpCommand.php │ ├── CloseWarpCommand.php │ ├── WarpReportCommand.php │ ├── ListWarpsCommand.php │ ├── WarpCommand.php │ └── AddWarpCommand.php │ ├── utils │ ├── WeakPosition.php │ ├── ChecksumVerify.php │ ├── DebugDumpFactory.php │ └── SpoonDetector.php │ ├── permission │ └── SimpleWarpPermissions.php │ ├── task │ ├── PlayerWarpTask.php │ └── CommandWarpTask.php │ ├── Warp.php │ ├── Destination.php │ ├── SimpleWarp.php │ ├── api │ └── SimpleWarpAPI.php │ ├── lang │ └── TranslationManager.php │ └── WarpManager.php ├── .poggit.yml ├── entry.php ├── ISSUE_TEMPLATE.md ├── LICENSE ├── plugin.yml ├── resources └── config.yml └── README.md /meta/simplewarp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falkirks/SimpleWarp/HEAD/meta/simplewarp.png -------------------------------------------------------------------------------- /meta/simplewarp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falkirks/SimpleWarp/HEAD/meta/simplewarp-1.png -------------------------------------------------------------------------------- /meta/simplewarp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falkirks/SimpleWarp/HEAD/meta/simplewarp-2.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | src/simplewarp 3 | out 4 | config.yml 5 | lang.yml 6 | warps.yml 7 | .started -------------------------------------------------------------------------------- /src/falkirks/simplewarp/store/Reloadable.php: -------------------------------------------------------------------------------- 1 | warp = $warp; 13 | } 14 | 15 | /** 16 | * @return Warp 17 | */ 18 | public function getWarp(): Warp{ 19 | return $this->warp; 20 | } 21 | } -------------------------------------------------------------------------------- /entry.php: -------------------------------------------------------------------------------- 1 | $warp){ 9 | $this->add($name, $warp); 10 | } 11 | } 12 | public function removeAll($warps){ 13 | foreach($warps as $warp){ 14 | $this->remove($warp); 15 | } 16 | } 17 | public function exists($name): bool{ 18 | return $this->get($name) !== null; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/event/WarpCloseEvent.php: -------------------------------------------------------------------------------- 1 | sender = $sender; 16 | } 17 | /** 18 | * @return CommandSender 19 | */ 20 | public function getSender(): CommandSender{ 21 | return $this->sender; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/event/WarpAddEvent.php: -------------------------------------------------------------------------------- 1 | sender = $sender; 16 | } 17 | 18 | 19 | /** 20 | * @return CommandSender 21 | */ 22 | public function getSender(): CommandSender{ 23 | return $this->sender; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/event/WarpOpenEvent.php: -------------------------------------------------------------------------------- 1 | sender = $sender; 18 | } 19 | 20 | /** 21 | * @return CommandSender 22 | */ 23 | public function getSender(): CommandSender{ 24 | return $this->sender; 25 | } 26 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/event/WarpDeleteEvent.php: -------------------------------------------------------------------------------- 1 | sender = $sender; 17 | } 18 | 19 | /** 20 | * @return CommandSender 21 | */ 22 | public function getSender(): CommandSender{ 23 | return $this->sender; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/Version.php: -------------------------------------------------------------------------------- 1 | sendMessage(Version::$quotes[array_rand(Version::$quotes)]); 18 | } 19 | //$sender->sendMessage("SimpleWarp " . self::VERSION_STRING); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/SimpleWarpCommand.php: -------------------------------------------------------------------------------- 1 | getPlugin()->isDisabled()){ 24 | $sender->sendMessage($this->getPlugin()->getApi()->executeTranslationItem("plugin-disabled")); 25 | return false; 26 | } 27 | return true; 28 | } 29 | 30 | public abstract function getPlugin(): Plugin; 31 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/store/DataStore.php: -------------------------------------------------------------------------------- 1 | player = $player; 19 | $this->warp = $warp; 20 | } 21 | 22 | /** 23 | * @return Warp 24 | */ 25 | public function getWarp(): Warp{ 26 | return $this->warp; 27 | } 28 | public function getDestination(): Destination{ 29 | return ($this->destination instanceof Destination ? $this->destination : $this->warp->getDestination()); 30 | } 31 | public function setDestination(Destination $destination){ 32 | $this->destination = $destination; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Falkirks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/utils/WeakPosition.php: -------------------------------------------------------------------------------- 1 | levelName = $levelName; 23 | } 24 | public function isValid(): bool { 25 | return Server::getInstance()->getLevelByName($this->levelName) instanceof Level; 26 | } 27 | public function updateProperties(){ 28 | $this->level = $this->getLevel(); 29 | } 30 | public function getLevel(): Level{ 31 | return Server::getInstance()->getLevelByName($this->levelName); 32 | } 33 | 34 | public function getLevelName(){ 35 | return $this->levelName; 36 | } 37 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/utils/ChecksumVerify.php: -------------------------------------------------------------------------------- 1 | getDescription()->getName() . "/" . $pluginBase->getDescription()->getVersion(); 18 | $hash = Internet::getURL($url); 19 | if($pluginBase->getPluginLoader() instanceof PharPluginLoader){ 20 | $reflect = new \ReflectionClass($pluginBase); 21 | $method = $reflect->getMethod("getFile"); 22 | $method->setAccessible(true); 23 | $file = $method->invoke($pluginBase); 24 | $method->setAccessible(false); 25 | 26 | $check = sha1_file(substr($file, 7, -1)); 27 | return $check === $hash; 28 | } 29 | return false; 30 | 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | # Do NOT edit this file to change permissions 2 | name: SimpleWarp 3 | main: falkirks\simplewarp\SimpleWarp 4 | version: 4.0.1 5 | author: Falkirks 6 | api: [3.0.0, 4.0.0] 7 | load: POSTWORLD 8 | softdepend: ["FastTransfer", "SlowTransfer", "EssentialsPE"] 9 | permissions: 10 | simplewarp: 11 | default: op 12 | children: 13 | simplewarp.command: 14 | default: op 15 | children: 16 | simplewarp.command.list: 17 | default: true 18 | children: 19 | simplewarp.command.list.xyz: 20 | default: op 21 | simplewarp.command.list.visual: 22 | default: op 23 | simplewarp.command.addwarp: 24 | default: op 25 | simplewarp.command.delwarp: 26 | default: op 27 | simplewarp.command.warp: 28 | default: true 29 | simplewarp.command.warp.other: 30 | default: op 31 | simplewarp.command.openwarp: 32 | default: op 33 | simplewarp.command.closewarp: 34 | default: op 35 | simplewarp.command.closewarp: 36 | default: op 37 | simplewarp.essentials.notice: 38 | default: op 39 | description: Recieve messages when their is warp conflict in Essentials 40 | simplewarp.warp: 41 | default: op 42 | description: Allows usage of all warps 43 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/store/YAMLStore.php: -------------------------------------------------------------------------------- 1 | config = $config; 12 | } 13 | 14 | public function add($name, $warp){ 15 | $past = $this->config->get($name, null); 16 | $this->config->set($name, $warp); 17 | $this->config->save(); 18 | return $past; 19 | } 20 | public function get($name){ 21 | return $this->config->get($name, null); 22 | } 23 | 24 | public function remove($name){ 25 | $past = $this->config->get($name, null); 26 | $this->config->remove($name); 27 | $this->config->save(); 28 | return $past; 29 | } 30 | 31 | public function clear(){ 32 | $this->config->setAll([]); 33 | $this->config->save(); 34 | } 35 | 36 | public function reload(){ 37 | $this->config->reload(); 38 | } 39 | /** 40 | * Returns something which can be used to iterate 41 | * over the store. 42 | * @return mixed 43 | */ 44 | public function getIterator(){ 45 | return $this->config->getAll(); 46 | } 47 | 48 | public function save(){ 49 | $this->config->save(); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/permission/SimpleWarpPermissions.php: -------------------------------------------------------------------------------- 1 | getPermission("simplewarp.warp"); 28 | $permission = new Permission(self::BASE_WARP_PERMISSION . "." . $warp->getName(), "Allow use of " . $warp->getName()); //TODO correct default value 29 | PermissionManager::getInstance()->addPermission($permission); 30 | self::$baseWarpPerm->getChildren()[$permission->getName()] = true; 31 | } 32 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/utils/DebugDumpFactory.php: -------------------------------------------------------------------------------- 1 | api = $simpleWarp; 18 | } 19 | 20 | 21 | public function generate(): string { 22 | return implode("\n", [ 23 | "SERVER VERSION: " . $this->api->getSimpleWarp()->getServer()->getPocketMineVersion(), 24 | "API: " . $this->api->getSimpleWarp()->getServer()->getApiVersion(), 25 | "MCPE VERSION: " . $this->api->getSimpleWarp()->getServer()->getVersion(), 26 | "SOFTWARE: " . $this->api->getSimpleWarp()->getServer()->getName(), 27 | "SimpleWarp Version: " . $this->api->getSimpleWarp()->getDescription()->getVersion(), 28 | "PLUGINS: " . implode(",", array_keys($this->api->getSimpleWarp()->getServer()->getPluginManager()->getPlugins())), 29 | "storage-mode: " . $this->api->getSimpleWarp()->getWarpManager()->getFlag(), 30 | "essentials-support: " . ($this->api->getSimpleWarp()->getConfig()->get("essentials-support") ? 'true' : 'false'), 31 | json_encode($this->api->getSimpleWarp()->getWarpManager()->getWarps(), JSON_PRETTY_PRINT) 32 | ]); 33 | } 34 | 35 | 36 | function __toString(){ 37 | return $this->generate(); 38 | } 39 | 40 | /** 41 | * @return SimpleWarpAPI 42 | */ 43 | public function getApi(): SimpleWarpAPI{ 44 | return $this->api; 45 | } 46 | } -------------------------------------------------------------------------------- /resources/config.yml: -------------------------------------------------------------------------------- 1 | # >=>>=> >=> >=> >=> >=> 2 | # >=> >=> >=> >=> >=> >=> 3 | # >=> >=> >===>>=>>==> >=> >=> >=> >==> >=> >> >=> >=> >=> >> >==> >=> >=> 4 | # >=> >=> >=> >> >=> >> >=> >=> >> >=> >=> >=> >=> >=> >=> >=> >> >=> 5 | # >=> >=> >=> >> >=> >> >=> >=> >>===>>=> >=> >> >=> >=> >=> >=> >=> >> >=> 6 | # >=> >=> >=> >=> >> >=> >=> >=> >=> >> >> >> >===> >=> >=> >=> >=> >=> 7 | # >=>>=> >=> >==> >> >=> >=> >==> >====> >=> >=> >==>>>==> >==> >=> 8 | # >=> The original warp plugin for PocketMine >=> 9 | 10 | display-exact-coordinates: false 11 | # If set to false the coordinates shown to the end user 12 | # will be rounded, players will still be teleported to the 13 | # exact location. 14 | storage-mode: 1 15 | # SimpleWarp can handle the storage of warps in three main ways. 16 | # 17 | # MEMORY_TILL_CLOSE = 0 18 | # Warps are loaded into memory when the server starts and are 19 | # held there until the server closes. When the server closes 20 | # they are converted back into YAML. This new YAML will 21 | # replace warps.yml, this means that changes are lost and 22 | # warps which fail to load are discarded. 23 | # 24 | # 25 | # FLUSH_ON_CHANGE = 1 26 | # Warps are loaded into memory when the server starts. Whenever a 27 | # warp is updated, it will be updated in the warps.yml. When the 28 | # server closes, the warps file is NOT overwritten. 29 | # 30 | # NO_MEMORY_STORE = 2 31 | # Warps are never "stored" in memory. They are converted on demand 32 | # between YAML and object format. Any changes made to the config 33 | # will be available right away in the server and vice versa. 34 | # 35 | essentials-support: false 36 | # If essentials-support is enabled and EssentialsPE is installed, 37 | # SimpleWarp will take steps to ensure compatibility between the 38 | # two plugins. 39 | hold-still-enabled: true 40 | hold-still-time: 60 -------------------------------------------------------------------------------- /src/falkirks/simplewarp/task/PlayerWarpTask.php: -------------------------------------------------------------------------------- 1 | simpleWarp = $plugin; 18 | $this->warp = $warp; 19 | $this->player = $player; 20 | $this->position = $player->getPosition(); 21 | } 22 | 23 | /** 24 | * Actions to execute when run 25 | * 26 | * @param $currentTick 27 | * 28 | * @return void 29 | */ 30 | public function onRun(int $currentTick){ 31 | if($this->player instanceof Player && $this->player->isOnline()){ 32 | if(!$this->getSimpleWarp()->getConfig()->get("hold-still-enabled") || $this->player->getPosition()->equals($this->position)){ 33 | $this->warp->teleport($this->player); 34 | } 35 | } 36 | } 37 | 38 | public function runNext(){ 39 | $this->getSimpleWarp()->getScheduler()->scheduleTask($this); 40 | } 41 | 42 | public function runWithHoldStill(){ 43 | $this->getSimpleWarp()->getScheduler()->scheduleDelayedTask($this, $this->getSimpleWarp()->getConfig()->get("hold-still-time")); 44 | } 45 | 46 | public function run(){ 47 | if($this->getSimpleWarp()->getConfig()->get("hold-still-enabled")){ 48 | $this->runWithHoldStill(); 49 | } 50 | else{ 51 | $this->runNext(); 52 | } 53 | } 54 | 55 | 56 | /** 57 | * @return Warp 58 | */ 59 | public function getWarp(): Warp{ 60 | return $this->warp; 61 | } 62 | 63 | /** 64 | * @return Player 65 | */ 66 | public function getPlayer(): Player{ 67 | return $this->player; 68 | } 69 | 70 | /** 71 | * @return SimpleWarp 72 | */ 73 | public function getSimpleWarp(): SimpleWarp{ 74 | return $this->simpleWarp; 75 | } 76 | 77 | 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/essentials/EssentialsWarpCommand.php: -------------------------------------------------------------------------------- 1 | essCommand = $essCommand; 18 | } 19 | 20 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 21 | if(isset($args[0])) { 22 | $ess = $this->getEssAPI(); 23 | if (isset($this->api->getWarpManager()[$args[0]])) { 24 | parent::execute($sender, $commandLabel, $args); 25 | if($ess->warpExists($args[0]) && $sender->hasPermission("simplewarp.essentials.notice")){ 26 | $sender->sendMessage($this->api->executeTranslationItem("ess-warp-conflict", $args[0])); 27 | } 28 | } 29 | elseif(($name = $this->getEssWarpName($ess, $args[0])) !== null){ 30 | $args[0] = $name; 31 | $this->getEssCommand()->execute($sender, $commandLabel, $args); 32 | } 33 | else{ 34 | $sender->sendMessage($this->api->executeTranslationItem("ess-warp-doesnt-exist")); 35 | } 36 | } 37 | else{ 38 | $sender->sendMessage($this->getUsage()); 39 | Version::sendVersionMessage($sender); 40 | } 41 | } 42 | private function getEssWarpName($loader, $string){ 43 | if($loader->warpExists($string)){ 44 | return $string; 45 | } 46 | if(substr($string, 0, 4) === "ess:" && $loader->warpExists(substr($string, 4))){ 47 | return substr($string, 4); 48 | } 49 | return null; 50 | } 51 | private function getEssAPI(){ 52 | $ess = $this->getPlugin()->getServer()->getPluginManager()->getPlugin("EssentialsPE"); 53 | if(method_exists($ess, "getAPI")){ 54 | return $ess->getAPI(); 55 | } 56 | return $ess; 57 | } 58 | /** 59 | * @return Command 60 | */ 61 | public function getEssCommand(): SimpleWarp{ 62 | return $this->essCommand; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/essentials/EssentialsDelWarpCommand.php: -------------------------------------------------------------------------------- 1 | essCommand = $essCommand; 19 | } 20 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 21 | if(isset($args[0])) { 22 | $ess = $this->getEssAPI(); 23 | if (isset($this->api->getWarpManager()[$args[0]])) { 24 | parent::execute($sender, $commandLabel, $args); 25 | if($ess->warpExists($args[0]) && $sender->hasPermission("simplewarp.essentials.notice")){ 26 | $sender->sendMessage($this->api->executeTranslationItem("ess-warp-conflict", $args[0])); 27 | } 28 | } 29 | elseif(($name = $this->getEssWarpName($ess, $args[0])) !== null){ 30 | $args[0] = $name; 31 | $this->getEssCommand()->execute($sender, $commandLabel, $args); 32 | } 33 | else{ 34 | $sender->sendMessage($this->api->executeTranslationItem("ess-warp-doesnt-exist")); 35 | } 36 | } 37 | else{ 38 | $sender->sendMessage($this->getUsage()); 39 | Version::sendVersionMessage($sender); 40 | } 41 | } 42 | private function getEssWarpName($loader, $string){ 43 | if($loader->warpExists($string)){ 44 | return $string; 45 | } 46 | if(substr($string, 0, 4) === "ess:" && $loader->warpExists(substr($string, 4))){ 47 | return substr($string, 4); 48 | } 49 | return null; 50 | } 51 | 52 | private function getEssAPI(){ 53 | $ess = $this->getPlugin()->getServer()->getPluginManager()->getPlugin("EssentialsPE"); 54 | if(method_exists($ess, "getAPI")){ 55 | return $ess->getAPI(); 56 | } 57 | return $ess; 58 | } 59 | 60 | /** 61 | * @return Command 62 | */ 63 | public function getEssCommand(): SimpleWarp{ 64 | return $this->essCommand; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/DelWarpCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("delwarp-cmd"), $api->executeTranslationItem("delwarp-desc"), $api->executeTranslationItem("delwarp-usage")); 20 | $this->api = $api; 21 | } 22 | 23 | /** 24 | * @param CommandSender $sender 25 | * @param string $commandLabel 26 | * @param string[] $args 27 | * 28 | * @return mixed 29 | */ 30 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 31 | if(parent::execute($sender, $commandLabel, $args)) { 32 | if ($sender->hasPermission(SimpleWarpPermissions::DEL_WARP_COMMAND)) { 33 | if (isset($args[0])) { 34 | if (isset($this->api->getWarpManager()[$args[0]])) { 35 | $ev = new WarpDeleteEvent($sender, $this->api->getWarpManager()[$args[0]]); 36 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 37 | if (!$ev->isCancelled()) { 38 | unset($this->api->getWarpManager()[$args[0]]); 39 | $sender->sendMessage($this->api->executeTranslationItem("warp-deleted", $args[0])); 40 | } 41 | else { 42 | $sender->sendMessage($this->api->executeTranslationItem("delwarp-event-cancelled")); 43 | } 44 | } 45 | else { 46 | $sender->sendMessage($this->api->executeTranslationItem("warp-doesnt-exist", $args[0])); 47 | } 48 | } 49 | else { 50 | $sender->sendMessage($this->getUsage()); 51 | Version::sendVersionMessage($sender); 52 | } 53 | } 54 | else { 55 | $sender->sendMessage($this->api->executeTranslationItem("delwarp-noperm")); 56 | } 57 | } 58 | } 59 | 60 | 61 | /** 62 | * @return \pocketmine\plugin\Plugin 63 | */ 64 | public function getPlugin(): Plugin{ 65 | return $this->api->getSimpleWarp(); 66 | } 67 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/utils/SpoonDetector.php: -------------------------------------------------------------------------------- 1 | getName(), self::$thingsThatAreNotSpoons); 40 | } 41 | 42 | private static function contentValid(string $content): bool { 43 | return (strpos($content, self::$spoonTxtContent) > -1) && (strrpos($content, "yes") > strrpos($content, "?")); 44 | } 45 | 46 | public static function printSpoon(PluginBase $pluginBase, $fileToCheck){ 47 | if(self::isThisSpoon()){ 48 | if(!file_exists($pluginBase->getDataFolder() . $fileToCheck)){ 49 | file_put_contents($pluginBase->getDataFolder() . $fileToCheck, self::$spoonTxtContent); 50 | } 51 | if(!self::contentValid(file_get_contents($pluginBase->getDataFolder() . $fileToCheck))) { 52 | $pluginBase->getLogger()->info(self::$subtleAsciiSpoon); 53 | $pluginBase->getLogger()->warning("You are attempting to run " . $pluginBase->getDescription()->getName() . " on a SPOON!"); 54 | $pluginBase->getLogger()->warning("Before using the plugin you will need to open /plugins/" . $pluginBase->getDescription()->getName() . "/" . $fileToCheck . " in a text editor and agree to the terms."); 55 | $pluginBase->getServer()->getPluginManager()->disablePlugin($pluginBase); 56 | } 57 | } 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/OpenWarpCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("openwarp-cmd"), $api->executeTranslationItem("openwarp-desc"), $api->executeTranslationItem("openwarp-usage")); 21 | $this->api = $api; 22 | } 23 | 24 | /** 25 | * @param CommandSender $sender 26 | * @param string $commandLabel 27 | * @param string[] $args 28 | * 29 | * @return mixed 30 | */ 31 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 32 | if(parent::execute($sender, $commandLabel, $args)) { 33 | if ($sender->hasPermission(SimpleWarpPermissions::OPEN_WARP_COMMAND)) { 34 | if (isset($args[0])) { 35 | if (isset($this->api->getWarpManager()[$args[0]])) { 36 | /** @var Warp $warp */ 37 | $warp = $this->api->getWarpManager()[$args[0]]; 38 | $ev = new WarpOpenEvent($sender, $warp); 39 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 40 | if (!$ev->isCancelled()) { 41 | $warp->setPublic(true); 42 | $sender->sendMessage($this->api->executeTranslationItem("opened-warp-1", $args[0])); 43 | $sender->sendMessage($this->api->executeTranslationItem("opened-warp-2")); 44 | } 45 | else { 46 | $sender->sendMessage($this->api->executeTranslationItem("openwarp-event-cancelled")); 47 | } 48 | } 49 | else { 50 | $sender->sendMessage($this->api->executeTranslationItem("warp-doesnt-exist", $args[0])); 51 | } 52 | } 53 | else { 54 | $sender->sendMessage($this->getUsage()); 55 | Version::sendVersionMessage($sender); 56 | } 57 | } 58 | else { 59 | $sender->sendMessage($this->api->executeTranslationItem("openwarp-noperm")); 60 | } 61 | } 62 | } 63 | 64 | 65 | /** 66 | * @return \pocketmine\plugin\Plugin 67 | */ 68 | public function getPlugin(): Plugin{ 69 | return $this->api->getSimpleWarp(); 70 | } 71 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/CloseWarpCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("closewarp-cmd"), $api->executeTranslationItem("closewarp-desc"), $api->executeTranslationItem("closewarp-usage")); 21 | $this->api = $api; 22 | } 23 | 24 | /** 25 | * @param CommandSender $sender 26 | * @param string $commandLabel 27 | * @param string[] $args 28 | * 29 | * @return mixed 30 | */ 31 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 32 | if(parent::execute($sender, $commandLabel, $args)) { 33 | if ($sender->hasPermission(SimpleWarpPermissions::OPEN_WARP_COMMAND)) { 34 | if (isset($args[0])) { 35 | if (isset($this->api->getWarpManager()[$args[0]])) { 36 | /** @var Warp $warp */ 37 | $warp = $this->api->getWarpManager()[$args[0]]; 38 | $ev = new WarpCloseEvent($sender, $warp); 39 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 40 | if (!$ev->isCancelled()) { 41 | $warp->setPublic(false); 42 | $sender->sendMessage($this->api->executeTranslationItem("closed-warp-1", $args[0])); 43 | $sender->sendMessage($this->api->executeTranslationItem("closed-warp-2", SimpleWarpPermissions::BASE_WARP_PERMISSION . "." . $warp->getName())); 44 | } 45 | else { 46 | $sender->sendMessage($this->api->executeTranslationItem("closewarp-event-cancelled")); 47 | } 48 | } 49 | else { 50 | $sender->sendMessage($this->api->executeTranslationItem("warp-doesnt-exist")); 51 | } 52 | } 53 | else { 54 | $sender->sendMessage($this->getUsage()); 55 | Version::sendVersionMessage($sender); 56 | } 57 | } 58 | else { 59 | $sender->sendMessage($this->api->executeTranslationItem("closewarp-noperm")); 60 | } 61 | } 62 | } 63 | 64 | 65 | /** 66 | * @return \pocketmine\plugin\Plugin 67 | */ 68 | public function getPlugin(): Plugin{ 69 | return $this->api->getSimpleWarp(); 70 | } 71 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/WarpReportCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("warpreport-cmd"), $api->executeTranslationItem("warpreport-desc"), $api->executeTranslationItem("warpreport-usage")); 23 | $this->api = $api; 24 | } 25 | 26 | /** 27 | * @param CommandSender $sender 28 | * @param string $commandLabel 29 | * @param string[] $args 30 | * 31 | * @return mixed 32 | */ 33 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 34 | if(parent::execute($sender, $commandLabel, $args)) { 35 | if ($sender->hasPermission(SimpleWarpPermissions::WARP_REPORT_COMMAND)) { 36 | $data = $this->getPlugin()->getDebugDumpFactory()->generate(); 37 | if ($sender instanceof ConsoleCommandSender) { 38 | $issueContent = "\n\n(Explain your problem here)\n\n```\n$data\n```"; 39 | $url = "https://github.com/Falkirks/SimpleWarp/issues/new" . (count($args) > 0 ? "?title=" . urlencode(implode(" ", $args)) . "\&" : "?") . "body=" . urlencode($issueContent); 40 | switch (Utils::getOS()) { 41 | case 'win': 42 | `start $url`; 43 | break; 44 | case 'mac': 45 | `open $url`; 46 | break; 47 | case 'linux': 48 | `xdg-open $url`; 49 | break; 50 | default: 51 | $sender->sendMessage("Copy and paste the following URL into your browser to start a report."); 52 | $sender->sendMessage("------------------"); 53 | $sender->sendMessage($url); 54 | $sender->sendMessage("------------------"); 55 | break; 56 | } 57 | } 58 | $sender->sendMessage("--- SimpleWarp Data ---"); 59 | $sender->sendMessage($data); 60 | } 61 | else { 62 | $sender->sendMessage($this->api->executeTranslationItem("warpreport-noperm")); 63 | } 64 | return true; 65 | } 66 | } 67 | 68 | 69 | /** 70 | * @return \pocketmine\plugin\Plugin 71 | */ 72 | public function getPlugin(): Plugin{ 73 | return $this->api->getSimpleWarp(); 74 | } 75 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![SimpleWarp](/meta/simplewarp-2.png) 2 | 3 | ![Poggit](https://poggit.pmmp.io/ci.shield/Falkirks/SimpleWarp/SimpleWarp) 4 | [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/Falkirks/SimpleWarp.svg)](http://isitmaintained.com/project/Falkirks/SimpleWarp "Average time to resolve an issue") 5 | ![Total downloads](https://img.shields.io/github/downloads/Falkirks/SimpleWarp/total.svg) 6 | 7 | SimpleWarp is the original warp plugin for PocketMine-MP. It allows players to move from point **A** to **B** with ease. At the core of SimpleWarp is simplicity and extensibility. Although very easy on the end user, it exposes a powerful backend for developers to hack around with. 8 | 9 | **SimpleWarp 2.0 is not compatible with older SimpleWarp and PocketMine versions.** 10 | 11 | ## Commands 12 | | Command | Usage | Description | 13 | | ------- | ----- | ----------- | 14 | | `/warp` | `/warp [player]` | Warps you or another player to a specified warp. | 15 | | `/addwarp` | `/addwarp [ \| \|]` | Creates a new warp at a set location. | 16 | | `/delwarp` | `/delwarp ` | Deletes specified warp. | 17 | | `/listwarps` | `/listwarps` | Prints out list of warps. | 18 | | `/openwarp` | `/openwarp ` | Allows any player to access specified warp. | 19 | | `/closewarp` | `/closewarp ` | Restricts specfied so that only players with correct permission node can use it | 20 | | `/warpreport` | `/warpreport [title]` | Run from console to generate a new GitHub issue for SimpleWarp | 21 | 22 | ## Permissions 23 | ```yaml 24 | simplewarp: 25 | default: op 26 | children: 27 | simplewarp.command: 28 | default: op 29 | children: 30 | simplewarp.command.list: 31 | default: true 32 | children: 33 | simplewarp.command.list.xyz: 34 | default: op 35 | simplewarp.command.list.visual: 36 | default: op 37 | simplewarp.command.addwarp: 38 | default: op 39 | simplewarp.command.delwarp: 40 | default: op 41 | simplewarp.command.warp: 42 | default: true 43 | children: 44 | simplewarp.command.warp.other: 45 | default: op 46 | simplewarp.command.openwarp: 47 | default: op 48 | simplewarp.command.closewarp: 49 | default: op 50 | simplewarp.command.closewarp: 51 | default: op 52 | simplewarp.essentials.notice: 53 | default: op 54 | description: Recieve messages when their is warp conflict in Essentials 55 | simplewarp.warp: 56 | default: op 57 | description: Allows usage of all warps 58 | ``` 59 | 60 | ## API 61 | What good is a plugin without an API? SimpleWarp has an API which is used by it's own core components. 62 | 63 | ### Getting access 64 | Make sure to add the following to your `plugin.yml` 65 | 66 | ```yaml 67 | depend: ["SimpleWarp"] 68 | ``` 69 | **Note:** If you use `softdepend` you will need to check if SimpleWarp is installed. 70 | 71 | Now you can a copy of the API in your `onEnable` method 72 | 73 | ```php 74 | $api = SimpleWarpAPI::getInstance($this); // This only works inside a PluginBase 75 | ``` 76 | 77 | If you want to get the instance outside your main class, you can do 78 | 79 | ```php 80 | $api = $server->getPluginManager()->getPlugin("SimpleWarp")->getApi(); // $server is an instance of \pocketmine\Server 81 | ``` 82 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/ListWarpsCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("listwarps-cmd"), $api->executeTranslationItem("listwarps-desc"), $api->executeTranslationItem("listwarps-usage")); 21 | $this->api = $api; 22 | } 23 | 24 | /** 25 | * @param CommandSender $sender 26 | * @param string $commandLabel 27 | * @param string[] $args 28 | * 29 | * @return mixed 30 | */ 31 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 32 | if(parent::execute($sender, $commandLabel, $args)) { 33 | if ($sender->hasPermission(SimpleWarpPermissions::LIST_WARPS_COMMAND)) { 34 | $ret = $this->api->executeTranslationItem("listwarps-list-title"); 35 | /** @var Warp[] $iterator */ 36 | $iterator = $this->api->getWarpManager(); 37 | foreach ($iterator as $w) { 38 | if ($w->canUse($sender)) { 39 | $ret .= " * " . $w->getName() . " "; 40 | if ($sender->hasPermission(SimpleWarpPermissions::LIST_WARPS_COMMAND_XYZ)) { 41 | $dest = $w->getDestination(); 42 | $ret .= $dest->toString(); 43 | } 44 | $ret .= "\n"; 45 | } 46 | } 47 | /** 48 | * EASTER EGG! 49 | */ 50 | if ($sender instanceof Player && $sender->hasPermission(SimpleWarpPermissions::LIST_WARPS_COMMAND_VISUAL) && isset($args[0]) && $args[0] === "v") { 51 | foreach ($iterator as $warp) { 52 | if ($warp->getDestination()->isInternal() && $warp->getDestination()->getPosition()->getLevel() === $sender->getLevel()) { 53 | $particle = new FloatingTextParticle($warp->getDestination()->getPosition(), "(X: {$warp->getDestination()->getPosition()->getFloorX()}}, Y: {$warp->getDestination()->getPosition()->getFloorY()}, Z: {$warp->getDestination()->getPosition()->getFloorZ()}, LEVEL: {$warp->getDestination()->getPosition()->getLevel()->getName()})", "WARP: " . TextFormat::AQUA . $warp->getName() . TextFormat::RESET); 54 | $sender->getLevel()->addParticle($particle, [$sender]); 55 | } 56 | } 57 | } 58 | $sender->sendMessage(($ret !== $this->api->executeTranslationItem("listwarps-list-title") ? $ret : $this->api->executeTranslationItem("listwarps-no-warps"))); 59 | } 60 | else { 61 | $sender->sendMessage($this->api->executeTranslationItem("listwarps-noperm")); 62 | } 63 | } 64 | } 65 | 66 | 67 | /** 68 | * @return \pocketmine\plugin\Plugin 69 | */ 70 | public function getPlugin(): Plugin{ 71 | return $this->api->getSimpleWarp(); 72 | } 73 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/task/CommandWarpTask.php: -------------------------------------------------------------------------------- 1 | sender = $sender; 21 | 22 | if($this->getSimpleWarp()->getConfig()->get("hold-still-enabled")){ 23 | if ($this->player->getName() !== $this->sender->getName()) { 24 | $this->player->sendPopup($this->getSimpleWarp()->getApi()->executeTranslationItem("hold-still-popup")); 25 | $this->sender->sendMessage($this->getSimpleWarp()->getApi()->executeTranslationItem("hold-still-other")); 26 | } 27 | else { 28 | $this->player->sendPopup($this->getSimpleWarp()->getApi()->executeTranslationItem("hold-still-popup")); 29 | } 30 | } 31 | } 32 | 33 | /** 34 | * Actions to execute when run 35 | * 36 | * @param $currentTick 37 | * 38 | * @return void 39 | */ 40 | public function onRun(int $currentTick){ 41 | if($this->player instanceof Player && $this->player->isOnline()){ 42 | if(!$this->getSimpleWarp()->getConfig()->get("hold-still-enabled") || $this->player->getPosition()->equals($this->position)) { 43 | 44 | $this->player->sendPopup($this->getSimpleWarp()->getApi()->executeTranslationItem("warping-popup", $this->warp->getName())); 45 | 46 | $this->warp->teleport($this->player); 47 | 48 | $this->displaySmoke($this->position); 49 | 50 | if ($this->player->getName() !== $this->sender->getName()) { 51 | $this->sender->sendMessage($this->getSimpleWarp()->getApi()->executeTranslationItem("other-player-warped", $this->player->getName(), $this->warp->getName())); 52 | } 53 | else { 54 | $this->sender->sendMessage($this->getSimpleWarp()->getApi()->executeTranslationItem("warp-done")); 55 | } 56 | } 57 | else{ 58 | if ($this->player->getName() !== $this->sender->getName()) { 59 | $this->sender->sendMessage($this->getSimpleWarp()->getApi()->executeTranslationItem("hold-still-cancelled-other")); 60 | } 61 | else { 62 | $this->sender->sendMessage($this->getSimpleWarp()->getApi()->executeTranslationItem("hold-still-cancelled")); 63 | } 64 | } 65 | } 66 | } 67 | 68 | public function displaySmoke(Position $pos){ 69 | //particle smoke 120 71 124 1 1 1 35 200 70 | $random = new Random((int) (microtime(true) * 1000) + mt_rand()); 71 | 72 | $particle = new SmokeParticle(new Vector3($pos->x, $pos->y + 0.7, $pos->z), 200); 73 | for($i = 0; $i < 35; ++$i){ 74 | $particle->setComponents( 75 | $pos->x + $random->nextSignedFloat(), 76 | $pos->y + $random->nextSignedFloat(), 77 | $pos->z + $random->nextSignedFloat() 78 | ); 79 | $pos->getLevel()->addParticle($particle); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/Warp.php: -------------------------------------------------------------------------------- 1 | manager = $manager; 27 | $this->name = $name; 28 | $this->destination = $destination; 29 | $this->isPublic = $isPublic; 30 | $this->metadata = $metadata; 31 | SimpleWarpPermissions::setupPermission($this); 32 | } 33 | public function teleport(Player $player){ 34 | $ev = new PlayerWarpEvent($player, $this); 35 | $this->getServer()->getPluginManager()->callEvent($ev); 36 | if($ev->isCancelled()){ 37 | return; 38 | } 39 | $ev->getDestination()->teleport($player); 40 | } 41 | public function canUse(CommandSender $player): bool{ 42 | return ($this->isPublic || $player->hasPermission(SimpleWarpPermissions::BASE_WARP_PERMISSION) || $player->hasPermission(SimpleWarpPermissions::BASE_WARP_PERMISSION . "." . $this->name)); 43 | } 44 | 45 | /** 46 | * @param boolean $isPublic 47 | */ 48 | public function setPublic($isPublic = true){ 49 | $this->isPublic = $isPublic; 50 | $this->getManager()->offsetSet($this->name, $this); 51 | } 52 | 53 | /** 54 | * @return mixed 55 | */ 56 | public function getName(){ 57 | return $this->name; 58 | } 59 | 60 | /** 61 | * @return Destination 62 | */ 63 | public function getDestination(): Destination{ 64 | return $this->destination; 65 | } 66 | 67 | /** 68 | * @param Destination $destination 69 | */ 70 | public function setDestination(Destination $destination){ 71 | $this->destination = $destination; 72 | $this->getManager()->offsetSet($this->name, $this); 73 | } 74 | 75 | /** 76 | * @param WarpManager $manager 77 | */ 78 | public function setManager(WarpManager $manager){ 79 | $this->manager = $manager; 80 | $this->getManager()->offsetSet($this->name, $this); 81 | } 82 | 83 | /** 84 | * @return array 85 | */ 86 | public function getAllMetadata(): array{ 87 | return $this->metadata; 88 | } 89 | 90 | /** 91 | * @param $key 92 | * @return mixed 93 | */ 94 | public function getMetadata($key){ 95 | return $this->metadata[$key] ?? null; 96 | } 97 | /** 98 | * @param $key 99 | * @param $value 100 | */ 101 | public function setMetadata($key, $value){ 102 | $this->metadata[$key] = $value; 103 | $this->getManager()->offsetSet($this->name, $this); 104 | } 105 | 106 | /** 107 | * @return boolean 108 | */ 109 | public function isPublic(): bool { 110 | return $this->isPublic; 111 | } 112 | private function getServer(): Server{ 113 | return Server::getInstance(); 114 | } 115 | 116 | /** 117 | * @return WarpManager 118 | */ 119 | public function getManager(): WarpManager{ 120 | return $this->manager; 121 | } 122 | 123 | /** 124 | * For debugging use 125 | * @return array 126 | */ 127 | public function jsonSerialize(){ 128 | return [ 129 | 'dest' => $this->getDestination()->toString(), 130 | 'isPublic' => $this->isPublic(), 131 | 'metadata' => $this->metadata 132 | ]; 133 | } 134 | 135 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/Destination.php: -------------------------------------------------------------------------------- 1 | position = $params[0]; 26 | $this->message = (isset($params[1]) ? $params[1] : null); 27 | } 28 | else{ 29 | if(isset($params[1])){ 30 | $this->address = $params[0]; 31 | $this->port = $params[1]; 32 | $this->message = (isset($params[2]) ? $params[2] : null); 33 | } 34 | else{ 35 | throw new \BadMethodCallException; 36 | } 37 | } 38 | } 39 | else{ 40 | throw new \BadMethodCallException; 41 | } 42 | } 43 | public function teleport(Player $player){ 44 | if($this->message !== null){ 45 | $player->sendMessage($this->message); 46 | } 47 | 48 | if($this->position instanceof Position){ 49 | if($this->position->isValid()) { 50 | if($this->position instanceof WeakPosition){ 51 | $this->position->updateProperties(); 52 | } 53 | //Server::getInstance()->getLogger()->info($this->position->x . " : " . $this->position->y . " : " . $this->position->z); 54 | $player->teleport($this->position); 55 | } 56 | else{ 57 | $player->sendMessage($this->getApi()->executeTranslationItem("level-not-loaded-warp")); 58 | } 59 | } 60 | else{ 61 | $plugin = $player->getServer()->getPluginManager()->getPlugin("FastTransfer"); 62 | if(method_exists($player, "transfer")){ 63 | $player->transfer($this->address, $this->port); 64 | } 65 | elseif($plugin instanceof PluginBase && $plugin->isEnabled()){ 66 | $plugin->transferPlayer($player, $this->address, $this->port); 67 | } 68 | else{ 69 | $player->getServer()->getPluginManager()->getPlugin("SimpleWarp")->getLogger()->warning("In order to use warps to other servers, you must install " . TextFormat::AQUA . "FastTransfer" . TextFormat::RESET . " or use a newer PocketMine version."); 70 | $player->sendPopup($this->getApi()->executeTranslationItem("warp-failed-popup")); 71 | } 72 | } 73 | } 74 | public function isInternal(): bool{ 75 | return $this->position instanceof Position; 76 | } 77 | 78 | /** 79 | * @return Position 80 | */ 81 | public function getPosition(): Position{ 82 | return $this->position; 83 | } 84 | 85 | /** 86 | * @return mixed 87 | */ 88 | public function getAddress(){ 89 | return $this->address; 90 | } 91 | 92 | /** 93 | * @return mixed 94 | */ 95 | public function getPort(){ 96 | return $this->port; 97 | } 98 | public function toString(){ 99 | if($this->isInternal()) { 100 | if($this->position instanceof WeakPosition){ 101 | $levelName = $this->position->levelName; 102 | } 103 | else{ 104 | $levelName = $this->position->getLevel()->getName(); 105 | } 106 | if($this->getApi()->getConfigItem("display-exact-coordinates")) { 107 | return "(X: {$this->getPosition()->x}, Y: {$this->getPosition()->y}, Z: {$this->getPosition()->z}, LEVEL: {$levelName})"; 108 | } 109 | else{ 110 | return "(X: {$this->getPosition()->getFloorX()}, Y: {$this->getPosition()->getFloorY()}, Z: {$this->getPosition()->getFloorZ()}, LEVEL: " . $levelName . ")"; 111 | } 112 | } 113 | return "(IP: {$this->getAddress()}, PORT: {$this->getPort()})"; 114 | } 115 | 116 | public function __toString() { 117 | return $this->toString(); 118 | } 119 | 120 | 121 | /** 122 | * @return SimpleWarpApi 123 | */ 124 | protected function getApi(): SimpleWarpAPI{ 125 | return Server::getInstance()->getPluginManager()->getPlugin("SimpleWarp")->getApi(); 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/WarpCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("warp-cmd"), $api->executeTranslationItem("warp-desc"), $api->executeTranslationItem("warp-usage")); 29 | $this->api = $api; 30 | } 31 | 32 | /** 33 | * @param CommandSender $sender 34 | * @param string $commandLabel 35 | * @param string[] $args 36 | * 37 | * @return mixed 38 | */ 39 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 40 | if (parent::execute($sender, $commandLabel, $args)) { 41 | if ($sender->hasPermission(SimpleWarpPermissions::WARP_COMMAND)) { 42 | if (isset($args[0])) { 43 | if (isset($this->api->getWarpManager()[$args[0]])) { 44 | if (isset($args[1])) { 45 | if ($sender->hasPermission(SimpleWarpPermissions::WARP_OTHER_COMMAND)) { 46 | if (($player = $this->api->getSimpleWarp()->getServer()->getPlayer($args[1])) instanceof Player) { 47 | /** @var Warp $warp */ 48 | $warp = $this->api->getWarpManager()[$args[0]]; 49 | if ($warp->canUse($sender)) { 50 | $task = new CommandWarpTask($this->getPlugin(), $warp, $player, $sender); 51 | $task->run(); 52 | } 53 | else { 54 | $sender->sendMessage($this->api->executeTranslationItem("no-permission-warp")); 55 | } 56 | } 57 | else { 58 | $sender->sendMessage($this->api->executeTranslationItem("player-not-loaded")); 59 | } 60 | } 61 | else { 62 | $sender->sendMessage($this->api->executeTranslationItem("no-permission-warp-other")); 63 | } 64 | } 65 | elseif ($sender instanceof Player) { 66 | /** @var Warp $warp */ 67 | $warp = $this->api->getWarpManager()[$args[0]]; 68 | if ($warp->canUse($sender)) { 69 | $task = new CommandWarpTask($this->getPlugin(), $warp, $sender, $sender); 70 | $task->run(); 71 | } 72 | else { 73 | $sender->sendMessage($this->api->executeTranslationItem("no-permission-warp")); 74 | } 75 | } 76 | else { 77 | $sender->sendMessage($this->getUsage()); 78 | 79 | } 80 | } 81 | else { 82 | $sender->sendMessage($this->api->executeTranslationItem("warp-doesnt-exist")); 83 | } 84 | } 85 | else { 86 | $sender->sendMessage($this->getUsage()); 87 | Version::sendVersionMessage($sender); 88 | } 89 | } 90 | else { 91 | $sender->sendMessage($this->api->executeTranslationItem("warp-noperm")); 92 | } 93 | } 94 | } 95 | 96 | public function displaySmoke(Position $pos) { 97 | //particle smoke 120 71 124 1 1 1 35 200 98 | $random = new Random((int)(microtime(true) * 1000) + mt_rand()); 99 | 100 | $particle = new SmokeParticle(new Vector3($pos->x, $pos->y + 0.7, $pos->z), 200); 101 | for ($i = 0; $i < 35; ++$i) { 102 | $particle->setComponents( 103 | $pos->x + $random->nextSignedFloat(), 104 | $pos->y + $random->nextSignedFloat(), 105 | $pos->z + $random->nextSignedFloat() 106 | ); 107 | $pos->getLevel()->addParticle($particle); 108 | } 109 | } 110 | 111 | /** 112 | * @return \pocketmine\plugin\Plugin 113 | */ 114 | public function getPlugin(): Plugin{ 115 | return $this->api->getSimpleWarp(); 116 | } 117 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/SimpleWarp.php: -------------------------------------------------------------------------------- 1 | saveDefaultConfig(); 40 | 41 | $this->api = new SimpleWarpAPI($this); 42 | $this->debugDumpFactory = new DebugDumpFactory($this->api); 43 | $this->translationManager = new TranslationManager($this->api, new YAMLStore(new Config($this->getDataFolder() . "lang.yml", Config::YAML))); 44 | $this->warpManager = new WarpManager($this->api, new YAMLStore(new Config($this->getDataFolder() . "warps.yml", Config::YAML)), ($this->getConfig()->get('storage-mode') != null ? $this->getConfig()->get('storage-mode') : WarpManager::MEMORY_TILL_CLOSE)); 45 | 46 | $this->commands = [ 47 | new ListWarpsCommand($this->api), 48 | new OpenWarpCommand($this->api), 49 | new CloseWarpCommand($this->api), 50 | new WarpReportCommand($this->api), 51 | new AddWarpCommand($this->api) 52 | ]; 53 | if($this->getServer()->getPluginManager()->getPlugin("EssentialsPE") instanceof Plugin && $this->getConfig()->get("essentials-support")){ 54 | $this->getLogger()->info("Enabling EssentialsPE support..."); 55 | $warpCommand = $this->getServer()->getCommandMap()->getCommand("warp"); 56 | $delWarpCommand = $this->getServer()->getCommandMap()->getCommand("delwarp"); 57 | $this->unregisterCommands([ 58 | "warp", 59 | "delwarp" 60 | ]); 61 | array_push($this->commands, new EssentialsWarpCommand($this->api, $warpCommand)); 62 | array_push($this->commands, new EssentialsDelWarpCommand($this->api, $delWarpCommand)); 63 | } 64 | else { 65 | array_push($this->commands, new WarpCommand($this->api)); 66 | array_push($this->commands, new DelWarpCommand($this->api)); 67 | } 68 | 69 | $this->getServer()->getCommandMap()->registerAll("simplewarp", $this->commands); 70 | 71 | if(file_exists($this->getDataFolder() . ".started") && $this->warpManager->getFlag() === WarpManager::MEMORY_TILL_CLOSE){ 72 | $this->getLogger()->critical("SimpleWarp is starting in an inconsistent state. This is likely due to a server crash. You are using storage-mode=0 which means you could have lost data. Read more at http://bit.ly/0data"); 73 | } 74 | 75 | file_put_contents($this->getDataFolder() . ".started", "true"); 76 | SpoonDetector::printSpoon($this, 'spoon.txt'); 77 | 78 | if(ChecksumVerify::isValid($this)){ 79 | $this->getLogger()->info(TextFormat::LIGHT_PURPLE . "Your copy of SimpleWarp was verified." . TextFormat::RESET); 80 | } 81 | else{ 82 | //TODO add negative response (in next version because I don't know if this works) 83 | } 84 | } 85 | public function onDisable(){ 86 | $this->warpManager->saveAll(); 87 | 88 | $this->warpManager = null; 89 | $this->api = null; 90 | $this->debugDumpFactory = null; 91 | $this->translationManager = null; 92 | 93 | @unlink($this->getDataFolder() . ".started"); 94 | if(file_exists($this->getDataFolder() . ".started")){ 95 | $this->getLogger()->alert("Unable to clean up session file. You will be shown an error next time you start. You can ignore it."); 96 | } 97 | } 98 | 99 | /** 100 | * @return DebugDumpFactory 101 | */ 102 | public function getDebugDumpFactory(): DebugDumpFactory{ 103 | return $this->debugDumpFactory; 104 | } 105 | 106 | 107 | /** 108 | * @return WarpManager 109 | */ 110 | public function getWarpManager(): WarpManager{ 111 | return $this->warpManager; 112 | } 113 | 114 | /** 115 | * @return TranslationManager 116 | */ 117 | public function getTranslationManager(): TranslationManager{ 118 | return $this->translationManager; 119 | } 120 | 121 | /** 122 | * @param WarpManager $warpManager 123 | */ 124 | public function setWarpManager(WarpManager $warpManager){ 125 | $warpManager->saveAll(); 126 | $this->warpManager = $warpManager; 127 | } 128 | 129 | /** 130 | * @param TranslationManager $translationManager 131 | */ 132 | public function setTranslationManager(TranslationManager $translationManager){ 133 | $this->translationManager = $translationManager; 134 | } 135 | 136 | /** 137 | * @return SimpleWarpAPI 138 | */ 139 | public function getApi(): SimpleWarpAPI{ 140 | return $this->api; 141 | } 142 | 143 | /** 144 | * Function to easily disable commands 145 | * 146 | * @param array $commands 147 | */ 148 | private function unregisterCommands(array $commands){ 149 | $commandMap = $this->getServer()->getCommandMap(); 150 | foreach($commands as $label){ 151 | $command = $commandMap->getCommand($label); 152 | $command->setLabel($label . "_disabled"); 153 | $command->unregister($commandMap); 154 | } 155 | } 156 | 157 | /** 158 | * @return Command[] 159 | */ 160 | public function getCommands(): array { 161 | return $this->commands; 162 | } 163 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/command/AddWarpCommand.php: -------------------------------------------------------------------------------- 1 | executeTranslationItem("addwarp-cmd"), $api->executeTranslationItem("addwarp-desc"), $api->executeTranslationItem("addwarp-usage")); 27 | $this->api = $api; 28 | } 29 | 30 | /** 31 | * @param CommandSender $sender 32 | * @param string $commandLabel 33 | * @param string[] $args 34 | * 35 | * @return mixed 36 | */ 37 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 38 | if (parent::execute($sender, $commandLabel, $args)) { 39 | if ($sender->hasPermission(SimpleWarpPermissions::ADD_WARP_COMMAND)) { 40 | if (isset($args[0])) { 41 | if (!isset($this->api->getWarpManager()[$args[0]])) { 42 | if (substr($args[0], 0, 4) === "ess:" && $this->api->getConfigItem("essentials-support") && $sender->hasPermission("simplewarp.essentials.notice")) { 43 | $sender->sendMessage($this->api->executeTranslationItem("addwarp-ess-prefix-warning")); 44 | } 45 | if (isset($args[3])) { 46 | $level = (isset($args[4]) ? $this->api->getSimpleWarp()->getServer()->getLevelByName($args[4]) : $this->api->getSimpleWarp()->getServer()->getDefaultLevel()); 47 | if ($level instanceof Level) { 48 | $dest = new Destination(new WeakPosition($args[1], $args[2], $args[3], $level->getName())); 49 | $warp = new Warp($this->api->getWarpManager(), $args[0], $dest); 50 | $ev = new WarpAddEvent($sender, $warp); 51 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 52 | if (!$ev->isCancelled()) { 53 | $this->api->getWarpManager()[$args[0]] = $warp; 54 | $sender->sendMessage($this->api->executeTranslationItem("warp-added-xyz", $args[0], $dest->toString())); 55 | } 56 | else { 57 | $sender->sendMessage($this->api->executeTranslationItem("addwarp-event-cancelled")); 58 | } 59 | } 60 | else { 61 | $sender->sendMessage($this->api->executeTranslationItem("level-not-loaded")); 62 | } 63 | } 64 | elseif (isset($args[2])) { 65 | $dest = new Destination($args[1], $args[2]); 66 | $warp = new Warp($this->api->getWarpManager(), $args[0], $dest); 67 | $ev = new WarpAddEvent($sender, $warp); 68 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 69 | if (!$ev->isCancelled()) { 70 | $this->api->getWarpManager()[$args[0]] = $warp; 71 | $sender->sendMessage($this->api->executeTranslationItem("warp-added-server", $args[0], $dest->toString())); 72 | if (!$this->api->supportsExternalWarps()) { 73 | $sender->sendMessage($this->api->executeTranslationItem("needs-external-warps")); 74 | } 75 | } 76 | else { 77 | $sender->sendMessage($this->api->executeTranslationItem("addwarp-event-cancelled")); 78 | } 79 | } 80 | elseif (isset($args[1])) { 81 | if (($player = $this->api->getSimpleWarp()->getServer()->getPlayer($args[1])) instanceof Player) { 82 | $dest = new Destination(new Position($player->getX(), $player->getY(), $player->getZ(), $player->getLevel())); 83 | $warp = new Warp($this->api->getWarpManager(), $args[0], $dest); 84 | $ev = new WarpAddEvent($sender, $warp); 85 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 86 | if (!$ev->isCancelled()) { 87 | $this->api->getWarpManager()[$args[0]] = $warp; 88 | $sender->sendMessage($this->api->executeTranslationItem("warp-added-player", $args[0], $dest->toString())); 89 | } 90 | else { 91 | $sender->sendMessage($this->api->executeTranslationItem("addwarp-event-cancelled")); 92 | } 93 | } 94 | else { 95 | $sender->sendMessage($this->api->executeTranslationItem("player-not-loaded")); 96 | } 97 | } 98 | else { 99 | if ($sender instanceof Player) { 100 | $dest = new Destination(new Position($sender->getX(), $sender->getY(), $sender->getZ(), $sender->getLevel())); 101 | $warp = new Warp($this->api->getWarpManager(), $args[0], $dest); 102 | $ev = new WarpAddEvent($sender, $warp); 103 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 104 | if (!$ev->isCancelled()) { 105 | $this->api->getWarpManager()[$args[0]] = $warp; 106 | $sender->sendMessage($this->api->executeTranslationItem("warp-added-self", $args[0], $dest->toString())); 107 | } 108 | else { 109 | $sender->sendMessage($this->api->executeTranslationItem("addwarp-event-cancelled")); 110 | } 111 | } 112 | else { 113 | $sender->sendMessage($this->getUsage()); 114 | } 115 | } 116 | } 117 | else { 118 | $sender->sendMessage($this->api->executeTranslationItem("bad-warp-name")); 119 | } 120 | } 121 | else { 122 | $sender->sendMessage($this->getUsage()); 123 | Version::sendVersionMessage($sender); 124 | } 125 | } 126 | else { 127 | $sender->sendMessage($this->api->executeTranslationItem("addwarp-no-perm")); 128 | } 129 | } 130 | } 131 | 132 | public function generateCustomCommandData(Player $player) { 133 | return parent::generateCustomCommandData($player); // TODO: Change the autogenerated stub 134 | } 135 | 136 | 137 | /** 138 | * @return \pocketmine\plugin\Plugin 139 | */ 140 | public function getPlugin(): Plugin{ 141 | return $this->api->getSimpleWarp(); 142 | } 143 | } -------------------------------------------------------------------------------- /src/falkirks/simplewarp/api/SimpleWarpAPI.php: -------------------------------------------------------------------------------- 1 | plugin = $simpleWarp; 35 | } 36 | 37 | /** 38 | * gets a copy of the SimpleWarp plugin object 39 | * @return SimpleWarp 40 | */ 41 | public function getSimpleWarp(): SimpleWarp{ 42 | return $this->plugin; 43 | } 44 | 45 | /** 46 | * gets a config option 47 | * example SimpleWarpAPI::getConfigItem('display-exact-coordinates') 48 | * @param $name 49 | * @return string 50 | */ 51 | public function getConfigItem($name): string{ 52 | return $this->plugin->getConfig()->get($name); 53 | } 54 | 55 | /** 56 | * @param $name 57 | * @param array ...$args 58 | * @return string 59 | */ 60 | public function executeTranslationItem($name, ...$args): string{ 61 | return $this->plugin->getTranslationManager()->execute($name, ...$args); 62 | } 63 | 64 | /** 65 | * @param $name 66 | * @return string 67 | */ 68 | public function getTranslationItem($name): string{ 69 | return $this->plugin->getTranslationManager()->get($name); 70 | } 71 | 72 | /** 73 | * Gets a warp object with $name from the current WarpManager 74 | * @param $name 75 | * @return Warp|null 76 | */ 77 | public function getWarp($name){ 78 | return $this->getWarpManager()[$name]; 79 | } 80 | 81 | /** 82 | * Adds a new Warp to the WarpManager, will be saved according to storage-mode 83 | * @param Warp $warp 84 | */ 85 | public function saveWarp(Warp $warp){ 86 | $this->getWarpManager()[$warp->getName()] = $warp; 87 | } 88 | 89 | /** 90 | * Creates a new warp object and saves it. 91 | * 92 | * @param $name 93 | * @param Destination $dest 94 | * @param bool $isPublic 95 | * @param array $metadata 96 | * @return Warp 97 | */ 98 | public function makeWarp($name, Destination $dest, $isPublic = false, $metadata = []){ 99 | $w = new Warp($this->getWarpManager(), $name, $dest, $isPublic, $metadata); 100 | $this->saveWarp($w); 101 | return $w; 102 | } 103 | 104 | /** 105 | * Warps a player to a warp with $name without checking 106 | * if the player can use that warp. 107 | * @param Player $player 108 | * @param $name 109 | * @return bool 110 | */ 111 | public function warpPlayerTo(Player $player, $name): bool{ 112 | $warp = $this->getWarp($name); 113 | if($warp instanceof Warp){ 114 | $warp->teleport($player); 115 | return true; 116 | } 117 | return false; 118 | } 119 | 120 | /** 121 | * Checks if a player has permission to use a warp 122 | * @param Player $player 123 | * @param $name 124 | * @return bool 125 | */ 126 | public function canPlayerUse(Player $player, $name): bool{ 127 | $warp = $this->getWarp($name); 128 | if($warp instanceof Warp){ 129 | return $warp->canUse($player); 130 | } 131 | return null; 132 | } 133 | 134 | /** 135 | * Returns the TranslationManager 136 | * @return TranslationManager 137 | */ 138 | public function getTranslationManager(): TranslationManager{ 139 | return $this->plugin->getTranslationManager(); 140 | } 141 | 142 | /** 143 | * Sets the TranslationManager 144 | * ! Will inject your code into SimpleWarp, potentially breaking ! 145 | * @param TranslationManager $translationManager 146 | */ 147 | public function setTranslationManager(TranslationManager $translationManager){ 148 | $this->plugin->setTranslationManager($translationManager); 149 | } 150 | 151 | /** 152 | * Returns the WarpManager 153 | * @return WarpManager 154 | */ 155 | public function getWarpManager(): WarpManager{ 156 | return $this->plugin->getWarpManager(); 157 | } 158 | 159 | /** 160 | * Sets the WarpManager, the old one's data store will be saved before a new one is added 161 | * ! Will inject your code into SimpleWarp, potentially breaking ! 162 | * @param WarpManager $warpManager 163 | */ 164 | public function setWarpManager(WarpManager $warpManager){ 165 | $this->plugin->setWarpManager($warpManager); 166 | } 167 | 168 | /** 169 | * gets whether warp metadata is being saved 170 | * you can use metadata regardless, it just won't be saved on restart 171 | * @return string 172 | */ 173 | public function isMetadataSaved(){ 174 | return true; 175 | } 176 | 177 | /** 178 | * Gets the value of a metadata item on a warp safely 179 | * IMPORANT: All plugin metadata keys should be expressed as "namespace-keyname" 180 | * this will avoid potential collisions. 181 | * You can use the provided getSafeMetadataName for this. 182 | * @param Warp $warp 183 | * @param $key 184 | * @return mixed 185 | */ 186 | public function getMetadata(Warp $warp, $key){ 187 | return $warp->getMetadata($key); 188 | } 189 | 190 | /** 191 | * Sets the value of a metadata item on a warp safely 192 | * IMPORANT: All plugin metadata keys should be expressed as "namespace-keyname" 193 | * this will avoid potential collisions. 194 | * You can use the provided getSafeMetadataName for this. 195 | * @param Warp $warp 196 | * @param $key 197 | * @param $value 198 | */ 199 | public function setMetadata(Warp $warp, $key, $value){ 200 | $warp->setMetadata($key, $value); 201 | } 202 | 203 | /** 204 | * Gets warp(s) with the key value pair of metadata as specified 205 | * 206 | * IMPORANT: All plugin metadata keys should be expressed as "namespace-keyname" 207 | * this will avoid potential collisions. 208 | * You can use the provided getSafeMetadataName for this. 209 | * @param $key 210 | * @param $value 211 | * @return array 212 | */ 213 | public function getWarpsFromMetadata($key, $value): array{ 214 | $ret = []; 215 | foreach ($this->getWarpManager() as $warp){ 216 | if($warp instanceof Warp && $warp->getMetadata($key) === $value){ 217 | $ret[] = $warp; 218 | } 219 | } 220 | return $ret; 221 | } 222 | 223 | /** 224 | * gets a c 225 | * @param PluginBase $plugin 226 | * @param $key 227 | * @return string 228 | */ 229 | public function getSafeMetadataName(PluginBase $plugin, $key){ 230 | return $plugin->getName() . "-" . $key; 231 | } 232 | 233 | /** 234 | * Produces true if FastTransfer is loaded and enabled 235 | * DEPRECATED! 236 | * @deprecated 237 | * @return bool 238 | */ 239 | public function isFastTransferLoaded(): bool{ 240 | return $this->getSimpleWarp()->getServer()->getPluginManager()->getPlugin("FastTransfer") instanceof PluginBase; 241 | } 242 | 243 | /** 244 | * Returns true if external warps are supported, false otherwise 245 | * @return bool 246 | */ 247 | public function supportsExternalWarps(): bool { 248 | return method_exists(Player::class, "transfer") || $this->getSimpleWarp()->getServer()->getPluginManager()->getPlugin("FastTransfer") instanceof PluginBase; 249 | } 250 | /** 251 | * This will hopefully save someone typing. 252 | * Call SimpleWarpAPI::getInstance($this) from your main class to get the current API instance 253 | * @param PluginBase $base 254 | * @return SimpleWarpAPI 255 | */ 256 | public static function getInstance(PluginBase $base): SimpleWarpAPI{ 257 | return $base->getServer()->getPluginManager()->getPlugin("SimpleWarp")->getApi(); 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/lang/TranslationManager.php: -------------------------------------------------------------------------------- 1 | api = $api; 24 | $this->store = $store; 25 | $this->registerDefaults(); 26 | $this->save(); 27 | 28 | } 29 | public function get($name){ 30 | return $this->store->get($name); 31 | } 32 | public function execute($name, ...$args): string{ 33 | if($args === null || count($args) === 0){ 34 | return $this->get($name); 35 | } 36 | if(is_array($args[0])){ 37 | $args = $args[0]; 38 | } 39 | return sprintf($this->get($name), ...$args); 40 | } 41 | protected function registerDefaults(){ 42 | $this->registerDefault("addwarp-cmd", "addwarp"); 43 | $this->registerDefault("addwarp-desc", "Add new warps."); 44 | $this->registerDefault("addwarp-usage", "/addwarp [ | |]"); 45 | $this->registerDefault("addwarp-event-cancelled", "A plugin has cancelled the creation of this warp."); 46 | 47 | $this->registerDefault("closewarp-cmd", "closewarp"); 48 | $this->registerDefault("closewarp-desc", "Close existing warps."); 49 | $this->registerDefault("closewarp-usage", "/closewarp "); 50 | $this->registerDefault("closewarp-event-cancelled", "A plugin has cancelled this action."); 51 | 52 | $this->registerDefault("delwarp-cmd", "delwarp"); 53 | $this->registerDefault("delwarp-desc", "Delete existing warps."); 54 | $this->registerDefault("delwarp-usage", "/delwarp "); 55 | $this->registerDefault("delewarp-event-cancelled", "A plugin has cancelled the deletion of this warp."); 56 | 57 | $this->registerDefault("listwarps-cmd", "listwarps"); 58 | $this->registerDefault("listwarps-desc", "List all your warps."); 59 | $this->registerDefault("listwarps-usage", "/listwarps"); 60 | $this->registerDefault("listwarps-list-title", "Warp list:\n"); 61 | $this->registerDefault("listwarps-no-warps", TextFormat::RED . "No warps found." . TextFormat::RESET); 62 | $this->registerDefault("listwarps-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 63 | 64 | $this->registerDefault("openwarp-cmd", "openwarp"); 65 | $this->registerDefault("openwarp-desc", "Open existing warps."); 66 | $this->registerDefault("openwarp-usage", "/openwarp "); 67 | $this->registerDefault("delwarp-event-cancelled", "A plugin has cancelled this action."); 68 | 69 | $this->registerDefault("warp-cmd", "warp"); 70 | $this->registerDefault("warp-desc", "Warp around your world."); 71 | $this->registerDefault("warp-usage", "/warp [player]"); 72 | 73 | $this->registerDefault("warp-added-xyz", "You have created a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET . " %s"); 74 | $this->registerDefault("warp-added-player", "You have created a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET . " %s"); 75 | $this->registerDefault("warp-added-server", "You have created a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET . " %s"); 76 | $this->registerDefault("warp-added-self", "You have created a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET . " %s"); 77 | 78 | $this->registerDefault("level-not-loaded", TextFormat::RED . "You specified a level which isn't loaded.\nPlease see http://bit.ly/levelerror for explanation." . TextFormat::RESET); 79 | 80 | $this->registerDefault("needs-external-warps", "This warp needs " . TextFormat::AQUA . "FastTransfer" . TextFormat::RESET . " or a newer version of PocketMine."); 81 | 82 | $this->registerDefault("player-not-loaded", TextFormat::RED . "You specified a player which isn't loaded." . TextFormat::RESET); 83 | 84 | $this->registerDefault("addwarp-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 85 | 86 | $this->registerDefault("bad-warp-name", TextFormat::RED . "That warp name is invalid." . TextFormat::RESET); 87 | 88 | $this->registerDefault("closed-warp-1", "You have closed a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET); 89 | $this->registerDefault("closed-warp-2", " Only players with the permission " . TextFormat::AQUA . "%s" . TextFormat::RESET . " will be able to use this warp."); 90 | $this->registerDefault("warp-doesnt-exist", TextFormat::RED . "That warp doesn't exist." . TextFormat::RESET); 91 | $this->registerDefault("closewarp-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 92 | 93 | $this->registerDefault("warp-deleted", "You have deleted a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET); 94 | $this->registerDefault("delwarp-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 95 | 96 | $this->registerDefault("opened-warp-1", "You have opened a warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET); 97 | $this->registerDefault("opened-warp-2", " Any player will be able to use this warp."); 98 | $this->registerDefault("openwarp-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 99 | 100 | $this->registerDefault("warping-popup", "Warping..."); 101 | $this->registerDefault("other-player-warped", "%s has been warped to " . TextFormat::AQUA . "%s" . TextFormat::RESET . "."); 102 | $this->registerDefault("no-permission-warp", TextFormat::RED . "You don't have permission to use this warp." . TextFormat::RESET); 103 | $this->registerDefault("no-permission-warp-other", TextFormat::RED . "You don't have permission to warp other players." . TextFormat::RESET); 104 | $this->registerDefault("warp-done", "You have been warped"); 105 | $this->registerDefault("warp-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 106 | 107 | $this->registerDefault("level-not-loaded-warp", "The warp you are using is attached to a level which isn't loaded"); 108 | 109 | $this->registerDefault("ess-warp-doesnt-exist", TextFormat::RED . "That warp doesn't exist." . TextFormat::RESET); 110 | $this->registerDefault("ess-warp-conflict", "The warp called " . TextFormat::AQUA . "%s" . TextFormat::RESET . " exists in both " . TextFormat::AQUA . "EssentialsPE" . TextFormat::RESET . " and " . TextFormat::AQUA . "SimpleWarp" . TextFormat::RESET . ". The one from " . TextFormat::AQUA . "SimpleWarp" . TextFormat::RESET . " will be used by default. If you wish to use the " . TextFormat::AQUA . "EssentialsPE" . TextFormat::RESET . " warp, prefix the warp name with " . TextFormat::DARK_AQUA . "ess:" . TextFormat::RESET); 111 | 112 | $this->registerDefault("addwarp-ess-prefix-warning", "Support for " . TextFormat::AQUA . "EssentialsPE" . TextFormat::RESET . " is enabled on this server. When a user wants to explicitly use an " . TextFormat::AQUA . "EssentialsPE" . TextFormat::RESET . " warp, they can prefix their command with " . TextFormat::DARK_AQUA . "ess:" . TextFormat::RESET . ". By choosing to pick a warp name that starts with the same prefix, you are making things complicated. Maybe pick a different name?"); 113 | 114 | $this->registerDefault("hold-still-popup", "HOLD STILL to WARP."); 115 | $this->registerDefault("hold-still-other", "The target must hold still to complete the warp."); 116 | $this->registerDefault("hold-still-cancelled", "The warp was unsuccessful because you moved."); 117 | $this->registerDefault("hold-still-cancelled-other", "The warp was unsuccessful because the target moved."); 118 | 119 | $this->registerDefault("warp-failed-popup", TextFormat::RED . "Warp failed!" . TextFormat::RESET); 120 | 121 | $this->registerDefault("warpreport-cmd", "warpreport"); 122 | $this->registerDefault("warpreport-desc", "Report an issue with SimpleWarp."); 123 | $this->registerDefault("warpreport-usage", "/warpreport [title]"); 124 | $this->registerDefault("warpreport-noperm", TextFormat::RED . "You don't have permission to use this command" . TextFormat::RESET); 125 | 126 | $this->registerDefault("plugin-disabled", TextFormat::RED . "SimpleWarp is disabled and can't execute commands." . TextFormat::RESET); 127 | } 128 | protected function registerDefault($name, $text){ 129 | if(!$this->store->exists($name)){ 130 | $this->store->add($name, $text); 131 | } 132 | } 133 | public function reload(){ 134 | if($this->store instanceof Reloadable){ 135 | $this->store->reload(); 136 | } 137 | } 138 | protected function save(){ 139 | if($this->store instanceof Saveable){ 140 | $this->store->save(); 141 | } 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/falkirks/simplewarp/WarpManager.php: -------------------------------------------------------------------------------- 1 | api = $api; 36 | $this->store = $store; 37 | $this->flag = $flag; 38 | $this->warps = []; 39 | if($this->flag < 2){ 40 | $this->warps = $this->loadWarps(); 41 | } 42 | } 43 | protected function reloadStore(){ 44 | if($this->flag >= 2 && $this->store instanceof Reloadable){ 45 | $this->store->reload(); 46 | } 47 | } 48 | protected function saveStore($force = false){ 49 | if(($this->flag > 0 || $force) && $this->store instanceof Saveable){ 50 | $this->store->save(); 51 | } 52 | } 53 | protected function loadWarps(): array{ 54 | $out = []; 55 | foreach($this->store->getIterator() as $name => $data){ 56 | $out[$name] = $this->warpFromData($name, $data); 57 | } 58 | return $out; 59 | } 60 | /** 61 | * WARNING 62 | * This function is for internal use only. 63 | */ 64 | public function saveAll(){ 65 | if($this->flag === 0){ 66 | $this->store->clear(); 67 | foreach($this->warps as $warp){ 68 | $this->store->add($warp->getName(), $this->warpToData($warp)); 69 | } 70 | $this->saveStore(true); 71 | } 72 | } 73 | /** 74 | * (PHP 5 >= 5.0.0)
75 | * Whether a offset exists 76 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php 77 | * @param mixed $offset

78 | * An offset to check for. 79 | *

80 | * @return boolean true on success or false on failure. 81 | *

82 | *

83 | * The return value will be casted to boolean if non-boolean was returned. 84 | */ 85 | public function offsetExists($offset){ 86 | $this->reloadStore(); 87 | if(isset($this->warps[$offset]) || ($this->flag >= 2 && $this->store->exists($offset))){ 88 | return true; 89 | } 90 | return false; 91 | } 92 | 93 | /** 94 | * (PHP 5 >= 5.0.0)
95 | * Offset to retrieve 96 | * @link http://php.net/manual/en/arrayaccess.offsetget.php 97 | * @param mixed $offset

98 | * The offset to retrieve. 99 | *

100 | * @return mixed Can return all value types. 101 | */ 102 | public function offsetGet($offset){ 103 | if($this->flag >= 2){ 104 | $this->reloadStore(); 105 | return $this->warpFromData($offset, $this->store->get($offset)); 106 | } 107 | return isset($this->warps[$offset]) ? $this->warps[$offset] : null; 108 | } 109 | 110 | /** 111 | * (PHP 5 >= 5.0.0)
112 | * Offset to set 113 | * @link http://php.net/manual/en/arrayaccess.offsetset.php 114 | * @param mixed $offset

115 | * The offset to assign the value to. 116 | *

117 | * @param mixed $value

118 | * The value to set. 119 | *

120 | * @return void 121 | */ 122 | public function offsetSet($offset, $value){ 123 | if($value instanceof Warp && $value->getName() === $offset) { 124 | if($this->flag < 2) { 125 | $this->warps[$offset] = $value; 126 | } 127 | 128 | if ($this->flag >= 1) { 129 | $this->store->add($offset, $this->warpToData($value)); 130 | $this->saveStore(); 131 | } 132 | } 133 | else{ 134 | //TODO report failure 135 | } 136 | } 137 | 138 | /** 139 | * (PHP 5 >= 5.0.0)
140 | * Offset to unset 141 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php 142 | * @param mixed $offset

143 | * The offset to unset. 144 | *

145 | * @return void 146 | */ 147 | public function offsetUnset($offset){ 148 | if($this->flag < 2){ 149 | unset($this->warps[$offset]); 150 | } 151 | 152 | if($this->flag >= 1){ 153 | $this->store->remove($offset); 154 | $this->saveStore(); 155 | } 156 | } 157 | 158 | /** 159 | * This method requires the key of the warp in order 160 | * to construct a warp object 161 | * @param $name 162 | * @param array $array 163 | * @return Warp 164 | * @throws \Exception 165 | */ 166 | protected function warpFromData($name, array $array){ 167 | if(isset($array["level"]) && isset($array["x"]) && isset($array["y"]) && isset($array["z"]) && isset($array["public"])){ // This is an internal warp 168 | return new Warp($this, $name, new Destination(new WeakPosition($array["x"], $array["y"], $array["z"], $array["level"])), $array["public"], $array["metadata"] ?? []); 169 | } 170 | elseif(isset($array["address"]) && isset($array["port"]) && isset($array["public"])) { 171 | return new Warp($this, $name, new Destination($array["address"], $array["port"]), $array["public"], $array["metadata"] ?? []); 172 | } 173 | 174 | $this->api->getSimpleWarp()->getLogger()->critical("A warp with the name " . TextFormat::AQUA . $name . TextFormat::RESET . " is incomplete. It will be removed automatically when your server stops."); 175 | return null; 176 | } 177 | 178 | /** 179 | * In order to pass data to a DataStore 180 | * a key is needed. Typically one should 181 | * use $warp->getName() 182 | * @param Warp $warp 183 | * @return array 184 | */ 185 | protected function warpToData(Warp $warp){ 186 | $ret = []; 187 | if($warp->getDestination()->isInternal()) { 188 | //TODO implement yaw and pitch 189 | $pos = $warp->getDestination()->getPosition(); 190 | $ret = [ 191 | "x" => $pos->getX(), 192 | "y" => $pos->getY(), 193 | "z" => $pos->getZ(), 194 | "level" => ($pos instanceof WeakPosition ? $pos->getLevelName() : $pos->getLevel()->getName()), 195 | "public" => $warp->isPublic(), 196 | ]; 197 | } 198 | else{ 199 | $ret = [ 200 | "address" => $warp->getDestination()->getAddress(), 201 | "port" => $warp->getDestination()->getPort(), 202 | "public" => $warp->isPublic() 203 | ]; 204 | } 205 | 206 | $ret["metadata"] = $warp->getAllMetadata(); 207 | return $ret; 208 | } 209 | 210 | /** 211 | * (PHP 5 >= 5.0.0)
212 | * Retrieve an external iterator 213 | * @link http://php.net/manual/en/iteratoraggregate.getiterator.php 214 | * @return Traversable An instance of an object implementing Iterator or 215 | * Traversable 216 | */ 217 | public function getIterator(){ 218 | if($this->flag >= 2){ 219 | return new \ArrayIterator($this->loadWarps()); 220 | } 221 | return new \ArrayIterator($this->warps); 222 | } 223 | 224 | /** 225 | * Returns the current storage-mode 226 | * ##### 227 | * MEMORY_TILL_CLOSE = 0 228 | * Warps are loaded into memory when the server starts and are 229 | * held there until the server closes. When the server closes 230 | * they are converted back into YAML. This new YAML will 231 | * replace warps.yml, this means that changes are lost and 232 | * warps which fail to load are discarded. 233 | * 234 | * 235 | * FLUSH_ON_CHANGE = 1 236 | * Warps are loaded into memory when the server starts. Whenever a 237 | * warp is updated, it will be updated in the warps.yml. When the 238 | * server closes, the warps file is NOT overwritten. 239 | * 240 | * NO_MEMORY_STORE = 2 241 | * Warps are never "stored" in memory. They are converted on demand 242 | * between YAML and object format. Any changes made to the config 243 | * will be available right away in the server and vice versa. 244 | * #### 245 | * @return int 246 | */ 247 | public function getFlag(): int{ 248 | return $this->flag; 249 | } 250 | 251 | /** 252 | * @return Warp[] 253 | */ 254 | public function getWarps(): array{ 255 | return $this->warps; 256 | } 257 | 258 | /** 259 | * returns the current data store 260 | * @return DataStore 261 | */ 262 | public function getStore(): DataStore{ 263 | return $this->store; 264 | } 265 | 266 | /** 267 | * Injects a new DataStore for warps 268 | * ! This will inject your code into SimpleWarp, potentially breaking! 269 | * @param DataStore $store 270 | */ 271 | public function setStore(DataStore $store){ 272 | $this->saveAll(); 273 | $this->store = $store; 274 | if($this->flag < 2){ 275 | $this->warps = $this->loadWarps(); 276 | } 277 | } 278 | } --------------------------------------------------------------------------------