Archived
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
230e447ea5 | ||
|
|
46d24a64c6 | ||
|
|
ed26126de1 | ||
|
|
c87adff9ba | ||
|
|
ec192ad790 | ||
|
|
7c2c87a05e | ||
|
|
939e744a33 | ||
|
|
b7aed64fe5 | ||
|
|
217f2cb579 | ||
|
|
b9f4d468ae | ||
|
|
fa6aaf0dff | ||
|
|
c30578525f | ||
|
|
bbbd180b98 | ||
|
|
911d61b9e5 | ||
|
|
2dff50201a | ||
|
|
2d5d6aace0 | ||
|
|
881c413642 | ||
|
|
24d341f833 | ||
|
|
97b6c3a152 | ||
|
|
5cac70af31 | ||
|
|
db50be458f | ||
|
|
08cae3213e | ||
|
|
180680422a | ||
|
|
712cd135fc | ||
|
|
b18bdb69cb | ||
|
|
a9b9fc6ae5 | ||
|
|
d4f618aa99 | ||
|
|
3cfb585c8b | ||
|
|
2a080b37a6 | ||
|
|
54beea6ee5 | ||
|
|
aad63e5416 | ||
|
|
2e7e021001 | ||
|
|
a854fa2039 | ||
|
|
e277b923a7 | ||
|
|
e65122d4b3 | ||
|
|
fe2cafe5c9 | ||
|
|
e67fe48317 | ||
|
|
7096d7036e | ||
|
|
7b1cd0799f | ||
|
|
e35b079263 | ||
|
|
993d1cf04c | ||
|
|
82c3015c04 | ||
|
|
0fd4894550 | ||
|
|
627e02226d | ||
|
|
2b409b0ccc | ||
|
|
a962e0b6a8 | ||
|
|
fa68622d2d | ||
|
|
98b2f564bc | ||
|
|
85eff42481 | ||
|
|
22cc16cc48 | ||
|
|
600e6c9c2f | ||
|
|
ee80672d38 | ||
|
|
c973025a8e | ||
|
|
eb287681d1 | ||
|
|
38cf2eb153 | ||
|
|
9dba5641e1 | ||
|
|
f48dcf11ef | ||
|
|
3806af1f66 | ||
|
|
c527d21de5 | ||
|
|
a0f5b99745 | ||
|
|
5f6b2409aa | ||
|
|
aa0357f0da | ||
|
|
9624107acd | ||
|
|
6ea1ae8718 | ||
|
|
59219cb7a0 | ||
|
|
cbdab2504d | ||
|
|
ccd0e3cd09 | ||
|
|
16c95e4a12 | ||
|
|
0f5e5335b2 | ||
|
|
2885e20669 | ||
|
|
45376bc38f | ||
|
|
a8a37f0553 | ||
|
|
c01caf04a9 | ||
|
|
c5a6d0b52b | ||
|
|
38ae7372ca | ||
|
|
a38eb33760 | ||
|
|
44d0541b29 | ||
|
|
9dd5555fb3 | ||
|
|
69f6423028 | ||
|
|
a53957e888 | ||
|
|
c00c36076a | ||
|
|
a54263a59d | ||
|
|
b1f00d3fe4 | ||
|
|
db6faa69ae | ||
|
|
546ce7cfb2 | ||
|
|
c4a8fc9358 | ||
|
|
b7fef7607b | ||
|
|
fb1655e01b | ||
|
|
432d249878 | ||
|
|
3691fa6503 | ||
|
|
e4dbf1c458 | ||
|
|
f4381ae7c2 | ||
|
|
e2ba62fd9d | ||
|
|
59e16e24a6 | ||
|
|
8f0d9611b0 | ||
|
|
0bf4cddb95 | ||
|
|
e65b8e25fb | ||
|
|
4d04d8df5b | ||
|
|
1a6e60fec4 | ||
|
|
195cf2c7ec | ||
|
|
433b2d3bbb | ||
|
|
65c3bb1371 | ||
|
|
0e65631ece | ||
|
|
8637976c76 | ||
|
|
cde51fd6f6 | ||
|
|
cb8e92a168 | ||
|
|
35e7bf098f | ||
|
|
9ae650549c | ||
|
|
70da17408f | ||
|
|
cc17a53f0e | ||
|
|
7d0d0fd3c7 | ||
|
|
4b19546c13 | ||
|
|
fa0823b15b | ||
|
|
4de83c5114 | ||
|
|
a03bb67d85 | ||
|
|
fb5a61b8d4 | ||
|
|
ab24808f0d | ||
|
|
c6dca4ac94 | ||
|
|
a272a615e4 | ||
|
|
5cee964b9c | ||
|
|
665fbcb430 | ||
|
|
626da9fb5c | ||
|
|
35e59583bc | ||
|
|
fac11c147d | ||
|
|
219bc0751b | ||
|
|
b082d6fdae | ||
|
|
0262d428d0 | ||
|
|
b75f4505d1 | ||
|
|
94b849b81c | ||
|
|
69ac22c69a | ||
|
|
0d9613911c | ||
|
|
4c0a482a3c | ||
|
|
69b21c6acf | ||
|
|
e36dbaeb44 | ||
|
|
086a1fe064 | ||
|
|
ba10e82171 | ||
|
|
c6bfe7c3d1 | ||
|
|
5838739985 | ||
|
|
7a53704e60 | ||
|
|
1f5ee6b348 | ||
|
|
e9f1142cea | ||
|
|
837b68e9f9 | ||
|
|
0151ca55ed | ||
|
|
e5b6f27b61 | ||
|
|
4b6bd6eaa2 | ||
|
|
5f2cf0b19e | ||
|
|
6771be27de | ||
|
|
cb7c8550fd | ||
|
|
ba7f03f5e1 | ||
|
|
cd0358de2b | ||
|
|
80dcbb3d13 | ||
|
|
90b2968df3 | ||
|
|
cba20fa67a | ||
|
|
be988fb9e5 | ||
|
|
71f5f46ff7 | ||
|
|
bd94ee9076 | ||
|
|
bb2bb0ecc8 | ||
|
|
b9e73b58d7 | ||
|
|
3f212dc451 | ||
|
|
33169883fb | ||
|
|
d89f649ca0 | ||
|
|
f526f521b5 | ||
|
|
ea7284f2c8 | ||
|
|
b284f6940f | ||
|
|
8bac5b5331 | ||
|
|
5846d0f765 | ||
|
|
a0f02fb846 | ||
|
|
a87b9eb9d1 | ||
|
|
2d02165d06 | ||
|
|
888136e30a | ||
|
|
b43d99b8bf | ||
|
|
81147baa11 | ||
|
|
b2d69ff507 | ||
|
|
616ddd4cfc | ||
|
|
fd212674c1 | ||
|
|
1c2c3782c7 | ||
|
|
6ccbf25d87 | ||
|
|
a1df5c73e8 | ||
|
|
e32edd981e | ||
|
|
dd2e16ef57 | ||
|
|
217dc64c87 | ||
|
|
0a04de8c0e | ||
|
|
f9744d787c | ||
|
|
340e09777e | ||
|
|
39a9644a1f | ||
|
|
81deba5af2 | ||
|
|
93f87a167d | ||
|
|
cc547dc543 | ||
|
|
4dbabb5ed2 | ||
|
|
6cb477e3df | ||
|
|
7e86a2b6a9 | ||
|
|
4909e1a452 | ||
|
|
f116d937ec | ||
|
|
5b7566ea67 | ||
|
|
bbc12659c2 | ||
|
|
7a0d0fee72 | ||
|
|
ead78abd1c | ||
|
|
5012696c56 | ||
|
|
45f105ec61 | ||
|
|
f2f6b49a7b | ||
|
|
4313bb90fd | ||
|
|
280525170c | ||
|
|
0be9493448 | ||
|
|
1dee504cfd | ||
|
|
1e0b45fb17 | ||
|
|
bec8a28302 | ||
|
|
af302f2ca9 | ||
|
|
32eae1b248 | ||
|
|
500b62affd | ||
|
|
7711b62b9e | ||
|
|
fb2cd7d3b7 | ||
|
|
90e6fe9280 | ||
|
|
56e50c81f9 | ||
|
|
57c721cbc6 | ||
|
|
0793413501 | ||
|
|
9dc890f2fa | ||
|
|
8e3585934b | ||
|
|
65c4affba8 | ||
|
|
6f0514709d | ||
|
|
f0fb488eb8 | ||
|
|
4ad50fa688 | ||
|
|
277a571e4a | ||
|
|
aa8ffd95b1 | ||
|
|
5431cd2b90 | ||
|
|
086902a202 | ||
|
|
927ea4d57a | ||
|
|
b1be92f1a9 | ||
|
|
2b6dd6555e | ||
|
|
0494b82bf0 | ||
|
|
1e399a002a | ||
|
|
2e31e3a463 | ||
|
|
2b89ec586c | ||
|
|
6963b02a03 | ||
|
|
e483f12630 | ||
|
|
c150fae053 | ||
|
|
3e27b2691b | ||
|
|
0b2fec7271 | ||
|
|
72219d9e27 | ||
|
|
51725b9add | ||
|
|
557142e82b | ||
|
|
3095761138 | ||
|
|
4e5ef743b6 | ||
|
|
366ac59901 | ||
|
|
8d0a66d492 | ||
|
|
18aee5a48e | ||
|
|
473c7c9ffd | ||
|
|
cceb7e7b53 | ||
|
|
7508938dbe | ||
|
|
c2275ee0bc | ||
|
|
4e9241c97e | ||
|
|
684c0c50e3 | ||
|
|
d6635c8951 | ||
|
|
c8d61d0c18 | ||
|
|
b764aa6bf4 | ||
|
|
3936f14861 | ||
|
|
768391fb60 | ||
|
|
2d608a8cee | ||
|
|
ec16b0045f | ||
|
|
6459884627 | ||
|
|
9302451854 | ||
|
|
0a16b25ef5 | ||
|
|
1c6931c027 | ||
|
|
d7c80d5034 | ||
|
|
c9bd89a3bb | ||
|
|
68df60865c | ||
|
|
acfd84906f | ||
|
|
68d627b6fc | ||
|
|
f92baebf68 | ||
|
|
1ab86ffc6f | ||
|
|
4916bd0382 | ||
|
|
843c34051f | ||
|
|
fc0030b326 | ||
|
|
1e80e50b1f | ||
|
|
e0393b4d63 | ||
|
|
84404fbffd | ||
|
|
f32f44d7d1 | ||
|
|
0db39e5ca1 | ||
|
|
3bf227ea1c | ||
|
|
cb716abd6b | ||
|
|
3dd467afec | ||
|
|
cec624a833 | ||
|
|
535dbcc94b | ||
|
|
e574e8e914 | ||
|
|
d582e8a457 | ||
|
|
e853681df6 | ||
|
|
bc301a3cb2 | ||
|
|
095df21073 | ||
|
|
b3c3886ffe | ||
|
|
aef7d5df3b | ||
|
|
4754083725 | ||
|
|
33c98181f8 | ||
|
|
e645949bab | ||
|
|
49edec4a9f | ||
|
|
ea277cb3ab | ||
|
|
0227c2071e | ||
|
|
b7de342537 |
@@ -1,10 +1,6 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
*.class
|
*.class
|
||||||
*sublime*
|
*sublime*
|
||||||
*.bat*
|
|
||||||
secrets.py
|
|
||||||
excluded.txt
|
|
||||||
.idea
|
|
||||||
|
|
||||||
# these are player/ingame specific
|
# these are player/ingame specific
|
||||||
files/
|
files/
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
If you want to contribute, please [read through the pages on the wiki](https://github.com/RedstonerServer/redstoner-utils/wiki).
|
|
||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
# The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) Redstoner
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE
|
|
||||||
@@ -2,8 +2,245 @@
|
|||||||
|
|
||||||
Redstoner's custom plugins, written in python.
|
Redstoner's custom plugins, written in python.
|
||||||
|
|
||||||
------
|
|
||||||
|
|
||||||
## Contributing
|
# Installation / Set-up
|
||||||
|
|
||||||
If you want to contribute, please [read through the pages on the wiki](https://github.com/RedstonerServer/redstoner-utils/wiki).
|
1-line-install-script for bash:
|
||||||
|
`wget -O install.sh "http://pastie.org/pastes/9310905/download?key = 6byp4mrqmiui8yqeo3s6yw"; md5sum --check <<<"3499671c0832e561bc9c7d476d2167cb install.sh" && sh install.sh`
|
||||||
|
|
||||||
|
Detailed description:
|
||||||
|
|
||||||
|
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. Run it once inside redstoner, then shut it down again
|
||||||
|
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
|
||||||
|
' 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. 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](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
|
||||||
|
|
||||||
|
|
||||||
|
# branches
|
||||||
|
|
||||||
|
* **dev**
|
||||||
|
Always use this branch to change code, please test before pushing. (If something goes wrong here, that's okay)
|
||||||
|
|
||||||
|
* **master**
|
||||||
|
Never commit into this branch directly! Only merge stable versions of *dev*:
|
||||||
|
```bash
|
||||||
|
git checkout master
|
||||||
|
git merge dev
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Deploying on the server
|
||||||
|
|
||||||
|
**Never** edit the files directly on the server!
|
||||||
|
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.)*
|
||||||
|
|
||||||
|
### Deploying on test server
|
||||||
|
* Push all changes
|
||||||
|
* Run `<server-dir>/git_pull_utils.sh`.
|
||||||
|
* Restart (You can try reloading here, but expect the unexpected)
|
||||||
|
|
||||||
|
### Deploying on production server
|
||||||
|
* Test all code carefully on the test server
|
||||||
|
***on your machine:***
|
||||||
|
* `git checkout master`
|
||||||
|
* `git pull`
|
||||||
|
* `git merge dev`
|
||||||
|
* `git push -u origin master`
|
||||||
|
* `git checkout dev`
|
||||||
|
***on the server:***
|
||||||
|
* `rs update_utils`
|
||||||
|
* Restart
|
||||||
|
|
||||||
|
|
||||||
|
# Modules / Files
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
|
||||||
|
* `files/`
|
||||||
|
|
||||||
|
> All config / storage files go here
|
||||||
|
|
||||||
|
* `plugin.yml`
|
||||||
|
|
||||||
|
> The plugin.yml file required for bukkut plugins
|
||||||
|
|
||||||
|
* `main.py`
|
||||||
|
|
||||||
|
> The only file loaded by PyPluginLoader, loads all other modules
|
||||||
|
> Contains a few methods that **need to be cleaned up**
|
||||||
|
|
||||||
|
* `helpers.py`
|
||||||
|
|
||||||
|
> Library that adds a bunch of re-usable methods which are used in nearly all other modules
|
||||||
|
|
||||||
|
* `adminchat.py`
|
||||||
|
|
||||||
|
> Adds chat for staff using `/ac <text` or `,<text>`
|
||||||
|
|
||||||
|
* `chatgroups.py`
|
||||||
|
|
||||||
|
> Adds group-chat with `/chatgroup` and `/cgt` to toggle normal chat into group mode
|
||||||
|
|
||||||
|
* `lagchunks.py`
|
||||||
|
|
||||||
|
> Plugin to locate laggy chunks. `/lc <n>` lists chunks with more than `n` entities
|
||||||
|
|
||||||
|
* `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.
|
||||||
|
|
||||||
|
* `plotter.py`
|
||||||
|
|
||||||
|
> Start of a custom plot-plugin like PlotMe, on hold because the PlotMe developer continued to develop PlotMe
|
||||||
|
|
||||||
|
* `reports.py`
|
||||||
|
|
||||||
|
> The `/report <text>` and `/rp` plugin
|
||||||
|
|
||||||
|
* `saylol.py`
|
||||||
|
|
||||||
|
> Remake of sheep's old SayLol plugin, originally written as a standalone plugin in Java
|
||||||
|
|
||||||
|
* `skullclick.py`
|
||||||
|
|
||||||
|
> Shows the owner of a skull when right-clicked
|
||||||
|
|
||||||
|
* `webtoken.py`
|
||||||
|
|
||||||
|
> Adds `/token`, reads and writes from the database to generate *pronouncable* (and thus memorable) registration-tokens for the website
|
||||||
|
|
||||||
|
* `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)
|
||||||
|
|
||||||
|
* `tilehelper.py`
|
||||||
|
|
||||||
|
> A plugin that automatically tiles (stacks) blocks inside a selected region in configurable directions.
|
||||||
|
|
||||||
|
* `mentio.py`
|
||||||
|
|
||||||
|
> Adds `/listen`, highlights chat and plays a sound when your name was mentioned
|
||||||
|
|
||||||
|
* `cycler.py`
|
||||||
|
|
||||||
|
> Adds `/cycler`, swaps the hotbar with inventory when player changes slot from right->left or left->right
|
||||||
|
|
||||||
|
* `motd.py`
|
||||||
|
|
||||||
|
> Adds `/getmotd` & `/setmotd` to update the motd on the fly (no reboot).
|
||||||
|
|
||||||
|
* `abot.py`
|
||||||
|
|
||||||
|
> AnswerBot. Hides stupid questions from chat and tells the sender about `/faq` or the like
|
||||||
|
|
||||||
|
* `damnspam.py`
|
||||||
|
|
||||||
|
> Adds `/damnspam`, creates timeout for buttons/levers to mitigate button spam.
|
||||||
|
|
||||||
|
* `forcefield.py`
|
||||||
|
|
||||||
|
> Adds '/forcefield', creates forcefield for players who want it.
|
||||||
|
|
||||||
|
# Code styleguide & tips
|
||||||
|
|
||||||
|
## Indentation
|
||||||
|
Never use tabs!
|
||||||
|
Use 2 spaces to indent.
|
||||||
|
|
||||||
|
## Quotes
|
||||||
|
Always use double-quotes!
|
||||||
|
Only use single-quotes when the string contains double-quotes that would need to be escaped.
|
||||||
|
|
||||||
|
## Capitalization
|
||||||
|
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`.
|
||||||
|
|
||||||
|
## Aligning variable assignments
|
||||||
|
In case you have multiple variable assignments, align the equals sign:
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# bad
|
||||||
|
foo = 1
|
||||||
|
foobar = 2
|
||||||
|
a = 3
|
||||||
|
|
||||||
|
# good
|
||||||
|
foo = 1
|
||||||
|
foobar = 2
|
||||||
|
a = 3
|
||||||
|
```
|
||||||
|
|
||||||
|
Pro Tip: Use the AlignTab plugin for Sublime Text!
|
||||||
|
|
||||||
|
## Horizontal spacing
|
||||||
|
Use at least one space left and one space right to equals signs, and one space right to colons.
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## Readability
|
||||||
|
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.
|
||||||
|
|
||||||
|
```Python
|
||||||
|
# bad
|
||||||
|
foo = int(player_data[str(server.getPlayer(args[4]).getUniqueId())]["details"].["last_login"].strftime("%s"))
|
||||||
|
|
||||||
|
# good
|
||||||
|
player = server.getPlayer(args[4])
|
||||||
|
player_id = uid(player)
|
||||||
|
logintime = player_data[played_id]["last_login"]
|
||||||
|
epoch_time = int(logintime.strftime("%s"))
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
Comments are good!
|
||||||
|
Please comment everything that's non-obious or makes it easier to understand
|
||||||
|
|
||||||
|
## Debugging
|
||||||
|
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.
|
||||||
|
...unless you take a closer look.
|
||||||
|
|
||||||
|
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.
|
||||||
|
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) ~[?:?]`
|
||||||
|
0. In this case, `_pyx5` is our module.
|
||||||
|
0. `horribleCode` is the method that was called
|
||||||
|
0. `/path/to/badcode.py` is the actual file of our module
|
||||||
|
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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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.
|
||||||
|
This will give you some more deatails:
|
||||||
|
```python
|
||||||
|
from traceback import format_exc as trace
|
||||||
|
try:
|
||||||
|
#code
|
||||||
|
except: # everything
|
||||||
|
print(trace())
|
||||||
|
```
|
||||||
@@ -27,7 +27,7 @@ def list_answers(sender):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("abot")
|
@hook.command("abot")
|
||||||
def on_abot_command(sender, command, label, args):
|
def on_abot_command(sender, args):
|
||||||
plugin_header(sender, "AnswerBot")
|
plugin_header(sender, "AnswerBot")
|
||||||
if sender.hasPermission("utils.abot.admin"):
|
if sender.hasPermission("utils.abot.admin"):
|
||||||
if not args:
|
if not args:
|
||||||
@@ -45,8 +45,10 @@ def on_abot_command(sender, command, label, args):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_msg(event, message):
|
@hook.event("player.AsyncPlayerChatEvent", "low")
|
||||||
|
def on_chat(event):
|
||||||
sender = event.getPlayer()
|
sender = event.getPlayer()
|
||||||
|
message = event.getMessage().lower()
|
||||||
for answer in answers:
|
for answer in answers:
|
||||||
for regex in answer["regex"]:
|
for regex in answer["regex"]:
|
||||||
if regex.search(message):
|
if regex.search(message):
|
||||||
@@ -58,15 +60,4 @@ def check_msg(event, message):
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "low")
|
|
||||||
def on_chat(event):
|
|
||||||
check_msg(event, event.getMessage().lower())
|
|
||||||
|
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "low")
|
|
||||||
def on_any_cmd(event):
|
|
||||||
words = event.getMessage().lower().split(" ")
|
|
||||||
cmd = words[0][1:]
|
|
||||||
if cmd in ["msg", "m", "t", "pm", "mail", "r", "reply"]:
|
|
||||||
check_msg(event, " ".join(words[1:]))
|
|
||||||
|
|
||||||
load_answers()
|
load_answers()
|
||||||
+5
-36
@@ -1,12 +1,8 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from basecommands import simplecommand
|
|
||||||
|
|
||||||
ac_permission = "utils.ac"
|
ac_permission = "utils.ac"
|
||||||
|
ac_key = ","
|
||||||
ac_defaultkey = ","
|
|
||||||
ac_keys = open_json_file("adminchat_keys", {})
|
|
||||||
|
|
||||||
ac_toggle_list = []
|
ac_toggle_list = []
|
||||||
ac_prefix = "&8[&cAC&8]"
|
ac_prefix = "&8[&cAC&8]"
|
||||||
|
|
||||||
@@ -17,7 +13,6 @@ def adminchat(sender, msg):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
name = sender.getName()
|
name = sender.getName()
|
||||||
broadcast(ac_permission, "%s &9%s&8: &b%s" % (ac_prefix, name, msg))
|
broadcast(ac_permission, "%s &9%s&8: &b%s" % (ac_prefix, name, msg))
|
||||||
# Needs something here like fine(message) to show up in the logs when you use ackey, but fine doesnt work for some reason. It did on the server with /pyeval (not show up on console, but show up in logs nevertheless)
|
|
||||||
|
|
||||||
|
|
||||||
# ac toggle
|
# ac toggle
|
||||||
@@ -46,41 +41,15 @@ def on_ac_command(sender, args):
|
|||||||
noperm(sender)
|
noperm(sender)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_key(uuid):
|
|
||||||
key = ac_keys.get(uuid)
|
|
||||||
return key if key != None else ac_defaultkey
|
|
||||||
|
|
||||||
@simplecommand("adminchatkey",
|
|
||||||
aliases = ["ackey"],
|
|
||||||
senderLimit = 0,
|
|
||||||
helpNoargs = True,
|
|
||||||
helpSubcmd = True,
|
|
||||||
description = "Sets a key character for adminchat",
|
|
||||||
usage = "<key>")
|
|
||||||
def adminchatkey_command(sender, command, label, args):
|
|
||||||
key = " ".join(args)
|
|
||||||
uuid = uid(sender)
|
|
||||||
if key.lower() == "default" or key == ac_defaultkey:
|
|
||||||
del ac_keys[uuid]
|
|
||||||
save_keys()
|
|
||||||
return "&aYour adminchat key was set to the default character: '&c%s&a'" % ac_defaultkey
|
|
||||||
ac_keys[uid(sender)] = key
|
|
||||||
save_keys()
|
|
||||||
return "&aYour adminchat key was set to: '&c%s&a'" % key
|
|
||||||
|
|
||||||
def save_keys():
|
|
||||||
save_json_file("adminchat_keys", ac_keys)
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "low")
|
@hook.event("player.AsyncPlayerChatEvent", "low")
|
||||||
def on_chat(event):
|
def on_chat(event):
|
||||||
sender = event.getPlayer()
|
sender = event.getPlayer()
|
||||||
msg = event.getMessage()
|
msg = event.getMessage()
|
||||||
if sender.hasPermission(ac_permission) and not event.isCancelled():
|
if sender.hasPermission(ac_permission) and not event.isCancelled():
|
||||||
key = get_key(uid(sender))
|
if msg[:len(ac_key)] == ac_key:
|
||||||
if sender.getName() in ac_toggle_list:
|
adminchat(sender, msg[1:])
|
||||||
|
event.setCancelled(True)
|
||||||
|
elif sender.getName() in ac_toggle_list:
|
||||||
adminchat(sender, msg)
|
adminchat(sender, msg)
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
elif msg[:len(key)] == key:
|
|
||||||
adminchat(sender, msg[len(key):])
|
|
||||||
event.setCancelled(True)
|
|
||||||
|
|||||||
-134
@@ -1,134 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
from traceback import format_exc as print_traceback
|
|
||||||
import time
|
|
||||||
|
|
||||||
an_permission = "utils.an";
|
|
||||||
notes = open_json_file("adminnotes", [])
|
|
||||||
continued_messages = {}
|
|
||||||
|
|
||||||
|
|
||||||
def save_notes():
|
|
||||||
save_json_file("adminnotes", notes)
|
|
||||||
|
|
||||||
|
|
||||||
def r_ago(unit, i):
|
|
||||||
# Return ago + plural
|
|
||||||
if i != 1:
|
|
||||||
unit += "s"
|
|
||||||
return "%s %s ago" % (i, unit)
|
|
||||||
|
|
||||||
|
|
||||||
def calc_diff(time_ago):
|
|
||||||
current = time.time()
|
|
||||||
s = current-time_ago
|
|
||||||
s = int(s)
|
|
||||||
ago = "Some time ago"
|
|
||||||
|
|
||||||
if s < 10:
|
|
||||||
ago = "Just now"
|
|
||||||
elif s >= 10 and s < 60:
|
|
||||||
ago = r_ago("second", s)
|
|
||||||
elif s >= 60 and s < 3600:
|
|
||||||
ago = r_ago("minute", s/60)
|
|
||||||
elif s >= 3600 and s < 43200:
|
|
||||||
ago = r_ago("hour", s/60/60)
|
|
||||||
elif s >= 43200:
|
|
||||||
ago = r_ago("day", s/60/60/12)
|
|
||||||
return ago
|
|
||||||
|
|
||||||
|
|
||||||
def show_all_notes(sender):
|
|
||||||
if len(notes) == 0:
|
|
||||||
msg(sender, "&aNo open notes at the moment!")
|
|
||||||
return
|
|
||||||
for i in range(0, len(notes)):
|
|
||||||
arr = notes[i]
|
|
||||||
name = arr[0]
|
|
||||||
message = arr[1]
|
|
||||||
note_time = arr[2]
|
|
||||||
|
|
||||||
ago = calc_diff(note_time)
|
|
||||||
|
|
||||||
msg(sender, "&6#%s - &e%s&6, %s:" % (str(i+1), name, ago))
|
|
||||||
msg(sender, "&7%s" % colorify(message))
|
|
||||||
|
|
||||||
|
|
||||||
def show_an_help(sender):
|
|
||||||
msg(sender, "&6AdminNotes Help:")
|
|
||||||
msg(sender, "&e- /an")
|
|
||||||
msg(sender, "&7&oLists all notes")
|
|
||||||
msg(sender, "&e- /an del <ID>")
|
|
||||||
msg(sender, "&7&oRemove a note")
|
|
||||||
msg(sender, "&e- /an help")
|
|
||||||
msg(sender, "&7&oShows this menu")
|
|
||||||
msg(sender, "&e- /an Some text...")
|
|
||||||
msg(sender, "&7&oWrite a new note")
|
|
||||||
msg(sender, "&e- /an This text is very++")
|
|
||||||
msg(sender, "&7&oContinue writing your note when using &e/an long guys!&7&o again")
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("an", aliases=["adminnotes", "adminnote"])
|
|
||||||
def adminnotes_command(sender, command, label, args):
|
|
||||||
if not sender.hasPermission(an_permission):
|
|
||||||
noperm(sender)
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
arglen = len(args)
|
|
||||||
|
|
||||||
# arg length not valid
|
|
||||||
if arglen == 0:
|
|
||||||
show_all_notes(sender)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Shows note help
|
|
||||||
subcmd = args[0].lower()
|
|
||||||
if subcmd == "help":
|
|
||||||
show_an_help(sender)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Delete note
|
|
||||||
if subcmd == "del":
|
|
||||||
if arglen != 2:
|
|
||||||
show_an_help(sender)
|
|
||||||
return
|
|
||||||
if not args[1].isdigit():
|
|
||||||
msg(sender, "&cThe ID has to be numeric (check /an if you're unsure)")
|
|
||||||
return
|
|
||||||
note_id = int(args[1])-1
|
|
||||||
if note_id >= len(notes):
|
|
||||||
msg(sender, "&cThere is no note with that ID!")
|
|
||||||
return
|
|
||||||
# Deletes note by index
|
|
||||||
del notes[note_id]
|
|
||||||
save_notes()
|
|
||||||
msg(sender, "&aSuccessfully deleted note #%s!" % str(note_id+1))
|
|
||||||
return
|
|
||||||
|
|
||||||
message = " ".join(args)
|
|
||||||
name = sender.getName()
|
|
||||||
if name in continued_messages:
|
|
||||||
message = continued_messages[name] + " " + message
|
|
||||||
del continued_messages[name]
|
|
||||||
|
|
||||||
if message[-2:] == "++":
|
|
||||||
message = message[:-2]
|
|
||||||
continued_messages[name] = message
|
|
||||||
msg(sender, "&6You can continue writing by using &e/an <text ...>")
|
|
||||||
else:
|
|
||||||
notes.append([name, message, time.time()])
|
|
||||||
save_notes()
|
|
||||||
msg(sender, "&eNew note:&6 " + message)
|
|
||||||
broadcast(an_permission, "&a%s just added a new note! &2Type /an" % name)
|
|
||||||
except:
|
|
||||||
error(print_traceback())
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "monitor")
|
|
||||||
def on_an_join(event):
|
|
||||||
player = event.getPlayer()
|
|
||||||
if not player.hasPermission(an_permission):
|
|
||||||
return
|
|
||||||
if len(notes) > 0:
|
|
||||||
msg(player, "&cThere are currently %s open notes!" % len(notes))
|
|
||||||
elif len(notes) == 0:
|
|
||||||
msg(player, "&aThere are currently no open notes!")
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
|
|
||||||
badges = open_json_file("badges", {})
|
|
||||||
badges_available = {
|
|
||||||
"helpful" : "A very helpful player",
|
|
||||||
"expert_minecraft" : "An expert in Minecraft",
|
|
||||||
"expert_coder" : "A good coder",
|
|
||||||
"oldtimer" : "A long time player",
|
|
||||||
"good_builder" : "A very good builder",
|
|
||||||
"friendly" : "Many think that this player is friendly",
|
|
||||||
"very_active" : "A very active player",
|
|
||||||
"trustworthy" : "This player is very trustworthy",
|
|
||||||
}
|
|
||||||
badges_perm_add = "utils.badges.add"
|
|
||||||
badges_perm_del = "utils.badges.delete"
|
|
||||||
|
|
||||||
def save_badges():
|
|
||||||
save_json_file("badges", badges)
|
|
||||||
|
|
||||||
|
|
||||||
def get_badges(player):
|
|
||||||
sender_id = uid(player)
|
|
||||||
return badges.get(sender_id, [])
|
|
||||||
|
|
||||||
|
|
||||||
def show_badges(sender, player):
|
|
||||||
player_badges = get_badges(player)
|
|
||||||
if player_badges:
|
|
||||||
msg(sender, "&6Badges of " + player.getName())
|
|
||||||
for key in player_badges:
|
|
||||||
msg(sender, "&b> &3&o%s" % badges_available[key])
|
|
||||||
else:
|
|
||||||
msg(sender, "&eThis player has no badges yet")
|
|
||||||
|
|
||||||
|
|
||||||
def new_badge_event(player, badge):
|
|
||||||
msg(player, "")
|
|
||||||
msg(player, "&6Wow! You just received a badge!")
|
|
||||||
msg(player, "&b-> &3%s" % badges_available[badge])
|
|
||||||
msg(player, "&7Type /badge to see all your badges!")
|
|
||||||
msg(player, "")
|
|
||||||
player.playSound(player.getLocation(), "random.orb", 1, 1)
|
|
||||||
|
|
||||||
|
|
||||||
def del_badge_event(player, badge):
|
|
||||||
msg(player, "&cWe took your badge \"%s\"." % badges_available[badge])
|
|
||||||
|
|
||||||
|
|
||||||
def list_badges(sender):
|
|
||||||
if badges_available:
|
|
||||||
for key in badges_available.keys():
|
|
||||||
msg(sender, "&b> &3%s &7&o\"%s\"" % (key, badges_available[key]))
|
|
||||||
else:
|
|
||||||
msg(sender, "&cThere are currently no badges available")
|
|
||||||
|
|
||||||
|
|
||||||
def add_badge(sender, target, badge):
|
|
||||||
if badge in badges_available:
|
|
||||||
player_badges = get_badges(target)
|
|
||||||
if badge in player_badges:
|
|
||||||
msg(sender, "&cThis player got this badge already!")
|
|
||||||
return
|
|
||||||
player_badges.append(badge)
|
|
||||||
if player_badges:
|
|
||||||
badges[uid(target)] = player_badges
|
|
||||||
msg(sender, "&aYou just gave %s a new badge!" % target.getName())
|
|
||||||
new_badge_event(target, badge)
|
|
||||||
save_badges()
|
|
||||||
else:
|
|
||||||
msg(sender, "&cThere is no badge called %s. Check /badge list!" % badge)
|
|
||||||
|
|
||||||
|
|
||||||
def del_badge(sender, target, badge):
|
|
||||||
if badge in badges_available.keys():
|
|
||||||
player_badges = get_badges(target)
|
|
||||||
if badge in player_badges:
|
|
||||||
player_badges.remove(badge)
|
|
||||||
badges[uid(target)] = player_badges
|
|
||||||
msg(sender, "&aYou just took %s from %s!" % (badge, target.getName()))
|
|
||||||
save_badges()
|
|
||||||
del_badge_event(target, badge)
|
|
||||||
return
|
|
||||||
msg(sender, "&c%s doesn't have this badge!" % target.getName())
|
|
||||||
else:
|
|
||||||
msg(sender, "&cThere is no badge called %s. Check /badge list!" % badge)
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("badge", aliases=["badges", "rewards"])
|
|
||||||
def on_badge_command(sender, command, label, args):
|
|
||||||
argnum = int(len(args))
|
|
||||||
|
|
||||||
# No arguments
|
|
||||||
if argnum is 0:
|
|
||||||
show_badges(sender, sender)
|
|
||||||
|
|
||||||
# Length of arguments is 1
|
|
||||||
if argnum == 1:
|
|
||||||
|
|
||||||
# If only argument is "list"
|
|
||||||
if args[0].lower() == "list":
|
|
||||||
list_badges(sender)
|
|
||||||
return True
|
|
||||||
|
|
||||||
# If only argument is a player name
|
|
||||||
target = server.getPlayer(args[0])
|
|
||||||
if is_player(target):
|
|
||||||
show_badges(sender, target)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
msg(sender, "&cThere is no player called %s online." % args[0])
|
|
||||||
return True
|
|
||||||
|
|
||||||
msg(sender, "&cUnknown syntax: /badge <playername> &o&c /badge list")
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Length of arguments is 3
|
|
||||||
if argnum == 3:
|
|
||||||
cmd = args[0].lower()
|
|
||||||
target = server.getPlayer(args[1])
|
|
||||||
new_badge = args[2].lower()
|
|
||||||
|
|
||||||
if cmd == "add":
|
|
||||||
if not sender.hasPermission(badges_perm_add):
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
add_badge(sender, target, new_badge)
|
|
||||||
return True
|
|
||||||
|
|
||||||
if cmd == "take" or cmd == "del":
|
|
||||||
if not sender.hasPermission(badges_perm_del):
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
del_badge(sender, target, new_badge)
|
|
||||||
return True
|
|
||||||
|
|
||||||
msg(sender, "&cUnknown syntax: /badge <add|take> <playername> <badge>")
|
|
||||||
return True
|
|
||||||
-110
@@ -1,110 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
|
|
||||||
to_see_permission = "utils.showpermission" # See cmd permission in help
|
|
||||||
|
|
||||||
|
|
||||||
def isSenderValid(senderLimit, isPlayer):
|
|
||||||
return True if senderLimit == -1 else senderLimit != isPlayer
|
|
||||||
|
|
||||||
def invalidSenderMsg(isPlayer):
|
|
||||||
return "&cThat command can only be run from the console" if isPlayer else "&cThat command can only be run by players"
|
|
||||||
|
|
||||||
def helpMsg(sender, cmd, description, usage, aliases, permission):
|
|
||||||
help_msg = "&aInformation about command /%s:\n &9%s" % (cmd, description.replace("\n", "\n "))
|
|
||||||
help_msg += "\n \n&aSyntax: /%s %s" % (cmd, usage)
|
|
||||||
if aliases:
|
|
||||||
help_msg += ("\n&6Aliases: " + "".join([(alias + ", ") for alias in aliases]))[:-2]
|
|
||||||
if sender.hasPermission(to_see_permission):
|
|
||||||
help_msg += "\n&6Required permission: " + permission
|
|
||||||
return help_msg
|
|
||||||
|
|
||||||
|
|
||||||
def simplecommand(cmd,
|
|
||||||
aliases = [],
|
|
||||||
usage = "[args...]",
|
|
||||||
description = None,
|
|
||||||
senderLimit = -1,
|
|
||||||
amin = 0,
|
|
||||||
amax = -1,
|
|
||||||
helpNoargs = False,
|
|
||||||
helpSubcmd = False):
|
|
||||||
cmd = cmd.lower()
|
|
||||||
permission = "utils." + cmd
|
|
||||||
if not description:
|
|
||||||
description = "Handles " + cmd
|
|
||||||
if not usage:
|
|
||||||
usage = "/%s <subcmd>" % cmd
|
|
||||||
|
|
||||||
def getHelp(sender):
|
|
||||||
return helpMsg(sender, cmd, description, usage, aliases, permission)
|
|
||||||
|
|
||||||
def decorator(function):
|
|
||||||
|
|
||||||
@hook.command(cmd, aliases = aliases)
|
|
||||||
def call(sender, command, label, args):
|
|
||||||
message = run(sender, command, label, args)
|
|
||||||
if message:
|
|
||||||
if message == "HELP":
|
|
||||||
message = getHelp(sender)
|
|
||||||
msg(sender, message)
|
|
||||||
return True
|
|
||||||
|
|
||||||
def run(sender, command, label, args):
|
|
||||||
isPlayer = is_player(sender)
|
|
||||||
if not isSenderValid(senderLimit, isPlayer):
|
|
||||||
return invalidSenderMsg(isPlayer)
|
|
||||||
if not sender.hasPermission(permission):
|
|
||||||
return "&cYou do not have permission to use that command"
|
|
||||||
if ((not args) and helpNoargs) or (helpSubcmd and args and args[0].lower() == "help"):
|
|
||||||
return getHelp(sender)
|
|
||||||
if not checkargs(sender, args, amin, amax):
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
return function(sender, command, label, args)
|
|
||||||
except CommandException, e:
|
|
||||||
return e.message
|
|
||||||
except Exception, e:
|
|
||||||
error(e.message, trace())
|
|
||||||
return "&cAn internal error occurred while attempting to perform this command"
|
|
||||||
|
|
||||||
return call
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
|
|
||||||
class CommandException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Validate():
|
|
||||||
@staticmethod
|
|
||||||
def notNone(obj, msg):
|
|
||||||
if obj == None:
|
|
||||||
raise CommandException(msg)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isPlayer(sender):
|
|
||||||
if not is_player(sender):
|
|
||||||
raise CommandException("&cThat command can only be run by players")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isConsole(sender):
|
|
||||||
if is_player(sender):
|
|
||||||
raise CommandException("&cThat command can only be run from the console")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isAuthorized(sender, permission, msg = "that command"):
|
|
||||||
if not sender.hasPermission(permission):
|
|
||||||
raise CommandException("&cYou do not have permission to use " + msg)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isTrue(obj, msg):
|
|
||||||
if obj != True:
|
|
||||||
raise CommandException(msg)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def checkArgs(sender, args, amin, amax):
|
|
||||||
if not checkargs(sender, args, amin, amax):
|
|
||||||
raise CommandException("")
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,285 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
from basecommands import simplecommand, Validate, CommandException
|
|
||||||
from time import sleep
|
|
||||||
from collections import deque
|
|
||||||
import thread
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
|
||||||
import org.bukkit.block.Furnace as Furnace
|
|
||||||
import org.bukkit.inventory.ItemStack as ItemStack
|
|
||||||
import org.bukkit.Material as Material
|
|
||||||
import org.bukkit.event.block.Action as Action
|
|
||||||
import org.bukkit.block.BlockFace as BlockFace
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable as Runnable
|
|
||||||
|
|
||||||
settingInformation = dict( #[setting type, identifying description, detailed description, aliases, (optional) max slot id], setting types: 0 = toggle, default on. 1 = Set your setting to held itemstack, 2 = toggle, default off
|
|
||||||
cauldron = [0,
|
|
||||||
"easy cauldron water level control",
|
|
||||||
"Toggles whether cauldrons auto-fill upon placement and whether right clicking them with redstone dust or empty hand will cycle their water level",
|
|
||||||
["caul", "water"]
|
|
||||||
],
|
|
||||||
slab = [0,
|
|
||||||
"automatically flipping placed slabs upside-down",
|
|
||||||
"Toggles whether slabs/steps which you place should be automatically flipped upside-down",
|
|
||||||
["step"]
|
|
||||||
],
|
|
||||||
furnace = [1,
|
|
||||||
"automatically filling furnaces upon placement",
|
|
||||||
"Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.",
|
|
||||||
["cooker", "fillf"], 2
|
|
||||||
],
|
|
||||||
#torch = [0,
|
|
||||||
# "removal of torches you place on redstone blocks",
|
|
||||||
# "Toggles whether redstone torches which you place on redstone blocks will be deleted after a short amount of delay.",
|
|
||||||
# ["redstonetorch", "tor"]
|
|
||||||
#],
|
|
||||||
piston = [2,
|
|
||||||
"rotating pistons, droppers and hoppers to face the block you place them against",
|
|
||||||
"Toggles whether pistons or sticky pistons which you place will be rotated to face the block which you placed them against.",
|
|
||||||
["invert", "rp"]
|
|
||||||
],
|
|
||||||
dropper = [1,
|
|
||||||
"automatically filling droppers upon placement",
|
|
||||||
"Sets your preferred default dropper contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.",
|
|
||||||
["itemshooter", "filld"], 8
|
|
||||||
],
|
|
||||||
hopper = [1,
|
|
||||||
"automatically filling hoppers upon placement",
|
|
||||||
"Sets your preferred default hopper contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.",
|
|
||||||
["itemtransporter", "fillh"], 4
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
defaults = {
|
|
||||||
0: list,
|
|
||||||
1: dict,
|
|
||||||
2: list
|
|
||||||
}
|
|
||||||
|
|
||||||
faces = {
|
|
||||||
BlockFace.DOWN : 0,
|
|
||||||
BlockFace.UP : 1,
|
|
||||||
BlockFace.NORTH : 2,
|
|
||||||
BlockFace.SOUTH : 3,
|
|
||||||
BlockFace.WEST : 4,
|
|
||||||
BlockFace.EAST : 5
|
|
||||||
}
|
|
||||||
|
|
||||||
playerSettings = open_json_file("blockplacemods", {})
|
|
||||||
|
|
||||||
for setting, details in settingInformation.iteritems():
|
|
||||||
if playerSettings.get(setting) == None:
|
|
||||||
playerSettings[setting] = defaults[details[0]]()
|
|
||||||
|
|
||||||
def get(setting):
|
|
||||||
return playerSettings[setting]
|
|
||||||
|
|
||||||
def saveSettings():
|
|
||||||
save_json_file("blockplacemods", playerSettings)
|
|
||||||
|
|
||||||
def getSettingDetails(arg):
|
|
||||||
try:
|
|
||||||
arg = arg.lower()
|
|
||||||
for setting, details in settingInformation.iteritems():
|
|
||||||
if setting == arg or arg in details[3]:
|
|
||||||
return (setting, details)
|
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
raise CommandException(" &cThat setting could not be found.\n For command help, use &o/toggle &cor &o/set")
|
|
||||||
|
|
||||||
@simplecommand("toggle",
|
|
||||||
aliases = ["setting", "set", "config"],
|
|
||||||
usage = "<setting> [value|info]",
|
|
||||||
description = "Toggles or sets your preferences for our redstone \nutilities. The following settings are available:\n" + ", ".join([x for x in settingInformation]),
|
|
||||||
senderLimit = 0,
|
|
||||||
helpNoargs = True,
|
|
||||||
helpSubcmd = True,
|
|
||||||
amax = 2)
|
|
||||||
def toggle_command(sender, command, label, args):
|
|
||||||
setting, details = getSettingDetails(args[0])
|
|
||||||
Validate.isAuthorized(sender, "utils.toggle." + setting, "that setting")
|
|
||||||
|
|
||||||
values = get(setting)
|
|
||||||
player = server.getPlayer(sender.getName())
|
|
||||||
uuid = uid(player)
|
|
||||||
arglen = len(args)
|
|
||||||
|
|
||||||
if details[0] in (0,2): # Toggle
|
|
||||||
default = details[0] == 0 # If True: toggle on if list doesn't contain the uuid
|
|
||||||
|
|
||||||
enabled = (uuid not in values) == default #Invert if details[0] == 2 (toggle disabled by default)
|
|
||||||
new = None
|
|
||||||
if arglen == 1:
|
|
||||||
new = not enabled
|
|
||||||
else:
|
|
||||||
arg2 = args[1].lower()
|
|
||||||
if arg2 == "info":
|
|
||||||
return " &aSetting %s:\n &9%s\n &6Accepted arguments: [on|enable|off|disable|toggle|switch|info]\n &6Aliases: %s" % (setting, details[2], ", ".join(details[3]))
|
|
||||||
elif arg2 in ("toggle", "switch"):
|
|
||||||
new = not enabled
|
|
||||||
elif arg2 in ("on", "enable"):
|
|
||||||
new = not default
|
|
||||||
elif arg2 in ("off", "disable"):
|
|
||||||
new = default
|
|
||||||
else:
|
|
||||||
return " &cArgument '%s' was not recognized. \n Use &o/toggle %s info &cfor more information" % (arg2, setting)
|
|
||||||
if enabled == new:
|
|
||||||
return " &cAlready %s: &a%s" % ("enabled" if enabled else "disabled", details[1])
|
|
||||||
if new == default:
|
|
||||||
values.remove(uuid)
|
|
||||||
else:
|
|
||||||
values.append(uuid)
|
|
||||||
saveSettings()
|
|
||||||
return (" &aEnabled " if new else " &aDisabled ") + details[1]
|
|
||||||
|
|
||||||
|
|
||||||
elif details[0] == 1: # Save ItemStack in hand
|
|
||||||
arg2 = args[1].lower() if arglen > 1 else ""
|
|
||||||
enabled = uuid in values
|
|
||||||
|
|
||||||
if arg2 == "clear":
|
|
||||||
if enabled:
|
|
||||||
del values[uuid]
|
|
||||||
return " &aDisabled " + details[1]
|
|
||||||
|
|
||||||
if arg2 == "details":
|
|
||||||
return " &aSetting %s:\n &9%s \n&6Accepted arguments: [<slot>|clear|details]" % (setting, details[2])
|
|
||||||
|
|
||||||
slot = int(arg2) if arg2.isdigit() else 0
|
|
||||||
if not (0 <= slot <= details[4]):
|
|
||||||
return " &cSlot number must be more than or equal to 0 and less than or equal to %s!" % details[4]
|
|
||||||
|
|
||||||
item = fromStack(player.getItemInHand())
|
|
||||||
if item[0] == 0 or item[1] <= 0:
|
|
||||||
if enabled:
|
|
||||||
items = values[uuid]
|
|
||||||
if slot in items:
|
|
||||||
del items[slot]
|
|
||||||
saveSettings()
|
|
||||||
if len(items) == 0:
|
|
||||||
del items
|
|
||||||
return " &aDisabled " + details[1]
|
|
||||||
return " &aCleared slot %s of setting %s" % (slot, setting)
|
|
||||||
return " &cSlot %s of setting %s was already cleared!" % (slot, setting)
|
|
||||||
return " &cAlready disabled: " + details[1]
|
|
||||||
|
|
||||||
if arglen == 2 and not arg2.isdigit():
|
|
||||||
return " &cArgument '%s' was not recognized. \nUse &o/toggle %s details &cfor more detailsrmation." % (arg2, setting)
|
|
||||||
|
|
||||||
if not enabled:
|
|
||||||
values[uuid] = {}
|
|
||||||
values[uuid][slot] = item
|
|
||||||
saveSettings()
|
|
||||||
return ((" &aEnabled setting %s, S" % setting) if len(values[uuid]) == 1 else " &aS") + "et itemstack in slot %s to item in hand" % (slot)
|
|
||||||
|
|
||||||
return None #This shouldn't happen
|
|
||||||
|
|
||||||
|
|
||||||
def fromStack(itemStack):
|
|
||||||
return [itemStack.getTypeId(), itemStack.getAmount(), itemStack.getData().getData()]
|
|
||||||
def toStack(lst):
|
|
||||||
return ItemStack(lst[0], lst[1], lst[2])
|
|
||||||
|
|
||||||
def isEnabled(toggleSetting, uuid):
|
|
||||||
return (uuid not in get(toggleSetting)) == (settingInformation[toggleSetting][0] == 0) #Invert if off by default
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("block.BlockPlaceEvent", "monitor")
|
|
||||||
def on_block_place(event):
|
|
||||||
if event.isCancelled():
|
|
||||||
return
|
|
||||||
player = event.getPlayer()
|
|
||||||
if not is_creative(player):
|
|
||||||
return
|
|
||||||
|
|
||||||
uuid = uid(player)
|
|
||||||
block = event.getBlockPlaced()
|
|
||||||
material = block.getType()
|
|
||||||
|
|
||||||
|
|
||||||
if (material in (Material.WOOD_STEP, Material.STEP)
|
|
||||||
and isEnabled("slab", uuid)
|
|
||||||
and player.hasPermission("utils.toggle.slab")
|
|
||||||
and block.getData() < 8
|
|
||||||
):
|
|
||||||
block.setData(block.getData() + 8) # Flip upside down
|
|
||||||
|
|
||||||
|
|
||||||
elif (material == Material.CAULDRON
|
|
||||||
and isEnabled("cauldron", uuid)
|
|
||||||
and player.hasPermission("utils.toggle.cauldron")
|
|
||||||
):
|
|
||||||
block.setData(3) #3 layers of water, 3 signal strength
|
|
||||||
|
|
||||||
|
|
||||||
elif ((material == Material.FURNACE and player.hasPermission("utils.toggle.furnace"))
|
|
||||||
or (material == Material.DROPPER and player.hasPermission("utils.toggle.dropper"))
|
|
||||||
or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper"))
|
|
||||||
):
|
|
||||||
stacks = get(str(material).lower()).get(uuid)
|
|
||||||
if stacks != None: # Enabled
|
|
||||||
state = block.getState()
|
|
||||||
inv = state.getInventory()
|
|
||||||
for slot, stack in stacks.iteritems():
|
|
||||||
inv.setItem(int(slot), toStack(stack))
|
|
||||||
state.update()
|
|
||||||
|
|
||||||
"""
|
|
||||||
elif (material == Material.REDSTONE_TORCH_ON
|
|
||||||
and event.getBlockAgainst().getType() == Material.REDSTONE_BLOCK
|
|
||||||
and isEnabled("torch", uuid)
|
|
||||||
and player.hasPermission("utils.toggle.torch")
|
|
||||||
):
|
|
||||||
torches_to_break.append(block)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
if (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE)
|
|
||||||
and isEnabled("piston", uuid)
|
|
||||||
and player.hasPermission("utils.toggle.piston")
|
|
||||||
):
|
|
||||||
block.setData(faces[block.getFace(event.getBlockAgainst())])
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerInteractEvent", "monitor")
|
|
||||||
def on_interact(event):
|
|
||||||
player = event.getPlayer()
|
|
||||||
if (isEnabled("cauldron", uid(player))
|
|
||||||
and player.hasPermission("utils.toggle.cauldron")
|
|
||||||
and is_creative(player)
|
|
||||||
and event.getAction() == Action.RIGHT_CLICK_BLOCK
|
|
||||||
and (not event.hasItem() or event.getItem().getType() == Material.REDSTONE)
|
|
||||||
and event.getClickedBlock().getType() == Material.CAULDRON
|
|
||||||
):
|
|
||||||
block = event.getClickedBlock()
|
|
||||||
event2 = BlockBreakEvent(block, player)
|
|
||||||
server.getPluginManager().callEvent(event2)
|
|
||||||
if not event2.isCancelled():
|
|
||||||
block.setData(block.getData() - 1 if block.getData() > 0 else 3)
|
|
||||||
|
|
||||||
"""
|
|
||||||
break_torches = True
|
|
||||||
torches_to_break = deque()
|
|
||||||
|
|
||||||
def stop_breaking_torches():
|
|
||||||
break_torches = False
|
|
||||||
info("Interrupted torch breaking thread")
|
|
||||||
|
|
||||||
|
|
||||||
class torch_breaker(Runnable):
|
|
||||||
|
|
||||||
def run():
|
|
||||||
|
|
||||||
try:
|
|
||||||
if break_torches:
|
|
||||||
for i in range(len(torches_to_break)):
|
|
||||||
block = torches_to_break.popleft()
|
|
||||||
mat = block.getType()
|
|
||||||
if mat == Material.REDSTONE_TORCH_OFF:
|
|
||||||
block.setTypeId(0)
|
|
||||||
elif mat == Material.REDSTONE_TORCH_ON:
|
|
||||||
torches_to_break.append(block)
|
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
"""
|
|
||||||
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
|
|
||||||
calc_users = open_json_file("calc", [])
|
|
||||||
math_operators = ["+", "-", "*", "/", "&", "|"]
|
|
||||||
ignore_operators = ["**", "&&", "||"] # ** may be too intensive, the others cause syntax errors
|
|
||||||
calc_perm = "utils.calc"
|
|
||||||
|
|
||||||
|
|
||||||
def calc(text):
|
|
||||||
"""
|
|
||||||
extracts a mathematical expression from `text`
|
|
||||||
returns (expression, result) or None
|
|
||||||
"""
|
|
||||||
expression = ""
|
|
||||||
should_calc = False
|
|
||||||
for char in text:
|
|
||||||
if char.isdigit() or (expression and char == ".") or (should_calc and char == " "):
|
|
||||||
expression += char
|
|
||||||
elif char in math_operators:
|
|
||||||
# calculation must include at least 1 operator
|
|
||||||
should_calc = True
|
|
||||||
expression += char
|
|
||||||
elif should_calc and char.isalpha():
|
|
||||||
# don't include any more text in the calculation
|
|
||||||
break
|
|
||||||
if should_calc and not any(op in expression for op in ignore_operators):
|
|
||||||
try:
|
|
||||||
result = str(eval(expression)) # pylint: disable = W0123
|
|
||||||
except: # pylint: disable = W0702
|
|
||||||
# we can run into all kinds of errors here
|
|
||||||
# most probably SyntaxError
|
|
||||||
return None
|
|
||||||
return (expression, result)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "monitor")
|
|
||||||
def on_calc_chat(event):
|
|
||||||
sender = event.getPlayer()
|
|
||||||
message = event.getMessage()
|
|
||||||
if not event.isCancelled() and uid(sender) in calc_users and sender.hasPermission(calc_perm):
|
|
||||||
output = calc(message)
|
|
||||||
if output:
|
|
||||||
msg(sender, "&2=== Calc: &e" + output[0] + " &2= &c" + output[1])
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("calc", description="Toggles chat calculations")
|
|
||||||
def on_calc_command(sender, command, label, args):
|
|
||||||
plugin_header(sender, "Chat Calculator")
|
|
||||||
if not sender.hasPermission(calc_perm):
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
if not checkargs(sender, args, 0, 1):
|
|
||||||
return True
|
|
||||||
if not is_player(sender):
|
|
||||||
msg(sender, "&cYou are not a player!")
|
|
||||||
return True
|
|
||||||
|
|
||||||
toggle(sender, calc_users, name = "Calc")
|
|
||||||
save_json_file("calc", calc_users)
|
|
||||||
|
|
||||||
return True
|
|
||||||
+12
-39
@@ -1,21 +1,15 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from basecommands import simplecommand
|
|
||||||
from java.util.UUID import fromString as juuid
|
from java.util.UUID import fromString as juuid
|
||||||
from traceback import format_exc as trace
|
|
||||||
|
|
||||||
groups = open_json_file("chatgroups", {})
|
groups = open_json_file("chatgroups", {})
|
||||||
cg_defaultkey = ":"
|
cg_key = ":"
|
||||||
cg_keys = open_json_file("chatgroup_keys", {})
|
|
||||||
cg_toggle_list = []
|
cg_toggle_list = []
|
||||||
|
|
||||||
def get_key(uuid):
|
|
||||||
key = cg_keys.get(uuid)
|
|
||||||
return key if key != None else cg_defaultkey
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("chatgroup")
|
@hook.command("chatgroup")
|
||||||
def on_chatgroup_command(sender, command, label, args):
|
def on_chatgroup_command(sender, args):
|
||||||
plugin_header(sender, "ChatGroups")
|
plugin_header(sender, "ChatGroups")
|
||||||
sender_id = uid(sender)
|
sender_id = uid(sender)
|
||||||
if len(args) == 1 and args[0] == "leave":
|
if len(args) == 1 and args[0] == "leave":
|
||||||
@@ -30,7 +24,12 @@ def on_chatgroup_command(sender, command, label, args):
|
|||||||
if sender_id in groups.keys():
|
if sender_id in groups.keys():
|
||||||
group = groups[sender_id]
|
group = groups[sender_id]
|
||||||
msg(sender, "&aCurrent chatgroup: %s" % group)
|
msg(sender, "&aCurrent chatgroup: %s" % group)
|
||||||
users = [user.getDisplayName() for user in [server.getPlayer(juuid(uuid)) for uuid, ugroup in groups.iteritems() if ugroup == group] if user]
|
users = []
|
||||||
|
for uuid, ugroup in groups.iteritems():
|
||||||
|
if ugroup == group:
|
||||||
|
usr = server.getPlayer(juuid(uuid))
|
||||||
|
if usr:
|
||||||
|
users.append(usr.getDisplayName())
|
||||||
msg(sender, "&aUsers in this group:")
|
msg(sender, "&aUsers in this group:")
|
||||||
msg(sender, "&a%s" % ", ".join(users))
|
msg(sender, "&a%s" % ", ".join(users))
|
||||||
else:
|
else:
|
||||||
@@ -40,18 +39,15 @@ def on_chatgroup_command(sender, command, label, args):
|
|||||||
groupchat(sender, "joined the group", True)
|
groupchat(sender, "joined the group", True)
|
||||||
save_groups()
|
save_groups()
|
||||||
msg(sender, "&aYour chatgroup is set to '%s'" % args[1])
|
msg(sender, "&aYour chatgroup is set to '%s'" % args[1])
|
||||||
msg(sender, "&aUse chat like '&e%s<message>' to send messages to this group." % get_key(sender_id))
|
msg(sender, "&aUse chat like '&e%s<message>' to send messages to this group." % cg_key)
|
||||||
elif len(args) == 1 and args[0] == "key":
|
|
||||||
msg(sender, "&aYour chatgroup key is currently: '&c%s&a'" % get_key(sender_id))
|
|
||||||
else:
|
else:
|
||||||
msg(sender, "&e/chatgroup join <name>")
|
msg(sender, "&e/chatgroup join <name>")
|
||||||
msg(sender, "&e/chatgroup leave")
|
msg(sender, "&e/chatgroup leave")
|
||||||
msg(sender, "&e/chatgroup info")
|
msg(sender, "&e/chatgroup info")
|
||||||
msg(sender, "&e/chatgroup key")
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("cgt")
|
@hook.command("cgt")
|
||||||
def on_cgt_command(sender, command, label, args):
|
def on_cgt_command(sender, args):
|
||||||
p = uid(sender)
|
p = uid(sender)
|
||||||
if p in cg_toggle_list:
|
if p in cg_toggle_list:
|
||||||
cg_toggle_list.remove(p)
|
cg_toggle_list.remove(p)
|
||||||
@@ -88,32 +84,9 @@ def on_chat(event):
|
|||||||
msge = event.getMessage()
|
msge = event.getMessage()
|
||||||
if not event.isCancelled():
|
if not event.isCancelled():
|
||||||
sender_id = uid(sender)
|
sender_id = uid(sender)
|
||||||
key = get_key(sender_id)
|
if msge[:len(cg_key)] == cg_key and sender_id in groups.keys():
|
||||||
keylen = len(key)
|
groupchat(sender, msge[1:])
|
||||||
if msge[:keylen] == key and sender_id in groups.keys():
|
|
||||||
groupchat(sender, msge[keylen:])
|
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
elif sender_id in cg_toggle_list:
|
elif sender_id in cg_toggle_list:
|
||||||
groupchat(sender, msge)
|
groupchat(sender, msge)
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
|
|
||||||
@simplecommand("chatgroupkey",
|
|
||||||
aliases = ["cgkey"],
|
|
||||||
senderLimit = 0,
|
|
||||||
helpNoargs = True,
|
|
||||||
helpSubcmd = True,
|
|
||||||
description = "Sets a key character for chatting to your chatgroup",
|
|
||||||
usage = "<key>")
|
|
||||||
def chatgroupkey_command(sender, command, label, args):
|
|
||||||
key = " ".join(args)
|
|
||||||
uuid = uid(sender)
|
|
||||||
if key.lower() == "default" or key == cg_defaultkey:
|
|
||||||
del cg_keys[uuid]
|
|
||||||
save_keys()
|
|
||||||
return "&aYour chatgroup key was set to the default character: '&c%s&a'" % cg_defaultkey
|
|
||||||
cg_keys[uid(sender)] = key
|
|
||||||
save_keys()
|
|
||||||
return "&aYour chatgroup key was set to: '&c%s&a'" % key
|
|
||||||
|
|
||||||
def save_keys():
|
|
||||||
save_json_file("chatgroup_keys", cg_keys)
|
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
import json
|
|
||||||
import urllib2
|
|
||||||
import datetime
|
|
||||||
import mysqlhack #pylint: disable = unused-import
|
|
||||||
from traceback import format_exc as print_traceback
|
|
||||||
from com.ziclix.python.sql import zxJDBC
|
|
||||||
from secrets import *
|
|
||||||
from helpers import *
|
|
||||||
|
|
||||||
|
|
||||||
# receive info based on the user's IP. information provided by ipinfo.io
|
|
||||||
def ip_info(player):
|
|
||||||
if player.isOnline():
|
|
||||||
return json.load(urllib2.urlopen("http://ipinfo.io%s/json" % str(player.getAddress().getAddress())))
|
|
||||||
else:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
# receive first join date based on the player data (may not be accurate)
|
|
||||||
def get_first_join(player):
|
|
||||||
first_join = int(player.getFirstPlayed())
|
|
||||||
dt = datetime.datetime.fromtimestamp(first_join/1000.0)
|
|
||||||
return dt.strftime("%Y-%m-%d %H:%M")
|
|
||||||
|
|
||||||
|
|
||||||
# receive last seen date based on the player data
|
|
||||||
def get_last_seen(player):
|
|
||||||
last_seen = int(player.getLastPlayed())
|
|
||||||
dt = datetime.datetime.fromtimestamp(last_seen/1000.0)
|
|
||||||
return dt.strftime("%Y-%m-%d %H:%M")
|
|
||||||
|
|
||||||
|
|
||||||
# receive link and email from website
|
|
||||||
def get_website_data(player):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
uuid = str(uid(player)).replace("-", "")
|
|
||||||
curs.execute("SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,))
|
|
||||||
results = curs.fetchall()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
return ("http://redstoner.com/users/%s" % results[0][0], results[0][1]) if results else (None, None)
|
|
||||||
|
|
||||||
|
|
||||||
# receive country based on the user's IP
|
|
||||||
def get_country(data):
|
|
||||||
return str(data.get("country"))
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_names(player):
|
|
||||||
uuid = str(uid(player)).replace("-", "")
|
|
||||||
names = json.load(urllib2.urlopen("https://api.mojang.com/user/profiles/%s/names" % uuid))
|
|
||||||
# [ {"name": "some_name"}, {"name": "other_name"} ]
|
|
||||||
return ", ".join([name["name"] for name in names])
|
|
||||||
|
|
||||||
|
|
||||||
# combines data
|
|
||||||
def get_all_data(sender, player):
|
|
||||||
data = ip_info(player)
|
|
||||||
|
|
||||||
msg(sender, "")
|
|
||||||
|
|
||||||
try:
|
|
||||||
msg(sender, "&7 -- Data provided by Redstoner")
|
|
||||||
msg(sender, "&6> UUID: &e%s" % str(uid(player)))
|
|
||||||
msg(sender, "&6> First joined: &7(y-m-d h:m:s) &e%s" % get_first_join(player))
|
|
||||||
msg(sender, "&6> Last seen: &7(y-m-d h:m:s) &e%s" % get_last_seen(player))
|
|
||||||
website = get_website_data(player)
|
|
||||||
msg(sender, "&6> Website account: &e%s" % website[0])
|
|
||||||
msg(sender, "&6> email: &e%s" % website[1])
|
|
||||||
msg(sender, "&7 -- Data provided by ipinfo.io")
|
|
||||||
msg(sender, "&6> Country: &e%s" % get_country(data))
|
|
||||||
msg(sender, "&7 -- Data provided by Mojang")
|
|
||||||
msg(sender, "&6> All ingame names used so far: &e%s" % get_all_names(player))
|
|
||||||
except:
|
|
||||||
# can throw exceptions such as timeouts when Mojang API is down
|
|
||||||
warn(print_traceback())
|
|
||||||
msg(sender, "&cSorry, something went wrong while fetching data")
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("check", description="Displays useful stuff about a user", usage="/check <player>")
|
|
||||||
def on_hook_command(sender, command, label, args):
|
|
||||||
if sender.hasPermission("utils.check"):
|
|
||||||
if not checkargs(sender, args, 1, 1):
|
|
||||||
return True
|
|
||||||
plugin_header(sender, "Check")
|
|
||||||
msg(sender, "&7Please notice that the data may not be fully accurate!")
|
|
||||||
player = server.getOfflinePlayer(args[0]) if len(args) > 0 else None
|
|
||||||
get_all_data(sender, player)
|
|
||||||
else:
|
|
||||||
msg(sender, "&4You don't have the required permissions to execute this command!")
|
|
||||||
return True
|
|
||||||
@@ -4,7 +4,7 @@ no_cyclers = open_json_file("cycle", [])
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("cycle")
|
@hook.command("cycle")
|
||||||
def on_cycler_command(sender, command, label, args):
|
def on_cycler_command(sender, args):
|
||||||
plugin_header(sender, "Cycle")
|
plugin_header(sender, "Cycle")
|
||||||
if not is_player(sender):
|
if not is_player(sender):
|
||||||
msg(sender, "&conly players can do this")
|
msg(sender, "&conly players can do this")
|
||||||
|
|||||||
+20
-48
@@ -5,8 +5,6 @@ import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
|||||||
|
|
||||||
inputs = open_json_file("damnspam", {}) # format "x;y;z;World"
|
inputs = open_json_file("damnspam", {}) # format "x;y;z;World"
|
||||||
accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"]
|
accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"]
|
||||||
changing_input = False
|
|
||||||
removing_input = False
|
|
||||||
|
|
||||||
|
|
||||||
def save_inputs():
|
def save_inputs():
|
||||||
@@ -27,15 +25,10 @@ def add_input(creator, block, timeout_off, timeout_on):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("damnspam")
|
@hook.command("damnspam")
|
||||||
def on_dammnspam_command(sender, command, label, args):
|
def on_dammnspam_command(sender, args):
|
||||||
global changing_input
|
|
||||||
|
|
||||||
plugin_header(sender, "DamnSpam")
|
plugin_header(sender, "DamnSpam")
|
||||||
if not checkargs(sender, args, 1, 2):
|
if len(args) in [1,2]:
|
||||||
msg(sender, "&c/damnspam <seconds> &e(Buttons/Levers)")
|
|
||||||
msg(sender, "&c/damnspam <seconds after off> <seconds after on> &e(Levers only)")
|
|
||||||
return True
|
|
||||||
#Gittestlol
|
|
||||||
if not is_creative(sender):
|
if not is_creative(sender):
|
||||||
msg(sender, "&cYou can only do this in Creative mode.")
|
msg(sender, "&cYou can only do this in Creative mode.")
|
||||||
return True
|
return True
|
||||||
@@ -46,10 +39,8 @@ def on_dammnspam_command(sender, command, label, args):
|
|||||||
try:
|
try:
|
||||||
timeout_on = round(float(timeout_on), 2)
|
timeout_on = round(float(timeout_on), 2)
|
||||||
timeout_off = timeout_on
|
timeout_off = timeout_on
|
||||||
if 60 >= timeout_on <= -2 or timeout_on == 0:
|
if not 0 <= timeout_on <= 60:
|
||||||
timeout_on = False
|
msg(sender, "&cThe timeout must be within 0-60.")
|
||||||
if timeout_on == False:
|
|
||||||
msg(sender, "&cThe timeout must be within 0-60 or -1.")
|
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
msg(sender, "&cThe timeout must be a number")
|
msg(sender, "&cThe timeout must be a number")
|
||||||
@@ -62,12 +53,8 @@ def on_dammnspam_command(sender, command, label, args):
|
|||||||
try:
|
try:
|
||||||
timeout_on = round(float(timeout_on), 2)
|
timeout_on = round(float(timeout_on), 2)
|
||||||
timeout_off = round(float(timeout_off), 2)
|
timeout_off = round(float(timeout_off), 2)
|
||||||
if 60 >= timeout_on <= -2 or timeout_on == 0:
|
if not 0 <= timeout_on <= 60 or not 0 <= timeout_off <= 60:
|
||||||
timeout_on = False
|
msg(sender, "&cThe timeout must be within 0-60.")
|
||||||
if 60 >= timeout_off <= -2 or timeout_off == 0:
|
|
||||||
timeout_off = False
|
|
||||||
if timeout_on == False or timeout_off == False:
|
|
||||||
msg(sender, "&cThe timeout must be within 0-60 or -1.")
|
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
msg(sender, "&cThe timeout must be a number")
|
msg(sender, "&cThe timeout must be a number")
|
||||||
@@ -80,52 +67,39 @@ def on_dammnspam_command(sender, command, label, args):
|
|||||||
msg(sender, "&cPlease look at a button or lever while executing this command!")
|
msg(sender, "&cPlease look at a button or lever while executing this command!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if location_str(target) in inputs:
|
|
||||||
changing_input = True # this input already has a timeout
|
|
||||||
# test if player is allowed to build here
|
|
||||||
test_event = BlockBreakEvent(target, sender)
|
test_event = BlockBreakEvent(target, sender)
|
||||||
server.getPluginManager().callEvent(test_event)
|
server.getPluginManager().callEvent(test_event)
|
||||||
changing_input = False
|
|
||||||
if test_event.isCancelled():
|
if test_event.isCancelled():
|
||||||
msg(sender, "&cYou are not allowed to modify this %s" % str(target.getType()).lower())
|
msg(sender, "&cYou are not allowed to modify this button")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# add block to inputs
|
# add block to inputs
|
||||||
add_input(sender, target, timeout_off, timeout_on)
|
add_input(sender, target, timeout_off, timeout_on)
|
||||||
save_inputs()
|
save_inputs()
|
||||||
msg(sender, "&aSuccessfully set a timeout for this %s." % ttype.lower().replace("_", " "))
|
msg(sender, "&aSuccessfully set a timeout for this %s." % ttype.lower())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
else:
|
||||||
|
msg(sender, "&c/damnspam <seconds> &e(Buttons/Levers)")
|
||||||
|
msg(sender, "&c/damnspam <seconds after off> <seconds after on> &e(Levers only)")
|
||||||
|
|
||||||
|
|
||||||
@hook.event("block.BlockBreakEvent", "normal")
|
@hook.event("block.BlockBreakEvent", "normal")
|
||||||
def on_block_break(event):
|
def on_block_break(event):
|
||||||
global removing_input
|
|
||||||
|
|
||||||
if removing_input:
|
|
||||||
return
|
|
||||||
sender = event.getPlayer()
|
sender = event.getPlayer()
|
||||||
block = event.getBlock()
|
block = event.getBlock()
|
||||||
btype = str(block.getType()).lower()
|
|
||||||
if str(block.getType()) in accepted_inputs and not event.isCancelled():
|
if str(block.getType()) in accepted_inputs and not event.isCancelled():
|
||||||
pos_str = location_str(block)
|
pos_str = location_str(block)
|
||||||
if inputs.get(pos_str):
|
if inputs.get(pos_str):
|
||||||
|
plugin_header(sender, "DamnSpam")
|
||||||
if sender.isSneaking():
|
if sender.isSneaking():
|
||||||
# test if player is allowed to build here
|
|
||||||
removing_input = True
|
|
||||||
test_event = BlockBreakEvent(block, sender)
|
|
||||||
server.getPluginManager().callEvent(test_event)
|
|
||||||
removing_input = False
|
|
||||||
if test_event.isCancelled():
|
|
||||||
event.setCancelled(True)
|
|
||||||
msg(sender, "&cYou are not allowed to remove this %s" % btype)
|
|
||||||
return True
|
|
||||||
inputs.pop(pos_str) # remove
|
inputs.pop(pos_str) # remove
|
||||||
save_inputs()
|
save_inputs()
|
||||||
msg(sender, "&eSuccessfully removed this %s!" % btype)
|
msg(sender, "&eSuccessfully removed the input!")
|
||||||
return True
|
return True
|
||||||
elif not changing_input:
|
else:
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
msg(sender, "&cYou cannot destroy this %s!" % btype)
|
msg(sender, "&cYou cannot destroy this input!")
|
||||||
msg(sender, "&c&nSneak&c and break if you want to remove it.")
|
msg(sender, "&c&nSneak&c and break if you want to remove it.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -141,11 +115,9 @@ def on_interact(event):
|
|||||||
data = inputs.get(pos_str)
|
data = inputs.get(pos_str)
|
||||||
if data:
|
if data:
|
||||||
checktime = data["timeout_on"] if powered else data["timeout_off"]
|
checktime = data["timeout_on"] if powered else data["timeout_off"]
|
||||||
if checktime == -1:
|
if data["last_time"] + checktime > now():
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
msg(sender, "&cThis %s is locked permanently by /damnspam." % (btype))
|
plugin_header(sender, "DamnSpam")
|
||||||
elif data["last_time"] + checktime > now():
|
msg(sender, "&cThis %s has a timeout of %ss." % (btype, checktime))
|
||||||
event.setCancelled(True)
|
|
||||||
msg(sender, "&cThis %s has a damnspam timeout of %ss." % (btype, checktime))
|
|
||||||
else:
|
else:
|
||||||
inputs[pos_str]["last_time"] = round(now(), 2)
|
inputs[pos_str]["last_time"] = round(now(), 2)
|
||||||
+2
-6
@@ -1,5 +1,4 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
import thread
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from org.bukkit.util import Vector
|
from org.bukkit.util import Vector
|
||||||
from math import sin
|
from math import sin
|
||||||
@@ -17,7 +16,7 @@ whitelists = {} # {ff_owner_id: [white, listed, ids]} (Adding file usage later,
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("forcefield")
|
@hook.command("forcefield")
|
||||||
def on_forcefield_command(sender, command, label, args):
|
def on_forcefield_command(sender, args):
|
||||||
if not is_player(sender) or not sender.hasPermission(ff_perm):
|
if not is_player(sender) or not sender.hasPermission(ff_perm):
|
||||||
noperm(sender)
|
noperm(sender)
|
||||||
return True
|
return True
|
||||||
@@ -29,7 +28,7 @@ def on_forcefield_command(sender, command, label, args):
|
|||||||
args[0] = args[0].upper() # If it gets to this point, there are argument(s).
|
args[0] = args[0].upper() # If it gets to this point, there are argument(s).
|
||||||
if args[0] in ["WHITELIST", "WL", "WLIST"]: # Whitelist commands
|
if args[0] in ["WHITELIST", "WL", "WLIST"]: # Whitelist commands
|
||||||
if not args[1:] or args[1].upper() == "LIST":
|
if not args[1:] or args[1].upper() == "LIST":
|
||||||
thread.start_new_thread(whitelist_list, (sender,))
|
whitelist_list(sender)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
args[1] = args[1].upper() # If it gets too this point, there is a second argument.
|
args[1] = args[1].upper() # If it gets too this point, there is a second argument.
|
||||||
@@ -89,7 +88,6 @@ def change_whitelist(sender, add, names): #Add names if add == True else Remove
|
|||||||
|
|
||||||
|
|
||||||
def whitelist_list(player):
|
def whitelist_list(player):
|
||||||
try:
|
|
||||||
player_id = uid(player)
|
player_id = uid(player)
|
||||||
count = 0
|
count = 0
|
||||||
forcefield_header(player, "&bForcefield whitelist:")
|
forcefield_header(player, "&bForcefield whitelist:")
|
||||||
@@ -99,8 +97,6 @@ def whitelist_list(player):
|
|||||||
msg(player, "&b %s. &f%s" % (count, pname))
|
msg(player, "&b %s. &f%s" % (count, pname))
|
||||||
if count == 0:
|
if count == 0:
|
||||||
msg(player, "&c Your whitelist has no entries.")
|
msg(player, "&c Your whitelist has no entries.")
|
||||||
except:
|
|
||||||
warn("Unable to finish whitelist_list process")
|
|
||||||
|
|
||||||
|
|
||||||
def whitelist_clear(player):
|
def whitelist_clear(player):
|
||||||
|
|||||||
+4
-6
@@ -1,4 +1,3 @@
|
|||||||
import thread
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
friends = open_json_file("friends", {}) # {Player_UUID:[List_of_friend_uuids]}
|
friends = open_json_file("friends", {}) # {Player_UUID:[List_of_friend_uuids]}
|
||||||
@@ -26,7 +25,6 @@ def friendmessage(player, message): # sends a message with a prefix
|
|||||||
|
|
||||||
|
|
||||||
def ls(sender):
|
def ls(sender):
|
||||||
try:
|
|
||||||
sender_friends = friends.get(uid(sender), False)
|
sender_friends = friends.get(uid(sender), False)
|
||||||
if sender_friends:
|
if sender_friends:
|
||||||
friends_string = ""
|
friends_string = ""
|
||||||
@@ -35,14 +33,14 @@ def ls(sender):
|
|||||||
friendmessage(sender, "&aYour friends list: " + friends_string[:len(friends_string)-2])
|
friendmessage(sender, "&aYour friends list: " + friends_string[:len(friends_string)-2])
|
||||||
else:
|
else:
|
||||||
friendmessage(sender, "&cYour friends list is empty")
|
friendmessage(sender, "&cYour friends list is empty")
|
||||||
except:
|
|
||||||
warn("Unable to finish friends' ls process")
|
|
||||||
|
|
||||||
|
|
||||||
def clear(sender):
|
def clear(sender):
|
||||||
sender_id = uid(sender)
|
sender_id = uid(sender)
|
||||||
|
|
||||||
if friends.get(sender_id, False):
|
if friends.get(sender_id, False):
|
||||||
|
for uuid in friends[sender_id]:
|
||||||
|
friendmessage(retrieve_player(uuid), "&c&o%s &cremoved you from their friends list" % stripcolors(sender.getDisplayName()))
|
||||||
friends.pop(sender_id)
|
friends.pop(sender_id)
|
||||||
friendmessage(sender, "&aFriends list cleared")
|
friendmessage(sender, "&aFriends list cleared")
|
||||||
save_friends()
|
save_friends()
|
||||||
@@ -125,7 +123,7 @@ def fhelp(sender):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("friends")
|
@hook.command("friends")
|
||||||
def on_friend_command(sender, command, label, args):
|
def on_friend_command(sender, args):
|
||||||
if not is_player(sender):
|
if not is_player(sender):
|
||||||
friendmessage(sender, "&c&lYou can't have friends!")
|
friendmessage(sender, "&c&lYou can't have friends!")
|
||||||
return True
|
return True
|
||||||
@@ -135,7 +133,7 @@ def on_friend_command(sender, command, label, args):
|
|||||||
|
|
||||||
# /friends list
|
# /friends list
|
||||||
if cmd in ["list", "lst", "*"]:
|
if cmd in ["list", "lst", "*"]:
|
||||||
thread.start_new_thread(ls, (sender,))
|
ls(sender)
|
||||||
|
|
||||||
# /friends clear
|
# /friends clear
|
||||||
elif cmd in ["clear", "/"]:
|
elif cmd in ["clear", "/"]:
|
||||||
|
|||||||
+36
-45
@@ -7,13 +7,6 @@ import org.bukkit.Location as Location
|
|||||||
import org.bukkit.entity.Player as Player
|
import org.bukkit.entity.Player as Player
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause
|
||||||
import org.bukkit.block as bblock
|
import org.bukkit.block as bblock
|
||||||
import org.bukkit.event.entity as entity
|
|
||||||
import org.bukkit.command.ConsoleCommandSender
|
|
||||||
from org.bukkit.entity import *
|
|
||||||
from player import get_py_player
|
|
||||||
from player import py_players
|
|
||||||
|
|
||||||
from traceback import format_exc as trace
|
|
||||||
|
|
||||||
|
|
||||||
shared = {} # this dict can be used to share stuff across modules
|
shared = {} # this dict can be used to share stuff across modules
|
||||||
@@ -22,32 +15,17 @@ server = bukkit.Bukkit.getServer()
|
|||||||
|
|
||||||
|
|
||||||
def info(text):
|
def info(text):
|
||||||
"""
|
|
||||||
Log info to console
|
|
||||||
"""
|
|
||||||
server.getLogger().info("[RedstonerUtils] %s" % text)
|
server.getLogger().info("[RedstonerUtils] %s" % text)
|
||||||
|
|
||||||
|
|
||||||
def warn(text):
|
def warn(text):
|
||||||
"""
|
|
||||||
Log warning to console
|
|
||||||
"""
|
|
||||||
server.getLogger().warning("[RedstonerUtils] %s" % text)
|
server.getLogger().warning("[RedstonerUtils] %s" % text)
|
||||||
|
|
||||||
|
|
||||||
def error(text):
|
def error(text):
|
||||||
"""
|
|
||||||
Log error to console
|
|
||||||
"""
|
|
||||||
server.getLogger().severe("[RedstonerUtils] %s" % text)
|
server.getLogger().severe("[RedstonerUtils] %s" % text)
|
||||||
|
|
||||||
|
|
||||||
def fine(text):
|
|
||||||
"""
|
|
||||||
Log anything to the logs alone, not the console
|
|
||||||
"""
|
|
||||||
server.getLogger().fine(text)
|
|
||||||
|
|
||||||
def msg(player, text, usecolor = True, basecolor = None):
|
def msg(player, text, usecolor = True, basecolor = None):
|
||||||
"""
|
"""
|
||||||
send a message to player
|
send a message to player
|
||||||
@@ -55,7 +33,7 @@ def msg(player, text, usecolor = True, basecolor = None):
|
|||||||
unless usecolor is False, &-codes are translated to real color codes
|
unless usecolor is False, &-codes are translated to real color codes
|
||||||
for that case, basecolor can be useful. basecolor accepts a single character as color code
|
for that case, basecolor can be useful. basecolor accepts a single character as color code
|
||||||
"""
|
"""
|
||||||
if player and (player == server.getConsoleSender() or player.isOnline()): # getPlayer() returns None when offline
|
if player and (player == server.getConsoleSender() or player.getPlayer()): # getPlayer() returns None when offline
|
||||||
if basecolor:
|
if basecolor:
|
||||||
if usecolor:
|
if usecolor:
|
||||||
text = colorify(text)
|
text = colorify(text)
|
||||||
@@ -64,16 +42,15 @@ def msg(player, text, usecolor = True, basecolor = None):
|
|||||||
player.sendMessage(colorify(text) if usecolor else text)
|
player.sendMessage(colorify(text) if usecolor else text)
|
||||||
|
|
||||||
|
|
||||||
def broadcast(perm, text, usecolor = True):
|
def broadcast(perm, text):
|
||||||
"""
|
"""
|
||||||
better than bukkit's broadcast.
|
better than bukkit's broadcast.
|
||||||
bukkit only works with permissibles that are subscribed to perm
|
bukkit only works with permissibles that are subscribed to perm
|
||||||
"""
|
"""
|
||||||
if usecolor:
|
|
||||||
text = colorify(text)
|
text = colorify(text)
|
||||||
for recipient in list(server.getOnlinePlayers()) + [server.getConsoleSender()]:
|
for recipient in list(server.getOnlinePlayers()) + [server.getConsoleSender()]:
|
||||||
if not perm or recipient.hasPermission(perm):
|
if not perm or recipient.hasPermission(perm):
|
||||||
msg(recipient, text, usecolor = False)
|
msg(recipient, text)
|
||||||
|
|
||||||
|
|
||||||
def colorify(text):
|
def colorify(text):
|
||||||
@@ -113,20 +90,14 @@ def plugin_header(recipient = None, name="Redstoner Utils"):
|
|||||||
|
|
||||||
|
|
||||||
def noperm(player):
|
def noperm(player):
|
||||||
"""
|
|
||||||
Send the default permission failure message to the player
|
|
||||||
"""
|
|
||||||
msg(player, "&cno permission")
|
msg(player, "&cno permission")
|
||||||
|
|
||||||
|
|
||||||
def runas(player, cmd):
|
def runas(player, cmd):
|
||||||
"""
|
"""
|
||||||
run a command as player
|
run a command as player
|
||||||
the cmd should NOT be prefixed with a /
|
the cmd should no be prefixed with a /
|
||||||
"""
|
"""
|
||||||
if is_player(player):
|
|
||||||
player.chat("/" + cmd)
|
|
||||||
else:
|
|
||||||
server.dispatchCommand(player, cmd)
|
server.dispatchCommand(player, cmd)
|
||||||
|
|
||||||
|
|
||||||
@@ -158,6 +129,13 @@ def checkargs(sender, args, amin, amax):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def warp(player, args, warpname):
|
||||||
|
if not checkargs(player, args, 0, 1):
|
||||||
|
return False # You can check if it worked
|
||||||
|
runas(player, "warp %s" % warpname)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_creative(player):
|
def is_creative(player):
|
||||||
"""
|
"""
|
||||||
returns True if the player is in Creative mode
|
returns True if the player is in Creative mode
|
||||||
@@ -189,23 +167,24 @@ def known_player(player):
|
|||||||
return player.hasPlayedBefore()
|
return player.hasPlayedBefore()
|
||||||
|
|
||||||
|
|
||||||
def open_json_file(filename, default = None):
|
def open_json_file(filename, default):
|
||||||
"""
|
"""
|
||||||
opens the given json file and returns an object or returns None on error
|
opens the given json file and returns an object or returns None on error
|
||||||
filename is only the name of the file without .json appended.
|
filename is the path + name of the file.
|
||||||
"""
|
"""
|
||||||
|
data = None
|
||||||
try:
|
try:
|
||||||
with open("plugins/redstoner-utils.py.dir/files/%s.json" % filename) as obj:
|
with open("plugins/redstoner-utils.py.dir/files/%s.json" % filename) as obj:
|
||||||
default = json_loads(obj.read())
|
data = json_loads(obj.read())
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
error("Failed to read from %s: %s" % (filename, e))
|
error("Failed to read from %s: %s" % (filename, e))
|
||||||
return default
|
return (default if data is None else data)
|
||||||
|
|
||||||
|
|
||||||
def save_json_file(filename, obj):
|
def save_json_file(filename, obj):
|
||||||
"""
|
"""
|
||||||
saves the given object as json into filename
|
saves the given object as json into filename
|
||||||
filename is only the name of the file without .json appended.
|
filename is the path + name of the file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open("plugins/redstoner-utils.py.dir/files/%s.json" % filename, "w") as f:
|
with open("plugins/redstoner-utils.py.dir/files/%s.json" % filename, "w") as f:
|
||||||
@@ -214,15 +193,27 @@ def save_json_file(filename, obj):
|
|||||||
error("Failed to write to %s: %s" % (filename, e))
|
error("Failed to write to %s: %s" % (filename, e))
|
||||||
|
|
||||||
|
|
||||||
def toggle(player, ls, name = "Toggle", add = None):
|
def toggle(player, ls, add = None, on = "&aToggle now on!", off = "&cToggle now off!", already = "&cToggle was already %s"):
|
||||||
"""
|
"""
|
||||||
Toggles presence of a player's UUID in a list
|
Toggle presence of a player's UUID in a list (ls)
|
||||||
If add is given, True explicitely adds it whereas False removes it
|
'add' controls if a player should be added(True) or removed(False)
|
||||||
|
if 'add' is None, ls will simply be toggled for that player.
|
||||||
|
when 'add' is given, but won't change anything, %s in 'already' is replaced with "ON" or "OFF"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pid = uid(player)
|
pid = uid(player)
|
||||||
if pid in ls or add == False:
|
enabled = pid in ls
|
||||||
|
|
||||||
|
# Do some checks and remove pid.
|
||||||
|
if enabled and add == False:
|
||||||
ls.remove(pid)
|
ls.remove(pid)
|
||||||
msg(player, "&a%s turned off!" % name)
|
msg(player, on)
|
||||||
elif add != False:
|
|
||||||
|
# Do some checks and append pid.
|
||||||
|
elif not enabled and add == True:
|
||||||
ls.append(pid)
|
ls.append(pid)
|
||||||
msg(player, "&a%s turned on!" % name)
|
msg(player, off)
|
||||||
|
|
||||||
|
# Already on/off (optional)
|
||||||
|
else:
|
||||||
|
msg(player, already % (" ON" if add else " OFF"))
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
from adminchat import *
|
|
||||||
|
|
||||||
imout_toggle_list = []
|
|
||||||
|
|
||||||
@hook.command("imout")
|
|
||||||
def on_imout_command(sender, command, label, args):
|
|
||||||
if not is_player(sender):
|
|
||||||
msg(sender, "&cThis command can't be run from the console")
|
|
||||||
return True
|
|
||||||
if sender.hasPermission("utils.imout"):
|
|
||||||
name = sender.getName()
|
|
||||||
symbol = "&a&l+"
|
|
||||||
if name in imout_toggle_list:
|
|
||||||
msg(sender, "&eWelcome back! You are no longer hidden")
|
|
||||||
msg(sender, "&6We disabled /act for you!")
|
|
||||||
runas(sender, "vanish off")
|
|
||||||
if name in imout_toggle_list:
|
|
||||||
imout_toggle_list.remove(name)
|
|
||||||
if name in ac_toggle_list:
|
|
||||||
ac_toggle_list.remove(name)
|
|
||||||
else:
|
|
||||||
symbol = "&c&l-"
|
|
||||||
msg(sender, "&eYou just left... Or didn't you?")
|
|
||||||
imout_toggle_list.append(name)
|
|
||||||
runas(sender, "vanish on")
|
|
||||||
if name not in ac_toggle_list:
|
|
||||||
msg(sender, "&6We enabled /act for you!")
|
|
||||||
ac_toggle_list.append(name)
|
|
||||||
|
|
||||||
broadcast(None, "%s &7%s" % (symbol, name))
|
|
||||||
return True
|
|
||||||
+1
-1
@@ -37,7 +37,7 @@ def tp_chunk(sender, id):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("lagchunks")
|
@hook.command("lagchunks")
|
||||||
def on_lagchunks_command(sender, command, label, args):
|
def on_lagchunks_command(sender, args):
|
||||||
if sender.hasPermission("utils.lagchunks"):
|
if sender.hasPermission("utils.lagchunks"):
|
||||||
plugin_header(sender, "Lagchunks")
|
plugin_header(sender, "Lagchunks")
|
||||||
global lagchunks
|
global lagchunks
|
||||||
|
|||||||
@@ -1,266 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
from passlib.hash import pbkdf2_sha256 as crypt
|
|
||||||
from basecommands import simplecommand
|
|
||||||
import time
|
|
||||||
import threading
|
|
||||||
from login_secrets import * #Don't forget to make login_secrets aswell
|
|
||||||
import mysqlhack
|
|
||||||
from com.ziclix.python.sql import zxJDBC
|
|
||||||
from java.lang import Runnable
|
|
||||||
|
|
||||||
wait_time = 60 #seconds
|
|
||||||
admin_perm = "utils.loginsecurity.admin"
|
|
||||||
min_pass_length = 8
|
|
||||||
blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def matches(password,user):
|
|
||||||
thread = threading.Thread(target=matches_thread, args = (password,user))
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
|
|
||||||
def matches_thread(password, user):
|
|
||||||
hashed = get_pass(uid(user))
|
|
||||||
py_player = get_py_player(user)
|
|
||||||
if crypt.verify(password, hashed):
|
|
||||||
if py_player.logging_in:
|
|
||||||
py_player.logging_in = False
|
|
||||||
msg(user, "&aLogged in successfully!")
|
|
||||||
else:
|
|
||||||
if py_player.logging_in:
|
|
||||||
msg(user, "&cInvalid password!")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("cgpass",
|
|
||||||
usage = "<password> <new password>",
|
|
||||||
description = "Changes your password",
|
|
||||||
senderLimit = 0,
|
|
||||||
helpNoargs = True)
|
|
||||||
def change_pass_command(sender, command, label, args):
|
|
||||||
|
|
||||||
py_player = get_py_player(sender)
|
|
||||||
|
|
||||||
if py_player.logging_in:
|
|
||||||
return "&cYou are not logged in"
|
|
||||||
if not len(args) == 2:
|
|
||||||
return "&cInvalid arguments"
|
|
||||||
|
|
||||||
password = args[0]
|
|
||||||
new_password = args[1]
|
|
||||||
uuid = uid(sender)
|
|
||||||
|
|
||||||
if is_registered(uuid):
|
|
||||||
change_pass(uuid, crypt.encrypt(new_password, rounds=200000, salt_size=16))
|
|
||||||
return "&aPassword changed"
|
|
||||||
return "&cYou are not registered"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("login",
|
|
||||||
usage = "<password>",
|
|
||||||
description = "Logs you in if <password> matches your password.",
|
|
||||||
senderLimit = 0,
|
|
||||||
helpNoargs = True)
|
|
||||||
def login_command(sender, command, label, args):
|
|
||||||
py_player = get_py_player(sender)
|
|
||||||
|
|
||||||
if not py_player.logging_in:
|
|
||||||
msg(sender,"&cAlready logged in!")
|
|
||||||
|
|
||||||
password = args[0]
|
|
||||||
matches(password, sender)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("register",
|
|
||||||
usage = "<password>",
|
|
||||||
description = "Registers you with <password>. Next time you join, log in with /login",
|
|
||||||
senderLimit = 0,
|
|
||||||
helpNoargs = True)
|
|
||||||
def register_command(sender, command, label, args):
|
|
||||||
|
|
||||||
py_player = get_py_player(sender)
|
|
||||||
|
|
||||||
if len(args) > 1:
|
|
||||||
return "&cPassword can only be one word!"
|
|
||||||
|
|
||||||
uuid = uid(sender)
|
|
||||||
if is_registered(uuid):
|
|
||||||
return "&cYou are already registered!"
|
|
||||||
|
|
||||||
password = args[0]
|
|
||||||
|
|
||||||
if len(password) < min_pass_length:
|
|
||||||
return "&cThe password has to be made up of at least %s characters!" % min_pass_length
|
|
||||||
|
|
||||||
create_pass(uuid, password)
|
|
||||||
return "&cPassword set. Use /login <password> upon join."
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("rmpass",
|
|
||||||
description = "Removes your password if the password matches",
|
|
||||||
senderLimit = 0,
|
|
||||||
amax = 0,
|
|
||||||
helpNoargs = False)
|
|
||||||
def rmpass_command(sender, command, label, args):
|
|
||||||
|
|
||||||
py_player = get_py_player(sender)
|
|
||||||
|
|
||||||
if py_player.logging_in:
|
|
||||||
return "&cYou are not logged in"
|
|
||||||
|
|
||||||
if not is_registered(uid(sender)):
|
|
||||||
return "&cYou are not registered!"
|
|
||||||
|
|
||||||
if py_player.logging_in == False:
|
|
||||||
delete_pass(uid(sender))
|
|
||||||
return "&aPassword removed successfully. You will not be prompted anymore."
|
|
||||||
return "&cFailed to remove password, please contact a staff member"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("rmotherpass",
|
|
||||||
aliases = ["lacrmpass"],
|
|
||||||
usage = "<user>",
|
|
||||||
senderLimit = -1,
|
|
||||||
description = "Removes password of <user> and sends them a notification",
|
|
||||||
helpNoargs = True)
|
|
||||||
def rmotherpass_command(sender, command, label, args):
|
|
||||||
|
|
||||||
py_player = get_py_player(sender)
|
|
||||||
|
|
||||||
if py_player.logging_in:
|
|
||||||
return "&cYou are not logged in"
|
|
||||||
|
|
||||||
if not sender.hasPermission(admin_perm):
|
|
||||||
noperm(sender)
|
|
||||||
return
|
|
||||||
|
|
||||||
user = server.getOfflinePlayer(args[0])
|
|
||||||
|
|
||||||
if is_registered(uid(user)):
|
|
||||||
delete_pass(uid(user))
|
|
||||||
runas(server.getConsoleSender(), colorify("mail send %s &cYour password was reset by a staff member. Use &6/register&c to set a new one." % user.getName()))
|
|
||||||
return "&aPassword of %s reset successfully" % user.getName()
|
|
||||||
return "&cThat player could not be found (or is not registered)"
|
|
||||||
|
|
||||||
def change_pass(uuid, pw):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("UPDATE secret SET pass = ? WHERE uuid = ?", (pw,uuid,))
|
|
||||||
conn.commit()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
def get_pass(uuid):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("SELECT pass FROM secret WHERE uuid = ?", (uuid,))
|
|
||||||
results = curs.fetchall()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
return results[0][0]
|
|
||||||
|
|
||||||
def create_pass(uuid,pw):
|
|
||||||
thread = threading.Thread(target=create_pass_thread, args=(uuid,pw))
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
def create_pass_thread(uuid, pw):
|
|
||||||
pw = crypt.encrypt(pw, rounds=200000, salt_size=16)
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("INSERT INTO secret VALUES (?,?)", (uuid,pw,))
|
|
||||||
conn.commit()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
def is_registered(uuid):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("SELECT EXISTS(SELECT * FROM secret WHERE uuid = ?)", (uuid,))
|
|
||||||
results = curs.fetchall()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
if results[0][0] == 1:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def delete_pass(uuid):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("DELETE FROM secret WHERE uuid = ?", (uuid,))
|
|
||||||
conn.commit()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "low")
|
|
||||||
def on_join(event):
|
|
||||||
user = event.getPlayer()
|
|
||||||
py_player = get_py_player(event.getPlayer())
|
|
||||||
if is_registered(uid(user)):
|
|
||||||
msg(event.getPlayer(), "&6You will be disconnected after 60 seconds if you don't &alogin")
|
|
||||||
msg(user, "&cUse /login <password>")
|
|
||||||
py_player.logging_in = True
|
|
||||||
py_player.login_time = time.time()
|
|
||||||
return
|
|
||||||
elif user.hasPermission(admin_perm):
|
|
||||||
pass #Do what? force them to make a password, lots of code, maybe just message us on slack?
|
|
||||||
|
|
||||||
#This shouldn't be needed anymore as py_player gets removed anyway.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent", "high")
|
|
||||||
def on_quit(event):
|
|
||||||
if event.getPlayer().getName() in logging_in:
|
|
||||||
del logging_in[event.getPlayer().getName()]
|
|
||||||
"""
|
|
||||||
|
|
||||||
##Threading start
|
|
||||||
class kick_class(Runnable):
|
|
||||||
|
|
||||||
def __init__(self, player):
|
|
||||||
self.player = player
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
if self.player.isOnline():
|
|
||||||
self.player.kickPlayer(colorify("&aLogin timed out"))
|
|
||||||
|
|
||||||
def kick_thread():
|
|
||||||
while True:
|
|
||||||
time.sleep(1)
|
|
||||||
now = time.time()
|
|
||||||
for py_player in py_players:
|
|
||||||
if py_player.logging_in:
|
|
||||||
if now - py_player.login_time > wait_time:
|
|
||||||
player = py_player.player
|
|
||||||
kick = kick_class(player)
|
|
||||||
server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"), kick)
|
|
||||||
|
|
||||||
|
|
||||||
"""if name in logging_in:
|
|
||||||
del logging_in[name]
|
|
||||||
break
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
thread = threading.Thread(target = kick_thread)
|
|
||||||
thread.daemon = True
|
|
||||||
thread.start()
|
|
||||||
##Threading end
|
|
||||||
|
|
||||||
for blocked_event in blocked_events:
|
|
||||||
@hook.event(blocked_event, "high")
|
|
||||||
def on_blocked_event(event):
|
|
||||||
user = get_py_player(event.getPlayer())
|
|
||||||
if user.logging_in:
|
|
||||||
event.setCancelled(True)
|
|
||||||
@@ -9,7 +9,6 @@ from traceback import format_exc as print_traceback
|
|||||||
sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/pyshared/python2.7']
|
sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/pyshared/python2.7']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Library that adds a bunch of re-usable methods which are used in nearly all other modules
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
except:
|
except:
|
||||||
print("[RedstonerUtils] ERROR: Failed to import helpers:")
|
print("[RedstonerUtils] ERROR: Failed to import helpers:")
|
||||||
@@ -32,54 +31,20 @@ info("Loading RedstonerUtils...")
|
|||||||
|
|
||||||
# Import all modules, in this order
|
# Import all modules, in this order
|
||||||
shared["load_modules"] = [
|
shared["load_modules"] = [
|
||||||
# Collection of tiny utilities
|
|
||||||
"misc",
|
"misc",
|
||||||
# Adds chat for staff using /ac <text or ,<text>
|
|
||||||
"adminchat",
|
"adminchat",
|
||||||
# Adds /badge, allows to give players achievements
|
|
||||||
"badges",
|
|
||||||
# Adds a few block placement corrections/mods
|
|
||||||
"blockplacemods",
|
|
||||||
# Adds /calc, toggles automatic solving of Math expressions in chat
|
|
||||||
"calc",
|
|
||||||
# Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities
|
|
||||||
"lagchunks",
|
"lagchunks",
|
||||||
# Adds /report and /rp, Stores reports with time and location
|
|
||||||
"reports",
|
"reports",
|
||||||
# Adds group-chat with /chatgroup and /cgt to toggle normal chat into group mode
|
|
||||||
"chatgroups",
|
"chatgroups",
|
||||||
# Adds /token, reads and writes from the database to generate pronouncable (and thus memorable) registration-tokens for the website
|
|
||||||
"webtoken",
|
"webtoken",
|
||||||
# Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu
|
|
||||||
"saylol",
|
"saylol",
|
||||||
# Shows the owner of a skull when right-clicked
|
|
||||||
"skullclick",
|
"skullclick",
|
||||||
# Adds /listen, highlights chat and plays a sound when your name was mentioned
|
|
||||||
"mentio",
|
"mentio",
|
||||||
# Adds /cycler, swaps the hotbar with inventory when player changes slot from right->left or left->right
|
|
||||||
"cycle",
|
"cycle",
|
||||||
# Adds /getmotd & /setmotd to update the motd on the fly (no reboot)
|
|
||||||
"motd",
|
"motd",
|
||||||
# AnswerBot. Hides stupid questions from chat and tells the sender about /faq or the like
|
|
||||||
"abot",
|
"abot",
|
||||||
# Adds '/forcefield', creates forcefield for players who want it.
|
|
||||||
"forcefield",
|
"forcefield",
|
||||||
# Adds /damnspam, creates timeout for buttons/levers to mitigate button spam.
|
"friends"
|
||||||
"damnspam",
|
|
||||||
# Adds /check, useful to lookup details about a player
|
|
||||||
"check",
|
|
||||||
# Adds /an, a command you can use to share thoughts/plans/news
|
|
||||||
"adminnotes",
|
|
||||||
# Adds /imout, displays fake leave/join messages
|
|
||||||
"imout",
|
|
||||||
#adds snowbrawl minigame
|
|
||||||
"snowbrawl",
|
|
||||||
# Adds /tm [player] for a messages to be sent to this player via /msg
|
|
||||||
"pmtoggle",
|
|
||||||
# Replacement for LoginSecurity
|
|
||||||
"loginsecurity",
|
|
||||||
# Centralized Player class
|
|
||||||
"player"
|
|
||||||
]
|
]
|
||||||
shared["modules"] = {}
|
shared["modules"] = {}
|
||||||
for module in shared["load_modules"]:
|
for module in shared["load_modules"]:
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ def onChat(event):
|
|||||||
except:
|
except:
|
||||||
# list might not be mutable, ignoring. Receiver will get the message twice
|
# list might not be mutable, ignoring. Receiver will get the message twice
|
||||||
pass
|
pass
|
||||||
message = " "+" ".join([sender.getDisplayName(), arrow] + rec_words)
|
message = " ".join([sender.getDisplayName(), arrow] + rec_words)
|
||||||
msg(recipient, message, usecolor = False)
|
msg(recipient, message, usecolor = False)
|
||||||
recipient.playSound(recipient.getLocation(), "mob.chicken.plop", 1, 2)
|
recipient.playSound(recipient.getLocation(), "mob.chicken.plop", 1, 2)
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ def add_keyword(sender, args):
|
|||||||
if keywords:
|
if keywords:
|
||||||
mentions[uid(sender)] = keywords
|
mentions[uid(sender)] = keywords
|
||||||
|
|
||||||
msg(sender, "&aYou are now listening for '&2%s&2'!" % new_word)
|
msg(sender, "&aYou are now listening for '&2%s'!" % new_word)
|
||||||
saveMentions()
|
saveMentions()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -107,19 +107,13 @@ def del_keyword(sender, args):
|
|||||||
elif sender_id in mentions:
|
elif sender_id in mentions:
|
||||||
del mentions[sender_id]
|
del mentions[sender_id]
|
||||||
saveMentions()
|
saveMentions()
|
||||||
msg(sender, "&aYou are no longer listening for '&2%s&2'!" % del_word)
|
msg(sender, "&aYou are no longer listening for '&2%s&e'!" % del_word)
|
||||||
else:
|
else:
|
||||||
msg(sender, "&cWe can't remove something that doesn't exist! Try &6/mentio list")
|
msg(sender, "&cWe can't remove something that doesn't exist! Try &6/mentio list")
|
||||||
|
|
||||||
|
|
||||||
def show_help(player):
|
|
||||||
msg(player, "&a/mentio add <word>")
|
|
||||||
msg(player, "&a/mentio del <word>")
|
|
||||||
msg(player, "&a/mentio list")
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("mentio")
|
@hook.command("mentio")
|
||||||
def onListenCommand(sender, command, label, args):
|
def onListenCommand(sender, args):
|
||||||
plugin_header(sender, "Mentio")
|
plugin_header(sender, "Mentio")
|
||||||
|
|
||||||
argnum = len(args)
|
argnum = len(args)
|
||||||
@@ -143,7 +137,7 @@ def onListenCommand(sender, command, label, args):
|
|||||||
if not keywords:
|
if not keywords:
|
||||||
msg(sender, "&cYou are currently listening for no words! Try &6/mentio add <word>")
|
msg(sender, "&cYou are currently listening for no words! Try &6/mentio add <word>")
|
||||||
else:
|
else:
|
||||||
show_help(sender)
|
msg(sender, "&a/mentio add <word>")
|
||||||
else:
|
msg(sender, "&a/mentio del <word>")
|
||||||
show_help(sender)
|
msg(sender, "&a/mentio list")
|
||||||
return True
|
return True
|
||||||
@@ -1,189 +1,128 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from time import time as now
|
from time import time as now
|
||||||
from time import sleep
|
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
import thread
|
import thread
|
||||||
import org.bukkit.inventory.ItemStack as ItemStack
|
import org.bukkit.inventory.ItemStack as ItemStack
|
||||||
import org.bukkit.Bukkit as Bukkit
|
|
||||||
from basecommands import simplecommand
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Welcome new players
|
||||||
|
#
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "monitor")
|
@hook.event("player.PlayerJoinEvent", "monitor")
|
||||||
def on_join(event):
|
def on_join(event):
|
||||||
"""
|
|
||||||
Welcome new players
|
|
||||||
"""
|
|
||||||
player = event.getPlayer()
|
player = event.getPlayer()
|
||||||
|
|
||||||
# send welcome broadcast
|
# send welcome broadcast
|
||||||
if not player.hasPlayedBefore():
|
if not player.hasPlayedBefore():
|
||||||
broadcast("utils.greet_new", "\n&a&lPlease welcome &f" + player.getDisplayName() + " &a<o Redstoner!\n")
|
broadcast("utils.greet_new", "")
|
||||||
|
broadcast("utils.greet_new", "&a&lPlease welcome &f" + player.getDisplayName() + " &a<o Redstoner!")
|
||||||
|
broadcast("utils.greet_new", "")
|
||||||
|
|
||||||
# clear out some eventual crap before
|
# clear out some eventual crap before
|
||||||
msg(player, " \n \n \n \n \n \n \n \n \n \n \n \n ")
|
msg(player, " \n \n \n \n \n \n \n \n \n \n \n \n ")
|
||||||
msg(player, " &4Welcome to the Redstoner Server!")
|
msg(player, " &4Welcome to the Redstoner Server!")
|
||||||
msg(player, " &6Before you ask us things, take a quick")
|
msg(player, " &6Before you ask us things, take a quick")
|
||||||
msg(player, " &6look at &a&nredstoner.com/info")
|
msg(player, " &6look at the &a&l/FAQ &6command.")
|
||||||
msg(player, " \n&6thank you and happy playing ;)")
|
msg(player, " \n&6thank you and happy playing ;)")
|
||||||
msg(player, " \n \n")
|
msg(player, " \n \n")
|
||||||
|
|
||||||
# teleport to spawn when spawning inside portal
|
# teleport to spawn when spawning inside portal
|
||||||
loginloc = player.getLocation().getBlock().getType()
|
loginloc = player.getLocation().getBlock().getType()
|
||||||
headloc = player.getEyeLocation().getBlock().getType()
|
headloc = player.getEyeLocation().getBlock().getType()
|
||||||
if "PORTAL" in [str(headloc), str(loginloc)]:
|
if str(loginloc) == "PORTAL" or str(headloc) == "PORTAL":
|
||||||
msg(player, "&4Looks like you spawned in a portal... Let me help you out")
|
msg(player, "&4Looks like you spawned in a portal... Let me help you out")
|
||||||
msg(player, "&6You can use /back if you &nreally&6 want to go back")
|
msg(player, "&6You can use /back if you &nreally&6 want to go back")
|
||||||
player.teleport(player.getWorld().getSpawnLocation())
|
player.teleport(player.getWorld().getSpawnLocation())
|
||||||
|
|
||||||
"""
|
|
||||||
This code fixes /up 0 destroying/replacing blocks in plots that are not yours.
|
|
||||||
If you use //up, this is caught by plotme and cancelled if you are not allowed to build.
|
|
||||||
However, if you use //up, WorldEdit does the following on "low" priority:
|
|
||||||
* Change the command to /up with the same arguments
|
|
||||||
* Run another event with /up but its cancelled (dunno why it does this)
|
|
||||||
|
|
||||||
Keep in mind that, on "lowest" priority, PlotMe might cancel events.
|
#
|
||||||
|
# /sudo - execute command/chat *as* a player/console
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
"""
|
@hook.command("sudo")
|
||||||
dup = 0 #Used to store when someone used //up
|
def on_sudo_command(sender, args):
|
||||||
|
if sender.hasPermission("utils.sudo"):
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "lowest")
|
plugin_header(sender, "Sudo")
|
||||||
def cmd_event(event):
|
if not checkargs(sender, args, 2, -1):
|
||||||
global dup
|
|
||||||
if event.getMessage().split(" ")[0] in ("//up", "/worldedit:/up"):
|
|
||||||
dup = True
|
|
||||||
|
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "normal")
|
|
||||||
def cmd_event2(event):
|
|
||||||
global dup
|
|
||||||
args = event.getMessage().split(" ")
|
|
||||||
if args[0].lower() in ("/up", "/worldedit:up"):
|
|
||||||
if dup: #If plotme cancelled this, it will not matter. This lets it through but PlotMe doesn't.
|
|
||||||
dup = False
|
|
||||||
elif not event.isCancelled():
|
|
||||||
event.setCancelled(True)
|
|
||||||
event.getPlayer().chat("//up " + " ".join(args[1:]))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""" Disabled while builder can't access Trusted
|
|
||||||
@hook.event("player.PlayerGameModeChangeEvent", "low")
|
|
||||||
def on_gamemode(event):
|
|
||||||
user = event.getPlayer()
|
|
||||||
if str(event.getNewGameMode()) != "SPECTATOR" and user.getWorld().getName() == "Trusted" and not user.hasPermission("mv.bypass.gamemode.Trusted"):
|
|
||||||
event.setCancelled(True)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerBedEnterEvent")
|
|
||||||
def on_bed_enter(event):
|
|
||||||
world = event.getPlayer().getWorld()
|
|
||||||
if world.getName() in ("Survival_1", "TrustedSurvival_1"):
|
|
||||||
for player in world.getPlayers():
|
|
||||||
player.setSleepingIgnored(True)
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerTeleportEvent")
|
|
||||||
def on_player_teleport(event):
|
|
||||||
"""
|
|
||||||
Disable spectator teleportation
|
|
||||||
"""
|
|
||||||
player = event.getPlayer()
|
|
||||||
if not event.isCancelled() and str(event.getCause()) == "SPECTATE" and not player.hasPermission("utils.tp.spectate"):
|
|
||||||
event.setCancelled(True)
|
|
||||||
msg(event.getPlayer(), "&cSpectator teleportation is disabled")
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("block.BlockFromToEvent", "highest")
|
|
||||||
def on_flow(event):
|
|
||||||
if event.isCancelled():
|
|
||||||
return
|
|
||||||
block = event.getToBlock()
|
|
||||||
if block.getWorld().getName() == "Creative" and rs_material_broken_by_flow(str(block.getType())):
|
|
||||||
event.setCancelled(True)
|
|
||||||
|
|
||||||
def rs_material_broken_by_flow(material):
|
|
||||||
if material in ("REDSTONE", "LEVER", "TRIPWIRE"):
|
|
||||||
return True
|
return True
|
||||||
parts = material.split("_")
|
|
||||||
length = len(parts)
|
|
||||||
return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR"))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("sudo",
|
|
||||||
usage = "<player> [cmd..]",
|
|
||||||
description = "Makes <player> write [cmd..] in chat",
|
|
||||||
amin = 2,
|
|
||||||
helpNoargs = True)
|
|
||||||
def on_sudo_command(sender, command, label, args):
|
|
||||||
target = args[0]
|
target = args[0]
|
||||||
|
|
||||||
cmd = " ".join(args[1:])
|
cmd = " ".join(args[1:])
|
||||||
msg(sender, "&2[SUDO] &rRunning '&e%s&r' as &3%s" % (cmd, target))
|
msg(sender, "Running '&e%s&r' as &3%s" % (cmd, target))
|
||||||
is_cmd = cmd[0] == "/"
|
if cmd[0] == "/":
|
||||||
is_console = target.lower() in ["server", "console"]
|
cmd = cmd[1:]
|
||||||
if is_console:
|
if target.lower() == "server" or target.lower() == "console":
|
||||||
server.dispatchCommand(server.getConsoleSender(), cmd[1:] if is_cmd else cmd)
|
runas(server.getConsoleSender(), cmd)
|
||||||
return None
|
elif server.getPlayer(target):
|
||||||
target_player = server.getPlayer(target)
|
runas(server.getPlayer(target), cmd)
|
||||||
if target_player:
|
else:
|
||||||
target_player.chat(cmd)
|
msg(sender, "&cPlayer %s not found!" % target)
|
||||||
return None
|
else:
|
||||||
return "&cPlayer %s not found!" % target
|
if target.lower() == "server" or target.lower() == "console":
|
||||||
|
runas(server.getConsoleSender(), "say %s" % cmd)
|
||||||
|
elif server.getPlayer(target):
|
||||||
|
server.getPlayer(target).chat(cmd)
|
||||||
|
else:
|
||||||
|
msg(sender, "&cPlayer %s not found!" % target)
|
||||||
|
else:
|
||||||
|
noperm(sender)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Clicking redstone_sheep with shears will drop redstone + wool and makes a moo sound
|
||||||
|
#
|
||||||
|
|
||||||
@simplecommand("me",
|
last_shear = 0.0
|
||||||
usage = "[message..]",
|
|
||||||
description = "Sends a message in third person",
|
@hook.event("player.PlayerInteractEntityEvent")
|
||||||
helpNoargs = True)
|
def on_player_entity_interact(event):
|
||||||
def on_me_command(sender, command, label, args):
|
global last_shear
|
||||||
text = colorify("&7- %s &7%s " % (sender.getDisplayName() if isinstance(sender, Player) else "&9CONSOLE", u"\u21E6"))
|
if not event.isCancelled():
|
||||||
broadcast("utils.me", text + " ".join(args), usecolor = sender.hasPermission("essentials.chat.color"))
|
shear_time = now()
|
||||||
return None
|
if last_shear + 0.4 < shear_time:
|
||||||
|
last_shear = shear_time
|
||||||
|
sender = event.getPlayer()
|
||||||
|
entity = event.getRightClicked()
|
||||||
|
if is_player(entity) and uid(entity) == "ae795aa8-6327-408e-92ab-25c8a59f3ba1" and str(sender.getItemInHand().getType()) == "SHEARS" and is_creative(sender):
|
||||||
|
for _ in range(5):
|
||||||
|
entity.getWorld().dropItemNaturally(entity.getLocation(), ItemStack(bukkit.Material.getMaterial("REDSTONE")))
|
||||||
|
entity.getWorld().dropItemNaturally(entity.getLocation(), ItemStack(bukkit.Material.getMaterial("WOOL")))
|
||||||
|
sender.playSound(entity.getLocation(), "mob.cow.say", 1, 1)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# /pluginversions - print all plugins + versions; useful when updating plugins
|
||||||
|
#
|
||||||
|
|
||||||
@hook.command("pluginversions")
|
@hook.command("pluginversions")
|
||||||
def on_pluginversions_command(sender, command, label, args):
|
def on_pluginversions_command(sender, args):
|
||||||
"""
|
|
||||||
/pluginversions
|
|
||||||
print all plugins + versions; useful when updating plugins
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
plugin_header(sender, "Plugin versions")
|
plugin_header(sender, "Plugin versions")
|
||||||
plugins = [pl.getDescription() for pl in list(ArrayList(java_array_to_list(server.getPluginManager().getPlugins())))]
|
plugins = list(server.getPluginManager().getPlugins())
|
||||||
info(type(plugins[0]).__name__)
|
|
||||||
plugins.sort(key = lambda pl: pl.getDescription().getName())
|
plugins.sort(key = lambda pl: pl.getDescription().getName())
|
||||||
msg(sender, "&3Listing all " + str(len(plugins)) + " plugins and their version:")
|
msg(sender, "&3Listing all " + str(len(plugins)) + " plugins and their version:")
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
msg(sender, "&6" + pl.getDescription().getName() + "&r: &e" + pl.getDescription().getVersion())
|
msg(sender, "&6" + plugin.getDescription().getName() + "&r: &e" + plugin.getDescription().getVersion())
|
||||||
return True
|
return True
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# /echo - essentials echo sucks and prints mail alerts sometimes
|
||||||
|
#
|
||||||
|
|
||||||
@hook.command("echo")
|
@hook.command("echo")
|
||||||
def on_echo_command(sender, command, label, args):
|
def on_echo_command(sender, args):
|
||||||
"""
|
|
||||||
/echo
|
|
||||||
essentials echo sucks and prints mail alerts sometimes
|
|
||||||
"""
|
|
||||||
msg(sender, " ".join(args).replace("\\n", "\n"))
|
msg(sender, " ".join(args).replace("\\n", "\n"))
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# /pyeval - run python ingame
|
||||||
|
#
|
||||||
|
# has to be in main.py so we can access the modules
|
||||||
|
|
||||||
def eval_thread(sender, code):
|
def eval_thread(sender, code):
|
||||||
"""
|
|
||||||
/pyeval
|
|
||||||
run python ingame
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
result = eval(code)
|
result = eval(code)
|
||||||
msg(sender, ">>> %s: %s" % (colorify("&3") + type(result).__name__, colorify("&a") + unicode(result) + "\n "), usecolor = False)
|
msg(sender, ">>> %s: %s" % (colorify("&3") + type(result).__name__, colorify("&a") + unicode(result) + "\n "), usecolor = False)
|
||||||
@@ -196,67 +135,22 @@ def eval_thread(sender, code):
|
|||||||
msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
||||||
thread.exit()
|
thread.exit()
|
||||||
|
|
||||||
@simplecommand("pyeval",
|
|
||||||
usage = "[code..]",
|
@hook.command("pyeval")
|
||||||
description = "Runs python [code..] and returns the result",
|
def on_pyeval_command(sender, args):
|
||||||
helpNoargs = True)
|
if sender.hasPermission("utils.pyeval"):
|
||||||
def on_pyeval_command(sender, command, label, args):
|
if not checkargs(sender, args, 1, -1):
|
||||||
msg(sender, " ".join(args), False, "e")
|
return True
|
||||||
|
msg(sender, "%s" % " ".join(args), False, "e")
|
||||||
thread.start_new_thread(eval_thread, (sender, " ".join(args)))
|
thread.start_new_thread(eval_thread, (sender, " ".join(args)))
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("tempadd",
|
|
||||||
usage = "<user> <group> [duration]",
|
|
||||||
description = "Temporarily adds <user> to <group> for \n[duration] minutes. Defaults to 1 week.",
|
|
||||||
helpNoargs = True,
|
|
||||||
helpSubcmd = True,
|
|
||||||
amin = 2,
|
|
||||||
amax = 3)
|
|
||||||
def tempadd_command(sender, command, label, args):
|
|
||||||
if not sender.hasPermission("permissions.manage.membership." + args[1]):
|
|
||||||
return "&cYou do not have permission to manage that group!"
|
|
||||||
if len(args) == 3:
|
|
||||||
if not args[2].isdigit():
|
|
||||||
return "&cThats not a number!"
|
|
||||||
duration = int(args[2]) * 60
|
|
||||||
else:
|
else:
|
||||||
duration = 604800
|
noperm(sender)
|
||||||
if duration <= 0:
|
return True
|
||||||
return "&cThats too short!"
|
|
||||||
cmd = "pex user %s group add %s * %s" % (args[0], args[1], duration)
|
|
||||||
runas(sender, cmd)
|
|
||||||
|
|
||||||
m, s = divmod(duration, 60)
|
|
||||||
h, m = divmod(m, 60)
|
|
||||||
d, h = divmod(h, 24)
|
|
||||||
return "&aAdded to group for %dd%dh%dm" % (d, h, m)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("modules")
|
@hook.command("modules")
|
||||||
def on_modules_command(sender, command, label, args):
|
def on_modules_command(sender, args):
|
||||||
"""
|
|
||||||
/modules
|
|
||||||
list all modules, unloaded modules in red
|
|
||||||
"""
|
|
||||||
plugin_header(sender, "Modules")
|
plugin_header(sender, "Modules")
|
||||||
msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]]))
|
for mod in shared["load_modules"]:
|
||||||
|
color = "a" if mod in shared["modules"] else "c"
|
||||||
|
msg(sender, "&" + color + mod)
|
||||||
""" Something I'm planning for schematics
|
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "low")
|
|
||||||
def on_command(event):
|
|
||||||
msg = " ".split(event.getMessage())
|
|
||||||
if len(msg) < 3:
|
|
||||||
return
|
|
||||||
if msg[0].lower() not in ("/schematic", "/schem"):
|
|
||||||
return
|
|
||||||
if msg[1].lower() not in ("save", "load"):
|
|
||||||
return
|
|
||||||
msg[2] = event.getPlayer().getName() + "/" + msg[2]
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ default_motd = colorify(server.getMotd())
|
|||||||
motd = default_motd
|
motd = default_motd
|
||||||
|
|
||||||
@hook.command("getmotd")
|
@hook.command("getmotd")
|
||||||
def on_getmotd_command(sender, command, label, args):
|
def on_getmotd_command(sender, args):
|
||||||
plugin_header(sender, "MOTD")
|
plugin_header(sender, "MOTD")
|
||||||
msg(sender, motd, usecolor = False)
|
msg(sender, motd, usecolor = False)
|
||||||
|
|
||||||
|
|
||||||
@hook.command("setmotd")
|
@hook.command("setmotd")
|
||||||
def on_setmotd_command(sender, command, label, args):
|
def on_setmotd_command(sender, args):
|
||||||
global motd
|
global motd
|
||||||
if sender.hasPermission("utils.setmotd"):
|
if sender.hasPermission("utils.setmotd"):
|
||||||
if not checkargs(sender, args, 1, -1):
|
if not checkargs(sender, args, 1, -1):
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
"""
|
|
||||||
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.
|
|
||||||
"""
|
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
|
|
||||||
py_players = []
|
|
||||||
|
|
||||||
class py_player:
|
|
||||||
def __init__(self,player):
|
|
||||||
self.player = player
|
|
||||||
self.logging_in = False
|
|
||||||
self.login_time = 0
|
|
||||||
|
|
||||||
def get_py_player(player):
|
|
||||||
#py_player = py_players[py_players.index(player)]
|
|
||||||
|
|
||||||
for py_player in py_players:
|
|
||||||
if py_player.player.getName() == player.getName():
|
|
||||||
return py_player
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent","lowest")
|
|
||||||
def on_join(event):
|
|
||||||
player = py_player(event.getPlayer())
|
|
||||||
py_players.append(player)
|
|
||||||
print str(len(py_players))+event.getPlayer().getName()
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent","highest")
|
|
||||||
def on_leave(event):
|
|
||||||
py_players.remove(get_py_player(event.getPlayer()))
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
import org.bukkit.entity.Player as Base_player
|
|
||||||
import blockplacemods as blockmods
|
|
||||||
import snowbrawl
|
|
||||||
import loginsecurity as login
|
|
||||||
import calc
|
|
||||||
import chatgroups as cg
|
|
||||||
import adminchat as ac
|
|
||||||
import cycle
|
|
||||||
import forcefield as ff
|
|
||||||
import imout
|
|
||||||
import mentio
|
|
||||||
import pmtoggle
|
|
||||||
|
|
||||||
|
|
||||||
get_info_perm = "utils.playermanager.info"
|
|
||||||
|
|
||||||
players = []
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################
|
|
||||||
# Outside-accessible functions
|
|
||||||
|
|
||||||
def get_player(name):
|
|
||||||
for player in players:
|
|
||||||
if player.get_name() == name:
|
|
||||||
return player
|
|
||||||
return None
|
|
||||||
|
|
||||||
##############################################################
|
|
||||||
# Events
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent", "highest")
|
|
||||||
def on_quit(event):
|
|
||||||
for i in range(len(players)):
|
|
||||||
if players[i].get_uuid() == uid(event.getPlayer()):
|
|
||||||
players.remove(players[i])
|
|
||||||
return
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "highest")
|
|
||||||
def on_join(event):
|
|
||||||
players.append(Player(event.getPlayer()))
|
|
||||||
|
|
||||||
#############################################################
|
|
||||||
# Commands
|
|
||||||
|
|
||||||
def send(sender, name, data):
|
|
||||||
if isinstance(data, bool):
|
|
||||||
if data == True:
|
|
||||||
msg(sender, "&e-&a %s&e:&a True" % name)
|
|
||||||
else:
|
|
||||||
msg(sender, "&e-&a %s&e:&c False" % name)
|
|
||||||
else:
|
|
||||||
msg(sender, "&e-&a %s&e:&6 %s" % (name, str(data)))
|
|
||||||
|
|
||||||
def send_header(sender, name):
|
|
||||||
msg(sender, "&e- &2 %s&e:" % name.upper())
|
|
||||||
|
|
||||||
def print_info(sender, player):
|
|
||||||
send_header(sender, "general")
|
|
||||||
send(sender, "Name", player.get_name())
|
|
||||||
send(sender, "UUID", player.get_uuid())
|
|
||||||
send(sender, "Logged in", player.logged_in())
|
|
||||||
send_header(sender, "snowbrawl")
|
|
||||||
send(sender, "In arena", player.in_sb_arena())
|
|
||||||
send(sender, "Arena", player.get_sb_arena())
|
|
||||||
send_header(sender, "place-mods")
|
|
||||||
send(sender, "Slab flip", player.has_autoflip_slab())
|
|
||||||
send(sender, "Cauldron fill", player.has_autofill_cauldron())
|
|
||||||
send(sender, "Piston face", player.has_autoface_piston())
|
|
||||||
send_header(sender, "chat groups")
|
|
||||||
send(sender, "In chatgroup", player.in_cg())
|
|
||||||
send(sender, "Chatgroup", player.get_cg())
|
|
||||||
send(sender, "Key", player.get_cg_key())
|
|
||||||
send(sender, "Toggle", player.has_cg_toggle())
|
|
||||||
send_header(sender, "Admin chat")
|
|
||||||
send(sender, "In adminchat", player.in_ac())
|
|
||||||
send(sender, "Key", player.get_ac_key())
|
|
||||||
send(sender, "Toggle", player.has_ac_toggle())
|
|
||||||
send_header(sender, "forcefield")
|
|
||||||
send(sender, "Whitelist", "&e, &6".join(player.get_ff_whitelist()))
|
|
||||||
send(sender, "Toggle", player.has_ff_toggle())
|
|
||||||
send_header(sender, "miscellaneous")
|
|
||||||
send(sender, "Calc", player.has_calc())
|
|
||||||
send(sender, "PM toggle", player.has_pm_toggle())
|
|
||||||
send(sender, "Cycle toggle", player.has_cycle())
|
|
||||||
send(sender, "Imout toggle", player.has_imout_toggle())
|
|
||||||
send(sender, "Mentio", "&e, &6".join(player.get_mentio_list()))
|
|
||||||
|
|
||||||
@hook.command("getinfo")
|
|
||||||
def on_command(sender, cmd, label, args):
|
|
||||||
if sender.hasPermission(get_info_perm):
|
|
||||||
if len(args) != 1:
|
|
||||||
msg(sender, "&e-&a /getinfo <name>")
|
|
||||||
else:
|
|
||||||
player = get_player(args[0])
|
|
||||||
if player != None:
|
|
||||||
print_info(sender, player)
|
|
||||||
else:
|
|
||||||
msg(sender, "&e-&c Player not online or does not exist")
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
|
|
||||||
#############################################################
|
|
||||||
# Player class
|
|
||||||
|
|
||||||
class Player():
|
|
||||||
|
|
||||||
def __init__(self, player):
|
|
||||||
self.player = player
|
|
||||||
|
|
||||||
def get_java_player(self):
|
|
||||||
return self.player
|
|
||||||
|
|
||||||
def get_uuid(self):
|
|
||||||
return uid(self.player)
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return self.get_java_player().getName()
|
|
||||||
|
|
||||||
def get_display_name(self):
|
|
||||||
return self.get_java_player().getDisplayName()
|
|
||||||
|
|
||||||
def in_sb_arena(self):
|
|
||||||
for arena in snowbrawl.arenas:
|
|
||||||
if arena.in_players(self.get_java_player()):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_sb_arena(self):
|
|
||||||
for arena in snowbrawl.arenas:
|
|
||||||
if arena.in_players(self.get_java_player()):
|
|
||||||
return arena
|
|
||||||
return None
|
|
||||||
|
|
||||||
def logged_in(self):
|
|
||||||
return self.get_name() not in login.logging_in
|
|
||||||
|
|
||||||
def has_autoflip_slab(self):
|
|
||||||
return blockmods.isEnabled("slab", self.get_uuid())
|
|
||||||
|
|
||||||
def has_autofill_cauldron(self):
|
|
||||||
return blockmods.isEnabled("cauldron", self.get_uuid())
|
|
||||||
|
|
||||||
def has_autoface_piston(self):
|
|
||||||
return blockmods.isEnabled("piston", self.get_uuid())
|
|
||||||
|
|
||||||
def has_calc(self):
|
|
||||||
return self.get_uuid() in calc.calc_users
|
|
||||||
|
|
||||||
def in_cg(self):
|
|
||||||
return self.get_uuid() in cg.groups.keys()
|
|
||||||
|
|
||||||
def get_cg(self):
|
|
||||||
if self.in_cg():
|
|
||||||
return cg.groups[self.get_uuid()]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_cg_key(self):
|
|
||||||
return cg.get_key(self.get_uuid())
|
|
||||||
|
|
||||||
def has_cg_toggle(self):
|
|
||||||
return self.get_uuid() in cg.cg_toggle_list
|
|
||||||
|
|
||||||
def in_ac(self):
|
|
||||||
return self.get_java_player().hasPermission(ac.ac_permission)
|
|
||||||
|
|
||||||
def get_ac_key(self):
|
|
||||||
return ac.get_key(self.get_uuid())
|
|
||||||
|
|
||||||
def has_ac_toggle(self):
|
|
||||||
return self.get_name() in ac.ac_toggle_list
|
|
||||||
|
|
||||||
def has_cycle(self):
|
|
||||||
return self.get_uuid() not in cycle.no_cyclers
|
|
||||||
|
|
||||||
def has_ff_toggle(self):
|
|
||||||
return self.get_uuid() in ff.ff_users
|
|
||||||
|
|
||||||
def get_ff_whitelist(self):
|
|
||||||
return ff.whitelists.get(self.get_uuid(), [])
|
|
||||||
|
|
||||||
def has_imout_toggle(self):
|
|
||||||
return self.get_name() in imout.imout_toggle_list
|
|
||||||
|
|
||||||
def get_mentio_list(self):
|
|
||||||
return mentio.get_keywords(self.get_java_player())
|
|
||||||
|
|
||||||
def has_pm_toggle(self):
|
|
||||||
return self.get_uuid() in pmtoggle.toggle_dict
|
|
||||||
+2
-4
@@ -1,9 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
"""
|
# this was going to be a PlotMe-like plugin "plotter"
|
||||||
*Very basic* start of a custom plot-plugin like PlotMe
|
# but it seems like PlotMe is still beeing developed, so we don't need our own.
|
||||||
on hold because the PlotMe developer continued to develop PlotMe
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
name: RedstonerUtils
|
name: RedstonerUtils
|
||||||
main: main.py
|
main: main.py
|
||||||
version: 3.1.0
|
version: 3.0.0
|
||||||
author: redstone_sheep
|
author: redstone_sheep
|
||||||
|
|
||||||
|
|||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
import org.bukkit.Bukkit as Bukkit
|
|
||||||
from java.util.UUID import fromString as juuid
|
|
||||||
|
|
||||||
toggle_dict = {}
|
|
||||||
permission = "utils.pmtoggle"
|
|
||||||
|
|
||||||
@hook.command("tm")
|
|
||||||
def on_toggle_message_command(sender, command, label, args):
|
|
||||||
if not sender.hasPermission(permission) or not is_player(sender):
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
plugin_header(sender, "Private Message Toggle")
|
|
||||||
uuid = uid(sender)
|
|
||||||
if len(args) > 0:
|
|
||||||
if len(args) > 1:
|
|
||||||
msg(sender, "&cToo many arguments!")
|
|
||||||
return True
|
|
||||||
target = Bukkit.getPlayer(args[0])
|
|
||||||
if target:
|
|
||||||
toggle_dict[uuid] = uid(target)
|
|
||||||
msg(sender, "&2Enabled toggle so that you're now sending only to %s &2by default" % target.getDisplayName())
|
|
||||||
else:
|
|
||||||
msg(sender, "&cThat player could not be found")
|
|
||||||
elif uuid in toggle_dict:
|
|
||||||
del toggle_dict[uuid]
|
|
||||||
msg(sender, "&2Disabled toggle successfully")
|
|
||||||
else:
|
|
||||||
msg(sender, "&cExpected a player as argument")
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "normal")
|
|
||||||
def on_chat(event):
|
|
||||||
if event.isCancelled():
|
|
||||||
return
|
|
||||||
player = event.getPlayer()
|
|
||||||
uuid = uid(player)
|
|
||||||
if uuid in toggle_dict:
|
|
||||||
event.setCancelled(True)
|
|
||||||
target = Bukkit.getPlayer(juuid(toggle_dict[uuid])).getName()
|
|
||||||
runas(player, "msg %s %s" % (target, event.getMessage()))
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent", "normal")
|
|
||||||
def on_quit(event):
|
|
||||||
uuid = uid(event.getPlayer())
|
|
||||||
if uuid in toggle_dict:
|
|
||||||
del toggle_dict[uuid]
|
|
||||||
for pid in list(toggle_dict):
|
|
||||||
if toggle_dict[pid] == uuid:
|
|
||||||
del toggle_dict[pid]
|
|
||||||
msg(Bukkit.getPlayer(juuid(pid)), "%s &cwent off so your Private Message Toggle has been disabled!" % Bukkit.getPlayer(juuid(uuid)).getDisplayName())
|
|
||||||
+27
-88
@@ -2,7 +2,6 @@ from helpers import *
|
|||||||
from java.util.UUID import fromString as juuid
|
from java.util.UUID import fromString as juuid
|
||||||
import time
|
import time
|
||||||
import thread
|
import thread
|
||||||
from traceback import format_exc as trace
|
|
||||||
|
|
||||||
|
|
||||||
time_format = "%Y.%m.%d %H:%M"
|
time_format = "%Y.%m.%d %H:%M"
|
||||||
@@ -14,83 +13,42 @@ rp_permission = "utils.rp"
|
|||||||
|
|
||||||
def print_help(sender):
|
def print_help(sender):
|
||||||
msg(sender, " &2/report <text> &eReport something")
|
msg(sender, " &2/report <text> &eReport something")
|
||||||
msg(sender, " &2/rp open &eList open reports (id, player, text)")
|
msg(sender, " &2/rp list &eList unresolved reports (id, player, text)")
|
||||||
msg(sender, " &2/rp closed &eList closed reports (id, player, text)")
|
|
||||||
msg(sender, " &2/rp tp <id> &eTeleport to report's location & show details")
|
msg(sender, " &2/rp tp <id> &eTeleport to report's location & show details")
|
||||||
msg(sender, " &2/rp close <id> &eResolve an open report")
|
msg(sender, " &2/rp del <id> &eResolve a report")
|
||||||
msg(sender, " &2/rp reopen <id> &eReopen a resolved report")
|
|
||||||
msg(sender, " &2/rp del <id> &eDelete a report (admin only)")
|
|
||||||
|
|
||||||
|
|
||||||
def print_list(sender, closed):
|
def print_list(sender):
|
||||||
try: # new thread, anything can happen.
|
try: # new thread, anything can happen.
|
||||||
targeted_reports = dict(enumerate(reports))
|
msg(sender, "&a" + str(len(reports)) + " reports:")
|
||||||
for i in list(targeted_reports):
|
for i, report in enumerate(reports):
|
||||||
report = targeted_reports[i]
|
name = server.getOfflinePlayer(juuid(report["uuid"])).getName()
|
||||||
if report["closed"] != closed:
|
msg(sender, "&8[&e%s&c%s&8] &3%s&f: &a%s" % (i, report["time"], name, report["msg"]))
|
||||||
targeted_reports.pop(i)
|
|
||||||
|
|
||||||
msg(sender, "&a%s %s reports:" % (len(targeted_reports), "closed" if closed else "open"))
|
|
||||||
for i in targeted_reports:
|
|
||||||
report = targeted_reports[i]
|
|
||||||
name = retrieve_player(report["uuid"]).getName()
|
|
||||||
msg(sender, "&8[&e%s &c%s&8] &3%s&f: &a%s" % (i, report["time"], name, report["msg"]))
|
|
||||||
except:
|
except:
|
||||||
warn("Failed to complete report's print_list() thread")
|
warn("Failed to complete report's print_list() thread")
|
||||||
error(trace())
|
|
||||||
|
|
||||||
|
|
||||||
def tp_report(sender, rep_id):
|
def tp_report(sender, rep_id):
|
||||||
if rep_id >= len(reports) or rep_id < 0:
|
if rep_id >= len(reports) or rep_id < 0:
|
||||||
msg(sender, "&cReport &3#" + str(rep_id) + "&c does not exist!")
|
msg(sender, "&cReport &3#" + str(rep_id) + "&c does not exist!")
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
report = reports[rep_id]
|
report = reports[rep_id]
|
||||||
safetp(sender, server.getWorld(report["world"]), report["x"], report["y"], report["z"], report["yaw"], report["pitch"])
|
safetp(sender, server.getWorld(report["world"]), report["x"], report["y"], report["z"], report["yaw"], report["pitch"])
|
||||||
msg(sender, "&aTeleported to %s&areport #%s" % ("&cclosed " if report["closed"] else "", rep_id))
|
msg(sender, "&aTeleported to report #%s" % rep_id )
|
||||||
|
|
||||||
|
|
||||||
# resolve == True: You're resolving, False: reopening
|
|
||||||
def resolve_reopen_report(sender, rep_id, resolve):
|
|
||||||
action = "resolved" if resolve else "reopened"
|
|
||||||
report = edit_report(sender, rep_id)
|
|
||||||
if report != None:
|
|
||||||
if report["closed"] == resolve:
|
|
||||||
msg(sender, "&cReport &3#%s&c was already %s!" % (rep_id, action))
|
|
||||||
else:
|
|
||||||
report["closed"] = resolve
|
|
||||||
save_reports()
|
|
||||||
msg(sender, "&aReport #%s %s" % (rep_id, action))
|
|
||||||
message_reporter(sender, report, action)
|
|
||||||
|
|
||||||
|
|
||||||
def delete_report(sender, rep_id):
|
def delete_report(sender, rep_id):
|
||||||
if not sender.hasPermission(rp_permission + ".del"):
|
|
||||||
noperm(sender)
|
|
||||||
return
|
|
||||||
action = "&cdeleted"
|
|
||||||
report = edit_report(sender, rep_id)
|
|
||||||
if report != None:
|
|
||||||
reports.remove(report)
|
|
||||||
save_reports()
|
|
||||||
msg(sender, "&aReport #%s %s" % (rep_id, action))
|
|
||||||
message_reporter(sender, report, action)
|
|
||||||
|
|
||||||
|
|
||||||
def edit_report(sender, rep_id):
|
|
||||||
if len(reports) > rep_id >= 0:
|
if len(reports) > rep_id >= 0:
|
||||||
return reports[rep_id]
|
report = reports[rep_id]
|
||||||
msg(sender, "&cThat report does not exist!")
|
reports.pop(rep_id)
|
||||||
return None
|
save_reports()
|
||||||
|
msg(sender, "&aReport #%s deleted." % rep_id)
|
||||||
|
reporter = server.getOfflinePlayer(juuid(report["uuid"]))
|
||||||
def message_reporter(sender, report, action):
|
plugin_header(reporter, "Report")
|
||||||
reporter = get_reporter(report)
|
msg(reporter, "&aReport '&e%s&a' was resolved by %s." % (report["msg"], sender.getName()))
|
||||||
message = "&aReport '&e%s&a' was %s &aby %s." % (report["msg"], action, sender.getName())
|
|
||||||
if reporter.isOnline():
|
|
||||||
plugin_header(reporter, "Reports")
|
|
||||||
msg(reporter, message)
|
|
||||||
else:
|
else:
|
||||||
server.dispatchCommand(sender, "mail send %s %s" % (reporter.getName(), colorify(message)))
|
msg(sender, "&cThat report does not exist!")
|
||||||
|
|
||||||
|
|
||||||
def save_reports():
|
def save_reports():
|
||||||
@@ -98,16 +56,13 @@ def save_reports():
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("rp")
|
@hook.command("rp")
|
||||||
def on_rp_command(sender, command, label, args):
|
def on_rp_command(sender, args):
|
||||||
if sender.hasPermission(rp_permission):
|
if sender.hasPermission(rp_permission):
|
||||||
plugin_header(sender, "Reports")
|
plugin_header(sender, "Reports")
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
subcmd = args[0].lower()
|
if args[0] == "list":
|
||||||
if subcmd == "closed":
|
|
||||||
# needs to run in seperate thread because of getOfflinePlayer
|
# needs to run in seperate thread because of getOfflinePlayer
|
||||||
thread.start_new_thread(print_list, (sender, True,))
|
thread.start_new_thread(print_list, (sender))
|
||||||
elif subcmd in ["open", "list"]:
|
|
||||||
thread.start_new_thread(print_list, (sender, False,))
|
|
||||||
else:
|
else:
|
||||||
if not checkargs(sender, args, 2, 2):
|
if not checkargs(sender, args, 2, 2):
|
||||||
return True
|
return True
|
||||||
@@ -117,17 +72,13 @@ def on_rp_command(sender, command, label, args):
|
|||||||
msg(sender, "&cDoesn't look like &3" + args[1] + "&c is a valid number!")
|
msg(sender, "&cDoesn't look like &3" + args[1] + "&c is a valid number!")
|
||||||
print_help(sender)
|
print_help(sender)
|
||||||
return True
|
return True
|
||||||
if subcmd == "tp":
|
if args[0] == "tp":
|
||||||
if not is_player(sender):
|
if not is_player(sender):
|
||||||
msg(sender, "&conly players can do this")
|
msg(sender, "&conly players can do this")
|
||||||
return True
|
return True
|
||||||
tp_report(sender, repid)
|
tp_report(sender, repid)
|
||||||
elif subcmd == "close":
|
elif args[0] == "del":
|
||||||
resolve_reopen_report(sender, repid, True)
|
|
||||||
elif subcmd == "del":
|
|
||||||
delete_report(sender, repid)
|
delete_report(sender, repid)
|
||||||
elif subcmd == "reopen":
|
|
||||||
resolve_reopen_report(sender, repid, False)
|
|
||||||
else:
|
else:
|
||||||
print_help(sender)
|
print_help(sender)
|
||||||
else:
|
else:
|
||||||
@@ -138,7 +89,7 @@ def on_rp_command(sender, command, label, args):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("report")
|
@hook.command("report")
|
||||||
def on_report_command(sender, command, label, args):
|
def on_report_command(sender, args):
|
||||||
plugin_header(sender, "Report")
|
plugin_header(sender, "Report")
|
||||||
if not is_player(sender):
|
if not is_player(sender):
|
||||||
msg(sender, "&conly players can do this")
|
msg(sender, "&conly players can do this")
|
||||||
@@ -158,8 +109,7 @@ def on_report_command(sender, command, label, args):
|
|||||||
"yaw": int(loc.yaw),
|
"yaw": int(loc.yaw),
|
||||||
"pitch": int(loc.pitch),
|
"pitch": int(loc.pitch),
|
||||||
"world": loc.getWorld().name,
|
"world": loc.getWorld().name,
|
||||||
"time": time.strftime(time_format),
|
"time": time.strftime(time_format)
|
||||||
"closed": False
|
|
||||||
}
|
}
|
||||||
reports.append(report)
|
reports.append(report)
|
||||||
save_reports()
|
save_reports()
|
||||||
@@ -175,9 +125,9 @@ def reports_reminder(): # needs 2 args for unknown reason
|
|||||||
if not check_reports:
|
if not check_reports:
|
||||||
info("Reports reminder thread killed.")
|
info("Reports reminder thread killed.")
|
||||||
thread.exit()
|
thread.exit()
|
||||||
targeted_reports = get_reports(False)
|
if len(reports) > 0:
|
||||||
if len(targeted_reports) > 0:
|
broadcast(rp_permission, "&2--=[ Reports ]=--")
|
||||||
broadcast(rp_permission, "&aThere are %s open reports!" % len(targeted_reports))
|
broadcast(rp_permission, "&aThere are %s pending reports!" % len(reports))
|
||||||
|
|
||||||
|
|
||||||
def stop_reporting():
|
def stop_reporting():
|
||||||
@@ -186,15 +136,4 @@ def stop_reporting():
|
|||||||
check_reports = False
|
check_reports = False
|
||||||
|
|
||||||
|
|
||||||
def get_reports(closed):
|
|
||||||
targeted_reports = []
|
|
||||||
for report in reports:
|
|
||||||
if report["closed"] == closed:
|
|
||||||
targeted_reports.append(report)
|
|
||||||
return targeted_reports
|
|
||||||
|
|
||||||
|
|
||||||
def get_reporter(report):
|
|
||||||
return server.getOfflinePlayer(juuid(report["uuid"]))
|
|
||||||
|
|
||||||
thread.start_new_thread(reports_reminder, ())
|
thread.start_new_thread(reports_reminder, ())
|
||||||
@@ -30,8 +30,10 @@ def print_lol(sender, lid):
|
|||||||
broadcast(None, "&8[&blol&8] &7%s&8: &e%s" % (dispname, lols[lid]))
|
broadcast(None, "&8[&blol&8] &7%s&8: &e%s" % (dispname, lols[lid]))
|
||||||
last_msg = time()
|
last_msg = time()
|
||||||
else:
|
else:
|
||||||
|
plugin_header(sender, "SayLol")
|
||||||
msg(sender, "&cInvalid id")
|
msg(sender, "&cInvalid id")
|
||||||
else:
|
else:
|
||||||
|
plugin_header(sender, "SayLol")
|
||||||
msg(sender, "&cYou can use SayLol again in &a%s seconds!" % int(timeout + 1 - (time() - last_msg)))
|
msg(sender, "&cYou can use SayLol again in &a%s seconds!" % int(timeout + 1 - (time() - last_msg)))
|
||||||
|
|
||||||
|
|
||||||
@@ -39,16 +41,15 @@ def search_lols(sender, keyword):
|
|||||||
if not keyword:
|
if not keyword:
|
||||||
msg(sender, "&cPlease provide a keyword to search for!")
|
msg(sender, "&cPlease provide a keyword to search for!")
|
||||||
return
|
return
|
||||||
keyword = keyword.lower()
|
|
||||||
msg(sender, "&aLols containing '&6%s&a':" % keyword)
|
msg(sender, "&aLols containing '&6%s&a':" % keyword)
|
||||||
for i, lol in enumerate(lols):
|
for i, lol in enumerate(lols):
|
||||||
if keyword in lol.lower():
|
if keyword in lol:
|
||||||
msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lol))
|
msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lol))
|
||||||
msg(sender, "") # empty line showing end of list
|
msg(sender, "") # empty line showing end of list
|
||||||
|
|
||||||
|
|
||||||
@hook.command("lol")
|
@hook.command("lol")
|
||||||
def on_lol_command(sender, command, label, args):
|
def on_lol_command(sender, args):
|
||||||
plugin_header(sender, "SayLol")
|
plugin_header(sender, "SayLol")
|
||||||
|
|
||||||
cmd = args[0] if len(args) > 0 else None
|
cmd = args[0] if len(args) > 0 else None
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
mysql_database = "jdbc:mysql://localhost/database"
|
|
||||||
mysql_user = "username"
|
|
||||||
mysql_pass = "secret"
|
|
||||||
-969
@@ -1,969 +0,0 @@
|
|||||||
#Snowbrawl
|
|
||||||
from helpers import *
|
|
||||||
import time, threading, copy
|
|
||||||
import org.bukkit.inventory.ItemStack as ItemStack
|
|
||||||
import org.bukkit.Material as Material
|
|
||||||
import org.bukkit.potion.PotionEffect as PotionEffect
|
|
||||||
import org.bukkit.potion.PotionEffectType as PotionEffectType
|
|
||||||
from java.lang import Runnable
|
|
||||||
from java.util.UUID import fromString as juuid
|
|
||||||
from operator import __contains__
|
|
||||||
from traceback import format_exc as trace
|
|
||||||
import random
|
|
||||||
from synchronize import make_synchronized
|
|
||||||
|
|
||||||
#file names
|
|
||||||
file = "snowbrawl"
|
|
||||||
|
|
||||||
#permissions
|
|
||||||
list_perm = "utils.snowbrawl.list"
|
|
||||||
modify_perm = "utils.snowbrawl.modify"
|
|
||||||
teleport_perm = "utils.snowbrawl.tp"
|
|
||||||
create_perm = "utils.snowbrawl.create"
|
|
||||||
info_perm = "utils.snowbrawl.info"
|
|
||||||
join_perm = "utils.snowbrawl.join"
|
|
||||||
quit_perm = "utils.snowbrawl.quit"
|
|
||||||
|
|
||||||
#commands - tp command does not exist
|
|
||||||
list_command = "list"
|
|
||||||
del_command = "del"
|
|
||||||
set_command = "set"
|
|
||||||
name_command = "name"
|
|
||||||
pos_command = "pos"
|
|
||||||
create_command = "create"
|
|
||||||
info_command = "info"
|
|
||||||
modify_command = "modify"
|
|
||||||
modify_command_alias = "m"
|
|
||||||
quit_command = "quit"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Arena(object):
|
|
||||||
|
|
||||||
def __init__(self, name):
|
|
||||||
self.queue = Queue()
|
|
||||||
self.name = name
|
|
||||||
self.refill = None
|
|
||||||
self.player_limit = None
|
|
||||||
self.start_time = None
|
|
||||||
self.match_goal = None # amount of deaths or time until the match ends (depends on arena_type)
|
|
||||||
self.arena_type = None # arena type (death or time)
|
|
||||||
self.explosion_damage = None
|
|
||||||
|
|
||||||
self.player_stats = {}
|
|
||||||
self.players = Queue()
|
|
||||||
self.spawn_location = []
|
|
||||||
self.respawn_location = []
|
|
||||||
self.sign_location = []
|
|
||||||
self.sign_click = []
|
|
||||||
|
|
||||||
self.corner1 = None # The corner1 given by the player (really bad for 3D position compare)
|
|
||||||
self.corner2 = None # The corner2 given by the player (really bad for 3D position compare)
|
|
||||||
self.tpp = None # The top, positive x, positive z corner
|
|
||||||
self.bnn = None # The bottom, negative x, negative z corner
|
|
||||||
|
|
||||||
#set corners of arena
|
|
||||||
def set_corner(self, sender, type):
|
|
||||||
loc = sender.getLocation()
|
|
||||||
if type == "1":
|
|
||||||
self.corner1 = Coords(loc)
|
|
||||||
elif type == "2":
|
|
||||||
self.corner2 = Coords(loc)
|
|
||||||
msg(sender, "&a-&e Arena corner %s set" % type)
|
|
||||||
self.update_corner_points()
|
|
||||||
|
|
||||||
#Compares the corner1 and corner2 locations and figures out tpp and bnn so that we dont have to do it everytime we run in_arena()
|
|
||||||
def update_corner_points(self):
|
|
||||||
self.tpp = None
|
|
||||||
self.bnn = None
|
|
||||||
if self.corner1 == None or self.corner2 == None:
|
|
||||||
return
|
|
||||||
corn1 = self.corner1.get_location()
|
|
||||||
corn2 = self.corner2.get_location()
|
|
||||||
if not corn1.getWorld().getName() == corn2.getWorld().getName():
|
|
||||||
return
|
|
||||||
|
|
||||||
top = corn1.y if corn1.y > corn2.y else corn2.y
|
|
||||||
bottom = corn1.y if corn1.y < corn2.y else corn2.y
|
|
||||||
pos_x = corn1.x if corn1.x > corn2.x else corn2.x
|
|
||||||
pos_z = corn1.z if corn1.z > corn2.z else corn2.z
|
|
||||||
neg_x = corn1.x if corn1.x < corn2.x else corn2.x
|
|
||||||
neg_z = corn1.z if corn1.z < corn2.z else corn2.z
|
|
||||||
|
|
||||||
self.tpp = Coords(corn1.getWorld(), pos_x, top, pos_z, 0, 0)
|
|
||||||
self.bnn = Coords(corn2.getWorld(), neg_x, bottom, neg_z, 0, 0)
|
|
||||||
|
|
||||||
#add sign to sign list
|
|
||||||
def add_sign(self, sender, name):
|
|
||||||
mats = set()
|
|
||||||
mats = None
|
|
||||||
block = sender.getTargetBlock(mats, 3).getState()
|
|
||||||
if isinstance(block, bukkit.block.Sign):
|
|
||||||
self.sign_click.append(NamedCoords(name, Coords(block.getLocation())))
|
|
||||||
msg(sender, "&a-&e Arena tp sign %s created and set" % name)
|
|
||||||
|
|
||||||
#Delete a sign from the sign list
|
|
||||||
def del_sign(self, sender, name):
|
|
||||||
for sign in self.sign_click:
|
|
||||||
if sign.get_name() == name:
|
|
||||||
self.sign_click.remove(sign)
|
|
||||||
msg(sender, "&a-&e Arena tp sign %s removed" % sign.get_name())
|
|
||||||
return
|
|
||||||
msg(sender, "&a-&e Arena tp sign with this name doesn't exist")
|
|
||||||
|
|
||||||
#Adds a player to the queue if they aren't already there.
|
|
||||||
def add_player(self, player):
|
|
||||||
if not self.queue.contains(player):
|
|
||||||
self.queue.put(player)
|
|
||||||
self.start_match()
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#remove a player from the queue
|
|
||||||
def remove_player(self, player):
|
|
||||||
if self.queue.contains(player):
|
|
||||||
self.queue.remove(player)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#return true if loc is inside the arena boundries
|
|
||||||
def in_arena(self, loc):
|
|
||||||
if self.tpp == None or self.bnn == None:
|
|
||||||
return False
|
|
||||||
loc_tpp = self.tpp.get_location()
|
|
||||||
loc_bnn = self.bnn.get_location()
|
|
||||||
|
|
||||||
if loc.y > loc_tpp.y:
|
|
||||||
return False
|
|
||||||
if loc.y < loc_bnn.y:
|
|
||||||
return False
|
|
||||||
if loc.x > loc_tpp.x:
|
|
||||||
return False
|
|
||||||
if loc.x < loc_bnn.x:
|
|
||||||
return False
|
|
||||||
if loc.z > loc_tpp.z:
|
|
||||||
return False
|
|
||||||
if loc.z < loc_bnn.z:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_respawn(self):
|
|
||||||
id = random.randint(0, len(self.respawn_location) - 1)
|
|
||||||
return self.respawn_location[id]
|
|
||||||
|
|
||||||
|
|
||||||
def spawn_player(self, player):
|
|
||||||
id = random.randint(0, len(self.spawn_location) - 1)
|
|
||||||
loc = self.spawn_location[id].get_location().get_location()
|
|
||||||
safetp(player, loc.getWorld(), loc.x, loc.y, loc.z, loc.yaw, loc.pitch)
|
|
||||||
|
|
||||||
#Start match
|
|
||||||
def start_match(self):
|
|
||||||
if self.player_limit == None or self.match_goal == None or self.arena_type == None or len(self.spawn_location) == 0 or len(self.respawn_location) == 0 or len(self.sign_location) == 0:
|
|
||||||
return
|
|
||||||
if len(self.queue.read()) >= self.player_limit and len(self.players.read()) == 0:
|
|
||||||
self.start_time = time.time()
|
|
||||||
for i in range(self.player_limit):
|
|
||||||
player = self.queue.get()
|
|
||||||
self.players.put(player)
|
|
||||||
for player in self.players.read():
|
|
||||||
self.player_stats[player.getName() + "_deaths"] = 0
|
|
||||||
self.spawn_player(player)
|
|
||||||
msg(player, "&6The match has started!")
|
|
||||||
|
|
||||||
def bubbleSort(self, alist):
|
|
||||||
for passnum in range(len(alist)-1,0,-1):
|
|
||||||
for i in range(passnum):
|
|
||||||
if self.player_stats[alist[i].getName()+"_deaths"]>self.player_stats[alist[i+1].getName()+"_deaths"]:
|
|
||||||
temp = alist[i]
|
|
||||||
alist[i] = alist[i+1]
|
|
||||||
alist[i+1] = temp
|
|
||||||
return alist
|
|
||||||
|
|
||||||
@make_synchronized #Jython synchronized block
|
|
||||||
def end_match(self): #End match, sort the players and print the 3 players with least amount of deaths
|
|
||||||
|
|
||||||
sorted_list = self.bubbleSort(self.players.read())
|
|
||||||
|
|
||||||
for player in self.players.read():
|
|
||||||
if player.isOnline():
|
|
||||||
loc = self.sign_location[0].get_location().get_location()
|
|
||||||
safetp(player, loc.getWorld(), loc.x, loc.y, loc.z, loc.yaw, loc.pitch)
|
|
||||||
msg(player, "&6================= Match over =================")
|
|
||||||
msg(player, "&c&c")
|
|
||||||
if not len(sorted_list) < 1:
|
|
||||||
msg(player, "&e1. %s (%s)" % (sorted_list[0].getName(), self.player_stats[sorted_list[0].getName()+"_deaths"]))
|
|
||||||
if not len(sorted_list) < 2:
|
|
||||||
msg(player, "&e2. %s (%s)" % (sorted_list[1].getName(), self.player_stats[sorted_list[1].getName()+"_deaths"]))
|
|
||||||
if not len(sorted_list) < 3:
|
|
||||||
msg(player, "&e3. %s (%s)" % (sorted_list[2].getName(), self.player_stats[sorted_list[2].getName()+"_deaths"]))
|
|
||||||
msg(player, "&c&c")
|
|
||||||
msg(player, "&e Your deaths:&6 %s" % str(self.player_stats[player.getName() + "_deaths"]))
|
|
||||||
msg(player, "&c&c")
|
|
||||||
msg(player, "&6==============================================")
|
|
||||||
self.players.clear()
|
|
||||||
self.player_stats = {}
|
|
||||||
self.start_match()
|
|
||||||
|
|
||||||
def check_deaths(self):
|
|
||||||
if self.arena_type == "death":
|
|
||||||
for player in self.players.read():
|
|
||||||
if self.player_stats[player.getName() + "_deaths"] >= self.match_goal:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def is_running(self):
|
|
||||||
if len(self.players.read()) == 0:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def set_explosion_damage(self, dmg):
|
|
||||||
self.explosion_damage = dmg
|
|
||||||
|
|
||||||
def get_explosion_damage(self):
|
|
||||||
if self.explosion_damage == None:
|
|
||||||
return 1
|
|
||||||
return self.explosion_damage
|
|
||||||
|
|
||||||
def in_players(self, player):
|
|
||||||
return self.players.contains(player)
|
|
||||||
|
|
||||||
def set_player_limit(self, limit):
|
|
||||||
self.player_limit = limit
|
|
||||||
|
|
||||||
def set_end_goal(self, value):
|
|
||||||
self.match_goal = value
|
|
||||||
|
|
||||||
def set_type(self, type):
|
|
||||||
self.arena_type = type
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def set_refill(self, amount):
|
|
||||||
self.refill = int(amount)
|
|
||||||
|
|
||||||
def set_name(self, name):
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
def get_refill(self):
|
|
||||||
if self.refill == None:
|
|
||||||
return 16
|
|
||||||
return self.refill
|
|
||||||
|
|
||||||
def get_tp_signs(self):
|
|
||||||
return self.sign_location
|
|
||||||
|
|
||||||
def get_click_signs(self):
|
|
||||||
return self.sign_click
|
|
||||||
|
|
||||||
#Check if player is in the queue
|
|
||||||
def in_queue(self,player):
|
|
||||||
if self.queue.contains(player):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#Returns queue contents in list. use "".join(queue) to get a string
|
|
||||||
def get_queue_contents(self):
|
|
||||||
return self.queue.read()
|
|
||||||
#Returns queue object
|
|
||||||
def get_queue(self):
|
|
||||||
return self.queue
|
|
||||||
|
|
||||||
#Returns list of location objects of type, type.
|
|
||||||
def get_location(self, type):
|
|
||||||
if type == "spawn":
|
|
||||||
return self.spawn_location
|
|
||||||
elif type == "respawn":
|
|
||||||
return self.respawn_location
|
|
||||||
elif type == "sign":
|
|
||||||
return self.sign_location
|
|
||||||
|
|
||||||
#Add a location to list of type location
|
|
||||||
def add_location(self, name, location, type):
|
|
||||||
named_loc = NamedCoords(name, Coords(location))
|
|
||||||
if type == "spawn":
|
|
||||||
self.spawn_location.append(named_loc)
|
|
||||||
elif type == "respawn":
|
|
||||||
self.respawn_location.append(named_loc)
|
|
||||||
elif type == "sign":
|
|
||||||
self.sign_location.append(named_loc)
|
|
||||||
|
|
||||||
#Change location of location of type, type
|
|
||||||
def change_location(self, name, location, type):
|
|
||||||
if type == "spawn":
|
|
||||||
for spawn in self.spawn_location:
|
|
||||||
if spawn.get_name() == name:
|
|
||||||
spawn.get_location().set_location(location)
|
|
||||||
break
|
|
||||||
elif type == "respawn":
|
|
||||||
for respawn in self.respawn_location:
|
|
||||||
if respawn.get_name() == name:
|
|
||||||
respawn.get_location().set_location(location)
|
|
||||||
break
|
|
||||||
elif type == "sign":
|
|
||||||
for sign in self.sign_location:
|
|
||||||
if sign.get_name() == name:
|
|
||||||
sign.get_location().set_location(location)
|
|
||||||
break
|
|
||||||
|
|
||||||
#Remove location out of location
|
|
||||||
def delete_location(self, name, type):
|
|
||||||
if type == "spawn":
|
|
||||||
for spawn in self.spawn_location[:]:
|
|
||||||
if spawn.get_name() == name:
|
|
||||||
self.spawn_location.remove(spawn)
|
|
||||||
break
|
|
||||||
elif type == "respawn":
|
|
||||||
for respawn in self.respawn_location[:]:
|
|
||||||
if respawn.get_name() == name:
|
|
||||||
self.respawn_location.remove(respawn)
|
|
||||||
break
|
|
||||||
elif type == "sign":
|
|
||||||
for sign in self.sign_location[:]:
|
|
||||||
if sign.get_name() == name:
|
|
||||||
self.sign_location.remove(sign)
|
|
||||||
break
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
spawns = []
|
|
||||||
for spawn in self.spawn_location:
|
|
||||||
spawns.append(spawn.get_data())
|
|
||||||
respawns = []
|
|
||||||
for respawn in self.respawn_location:
|
|
||||||
respawns.append(respawn.get_data())
|
|
||||||
signs = []
|
|
||||||
for sign in self.sign_location:
|
|
||||||
signs.append(sign.get_data())
|
|
||||||
sign_clicks = []
|
|
||||||
for click in self.sign_click:
|
|
||||||
sign_clicks.append(click.get_data())
|
|
||||||
corners = []
|
|
||||||
corners.append(self.corner1.get_data() if not self.corner1 == None else None)
|
|
||||||
corners.append(self.corner2.get_data() if not self.corner2 == None else None)
|
|
||||||
corners.append(self.tpp.get_data() if not self.tpp == None else None)
|
|
||||||
corners.append(self.bnn.get_data() if not self.bnn == None else None)
|
|
||||||
data = {
|
|
||||||
"spawns": spawns,
|
|
||||||
"respawns": respawns,
|
|
||||||
"signs": signs,
|
|
||||||
"clicks": sign_clicks,
|
|
||||||
"corners": corners,
|
|
||||||
"explosion": self.explosion_damage,
|
|
||||||
"players": self.player_limit,
|
|
||||||
"refill": self.refill,
|
|
||||||
"type": self.arena_type,
|
|
||||||
"goal": self.match_goal,
|
|
||||||
"name": self.name
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
|
|
||||||
def load(self, data):
|
|
||||||
self.explosion_damage = float(data["explosion"])
|
|
||||||
self.player_limit = int(data["players"])
|
|
||||||
self.refill = int(data["refill"])
|
|
||||||
self.arena_type = str(data["type"])
|
|
||||||
self.match_goal = int(data["goal"])
|
|
||||||
self.corner1 = Coords(None).load(data["corners"][0]) if not data["corners"][0] == None else None
|
|
||||||
self.corner2 = Coords(None).load(data["corners"][1]) if not data["corners"][1] == None else None
|
|
||||||
self.tpp = Coords(None).load(data["corners"][2]) if not data["corners"][2] == None else None
|
|
||||||
self.bnn = Coords(None).load(data["corners"][3]) if not data["corners"][3] == None else None
|
|
||||||
for subdata in data["spawns"]:
|
|
||||||
self.spawn_location.append(NamedCoords(None, None).load(subdata))
|
|
||||||
for subdata in data["respawns"]:
|
|
||||||
self.respawn_location.append(NamedCoords(None, None).load(subdata))
|
|
||||||
for subdata in data["signs"]:
|
|
||||||
self.sign_location.append(NamedCoords(None, None).load(subdata))
|
|
||||||
for subdata in data["clicks"]:
|
|
||||||
self.sign_click.append(NamedCoords(None, None).load(subdata))
|
|
||||||
self.name = data["name"]
|
|
||||||
return self
|
|
||||||
|
|
||||||
#coord = an instance of Coords class, adds a name to it.
|
|
||||||
class NamedCoords(object):
|
|
||||||
|
|
||||||
def __init__(self, name, coord):
|
|
||||||
self.name = name
|
|
||||||
self.coord = coord
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_location(self):
|
|
||||||
return self.coord
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
coords = self.coord.get_location()
|
|
||||||
data = {
|
|
||||||
"x": coords.x,
|
|
||||||
"y": coords.y,
|
|
||||||
"z": coords.z,
|
|
||||||
"yaw": coords.yaw,
|
|
||||||
"pitch": coords.pitch,
|
|
||||||
"world": coords.getWorld().getName(),
|
|
||||||
"name": self.name
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
|
|
||||||
def load(self, data):
|
|
||||||
self.name = str(data["name"])
|
|
||||||
self.coord = Coords(None).load(data)
|
|
||||||
return self
|
|
||||||
|
|
||||||
class Coords(object):
|
|
||||||
|
|
||||||
def __init__(self, world = None, x = None, y = None, z = None, yaw = None, pitch = None):
|
|
||||||
if world == None:
|
|
||||||
self.world = None
|
|
||||||
self.x = None
|
|
||||||
self.y = None
|
|
||||||
self.z = None
|
|
||||||
self.yaw = None
|
|
||||||
self.pitch = None
|
|
||||||
return
|
|
||||||
if not isinstance(world, Location):
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.z = z
|
|
||||||
self.yaw = yaw
|
|
||||||
self.pitch = pitch
|
|
||||||
self.world = world.getName()
|
|
||||||
else:
|
|
||||||
location = world
|
|
||||||
self.x = location.x
|
|
||||||
self.y = location.y
|
|
||||||
self.z = location.z
|
|
||||||
self.yaw = location.yaw
|
|
||||||
self.pitch = location.pitch
|
|
||||||
self.world = location.getWorld().getName()
|
|
||||||
|
|
||||||
def get_location(self):
|
|
||||||
return Location(server.getWorld(str(self.world)), float(self.x), float(self.y), float(self.z), int(self.yaw), int(self.pitch))
|
|
||||||
|
|
||||||
def set_location(self, location):
|
|
||||||
self.x = location.x
|
|
||||||
self.y = location.y
|
|
||||||
self.z = location.z
|
|
||||||
self.yaw = location.yaw
|
|
||||||
self.pitch = location.pitch
|
|
||||||
self.world = location.getWorld().getName()
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
data = {
|
|
||||||
"x": self.x,
|
|
||||||
"y": self.y,
|
|
||||||
"z": self.z,
|
|
||||||
"yaw": self.yaw,
|
|
||||||
"pitch": self.pitch,
|
|
||||||
"world": self.world
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
|
|
||||||
def load(self, data):
|
|
||||||
self.x = float(data["x"])
|
|
||||||
self.y = float(data["y"])
|
|
||||||
self.z = float(data["z"])
|
|
||||||
self.yaw = int(data["yaw"])
|
|
||||||
self.pitch = int(data["pitch"])
|
|
||||||
self.world = str(data["world"])
|
|
||||||
return self
|
|
||||||
|
|
||||||
class Queue(object):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.queue = []
|
|
||||||
|
|
||||||
#Appends to queue
|
|
||||||
def put(self,args):
|
|
||||||
self.queue.append(args)
|
|
||||||
|
|
||||||
#Returns the first item in the queue and removes it
|
|
||||||
def get(self):
|
|
||||||
if len(self.queue) > 0:
|
|
||||||
return self.queue.pop(0)
|
|
||||||
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
#Returns the queue's list object
|
|
||||||
def read(self):
|
|
||||||
return self.queue
|
|
||||||
|
|
||||||
#Removes the value args from the queue
|
|
||||||
def remove(self,args):
|
|
||||||
self.queue.remove(args)
|
|
||||||
|
|
||||||
#Check if queue contains player
|
|
||||||
def contains(self, player):
|
|
||||||
if player in self.queue:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
#Clear the queue
|
|
||||||
def clear(self):
|
|
||||||
self.queue = []
|
|
||||||
|
|
||||||
##############################################################################################
|
|
||||||
# Initialization
|
|
||||||
##############################################################################################
|
|
||||||
|
|
||||||
def save_snowbrawl():
|
|
||||||
out = []
|
|
||||||
for arena in arenas:
|
|
||||||
out.append(arena.get_data())
|
|
||||||
save_json_file(file, out)
|
|
||||||
|
|
||||||
def load_snowbrawl():
|
|
||||||
out = []
|
|
||||||
buffer = open_json_file(file, [])
|
|
||||||
for data in buffer:
|
|
||||||
out.append(Arena(None).load(data))
|
|
||||||
return out
|
|
||||||
|
|
||||||
arenas = load_snowbrawl()
|
|
||||||
|
|
||||||
##############################################################################################
|
|
||||||
# Threads
|
|
||||||
##############################################################################################
|
|
||||||
|
|
||||||
class timings_runnable(Runnable):
|
|
||||||
|
|
||||||
def __init__(self, arena):
|
|
||||||
self.arena = arena
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
self.arena.end_match()
|
|
||||||
|
|
||||||
#timings thread to end arenas if their type is time
|
|
||||||
def timings():
|
|
||||||
while True:
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.is_running():
|
|
||||||
if arena.arena_type == "time":
|
|
||||||
current_time = time.time()
|
|
||||||
start_time = arena.start_time
|
|
||||||
if arena.start_time + arena.match_goal < current_time:
|
|
||||||
timing = timings_runnable(arena)
|
|
||||||
server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"), timing)
|
|
||||||
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
|
|
||||||
timingsThread = threading.Thread(target = timings)
|
|
||||||
timingsThread.daemon = True #Thread dies if main thread dies
|
|
||||||
timingsThread.start()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##############################################################################################
|
|
||||||
# Events
|
|
||||||
##############################################################################################
|
|
||||||
|
|
||||||
@hook.event("player.PlayerMoveEvent", "high")
|
|
||||||
def onMove(event):
|
|
||||||
if event.getPlayer().getWorld().getName() != "minigames":
|
|
||||||
return
|
|
||||||
player = event.getPlayer()
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_players(player):
|
|
||||||
loc = player.getLocation()
|
|
||||||
block = player.getWorld().getBlockAt(int(loc.x), int(loc.y) - 1, int(loc.z))
|
|
||||||
if block != None:
|
|
||||||
material = block.getType()
|
|
||||||
if material == Material.SPONGE:
|
|
||||||
player.addPotionEffect(PotionEffect(PotionEffectType.JUMP, 60, 0))
|
|
||||||
elif material == Material.GLASS or material == Material.STAINED_GLASS:
|
|
||||||
player.addPotionEffect(PotionEffect(PotionEffectType.SPEED, 60, 0))
|
|
||||||
elif material == Material.OBSIDIAN:
|
|
||||||
player.addPotionEffect(PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 300, 0))
|
|
||||||
break
|
|
||||||
|
|
||||||
@hook.event("entity.PlayerDeathEvent", "high")
|
|
||||||
def onDeath(event):
|
|
||||||
if event.getEntity().getWorld().getName() != "minigames":
|
|
||||||
return
|
|
||||||
if not isinstance(event.getEntity(), bukkit.entity.Player):
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_players(event.getEntity()):
|
|
||||||
arena.player_stats[event.getEntity().getName() + "_deaths"] += 1
|
|
||||||
if arena.check_deaths():
|
|
||||||
arena.end_match()
|
|
||||||
break
|
|
||||||
|
|
||||||
@hook.event("player.PlayerRespawnEvent", "high")
|
|
||||||
def onRespawn(event):
|
|
||||||
if event.getPlayer().getWorld().getName() != "minigames":
|
|
||||||
return
|
|
||||||
player = event.getPlayer()
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_players(player):
|
|
||||||
event.setRespawnLocation(arena.get_respawn().get_location().get_location())
|
|
||||||
break
|
|
||||||
|
|
||||||
@hook.event("entity.ProjectileHitEvent", "high")
|
|
||||||
def onHit(event):
|
|
||||||
if event.getEntity().getWorld().getName() != "minigames":
|
|
||||||
return
|
|
||||||
if event.getEntity().getName() != "Snowball":
|
|
||||||
return
|
|
||||||
location = event.getEntity().getLocation()
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_arena(location):
|
|
||||||
event.getEntity().getWorld().createExplosion(location.x, location.y, location.z, float(arena.get_explosion_damage()), False, False)
|
|
||||||
break
|
|
||||||
|
|
||||||
@hook.event("player.PlayerInteractEvent", "high")
|
|
||||||
def onClick(event):
|
|
||||||
if event.getPlayer().getWorld().getName() != "minigames":
|
|
||||||
return
|
|
||||||
if str(event.getAction()) != "RIGHT_CLICK_BLOCK":
|
|
||||||
return
|
|
||||||
block = event.getClickedBlock().getState()
|
|
||||||
if event.getClickedBlock().getType() == Material.SNOW_BLOCK:
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_players(event.getPlayer()):
|
|
||||||
inv = event.getPlayer().getInventory()
|
|
||||||
inv.remove(Material.SNOW_BALL)
|
|
||||||
inv.setItemInHand(ItemStack(Material.SNOW_BALL, arena.get_refill()))
|
|
||||||
event.getPlayer().updateInventory()
|
|
||||||
break
|
|
||||||
|
|
||||||
elif isinstance(block, bukkit.block.Sign):
|
|
||||||
line = str(block.getLine(1))
|
|
||||||
if not event.getPlayer().hasPermission(join_perm):
|
|
||||||
msg(event.getPlayer(), "&a-&e You don't have permission to join snowbrawl matches")
|
|
||||||
return
|
|
||||||
#go through arenas, if name matches line then add player to it
|
|
||||||
for arena in arenas:
|
|
||||||
if line == arena.get_name():
|
|
||||||
for sign in arena.get_click_signs():
|
|
||||||
sign_loc = sign.get_location().get_location()
|
|
||||||
loc = block.getLocation()
|
|
||||||
if sign_loc.getWorld().getName() == loc.getWorld().getName() and sign_loc.x == loc.x and sign_loc.y == loc.y and sign_loc.z == loc.z:
|
|
||||||
if arena.add_player(event.getPlayer()):
|
|
||||||
msg(event.getPlayer(),"&a- &eYou have been added to the queue")
|
|
||||||
else:
|
|
||||||
msg(event.getPlayer(),"&a- &eYou are already in the queue")
|
|
||||||
break
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent", "normal")
|
|
||||||
def on_quit(event):
|
|
||||||
#remove the player from the queue
|
|
||||||
player = event.getPlayer().getName()
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_queue(player):
|
|
||||||
arena.remove_player(player)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##############################################################################################
|
|
||||||
# Command handling
|
|
||||||
##############################################################################################
|
|
||||||
|
|
||||||
|
|
||||||
def create_arena(sender, args):
|
|
||||||
if len(args) == 0:
|
|
||||||
msg(sender, "&c/sb %s <name>" % create_command)
|
|
||||||
return
|
|
||||||
arena = Arena(args[0])
|
|
||||||
arenas.append(arena)
|
|
||||||
msg(sender, "&a-&e Arena %s created" % args[0])
|
|
||||||
|
|
||||||
def list_arenas(sender):
|
|
||||||
if len(arenas) == 0:
|
|
||||||
msg(sender, "&a-&e There are currently no arenas")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
msg(sender, "&a-&e %s" % arena.get_name())
|
|
||||||
|
|
||||||
def arena_info(sender, args):
|
|
||||||
if len(args) == 0:
|
|
||||||
msg(sender, "&a-&e /sb info <name>")
|
|
||||||
return
|
|
||||||
if len(arenas) == 0:
|
|
||||||
msg(sender, "&a-&e There are currently no arenas")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == args[0]:
|
|
||||||
msg(sender, "&a-&e %s" % arena.get_name())
|
|
||||||
#msg(sender, "&ePlayers:&6 " + "&e,&6 ".join(arena.get_queue_contents()))
|
|
||||||
spawn_list = []
|
|
||||||
for spawn in arena.get_location("spawn"):
|
|
||||||
spawn_list.append(spawn.get_name())
|
|
||||||
msg(sender, "&eSpawns:&6 " + "&e,&6 ".join(spawn_list))
|
|
||||||
respawn_list = []
|
|
||||||
for respawn in arena.get_location("respawn"):
|
|
||||||
respawn_list.append(respawn.get_name())
|
|
||||||
msg(sender, "&eRespawns:&6 " + "&e,&6 ".join(respawn_list))
|
|
||||||
sign_list = []
|
|
||||||
for sign in arena.get_location("sign"):
|
|
||||||
sign_list.append(sign.get_name())
|
|
||||||
msg(sender, "&eSigns:&6 " + "&e,&6 ".join(sign_list))
|
|
||||||
break
|
|
||||||
|
|
||||||
def quit_match(sender):
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.in_queue(sender):
|
|
||||||
arena.remove_player(sender)
|
|
||||||
msg(sender, "&a-&e Quit arena")
|
|
||||||
return
|
|
||||||
msg(sender, "&a-&e You're not in a queue")
|
|
||||||
|
|
||||||
def print_help(sender):
|
|
||||||
msg(sender, "&a-&e Alias: &6/sb")
|
|
||||||
if sender.hasPermission(teleport_perm):
|
|
||||||
msg(sender, "&a-&e /sb <name> Teleport to an arena")
|
|
||||||
if sender.hasPermission(quit_perm):
|
|
||||||
msg(sender, "&a-&e /sb %s Quit a queue" % quit_command)
|
|
||||||
if sender.hasPermission(list_perm):
|
|
||||||
msg(sender, "&a-&e /sb %s List all existing arenas" % list_command)
|
|
||||||
if sender.hasPermission(create_perm):
|
|
||||||
msg(sender, "&a-&e /sb %s Create an arena" % create_command)
|
|
||||||
if sender.hasPermission(info_perm):
|
|
||||||
msg(sender, "&a-&e /sb %s Show info about an arena" % info_command)
|
|
||||||
if sender.hasPermission(modify_perm):
|
|
||||||
msg(sender, "&a-&e /sb %s Deletes an arena" % del_command)
|
|
||||||
msg(sender, "&a-&e /sb %s Sets a teleport for an arena to a sign" % set_command)
|
|
||||||
msg(sender, "&a-&e /sb %s Renames an arena" % name_command)
|
|
||||||
msg(sender, "&a-&e /sb %s Sets the locations for an arena" % pos_command)
|
|
||||||
msg(sender, "&a-&e /sb %s Modifies the arena" % modify_command)
|
|
||||||
msg(sender, "&a-&e Modify Aliases: &6/sbm&e,&6 /sb %s" % modify_command_alias)
|
|
||||||
|
|
||||||
def set_location(sender, args):
|
|
||||||
if len(args) < 3:
|
|
||||||
msg(sender, "&c/sb pos <arena name> respawn/spawn/sign set/add/del <name>")
|
|
||||||
msg(sender, "&c/sb pos <arena name> bounds corner1/corner2")
|
|
||||||
return
|
|
||||||
if "bounds" not in args:
|
|
||||||
if len(args) < 4:
|
|
||||||
msg(sender, "&c/sb pos <arena name> respawn/spawn/sign set/add/del <name>")
|
|
||||||
msg(sender, "&c/sb pos <arena name> bounds corner1/corner2")
|
|
||||||
return
|
|
||||||
if len(arenas) == 0:
|
|
||||||
msg(sender, "&a-&e There are currently no arenas")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == args[0]:
|
|
||||||
if args[1] == "respawn":
|
|
||||||
set_location_of_type(sender, args[2:], "respawn", arena)
|
|
||||||
elif args[1] == "spawn":
|
|
||||||
set_location_of_type(sender, args[2:], "spawn", arena)
|
|
||||||
elif args[1] == "sign":
|
|
||||||
set_location_of_type(sender, args[2:], "sign", arena)
|
|
||||||
elif args[1] == "bounds":
|
|
||||||
set_location_of_type(sender, args[2:], "bounds", arena)
|
|
||||||
break
|
|
||||||
|
|
||||||
def set_location_of_type(sender, args, type, arena):
|
|
||||||
if len(args) == 0:
|
|
||||||
msg(sender, "&c/sb pos <arena name> respawn/spawn/sign set/add/del <name>")
|
|
||||||
msg(sender, "&c/sb pos <arena name> bounds corner1/corner2")
|
|
||||||
return
|
|
||||||
location = sender.getLocation()
|
|
||||||
if args[0] == "set":
|
|
||||||
arena.change_location(args[1], location, type)
|
|
||||||
msg(sender, "&a-&e Location of name %s and type %s changed to your current location" % (args[1], type))
|
|
||||||
elif args[0] == "add":
|
|
||||||
arena.add_location(args[1], location, type)
|
|
||||||
msg(sender, "&a-&e Location of name %s and type %s created at your current location" % (args[1], type))
|
|
||||||
elif args[0] == "del":
|
|
||||||
arena.delete_location(args[1], type)
|
|
||||||
msg(sender, "&a-&e Location of name %s deleted" % args[1])
|
|
||||||
elif args[0] == "corner1":
|
|
||||||
arena.set_corner(sender, "1")
|
|
||||||
elif args[0] == "corner2":
|
|
||||||
arena.set_corner(sender, "2")
|
|
||||||
|
|
||||||
def rename_arena(sender, args):
|
|
||||||
if len(args) < 2:
|
|
||||||
msg(sender, "&c/sb name <name> <new name>")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == args[0]:
|
|
||||||
arena.set_name(args[1])
|
|
||||||
msg(sender, "&a-&e Arena %s renamed to %s" % (args[0], args[1]))
|
|
||||||
return
|
|
||||||
msg(sender, "&a-&e Arena with this name doesn't exist")
|
|
||||||
|
|
||||||
def delete_arena(sender, args):
|
|
||||||
if len(args) == 0:
|
|
||||||
msg(sender, "&c/sb del <name>")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == args[0]:
|
|
||||||
arenas.remove(arena)
|
|
||||||
msg(sender, "&a-&e Arena %s deleted" % arena.get_name())
|
|
||||||
return
|
|
||||||
msg(sender, "&a-&e Arena with this name doesn't exist")
|
|
||||||
|
|
||||||
def teleport_to_arena(sender, name, id):
|
|
||||||
try:
|
|
||||||
int(id)
|
|
||||||
except ValueError:
|
|
||||||
msg(sender, "&c/sb <name> <id of teleport>")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == name:
|
|
||||||
i = 0
|
|
||||||
if int(id) > len(arena.get_tp_signs()):
|
|
||||||
msg(sender, "&cGiven tp id is out of range")
|
|
||||||
return
|
|
||||||
for sign in arena.get_tp_signs():
|
|
||||||
i += 1
|
|
||||||
if i == int(id):
|
|
||||||
loc = sign.get_location().get_location()
|
|
||||||
safetp(sender, loc.getWorld(), loc.x, loc.y, loc.z, loc.yaw, loc.pitch)
|
|
||||||
break
|
|
||||||
msg(sender, "&a-&e Teleporting to arena %s" % name)
|
|
||||||
return
|
|
||||||
msg(sender, "&a-&e Arena with this name doesn't exist")
|
|
||||||
|
|
||||||
def modify_arena(sender, args):
|
|
||||||
if len(args) < 3:
|
|
||||||
msg(sender, "&c/sb modify <arena name> limit/mode/players/explosion/refill <amount/mode (death/time)>")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == args[0]:
|
|
||||||
if args[1] == "limit":
|
|
||||||
try:
|
|
||||||
int(args[2])
|
|
||||||
except ValueError:
|
|
||||||
msg(sender, "&cLast parameter has to be a number")
|
|
||||||
return
|
|
||||||
arena.set_end_goal(int(args[2]))
|
|
||||||
msg(sender, "&a-&e Set time/death limit to:&6 %s" % int(args[2]))
|
|
||||||
elif args[1] == "mode":
|
|
||||||
if args[2] == "time" or args[2] == "death":
|
|
||||||
arena.set_type(args[2])
|
|
||||||
msg(sender, "&a-&e Set mode to:&6 %s" % args[2])
|
|
||||||
else:
|
|
||||||
msg(sender, "&cInvalid mode (time, death)")
|
|
||||||
elif args[1] == "players":
|
|
||||||
try:
|
|
||||||
int(args[2])
|
|
||||||
except ValueError:
|
|
||||||
msg(sender, "&cLast parameter has to be a number")
|
|
||||||
return
|
|
||||||
arena.set_player_limit(int(args[2]))
|
|
||||||
msg(sender, "&a-&e Set player limit to:&6 %s" % int(args[2]))
|
|
||||||
elif args[1] == "explosion":
|
|
||||||
try:
|
|
||||||
float(args[2])
|
|
||||||
except ValueError:
|
|
||||||
msg(sender, "&cLast parameter has to be a number")
|
|
||||||
return
|
|
||||||
arena.set_explosion_damage(float(args[2]))
|
|
||||||
msg(sender, "&a-&e Set explosion power to:&6 %s" % float(args[2]))
|
|
||||||
elif args[1] == "refill":
|
|
||||||
try:
|
|
||||||
int(args[2])
|
|
||||||
except ValueError:
|
|
||||||
msg(sender, "&cLast parameter has to be a number")
|
|
||||||
return
|
|
||||||
arena.set_refill(int(args[2]))
|
|
||||||
msg(sender, "&a-&e Set snowball refill to:&6 %s" % int(args[2]))
|
|
||||||
return
|
|
||||||
msg(sender, "&a-&e Arena with this name doesn't exist")
|
|
||||||
|
|
||||||
def set_arena_sign(sender, args):
|
|
||||||
if len(args) < 3:
|
|
||||||
msg(sender, "&c/sb set <arena name> add/del <name>")
|
|
||||||
return
|
|
||||||
for arena in arenas:
|
|
||||||
if arena.get_name() == args[0]:
|
|
||||||
if args[1] == "add":
|
|
||||||
arena.add_sign(sender, args[2])
|
|
||||||
elif args[1] == "del":
|
|
||||||
arena.del_sign(sender, args[2])
|
|
||||||
|
|
||||||
@hook.command("snowbrawl")
|
|
||||||
def on_snowbrawl_command(sender, command, label, args):
|
|
||||||
if len(args) == 0:
|
|
||||||
#print help
|
|
||||||
plugin_header(sender, "Snowbrawl")
|
|
||||||
print_help(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == list_command:
|
|
||||||
if sender.hasPermission(list_perm):
|
|
||||||
#print the list of arenas
|
|
||||||
list_arenas(sender)
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == del_command:
|
|
||||||
if sender.hasPermission(modify_perm):
|
|
||||||
#delete an arena
|
|
||||||
delete_arena(sender, args[1:])
|
|
||||||
save_snowbrawl()
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == info_command:
|
|
||||||
if sender.hasPermission(info_perm):
|
|
||||||
#print info about an arena
|
|
||||||
arena_info(sender, args[1:])
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == create_command:
|
|
||||||
if sender.hasPermission(create_perm):
|
|
||||||
#create an arena
|
|
||||||
create_arena(sender, args[1:])
|
|
||||||
save_snowbrawl()
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == pos_command:
|
|
||||||
if sender.hasPermission(modify_perm):
|
|
||||||
#set arena spawn/respawn/sign tp locations
|
|
||||||
set_location(sender, args[1:])
|
|
||||||
save_snowbrawl()
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == name_command:
|
|
||||||
if sender.hasPermission(modify_perm):
|
|
||||||
#rename an arena
|
|
||||||
rename_arena(sender, args[1:])
|
|
||||||
save_snowbrawl()
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == set_command:
|
|
||||||
if sender.hasPermission(modify_perm):
|
|
||||||
#set an arena tp sign
|
|
||||||
set_arena_sign(sender, args[1:])
|
|
||||||
save_snowbrawl()
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == modify_command or args[0] == modify_command_alias:
|
|
||||||
if sender.hasPermission(modify_perm):
|
|
||||||
#modify the arena
|
|
||||||
modify_arena(sender, args[1:])
|
|
||||||
save_snowbrawl()
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
elif args[0] == quit_command:
|
|
||||||
if sender.hasPermission(quit_perm):
|
|
||||||
#quit match
|
|
||||||
quit_match(sender)
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
if sender.hasPermission(teleport_perm):
|
|
||||||
#try to tp to an arena
|
|
||||||
if len(args) > 1:
|
|
||||||
teleport_to_arena(sender, args[0], args[1])
|
|
||||||
else:
|
|
||||||
teleport_to_arena(sender, args[0], 1)
|
|
||||||
else:
|
|
||||||
noperm(sender)
|
|
||||||
return True
|
|
||||||
+1
-7
@@ -1,9 +1,3 @@
|
|||||||
"""
|
|
||||||
Code that was used once to create this awesome screenshot
|
|
||||||
- https://i.imgur.com/v4wg5kl.png
|
|
||||||
- https://i.imgur.com/tIZ3jmC.png
|
|
||||||
- https://www.reddit.com/r/Minecraft/comments/28le52/screenshot_of_all_players_that_joined_my_server/
|
|
||||||
"""
|
|
||||||
import net.minecraft.server.v1_7_R1.EntityPlayer as EntityPlayer
|
import net.minecraft.server.v1_7_R1.EntityPlayer as EntityPlayer
|
||||||
import net.minecraft.server.v1_7_R1.PacketPlayOutNamedEntitySpawn as PacketPlayOutNamedEntitySpawn
|
import net.minecraft.server.v1_7_R1.PacketPlayOutNamedEntitySpawn as PacketPlayOutNamedEntitySpawn
|
||||||
import net.minecraft.server.v1_7_R1.PlayerInteractManager as PlayerInteractManager
|
import net.minecraft.server.v1_7_R1.PlayerInteractManager as PlayerInteractManager
|
||||||
@@ -38,7 +32,7 @@ def spawn(dispname, sender, x, y, z):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("spawnplayer")
|
@hook.command("spawnplayer")
|
||||||
def on_spawnplayer_command(sender, command, label, args):
|
def on_spawnplayer_command(sender, args):
|
||||||
global amount, row, ground, goup
|
global amount, row, ground, goup
|
||||||
|
|
||||||
# X and Z position
|
# X and Z position
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
from helpers import *
|
|
||||||
from secrets import *
|
|
||||||
import mysqlhack
|
|
||||||
from com.ziclix.python.sql import zxJDBC
|
|
||||||
|
|
||||||
ranks = {
|
|
||||||
"member" : 3,
|
|
||||||
"builder" : 7,
|
|
||||||
"trusted" : 8,
|
|
||||||
"helper" : 9,
|
|
||||||
"trainingmod" : 10,
|
|
||||||
"mod" : 4,
|
|
||||||
"admin" : 5
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "normal")
|
|
||||||
def on_player_join(event):
|
|
||||||
user = event.getPlayer()
|
|
||||||
uuid = uid(player).replace("-", "")
|
|
||||||
role = get_role(uuid)
|
|
||||||
if role in [1, 2, 6]: #Disabled/Banned/Superadmin
|
|
||||||
return
|
|
||||||
if role:
|
|
||||||
for rank in ranks:
|
|
||||||
if user.hasPermission("group." + rank):
|
|
||||||
if role != ranks[rank]:
|
|
||||||
set_role(uuid, ranks[rank])
|
|
||||||
return
|
|
||||||
if not user.hasPlayedBefore():
|
|
||||||
return
|
|
||||||
if role == None:
|
|
||||||
msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_role(uuid):
|
|
||||||
return execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1", uuid)[0][17]
|
|
||||||
|
|
||||||
|
|
||||||
def set_role(uuid, role_id):
|
|
||||||
execute_update("UPDATE users SET `role_id` = %d WHERE `uuid` = ?" % role_id, uuid)
|
|
||||||
|
|
||||||
|
|
||||||
def execute_query(query, uuid):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute(query, (uuid,))
|
|
||||||
results = curs.fetchall()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
def execute_update(update, uuid):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute(update, (uuid,))
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
"""
|
|
||||||
A plugin that automatically tiles (stacks) blocks inside a selected region in configurable directions.
|
|
||||||
"""
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent as BlockPlaceEvent
|
import org.bukkit.event.block.BlockPlaceEvent as BlockPlaceEvent
|
||||||
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
||||||
import org.bukkit.event.player.PlayerInteractEvent as PlayerInteractEvent
|
import org.bukkit.event.player.PlayerInteractEvent as PlayerInteractEvent
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import glob
|
||||||
|
tools = []
|
||||||
|
for module_name in glob.glob("plugins/redstoner-utils.py.dir/toolbox/*.py"):
|
||||||
|
tools.append(__import__(module_name))
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
from helpers import *
|
||||||
|
|
||||||
|
gamemode_permission = {"self":"gamemode.self","other":"gamemode.other"}
|
||||||
|
|
||||||
|
# Helping functions
|
||||||
|
|
||||||
|
def setGamemode(sender, gmstring):
|
||||||
|
gmstring = gmstring.lower()
|
||||||
|
if is_player(sender):
|
||||||
|
if gmstring == "c" || gmstring == "creative" || gmstring == "1":
|
||||||
|
sender.setGameMode(GameMode.CREATIVE)
|
||||||
|
elif gmstring == "s" || gmstring == "survival" || gmstring == "0":
|
||||||
|
sender.setGameMode(GameMode.SURVIVAL)
|
||||||
|
elif gmstring == "a" || gmstring == "adventure" || gmstring == "2":
|
||||||
|
sender.setGameMode(GameMode.ADVENTURE)
|
||||||
|
else
|
||||||
|
msg(sender, "&c%s is no known gamemode (survival/creative/adventure)")
|
||||||
|
else
|
||||||
|
msg(sender, "&cYou have to be a valid player to perform this command. Try /gamemode <player> <gamemode>")
|
||||||
|
|
||||||
|
# /toolbox
|
||||||
|
@hook.command("toolbox", desc="The basic command of Toolbox")
|
||||||
|
def toolbox_command(sender, args):
|
||||||
|
msg(sender, "&6Toolbox&f is a command library written for Redstoner.com")
|
||||||
|
|
||||||
|
# /gamemode
|
||||||
|
@hook.command("gamemode", aliases=["gm"], desc="Change a player's gamemode")
|
||||||
|
def toolbox_gamemode_command(sender, args):
|
||||||
|
param1 = args[0].lower() if len(args)>0 else None
|
||||||
|
param2 = args[1] if len(args)>1 else None
|
||||||
|
|
||||||
|
if len(args) == 1:
|
||||||
|
if sender.hasPermission(gamemode_permission["self"]) || sender.hasPermission(gamemode_permission["other"]):
|
||||||
|
setGameMode(sender, param1)
|
||||||
|
else
|
||||||
|
noperm(sender)
|
||||||
|
elif len(args) == 2:
|
||||||
|
if sender.hasPermission(gamemode_permission["other"]):
|
||||||
|
if server.getPlayer(param) != None:
|
||||||
|
setGameMode(server.getPlayer(param), param2)
|
||||||
|
else
|
||||||
|
msg(sender, "&cThere's no online player called "+param)
|
||||||
+2
-2
@@ -99,13 +99,13 @@ def tokengen_command(sender, args):
|
|||||||
|
|
||||||
|
|
||||||
@hook.command("token")
|
@hook.command("token")
|
||||||
def on_token_command(sender, command, label, args):
|
def on_token_command(sender, args):
|
||||||
thread.start_new_thread(token_command, (sender,))
|
thread.start_new_thread(token_command, (sender,))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@hook.command("gettoken")
|
@hook.command("gettoken")
|
||||||
def on_gettoken_command(sender, command, label, args):
|
def on_gettoken_command(sender, args):
|
||||||
thread.start_new_thread(tokengen_command, (sender, args))
|
thread.start_new_thread(tokengen_command, (sender, args))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user