From 925b6c4473d71b4e9012a0c5c5fff05d4ab4d702 Mon Sep 17 00:00:00 2001 From: alejandroliu Date: Fri, 26 Aug 2016 15:08:21 +0200 Subject: [PATCH] Clean-up for use library, translated to Spanish, removed braodcast setting --- README.md | 115 +++++++-------- plugin.yml | 4 +- resources/messages/messages.ini | 40 ++++++ resources/messages/spa.ini | 40 ++++++ src/aliuly/signwarp/Main.php | 133 +++++++++--------- src/aliuly/signwarp/common/MPMU.php | 99 +++++++++++++ .../{ => common}/PluginCallbackTask.php | 3 +- src/aliuly/signwarp/common/mc.php | 67 +++++++++ 8 files changed, 366 insertions(+), 135 deletions(-) create mode 100644 resources/messages/messages.ini create mode 100644 resources/messages/spa.ini create mode 100644 src/aliuly/signwarp/common/MPMU.php rename src/aliuly/signwarp/{ => common}/PluginCallbackTask.php (97%) create mode 100644 src/aliuly/signwarp/common/mc.php diff --git a/README.md b/README.md index 9f042fd..151117d 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,28 @@ -SignWarp -======== + + +# SignWarp * Summary: Warp between places using signs * Dependency Plugins: n/a * PocketMine-MP version: 1.4 - API 1.10.0 -* OptionalPlugins: ManyWorlds, FastTransfer +* OptionalPlugins: FastTransfer * Categories: Teleportation -* Plugin Access: Commands, Tile Entities, Items/Blocks +* Plugin Access: Other Plugins, Commands, Tile Entities, Manages worlds * WebSite: [github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/SignWarp) -Overview --------- +## Overview + +**DO NOT POST QUESTION/BUG-REPORTS/REQUESTS IN THE REVIEWS** +It is difficult to carry a conversation in the reviews. If you have a +question/bug-report/request please use the +[Thread](http://forums.pocketmine.net/threads/signwarp.7276/) for +that. You are more likely to get a response and help that way. -A very basic Plugin implementing simple _Sign_ based warps. +Please go to +[github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/SignWarp) +for the most up-to-date documentation. + +A Plugin implementing simple _Sign_ based warps. Basic Usage: @@ -41,9 +51,7 @@ For Warp between servers use: You need the **FastTransfer** plugin for this to work. - -Documentation -------------- +## Documentation This plugin implements _warps_ through the placement of _signs_. You need to create a sign with the text: @@ -73,7 +81,7 @@ target location. If not specified it defaults to the `spawn` world. If dynamic updates are enabled, the fourth line can contain the text `Players:`, which will get updated dynamically with the number of -players on that world. Otherwise the ine is ignored and can be +players on that world. Otherwise the ine is ignored and can contain any descriptive text. To help identify potential _warp_ targets, the command `xyz` is @@ -93,57 +101,40 @@ can be used for description. You need the **FastTransfer** plugin for this to work. -### config.yml - - --- - # Example config.yml - settings: - dynamic-updates: true - broadcast-tp: true - xyz.cmd: true - text: - world: - - '[WORLD]' - - '[MUNDO]' - warp: - - '[WARP]' - - '[SWARP]' - - '[TELEPORT]' - transfer: - - '[TRANSFER]' - players: - - 'Players:' - - 'Jugadores:' - ... - -* dynamic-updates: 1 or 0, true or false - If enabled, signs will be updated with the number of players in a - particular world. -* broadcast-tp: 1 or 0, true or false - If enabled, teleports will be broadcast to all players. -* xyz.cmd: 1 or 0, true or false - If enabled, the `xyz` command will be available. -* world: - List of texts to use for `[WORLD]` teleport signs. -* warp: - List of texts to use for `[SWARP]` teleport signs. -* transfer: - List of texts to use for Transfer signs. -* players: - List of texts to use for the `Players:` counters. - -### Permission Nodes: - -* signwarp.cmd.xyz - Allows the user to show current x,y,z coordinates -* signwarp.place.sign - Allow user to create warp signs -* signwarp.place.transfer.sign - Allow user to create transfer signs -* signwarp.touch.sign - Allow user to use warp signs -* signwarp.touch.transfer.sign - Allow user to use transfer signs - - -Changes -------- +### Configuration + +Configuration is throug the `config.yml` file. +The following sections are defined: + +#### config.yml + +* settings: configurable variables + * dynamic updates: Signs will be udpated with the number of players in a world + * xyz.cmd: If true, the **xyz** command will be available +* text: Text displayed on the different signs + * transfer: Fast transfer signs + * world: World teleport signs + * warp: Local world teleport signs + * players: Text to use when displaying player counts + +### Permission Nodes + +* signwarp.place.sign : Allow user to create warp + (Defaults to Op) +* signwarp.touch.sign : Allow user to use warp +* signwarp.place.transfer.sign : Allow user to create transfer signs + (Defaults to Op) +* signwarp.touch.transfer.sign : Allow user to use transfer signs +* signwarp.cmd.xyz : Shows current x,y,z coordinates + + +# Changes + +* 1.4.0: + * Clean-up and use library stuff + * Removed broadcast setting + * Translations: Spanish * 1.3.2: CallbackTask * Removed CallbackTask deprecation warnings * 1.3.1: FastTransfer @@ -175,7 +166,6 @@ FAQ * You can use a plugin like `ManyWorlds` or modify the `worlds` secion in your `pocketmine.yml` file. - Copyright ========= @@ -198,3 +188,4 @@ Copyright 128 70 128 X:-100 Y:69 Z:1072 + diff --git a/plugin.yml b/plugin.yml index 5114190..18b9bd6 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,10 +1,10 @@ name: SignWarp api: [1.10.0] -version: 1.3.2 +version: 1.4.0 load: POSTWORLD main: aliuly\signwarp\Main author: aliuly -softdepend: [ManyWorlds,FastTransfer] +softdepend: [FastTransfer] permissions: signwarp.place.sign: diff --git a/resources/messages/messages.ini b/resources/messages/messages.ini new file mode 100644 index 0000000..66ffbc4 --- /dev/null +++ b/resources/messages/messages.ini @@ -0,0 +1,40 @@ +; messages.ini +"%1%-mode"="" +"- Player: %1% => %2%:%3%"="" +"/xyz"="" +"Adventure"="" +"Can not teleport while holding sign!"="" +"Creative"="" +"Did you expect something to happen?"="" +"Disabling FastTransfer support"="" +"Enabling FastTransfer support"="" +"FAST TRANSFER NOT INSTALLED"="" +"FastTransfer being used hope it works!"="" +"N/A"="" +"Nothing happens!"="" +"Nothing happens..."="" +"Returns x,y,z coordinates"="" +"Somebody removed FastTransfer!"="" +"Spectator"="" +"Survival"="" +"Teleporting..."="" +"You are at %1%,%2%,%3%"="" +"You are not allowed to make Warp signs"="" +"You are not allowed to make\nTransfer Warp signs"="" +"You can only do this in-game"="" +"You do not have permission to do that."="" +"[SignWarp] Error loading \"%1%\""="" +"[SignWarp] INTERNAL ERROR"="" +"[SignWarp] Invalid coordinates %1%"="" +"[SignWarp] Loading \"%1%\""="" +"[SignWarp] No World specified"="" +"[SignWarp] No coordinates specified"="" +"[SignWarp] Portal to %1% created by %2%"="" +"[SignWarp] This command may only be used in-game"="" +"[SignWarp] Transfer portal %1% created by %2%"="" +"[SignWarp] Unable to load world \"%1%\""="" +"[SignWarp] Warp to %1%,%2%,%3% created by %4%"="" +"[SignWarp] World \"%1%\" does not exist!"="" +"dynamic-updates: OFF"="" +"dynamic-updates: ON"="" +"enabled /xyz command"="" diff --git a/resources/messages/spa.ini b/resources/messages/spa.ini new file mode 100644 index 0000000..259dc99 --- /dev/null +++ b/resources/messages/spa.ini @@ -0,0 +1,40 @@ +; spa.ini +"%1%-mode"="modo-%1%" +"- Player: %1% => %2%:%3%"="- Jugador: %1% => %2%:%3%" +"/xyz"="/xyz" +"Adventure"="Aventura" +"Can not teleport while holding sign!"="No se puede teletransportar si tiene un cartel en la mano!" +"Creative"="Creativo" +"Did you expect something to happen?"="Esperabas que ocurra algo?" +"Disabling FastTransfer support"="Des-habilitando compatibilidad con FastTransfer" +"Enabling FastTransfer support"="Habilitando carteles con FastTransfer" +"FAST TRANSFER NOT INSTALLED"="FAST TRANSFER NO ESTÁ INSTALADO" +"FastTransfer being used hope it works!"="Usando FastTransfer. Espero que funcione" +"N/A"="N/A" +"Nothing happens!"="No pasa nada!" +"Nothing happens..."="No pasa nada..." +"Returns x,y,z coordinates"="Muestra la ubicación x,y,z" +"Somebody removed FastTransfer!"="Algien borró FastTransfer!" +"Spectator"="Espectador" +"Survival"="Supervivencia" +"Teleporting..."="Teletransportando..." +"You are at %1%,%2%,%3%"="Usted está en %1%,%2%,%3%" +"You are not allowed to make Warp signs"="No tiene permiso para crear carteles de Warp" +"You are not allowed to make\nTransfer Warp signs"="No tiene permiso para create carteles the FastTransfer" +"You can only do this in-game"="Solo puede hacer eso en juego" +"You do not have permission to do that."="No tiene permitido hacer eso" +"[SignWarp] Error loading \"%1%\""="[SignWarp] Problemas cargando %1%" +"[SignWarp] INTERNAL ERROR"="[SignWarp] ERROR INTERNO" +"[SignWarp] Invalid coordinates %1%"="[SignWarp] Coordenadas no validas" +"[SignWarp] Loading \"%1%\""="Cargando \"%1%\"" +"[SignWarp] No World specified"="[SignWarp] No hay mundo proporcionado" +"[SignWarp] No coordinates specified"="[SignWarp] No se proporcionó coordenadas" +"[SignWarp] Portal to %1% created by %2%"="[SignWarp] Portal a %1% creado por %2%" +"[SignWarp] This command may only be used in-game"="[SignWarp] Solo se puede usar " +"[SignWarp] Transfer portal %1% created by %2%"="[SignWarp] Portal de Transferencia a %1% creado por %2%" +"[SignWarp] Unable to load world \"%1%\""="[SignWarp] No se pudo cargar %1%" +"[SignWarp] Warp to %1%,%2%,%3% created by %4%"="[SignWarp] Warp para %1%,%2%,%3% creado por %4%" +"[SignWarp] World \"%1%\" does not exist!"="[SignWarp] %1% no existe" +"dynamic-updates: OFF"="" +"dynamic-updates: ON"="" +"enabled /xyz command"="Comando /xyz activado" diff --git a/src/aliuly/signwarp/Main.php b/src/aliuly/signwarp/Main.php index b1c38a2..996b4ed 100644 --- a/src/aliuly/signwarp/Main.php +++ b/src/aliuly/signwarp/Main.php @@ -1,5 +1,7 @@ getDataFolder())) mkdir($this->getDataFolder()); + mc::plugin_init($this,$this->getFile()); $defaults = [ + "version" => $this->getDescription()->getVersion(), + "# settings" => "configurable variables", "settings" => [ + "# dynamic updates" => "Signs will be udpated with the number of players in a world", "dynamic-updates" => true, - "broadcast-tp" => true, + "# xyz.cmd" => "If true, the **xyz** command will be available", "xyz.cmd" => true, ], + "# text" => "Text displayed on the different signs", "text" => [ + "# transfer" => "Fast transfer signs", "transfer" => [ "[TRANSFER]" ], + "# world" => "World teleport signs", "world" => [ "[WORLD]" ], + "# warp" => "Local world teleport signs", "warp" => [ "[WARP]", "[SWARP]" ], + "# players" => "Text to use when displaying player counts", "players" => [ "Players:" ], ] ]; @@ -53,13 +66,12 @@ public function onEnable(){ Config::YAML,$defaults))->getAll(); if ($this->getServer()->getPluginManager()->getPlugin("FastTransfer")){ - $this->getLogger()->info("Enabling FastTransfer support"); + $this->getLogger()->info(TextFormat::GREEN.mc::_("Enabling FastTransfer support")); }else{ - $this->getLogger()->info("Disabling FastTransfer support"); + $this->getLogger()->warning(TextFormat::BLUE.mc::_("Disabling FastTransfer support")); $cfg["text"]["transfer"] = []; } - $this->broadcast = $cfg["settings"]["broadcast-tp"]; $this->text = [ "sign" => [] ]; foreach (["world","warp","transfer"] as $n) { $thist->text[$n] = []; @@ -72,21 +84,21 @@ public function onEnable(){ if ($cfg["settings"]["xyz.cmd"]) { $newCmd = new PluginCommand("xyz",$this); - $newCmd->setDescription("Returns x,y,z coordinates"); - $newCmd->setUsage("/xyz"); + $newCmd->setDescription(mc::_("Returns x,y,z coordinates")); + $newCmd->setUsage(mc::_("/xyz")); $newCmd->setPermission("signwarp.cmd.xyz"); $cmdMap = $this->getServer()->getCommandMap(); $cmdMap->registerAll($this->getDescription()->getName(), [$newCmd]); - $this->getLogger()->info("enabled /xyz command"); + $this->getLogger()->info(TextFormat::GREEN.mc::_("enabled /xyz command")); } if ($cfg["settings"]["dynamic-updates"]) { - $this->getLogger()->info("dynamic-updates: ON"); + $this->getLogger()->info(TextFormat::GREEN.mc::_("dynamic-updates: ON")); $tt = new PluginCallbackTask($this,[$this,"updateSigns"],[]); $this->getServer()->getScheduler()->scheduleRepeatingTask($tt,40); } else { - $this->getLogger()->info("dynamic-updates: OFF"); + $this->getLogger()->info(TextFormat::YELLOW.mc::_("dynamic-updates: OFF")); } $this->getServer()->getPluginManager()->registerEvents($this, $this); } @@ -100,12 +112,12 @@ private function checkSign(Player $pl,array $sign) { if (isset($this->text["warp"][$sign[0]])) { // Short warp... if (empty($sign[1])) { - $pl->sendMessage("[SignWarp] No coordinates specified"); + $pl->sendMessage(mc::_("[SignWarp] No coordinates specified")); return null; } $mv = []; if ($this->check_coords($sign[1],$mv) !== true) { - $pl->sendMessage("[SignWarp] Invalid coordinates ".$sign[1]); + $pl->sendMessage(mc::_("[SignWarp] Invalid coordinates %1%",$sign[1])); return null; } return new Position($mv[0],$mv[1],$mv[2],$pl->getLevel()); @@ -113,27 +125,26 @@ private function checkSign(Player $pl,array $sign) { // Long warp! if (isset($this->text["world"][$sign[0]])) { if (empty($sign[1])) { - $pl->sendMessage("[SignWarp] No World specified"); + $pl->sendMessage(mc::_("[SignWarp] No World specified")); return null; } // Check level... if (!$this->getServer()->isLevelGenerated($sign[1])) { - $pl->sendMessage("[SignWarp] World \"".$sign[1] - ."\" does not exist!"); + $pl->sendMessage(mc::_("[SignWarp] World \"%1%\" does not exist!",$sign[1])); + return null; } if (!$this->getServer()->isLevelLoaded($sign[1])) { - $pl->sendMessage("[SignWarp] Loading \"".$sign[1]."\""); + $pl->sendMessage(mc::_("[SignWarp] Loading \"%1%\"",$sign[1])); if (!$this->getServer()->loadLevel($sign[1])) { - $pl->sendMessage("[SignWarp] Unable to load world \"". - $sign[1]."\""); + $pl->sendMessage(mc::_("[SignWarp] Unable to load world \"%1%\"",$sign[1])); return null; } } $l = $this->getServer()->getLevelByName($sign[1]); if ($l == null) { - $pl->sendMessage("[SignWarp] Error loading \"". - $sign[1]."\""); + $pl->sendMessage(mc::_("[SignWarp] Error loading \"%1%\"", + $sign[1])); return null; } @@ -153,7 +164,7 @@ private function checkSign(Player $pl,array $sign) { if ($port == 0) $port = 19132; // Default for Minecraft PE return [$address,$port]; } - $pl->sendMessage("[SignWarp] INTERNAL ERROR"); + $pl->sendMessage(mc::_("[SignWarp] INTERNAL ERROR")); return null; } private function breakSign(Player $pl,Sign $tile,$msg = "") { @@ -191,12 +202,12 @@ public function onCommand(CommandSender $sender,Command $cmd,$label, array $args case "xyz": if ($sender instanceof Player) { $pos = $sender->getPosition(); - $sender->sendMessage("You are at ". - intval($pos->getX()).",". - intval($pos->getY()).",". - intval($pos->getZ())); + $sender->sendMessage(mc::_("You are at %1%,%2%,%3%", + intval($pos->getX()), + intval($pos->getY()), + intval($pos->getZ()))); } else { - $sender->sendMessage("[SignWarp] This command may only be used in-game"); + $sender->sendMessage(TextFormat::RED.mc::_("[SignWarp] This command may only be used in-game")); } return true; } @@ -231,14 +242,14 @@ public function signChanged(SignChangeEvent $event){ if (!isset($this->text["sign"][$sign[0]])) return; if(!$pl->hasPermission("signwarp.place.sign")) { - $this->breakSign($pl,$tile,"You are not allowed to make Warp signs"); + $this->breakSign($pl,$tile,mc::_("You are not allowed to make Warp signs")); return; } // FastTransfer! if (isset($this->text["transfer"][$sign[0]])) { // Fast transfer! if(!$pl->hasPermission("signwarp.place.transfer.sign")) { - $this->breakSign($pl,$tile,"You are not allowed to make\nTransfer Warp signs"); + $this->breakSign($pl,$tile,mc::_("You are not allowed to make\nTransfer Warp signs")); return; } } @@ -248,25 +259,18 @@ public function signChanged(SignChangeEvent $event){ $this->breakSign($pl,$tile); return; } - if ($this->broadcast) { - if ($pos instanceof Position) { - $this->getServer()->broadcastMessage(isset($this->text["world"][$sign[0]]) ? - "[SignWarp] Portal to ". - $pos->getLevel()->getName(). - " created by ". - $pl->getName() : - "[SignWarp] Warp to ". - $pos->getX().",". - $pos->getY().",". - $pos->getZ()." created by ". - $pl->getName()); - } else { - $this->getServer()->broadcastMessage("[SignWarp] Transfer portal ". - " created by ". - $pl->getName()); - } + if ($pos instanceof Position) { + $this->getServer()->broadcastMessage( + isset($this->text["world"][$sign[0]]) ? + mc::_("[SignWarp] Portal to %1% created by %2%", + $pos->getLevel()->getName(),$pl->getName()) : + mc::_("[SignWarp] Warp to %1%,%2%,%3% created by %4%", + $pos->getX(),$pos->getY(),$pos->getZ(), + $pl->getName())); } else { - $pl->sendMessage("SignWarp created..."); + $this->getServer()->broadcastMessage( + mc::_("[SignWarp] Transfer portal %1% created by %2%", + implode(":",$pos), $pl->getName())); } } public function playerTouchIt(PlayerInteractEvent $event){ @@ -279,12 +283,12 @@ public function playerTouchIt(PlayerInteractEvent $event){ if (!isset($this->text["sign"][$sign[0]])) return; if(!$pl->hasPermission("signwarp.touch.sign")) { - $pl->sendMessage("Nothing happens..."); + $pl->sendMessage(mc::_("Nothing happens...")); return; } if ($event->getItem()->getId() == Item::SIGN) { // Check if the user is holding a sign this stops teleports - $pl->sendMessage("Can not teleport while holding sign!"); + $pl->sendMessage(mc::_("Can not teleport while holding sign!")); return; } $pos = $this->checkSign($pl,$sign); @@ -293,37 +297,28 @@ public function playerTouchIt(PlayerInteractEvent $event){ if ($pos instanceof Position) { $this->teleporters[$pl->getName()] = time(); - $pl->sendMessage("Teleporting..."); - if (($mw = $this->getServer()->getPluginManager()->getPlugin("ManyWorlds")) != null) { - $mw->mwtp($pl,$pos); - } else { - $pl->teleport($pos); - } - if ($this->broadcast) - $this->getServer()->broadcastMessage($pl->getName()." teleported to ". - $pos->getLevel()->getName()); + $pl->sendMessage(mc::_("Teleporting...")); + $pl->teleport($pos); return; } // FastTransfer if(!$pl->hasPermission("signwarp.touch.transfer.sign")) { - $pl->sendMessage("Did you expect something to happen?"); + $pl->sendMessage(mc::_("Did you expect something to happen?")); return; } $this->teleporters[$pl->getName()] = time(); $ft = $this->getServer()->getPluginManager()->getPlugin("FastTransfer"); if (!$ft) { - $this->getLogger()->info("FAST TRANSFER NOT INSTALLED"); - $pl->sendMessage("Nothing happens!"); - $pl->sendMessage("Somebody removed FastTransfer!"); + $this->getLogger()->error(mc::_("FAST TRANSFER NOT INSTALLED")); + $pl->sendMessage(TextFormat::RED.mc::_("Nothing happens!")); + $pl->sendMessage(TextFormat::RED.mc::_("Somebody removed FastTransfer!")); return; } list($addr,$port) = $pos; - $this->getLogger()->info("FastTransfer being used hope it works!"); - $this->getLogger()->info("- Player: ".$pl->getName()." => ". - $addr.":".$port); + $this->getLogger()->info(mc::_("FastTransfer being used hope it works!")); + $this->getLogger()->info(mc::_("- Player: %1% => %2%:%3%", + $pl->getName(),$addr,$port)); $ft->transferPlayer($pl,$addr,$port); - if ($this->broadcast) - $this->getServer()->broadcastMessage($pl->getName()." transferred servers..."); } ////////////////////////////////////////////////////////////////////// // @@ -342,7 +337,7 @@ public function updateSigns() { $cnt = count($this->getServer()->getLevelByName($sign[1])->getPlayers()); $upd = $t.$cnt; } else { - $upd = $t."N/A"; + $upd = $t.mc::_("N/A"); } if ($upd == $sign[3]) continue; $tile->setText($sign[0],$sign[1],$sign[2],$upd); diff --git a/src/aliuly/signwarp/common/MPMU.php b/src/aliuly/signwarp/common/MPMU.php new file mode 100644 index 0000000..db78e1c --- /dev/null +++ b/src/aliuly/signwarp/common/MPMU.php @@ -0,0 +1,99 @@ +=": + return version_compare($api,trim(substr($version,2))) >= 0; + case "<=": + return version_compare($api,trim(substr($version,2))) <= 0; + case "<>": + case "!=": + return version_compare($api,trim(substr($version,2))) != 0; + } + switch (substr($version,0,1)) { + case "=": + return version_compare($api,trim(substr($version,1))) == 0; + case "!": + case "~": + return version_compare($api,trim(substr($version,1))) != 0; + case "<": + return version_compare($api,trim(substr($version,1))) < 0; + case ">": + return version_compare($api,trim(substr($version,1))) > 0; + } + if (intval($api) != intval($version)) return 0; + return version_compare($api,$version) >= 0; + } + static public function itemName(Item $item) { + $n = $item->getName(); + if ($n != "Unknown") return $n; + if (count(self::$items) == 0) { + $constants = array_keys((new \ReflectionClass("pocketmine\\item\\Item"))->getConstants()); + foreach ($constants as $constant) { + $id = constant("pocketmine\\item\\Item::$constant"); + $constant = str_replace("_", " ", $constant); + self::$items[$id] = $constant; + } + } + if (isset(self::$items[$item->getId()])) + return self::$items[$item->getId()]; + return $n; + } + static public function gamemodeStr($mode) { + if (class_exists(__NAMESPACE__."\\mc",false)) { + switch ($mode) { + case 0: return mc::_("Survival"); + case 1: return mc::_("Creative"); + case 2: return mc::_("Adventure"); + case 3: return mc::_("Spectator"); + } + return mc::_("%1%-mode",$mode); + } + switch ($mode) { + case 0: return "Survival"; + case 1: return "Creative"; + case 2: return "Adventure"; + case 3: return "Spectator"; + } + return "$mode-mode"; + } + + static public function access(CommandSender $sender, $permission,$msg=true) { + if($sender->hasPermission($permission)) return true; + if ($msg) + $sender->sendMessage(mc::_("You do not have permission to do that.")); + return false; + } + static public function inGame(CommandSender $sender,$msg = true) { + if (!($sender instanceof Player)) { + if ($msg) $sender->sendMessage(mc::_("You can only do this in-game")); + return false; + } + return true; + } + static public function iName($player) { + if ($player instanceof Player) { + $player = strtolower($player->getName()); + } + return $player; + } +} diff --git a/src/aliuly/signwarp/PluginCallbackTask.php b/src/aliuly/signwarp/common/PluginCallbackTask.php similarity index 97% rename from src/aliuly/signwarp/PluginCallbackTask.php rename to src/aliuly/signwarp/common/PluginCallbackTask.php index 7b61b69..a0a502f 100644 --- a/src/aliuly/signwarp/PluginCallbackTask.php +++ b/src/aliuly/signwarp/common/PluginCallbackTask.php @@ -1,5 +1,4 @@ "%" ]; + $i = 1; + foreach ($args as $j) { + $vars["%$i%"] = $j; + ++$i; + } + $fmt = strtr($fmt,$vars); + } + return $fmt; + } + public static function n($a,$b,$c) { + return $c == 1 ? $a : $b; + } + public static function plugin_init($plugin,$path) { + if (file_exists($plugin->getDataFolder()."messages.ini")) { + self::load($plugin->getDataFolder()."messages.ini"); + return; + } + $msgs = $path."resources/messages/". + $plugin->getServer()->getProperty("settings.language"). + ".ini"; + if (!file_exists($msgs)) return; + mc::load($msgs); + } + + public static function load($f) { + $potxt = "\n".file_get_contents($f)."\n"; + if (preg_match('/\nmsgid\s/',$potxt)) { + $potxt = preg_replace('/\\\\n"\n"/',"\\n", + preg_replace('/\s+""\s*\n\s*"/'," \"", + $potxt)); + } + foreach (['/\nmsgid "(.+)"\nmsgstr "(.+)"\n/', + '/^\s*"(.+)"\s*=\s*"(.+)"\s*$/m'] as $re) { + $c = preg_match_all($re,$potxt,$mm); + if ($c) { + for ($i=0;$i<$c;++$i) { + if ($mm[2][$i] == "") continue; + eval('$a = "'.$mm[1][$i].'";'); + eval('$b = "'.$mm[2][$i].'";'); + mc::$txt[$a] = $b; + } + return $c; + } + } + return false; + } +}