|
| 1 | +<img src="https://raw.githubusercontent.com/Muirfield/pocketmine-plugins/master/Media/common.png" style="width:64px;height:64px" width="64" height="64"/> |
| 2 | + |
| 3 | +<!-- meta:Categories = DevTools --> |
| 4 | +<!-- meta:PluginAccess = N/A --> |
| 5 | + |
| 6 | +<!-- template: gd2/header.md --> |
| 7 | + |
1 | 8 | # libcommon |
2 | | -Muirfield's common library |
| 9 | + |
| 10 | +- Summary: aliuly's common library |
| 11 | +- PocketMine-MP version: 1.6+php7 (API:2.0.0) |
| 12 | +- DependencyPlugins: |
| 13 | +- OptionalPlugins: |
| 14 | +- Categories: DevTools |
| 15 | +- Plugin Access: N/A |
| 16 | +- WebSite: https://github.com/Muirfield/pocketmine-plugins/tree/master/libcommon |
| 17 | + |
| 18 | +<!-- end-include --> |
| 19 | + |
| 20 | +## Overview |
| 21 | + |
| 22 | +<!-- php: //$v_forum_thread = "http://forums.pocketmine.net/threads/simpleauthhelper.8074/"; --> |
| 23 | +<!-- template: nn/prologue.md --> |
| 24 | +<!-- MISSING TEMPLATE: nn/prologue.md -> |
| 25 | +
|
| 26 | +<!-- end-include --> |
| 27 | + |
| 28 | +This plugin contains a lot of functionality that can be used in other |
| 29 | +plugins, in particular, ScriptPlugins. |
| 30 | + |
| 31 | +API Features: |
| 32 | + |
| 33 | +<!-- snippet:api-features --> |
| 34 | +- Armor constants |
| 35 | +- Paginated output |
| 36 | +- Command and sub command dispatchers |
| 37 | +- Config shortcuts and multi-module|feature management |
| 38 | +- FastTransfer work-around wrapper |
| 39 | +- API version checking |
| 40 | +- Misc shorcuts and pre-canned routines |
| 41 | +- Multiple money support |
| 42 | +- Player session and state management |
| 43 | +- Skin tools |
| 44 | +- Teleport wrappers |
| 45 | +- Translations |
| 46 | +<!-- end-include --> |
| 47 | + |
| 48 | +It also bundles useful third party libraries: |
| 49 | + |
| 50 | +- xPaw MinecraftQuery |
| 51 | + |
| 52 | +See [API documentation](http://muirfield.github.io/pocketmine-plugins/apidocs/index.html) |
| 53 | +for full details. |
| 54 | + |
| 55 | +The **libcommon** library is my standard library that I personally use when |
| 56 | +writing PocketMine-MP plugins. Normally I embed the different modules |
| 57 | +when creating my plugins in order to avoid dependency issues. |
| 58 | + |
| 59 | +For use on your own plugins, you can either use the stand-alone **libcommon** |
| 60 | +phar, or use the one bundled in **GrabBag**. |
| 61 | + |
| 62 | +This plugin can be downloaded from its |
| 63 | +[Downloads](https://github.com/Muirfield/pocketmine-plugins/tree/master/libcommon/downloads.md) |
| 64 | +<img src="https://raw.githubusercontent.com/Muirfield/pocketmine-plugins/master/Media/download-icon.png" alt="Downloads"/> |
| 65 | +page. |
| 66 | + |
| 67 | +Example scripts can be found here: |
| 68 | + |
| 69 | +* [GitHub Examples](https://github.com/Muirfield/pocketmine-plugins/tree/master/libcommon/resources/examples/) |
| 70 | + |
| 71 | +<!-- snippet: pmscript --> |
| 72 | +## PMScript |
| 73 | + |
| 74 | +The PMScript module implements a simple [PHP](https://secure.php.net/) |
| 75 | +based scripting engine. It can be used to enter multiple PocketMine |
| 76 | +commands while allowing you to add PHP code to control the flow of |
| 77 | +the script. |
| 78 | + |
| 79 | +While you can embed any arbitrary PHP code, for readability purposes |
| 80 | +it is recommended that you use |
| 81 | +[PHP's alternative syntax](http://php.net/manual/en/control-structures.alternative-syntax.php) |
| 82 | + |
| 83 | +By convention, PMScript's have a file extension of ".pms" and they are |
| 84 | +just simple text file containing PHP console commands (without the "/"). |
| 85 | + |
| 86 | +To control the execution you can use the following prefixes when |
| 87 | +entering commands: |
| 88 | + |
| 89 | +* **+op:** - will give Op access to the player (temporarily) before executing |
| 90 | + a command |
| 91 | +* **+console:** - run the command as if it was run from the console. |
| 92 | +* **+rcon:** - like **+console:** but the output is sent to the player. |
| 93 | + |
| 94 | +Also, before executing a command variable expansion (e.g. {vars}) and |
| 95 | +command selector expansion (e.g. @a, @r, etc) takes place. |
| 96 | + |
| 97 | +Available variables depend on installed plugins, pocketmine.yml |
| 98 | +settings, execution context, etc. |
| 99 | + |
| 100 | +It is possible to use PHP functions and variables in command lines by |
| 101 | +surrounding PHP expressions with: |
| 102 | + |
| 103 | + '.(php expression).' |
| 104 | + |
| 105 | +For example: |
| 106 | + |
| 107 | + echo MaxPlayers: '.$interp->getServer()->getMaxPlayers().' |
| 108 | + |
| 109 | +### Adding logic flow to PMScripts |
| 110 | + |
| 111 | +Arbitrary PHP code can be added to your pmscripts. Lines that start |
| 112 | +with "@" are treated as PHP code. For your convenience, |
| 113 | +you can ommit ";" at the end of the line. |
| 114 | + |
| 115 | +Any valid PHP code can be used, but for readability, the use of |
| 116 | +alternative syntax is recommended. |
| 117 | + |
| 118 | +The execution context for this PHP code has the following variables |
| 119 | +available: |
| 120 | + |
| 121 | +* **$interp** - reference to the running PMSCript object. |
| 122 | +* **$context** - This is the CommandSender that is executing the script |
| 123 | +* **$vars** - This is the variables array used for variable substitution |
| 124 | + when executing commands. |
| 125 | +* **$args** - Command line arguments. |
| 126 | +* **$env** - execution environment. Empty by default but may be used |
| 127 | + by third party plugins. |
| 128 | +* **$v_xxxxx** - When posible the variables use for command variable |
| 129 | + substitution are made available as **$v_xxxx**. For example, the |
| 130 | + **{tps}** variable, will be available as **$v_tps** |
| 131 | + |
| 132 | +Example: |
| 133 | + |
| 134 | + # Sample PMScript |
| 135 | + # |
| 136 | + ; You can use ";" or "#" as comments |
| 137 | + # |
| 138 | + # Just place your commands as you would enter them on the console |
| 139 | + # on your .pms file. |
| 140 | + echo You have the following plugins: |
| 141 | + plugins |
| 142 | + echo {GOLD}Variable {RED}Expansions {BLUE}are {GREEN}possible |
| 143 | + echo libcommon: {libcommon} MOTD: {MOTD} |
| 144 | + # |
| 145 | + # You can include in there PHP expressions... |
| 146 | + say '.$context->getName().' is AWESOME! |
| 147 | + # CommandSelectors are possible... |
| 148 | + echo Greeting everybody |
| 149 | + say Hello @a |
| 150 | + ; |
| 151 | + # Adding PHP control code is possible: |
| 152 | + @if ($v_tps > 10): |
| 153 | + echo Your TPS {tps} is greater than 10 |
| 154 | + @else: |
| 155 | + echo Your TPS {tps} is less or equal to 10 |
| 156 | + @endif |
| 157 | + ; |
| 158 | + ; |
| 159 | + echo The following variables are available in this context: |
| 160 | + echo '.print_r($vars,true).' |
| 161 | + echo You passed {#} arguments to this script. |
| 162 | +<!-- end-include --> |
| 163 | + |
| 164 | +### Command Selectors |
| 165 | + |
| 166 | +Command selectors are available in PMScripts. |
| 167 | + |
| 168 | +<!-- snippet: cmdselector --> |
| 169 | + |
| 170 | +This adds "@" prefixes for commands. |
| 171 | +See |
| 172 | +[Command Prefixes](http://minecraft.gamepedia.com/Commands#Target_selector_arguments) |
| 173 | +for an explanation on prefixes. |
| 174 | + |
| 175 | +This only implements the following prefixes: |
| 176 | + |
| 177 | +- @a - all players |
| 178 | +- @e - all entities (including players) |
| 179 | +- @r - random player/entity |
| 180 | + |
| 181 | +The following selectors are implemented: |
| 182 | + |
| 183 | +- c: (only for @r),count |
| 184 | +- m: game mode |
| 185 | +- type: entity type, use Player for player. |
| 186 | +- name: player's name |
| 187 | +- w: world |
| 188 | + |
| 189 | +<!-- end-include --> |
| 190 | + |
| 191 | +<!-- php:$h=3; --> |
| 192 | +<!-- template: gd2/permissions.md --> |
| 193 | + |
| 194 | +### Permission Nodes |
| 195 | + |
| 196 | +* libcommon.command: libcommon command |
| 197 | + |
| 198 | +<!-- end-include --> |
| 199 | + |
| 200 | +## Changes |
| 201 | + |
| 202 | +- 1.92.0: Update to new API |
| 203 | + * Added a FastTransfer class, with temporary work-around |
| 204 | +- 1.91.0: De-bundle |
| 205 | + * New modules: TPUtils, ShoppingCart, SignUtils, SkinUtils, SpySession |
| 206 | + * De-bundled, now it is just a library again. All sub-commands were moved |
| 207 | + to GrabBag. |
| 208 | + * Bug-Fixes: Cmd, InvUtils, Session, ShieldSession, BaseSelector |
| 209 | +- 1.90.0: Major Update 2 |
| 210 | + * MoneyAPI bug fix |
| 211 | + * Fixed BasicPlugin bug |
| 212 | + * Lots of new API features. |
| 213 | + * Added sub-commands |
| 214 | + * Bug Fixes: |
| 215 | + * MoneyAPI crash |
| 216 | + * BasicPlugin permission dispatcher |
| 217 | + * API Features |
| 218 | + * GetMotdAsyncTask |
| 219 | + * Session management |
| 220 | + * FileUtils |
| 221 | + * ArmorItems |
| 222 | + * Variables |
| 223 | + * PMScripts |
| 224 | + * ItemName can load user defined tables |
| 225 | + * SubCommandMap spinned-off from BasicPlugin |
| 226 | + * Sub commands |
| 227 | + * DumpMsgs |
| 228 | + * echo and basic echo |
| 229 | + * rc |
| 230 | + * motd utils |
| 231 | + * version |
| 232 | + * trace |
| 233 | +- 1.1.0: Update 1 |
| 234 | + * Added ItemName class (with more item names) |
| 235 | + * Removed MPMU::itemName |
| 236 | +- 1.0.0: First release |
| 237 | + |
| 238 | +<!-- php:$copyright="2015"; --> |
| 239 | +<!-- template: gd2/gpl2.md --> |
| 240 | +# Copyright |
| 241 | + |
| 242 | + libcommon |
| 243 | + Copyright (C) 2015 Alejandro Liu |
| 244 | + All Rights Reserved. |
| 245 | + |
| 246 | + This program is free software: you can redistribute it and/or modify |
| 247 | + it under the terms of the GNU General Public License as published by |
| 248 | + the Free Software Foundation, either version 2 of the License, or |
| 249 | + (at your option) any later version. |
| 250 | + |
| 251 | + This program is distributed in the hope that it will be useful, |
| 252 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 253 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 254 | + GNU General Public License for more details. |
| 255 | + |
| 256 | + You should have received a copy of the GNU General Public License |
| 257 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 258 | + |
| 259 | +<!-- end-include --> |
| 260 | + |
0 commit comments