remove windoge line breaks

This commit is contained in:
jomo
2014-12-17 22:13:23 +01:00
parent 46fad3c2f4
commit ce8683e85a

480
README.md
View File

@@ -1,241 +1,241 @@
# RedstonerUtils # RedstonerUtils
Redstoner's custom plugins, written in python. Redstoner's custom plugins, written in python.
# Installation / Set-up # Installation / Set-up
0. Create a new directory called 'redstoner' 0. Create a new directory called 'redstoner'
0. Download [the latest spigot](http://ci.md-5.net/job/Spigot/lastStableBuild/artifact/Spigot-Server/target/spigot.jar) 0. Get the latest spigot
0. Run it once inside redstoner, then shut it down again 0. Run it once inside 'redstoner', then shut it down again
0. Create a new directory (inside redstoner) called 'lib' 0. Create a new directory (inside redstoner) called 'lib'
0. Download [mysql-connector](https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.zip), extract 'mysql-connector-java-X.X.XX-bin.jar 0. Download [mysql-connector](https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.30.zip), extract 'mysql-connector-java-X.X.XX-bin.jar
' and save it as 'mysql-connector.jar' inside lib ' and save it as 'mysql-connector.jar' inside lib
0. Download [PyPluginLoader](http://bamboo.gserv.me/browse/PLUG-PYPL/latestSuccessful/artifact/JOB1/Version-agnostic-jar/PyPluginLoader.jar) (we're using [this fork](https://github.com/gdude2002/Python-Plugin-Loader)) into the plugins directory 0. Download [PyPluginLoader](http://bamboo.gserv.me/browse/PLUG-PYPL/latestSuccessful/artifact/JOB1/Version-agnostic-jar/PyPluginLoader.jar) (we're using [this fork](https://github.com/gdude2002/Python-Plugin-Loader)) into the plugins directory
0. inside plugins, clone this directory into 'redstoner-utils**.py.dir**': 0. Inside plugins, clone this directory into 'redstoner-utils**.py.dir**'
`git clone git@bitbucket.org:redstonesheep/redstoner-utils.git redstoner-utils.py.dir` 0. Download PEX from [here](https://github.com/PEXPlugins/PermissionsEx/releases/latest) into plugins
0. Download [PEX](http://dev.bukkit.org/media/files/789/291/PermissionsEx.jar) into plugins 0. **if you want** to develop mysql things, set up a local MySQL server
0. **if you want** to develop mysql things, set up a local MySQL server
# branches
# branches
* **dev**
* **dev** Always use this branch to change code, please test before pushing. (If something goes wrong here, that's okay)
Always use this branch to change code, please test before pushing. (If something goes wrong here, that's okay)
* **master**
* **master** This branch is used for the production server.
Never commit into this branch directly! Only merge stable versions of *dev*: Never commit into this branch directly! Only merge stable versions of *dev*:
```bash ```bash
git checkout master git checkout master
git merge dev git merge dev
``` ```
# Deploying on the server # Deploying on the server
**Never** edit the files directly on the server! **Never** edit the files directly on the server!
The dev server uses the *dev* branch, the live server uses *master*. The dev server uses the *dev* branch, the live server uses *master*.
**Do not use `git pull` on the server!** *(All files must be pulled/owned by the 'redstoner' user.)* **Do not use `git pull` on the server!** *(All files must be pulled/owned by the 'redstoner' user.)*
### Deploying on test server ### Deploying on test server
* Push all changes * Push all changes
* Run `<server-dir>/git_pull_utils.sh`. * Run `<server-dir>/git_pull_utils.sh`.
* Restart (You can try reloading here, but expect the unexpected) * Restart (You can try reloading here, but expect the unexpected)
### Deploying on production server ### Deploying on production server
* Test all code carefully on the test server 0. Test all code carefully on the test server
***on your machine:*** 0. on your machine:
* `git checkout master` * `git checkout master`
* `git pull` * `git pull`
* `git merge dev` * `git merge dev`
* `git push -u origin master` * `git push origin master`
* `git checkout dev` * `git checkout dev`
***on the server:*** 0. on the server:
* `rs update_utils` * `rs update_utils`
* Restart * Restart (Do NOT `/reload`!)
# Modules / Files # Modules / Files
If you add a new file, please update this list! If you add a new file, please update this list!
If you want the server to load a file (*module*) on startup, add it to the `modules` list in `main.py`. If you want the server to load a file (*module*) on startup, add it to the `modules` list in `main.py`.
* `files/` * `files/`
> All config / storage files go here > All config / storage files go here
* `plugin.yml` * `plugin.yml`
> The plugin.yml file required for bukkut plugins > The plugin.yml file required for bukkut plugins
* `main.py` * `main.py`
> The only file loaded by PyPluginLoader, loads all other modules > The only file loaded by PyPluginLoader, loads all other modules
> Contains a few methods that **need to be cleaned up** > Contains a few methods that **need to be cleaned up**
* `helpers.py` * `helpers.py`
> Library that adds a bunch of re-usable methods which are used in nearly all other modules > Library that adds a bunch of re-usable methods which are used in nearly all other modules
* `adminchat.py` * `adminchat.py`
> Adds chat for staff using `/ac <text` or `,<text>` > Adds chat for staff using `/ac <text` or `,<text>`
* `chatgroups.py` * `chatgroups.py`
> Adds group-chat with `/chatgroup` and `/cgt` to toggle normal chat into group mode > Adds group-chat with `/chatgroup` and `/cgt` to toggle normal chat into group mode
* `lagchunks.py` * `lagchunks.py`
> Plugin to locate laggy chunks. `/lc <n>` lists chunks with more than `n` entities > Plugin to locate laggy chunks. `/lc <n>` lists chunks with more than `n` entities
* `mysqlhack.py` * `mysqlhack.py`
> A library that makes use of the so called ClassPathHack for jython to allow proper loading of `mysql-connector.jar` at runtime. import only, no methods. > A library that makes use of the so called ClassPathHack for jython to allow proper loading of `mysql-connector.jar` at runtime. import only, no methods.
* `plotter.py` * `plotter.py`
> Start of a custom plot-plugin like PlotMe, on hold because the PlotMe developer continued to develop PlotMe > Start of a custom plot-plugin like PlotMe, on hold because the PlotMe developer continued to develop PlotMe
* `reports.py` * `reports.py`
> The `/report <text>` and `/rp` plugin > The `/report <text>` and `/rp` plugin
* `saylol.py` * `saylol.py`
> Remake of sheep's old SayLol plugin, originally written as a standalone plugin in Java > Remake of sheep's old SayLol plugin, originally written as a standalone plugin in Java
* `skullclick.py` * `skullclick.py`
> Shows the owner of a skull when right-clicked > Shows the owner of a skull when right-clicked
* `webtoken.py` * `webtoken.py`
> Adds `/token`, reads and writes from the database to generate *pronouncable* (and thus memorable) registration-tokens for the website > Adds `/token`, reads and writes from the database to generate *pronouncable* (and thus memorable) registration-tokens for the website
* `spawnplayer.py` * `spawnplayer.py`
> Code that was used once to create [this](http://www.reddit.com/r/Minecraft/comments/28le52/screenshot_of_all_players_that_joined_my_server/) awesome [screenshot](http://i.imgur.com/v4wg5kl.png) > Code that was used once to create [this](http://www.reddit.com/r/Minecraft/comments/28le52/screenshot_of_all_players_that_joined_my_server/) awesome [screenshot](http://i.imgur.com/v4wg5kl.png)
* `tilehelper.py` * `tilehelper.py`
> A plugin that automatically tiles (stacks) blocks inside a selected region in configurable directions. > A plugin that automatically tiles (stacks) blocks inside a selected region in configurable directions.
* `mentio.py` * `mentio.py`
> Adds `/listen`, highlights chat and plays a sound when your name was mentioned > Adds `/listen`, highlights chat and plays a sound when your name was mentioned
* `cycler.py` * `cycler.py`
> Adds `/cycler`, swaps the hotbar with inventory when player changes slot from right->left or left->right > Adds `/cycler`, swaps the hotbar with inventory when player changes slot from right->left or left->right
* `motd.py` * `motd.py`
> Adds `/getmotd` & `/setmotd` to update the motd on the fly (no reboot). > Adds `/getmotd` & `/setmotd` to update the motd on the fly (no reboot).
* `abot.py` * `abot.py`
> AnswerBot. Hides stupid questions from chat and tells the sender about `/faq` or the like > AnswerBot. Hides stupid questions from chat and tells the sender about `/faq` or the like
* `damnspam.py` * `damnspam.py`
> Adds `/damnspam`, creates timeout for buttons/levers to mitigate button spam. > Adds `/damnspam`, creates timeout for buttons/levers to mitigate button spam.
* `forcefield.py` * `forcefield.py`
> Adds '/forcefield', creates forcefield for players who want it. > Adds '/forcefield', creates forcefield for players who want it.
# Code styleguide & tips # Code styleguide & tips
## Indentation ## Indentation
Never use tabs! Never use tabs!
Use 2 spaces to indent. Use 2 spaces to indent.
## Quotes ## Quotes
Always use double-quotes! Always use double-quotes!
Only use single-quotes when the string contains double-quotes that would need to be escaped. Only use single-quotes when the string contains double-quotes that would need to be escaped.
## Capitalization ## Capitalization
Do not use camelCase for variable or function names! Use under_score naming. Do not use camelCase for variable or function names! Use under_score naming.
camelCase is okay when used like `import foo.bar.camelCase as camelCase`. camelCase is okay when used like `import foo.bar.camelCase as camelCase`.
## Aligning variable assignments ## Aligning variable assignments
In case you have multiple variable assignments, align the equals sign: In case you have multiple variable assignments, align the equals sign:
```Python ```Python
# bad # bad
foo = 1 foo = 1
foobar = 2 foobar = 2
a = 3 a = 3
# good # good
foo = 1 foo = 1
foobar = 2 foobar = 2
a = 3 a = 3
``` ```
Pro Tip: Use the AlignTab plugin for Sublime Text! Pro Tip: Use the AlignTab plugin for Sublime Text!
## Horizontal spacing ## Horizontal spacing
Use at least one space left and one space right to equals signs, and one space right to colons. Use at least one space left and one space right to equals signs, and one space right to colons.
## Vertical spacing ## Vertical spacing
Leave two empty lines before function definitions. In case you need to use `@hook.something`, add the two lines before that, directly followed by the definition. Leave two empty lines before function definitions. In case you need to use `@hook.something`, add the two lines before that, directly followed by the definition.
## Meaningful names ## Meaningful names
Give function and variable names meaningful names. If you want to shorten long names, that's fine, but leave a comment on assigment with the actual meaning. Give function and variable names meaningful names. If you want to shorten long names, that's fine, but leave a comment on assigment with the actual meaning.
## Readability ## Readability
Don't create long lines with lots of function calls. Split into multiple lines instead. Don't create long lines with lots of function calls. Split into multiple lines instead.
Also avoid methods with lots of lines. Split into multiple methods instead. Also avoid methods with lots of lines. Split into multiple methods instead.
```Python ```Python
# bad # bad
foo = int(player_data[str(server.getPlayer(args[4]).getUniqueId())]["details"].["last_login"].strftime("%s")) foo = int(player_data[str(server.getPlayer(args[4]).getUniqueId())]["details"].["last_login"].strftime("%s"))
# good # good
player = server.getPlayer(args[4]) player = server.getPlayer(args[4])
player_id = uid(player) player_id = uid(player)
logintime = player_data[played_id]["last_login"] logintime = player_data[played_id]["last_login"]
epoch_time = int(logintime.strftime("%s")) epoch_time = int(logintime.strftime("%s"))
``` ```
## Comments ## Comments
Comments are good! Comments are good!
Please comment everything that's non-obious or makes it easier to understand Please comment everything that's non-obious or makes it easier to understand
## Debugging ## Debugging
Debugging can be a bit special with jython/PyPluginLoader. Debugging can be a bit special with jython/PyPluginLoader.
When something goes wrong, you probably see a weird traceback that's not telling you shit. When something goes wrong, you probably see a weird traceback that's not telling you shit.
...unless you take a closer look. ...unless you take a closer look.
You will not see a direct traceback of the python methods. You will not see a direct traceback of the python methods.
Instead, you'll probably see a bunch of java, bukkit and python things, because it tries to translate python into java, line per line. Instead, you'll probably see a bunch of java, bukkit and python things, because it tries to translate python into java, line per line.
Take a closer look at the method names, they might tell you what it's trying to do and where it's coming from. Take a closer look at the method names, they might tell you what it's trying to do and where it's coming from.
Watch out for something like `org.python.pycode._pyx5.horribleCode$23(/path/to/badcode.py:214) ~[?:?]` Watch out for something like `org.python.pycode._pyx5.horribleCode$23(/path/to/badcode.py:214) ~[?:?]`
0. In this case, `_pyx5` is our module. 0. In this case, `_pyx5` is our module.
0. `horribleCode` is the method that was called 0. `horribleCode` is the method that was called
0. `/path/to/badcode.py` is the actual file of our module 0. `/path/to/badcode.py` is the actual file of our module
0. `:214` is the line in which the error occured. 0. `:214` is the line in which the error occured.
Please note that the line may not be accurate. You'll often get the start of a loop, or the end of a method - when the actual error was somewhere in there. Please note that the line may not be accurate. You'll often get the start of a loop, or the end of a method - when the actual error was somewhere in there.
In many cases, this is enough to find your bug. If you still cannot find it,try to catch exceptions in your code, as follows: In many cases, this is enough to find your bug. If you still cannot find it,try to catch exceptions in your code, as follows:
## Catching exceptions ## Catching exceptions
If you want to catch all exceptions (e.g. for debugging), do not `catch Exception`. If you want to catch all exceptions (e.g. for debugging), do not `catch Exception`.
Since we're using jython, this will not catch Java exceptions. Since we're using jython, this will not catch Java exceptions.
This will give you some more deatails: This will give you some more deatails:
```python ```python
from traceback import format_exc as trace from traceback import format_exc as trace
try: try:
#code #code
except: # everything except: # everything
print(trace()) print(trace())
``` ```