Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc6796e20f | ||
|
|
6040a27126 | ||
|
|
1c483148dc | ||
|
|
128442c062 | ||
|
|
141854f076 | ||
|
|
f72cc6764b | ||
|
|
d95ecfaa8e | ||
|
|
6c96f4e974 | ||
|
|
28cee291c6 | ||
|
|
155f32c00f | ||
|
|
071ba05d81 | ||
|
|
2ee5aea06b | ||
|
|
3bb8de6d33 | ||
|
|
79ac01da34 | ||
|
|
6e4fbb0ece | ||
|
|
167ed5e0d3 | ||
|
|
91f3304f78 | ||
|
|
7928e73a32 | ||
|
|
d61d186544 | ||
|
|
dc356e88d0 | ||
|
|
d0d5574580 | ||
|
|
29617059b3 | ||
|
|
bf05fc81dd | ||
|
|
a2c5bf70f0 | ||
|
|
ea19006465 | ||
|
|
89f685ff9a | ||
|
|
ecc76033dc | ||
|
|
e843b0711d | ||
|
|
eddfaf7df0 | ||
|
|
d1150ab5f8 | ||
|
|
cc3996ca76 | ||
|
|
1965aecfba | ||
|
|
ce34ae44d8 | ||
|
|
f5a2d7bc47 | ||
|
|
24295025ef | ||
|
|
e3f56f6498 | ||
|
|
bd0c3cff3f | ||
|
|
7c4ab035a0 | ||
|
|
2593080f77 | ||
|
|
0d4595d511 | ||
|
|
bf820c2c27 | ||
|
|
a12718d354 | ||
|
|
b23c1ae606 | ||
|
|
7c59dcbcb9 | ||
|
|
15cacba7c9 | ||
|
|
adbe88daa6 | ||
|
|
5350c012f7 | ||
|
|
a91f377cf5 | ||
|
|
c3ae5ac210 | ||
|
|
f4ce740c06 | ||
|
|
3ff8d34053 | ||
|
|
f362f09380 | ||
|
|
62b789dff5 | ||
|
|
84a9db597a | ||
|
|
89fd700e32 | ||
|
|
001a6000f8 | ||
|
|
bf61069fed | ||
|
|
d93def8b5b | ||
|
|
540394e266 | ||
|
|
425b1c80cc | ||
|
|
47ae6f5378 | ||
|
|
48601e4215 | ||
|
|
ed80083fe8 | ||
|
|
d041e0a8d1 | ||
|
|
de85be5832 | ||
|
|
81d59d8bf5 | ||
|
|
0c2d2f4e0a | ||
|
|
3d9108fb48 | ||
|
|
25c616bc32 | ||
|
|
148187025a | ||
|
|
115b0dc078 | ||
|
|
78bf6ba3bf | ||
|
|
e31c391af4 | ||
|
|
6ed4be9a64 | ||
|
|
d626e7e4b1 | ||
|
|
e7dd4fee51 | ||
|
|
146075de69 | ||
|
|
9fce6c54f6 | ||
|
|
f189eb3b7e | ||
|
|
ed77cacb1a | ||
|
|
2d4fe301cf | ||
|
|
e5fe1fe565 | ||
|
|
83010f1a28 | ||
|
|
864e50e38c | ||
|
|
0a99258f3e | ||
|
|
cfae997de4 | ||
|
|
b345baf20e | ||
|
|
d532052c7b | ||
|
|
1c02fb4387 | ||
|
|
2a99649e1e | ||
|
|
994bf922af | ||
|
|
36094e2bea | ||
|
|
6243b41956 | ||
|
|
32170cc089 | ||
|
|
c1a3d48944 | ||
|
|
75855826e7 | ||
|
|
d35363b10c | ||
|
|
ad1b733498 | ||
|
|
9159dfbb7d | ||
|
|
b8acd339b3 | ||
|
|
51e035eb3e | ||
|
|
2fd8e3edc3 | ||
|
|
faf20ee36e | ||
|
|
e1494808f3 | ||
|
|
05cf052204 | ||
|
|
242f05fc77 | ||
|
|
dd29fcc1dd | ||
|
|
d5013546d1 | ||
|
|
058c0837f0 | ||
|
|
e01c646562 | ||
|
|
3afca50930 | ||
|
|
94ca18e95c | ||
|
|
707eae92a8 | ||
|
|
b4a4519876 | ||
|
|
4f41b7aa6e | ||
|
|
b9267a3dfc | ||
|
|
a53c4214f0 | ||
|
|
343695e23e | ||
|
|
e17e9c8ce9 | ||
|
|
676c3a2e3d | ||
|
|
e821611744 | ||
|
|
d69c492577 | ||
|
|
eb91eefc80 | ||
|
|
f570c81366 | ||
|
|
b3f23278b1 | ||
|
|
3fa2bfa7cf | ||
|
|
582d6bef1a | ||
|
|
04c65cc59e | ||
|
|
268c4982c3 | ||
|
|
8983a0c024 | ||
|
|
1cbe901e4d | ||
|
|
4894abd1f1 | ||
|
|
1fac13247f | ||
|
|
59cfacf007 | ||
|
|
5f916fbf27 | ||
|
|
c70e254dbf | ||
|
|
9d42a05759 | ||
|
|
46f8453b5b | ||
|
|
b4b0940918 | ||
|
|
22ad7214b0 | ||
|
|
1ba693ffd5 | ||
|
|
6ee0d8a05e | ||
|
|
d3ff2922fd | ||
|
|
5e2824abeb | ||
|
|
926e23bf19 | ||
|
|
841598232c | ||
|
|
540b6abcab | ||
|
|
38d5917915 | ||
|
|
da6bd20b42 | ||
|
|
8859fa78fd | ||
|
|
4de6b9ce47 | ||
|
|
f595f4cdb9 | ||
|
|
1581e1e009 | ||
|
|
7cb9bd4bc2 | ||
|
|
32e72bb355 | ||
|
|
950402a144 | ||
|
|
f598551d9c | ||
|
|
c3f08318d4 | ||
|
|
f0343b08b5 | ||
|
|
20a1fcb9f5 | ||
|
|
253ede1c9a | ||
|
|
d4454703e4 | ||
|
|
9737b62813 | ||
|
|
06bd1a838f | ||
|
|
4343167240 | ||
|
|
7762aca019 | ||
|
|
6ebc1188e8 | ||
|
|
8b358b0955 | ||
|
|
b201b09719 | ||
|
|
4c9d108f08 | ||
|
|
564a7d3684 | ||
|
|
d832e9e6d9 | ||
|
|
aa574b6236 | ||
|
|
d7894eb847 | ||
|
|
5e067fa72d | ||
|
|
b1bf68a0ad | ||
|
|
89a8f24b14 | ||
|
|
43ecdc913a | ||
|
|
0f14ee557d | ||
|
|
9b88d1d491 | ||
|
|
606a3fa3ce | ||
|
|
a7cace0fdc | ||
|
|
ae314108a3 | ||
|
|
d0180f05d5 | ||
|
|
07df8d0d09 | ||
|
|
4552f70f7e | ||
|
|
a6912c3cb5 | ||
|
|
4bdeacfd05 | ||
|
|
01f549f408 | ||
|
|
f7bbb5029b | ||
|
|
658b5219c3 | ||
|
|
fb505ab161 | ||
|
|
284b3179ad | ||
|
|
532ffacf5a | ||
|
|
2b4d386eb2 | ||
|
|
bc20ecbe60 | ||
|
|
4878395460 | ||
|
|
467ec809b5 | ||
|
|
ceb6850670 | ||
|
|
63abf33414 | ||
|
|
bcd7fcaee7 | ||
|
|
d18581828d | ||
|
|
54209e1535 | ||
|
|
2ed59a866f | ||
|
|
41b3096600 | ||
|
|
42adfa8175 | ||
|
|
12bcf71028 | ||
|
|
a826d0b2ff | ||
|
|
59cab8a417 | ||
|
|
da6a62b984 | ||
|
|
806c5909c4 | ||
|
|
c00847f173 | ||
|
|
626e5d3e4b | ||
|
|
f5e8a9c2e8 | ||
|
|
3364709e53 | ||
|
|
67d172fd08 | ||
|
|
f3a420d85c | ||
|
|
aba1f05c5b | ||
|
|
8fdc0ad3da | ||
|
|
3db57ee1d9 | ||
|
|
b3841adcc1 | ||
|
|
0b0b3c0088 | ||
|
|
a64a8d9605 | ||
|
|
0a0d3ba527 | ||
|
|
a351fbb345 | ||
|
|
46359cfbfe | ||
|
|
f52004cb76 | ||
|
|
0e3848874a | ||
|
|
71ba31a0f4 | ||
|
|
7b1e77340b | ||
|
|
bebd4742b9 | ||
|
|
b933027523 | ||
|
|
bd1d852393 | ||
|
|
648365f336 | ||
|
|
12b6a69146 | ||
|
|
cd312c3ab9 | ||
|
|
d2d243caec | ||
|
|
865434d1b1 | ||
|
|
0858e324dd | ||
|
|
618986e216 | ||
|
|
cc3dfe9fd4 | ||
|
|
6ee8466ac0 | ||
|
|
3b7dd21440 | ||
|
|
528dc25fcb | ||
|
|
762d8e3ebb | ||
|
|
ef251c256d | ||
|
|
da3015c72c | ||
|
|
601f457e6f | ||
|
|
ec805f38d7 | ||
|
|
61710369f4 | ||
|
|
4824d53fab | ||
|
|
65cc817573 | ||
|
|
9bb7dd6e5d | ||
|
|
fadb3280e3 | ||
|
|
b64dfa34af | ||
|
|
584a81fac6 | ||
|
|
4233e4f8b4 | ||
|
|
28da4aac2f | ||
|
|
c37dd803c8 | ||
|
|
27abb55006 | ||
|
|
c607aa1c47 | ||
|
|
79f8f6bd55 | ||
|
|
1446dd936a | ||
|
|
8664f56eeb | ||
|
|
1c2514d5db | ||
|
|
34c8b7cf0b | ||
|
|
63af4370b5 | ||
|
|
832e0f6497 | ||
|
|
b198942742 | ||
|
|
b60250287e | ||
|
|
86ba242f33 | ||
|
|
0639d39d5a | ||
|
|
ee745f8a55 | ||
|
|
243fc8bc20 | ||
|
|
807730805c | ||
|
|
c8abdf00b5 | ||
|
|
21aaf4a03e | ||
|
|
8ea639eba8 | ||
|
|
a7e6fd1412 | ||
|
|
636b8289f6 | ||
|
|
79290eed0d | ||
|
|
9f927605da | ||
|
|
e69b5a6b17 | ||
|
|
cbe6c2c901 | ||
|
|
875685b705 | ||
|
|
ad6f0d1b62 | ||
|
|
4a66a2f5bb | ||
|
|
a8040abd52 | ||
|
|
72a14719ac | ||
|
|
2b827a1fae | ||
|
|
e45520c43b | ||
|
|
0fb33d12d6 | ||
|
|
ebe44ed99e | ||
|
|
23ba7fe73b | ||
|
|
4efa97ee0e | ||
|
|
ce80fc190d | ||
|
|
8bfe3a5473 | ||
|
|
07a38e3e58 | ||
|
|
360c63fad9 | ||
|
|
2a5edc4f91 | ||
|
|
dba21cadaf | ||
|
|
fa9191dd8f | ||
|
|
4043d5abcb | ||
|
|
eff56f74da | ||
|
|
d97a9bccde | ||
|
|
55741b524d | ||
|
|
186d3f15a4 | ||
|
|
841f6f05df | ||
|
|
ebc2a516bb | ||
|
|
9e029ad6ae | ||
|
|
b2135a8f42 | ||
|
|
8cbffd1cee | ||
|
|
ff22077adf | ||
|
|
60c0a1ab92 | ||
|
|
58eeecbcb8 | ||
|
|
876456b932 | ||
|
|
18db50ca56 | ||
|
|
cce1ccc967 | ||
|
|
e5537dd8f1 | ||
|
|
0c7ba2ae67 | ||
|
|
bbfc672582 | ||
|
|
a65dc4966b | ||
|
|
4780f87278 | ||
|
|
b11d911e4a | ||
|
|
155aad8bf2 | ||
|
|
6e1d4ef961 | ||
|
|
cfa5a04e3a | ||
|
|
7d1c47c2fc | ||
|
|
957c55955d | ||
|
|
0226ab9609 | ||
|
|
b888561d98 | ||
|
|
f210851294 | ||
|
|
73e394d5ec | ||
|
|
63f8811b67 | ||
|
|
d01ce71343 | ||
|
|
fe00aae7e3 | ||
|
|
d4347d0cff | ||
|
|
b033d59b8a | ||
|
|
aedbfd7bab | ||
|
|
b93822502e | ||
|
|
f053f0546b | ||
|
|
af3b3d0fab | ||
|
|
b1fa677330 | ||
|
|
9691a0f978 | ||
|
|
0b1a387003 | ||
|
|
4ce503f55e | ||
|
|
74947a7efd | ||
|
|
85cd71cb8a | ||
|
|
3ad7d86f74 | ||
|
|
ac9194ec87 | ||
|
|
96e8208f3d | ||
|
|
895360ce8b | ||
|
|
59e34ef353 | ||
|
|
11e556c099 | ||
|
|
a9579a6594 | ||
|
|
5a1fe2a9e5 |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 💬 Multiverse Discord Server
|
||||
url: https://discord.gg/NZtfKky
|
||||
about: Need help with using Multiverse-Core or just want to chat with the devs? Join the Multiverse Discord Server for help!
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
name: ❓ Help!
|
||||
about: Encountered a problem with Multiverse-Core? Not sure how to fix it?
|
||||
title: ''
|
||||
labels: 'Type: Assistance'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Multiverse-Core help guide
|
||||
|
||||
Don't write inside the arrows as they will be hidden when you post your issue.
|
||||
|
||||
Get latest build from: http://ci.onarandombox.com/view/Multiverse/
|
||||
|
||||
If you need help other submodules of Multiverse, go to their respective git repo:
|
||||
Multiverse-Portals: https://github.com/Multiverse/Multiverse-Portals/issues
|
||||
Multiverse-NetherPortals: https://github.com/Multiverse/Multiverse-NetherPortals/issues
|
||||
Multiverse-Inventories: https://github.com/Multiverse/Multiverse-Inventories/issues
|
||||
Multiverse-SignPortals: https://github.com/Multiverse/Multiverse-SignPortals/issues
|
||||
|
||||
Or come join our Discord server to get help sooner: https://discord.gg/NZtfKky
|
||||
|
||||
If you're happy to wait (or you were sent here from Discord), read on:
|
||||
|
||||
1. Check the Usage and FAQ pages to see if it answers your queries:
|
||||
https://github.com/Multiverse/Multiverse-Core/wiki/Basics
|
||||
https://github.com/Multiverse/Multiverse-Core/wiki/FAQ
|
||||
|
||||
2. Fill out the template.
|
||||
This will help us understand what problem you've encountered and help us
|
||||
find a solution.
|
||||
|
||||
3. When linking files, do not attach them to the post!
|
||||
Copy and paste any logs into https://gist.github.com/ or other similar service.
|
||||
|
||||
4. Delete this line and all above lines before posting your issue! -->
|
||||
|
||||
### Information
|
||||
|
||||
* **Server version:** <!-- Insert output of `/version` command -->
|
||||
|
||||
* **Full output of `/mv version -p`:** <!-- Replace this with the command output's https://paste.gg/ link -->
|
||||
|
||||
* **Server log:** <!-- Upload `logs/latest.log` to https://gist.github.com/ -->
|
||||
|
||||
### Help request
|
||||
|
||||
**Problem**
|
||||
<!-- What problem did you encounter? -->
|
||||
|
||||
**What I have tried**
|
||||
<!-- What have you tried so far? -->
|
||||
|
||||
**Screenshots**
|
||||
<!-- If relevant, include any screenshots here. -->
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: 🐛 Report a Bug
|
||||
about: Report a Multiverse-Core bug. Only use this if you're 100% sure it's something wrong with Multiverse-Core - otherwise, try "Help!".
|
||||
title: ''
|
||||
labels: 'Bug: Unconfirmed'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Multiverse-Core bug reporting guide
|
||||
|
||||
Don't put anything inside this block, as it won't be included in the issue.
|
||||
|
||||
Get latest build from: http://ci.onarandombox.com/view/Multiverse/
|
||||
|
||||
If you are having issues with other submodules of Multiverse, go to their respective git repo:
|
||||
Multiverse-Portals: https://github.com/Multiverse/Multiverse-Portals/issues
|
||||
Multiverse-NetherPortals: https://github.com/Multiverse/Multiverse-NetherPortals/issues
|
||||
Multiverse-Inventories: https://github.com/Multiverse/Multiverse-Inventories/issues
|
||||
Multiverse-SignPortals: https://github.com/Multiverse/Multiverse-SignPortals/issues
|
||||
|
||||
If you are reporting a bug, please follow the following steps:
|
||||
|
||||
1. Fill out the template in full.
|
||||
Run the commands in the console. Don't just put "latest" as a version,
|
||||
or we will ignore it.
|
||||
|
||||
2. When linking files, do not attach them to the post!
|
||||
Copy and paste any logs into https://gist.github.com/, then paste a
|
||||
link to them in the relevant parts of the template.
|
||||
**DO NOT drag files into this box!**
|
||||
|
||||
3. Make sure not to write between the arrows, as anything there will be
|
||||
hidden.
|
||||
|
||||
4. Delete this line and all above lines before posting your issue! -->
|
||||
|
||||
### Information
|
||||
|
||||
* **Server version:** <!-- Insert output of `/version` command -->
|
||||
|
||||
* **Full output of `/mv version -p`:** <!-- Replace this with the command output's https://paste.gg/ link -->
|
||||
|
||||
* **Server log:** <!-- Upload `logs/latest.log` to https://gist.github.com/ -->
|
||||
|
||||
### Details
|
||||
I was **`<able / not able>`** to reproduce my issue on a freshly setup and up-to-date server with the latest version of Multiverse plugins with no other plugins and with no kinds of other server or client mods.
|
||||
|
||||
**Description**
|
||||
<!-- Replace this with a brief summary of the bug. -->
|
||||
|
||||
**Steps to reproduce**
|
||||
<!-- Replace this with exactly what you did to cause the bug. -->
|
||||
|
||||
**Expected behavior**
|
||||
<!-- Replace this with what you expected to happen. -->
|
||||
|
||||
**Screenshots**
|
||||
<!-- Replace this with screenshots, if necessary. -->
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
name: 💡 Request a Feature
|
||||
about: Suggest a feature you want to see in Multiverse-Core!
|
||||
title: ''
|
||||
labels: 'Type: Idea'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Multiverse-Core feature request guide
|
||||
|
||||
Fill out the template. Don't write inside the arrows as they will be hidden
|
||||
when you post your issue.
|
||||
|
||||
Get latest build from: http://ci.onarandombox.com/view/Multiverse/
|
||||
|
||||
If you are look for other submodules of Multiverse, go to their respective git repo:
|
||||
Multiverse-Portals: https://github.com/Multiverse/Multiverse-Portals/issues
|
||||
Multiverse-NetherPortals: https://github.com/Multiverse/Multiverse-NetherPortals/issues
|
||||
Multiverse-Inventories: https://github.com/Multiverse/Multiverse-Inventories/issues
|
||||
Multiverse-SignPortals: https://github.com/Multiverse/Multiverse-SignPortals/issues
|
||||
|
||||
Not sure if your feature fits in Multiverse-Core? Feel free to ask on our Discord
|
||||
server: https://discord.gg/NZtfKky
|
||||
|
||||
If you have a feature suggestion for Multiverse-Core, read the following tips:
|
||||
|
||||
1. Fill out the template.
|
||||
This will help us understand what you're requesting and why you want us
|
||||
to add it.
|
||||
|
||||
2. Keep it simple.
|
||||
Make sure it's easy to understand what you're requesting. A good way is
|
||||
to keep it to one request per GitHub issue, as we can then easily track
|
||||
feature requests.
|
||||
|
||||
3. Check whether it has already been asked or added.
|
||||
You can search the issue tracker to see if your feature has already been
|
||||
requested at https://github.com/Multiverse/Multiverse-Core/issues.
|
||||
|
||||
4. Ask yourself: "Does this belong in Multiverse-Core?"
|
||||
There are lots of features that we reject because most servers won't
|
||||
need or use them. If your feature is very specific or already exists in
|
||||
another plugin, it might not be a good fit for Multiverse-Core.
|
||||
|
||||
5. Delete this line and all above lines before posting your issue! -->
|
||||
|
||||
### Feature request
|
||||
|
||||
**Feature description**
|
||||
<!-- What feature are you suggesting? -->
|
||||
|
||||
**How the feature is useful**
|
||||
<!-- How is the feature useful to players, server owners and/or developers? -->
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
# maven
|
||||
/target
|
||||
dependency-reduced-pom.xml
|
||||
|
||||
# vim
|
||||
.*.sw[a-p]
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
notifications:
|
||||
email: false
|
||||
dist: trusty
|
||||
@@ -13,3 +13,4 @@ Copyright (c) 2011, The Multiverse Team All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the The Multiverse Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
@@ -104,7 +104,6 @@
|
||||
</module>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="RightCurly"/>
|
||||
<module name="DoubleCheckedLocking"/>
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<module name="HiddenField">
|
||||
@@ -116,7 +115,6 @@
|
||||
<property name="ignoreNumbers" value="-1, 0, 0.5, 1, 2, 3"/>
|
||||
</module>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="RedundantThrows"/>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
<!-- Don't like errors for `final` missing
|
||||
|
||||
@@ -3,32 +3,36 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.onarandombox.multiversecore</groupId>
|
||||
<artifactId>Multiverse-Core</artifactId>
|
||||
<version>2.5</version>
|
||||
<version>4.3.0</version>
|
||||
<name>Multiverse-Core</name>
|
||||
<description>World Management Plugin</description>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.build.number>UNKNOWN</project.build.number>
|
||||
<project.bitly-access-token>bitly-access-token</project.bitly-access-token>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<!-- Spigot -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>onarandombox</id>
|
||||
<url>http://repo.onarandombox.com/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Bukkit Official</id>
|
||||
<url>http://repo.bukkit.org/content/repositories/public</url>
|
||||
<id>spigot</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<!-- Required for Metrics -->
|
||||
<repository>
|
||||
<id>mcstats</id>
|
||||
<url>http://repo.mcstats.org/content/repositories/snapshots</url>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<!-- Required for Vault -->
|
||||
<repository>
|
||||
<id>herocraft</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything/</url>
|
||||
<id>minebench-repo</id>
|
||||
<url>https://repo.minebench.de/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -62,6 +66,17 @@
|
||||
<project.build.number>${env.BUILD_NUMBER}</project.build.number>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>bitly</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env.BITLY_ACCESS_TOKEN</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<project.bitly-access-token>${env.BITLY_ACCESS_TOKEN}</project.bitly-access-token>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
@@ -71,39 +86,62 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||
<artifactId>maven-replacer-plugin</artifactId>
|
||||
<version>1.3.8</version>
|
||||
<version>1.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>replace-bitly-access-token</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>replace</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<basedir>${project.build.sourceDirectory}</basedir>
|
||||
<includes>
|
||||
<include>com/onarandombox/MultiverseCore/utils/webpaste/BitlyURLShortener.java</include>
|
||||
</includes>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>bitly-access-token</token>
|
||||
<value>${project.bitly-access-token}</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>replace-maven-version-number</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>replace</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<basedir>${project.build.directory}/classes</basedir>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>maven-version-number</token>
|
||||
<value>${project.version}-b${project.build.number}</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<file>target/classes/plugin.yml</file>
|
||||
<replacements>
|
||||
<replacement>
|
||||
<token>maven-version-number</token>
|
||||
<value>${project.version}-b${project.build.number}</value>
|
||||
</replacement>
|
||||
</replacements>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Jar Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<version>3.0.2</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
@@ -114,7 +152,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.11</version>
|
||||
<version>3.0.0-M3</version>
|
||||
<configuration>
|
||||
<parallel>methods</parallel>
|
||||
<threadCount>10</threadCount>
|
||||
@@ -127,14 +165,14 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-junit47</artifactId>
|
||||
<version>2.11</version>
|
||||
<version>3.0.0-M3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<version>2.17</version>
|
||||
<configuration>
|
||||
<enableRulesSummary>true</enableRulesSummary>
|
||||
<configLocation>${project.basedir}/config/mv_checks.xml</configLocation>
|
||||
@@ -143,7 +181,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
@@ -156,7 +194,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<version>2.10.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>javadoc-jar</id>
|
||||
@@ -164,13 +202,16 @@
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -178,36 +219,23 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>me.main__.util:SerializationConfig</include>
|
||||
<include>com.pneumaticraft.commandhandler:CommandHandler</include>
|
||||
<include>com.dumptruckman.minecraft:buscript</include>
|
||||
<include>org.mcstats:metrics</include>
|
||||
<include>com.dumptruckman.minecraft:Logging</include>
|
||||
<include>com.fernferret.allpay:AllPay</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.fernferret.allpay</pattern>
|
||||
<shadedPattern>com.fernferret.allpay.multiverse</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>me.main__.util</pattern>
|
||||
<shadedPattern>me.main__.util.multiverse</shadedPattern>
|
||||
<shadedPattern>com.onarandombox.serializationconfig</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.pneumaticraft.commandhandler</pattern>
|
||||
<shadedPattern>com.pneumaticraft.commandhandler.multiverse</shadedPattern>
|
||||
<shadedPattern>com.onarandombox.commandhandler</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>buscript</pattern>
|
||||
<shadedPattern>buscript.multiverse</shadedPattern>
|
||||
<shadedPattern>com.onarandombox.buscript</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>org.mcstats.multiverse</shadedPattern>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>com.onarandombox.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.dumptruckman.minecraft.util.Logging</pattern>
|
||||
@@ -217,133 +245,150 @@
|
||||
<pattern>com.dumptruckman.minecraft.util.DebugLog</pattern>
|
||||
<shadedPattern>com.onarandombox.MultiverseCore.utils.DebugFileLogger</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.codehaus.jettison</pattern>
|
||||
<shadedPattern>com.onarandombox.jettison</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.themoep.idconverter</pattern>
|
||||
<shadedPattern>com.onarandombox.idconverter</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>se.eris</groupId>
|
||||
<artifactId>notnull-instrumenter-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>instrument</goal>
|
||||
<goal>tests-instrument</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<notNull>
|
||||
<param>org.jetbrains.annotations.NotNull</param>
|
||||
<param>javax.validation.constraints.NotNull</param>
|
||||
</notNull>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Bukkit Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.3.2-R2.1-SNAPSHOT</version>
|
||||
<!-- If you want the lates, use this -->
|
||||
<!-- <version>LATEST</version> -->
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Bukkit Dependency -->
|
||||
<!-- Start of Spout (disabled because we aren't using it)
|
||||
<dependency>
|
||||
<groupId>org.getspout</groupId>
|
||||
<artifactId>spoutpluginapi</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</dependency>
|
||||
End of Spout -->
|
||||
<!-- SerializationConfig Dependency -->
|
||||
<dependency>
|
||||
<groupId>me.main__.util</groupId>
|
||||
<artifactId>SerializationConfig</artifactId>
|
||||
<version>1.6b</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<version>1.7</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- End of SerializationConfig Dependency -->
|
||||
<!-- Start of Economy Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.fernferret.allpay</groupId>
|
||||
<artifactId>AllPay</artifactId>
|
||||
<version>10</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.19-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- End of Economy Dependency -->
|
||||
<!-- Start of CommandHandler Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.pneumaticraft.commandhandler</groupId>
|
||||
<artifactId>CommandHandler</artifactId>
|
||||
<version>7</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<version>11</version>
|
||||
</dependency>
|
||||
<!-- End of CommandHandler Dependency -->
|
||||
<!-- Start of Buscript Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.dumptruckman.minecraft</groupId>
|
||||
<artifactId>buscript</artifactId>
|
||||
<version>1.0</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- End of Buscript Dependency -->
|
||||
<!-- Start of Metrics Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.mcstats</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
</dependency>
|
||||
<!-- End of Metrics Dependency -->
|
||||
<!-- Start of Logging Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.dumptruckman.minecraft</groupId>
|
||||
<artifactId>Logging</artifactId>
|
||||
<version>1.0.6</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!-- End of Logging Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>16.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.themoep.idconverter</groupId>
|
||||
<artifactId>mappings</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<version>2.0.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<version>2.0.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<version>2.0.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.0</version>
|
||||
<version>4.0.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- End of Test Dependencies -->
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>OnARandomBox</id>
|
||||
<url>http://repo.onarandombox.com/content/repositories/multiverse</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>OnARandomBox</id>
|
||||
<url>http://repo.onarandombox.com/content/repositories/multiverse-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -7,10 +7,24 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
|
||||
import com.onarandombox.MultiverseCore.api.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.api.LocationManipulation;
|
||||
@@ -18,7 +32,6 @@ import com.onarandombox.MultiverseCore.api.MVPlugin;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.commands.AnchorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CheckCommand;
|
||||
@@ -30,6 +43,8 @@ import com.onarandombox.MultiverseCore.commands.CreateCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DebugCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DeleteCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GameruleCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GamerulesCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.GeneratorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.HelpCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ImportCommand;
|
||||
@@ -47,11 +62,13 @@ import com.onarandombox.MultiverseCore.commands.ReloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RemoveCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ScriptCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SetSpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SilentCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.SpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.VersionCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.WhoCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.BedDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
@@ -59,65 +76,58 @@ import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.destination.ExactDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVMapListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPluginListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWorldInitListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVWorldListener;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.CompatibilityLayer;
|
||||
import com.onarandombox.MultiverseCore.utils.MVEconomist;
|
||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||
import com.onarandombox.MultiverseCore.utils.MaterialConverter;
|
||||
import com.onarandombox.MultiverseCore.utils.TestingMode;
|
||||
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
|
||||
/**
|
||||
* The implementation of the Multiverse-{@link Core}.
|
||||
*/
|
||||
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listener {
|
||||
private static final int PROTOCOL = 18;
|
||||
public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private static final int PROTOCOL = 24;
|
||||
// TODO: Investigate if this one is really needed to be static.
|
||||
// Doubt it. -- FernFerret
|
||||
private static Map<String, String> teleportQueue = new HashMap<String, String>();
|
||||
@@ -126,6 +136,21 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// TODO please let's make this non-static
|
||||
private volatile MultiverseCoreConfiguration config;
|
||||
|
||||
public MultiverseCore() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is for unit testing.
|
||||
* @param loader The PluginLoader to use.
|
||||
* @param description The Description file to use.
|
||||
* @param dataFolder The folder that other datafiles can be found in.
|
||||
* @param file The location of the plugin.
|
||||
*/
|
||||
public MultiverseCore(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||
super(loader, description, dataFolder, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to find out who is teleporting a player.
|
||||
* @param playerName The teleported player (the teleportee).
|
||||
@@ -147,15 +172,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
* @param teleportee The name of the player that was teleported.
|
||||
*/
|
||||
public static void addPlayerToTeleportQueue(String teleporter, String teleportee) {
|
||||
Logging.finest( "Adding mapping '%s' => '%s' to teleport queue", teleporter, teleportee);
|
||||
Logging.finest("Adding mapping '%s' => '%s' to teleport queue", teleporter, teleportee);
|
||||
teleportQueue.put(teleportee, teleporter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "The Multiverse-Core Plugin";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This is now deprecated, nobody needs it any longer.
|
||||
@@ -185,6 +205,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
|
||||
// Setup our Map for our Commands using the CommandHandler.
|
||||
private CommandHandler commandHandler;
|
||||
private CommandQueueManager commandQueueManager;
|
||||
|
||||
private static final String LOG_TAG = "[Multiverse-Core]";
|
||||
|
||||
@@ -199,24 +220,22 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// Setup the block/player/entity listener.
|
||||
private final MVPlayerListener playerListener = new MVPlayerListener(this);
|
||||
private final MVEntityListener entityListener = new MVEntityListener(this);
|
||||
private final MVPluginListener pluginListener = new MVPluginListener(this);
|
||||
private final MVWeatherListener weatherListener = new MVWeatherListener(this);
|
||||
private final MVPortalListener portalListener = new MVPortalListener(this);
|
||||
private final MVWorldListener worldListener = new MVWorldListener(this);
|
||||
private MVChatListener chatListener;
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
private HashMap<String, MVPlayerSession> playerSessions;
|
||||
private Economy vaultEco = null;
|
||||
private GenericBank bank = null;
|
||||
private AllPay banker;
|
||||
private MVEconomist economist;
|
||||
private Buscript buscript;
|
||||
private int pluginCount;
|
||||
private DestinationFactory destFactory;
|
||||
//private SpoutInterface spoutInterface = null;
|
||||
private MultiverseMessaging messaging;
|
||||
private BlockSafety blockSafety;
|
||||
private LocationManipulation locationManipulation;
|
||||
private SafeTTeleporter safeTTeleporter;
|
||||
private UnsafeCallWrapper unsafeCallWrapper;
|
||||
|
||||
private File serverFolder = new File(System.getProperty("user.dir"));
|
||||
|
||||
@@ -225,7 +244,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// Register our config
|
||||
SerializationConfig.registerAll(MultiverseCoreConfiguration.class);
|
||||
// Register our world
|
||||
SerializationConfig.registerAll(MVWorld.class);
|
||||
SerializationConfig.registerAll(WorldProperties.class);
|
||||
// Create our DataFolder
|
||||
getDataFolder().mkdirs();
|
||||
// Setup our Debug Log
|
||||
@@ -237,33 +256,20 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
this.locationManipulation = new SimpleLocationManipulation();
|
||||
// Setup our SafeTTeleporter
|
||||
this.safeTTeleporter = new SimpleSafeTTeleporter(this);
|
||||
this.unsafeCallWrapper = new UnsafeCallWrapper(this);
|
||||
// Setup our CompatibilityLayer
|
||||
CompatibilityLayer.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public FileConfiguration getMVConfiguration() {
|
||||
return this.multiverseConfig;
|
||||
public VaultHandler getVaultHandler() {
|
||||
return getEconomist().getVaultHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public GenericBank getBank() {
|
||||
return this.bank;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Economy getVaultEconomy() {
|
||||
return vaultEco;
|
||||
public MVEconomist getEconomist() {
|
||||
return economist;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,10 +277,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(new MVWorldInitListener(this), this);
|
||||
|
||||
this.messaging = new MVMessaging();
|
||||
this.banker = new AllPay(this, LOG_TAG + " ");
|
||||
// Output a little snippet to show it's enabled.
|
||||
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + PROTOCOL + ") Enabled - By " + getAuthors());
|
||||
this.economist = new MVEconomist(this);
|
||||
// Load the defaultWorldGenerators
|
||||
this.worldManager.getDefaultWorldGenerators();
|
||||
|
||||
@@ -282,10 +288,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
|
||||
this.ph = new MVPermissions(this);
|
||||
|
||||
this.bank = this.banker.loadEconPlugin();
|
||||
|
||||
// Setup the command manager
|
||||
this.commandHandler = new CommandHandler(this, this.ph);
|
||||
this.commandQueueManager = new CommandQueueManager(this);
|
||||
// Call the Function to assign all the Commands to their Class.
|
||||
this.registerCommands();
|
||||
|
||||
@@ -303,11 +308,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// Setup & Load our Configuration files.
|
||||
loadConfigs();
|
||||
if (this.multiverseConfig != null) {
|
||||
Logging.setShowingConfig(!getMVConfig().getSilentStart());
|
||||
this.worldManager.loadDefaultWorlds();
|
||||
this.worldManager.loadWorlds(true);
|
||||
Logging.setDebugLevel(getMVConfig().getGlobalDebug());
|
||||
} else {
|
||||
this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse.");
|
||||
Logging.severe("Your configs were not loaded. Very little will function in Multiverse.");
|
||||
}
|
||||
this.anchorManager.loadAnchors();
|
||||
|
||||
@@ -331,52 +336,22 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
this.chatListener = new MVPlayerChatListener(this, this.playerListener);
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(this.chatListener, this);
|
||||
/*
|
||||
// Check to see if spout was already loaded (most likely):
|
||||
if (this.getServer().getPluginManager().getPlugin("Spout") != null) {
|
||||
this.setSpout();
|
||||
this.log(Level.INFO, "Spout integration enabled.");
|
||||
}
|
||||
*/
|
||||
|
||||
this.initializeBuscript();
|
||||
this.setupMetrics();
|
||||
// Listen out for vault.
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
this.setupVaultEconomy();
|
||||
}
|
||||
|
||||
private boolean setupVaultEconomy() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
final RegisteredServiceProvider<Economy> economyProvider
|
||||
= getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
Logging.fine("Vault economy enabled.");
|
||||
vaultEco = economyProvider.getProvider();
|
||||
} else {
|
||||
Logging.finer("Vault economy not detected.");
|
||||
vaultEco = null;
|
||||
}
|
||||
} else {
|
||||
Logging.finer("Vault was not found.");
|
||||
vaultEco = null;
|
||||
}
|
||||
// Output a little snippet to show it's enabled.
|
||||
Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), PROTOCOL, getAuthors());
|
||||
|
||||
return (vaultEco != null);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void vaultEnabled(PluginEnableEvent event) {
|
||||
if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) {
|
||||
setupVaultEconomy();
|
||||
if (getMVConfig().isShowingDonateMessage()) {
|
||||
getLogger().config("Help dumptruckman keep this project alive. Become a patron! https://www.patreon.com/dumptruckman");
|
||||
getLogger().config("One time donations are also appreciated: https://www.paypal.me/dumptruckman");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void vaultDisabled(PluginDisableEvent event) {
|
||||
if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) {
|
||||
Logging.fine("Vault economy disabled");
|
||||
setupVaultEconomy();
|
||||
private void setupMetrics() {
|
||||
if (TestingMode.isDisabled()) {
|
||||
MetricsConfigurator.configureMetrics(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,99 +359,18 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
* Initializes the buscript javascript library.
|
||||
*/
|
||||
private void initializeBuscript() {
|
||||
buscript = new Buscript(this);
|
||||
// Add global variable "multiverse" to javascript environment
|
||||
buscript.getGlobalScope().put("multiverse", buscript.getGlobalScope(), this);
|
||||
}
|
||||
buscript = null;
|
||||
|
||||
/**
|
||||
* Plotter for Environment-Values.
|
||||
*/
|
||||
private static final class EnvironmentPlotter extends Metrics.Plotter {
|
||||
private MultiverseCore core;
|
||||
private final Environment env;
|
||||
|
||||
public EnvironmentPlotter(MultiverseCore core, Environment env) {
|
||||
super(envToString(env));
|
||||
this.core = core;
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
private static String envToString(Environment env) {
|
||||
return new StringBuilder().append(env.name().toUpperCase().charAt(0))
|
||||
.append(env.name().toLowerCase().substring(1)).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
int count = 0;
|
||||
for (MultiverseWorld w : core.getMVWorldManager().getMVWorlds())
|
||||
if (w.getEnvironment() == env)
|
||||
count++;
|
||||
core.log(Level.FINE, String.format("Tracking %d worlds of type %s", count, env));
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plotter for Generator-Values.
|
||||
*/
|
||||
private static final class GeneratorPlotter extends Metrics.Plotter {
|
||||
private MultiverseCore core;
|
||||
private final String gen;
|
||||
|
||||
public GeneratorPlotter(MultiverseCore core, String gen) {
|
||||
super(gen);
|
||||
this.core = core;
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
int count = 0;
|
||||
for (MultiverseWorld w : core.getMVWorldManager().getMVWorlds())
|
||||
if (gen.equals(w.getGenerator()))
|
||||
count++;
|
||||
core.log(Level.FINE, String.format("Tracking %d worlds of type %s", count, gen));
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
try {
|
||||
Metrics m = new Metrics(this);
|
||||
|
||||
Metrics.Graph envGraph = m.createGraph("worlds_by_env");
|
||||
for (Environment env : Environment.values())
|
||||
envGraph.addPlotter(new EnvironmentPlotter(this, env));
|
||||
|
||||
m.addCustomData(new Metrics.Plotter("Loaded worlds") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getMVWorldManager().getMVWorlds().size();
|
||||
}
|
||||
});
|
||||
m.addCustomData(new Metrics.Plotter("Total number of worlds") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return getMVWorldManager().getMVWorlds().size()
|
||||
+ getMVWorldManager().getUnloadedWorlds().size();
|
||||
}
|
||||
});
|
||||
|
||||
Set<String> gens = new HashSet<String>();
|
||||
for (MultiverseWorld w : this.getMVWorldManager().getMVWorlds())
|
||||
gens.add(w.getGenerator());
|
||||
gens.remove(null);
|
||||
gens.remove("null");
|
||||
Metrics.Graph genGraph = m.createGraph("custom_gens");
|
||||
for (String gen : gens)
|
||||
genGraph.addPlotter(new GeneratorPlotter(this, gen));
|
||||
|
||||
m.start();
|
||||
log(Level.FINE, "Metrics have run!");
|
||||
} catch (IOException e) {
|
||||
log(Level.WARNING, "There was an issue while enabling metrics: " + e.getMessage());
|
||||
if (this.getMVConfig().getEnableBuscript()) {
|
||||
try {
|
||||
buscript = new Buscript(this);
|
||||
// Add global variable "multiverse" to javascript environment
|
||||
buscript.setScriptVariable("multiverse", this);
|
||||
} catch (NullPointerException e) {
|
||||
Logging.warning("Buscript failed to load! The script command will be disabled! " +
|
||||
"If you would like not to see this message, " +
|
||||
"use `/mv conf enablebuscript false` to disable Buscript from loading.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,10 +392,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(this.playerListener, this);
|
||||
pm.registerEvents(this.entityListener, this);
|
||||
pm.registerEvents(this.pluginListener, this);
|
||||
pm.registerEvents(this.weatherListener, this);
|
||||
pm.registerEvents(this.portalListener, this);
|
||||
|
||||
Logging.info(ChatColor.GREEN + "We are aware of the warning about the deprecated event. There is no alternative that allows us to do what we need to do and performance impact is negligible. It is safe to ignore.");
|
||||
pm.registerEvents(this.worldListener, this);
|
||||
pm.registerEvents(new MVMapListener(this), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -511,8 +406,19 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
public void loadConfigs() {
|
||||
// Now grab the Configuration Files.
|
||||
this.multiverseConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
|
||||
Configuration coreDefaults = YamlConfiguration.loadConfiguration(this.getClass().getResourceAsStream("/defaults/config.yml"));
|
||||
this.multiverseConfig.setDefaults(coreDefaults);
|
||||
InputStream resourceURL = this.getClass().getResourceAsStream("/defaults/config.yml");
|
||||
|
||||
// Read in our default config with UTF-8 now
|
||||
Configuration coreDefaults;
|
||||
try {
|
||||
coreDefaults = YamlConfiguration.loadConfiguration(new BufferedReader(new InputStreamReader(resourceURL, "UTF-8")));
|
||||
this.multiverseConfig.setDefaults(coreDefaults);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Logging.severe("Couldn't load default config with UTF-8 encoding. Details follow:");
|
||||
e.printStackTrace();
|
||||
Logging.severe("Default configs NOT loaded.");
|
||||
}
|
||||
|
||||
this.multiverseConfig.options().copyDefaults(false);
|
||||
this.multiverseConfig.options().copyHeader(true);
|
||||
|
||||
@@ -536,6 +442,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// Old Config Format
|
||||
this.migrate22Values();
|
||||
this.saveMVConfigs();
|
||||
|
||||
int level = Logging.getDebugLevel();
|
||||
Logging.setDebugLevel(getMVConfig().getGlobalDebug());
|
||||
if (level != Logging.getDebugLevel()) {
|
||||
getServer().getPluginManager().callEvent(new MVDebugModeEvent(level));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,60 +456,70 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
*/
|
||||
private void migrate22Values() {
|
||||
if (this.multiverseConfig.isSet("worldnameprefix")) {
|
||||
this.log(Level.INFO, "Migrating 'worldnameprefix'...");
|
||||
Logging.config("Migrating 'worldnameprefix'...");
|
||||
this.getMVConfig().setPrefixChat(this.multiverseConfig.getBoolean("worldnameprefix"));
|
||||
this.multiverseConfig.set("worldnameprefix", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("firstspawnworld")) {
|
||||
this.log(Level.INFO, "Migrating 'firstspawnworld'...");
|
||||
Logging.config("Migrating 'firstspawnworld'...");
|
||||
this.getMVConfig().setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld"));
|
||||
this.multiverseConfig.set("firstspawnworld", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("enforceaccess")) {
|
||||
this.log(Level.INFO, "Migrating 'enforceaccess'...");
|
||||
Logging.config("Migrating 'enforceaccess'...");
|
||||
this.getMVConfig().setEnforceAccess(this.multiverseConfig.getBoolean("enforceaccess"));
|
||||
this.multiverseConfig.set("enforceaccess", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("displaypermerrors")) {
|
||||
this.log(Level.INFO, "Migrating 'displaypermerrors'...");
|
||||
Logging.config("Migrating 'displaypermerrors'...");
|
||||
this.getMVConfig().setDisplayPermErrors(this.multiverseConfig.getBoolean("displaypermerrors"));
|
||||
this.multiverseConfig.set("displaypermerrors", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("teleportintercept")) {
|
||||
this.log(Level.INFO, "Migrating 'teleportintercept'...");
|
||||
Logging.config("Migrating 'teleportintercept'...");
|
||||
this.getMVConfig().setTeleportIntercept(this.multiverseConfig.getBoolean("teleportintercept"));
|
||||
this.multiverseConfig.set("teleportintercept", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("firstspawnoverride")) {
|
||||
this.log(Level.INFO, "Migrating 'firstspawnoverride'...");
|
||||
Logging.config("Migrating 'firstspawnoverride'...");
|
||||
this.getMVConfig().setFirstSpawnOverride(this.multiverseConfig.getBoolean("firstspawnoverride"));
|
||||
this.multiverseConfig.set("firstspawnoverride", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("messagecooldown")) {
|
||||
this.log(Level.INFO, "Migrating 'messagecooldown'...");
|
||||
Logging.config("Migrating 'messagecooldown'...");
|
||||
this.getMVConfig().setMessageCooldown(this.multiverseConfig.getInt("messagecooldown"));
|
||||
this.multiverseConfig.set("messagecooldown", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("debug")) {
|
||||
this.log(Level.INFO, "Migrating 'debug'...");
|
||||
Logging.config("Migrating 'debug'...");
|
||||
this.getMVConfig().setGlobalDebug(this.multiverseConfig.getInt("debug"));
|
||||
this.multiverseConfig.set("debug", null);
|
||||
}
|
||||
if (this.multiverseConfig.isSet("version")) {
|
||||
this.log(Level.INFO, "Migrating 'version'...");
|
||||
Logging.config("Migrating 'version'...");
|
||||
this.multiverseConfig.set("version", null);
|
||||
}
|
||||
}
|
||||
|
||||
private static final char PATH_SEPARATOR = '\uF8FF';
|
||||
|
||||
/**
|
||||
* Migrate the worlds.yml to SerializationConfig.
|
||||
*/
|
||||
private void migrateWorldConfig() { // SUPPRESS CHECKSTYLE: MethodLength
|
||||
FileConfiguration wconf = YamlConfiguration
|
||||
.loadConfiguration(new File(getDataFolder(), "worlds.yml"));
|
||||
FileConfiguration wconf = new YamlConfiguration();
|
||||
wconf.options().pathSeparator(PATH_SEPARATOR);
|
||||
File worldsFile = new File(getDataFolder(), "worlds.yml");
|
||||
try {
|
||||
wconf.load(worldsFile);
|
||||
} catch (IOException e) {
|
||||
Logging.warning("Cannot load worlds.yml");
|
||||
} catch (InvalidConfigurationException e) {
|
||||
Logging.warning("Your worlds.yml is invalid!");
|
||||
}
|
||||
|
||||
if (!wconf.isConfigurationSection("worlds")) { // empty config
|
||||
this.log(Level.FINE, "No worlds to migrate!");
|
||||
Logging.fine("No worlds to migrate!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -606,13 +528,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
boolean wasChanged = false;
|
||||
Map<String, Object> newValues = new LinkedHashMap<String, Object>(values.size());
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
if (entry.getValue() instanceof MVWorld) {
|
||||
if (entry.getValue() instanceof WorldProperties) {
|
||||
// fine
|
||||
newValues.put(entry.getKey(), entry.getValue());
|
||||
} else if (entry.getValue() instanceof ConfigurationSection) {
|
||||
this.log(Level.FINE, "Migrating: " + entry.getKey());
|
||||
Logging.fine("Migrating: " + entry.getKey());
|
||||
// we have to migrate this
|
||||
MVWorld world = new MVWorld(Collections.EMPTY_MAP);
|
||||
WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
|
||||
ConfigurationSection section = (ConfigurationSection) entry.getValue();
|
||||
|
||||
// migrate animals and monsters
|
||||
@@ -646,8 +568,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// migrate entryfee
|
||||
if (section.isConfigurationSection("entryfee")) {
|
||||
ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
|
||||
if (feeSection.isInt("currency"))
|
||||
world.setCurrency(feeSection.getInt("currency"));
|
||||
if (feeSection.isInt("currency")) {
|
||||
world.setCurrency(MaterialConverter.convertConfigType(feeSection, "currency"));
|
||||
}
|
||||
|
||||
if (feeSection.isDouble("amount"))
|
||||
world.setPrice(feeSection.getDouble("amount"));
|
||||
@@ -682,10 +605,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
|
||||
// migrate gamemode
|
||||
if (section.isString("gamemode")) {
|
||||
try {
|
||||
world.setPropertyValue("gamemode", section.getString("gamemode"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
final GameMode gameMode = GameMode.valueOf(section.getString("gamemode").toUpperCase());
|
||||
if (gameMode != null) {
|
||||
world.setGameMode(gameMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,8 +629,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// migrate portalform
|
||||
if (section.isString("portalform")) {
|
||||
try {
|
||||
world.setPropertyValue("portalform", section.getString("portalform"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
world.setProperty("portalform", section.getString("portalform"), true);
|
||||
} catch (NoSuchPropertyException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
@@ -716,8 +638,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// migrate environment
|
||||
if (section.isString("environment")) {
|
||||
try {
|
||||
world.setPropertyValue("environment", section.getString("environment"));
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
world.setProperty("environment", section.getString("environment"), true);
|
||||
} catch (NoSuchPropertyException e) {
|
||||
throw new RuntimeException("Who forgot to update the migrator?", e);
|
||||
}
|
||||
}
|
||||
@@ -755,7 +677,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// migrate spawn
|
||||
if (section.isConfigurationSection("spawn")) {
|
||||
ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
|
||||
Location spawnLoc = world.getSpawnLocation();
|
||||
Location spawnLoc = new NullLocation();
|
||||
if (spawnSect.isDouble("yaw"))
|
||||
spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
|
||||
if (spawnSect.isDouble("pitch"))
|
||||
@@ -770,11 +692,31 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
world.setSpawnLocation(spawnLoc);
|
||||
}
|
||||
|
||||
// migrate difficulty
|
||||
if (section.isString("difficulty")) {
|
||||
Difficulty difficulty;
|
||||
try {
|
||||
difficulty = Difficulty.valueOf(section.getString("difficulty").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
Logging.warning("Could not parse difficulty: " + section.getString("difficulty"));
|
||||
Logging.warning("Setting world " + entry.getKey() + " difficulty to NORMAL");
|
||||
difficulty = Difficulty.NORMAL;
|
||||
}
|
||||
if (difficulty != null) {
|
||||
world.setDifficulty(difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
// migrate keepspawninmemory
|
||||
if (section.isBoolean("keepspawninmemory")) {
|
||||
world.setKeepSpawnInMemory(section.getBoolean("keepspawninmemory"));
|
||||
}
|
||||
|
||||
newValues.put(entry.getKey(), world);
|
||||
wasChanged = true;
|
||||
} else {
|
||||
// huh?
|
||||
this.log(Level.WARNING, "Removing unknown entry in the config: " + entry);
|
||||
Logging.warning("Removing unknown entry in the config: " + entry);
|
||||
// just don't add to newValues
|
||||
wasChanged = true;
|
||||
}
|
||||
@@ -844,9 +786,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
// Misc Commands
|
||||
this.commandHandler.registerCommand(new EnvironmentCommand(this));
|
||||
this.commandHandler.registerCommand(new DebugCommand(this));
|
||||
this.commandHandler.registerCommand(new SilentCommand(this));
|
||||
this.commandHandler.registerCommand(new GeneratorCommand(this));
|
||||
this.commandHandler.registerCommand(new CheckCommand(this));
|
||||
this.commandHandler.registerCommand(new ScriptCommand(this));
|
||||
this.commandHandler.registerCommand(new GameruleCommand(this));
|
||||
this.commandHandler.registerCommand(new GamerulesCommand(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -855,9 +800,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.saveMVConfigs();
|
||||
this.banker = null;
|
||||
this.bank = null;
|
||||
log(Level.INFO, "- Disabled");
|
||||
Logging.shutdown();
|
||||
}
|
||||
|
||||
@@ -874,17 +816,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public com.onarandombox.MultiverseCore.utils.SafeTTeleporter getTeleporter() {
|
||||
return new com.onarandombox.MultiverseCore.utils.SafeTTeleporter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -919,8 +850,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated This is now deprecated, nobody needs it any longer.
|
||||
* All logging is now done with {@link Logging}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void log(Level level, String msg) {
|
||||
Logging.log(level, msg);
|
||||
}
|
||||
@@ -987,6 +922,15 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
return this.commandHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public CommandQueueManager getCommandQueueManager() {
|
||||
return commandQueueManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the log-tag.
|
||||
*
|
||||
@@ -1043,24 +987,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
this.pluginCount -= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public AllPay getBanker() {
|
||||
return this.banker;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setBank(GenericBank bank) {
|
||||
this.bank = bank;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1102,25 +1028,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
this.serverFolder = newServerFolder;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initializes Spout.
|
||||
* /
|
||||
public void setSpout() {
|
||||
this.spoutInterface = new SpoutInterface();
|
||||
this.commandHandler.registerCommand(new SpoutCommand(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets our {@link SpoutInterface}.
|
||||
*
|
||||
* @return The {@link SpoutInterface} we're using.
|
||||
* /
|
||||
public SpoutInterface getSpout() {
|
||||
return this.spoutInterface;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1176,7 +1083,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
this.multiverseConfig.save(new File(getDataFolder(), "config.yml"));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
this.log(Level.SEVERE, "Could not save Multiverse config.yml config. Please check your file permissions.");
|
||||
Logging.severe("Could not save Multiverse config.yml config. Please check your file permissions.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1224,12 +1131,22 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This is deprecated!
|
||||
* @deprecated This is deprecated! Do not use!
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed) {
|
||||
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed);
|
||||
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This is deprecated! Do not use!
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed, Boolean keepGameRules) {
|
||||
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed, keepGameRules);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1253,6 +1170,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
*/
|
||||
@Override
|
||||
public void setBlockSafety(BlockSafety bs) {
|
||||
if (bs == null) {
|
||||
throw new NullPointerException("block safety may not be null.");
|
||||
}
|
||||
this.blockSafety = bs;
|
||||
}
|
||||
|
||||
@@ -1311,4 +1231,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Listen
|
||||
public Buscript getScriptAPI() {
|
||||
return buscript;
|
||||
}
|
||||
|
||||
public UnsafeCallWrapper getUnsafeCallWrapper() {
|
||||
return this.unsafeCallWrapper;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Our configuration.
|
||||
@@ -44,6 +46,8 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
@Property
|
||||
private volatile boolean prefixchat;
|
||||
@Property
|
||||
private volatile String prefixchatformat;
|
||||
@Property
|
||||
private volatile boolean useasyncchat;
|
||||
@Property
|
||||
private volatile boolean teleportintercept;
|
||||
@@ -52,8 +56,12 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
@Property
|
||||
private volatile boolean displaypermerrors;
|
||||
@Property
|
||||
private volatile boolean enablebuscript;
|
||||
@Property
|
||||
private volatile int globaldebug;
|
||||
@Property
|
||||
private volatile boolean silentstart;
|
||||
@Property
|
||||
private volatile int messagecooldown;
|
||||
@Property
|
||||
private volatile double version;
|
||||
@@ -61,6 +69,14 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
private volatile String firstspawnworld;
|
||||
@Property
|
||||
private volatile int teleportcooldown;
|
||||
@Property
|
||||
private volatile boolean defaultportalsearch;
|
||||
@Property
|
||||
private volatile int portalsearchradius;
|
||||
@Property
|
||||
private volatile boolean autopurge;
|
||||
@Property
|
||||
private volatile boolean idonotwanttodonate;
|
||||
|
||||
public MultiverseCoreConfiguration() {
|
||||
super();
|
||||
@@ -80,14 +96,21 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
enforceaccess = false;
|
||||
useasyncchat = true;
|
||||
prefixchat = true;
|
||||
prefixchat = false;
|
||||
prefixchatformat = "[%world%]%chat%";
|
||||
teleportintercept = true;
|
||||
firstspawnoverride = true;
|
||||
displaypermerrors = true;
|
||||
enablebuscript = true;
|
||||
globaldebug = 0;
|
||||
messagecooldown = 5000;
|
||||
teleportcooldown = 1000;
|
||||
this.version = 2.9;
|
||||
silentstart = false;
|
||||
defaultportalsearch = false;
|
||||
portalsearchradius = 128;
|
||||
autopurge = true;
|
||||
idonotwanttodonate = false;
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
@@ -136,6 +159,22 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
public void setPrefixChat(boolean prefixChat) {
|
||||
this.prefixchat = prefixChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getPrefixChatFormat() {
|
||||
return this.prefixchatformat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setPrefixChatFormat(String prefixChatFormat) {
|
||||
this.prefixchatformat = prefixChatFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -177,6 +216,22 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
return this.displaypermerrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getEnableBuscript() {
|
||||
return this.enablebuscript;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setEnableBuscript(boolean enableBuscript) {
|
||||
this.enablebuscript = enableBuscript;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -200,6 +255,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
public void setGlobalDebug(int globalDebug) {
|
||||
this.globaldebug = globalDebug;
|
||||
Logging.setDebugLevel(globalDebug);
|
||||
Bukkit.getPluginManager().callEvent(new MVDebugModeEvent(globalDebug));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,4 +331,55 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
public boolean getUseAsyncChat() {
|
||||
return this.useasyncchat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilentStart(boolean silentStart) {
|
||||
Logging.setShowingConfig(!silentStart);
|
||||
this.silentstart = silentStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSilentStart() {
|
||||
return silentstart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseDefaultPortalSearch(boolean useDefaultPortalSearch) {
|
||||
defaultportalsearch = useDefaultPortalSearch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsingDefaultPortalSearch() {
|
||||
return defaultportalsearch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortalSearchRadius(int searchRadius) {
|
||||
this.portalsearchradius = searchRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortalSearchRadius() {
|
||||
return portalsearchradius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoPurgeEnabled() {
|
||||
return autopurge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoPurgeEnabled(boolean autopurge) {
|
||||
this.autopurge = autopurge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowingDonateMessage() {
|
||||
return !idonotwanttodonate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowDonateMessage(boolean showDonateMessage) {
|
||||
this.idonotwanttodonate = !showDonateMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,655 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
|
||||
import com.onarandombox.MultiverseCore.configuration.EntryFee;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnLocation;
|
||||
import com.onarandombox.MultiverseCore.configuration.SpawnSettings;
|
||||
import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
import me.main__.util.SerializationConfig.Serializor;
|
||||
import me.main__.util.SerializationConfig.Validator;
|
||||
import me.main__.util.SerializationConfig.VirtualProperty;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* This is a property class, I think we don't need that much javadoc.
|
||||
* BEGIN CHECKSTYLE-SUPPRESSION: Javadoc
|
||||
*/
|
||||
|
||||
@SerializableAs("MVWorld")
|
||||
public class WorldProperties extends SerializationConfig {
|
||||
|
||||
private static final Map<String, String> PROPERTY_ALIASES;
|
||||
|
||||
static {
|
||||
PROPERTY_ALIASES = new HashMap<String, String>();
|
||||
PROPERTY_ALIASES.put("curr", "entryfee.currency");
|
||||
PROPERTY_ALIASES.put("currency", "entryfee.currency");
|
||||
PROPERTY_ALIASES.put("price", "entryfee.amount");
|
||||
PROPERTY_ALIASES.put("scaling", "scale");
|
||||
PROPERTY_ALIASES.put("aliascolor", "color");
|
||||
PROPERTY_ALIASES.put("heal", "autoHeal");
|
||||
PROPERTY_ALIASES.put("storm", "allowWeather");
|
||||
PROPERTY_ALIASES.put("weather", "allowWeather");
|
||||
PROPERTY_ALIASES.put("spawnmemory", "keepSpawnInMemory");
|
||||
PROPERTY_ALIASES.put("memory", "keepSpawnInMemory");
|
||||
PROPERTY_ALIASES.put("mode", "gameMode");
|
||||
PROPERTY_ALIASES.put("diff", "difficulty");
|
||||
PROPERTY_ALIASES.put("spawnlocation", "spawn");
|
||||
PROPERTY_ALIASES.put("limit", "playerLimit");
|
||||
PROPERTY_ALIASES.put("animals", "spawning.animals.spawn");
|
||||
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
|
||||
PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate");
|
||||
PROPERTY_ALIASES.put("monstersrate", "spawning.monsters.spawnrate");
|
||||
PROPERTY_ALIASES.put("flight", "allowFlight");
|
||||
PROPERTY_ALIASES.put("fly", "allowFlight");
|
||||
PROPERTY_ALIASES.put("allowfly", "allowFlight");
|
||||
}
|
||||
|
||||
private final boolean keepSpawnFallback;
|
||||
|
||||
public WorldProperties(Map<String, Object> values) {
|
||||
super(values);
|
||||
Object keepSpawnObject = values.get("keepSpawnInMemory");
|
||||
keepSpawnFallback = keepSpawnObject == null || Boolean.parseBoolean(keepSpawnObject.toString());
|
||||
}
|
||||
|
||||
public WorldProperties() {
|
||||
super();
|
||||
keepSpawnFallback = true;
|
||||
}
|
||||
|
||||
public WorldProperties(final boolean fixSpawn, final Environment environment) {
|
||||
super();
|
||||
if (!fixSpawn) {
|
||||
this.adjustSpawn = false;
|
||||
}
|
||||
setScaling(getDefaultScale(environment));
|
||||
keepSpawnFallback = true;
|
||||
}
|
||||
|
||||
void setMVWorld(MVWorld world) {
|
||||
registerObjectUsing(world);
|
||||
registerGlobalValidator(new WorldPropertyValidator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the color-property.
|
||||
*/
|
||||
private static final class EnumPropertySerializor<T extends Enum<T>> implements Serializor<T, String> {
|
||||
@Override
|
||||
public String serialize(T from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(String serialized, Class<T> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return Enum.valueOf(wanted, serialized.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalPropertyValueException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the difficulty-property.
|
||||
*/
|
||||
private static final class DifficultyPropertySerializor implements Serializor<Difficulty, String> {
|
||||
@Override
|
||||
public String serialize(Difficulty from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Difficulty deserialize(String serialized, Class<Difficulty> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return Difficulty.getByValue(Integer.parseInt(serialized));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
return Difficulty.valueOf(serialized.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new IllegalPropertyValueException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the gameMode-property.
|
||||
*/
|
||||
private static final class GameModePropertySerializor implements Serializor<GameMode, String> {
|
||||
@Override
|
||||
public String serialize(GameMode from) {
|
||||
return from.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode deserialize(String serialized, Class<GameMode> wanted) throws IllegalPropertyValueException {
|
||||
try {
|
||||
return GameMode.getByValue(Integer.parseInt(serialized));
|
||||
} catch (NumberFormatException nfe) {
|
||||
}
|
||||
try {
|
||||
return GameMode.valueOf(serialized.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
throw new IllegalPropertyValueException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializor for the time-property.
|
||||
*/
|
||||
private static final class TimePropertySerializor implements Serializor<Long, String> {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
private static final String TIME_REGEX = "(\\d\\d?):?(\\d\\d)(a|p)?m?";
|
||||
private static final Map<String, String> TIME_ALIASES;
|
||||
static {
|
||||
Map<String, String> staticTimes = new HashMap<String, String>();
|
||||
staticTimes.put("morning", "8:00");
|
||||
staticTimes.put("day", "12:00");
|
||||
staticTimes.put("noon", "12:00");
|
||||
staticTimes.put("midnight", "0:00");
|
||||
staticTimes.put("night", "20:00");
|
||||
|
||||
// now set TIME_ALIASES to a "frozen" map
|
||||
TIME_ALIASES = Collections.unmodifiableMap(staticTimes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(Long from) {
|
||||
// I'm tired, so they get time in 24 hour for now.
|
||||
// Someone else can add 12 hr format if they want :P
|
||||
|
||||
int hours = (int) ((from / 1000 + 8) % 24);
|
||||
int minutes = (int) (60 * (from % 1000) / 1000);
|
||||
|
||||
return String.format("%d:%02d", hours, minutes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long deserialize(String serialized, Class<Long> wanted) throws IllegalPropertyValueException {
|
||||
if (TIME_ALIASES.containsKey(serialized.toLowerCase())) {
|
||||
serialized = TIME_ALIASES.get(serialized.toLowerCase());
|
||||
}
|
||||
// Regex that extracts a time in the following formats:
|
||||
// 11:11pm, 11:11, 23:11, 1111, 1111p, and the aliases at the top of this file.
|
||||
Pattern pattern = Pattern.compile(TIME_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(serialized);
|
||||
matcher.find();
|
||||
int hour = 0;
|
||||
double minute = 0;
|
||||
int count = matcher.groupCount();
|
||||
if (count >= 2) {
|
||||
hour = Integer.parseInt(matcher.group(1));
|
||||
minute = Integer.parseInt(matcher.group(2));
|
||||
}
|
||||
// If there were 4 matches (all, hour, min, am/pm)
|
||||
if (count == 4) {
|
||||
// We want 24 hour time for calcs, but if they
|
||||
// added a p[m], turn it into a 24 hr one.
|
||||
if (matcher.group(3).equals("p")) {
|
||||
hour += 12;
|
||||
}
|
||||
}
|
||||
// Translate 24th hour to 0th hour.
|
||||
if (hour == 24) {
|
||||
hour = 0;
|
||||
}
|
||||
// Clamp the hour
|
||||
if (hour > 23 || hour < 0) {
|
||||
throw new IllegalPropertyValueException("Illegal hour!");
|
||||
}
|
||||
// Clamp the minute
|
||||
if (minute > 59 || minute < 0) {
|
||||
throw new IllegalPropertyValueException("Illegal minute!");
|
||||
}
|
||||
// 60 seconds in a minute, time needs to be in hrs * 1000, per
|
||||
// the bukkit docs.
|
||||
double totaltime = (hour + (minute / 60.0)) * 1000;
|
||||
// Somehow there's an 8 hour offset...
|
||||
totaltime -= 8000;
|
||||
if (totaltime < 0) {
|
||||
totaltime = 24000 + totaltime;
|
||||
}
|
||||
|
||||
return (long) totaltime;
|
||||
}
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Begin properties
|
||||
@Property(description = "Sorry, 'hidden' must either be: true or false.")
|
||||
private volatile boolean hidden;
|
||||
@Property(description = "Alias must be a valid string.")
|
||||
private volatile String alias;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'color' must be a valid color-name.")
|
||||
private volatile EnglishChatColor color;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Sorry, 'style' must be a valid style-name.")
|
||||
private volatile EnglishChatStyle style;
|
||||
@Property(description = "Sorry, 'pvp' must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||
volatile VirtualProperty<Boolean> pvp; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Scale must be a positive double value. ex: 2.3")
|
||||
private volatile double scale;
|
||||
@Property(description = "You must set this to the NAME not alias of a world.")
|
||||
private volatile String respawnWorld;
|
||||
@Property(description = "Sorry, this must either be: true or false.")
|
||||
private volatile boolean allowWeather;
|
||||
@Property(serializor = DifficultyPropertySerializor.class, virtualType = Difficulty.class, persistVirtual = true,
|
||||
description = "Difficulty must be set as one of the following: peaceful easy normal hard")
|
||||
volatile VirtualProperty<Difficulty> difficulty; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Sorry, 'animals' must either be: true or false.")
|
||||
private volatile SpawnSettings spawning;
|
||||
@Property
|
||||
volatile EntryFee entryfee;
|
||||
@Property(description = "Sorry, 'hunger' must either be: true or false.")
|
||||
private volatile boolean hunger;
|
||||
@Property(description = "Sorry, 'autoheal' must either be: true or false.")
|
||||
private volatile boolean autoHeal;
|
||||
@Property(description = "Sorry, 'adjustspawn' must either be: true or false.")
|
||||
private volatile boolean adjustSpawn;
|
||||
@Property(serializor = EnumPropertySerializor.class, description = "Allow portal forming must be NONE, ALL, NETHER or END.")
|
||||
private volatile AllowedPortalType portalForm;
|
||||
@Property(serializor = GameModePropertySerializor.class, description = "GameMode must be set as one of the following: survival creative")
|
||||
private volatile GameMode gameMode;
|
||||
@Property(description = "Sorry, this must either be: true or false.", virtualType = Boolean.class, persistVirtual = true)
|
||||
volatile VirtualProperty<Boolean> keepSpawnInMemory; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile SpawnLocation spawnLocation; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(virtualType = Location.class,
|
||||
description = "There is no help available for this variable. Go bug Rigby90 about it.")
|
||||
volatile VirtualProperty<Location> spawn; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property(description = "Set this to false ONLY if you don't want this world to load itself on server restart.")
|
||||
private volatile boolean autoLoad;
|
||||
@Property(description = "If a player dies in this world, shoudld they go to their bed?")
|
||||
private volatile boolean bedRespawn;
|
||||
@Property
|
||||
private volatile List<String> worldBlacklist;
|
||||
@Property(serializor = TimePropertySerializor.class, virtualType = Long.class,
|
||||
description = "Set the time to whatever you want! (Will NOT freeze time)")
|
||||
volatile VirtualProperty<Long> time; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile Environment environment; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
volatile long seed; // SUPPRESS CHECKSTYLE: VisibilityModifier
|
||||
@Property
|
||||
private volatile String generator;
|
||||
@Property
|
||||
private volatile int playerLimit;
|
||||
@Property
|
||||
private volatile boolean allowFlight;
|
||||
// End of properties
|
||||
// --------------------------------------------------------------
|
||||
|
||||
void setValidator(String fieldName, Validator validator) {
|
||||
registerValidator(fieldName, validator); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyValues(SerializationConfig other) {
|
||||
super.copyValues(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* This prepares the MVWorld for unloading.
|
||||
*/
|
||||
public void cacheVirtualProperties() {
|
||||
try {
|
||||
this.buildVPropChanges();
|
||||
} catch (IllegalStateException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
this.hidden = false;
|
||||
this.alias = new String();
|
||||
this.color = EnglishChatColor.WHITE;
|
||||
this.style = EnglishChatStyle.NORMAL;
|
||||
this.scale = 1D;
|
||||
this.respawnWorld = new String();
|
||||
this.allowWeather = true;
|
||||
this.spawning = new SpawnSettings();
|
||||
this.entryfee = new EntryFee();
|
||||
this.hunger = true;
|
||||
this.autoHeal = true;
|
||||
this.adjustSpawn = true;
|
||||
this.portalForm = AllowedPortalType.ALL;
|
||||
this.gameMode = GameMode.SURVIVAL;
|
||||
this.spawnLocation = new NullLocation();
|
||||
this.autoLoad = true;
|
||||
this.bedRespawn = true;
|
||||
this.worldBlacklist = new ArrayList<String>();
|
||||
this.generator = null;
|
||||
this.playerLimit = -1;
|
||||
this.allowFlight = true;
|
||||
}
|
||||
|
||||
private static double getDefaultScale(Environment environment) {
|
||||
if (environment == Environment.NETHER) {
|
||||
return 8.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} else if (environment == Environment.THE_END) {
|
||||
return 16.0; // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAliases().
|
||||
* @return The alias-map.
|
||||
* @see SerializationConfig
|
||||
*/
|
||||
protected static Map<String, String> getAliases() {
|
||||
return PROPERTY_ALIASES;
|
||||
}
|
||||
|
||||
void flushChanges() {
|
||||
this.flushPendingVPropChanges();
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.setPropertyValueUnchecked("alias", alias);
|
||||
}
|
||||
|
||||
public Environment getEnvironment() {
|
||||
return this.environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.setPropertyValueUnchecked("environment", environment);
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
public void setSeed(long seed) {
|
||||
this.setPropertyValueUnchecked("seed", seed);
|
||||
}
|
||||
|
||||
public String getGenerator() {
|
||||
return this.generator;
|
||||
}
|
||||
|
||||
public void setGenerator(String generator) {
|
||||
this.setPropertyValueUnchecked("generator", generator);
|
||||
}
|
||||
|
||||
public int getPlayerLimit() {
|
||||
return this.playerLimit;
|
||||
}
|
||||
|
||||
public void setPlayerLimit(int limit) {
|
||||
this.setPropertyValueUnchecked("playerLimit", limit);
|
||||
}
|
||||
|
||||
public boolean canAnimalsSpawn() {
|
||||
return this.spawning.getAnimalSettings().doSpawn();
|
||||
}
|
||||
|
||||
public void setAllowAnimalSpawn(boolean animals) {
|
||||
this.setPropertyValueUnchecked("spawning.animals.spawn", animals);
|
||||
}
|
||||
|
||||
public List<String> getAnimalList() {
|
||||
// These don't fire events at the moment. Should they?
|
||||
return this.spawning.getAnimalSettings().getExceptions();
|
||||
}
|
||||
|
||||
public boolean canMonstersSpawn() {
|
||||
return this.spawning.getMonsterSettings().doSpawn();
|
||||
}
|
||||
|
||||
public void setAllowMonsterSpawn(boolean monsters) {
|
||||
this.setPropertyValueUnchecked("spawning.monsters.spawn", monsters);
|
||||
}
|
||||
|
||||
public int getAnimalSpawnRate() {
|
||||
return this.spawning.getAnimalSettings().getSpawnRate();
|
||||
}
|
||||
|
||||
public int getMonsterSpawnRate() {
|
||||
return this.spawning.getMonsterSettings().getSpawnRate();
|
||||
}
|
||||
|
||||
public List<String> getMonsterList() {
|
||||
// These don't fire events at the moment. Should they?
|
||||
return this.spawning.getMonsterSettings().getExceptions();
|
||||
}
|
||||
|
||||
public boolean isPVPEnabled() {
|
||||
return this.pvp.get();
|
||||
}
|
||||
|
||||
public void setPVPMode(boolean pvp) {
|
||||
this.setPropertyValueUnchecked("pvp", pvp);
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.setPropertyValueUnchecked("hidden", hidden);
|
||||
}
|
||||
|
||||
public List<String> getWorldBlacklist() {
|
||||
return this.worldBlacklist;
|
||||
}
|
||||
|
||||
public double getScaling() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
public boolean setScaling(double scaling) {
|
||||
return this.setPropertyValueUnchecked("scale", scaling);
|
||||
}
|
||||
|
||||
public boolean setColor(String aliasColor) {
|
||||
return this.setPropertyUnchecked("color", aliasColor);
|
||||
}
|
||||
|
||||
public boolean setColor(EnglishChatColor color) {
|
||||
return this.setPropertyValueUnchecked("color", color);
|
||||
}
|
||||
|
||||
public EnglishChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public String getRespawnToWorld() {
|
||||
return this.respawnWorld;
|
||||
}
|
||||
|
||||
public boolean setRespawnToWorld(String respawnToWorld) {
|
||||
return this.setPropertyValueUnchecked("respawnWorld", respawnToWorld);
|
||||
}
|
||||
|
||||
public Material getCurrency() {
|
||||
return this.entryfee.getCurrency();
|
||||
}
|
||||
|
||||
public void setCurrency(@Nullable Material currency) {
|
||||
this.setPropertyValueUnchecked("entryfee.currency", currency);
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return this.entryfee.getAmount();
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.setPropertyValueUnchecked("entryfee.amount", price);
|
||||
}
|
||||
|
||||
public boolean setGameMode(String mode) {
|
||||
return this.setPropertyUnchecked("gameMode", mode);
|
||||
}
|
||||
|
||||
public boolean setGameMode(GameMode mode) {
|
||||
return this.setPropertyValueUnchecked("gameMode", mode);
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
public void setEnableWeather(boolean weather) {
|
||||
this.setPropertyValueUnchecked("allowWeather", weather);
|
||||
}
|
||||
|
||||
public boolean isWeatherEnabled() {
|
||||
return this.allowWeather;
|
||||
}
|
||||
|
||||
public boolean isKeepingSpawnInMemory() {
|
||||
if (keepSpawnInMemory == null) {
|
||||
return keepSpawnFallback;
|
||||
}
|
||||
try {
|
||||
return this.keepSpawnInMemory.get();
|
||||
} catch (IllegalStateException e) {
|
||||
return keepSpawnFallback;
|
||||
}
|
||||
}
|
||||
|
||||
public void setKeepSpawnInMemory(boolean value) {
|
||||
this.setPropertyValueUnchecked("keepSpawnInMemory", value);
|
||||
}
|
||||
|
||||
public boolean getHunger() {
|
||||
return this.hunger;
|
||||
}
|
||||
|
||||
public void setHunger(boolean hunger) {
|
||||
this.setPropertyValueUnchecked("hunger", hunger);
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
return this.spawn.get();
|
||||
}
|
||||
|
||||
public void setSpawnLocation(Location l) {
|
||||
this.setPropertyValueUnchecked("spawn", l);
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return this.difficulty.get();
|
||||
}
|
||||
|
||||
@Deprecated // SUPPRESS CHECKSTYLE: Deprecated
|
||||
public boolean setDifficulty(String difficulty) {
|
||||
return this.setPropertyUnchecked("difficulty", difficulty);
|
||||
}
|
||||
|
||||
public boolean setDifficulty(Difficulty difficulty) {
|
||||
return this.setPropertyValueUnchecked("difficulty", difficulty);
|
||||
}
|
||||
|
||||
public boolean getAutoHeal() {
|
||||
return this.autoHeal;
|
||||
}
|
||||
|
||||
public void setAutoHeal(boolean heal) {
|
||||
this.setPropertyValueUnchecked("autoHeal", heal);
|
||||
}
|
||||
|
||||
public void setAdjustSpawn(boolean adjust) {
|
||||
this.setPropertyValueUnchecked("adjustSpawn", adjust);
|
||||
}
|
||||
|
||||
public boolean getAdjustSpawn() {
|
||||
return this.adjustSpawn;
|
||||
}
|
||||
|
||||
public void setAutoLoad(boolean load) {
|
||||
this.setPropertyValueUnchecked("autoLoad", load);
|
||||
}
|
||||
|
||||
public boolean getAutoLoad() {
|
||||
return this.autoLoad;
|
||||
}
|
||||
|
||||
public void setBedRespawn(boolean respawn) {
|
||||
this.setPropertyValueUnchecked("bedRespawn", respawn);
|
||||
}
|
||||
|
||||
public boolean getBedRespawn() {
|
||||
return this.bedRespawn;
|
||||
}
|
||||
|
||||
public String getAllPropertyNames() {
|
||||
ChatColor myColor = ChatColor.AQUA;
|
||||
StringBuilder result = new StringBuilder();
|
||||
Map<String, Object> serialized = this.serialize();
|
||||
for (String key : serialized.keySet()) {
|
||||
result.append(myColor).append(key).append(' ');
|
||||
myColor = (myColor == ChatColor.AQUA) ? ChatColor.GOLD : ChatColor.AQUA;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return this.getPropertyUnchecked("time");
|
||||
}
|
||||
|
||||
public boolean setTime(String timeAsString) {
|
||||
return this.setPropertyUnchecked("time", timeAsString);
|
||||
}
|
||||
|
||||
public AllowedPortalType getAllowedPortals() {
|
||||
return portalForm;
|
||||
}
|
||||
|
||||
public void allowPortalMaking(AllowedPortalType portalType) {
|
||||
this.setPropertyValueUnchecked("portalForm", portalType);
|
||||
}
|
||||
|
||||
public EnglishChatStyle getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
public boolean setStyle(String style) {
|
||||
return this.setPropertyUnchecked("style", style);
|
||||
}
|
||||
|
||||
public boolean getAllowFlight() {
|
||||
return this.allowFlight;
|
||||
}
|
||||
|
||||
public void setAllowFlight(final boolean allowFlight) {
|
||||
this.setPropertyValueUnchecked("allowFlight", allowFlight);
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,17 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVEconomist;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
@@ -31,29 +29,22 @@ import org.bukkit.entity.Player;
|
||||
public interface Core {
|
||||
|
||||
/**
|
||||
* Gets the Multiverse config file.
|
||||
* Returns the Vault handler used by Multiverse. The returned object will have all methods necessary for
|
||||
* interfacing with Vault.
|
||||
*
|
||||
* @return The Multiverse config file.
|
||||
* @deprecated Don't modify the config-file manually!
|
||||
* @return the Vault handler for Multiverse.
|
||||
* @deprecated we are now using {@link #getEconomist()} for all economy needs.
|
||||
*/
|
||||
@Deprecated
|
||||
FileConfiguration getMVConfiguration();
|
||||
VaultHandler getVaultHandler();
|
||||
|
||||
/**
|
||||
* Gets the Banking system that Multiverse-Core has hooked into.
|
||||
* Retrieves Multiverse's friendly economist. The economist can be used for dealing with economies without
|
||||
* worrying about any of the messy details.
|
||||
*
|
||||
* @return A {@link GenericBank} that can be used for payments.
|
||||
* @deprecated Now using vault, see {@link #getVaultEconomy}
|
||||
* @return the economy manager for Multiverse.
|
||||
*/
|
||||
@Deprecated
|
||||
GenericBank getBank();
|
||||
|
||||
/**
|
||||
* Returns the Vault economy system if Vault is present and has an economy system enabled.
|
||||
*
|
||||
* @return The vault economy system or null if not configured.
|
||||
*/
|
||||
Economy getVaultEconomy();
|
||||
MVEconomist getEconomist();
|
||||
|
||||
/**
|
||||
* Reloads the Multiverse Configuration files:
|
||||
@@ -80,17 +71,6 @@ public interface Core {
|
||||
*/
|
||||
MVPlayerSession getPlayerSession(Player player);
|
||||
|
||||
/**
|
||||
* Gets the instantiated Safe-T-Teleporter for performing
|
||||
* safe teleports.
|
||||
*
|
||||
* @return A non-null {@link SafeTTeleporter}.
|
||||
*
|
||||
* @deprecated Use {@link #getSafeTTeleporter()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
com.onarandombox.MultiverseCore.utils.SafeTTeleporter getTeleporter();
|
||||
|
||||
/**
|
||||
* Multiverse uses an advanced permissions setup, this object
|
||||
* simplifies getting/setting permissions.
|
||||
@@ -107,6 +87,15 @@ public interface Core {
|
||||
*/
|
||||
CommandHandler getCommandHandler();
|
||||
|
||||
/**
|
||||
* Manager for command that requires /mv confirm before execution.
|
||||
*
|
||||
* @return A non-null {@link CommandQueueManager}.
|
||||
* @deprecated To be moved to new command manager in 5.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
CommandQueueManager getCommandQueueManager();
|
||||
|
||||
/**
|
||||
* Gets the factory class responsible for loading many different destinations
|
||||
* on demand.
|
||||
@@ -118,7 +107,7 @@ public interface Core {
|
||||
/**
|
||||
* Gets the primary class responsible for managing Multiverse Worlds.
|
||||
*
|
||||
* @return {@link WorldManager}.
|
||||
* @return {@link MVWorldManager}.
|
||||
*/
|
||||
MVWorldManager getMVWorldManager();
|
||||
|
||||
@@ -137,37 +126,37 @@ public interface Core {
|
||||
AnchorManager getAnchorManager();
|
||||
|
||||
/**
|
||||
* Used by queued commands to regenerate a world on a delay.
|
||||
* Previously used by queued commands to regenerate a world on a delay.
|
||||
* Do not use api method for any other purpose.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed IF the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*
|
||||
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String)} instead.
|
||||
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed);
|
||||
|
||||
/**
|
||||
* Sets the {@link GenericBank}-Bank AllPay is using.
|
||||
* Used by queued commands to regenerate a world on a delay.
|
||||
* Do not use api method for any other purpose.
|
||||
*
|
||||
* @param bank The new {@link GenericBank}
|
||||
* @deprecated Now using vault, see {@link #getVaultEconomy}
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
* @param keepGameRules If GameRules should be kept on world regen.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*
|
||||
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
void setBank(GenericBank bank);
|
||||
|
||||
/**
|
||||
* Gets this plugin's {@link AllPay}-Banker.
|
||||
*
|
||||
* @return An {@link AllPay}-Banker
|
||||
* @deprecated Now using vault, see {@link #getVaultEconomy}
|
||||
*/
|
||||
@Deprecated
|
||||
AllPay getBanker();
|
||||
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed, Boolean keepGameRules);
|
||||
|
||||
/**
|
||||
* Decrements the number of plugins that have specifically hooked into core.
|
||||
|
||||
@@ -7,11 +7,17 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/** A simple API to require plugins to have a log method. */
|
||||
/**
|
||||
* A simple API to require plugins to have a log method.
|
||||
*
|
||||
* @deprecated Replaced by {@link Logging}.
|
||||
* */
|
||||
@Deprecated
|
||||
public interface LoggablePlugin {
|
||||
/**
|
||||
* Logs a message at the specified level.
|
||||
|
||||
@@ -30,14 +30,14 @@ public interface MVPlugin extends LoggablePlugin {
|
||||
/**
|
||||
* Gets the reference to MultiverseCore.
|
||||
*
|
||||
* @return A valid {@link MultiverseCore}.
|
||||
* @return A valid {@link com.onarandombox.MultiverseCore}.
|
||||
*/
|
||||
MultiverseCore getCore();
|
||||
|
||||
/**
|
||||
* Sets the reference to MultiverseCore.
|
||||
*
|
||||
* @param core A valid {@link MultiverseCore}.
|
||||
* @param core A valid {@link com.onarandombox.MultiverseCore}.
|
||||
*/
|
||||
void setCore(MultiverseCore core);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
@@ -65,16 +64,30 @@ public interface MVWorldManager {
|
||||
*
|
||||
* @param oldName Name of world to be copied
|
||||
* @param newName Name of world to be created
|
||||
* @param generator The Custom generator plugin to use.
|
||||
* @param generator The Custom generator plugin to use. Ignored.
|
||||
* @return True if the world is copied successfully, false if not.
|
||||
* @deprecated Use {@link #cloneWorld(String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean cloneWorld(String oldName, String newName, String generator);
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list, from the
|
||||
* config and deletes the folder.
|
||||
* Make a copy of a world.
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @param oldName
|
||||
* Name of world to be copied
|
||||
* @param newName
|
||||
* Name of world to be created
|
||||
* @return True if the world is copied successfully, false if not.
|
||||
*/
|
||||
boolean cloneWorld(String oldName, String newName);
|
||||
|
||||
/**
|
||||
* Remove the world from the Multiverse list, from the config and deletes
|
||||
* the folder.
|
||||
*
|
||||
* @param name
|
||||
* The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean deleteWorld(String name);
|
||||
@@ -90,6 +103,17 @@ public interface MVWorldManager {
|
||||
*/
|
||||
boolean deleteWorld(String name, boolean removeConfig);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name The name of the world to remove
|
||||
* @param removeFromConfig If true(default), we'll remove the entries from the
|
||||
* config. If false, they'll stay and the world may come back.
|
||||
* @param deleteWorldFolder If true the world folder will be completely deleted. If false
|
||||
* only the contents of the world folder will be deleted
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
boolean deleteWorld(String name, boolean removeFromConfig, boolean deleteWorldFolder);
|
||||
|
||||
/**
|
||||
* Unload a world from Multiverse.
|
||||
*
|
||||
@@ -98,6 +122,15 @@ public interface MVWorldManager {
|
||||
*/
|
||||
boolean unloadWorld(String name);
|
||||
|
||||
/**
|
||||
* Unload a world from Multiverse with option to prevent calling unloadWorld in Bukkit.
|
||||
*
|
||||
* @param name Name of the world to unload
|
||||
* @param unloadBukkit True if Bukkit world should be unloaded
|
||||
* @return True if the world was unloaded, false if not.
|
||||
*/
|
||||
boolean unloadWorld(String name, boolean unloadBukkit);
|
||||
|
||||
/**
|
||||
* Loads the world. Only use this if the world has been
|
||||
* unloaded with {@link #unloadWorld(String)}.
|
||||
@@ -141,6 +174,16 @@ public interface MVWorldManager {
|
||||
*/
|
||||
MultiverseWorld getMVWorld(String name);
|
||||
|
||||
/**
|
||||
* Returns a {@link MultiverseWorld} if the world with name given exists, and null if it does not.
|
||||
* This will search optionally for alias names.
|
||||
*
|
||||
* @param name The name or optionally the alias of the world to get.
|
||||
* @param checkAliases Indicates whether to check for world alias name.
|
||||
* @return A {@link MultiverseWorld} or null.
|
||||
*/
|
||||
MultiverseWorld getMVWorld(String name, boolean checkAliases);
|
||||
|
||||
/**
|
||||
* Returns a {@link MultiverseWorld} if it exists, and null if it does not.
|
||||
*
|
||||
@@ -150,13 +193,24 @@ public interface MVWorldManager {
|
||||
MultiverseWorld getMVWorld(World world);
|
||||
|
||||
/**
|
||||
* Checks to see if the given name is a valid {@link MultiverseWorld}.
|
||||
* Checks to see if the given name is a valid {@link MultiverseWorld}
|
||||
* Searches based on world name AND alias.
|
||||
*
|
||||
* @param name The name or alias of the world to check.
|
||||
* @return True if the world exists, false if not.
|
||||
*/
|
||||
boolean isMVWorld(String name);
|
||||
|
||||
/**
|
||||
* Checks to see if the given name is a valid {@link MultiverseWorld}.
|
||||
* Optionally searches by alias is specified.
|
||||
*
|
||||
* @param name The name or alias of the world to check.
|
||||
* @param checkAliases Indicates whether to check for world alias name.
|
||||
* @return True if the world exists, false if not.
|
||||
*/
|
||||
boolean isMVWorld(String name, boolean checkAliases);
|
||||
|
||||
/**
|
||||
* Checks to see if the given world is a valid {@link MultiverseWorld}.
|
||||
*
|
||||
@@ -166,7 +220,7 @@ public interface MVWorldManager {
|
||||
boolean isMVWorld(World world);
|
||||
|
||||
/**
|
||||
* Load the Worlds & Settings from the configuration file.
|
||||
* Load the Worlds & Settings from the configuration file.
|
||||
*
|
||||
* @param forceLoad If set to true, this will perform a total
|
||||
* reset and not just load new worlds.
|
||||
@@ -174,7 +228,7 @@ public interface MVWorldManager {
|
||||
void loadWorlds(boolean forceLoad);
|
||||
|
||||
/**
|
||||
* Loads the Worlds & Settings for any worlds that bukkit loaded before us.
|
||||
* Loads the Worlds & Settings for any worlds that bukkit loaded before us.
|
||||
* <p>
|
||||
* This way people will _always_ have some worlds in the list.
|
||||
*/
|
||||
@@ -259,12 +313,46 @@ public interface MVWorldManager {
|
||||
/**
|
||||
* Regenerates a world.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed IF the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed);
|
||||
|
||||
/**
|
||||
* Regenerates a world.
|
||||
*
|
||||
* @param name Name of the world to regenerate
|
||||
* @param useNewSeed If a new seed should be used
|
||||
* @param randomSeed If the new seed should be random
|
||||
* @param seed The seed of the world.
|
||||
* @param keepGameRules If GameRules should be kept on world regen.
|
||||
*
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed, boolean keepGameRules);
|
||||
|
||||
boolean isKeepingSpawnInMemory(World world);
|
||||
|
||||
/**
|
||||
* Checks whether Multiverse knows about a provided unloaded world. This
|
||||
* method will check the parameter against the alias mappings.
|
||||
*
|
||||
* @param name The name of the unloaded world
|
||||
* @param includeLoaded The value to return if the world is loaded
|
||||
*
|
||||
* @return True if the world exists and is unloaded. False if the world
|
||||
* does not exist. {@code includeLoaded} if the world exists and is loaded.
|
||||
*/
|
||||
boolean hasUnloadedWorld(String name, boolean includeLoaded);
|
||||
|
||||
/**
|
||||
* Get all the possible worlds that Multiverse has detected to be importable.
|
||||
*
|
||||
* @return A collection of world names that are deemed importable.
|
||||
*/
|
||||
Collection<String> getPotentialWorlds();
|
||||
}
|
||||
@@ -86,6 +86,18 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
*/
|
||||
boolean getDisplayPermErrors();
|
||||
|
||||
/**
|
||||
* Sets enableBuscript.
|
||||
* @param enableBuscript The new value.
|
||||
*/
|
||||
void setEnableBuscript(boolean enableBuscript);
|
||||
|
||||
/**
|
||||
* Gets enableBuscript.
|
||||
* @return enableBuscript.
|
||||
*/
|
||||
boolean getEnableBuscript();
|
||||
|
||||
/**
|
||||
* Sets firstSpawnOverride.
|
||||
* @param firstSpawnOverride The new value.
|
||||
@@ -121,6 +133,18 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
* @return prefixChat.
|
||||
*/
|
||||
boolean getPrefixChat();
|
||||
|
||||
/**
|
||||
* Sets prefixChatFormat.
|
||||
* @param prefixChatFormat The new value.
|
||||
*/
|
||||
void setPrefixChatFormat(String prefixChatFormat);
|
||||
|
||||
/**
|
||||
* Gets prefixChatFormat.
|
||||
* @return prefixChatFormat.
|
||||
*/
|
||||
String getPrefixChatFormat();
|
||||
|
||||
/**
|
||||
* Sets enforceAccess.
|
||||
@@ -145,4 +169,74 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
* @return useasyncchat.
|
||||
*/
|
||||
boolean getUseAsyncChat();
|
||||
|
||||
/**
|
||||
* Sets whether to suppress startup messages.
|
||||
*
|
||||
* @param silentStart true to suppress messages.
|
||||
*/
|
||||
void setSilentStart(boolean silentStart);
|
||||
|
||||
/**
|
||||
* Whether we are suppressing startup messages.
|
||||
*
|
||||
* @return true if we are suppressing startup messages.
|
||||
*/
|
||||
boolean getSilentStart();
|
||||
|
||||
/**
|
||||
* Sets whether or not to let Bukkit determine portal search radius on its own or if Multiverse should give input.
|
||||
*
|
||||
* @param useDefaultPortalSearch True to let Bukkit determine portal search radius on its own.
|
||||
*/
|
||||
void setUseDefaultPortalSearch(boolean useDefaultPortalSearch);
|
||||
|
||||
/**
|
||||
* Gets whether or not Bukkit will be determining portal search radius on its own or if Multiverse should help.
|
||||
*
|
||||
* @return True means Bukkit will use its own default values.
|
||||
*/
|
||||
boolean isUsingDefaultPortalSearch();
|
||||
|
||||
/**
|
||||
* Sets the radius at which vanilla style portals will be searched for to connect to worlds together.
|
||||
*
|
||||
* @param searchRadius The portal search radius.
|
||||
*/
|
||||
void setPortalSearchRadius(int searchRadius);
|
||||
|
||||
/**
|
||||
* Gets the radius at which vanilla style portals will be searched for to connect to worlds together.
|
||||
*
|
||||
* @return The portal search radius.
|
||||
*/
|
||||
int getPortalSearchRadius();
|
||||
|
||||
/**
|
||||
* Gets whether or not the automatic purge of entities is enabled.
|
||||
*
|
||||
* @return True if automatic purge is enabled.
|
||||
*/
|
||||
boolean isAutoPurgeEnabled();
|
||||
|
||||
/**
|
||||
* Sets whether or not the automatic purge of entities is enabled.
|
||||
*
|
||||
* @param autopurge True if automatic purge should be enabled.
|
||||
*/
|
||||
void setAutoPurgeEnabled(boolean autopurge);
|
||||
|
||||
/**
|
||||
* Gets whether or not the donation/patreon messages are shown.
|
||||
*
|
||||
* @return True if donation/patreon messages should be shown.
|
||||
*/
|
||||
boolean isShowingDonateMessage();
|
||||
|
||||
/**
|
||||
* Sets whether or not the donation/patreon messages are shown.
|
||||
*
|
||||
* @param idonotwanttodonate True if donation/patreon messages should be shown.
|
||||
*/
|
||||
void setShowDonateMessage(boolean idonotwanttodonate);
|
||||
}
|
||||
@@ -9,15 +9,16 @@ package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -154,37 +155,6 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
boolean setPropertyValue(String property, String value) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Gets the actual MVConfigProperty from this world.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to get.
|
||||
* @param expected The type of the expected property. Use Object.class if this doesn't matter for you.
|
||||
* @param <T> The type of the expected property.
|
||||
*
|
||||
* @return A valid MVWorldProperty.
|
||||
*
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
* @deprecated We don't use {@link com.onarandombox.MultiverseCore.configuration.MVConfigProperty} any longer!
|
||||
*/
|
||||
@Deprecated
|
||||
<T> com.onarandombox.MultiverseCore.configuration.MVConfigProperty<T> getProperty(String property, Class<T> expected) throws PropertyDoesNotExistException;
|
||||
|
||||
// old config
|
||||
/**
|
||||
* Adds the property to the given value.
|
||||
* It will throw a PropertyDoesNotExistException if the property is not found.
|
||||
*
|
||||
* @param property The name of a world property to set.
|
||||
* @param value A value in string representation, it will be parsed to the correct type.
|
||||
* @param sender The sender who wants this value to be set.
|
||||
* @return True if the value was set, false if not.
|
||||
* @throws PropertyDoesNotExistException Thrown if the property was not found in the world.
|
||||
* @deprecated Use {@link #setPropertyValue(String, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setProperty(String property, String value, CommandSender sender) throws PropertyDoesNotExistException;
|
||||
|
||||
/**
|
||||
* Adds a value to the given property. The property must be a {@link com.onarandombox.MultiverseCore.enums.AddProperties}.
|
||||
*
|
||||
@@ -505,26 +475,28 @@ public interface MultiverseWorld {
|
||||
/**
|
||||
* Sets the price for entry to this world.
|
||||
* You can think of this like an amount.
|
||||
* The type can be set with {@link #setCurrency(int)}
|
||||
* The type can be set with {@link #setCurrency(Material)}
|
||||
*
|
||||
* @param price The Amount of money/item to enter the world.
|
||||
*/
|
||||
void setPrice(double price);
|
||||
|
||||
/**
|
||||
* Gets the Type of currency that will be used when users enter this world.
|
||||
* Gets the type of currency that will be used when users enter this world. A value of null indicates a non-item
|
||||
* based currency is used.
|
||||
*
|
||||
* @return The Type of currency that will be used when users enter this world.
|
||||
* @return The type of currency that will be used when users enter this world.
|
||||
*/
|
||||
int getCurrency();
|
||||
@Nullable
|
||||
Material getCurrency();
|
||||
|
||||
/**
|
||||
* Sets the type of item that will be required given the price is not 0.
|
||||
* Use -1 to use an AllPay economy, or any valid itemid
|
||||
* Use a value of null to specify a non-item based currency.
|
||||
*
|
||||
* @param item The Type of currency that will be used when users enter this world.
|
||||
*/
|
||||
void setCurrency(int item);
|
||||
void setCurrency(@Nullable Material item);
|
||||
|
||||
/**
|
||||
* Gets the world players will respawn in if they die in this one.
|
||||
@@ -621,6 +593,22 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
void setBedRespawn(boolean autoLoad);
|
||||
|
||||
/**
|
||||
* Sets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
* @param limit The new limit
|
||||
*/
|
||||
void setPlayerLimit(int limit);
|
||||
|
||||
/**
|
||||
* Gets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
* @return The player limit
|
||||
*/
|
||||
int getPlayerLimit();
|
||||
|
||||
/**
|
||||
* Same as {@link #getTime()}, but returns a string.
|
||||
* @return The time as a short string: 12:34pm
|
||||
@@ -669,4 +657,18 @@ public interface MultiverseWorld {
|
||||
* @return All property names, with alternating colors.
|
||||
*/
|
||||
String getAllPropertyNames();
|
||||
|
||||
/**
|
||||
* Whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @return True if players allowed to fly in this world.
|
||||
*/
|
||||
boolean getAllowFlight();
|
||||
|
||||
/**
|
||||
* Sets whether or not players are allowed to fly in this world.
|
||||
*
|
||||
* @param allowFlight True to allow flight in this world.
|
||||
*/
|
||||
void setAllowFlight(final boolean allowFlight);
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
/**
|
||||
* Used to safely teleport people.
|
||||
*/
|
||||
public interface SafeTTeleporter {
|
||||
public interface SafeTTeleporter extends Teleporter {
|
||||
|
||||
/**
|
||||
* Gets the next safe location around the given location.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Teleporter {
|
||||
TeleportResult teleport(CommandSender teleporter, Player teleportee, MVDestination destination);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public interface WorldPurger {
|
||||
void purgeWorlds(List<MultiverseWorld> worlds);
|
||||
|
||||
/**
|
||||
* Convenience method for {@link #purgeWorld(CommandSender, MultiverseWorld, List, boolean, boolean)} that takes the settings from the world-config.
|
||||
* Convenience method for {@link #purgeWorld(MultiverseWorld, java.util.List, boolean, boolean)} that takes the settings from the world-config.
|
||||
*
|
||||
* @param world The {@link MultiverseWorld}.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -37,7 +38,7 @@ public class CheckCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = this.plugin.getServer().getPlayer(args.get(0));
|
||||
Player p = PlayerFinder.get(args.get(0), sender);
|
||||
if (p == null) {
|
||||
sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0));
|
||||
sender.sendMessage("Are they online?");
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
|
||||
/**
|
||||
* Creates a clone of a world.
|
||||
@@ -34,27 +33,23 @@ public class CloneCommand extends MultiverseCommand {
|
||||
this.addKey("mv clone");
|
||||
this.addCommandExample("/mv clone " + ChatColor.GOLD + "world" + ChatColor.GREEN + " world_backup");
|
||||
this.addCommandExample("/mv clone " + ChatColor.GOLD + "skyblock_pristine" + ChatColor.GREEN + " skyblock");
|
||||
this.addCommandExample("To clone a world that uses a generator:");
|
||||
this.addCommandExample("/mv clone " + ChatColor.GOLD + "CleanRoom"
|
||||
+ ChatColor.GREEN + " CleanRoomCopy" + ChatColor.DARK_AQUA + " -g CleanRoomGenerator");
|
||||
this.setPermission("multiverse.core.clone", "Clones a world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Class<?>[] paramTypes = {String.class, String.class, String.class};
|
||||
List<Object> objectArgs = new ArrayList<Object>();
|
||||
objectArgs.add(args.get(0));
|
||||
objectArgs.add(args.get(1));
|
||||
objectArgs.add(CommandHandler.getFlag("-g", args));
|
||||
if (!this.worldManager.isMVWorld(args.get(0))) {
|
||||
String oldName = args.get(0);
|
||||
if (!this.worldManager.hasUnloadedWorld(oldName, true)) {
|
||||
// If no world was found, we can't clone.
|
||||
sender.sendMessage("Sorry, Multiverse doesn't know about world " + args.get(0) + ", so we can't clone it!");
|
||||
sender.sendMessage("Sorry, Multiverse doesn't know about world " + oldName + ", so we can't clone it!");
|
||||
sender.sendMessage("Check the " + ChatColor.GREEN + "/mv list" + ChatColor.WHITE + " command to verify it is listed.");
|
||||
return;
|
||||
}
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvclone", "cloneWorld", objectArgs,
|
||||
paramTypes, ChatColor.GREEN + "World Cloned!", ChatColor.RED + "World could NOT be cloned!");
|
||||
if (this.plugin.getMVWorldManager().cloneWorld(oldName, args.get(1))) {
|
||||
sender.sendMessage(ChatColor.GREEN + "World cloned!");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "World could NOT be cloned!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class ConfirmCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
this.plugin.getCommandHandler().confirmQueuedCommand(sender);
|
||||
this.plugin.getCommandQueueManager().runQueuedCommand(sender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class CoordCommand extends MultiverseCommand {
|
||||
df.setMaximumFractionDigits(2);
|
||||
p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + plugin.getLocationManipulation().strCoords(p.getLocation()));
|
||||
p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + plugin.getLocationManipulation().getDirection(p.getLocation()));
|
||||
p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + Material.getMaterial(world.getBlockTypeIdAt(p.getLocation())));
|
||||
p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + world.getBlockAt(p.getLocation()).getType());
|
||||
} else {
|
||||
sender.sendMessage("This command needs to be used from a Player.");
|
||||
}
|
||||
|
||||
@@ -46,10 +46,15 @@ public class CreateCommand extends MultiverseCommand {
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
|
||||
private String trimWorldName(String userInput) {
|
||||
// Removes relative paths.
|
||||
return userInput.replaceAll("^[./\\\\]+", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = args.get(0);
|
||||
String worldName = trimWorldName(args.get(0));
|
||||
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
String env = args.get(1);
|
||||
String seed = CommandHandler.getFlag("-s", args);
|
||||
@@ -66,9 +71,16 @@ public class CreateCommand extends MultiverseCommand {
|
||||
useSpawnAdjust = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Make sure the world name doesn't contain the words 'plugins' and '.dat'
|
||||
if(worldName.contains("plugins")||worldName.contains(".dat")){
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD +ChatColor.UNDERLINE + "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
|
||||
+ "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -116,4 +128,4 @@ public class CreateCommand extends MultiverseCommand {
|
||||
Command.broadcastCommandMessage(sender, "FAILED.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -23,7 +24,7 @@ public class DebugCommand extends MultiverseCommand {
|
||||
public DebugCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Turn Debug on/off?");
|
||||
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off]");
|
||||
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv debug");
|
||||
this.addKey("mv d");
|
||||
@@ -55,11 +56,12 @@ public class DebugCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
private void displayDebugMode(CommandSender sender) {
|
||||
if (plugin.getMVConfig().getGlobalDebug() == 0) {
|
||||
final int debugLevel = plugin.getMVConfig().getGlobalDebug();
|
||||
if (debugLevel == 0) {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
|
||||
} else {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + plugin.getMVConfig().getGlobalDebug());
|
||||
this.plugin.log(Level.FINE, "Multiverse Debug ENABLED");
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel);
|
||||
Logging.fine("Multiverse Debug ENABLED");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,11 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,15 +29,32 @@ public class DeleteCommand extends MultiverseCommand {
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvdelete");
|
||||
this.addKey("mv delete");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "MyWorld");
|
||||
this.addCommandExample("/mv delete " + ChatColor.GOLD + "MyWorld");
|
||||
this.setPermission("multiverse.core.delete", "Deletes a world on your server. " + ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Class<?>[] paramTypes = {String.class};
|
||||
List<Object> objectArgs = new ArrayList<Object>(args);
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", objectArgs,
|
||||
paramTypes, ChatColor.GREEN + "World Deleted!", ChatColor.RED + "World could NOT be deleted!");
|
||||
String worldName = args.get(0);
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
deleteRunnable(sender, worldName),
|
||||
String.format("Are you sure you want to delete world '%s'? You cannot undo this action.", worldName)
|
||||
));
|
||||
}
|
||||
|
||||
private Runnable deleteRunnable(@NotNull CommandSender sender,
|
||||
@NotNull String worldName) {
|
||||
|
||||
return () -> {
|
||||
sender.sendMessage(String.format("Deleting world '%s'...", worldName));
|
||||
if (this.plugin.getMVWorldManager().deleteWorld(worldName)) {
|
||||
sender.sendMessage(String.format("%sWorld %s was deleted!", ChatColor.GREEN, worldName));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(String.format("%sThere was an issue deleting '%s'! Please check console for errors.",
|
||||
ChatColor.RED, worldName));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -71,12 +71,14 @@ public class EnvironmentCommand extends MultiverseCommand {
|
||||
*/
|
||||
public static WorldType getWorldTypeFromString(String type) {
|
||||
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
|
||||
if (type.equalsIgnoreCase("normal"))
|
||||
if (type.equalsIgnoreCase("normal")) {
|
||||
type = "NORMAL";
|
||||
if (type.equalsIgnoreCase("flat"))
|
||||
} else if (type.equalsIgnoreCase("flat")) {
|
||||
type = "FLAT";
|
||||
if (type.equalsIgnoreCase("largebiomes")) {
|
||||
} else if (type.equalsIgnoreCase("largebiomes")) {
|
||||
type = "LARGE_BIOMES";
|
||||
} else if (type.equalsIgnoreCase("amplified")) {
|
||||
type = "AMPLIFIED";
|
||||
}
|
||||
try {
|
||||
// Now that we've converted a potentially unfriendly value
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GameruleCommand extends MultiverseCommand {
|
||||
|
||||
public GameruleCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Set a Minecraft Game Rule for a World.");
|
||||
this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mv gamerule");
|
||||
this.addKey("mv rule");
|
||||
this.addKey("mvgamerule");
|
||||
this.addKey("mvrule");
|
||||
this.addCommandExample("/mv gamerule " + ChatColor.GREEN + "doMobLoot false");
|
||||
this.addCommandExample("/mvrule " + ChatColor.GREEN + "keepInventory true " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.set", "Allows a player to set a gamerule.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final GameRule gameRule = GameRule.getByName(args.get(0));
|
||||
final String value = args.get(1);
|
||||
final World world;
|
||||
if (args.size() == 2) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(2));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(2)
|
||||
+ ChatColor.WHITE + " does not exist.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (gameRule == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Failure! " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE
|
||||
+ " is not a valid gamerule.");
|
||||
} else {
|
||||
if (gameRule.getType() == Boolean.class) {
|
||||
boolean booleanValue;
|
||||
if (value.equalsIgnoreCase("true")) {
|
||||
booleanValue = true;
|
||||
} else if (value.equalsIgnoreCase("false")) {
|
||||
booleanValue = false;
|
||||
} else {
|
||||
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to true or false.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!world.setGameRule(gameRule, booleanValue)) {
|
||||
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong.");
|
||||
return;
|
||||
}
|
||||
} else if (gameRule.getType() == Integer.class) {
|
||||
try {
|
||||
if (!world.setGameRule(gameRule, Integer.parseInt(value))) {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to a positive integer.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName()
|
||||
+ ChatColor.WHITE + " isn't supported yet, please let us know about it.");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName()
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + ".");
|
||||
}
|
||||
}
|
||||
|
||||
private String getErrorMessage(String gameRule, String value) {
|
||||
return ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " could not be set to " + ChatColor.RED + value + ChatColor.WHITE + ", ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class GamerulesCommand extends MultiverseCommand {
|
||||
|
||||
public GamerulesCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("List the Minecraft Game Rules for a World.");
|
||||
this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv gamerules");
|
||||
this.addKey("mv rules");
|
||||
this.addKey("mvgamerules");
|
||||
this.addKey("mvrules");
|
||||
this.addCommandExample("/mv gamerules");
|
||||
this.addCommandExample("/mvrules " + ChatColor.RED + "world_nether");
|
||||
this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
final Player p;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
} else {
|
||||
p = null;
|
||||
}
|
||||
|
||||
if (args.size() == 0 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
final World world;
|
||||
if (args.size() == 0) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
world = Bukkit.getWorld(args.get(0));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0)
|
||||
+ ChatColor.WHITE + " does not exist.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder gameRules = new StringBuilder();
|
||||
for (final String gameRule : world.getGameRules()) {
|
||||
if (gameRules.length() != 0) {
|
||||
gameRules.append(ChatColor.WHITE).append(", ");
|
||||
}
|
||||
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
|
||||
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(GameRule.getByName(gameRule)));
|
||||
}
|
||||
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
|
||||
sender.sendMessage(gameRules.toString());
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -15,7 +16,6 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Returns a list of loaded generator plugins.
|
||||
@@ -37,7 +37,7 @@ public class GeneratorCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
this.plugin.log(Level.INFO, "PLEASE IGNORE the 'Plugin X does not contain any generators' message below!");
|
||||
Logging.info("PLEASE IGNORE the 'Plugin X does not contain any generators' message below!");
|
||||
Plugin[] plugins = this.plugin.getServer().getPluginManager().getPlugins();
|
||||
List<String> generators = new ArrayList<String>();
|
||||
for (Plugin p : plugins) {
|
||||
|
||||
@@ -9,7 +9,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldNameChecker;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
@@ -18,8 +18,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,63 +43,30 @@ public class ImportCommand extends MultiverseCommand {
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* A very basic check to see if a folder has a level.dat file.
|
||||
* If it does, we can safely assume it's a world folder.
|
||||
*
|
||||
* @param worldFolder The File that may be a world.
|
||||
* @return True if it looks like a world, false if not.
|
||||
*/
|
||||
private static boolean checkIfIsWorld(File worldFolder) {
|
||||
if (worldFolder.isDirectory()) {
|
||||
File[] files = worldFolder.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return name.equalsIgnoreCase("level.dat");
|
||||
}
|
||||
});
|
||||
if (files != null && files.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getPotentialWorlds() {
|
||||
File worldFolder = this.plugin.getServer().getWorldContainer();
|
||||
if (worldFolder == null) {
|
||||
return "";
|
||||
}
|
||||
File[] files = worldFolder.listFiles();
|
||||
String worldList = "";
|
||||
Collection<MultiverseWorld> worlds = this.worldManager.getMVWorlds();
|
||||
List<String> worldStrings = new ArrayList<String>();
|
||||
for (MultiverseWorld world : worlds) {
|
||||
worldStrings.add(world.getName());
|
||||
}
|
||||
for (String world : this.worldManager.getUnloadedWorlds()) {
|
||||
worldStrings.add(world);
|
||||
}
|
||||
private String getPotentialWorldStrings() {
|
||||
final Collection<String> potentialWorlds = this.worldManager.getPotentialWorlds();
|
||||
StringBuilder worldList = new StringBuilder();
|
||||
ChatColor currColor = ChatColor.WHITE;
|
||||
for (File file : files) {
|
||||
if (file.isDirectory() && checkIfIsWorld(file) && !worldStrings.contains(file.getName())) {
|
||||
worldList += currColor + file.getName() + " ";
|
||||
if (currColor == ChatColor.WHITE) {
|
||||
currColor = ChatColor.YELLOW;
|
||||
} else {
|
||||
currColor = ChatColor.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
for (String world : potentialWorlds) {
|
||||
worldList.append(currColor).append(world).append(' ');
|
||||
currColor = currColor == ChatColor.WHITE ? ChatColor.YELLOW : ChatColor.WHITE;
|
||||
}
|
||||
return worldList;
|
||||
|
||||
return worldList.toString();
|
||||
}
|
||||
|
||||
private String trimWorldName(String userInput) {
|
||||
// Removes relative paths.
|
||||
return userInput.replaceAll("^[./\\\\]+", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = args.get(0);
|
||||
String worldName = trimWorldName(args.get(0));
|
||||
|
||||
if (worldName.toLowerCase().equals("--list") || worldName.toLowerCase().equals("-l")) {
|
||||
String worldList = this.getPotentialWorlds();
|
||||
String worldList = this.getPotentialWorldStrings();
|
||||
if (worldList.length() > 2) {
|
||||
sender.sendMessage(ChatColor.AQUA + "====[ These look like worlds ]====");
|
||||
sender.sendMessage(worldList);
|
||||
@@ -112,10 +77,16 @@ public class ImportCommand extends MultiverseCommand {
|
||||
}
|
||||
// Since we made an exception for the list, we have to make sure they have at least 2 params:
|
||||
// Note the exception is --list, which is covered above.
|
||||
if (args.size() == 1) {
|
||||
if (args.size() == 1 || worldName.length() < 1) {
|
||||
this.showHelp(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the world name doesn't contain the words 'plugins' and '.dat'
|
||||
if(worldName.contains("plugins")||worldName.contains(".dat")){
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we don't already know about this world.
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
@@ -142,21 +113,25 @@ public class ImportCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldFile.exists() && env != null) {
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust))
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
|
||||
else
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
|
||||
if (!worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
String worldList = this.getPotentialWorldStrings();
|
||||
sender.sendMessage("That world folder does not exist. These look like worlds to me:");
|
||||
sender.sendMessage(worldList);
|
||||
} else if (!WorldNameChecker.isValidWorldFolder(worldFile)) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage(String.format("'%s' does not appear to be a world. It is lacking a .dat file.",
|
||||
worldName));
|
||||
} else if (env == null) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
sender.sendMessage("That world environment did not exist.");
|
||||
sender.sendMessage("For a list of available world types, type: " + ChatColor.AQUA + "/mvenv");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
String worldList = this.getPotentialWorlds();
|
||||
sender.sendMessage("That world folder does not exist. These look like worlds to me:");
|
||||
sender.sendMessage(worldList);
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust))
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!");
|
||||
else
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
FancyColorScheme colors = new FancyColorScheme(ChatColor.AQUA, ChatColor.AQUA, ChatColor.GOLD, ChatColor.WHITE);
|
||||
message.add(new FancyHeader("General Info", colors));
|
||||
message.add(new FancyMessage("World Name: ", world.getName(), colors));
|
||||
message.add(new FancyMessage("World UID: ", world.getCBWorld().getUID().toString(), colors));
|
||||
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
|
||||
message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors));
|
||||
message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors));
|
||||
@@ -122,15 +123,16 @@ public class InfoCommand extends MultiverseCommand {
|
||||
//message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors));
|
||||
Location spawn = world.getSpawnLocation();
|
||||
message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors));
|
||||
message.add(new FancyMessage("World Scale: ", world.getScaling() + "", colors));
|
||||
message.add(new FancyMessage("World Scale: ", String.valueOf(world.getScaling()), colors));
|
||||
message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors));
|
||||
if (world.getPrice() > 0) {
|
||||
final String formattedAmount;
|
||||
if (world.getCurrency() <= 0 && plugin.getVaultEconomy() != null) {
|
||||
formattedAmount = plugin.getVaultEconomy().format(world.getPrice());
|
||||
} else {
|
||||
formattedAmount = this.plugin.getBank().getFormattedAmount(p, world.getPrice(), world.getCurrency());
|
||||
}
|
||||
message.add(new FancyMessage("Price to enter this world: ", formattedAmount, colors));
|
||||
message.add(new FancyMessage("Price to enter this world: ",
|
||||
plugin.getEconomist().formatPrice(world.getPrice(), world.getCurrency()),
|
||||
colors));
|
||||
} else if (world.getPrice() < 0) {
|
||||
message.add(new FancyMessage("Reward for entering this world: ",
|
||||
plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency()),
|
||||
colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors));
|
||||
}
|
||||
@@ -150,6 +152,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
message = new ArrayList<FancyText>();
|
||||
message.add(new FancyHeader("More World Settings", colors));
|
||||
message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors));
|
||||
message.add(new FancyMessage("Generator: ", world.getGenerator(), colors));
|
||||
message.add(new FancyMessage("Structures: ", world.getCBWorld().canGenerateStructures() + "", colors));
|
||||
message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
|
||||
@@ -180,8 +183,8 @@ public class InfoCommand extends MultiverseCommand {
|
||||
message.add(new FancyHeader("Animal Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.canAnimalsSpawn() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors));
|
||||
if (world.getMonsterList().size() > 0) {
|
||||
if (world.canMonstersSpawn()) {
|
||||
if (world.getAnimalList().size() > 0) {
|
||||
if (world.canAnimalsSpawn()) {
|
||||
message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT "
|
||||
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors));
|
||||
} else {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ListCommand extends PaginatedCoreCommand<String> {
|
||||
public ListCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Listing");
|
||||
this.setCommandUsage("/mv list");
|
||||
this.setCommandUsage("/mv list [page]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mvlist");
|
||||
this.addKey("mvl");
|
||||
|
||||
@@ -77,7 +77,7 @@ public class ModifyAddCommand extends MultiverseCommand {
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Add, property)) {
|
||||
sender.sendMessage("Sorry, you can't ADD to " + property);
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/4W8cY");
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/OMGwzx");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ModifyClearCommand extends MultiverseCommand {
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Clear, property)) {
|
||||
sender.sendMessage("Sorry, you can't use CLEAR with " + property);
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/cgB2B");
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/q1h01S");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ModifyRemoveCommand extends MultiverseCommand {
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Remove, property)) {
|
||||
sender.sendMessage("Sorry, you can't REMOVE anything from" + property);
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: http://goo.gl/4W8cY");
|
||||
sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/OMGwzx");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -23,8 +25,8 @@ public class RegenCommand extends MultiverseCommand {
|
||||
public RegenCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Regenerates a World");
|
||||
this.setCommandUsage("/mv regen" + ChatColor.GREEN + " {WORLD}" + ChatColor.GOLD + " [-s [SEED]]");
|
||||
this.setArgRange(1, 3);
|
||||
this.setCommandUsage("/mv regen" + ChatColor.GREEN + " {WORLD}" + ChatColor.GOLD + " [-s [SEED]] [--keep-gamerules]");
|
||||
this.setArgRange(1, 4);
|
||||
this.addKey("mvregen");
|
||||
this.addKey("mv regen");
|
||||
this.addCommandExample("You can use the -s with no args to get a new seed:");
|
||||
@@ -37,17 +39,31 @@ public class RegenCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Boolean useseed = (!(args.size() == 1));
|
||||
Boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s"));
|
||||
String worldName = args.get(0);
|
||||
boolean useseed = (!(args.size() == 1));
|
||||
boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s"));
|
||||
String seed = (args.size() == 3) ? args.get(2) : "";
|
||||
boolean keepGamerules = CommandHandler.hasFlag("--keep-gamerules", args);
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
doWorldRegen(sender, worldName, useseed, randomseed, seed, keepGamerules),
|
||||
String.format("Are you sure you want to regen '%s'? You cannot undo this action.", worldName)
|
||||
));
|
||||
}
|
||||
|
||||
Class<?>[] paramTypes = {String.class, Boolean.class, Boolean.class, String.class};
|
||||
List<Object> objectArgs = new ArrayList<Object>();
|
||||
objectArgs.add(args.get(0));
|
||||
objectArgs.add(useseed);
|
||||
objectArgs.add(randomseed);
|
||||
objectArgs.add(seed);
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvregen", "regenWorld", objectArgs,
|
||||
paramTypes, ChatColor.GREEN + "World Regenerated!", ChatColor.RED + "World could NOT be regenerated!");
|
||||
private Runnable doWorldRegen(@NotNull CommandSender sender,
|
||||
@NotNull String worldName,
|
||||
boolean useSeed,
|
||||
boolean randomSeed,
|
||||
@NotNull String seed,
|
||||
boolean keepGamerules) {
|
||||
|
||||
return () -> {
|
||||
if (this.plugin.getMVWorldManager().regenWorld(worldName, useSeed, randomSeed, seed, keepGamerules)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "World Regenerated!");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "World could NOT be regenerated!");
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class ReloadCommand extends MultiverseCommand {
|
||||
this.setCommandUsage("/mv reload");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvreload");
|
||||
this.addKey("mvr");
|
||||
this.addKey("mv reload");
|
||||
this.addCommandExample("/mv reload");
|
||||
this.setPermission("multiverse.core.reload", "Reloads worlds.yml and config.yml.", PermissionDefault.OP);
|
||||
|
||||
@@ -35,6 +35,10 @@ public class ScriptCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (plugin.getScriptAPI() == null) {
|
||||
sender.sendMessage("Buscript failed to load while the server was starting. Scripts cannot be run.");
|
||||
return;
|
||||
}
|
||||
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
|
||||
if (!file.exists()) {
|
||||
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Sets the spawn for a world.
|
||||
@@ -27,8 +28,9 @@ public class SetSpawnCommand extends MultiverseCommand {
|
||||
super(plugin);
|
||||
this.setName("Set World Spawn");
|
||||
this.setCommandUsage("/mv setspawn");
|
||||
this.setArgRange(0, 0);
|
||||
this.setArgRange(0, 6);
|
||||
this.addKey("mvsetspawn");
|
||||
this.addKey("mvsets");
|
||||
this.addKey("mvss");
|
||||
this.addKey("mv set spawn");
|
||||
this.addKey("mv setspawn");
|
||||
@@ -37,40 +39,110 @@ public class SetSpawnCommand extends MultiverseCommand {
|
||||
this.setPermission("multiverse.core.spawn.set", "Sets the spawn for the current world.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches the user's command depending on the number of parameters
|
||||
* @param sender The player who executes the command, may be console as well.
|
||||
* @param args Command line parameters
|
||||
*/
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
setWorldSpawn(sender);
|
||||
if (args.isEmpty()) {
|
||||
setWorldSpawn(sender);
|
||||
} else if (args.size() == 4) {
|
||||
setWorldSpawn(sender, args.get(0), args.get(1), args.get(2), args.get(3));
|
||||
} else if (args.size() == 6) {
|
||||
setWorldSpawn(sender, args.get(0), args.get(1), args.get(2), args.get(3), args.get(4), args.get(5));
|
||||
} else {
|
||||
sender.sendMessage("Use no arguments for your current location, or world/x/y/z, or world/x/y/z/yaw/pitch!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual spawn-setting-work.
|
||||
*
|
||||
* @param sender The {@link CommandSender} that's setting the spawn.
|
||||
* Set the world spawn when no parameters are given
|
||||
* @param sender The {@link CommandSender} who executes the command.
|
||||
* Everything not a {@link Player}, e.g. console, gets rejected, as we can't get coordinates from there.
|
||||
*/
|
||||
protected void setWorldSpawn(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location l = p.getLocation();
|
||||
World w = p.getWorld();
|
||||
MultiverseWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName());
|
||||
if (foundWorld != null) {
|
||||
foundWorld.setSpawnLocation(p.getLocation());
|
||||
BlockSafety bs = this.plugin.getBlockSafety();
|
||||
if (!bs.playerCanSpawnHereSafely(p.getLocation()) && foundWorld.getAdjustSpawn()) {
|
||||
sender.sendMessage("It looks like that location would normally be unsafe. But I trust you.");
|
||||
sender.sendMessage("I'm turning off the Safe-T-Teleporter for spawns to this world.");
|
||||
sender.sendMessage("If you want this turned back on just do:");
|
||||
sender.sendMessage(ChatColor.AQUA + "/mvm set adjustspawn true " + foundWorld.getAlias());
|
||||
foundWorld.setAdjustSpawn(false);
|
||||
}
|
||||
sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(p.getLocation()));
|
||||
} else {
|
||||
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws).");
|
||||
}
|
||||
|
||||
setWorldSpawn(sender, w, l);
|
||||
} else {
|
||||
sender.sendMessage("You cannot use this command from the console.");
|
||||
sender.sendMessage("You need to give coordinates to use this command from the console!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the world spawn when 4 parameters are given
|
||||
* @param sender The {@link CommandSender} who executes the command
|
||||
* @param world The world to set the spawn in
|
||||
* @param x X-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param y Y-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param z Z-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
*/
|
||||
protected void setWorldSpawn(CommandSender sender, String world, String x, String y, String z) {
|
||||
setWorldSpawn(sender, world, x, y, z, "0", "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the world spawn when 6 parameters are given
|
||||
* @param sender The {@link CommandSender} who executes the command
|
||||
* @param world The world to set the spawn in
|
||||
* @param x X-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param y Y-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param z Z-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double)
|
||||
* @param yaw Yaw a newly spawned player should look at (as a {@link String} as it's from the command line, gets parsed into a float)
|
||||
* @param pitch Pitch a newly spawned player should look at (as a {@link String} as it's from the command line, gets parsed into a float)
|
||||
*/
|
||||
protected void setWorldSpawn(CommandSender sender, String world, String x, String y, String z, String yaw, String pitch) {
|
||||
double dx, dy, dz;
|
||||
float fpitch, fyaw;
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
if (bukkitWorld == null) {
|
||||
sender.sendMessage("World " + world + " is unknown!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
dx = Double.parseDouble(x);
|
||||
dy = Double.parseDouble(y);
|
||||
dz = Double.parseDouble(z);
|
||||
fpitch = Float.parseFloat(pitch);
|
||||
fyaw = Float.parseFloat(yaw);
|
||||
} catch (NumberFormatException ex) {
|
||||
sender.sendMessage("All coordinates must be numeric");
|
||||
return;
|
||||
}
|
||||
Location l = new Location(bukkitWorld, dx, dy, dz, fyaw, fpitch);
|
||||
setWorldSpawn(sender, bukkitWorld, l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual spawn-setting-work.
|
||||
*
|
||||
* @param sender The {@link CommandSender} that's setting the spawn.
|
||||
* @param w The {@link World} to set the spawn in
|
||||
* @param l The {@link Location} to set the spawn to
|
||||
*/
|
||||
private void setWorldSpawn(CommandSender sender, World w, Location l) {
|
||||
MultiverseWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName());
|
||||
if (foundWorld != null) {
|
||||
foundWorld.setSpawnLocation(l);
|
||||
BlockSafety bs = this.plugin.getBlockSafety();
|
||||
if (!bs.playerCanSpawnHereSafely(l) && foundWorld.getAdjustSpawn()) {
|
||||
sender.sendMessage("It looks like that location would normally be unsafe. But I trust you.");
|
||||
sender.sendMessage("I'm turning off the Safe-T-Teleporter for spawns to this world.");
|
||||
sender.sendMessage("If you want this turned back on just do:");
|
||||
sender.sendMessage(ChatColor.AQUA + "/mvm set adjustspawn true " + foundWorld.getAlias());
|
||||
foundWorld.setAdjustSpawn(false);
|
||||
}
|
||||
sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(l));
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws).");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Enables debug-information.
|
||||
*/
|
||||
public class SilentCommand extends MultiverseCommand {
|
||||
|
||||
public SilentCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Turn silent mode on/off?");
|
||||
this.setCommandUsage("/mv silent" + ChatColor.GOLD + " [true|false|on|off]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv silent");
|
||||
this.addKey("mvsilent");
|
||||
this.addCommandExample("/mv silent " + ChatColor.GOLD + "true");
|
||||
this.setPermission("multiverse.core.silent", "Reduces the amount of startup messages.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("on")) {
|
||||
args.set(0, "true");
|
||||
}
|
||||
plugin.getMVConfig().setSilentStart(Boolean.valueOf(args.get(0)));
|
||||
plugin.saveMVConfigs();
|
||||
}
|
||||
this.displaySilentMode(sender);
|
||||
}
|
||||
|
||||
private void displaySilentMode(CommandSender sender) {
|
||||
if (plugin.getMVConfig().getSilentStart()) {
|
||||
sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.GREEN + "ON");
|
||||
} else {
|
||||
sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.RED + "OFF");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -50,7 +51,7 @@ public class SpawnCommand extends MultiverseCommand {
|
||||
sender.sendMessage("You don't have permission to teleport another player to spawn. (multiverse.core.spawn.other)");
|
||||
return;
|
||||
}
|
||||
Player target = this.plugin.getServer().getPlayer(args.get(0));
|
||||
Player target = PlayerFinder.get(args.get(0), sender);
|
||||
if (target != null) {
|
||||
target.sendMessage("Teleporting to this world's spawn...");
|
||||
spawnAccurately(target);
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
/*
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.getspout.spoutapi.gui.GenericButton;
|
||||
import org.getspout.spoutapi.gui.GenericPopup;
|
||||
import org.getspout.spoutapi.gui.PopupScreen;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Edit a world with spout.
|
||||
* /
|
||||
public class SpoutCommand extends MultiverseCommand {
|
||||
|
||||
public SpoutCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Edit World with Spout");
|
||||
this.setCommandUsage("/mv spout");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv spout");
|
||||
this.setPermission("multiverse.core.spout", "Edit a world with spout.", PermissionDefault.OP);
|
||||
this.addCommandExample("/mv spout");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command must be run as a player!");
|
||||
return;
|
||||
}
|
||||
if (plugin.getSpout() == null) {
|
||||
sender.sendMessage(ChatColor.RED + "You need spout installed on this server to use it with Multiverse!");
|
||||
return;
|
||||
}
|
||||
SpoutPlayer p = (SpoutPlayer) sender;
|
||||
if (!p.isSpoutCraftEnabled()) {
|
||||
sender.sendMessage(ChatColor.RED + p.getName() + "You need to be using the Spoutcraft client to run this command!");
|
||||
return;
|
||||
}
|
||||
PopupScreen pop = new GenericPopup();
|
||||
GenericButton button = new GenericButton("Fish");
|
||||
// TO-DO maybe use constants for these
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
button.setX(50);
|
||||
button.setY(50);
|
||||
button.setWidth(100);
|
||||
button.setHeight(40);
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
pop.attachWidget(this.plugin, button);
|
||||
sender.sendMessage(ChatColor.GREEN + "YAY!");
|
||||
p.getMainScreen().attachPopupScreen(pop);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -7,14 +7,19 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -25,7 +30,6 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Used to teleport players.
|
||||
@@ -38,7 +42,7 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
Permission menu = new Permission("multiverse.teleport.*", "Allows you to display the teleport menu.", PermissionDefault.OP);
|
||||
|
||||
this.setName("Teleport");
|
||||
this.setCommandUsage("/mv tp " + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setCommandUsage("/mv tp " + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {DESTINATION}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvtp");
|
||||
this.addKey("mv tp");
|
||||
@@ -56,7 +60,7 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
String destinationName;
|
||||
|
||||
if (args.size() == 2) {
|
||||
teleportee = this.plugin.getServer().getPlayer(args.get(0));
|
||||
teleportee = PlayerFinder.get(args.get(0), sender);
|
||||
if (teleportee == null) {
|
||||
this.messaging.sendMessage(sender, String.format("Sorry, I couldn't find player: %s%s",
|
||||
ChatColor.GOLD, args.get(0)), false);
|
||||
@@ -72,27 +76,14 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
}
|
||||
teleportee = (Player) sender;
|
||||
}
|
||||
// Special case for cannons:
|
||||
if (destinationName.matches("(?i)cannon-[\\d]+(\\.[\\d]+)?")) {
|
||||
String[] cannonSpeed = destinationName.split("-");
|
||||
try {
|
||||
double speed = Double.parseDouble(cannonSpeed[1]);
|
||||
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
|
||||
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
|
||||
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
|
||||
} catch (Exception e) {
|
||||
destinationName = "i:invalid";
|
||||
}
|
||||
|
||||
}
|
||||
DestinationFactory df = this.plugin.getDestFactory();
|
||||
MVDestination d = df.getDestination(destinationName);
|
||||
|
||||
MVDestination d = df.getPlayerAwareDestination(teleportee, destinationName);
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter, true);
|
||||
this.plugin.getServer().getPluginManager().callEvent(teleportEvent);
|
||||
if (teleportEvent.isCancelled()) {
|
||||
this.plugin.log(Level.FINE, "Someone else cancelled the MVTeleport Event!!!");
|
||||
Logging.fine("Someone else cancelled the MVTeleport Event!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -156,28 +147,33 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false);
|
||||
return;
|
||||
}
|
||||
TeleportResult result = this.playerTeleporter.safelyTeleport(teleporter, teleportee, d);
|
||||
Teleporter teleportObject = (d instanceof CustomTeleporterDestination) ?
|
||||
((CustomTeleporterDestination)d).getTeleporter() : this.playerTeleporter;
|
||||
TeleportResult result = teleportObject.teleport(teleporter, teleportee, d);
|
||||
if (result == TeleportResult.FAIL_UNSAFE) {
|
||||
this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName()
|
||||
Logging.fine("Could not teleport " + teleportee.getName()
|
||||
+ " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee)));
|
||||
this.plugin.log(Level.FINE, "Queueing Command");
|
||||
Class<?>[] paramTypes = { CommandSender.class, Player.class, Location.class };
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
items.add(teleporter);
|
||||
items.add(teleportee);
|
||||
items.add(d.getLocation(teleportee));
|
||||
|
||||
String player = "you";
|
||||
if (!teleportee.equals(teleporter)) {
|
||||
player = teleportee.getName();
|
||||
}
|
||||
String message = String.format("%sMultiverse %sdid not teleport %s%s%sto %s%s%sbecause it was unsafe.",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE);
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "teleportPlayer", items,
|
||||
paramTypes, message, "Would you like to try anyway?", "", "", UNSAFE_TELEPORT_EXPIRE_DELAY);
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
doUnsafeTeleport(teleporter, teleportee, d.getLocation(teleportee)),
|
||||
String.format("%sMultiverse %sdid not teleport %s%s %sto %s%s %sbecause it was unsafe. Would you like to try anyway?",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE),
|
||||
UNSAFE_TELEPORT_EXPIRE_DELAY
|
||||
));
|
||||
}
|
||||
// else: Player was teleported successfully (or the tp event was fired I should say)
|
||||
}
|
||||
|
||||
private Runnable doUnsafeTeleport(CommandSender teleporter, Player player, Location location) {
|
||||
return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, player, location, false);
|
||||
}
|
||||
|
||||
private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) {
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) {
|
||||
|
||||
@@ -7,38 +7,122 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.BitlyURLShortener;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteService;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortener;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerType;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Dumps version info to the console.
|
||||
*/
|
||||
public class VersionCommand extends MultiverseCommand {
|
||||
private static final URLShortener SHORTENER = new BitlyURLShortener();
|
||||
private static final URLShortener SHORTENER = URLShortenerFactory.getService(URLShortenerType.BITLY);
|
||||
|
||||
public VersionCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Multiverse Version");
|
||||
this.setCommandUsage("/mv version " + ChatColor.GOLD + "-[pb]");
|
||||
this.setArgRange(0, 1);
|
||||
this.setCommandUsage("/mv version " + ChatColor.GOLD + "[-b|-h|-p] [--include-plugin-list]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv version");
|
||||
this.addKey("mvver");
|
||||
this.addKey("mvv");
|
||||
this.addKey("mvversion");
|
||||
this.setPermission("multiverse.core.version",
|
||||
"Dumps version info to the console, optionally to pastie.org with -p or pastebin.com with a -b.", PermissionDefault.TRUE);
|
||||
this.setPermission(
|
||||
"multiverse.core.version",
|
||||
"Dumps version info to the console, optionally to pastebin.com with -b, to hastebin.com using -h, or to paste.gg with -p.",
|
||||
PermissionDefault.OP)
|
||||
;
|
||||
}
|
||||
|
||||
private String getLegacyString() {
|
||||
return "[Multiverse-Core] Multiverse-Core Version: " + this.plugin.getDescription().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] Bukkit Version: " + this.plugin.getServer().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] Loaded Worlds: " + this.plugin.getMVWorldManager().getMVWorlds() + '\n'
|
||||
+ "[Multiverse-Core] Multiverse Plugins Loaded: " + this.plugin.getPluginCount() + '\n'
|
||||
+"[Multiverse-Core] Economy being used: " + plugin.getEconomist().getEconomyName() + '\n'
|
||||
+ "[Multiverse-Core] Permissions Plugin: " + this.plugin.getMVPerms().getType() + '\n'
|
||||
+ "[Multiverse-Core] Dumping Config Values: (version " + this.plugin.getMVConfig().getVersion() + ")" + '\n'
|
||||
+ "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + '\n'
|
||||
+ "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + '\n'
|
||||
+ "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + '\n'
|
||||
+ "[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + '\n'
|
||||
+ "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + '\n'
|
||||
+ "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + '\n'
|
||||
+ "[Multiverse-Core] enablebuscript: " + plugin.getMVConfig().getEnableBuscript() + '\n'
|
||||
+ "[Multiverse-Core] globaldebug: " + plugin.getMVConfig().getGlobalDebug() + '\n'
|
||||
+ "[Multiverse-Core] silentstart: " + plugin.getMVConfig().getSilentStart() + '\n'
|
||||
+ "[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + '\n'
|
||||
+ "[Multiverse-Core] version: " + plugin.getMVConfig().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnworld: " + plugin.getMVConfig().getFirstSpawnWorld() + '\n'
|
||||
+ "[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + '\n'
|
||||
+ "[Multiverse-Core] defaultportalsearch: " + plugin.getMVConfig().isUsingDefaultPortalSearch() + '\n'
|
||||
+ "[Multiverse-Core] portalsearchradius: " + plugin.getMVConfig().getPortalSearchRadius() + '\n'
|
||||
+ "[Multiverse-Core] autopurge: " + plugin.getMVConfig().isAutoPurgeEnabled() + '\n'
|
||||
+ "[Multiverse-Core] Special Code: FRN002" + '\n';
|
||||
}
|
||||
|
||||
private String getMarkdownString() {
|
||||
return "# Multiverse-Core" + '\n'
|
||||
+ "## Overview" + '\n'
|
||||
+ "| Name | Value |" + '\n'
|
||||
+ "| --- | --- |" + '\n'
|
||||
+ "| Multiverse-Core Version | `" + this.plugin.getDescription().getVersion() + "` |" + '\n'
|
||||
+ "| Bukkit Version | `" + this.plugin.getServer().getVersion() + "` |" + '\n'
|
||||
+ "| Loaded Worlds | `" + this.plugin.getMVWorldManager().getMVWorlds() + "` |" + '\n'
|
||||
+ "| Multiverse Plugins Loaded | `" + this.plugin.getPluginCount() + "` |" + '\n'
|
||||
+ "| Economy being used | `" + plugin.getEconomist().getEconomyName() + "` |" + '\n'
|
||||
+ "| Permissions Plugin | `" + this.plugin.getMVPerms().getType() + "` |" + '\n'
|
||||
+ "## Parsed Config" + '\n'
|
||||
+ "These are what Multiverse thought the in-memory values of the config were." + "\n\n"
|
||||
+ "| Config Key | Value |" + '\n'
|
||||
+ "| --- | --- |" + '\n'
|
||||
+ "| version | `" + this.plugin.getMVConfig().getVersion() + "` |" + '\n'
|
||||
+ "| messagecooldown | `" + plugin.getMessaging().getCooldown() + "` |" + '\n'
|
||||
+ "| teleportcooldown | `" + plugin.getMVConfig().getTeleportCooldown() + "` |" + '\n'
|
||||
+ "| worldnameprefix | `" + plugin.getMVConfig().getPrefixChat() + "` |" + '\n'
|
||||
+ "| worldnameprefixFormat | `" + plugin.getMVConfig().getPrefixChatFormat() + "` |" + '\n'
|
||||
+ "| enforceaccess | `" + plugin.getMVConfig().getEnforceAccess() + "` |" + '\n'
|
||||
+ "| displaypermerrors | `" + plugin.getMVConfig().getDisplayPermErrors() + "` |" + '\n'
|
||||
+ "| teleportintercept | `" + plugin.getMVConfig().getTeleportIntercept() + "` |" + '\n'
|
||||
+ "| firstspawnoverride | `" + plugin.getMVConfig().getFirstSpawnOverride() + "` |" + '\n'
|
||||
+ "| firstspawnworld | `" + plugin.getMVConfig().getFirstSpawnWorld() + "` |" + '\n'
|
||||
+ "| debug | `" + plugin.getMVConfig().getGlobalDebug() + "` |" + '\n';
|
||||
}
|
||||
|
||||
private void addVersionInfoToEvent(MVVersionEvent event) {
|
||||
// add the legacy version info
|
||||
event.appendVersionInfo(this.getLegacyString());
|
||||
|
||||
// add the legacy file, but as markdown so it's readable
|
||||
// TODO Readd this in 5.0.0
|
||||
// event.putDetailedVersionInfo("version.md", this.getMarkdownString());
|
||||
|
||||
// add config.yml
|
||||
File configFile = new File(this.plugin.getDataFolder(), "config.yml");
|
||||
event.putDetailedVersionInfo("multiverse-core/config.yml", configFile);
|
||||
|
||||
// add worlds.yml
|
||||
File worldsFile = new File(this.plugin.getDataFolder(), "worlds.yml");
|
||||
event.putDetailedVersionInfo("multiverse-core/worlds.yml", worldsFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,76 +132,94 @@ public class VersionCommand extends MultiverseCommand {
|
||||
sender.sendMessage("Version info dumped to console. Please check your server logs.");
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("[Multiverse-Core] Multiverse-Core Version: ").append(this.plugin.getDescription().getVersion()).append('\n');
|
||||
buffer.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n');
|
||||
buffer.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds()).append('\n');
|
||||
buffer.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n');
|
||||
final boolean usingVault = this.plugin.getVaultEconomy() != null;
|
||||
buffer.append("[Multiverse-Core] Using Vault: ").append(usingVault).append('\n');
|
||||
if (usingVault) {
|
||||
buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getVaultEconomy().getName()).append('\n');
|
||||
} else {
|
||||
buffer.append("[Multiverse-Core] Economy being used: ").append(this.plugin.getBank().getEconUsed()).append('\n');
|
||||
}
|
||||
buffer.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
|
||||
buffer.append("[Multiverse-Core] Dumping Config Values: (version ")
|
||||
.append(this.plugin.getMVConfig().getVersion()).append(")").append('\n');
|
||||
buffer.append("[Multiverse-Core] messagecooldown: ").append(plugin.getMessaging().getCooldown()).append('\n');
|
||||
buffer.append("[Multiverse-Core] teleportcooldown: ").append(plugin.getMVConfig().getTeleportCooldown()).append('\n');
|
||||
buffer.append("[Multiverse-Core] worldnameprefix: ").append(plugin.getMVConfig().getPrefixChat()).append('\n');
|
||||
buffer.append("[Multiverse-Core] enforceaccess: ").append(plugin.getMVConfig().getEnforceAccess()).append('\n');
|
||||
buffer.append("[Multiverse-Core] displaypermerrors: ").append(plugin.getMVConfig().getDisplayPermErrors()).append('\n');
|
||||
buffer.append("[Multiverse-Core] teleportintercept: ").append(plugin.getMVConfig().getTeleportIntercept()).append('\n');
|
||||
buffer.append("[Multiverse-Core] firstspawnoverride: ").append(plugin.getMVConfig().getFirstSpawnOverride()).append('\n');
|
||||
buffer.append("[Multiverse-Core] firstspawnworld: ").append(plugin.getMVConfig().getFirstSpawnWorld()).append('\n');
|
||||
buffer.append("[Multiverse-Core] debug: ").append(plugin.getMVConfig().getGlobalDebug()).append('\n');
|
||||
buffer.append("[Multiverse-Core] Special Code: FRN002").append('\n');
|
||||
MVVersionEvent versionEvent = new MVVersionEvent();
|
||||
|
||||
MVVersionEvent versionEvent = new MVVersionEvent(buffer.toString());
|
||||
this.addVersionInfoToEvent(versionEvent);
|
||||
this.plugin.getServer().getPluginManager().callEvent(versionEvent);
|
||||
|
||||
// log to console
|
||||
final String data = versionEvent.getVersionInfo();
|
||||
String[] lines = data.split("\n");
|
||||
for (String line : lines) {
|
||||
this.plugin.log(Level.INFO, line);
|
||||
if (CommandHandler.hasFlag("--include-plugin-list", args)) {
|
||||
versionEvent.appendVersionInfo('\n' + "Plugins: " + getPluginList());
|
||||
versionEvent.putDetailedVersionInfo("plugins.txt", "Plugins: " + getPluginList());
|
||||
}
|
||||
|
||||
this.plugin.getServer().getScheduler().scheduleAsyncDelayedTask(this.plugin, new Runnable() {
|
||||
final String versionInfo = versionEvent.getVersionInfo();
|
||||
versionEvent.putDetailedVersionInfo("version.txt", versionInfo);
|
||||
|
||||
final Map<String, String> files = versionEvent.getDetailedVersionInfo();
|
||||
|
||||
// log to console
|
||||
String[] lines = versionInfo.split("\\r?\\n");
|
||||
for (String line : lines) {
|
||||
if (!line.isEmpty()) {
|
||||
this.plugin.getServer().getLogger().info(line);
|
||||
}
|
||||
}
|
||||
|
||||
BukkitRunnable logPoster = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.size() == 1) {
|
||||
if (args.size() > 0) {
|
||||
String pasteUrl;
|
||||
if (args.get(0).equalsIgnoreCase("-p")) {
|
||||
pasteUrl = postToService(PasteServiceType.PASTIE, true, data); // private post to pastie
|
||||
} else if (args.get(0).equalsIgnoreCase("-b")) {
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data); // private post to pastie
|
||||
if (CommandHandler.hasFlag("-b", args)) {
|
||||
// private post to pastebin
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, versionInfo, files);
|
||||
} else if (CommandHandler.hasFlag("-g", args)) {
|
||||
// private post to github
|
||||
pasteUrl = postToService(PasteServiceType.GITHUB, true, versionInfo, files);
|
||||
} else if (CommandHandler.hasFlag("-h", args)) {
|
||||
// private post to hastebin
|
||||
pasteUrl = postToService(PasteServiceType.HASTEBIN, true, versionInfo, files);
|
||||
} else if (CommandHandler.hasFlag("-p", args)) {
|
||||
// private post to paste.gg
|
||||
pasteUrl = postToService(PasteServiceType.PASTEGG, true, versionInfo, files);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
plugin.log(Level.INFO, "Version info dumped here: " + pasteUrl);
|
||||
if (!(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
}
|
||||
Logging.info("Version info dumped here: %s", pasteUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Run the log posting operation asynchronously, since we don't know how long it will take.
|
||||
logPoster.runTaskAsynchronously(this.plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current contents of this.pasteBinBuffer to a web service.
|
||||
*
|
||||
* @param type Service type to send to
|
||||
* @param isPrivate Should the paste be marked as private.
|
||||
* @param type Service type to send paste data to.
|
||||
* @param isPrivate Should the paste be marked as private.
|
||||
* @param pasteData Legacy string only data to post to a service.
|
||||
* @param pasteFiles Map of filenames/contents of debug info.
|
||||
* @return URL of visible paste
|
||||
*/
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData) {
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData, Map<String, String> pasteFiles) {
|
||||
PasteService ps = PasteServiceFactory.getService(type, isPrivate);
|
||||
|
||||
try {
|
||||
return SHORTENER.shorten(ps.postData(ps.encodeData(pasteData), ps.getPostURL()));
|
||||
String result;
|
||||
if (ps.supportsMultiFile()) {
|
||||
result = ps.postData(pasteFiles);
|
||||
} else {
|
||||
result = ps.postData(pasteData);
|
||||
}
|
||||
|
||||
if (SHORTENER != null) return SHORTENER.shorten(result);
|
||||
return result;
|
||||
} catch (PasteFailedException e) {
|
||||
System.out.print(e);
|
||||
return "Error posting to service";
|
||||
e.printStackTrace();
|
||||
return "Error posting to service.";
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return "That service isn't supported yet.";
|
||||
}
|
||||
}
|
||||
|
||||
private String getPluginList() {
|
||||
return StringUtils.join(plugin.getServer().getPluginManager().getPlugins(), ", ");
|
||||
}
|
||||
}
|
||||
@@ -52,11 +52,11 @@ public class WhoCommand extends MultiverseCommand {
|
||||
showAll = false;
|
||||
}
|
||||
|
||||
final Player[] onlinePlayers = plugin.getServer().getOnlinePlayers();
|
||||
final Collection<Player> visiblePlayers = new HashSet<Player>(onlinePlayers.length);
|
||||
for (final Player player : onlinePlayers) {
|
||||
if (p == null || p.canSee(player)) {
|
||||
visiblePlayers.add(player);
|
||||
final Collection onlinePlayers = plugin.getServer().getOnlinePlayers();
|
||||
final Collection<Player> visiblePlayers = new HashSet<Player>(onlinePlayers.size());
|
||||
for (final Object player : onlinePlayers) {
|
||||
if (player instanceof Player && (p == null || p.canSee((Player) player))) {
|
||||
visiblePlayers.add((Player) player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2020. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandtools.queue;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.data.type.CommandBlock;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* <p>Manages the queuing of dangerous commands that require {@code /mv confirm} before executing.</p>
|
||||
*
|
||||
* <p>Each sender can only have one command in queue at any given time. When a queued command is added
|
||||
* for a sender that already has a command in queue, it will replace the old queued command.</p>
|
||||
*/
|
||||
public class CommandQueueManager {
|
||||
|
||||
private static final long TICKS_PER_SECOND = 20;
|
||||
private static final DummyCommandBlockSender COMMAND_BLOCK = new DummyCommandBlockSender();
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final Map<CommandSender, QueuedCommand> queuedCommandMap;
|
||||
|
||||
public CommandQueueManager(@NotNull MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.queuedCommandMap = new WeakHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link QueuedCommand} into queue.
|
||||
*
|
||||
* @param queuedCommand The queued command to add.
|
||||
*/
|
||||
public void addToQueue(QueuedCommand queuedCommand) {
|
||||
CommandSender targetSender = parseSender(queuedCommand.getSender());
|
||||
|
||||
// Since only one command is stored in queue per sender, we remove the old one.
|
||||
this.removeFromQueue(targetSender);
|
||||
|
||||
Logging.finer("Add new command to queue for sender %s.", targetSender);
|
||||
this.queuedCommandMap.put(targetSender, queuedCommand);
|
||||
queuedCommand.setExpireTask(runExpireLater(queuedCommand));
|
||||
|
||||
queuedCommand.getSender().sendMessage(queuedCommand.getPrompt());
|
||||
queuedCommand.getSender().sendMessage(String.format("Run %s/mv confirm %sto continue. This will expire in %s seconds.",
|
||||
ChatColor.GREEN, ChatColor.WHITE, queuedCommand.getValidDuration()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expire task that removes a {@link QueuedCommand} from queue after valid duration defined.
|
||||
*
|
||||
* @param queuedCommand Command to run the expire task on.
|
||||
* @return The expire {@link BukkitTask}.
|
||||
*/
|
||||
@NotNull
|
||||
private BukkitTask runExpireLater(@NotNull QueuedCommand queuedCommand) {
|
||||
return Bukkit.getScheduler().runTaskLater(
|
||||
this.plugin,
|
||||
expireRunnable(queuedCommand),
|
||||
queuedCommand.getValidDuration() * TICKS_PER_SECOND
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runnable responsible for expiring the queued command.
|
||||
*
|
||||
* @param queuedCommand Command to create the expire task on.
|
||||
* @return The expire runnable.
|
||||
*/
|
||||
@NotNull
|
||||
private Runnable expireRunnable(@NotNull QueuedCommand queuedCommand) {
|
||||
return () -> {
|
||||
CommandSender targetSender = parseSender(queuedCommand.getSender());
|
||||
QueuedCommand matchingQueuedCommand = this.queuedCommandMap.get(targetSender);
|
||||
if (!queuedCommand.equals(matchingQueuedCommand) || queuedCommand.getExpireTask().isCancelled()) {
|
||||
// To be safe, but this shouldn't happen since we cancel old commands before add new once.
|
||||
Logging.finer("This is an old queue command already.");
|
||||
return;
|
||||
}
|
||||
queuedCommand.getSender().sendMessage("Your queued command has expired.");
|
||||
this.queuedCommandMap.remove(queuedCommand.getSender());
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the command in queue for the given sender, if any.
|
||||
*
|
||||
* @param sender {@link CommandSender} that confirmed the command.
|
||||
* @return True if queued command ran successfully, else false.
|
||||
*/
|
||||
public boolean runQueuedCommand(@NotNull CommandSender sender) {
|
||||
CommandSender targetSender = parseSender(sender);
|
||||
QueuedCommand queuedCommand = this.queuedCommandMap.get(targetSender);
|
||||
if (queuedCommand == null) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have any commands in queue.");
|
||||
return false;
|
||||
}
|
||||
Logging.finer("Running queued command...");
|
||||
queuedCommand.getAction().run();
|
||||
return removeFromQueue(targetSender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since only one command is stored in queue per sender, we remove the old one.
|
||||
*
|
||||
* @param sender The {@link CommandSender} that executed the command.
|
||||
* @return True if queue command is removed from sender successfully, else false.
|
||||
*/
|
||||
public boolean removeFromQueue(@NotNull CommandSender sender) {
|
||||
CommandSender targetSender = parseSender(sender);
|
||||
QueuedCommand previousCommand = this.queuedCommandMap.remove(targetSender);
|
||||
if (previousCommand == null) {
|
||||
Logging.finer("No queue command to remove for sender %s.", targetSender.getName());
|
||||
return false;
|
||||
}
|
||||
previousCommand.getExpireTask().cancel();
|
||||
Logging.finer("Removed queue command for sender %s.", targetSender.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* To allow all CommandBlocks to be a common sender with use of {@link DummyCommandBlockSender}.
|
||||
* So confirm command can be used for a queued command on another command block.
|
||||
*
|
||||
* @param sender The sender to parse.
|
||||
* @return The sender, or if its a command block, a {@link DummyCommandBlockSender}.
|
||||
*/
|
||||
@NotNull
|
||||
private CommandSender parseSender(@NotNull CommandSender sender) {
|
||||
Logging.fine(sender.getClass().getName());
|
||||
if (isCommandBlock(sender)) {
|
||||
Logging.finer("Is command block.");
|
||||
return COMMAND_BLOCK;
|
||||
}
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the sender is a command block.
|
||||
*
|
||||
* @param sender The sender to check.
|
||||
* @return True if sender is a command block, else false.
|
||||
*/
|
||||
private boolean isCommandBlock(@NotNull CommandSender sender) {
|
||||
return sender instanceof BlockCommandSender
|
||||
&& ((BlockCommandSender) sender).getBlock().getBlockData() instanceof CommandBlock;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.queue;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Used by {@link CommandQueueManager}, so different commands block can be recognised as one.
|
||||
*/
|
||||
class DummyCommandBlockSender implements CommandSender {
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NotNull String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NotNull String[] messages) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Server getServer() {
|
||||
return Bukkit.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "DummyCommandBlockSender";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull Permission perm) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Permission perm) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(@NotNull PermissionAttachment attachment) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2020. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandtools.queue;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a single command used in {@link CommandQueueManager} for confirming before running potentially
|
||||
* dangerous action.
|
||||
*/
|
||||
public class QueuedCommand {
|
||||
|
||||
private static final String DEFAULT_PROMPT_MESSAGE = "The command you are trying to run is deemed dangerous.";
|
||||
private static final int DEFAULT_VALID_TIME = 10;
|
||||
|
||||
private final CommandSender sender;
|
||||
private final Runnable action;
|
||||
private final String prompt;
|
||||
private final int validDuration;
|
||||
private BukkitTask expireTask;
|
||||
|
||||
public QueuedCommand(CommandSender sender, Runnable action) {
|
||||
this(sender, action, DEFAULT_PROMPT_MESSAGE, DEFAULT_VALID_TIME);
|
||||
}
|
||||
|
||||
public QueuedCommand(CommandSender sender, Runnable action, String prompt) {
|
||||
this(sender, action, prompt, DEFAULT_VALID_TIME);
|
||||
}
|
||||
|
||||
public QueuedCommand(CommandSender sender, Runnable action, int validDuration) {
|
||||
this(sender, action, DEFAULT_PROMPT_MESSAGE, validDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new queue command, to be registered at {@link CommandQueueManager#addToQueue(QueuedCommand)}.
|
||||
*
|
||||
* @param sender The sender that ran the command needed for confirmation.
|
||||
* @param action The logic to execute upon confirming.
|
||||
* @param prompt Question to ask sender to confirm.
|
||||
* @param validDuration Duration in which the command is valid for confirm in seconds.
|
||||
*/
|
||||
public QueuedCommand(CommandSender sender, Runnable action, String prompt, int validDuration) {
|
||||
this.sender = sender;
|
||||
this.action = action;
|
||||
this.prompt = prompt;
|
||||
this.validDuration = validDuration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
int getValidDuration() {
|
||||
return validDuration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Runnable getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
BukkitTask getExpireTask() {
|
||||
return expireTask;
|
||||
}
|
||||
|
||||
void setExpireTask(@NotNull BukkitTask expireTask) {
|
||||
if (this.expireTask != null) {
|
||||
throw new IllegalStateException("This queue command already has an expire task. You can't register twice!");
|
||||
}
|
||||
this.expireTask = expireTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Manager queuing of dangerous commands in need of confirmation.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools.queue;
|
||||
@@ -2,10 +2,14 @@ package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.onarandombox.MultiverseCore.utils.MaterialConverter;
|
||||
import me.main__.util.SerializationConfig.Property;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
|
||||
import me.main__.util.SerializationConfig.Serializor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Entryfee-settings.
|
||||
@@ -14,8 +18,11 @@ import org.bukkit.configuration.serialization.SerializableAs;
|
||||
public class EntryFee extends SerializationConfig {
|
||||
@Property
|
||||
private double amount;
|
||||
@Property
|
||||
private int currency;
|
||||
@Property(serializor = EntryFeeCurrencySerializor.class)
|
||||
@Nullable
|
||||
private Material currency;
|
||||
|
||||
private final Material DISABLED_MATERIAL = Material.AIR;
|
||||
|
||||
public EntryFee() {
|
||||
super();
|
||||
@@ -31,7 +38,7 @@ public class EntryFee extends SerializationConfig {
|
||||
@Override
|
||||
protected void setDefaults() {
|
||||
amount = 0D;
|
||||
currency = -1;
|
||||
currency = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +51,11 @@ public class EntryFee extends SerializationConfig {
|
||||
/**
|
||||
* @return the currency
|
||||
*/
|
||||
public int getCurrency() {
|
||||
@Nullable
|
||||
public Material getCurrency() {
|
||||
if (currency == null || currency.equals(DISABLED_MATERIAL)) {
|
||||
return null;
|
||||
}
|
||||
return currency;
|
||||
}
|
||||
|
||||
@@ -60,7 +71,19 @@ public class EntryFee extends SerializationConfig {
|
||||
* Sets the currency.
|
||||
* @param currency The new value.
|
||||
*/
|
||||
public void setCurrency(int currency) {
|
||||
public void setCurrency(@Nullable Material currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
public static final class EntryFeeCurrencySerializor implements Serializor<Material, Object> {
|
||||
@Override
|
||||
public String serialize(Material material) {
|
||||
return material.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material deserialize(Object o, Class<Material> aClass) {
|
||||
return MaterialConverter.convertTypeString(o.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
/**
|
||||
* An "active" {@link MVConfigProperty} that uses the specified method to be "actually" set.
|
||||
* @param <T> The type of the config-property.
|
||||
* @deprecated This is deprecated.
|
||||
* @see MVConfigProperty
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MVActiveConfigProperty<T> extends MVConfigProperty<T> {
|
||||
/**
|
||||
* Gets the method that will be executed.
|
||||
*
|
||||
* @return The name of the method in MVWorld to be called.
|
||||
*/
|
||||
String getMethod();
|
||||
|
||||
/**
|
||||
* Sets the method that will be executed.
|
||||
*
|
||||
* @param methodName The name of the method in MVWorld to be called.
|
||||
*/
|
||||
void setMethod(String methodName);
|
||||
|
||||
/**
|
||||
* Returns the class of the object we're looking at.
|
||||
* @return the class of the object we're looking at.
|
||||
*/
|
||||
Class<?> getPropertyClass();
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.configuration;
|
||||
|
||||
/**
|
||||
* A generic config-property.
|
||||
*
|
||||
* @param <T> The type of the config-property.
|
||||
* @deprecated This is deprecated.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MVConfigProperty<T> {
|
||||
/**
|
||||
* Gets the name of this property.
|
||||
*
|
||||
* @return The name of this property.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the value of this property.
|
||||
*
|
||||
* @return The value of this property.
|
||||
*/
|
||||
T getValue();
|
||||
|
||||
/**
|
||||
* Gets the string representation of this value.
|
||||
*
|
||||
* @return The value of this property as a string.
|
||||
*/
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Gets the help string for this.
|
||||
*
|
||||
* @return The value of this property as a string.
|
||||
*/
|
||||
String getHelp();
|
||||
|
||||
/**
|
||||
* Sets the value of this property.
|
||||
*
|
||||
* @param value The T representation of this value.
|
||||
* @return True the value was successfully set.
|
||||
*/
|
||||
boolean setValue(T value);
|
||||
|
||||
/**
|
||||
* This parseValue should be used with strings.
|
||||
*
|
||||
* @param value The string representation of the value to set.
|
||||
*
|
||||
* @return True if the value was set, false if not.
|
||||
*/
|
||||
boolean parseValue(String value);
|
||||
|
||||
/**
|
||||
* Gets the name of the config-node that this {@link MVConfigProperty} is saved as.
|
||||
*
|
||||
* @return The name of the config-node that this {@link MVConfigProperty} is saved as.
|
||||
*/
|
||||
String getConfigNode();
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public class SubSpawnSettings extends SerializationConfig {
|
||||
@Property
|
||||
private boolean spawn;
|
||||
@Property
|
||||
private int spawnrate;
|
||||
@Property
|
||||
private List<String> exceptions;
|
||||
|
||||
public SubSpawnSettings() {
|
||||
@@ -34,6 +36,7 @@ public class SubSpawnSettings extends SerializationConfig {
|
||||
public void setDefaults() {
|
||||
spawn = true;
|
||||
exceptions = new ArrayList<String>();
|
||||
spawnrate = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,9 +54,23 @@ public class SubSpawnSettings extends SerializationConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the exceptions
|
||||
* @return The exceptions
|
||||
*/
|
||||
public List<String> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rate The new spawn rate
|
||||
*/
|
||||
public void setSpawnRate(int rate) {
|
||||
this.spawnrate = rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The spawn rate
|
||||
*/
|
||||
public int getSpawnRate() {
|
||||
return this.spawnrate;
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,11 @@ package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -20,7 +23,8 @@ import org.bukkit.util.Vector;
|
||||
* A bed-{@link MVDestination}.
|
||||
*/
|
||||
public class BedDestination implements MVDestination {
|
||||
|
||||
public static final String OWN_BED_STRING = "playerbed";
|
||||
private String playername = "";
|
||||
private boolean isValid;
|
||||
private Location knownBedLoc;
|
||||
private MultiverseCore plugin;
|
||||
@@ -39,7 +43,15 @@ public class BedDestination implements MVDestination {
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] split = destination.split(":");
|
||||
this.isValid = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
||||
boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
||||
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]);
|
||||
boolean validPlayer = p.getName() != null && !p.getName().equals(OWN_BED_STRING);
|
||||
|
||||
if (validFormat && validPlayer) this.playername = p.getName();
|
||||
|
||||
this.isValid = destination.equals("b:" + OWN_BED_STRING) || (validFormat && validPlayer);
|
||||
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
@@ -49,9 +61,13 @@ public class BedDestination implements MVDestination {
|
||||
@Override
|
||||
public Location getLocation(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
|
||||
if (this.playername.isEmpty())
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
|
||||
else
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(Bukkit.getOfflinePlayer(this.playername).getBedSpawnLocation());
|
||||
|
||||
if (this.knownBedLoc == null) {
|
||||
((Player) entity).sendMessage("Your bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
|
||||
((Player) entity).sendMessage("The bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
|
||||
}
|
||||
return this.knownBedLoc;
|
||||
}
|
||||
@@ -120,6 +136,6 @@ public class BedDestination implements MVDestination {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "b:playerbed";
|
||||
return "b:" + (playername.isEmpty() ? OWN_BED_STRING : playername);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public abstract class CustomTeleporterDestination implements MVDestination {
|
||||
@Override
|
||||
public final Location getLocation(final Entity entity) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Vector getVelocity() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean useSafeTeleporter() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public abstract Teleporter getTeleporter();
|
||||
}
|
||||
@@ -11,16 +11,29 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** A factory class that will create destinations from specific strings. */
|
||||
/**
|
||||
* A factory class that will create destinations from specific strings.
|
||||
*/
|
||||
public class DestinationFactory {
|
||||
|
||||
private static final Pattern CANNON_PATTERN = Pattern.compile("(?i)cannon-[\\d]+(\\.[\\d]+)?");
|
||||
|
||||
private MultiverseCore plugin;
|
||||
private Map<String, Class<? extends MVDestination>> destList;
|
||||
private Command teleportCommand;
|
||||
@@ -36,6 +49,59 @@ public class DestinationFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a destination that has relation to sender, such as a cannon or player destination.
|
||||
*
|
||||
* @param teleportee The player that is going to be teleported.
|
||||
* @param destinationName The destination to parse.
|
||||
* @return A non-null MVDestination
|
||||
*/
|
||||
@NotNull
|
||||
public MVDestination getPlayerAwareDestination(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
// Prioritise world, in the event that a world is named after a player online.
|
||||
if (Bukkit.getWorld(destinationName) != null) {
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
Player targetPlayer = PlayerFinder.get(destinationName, teleportee);
|
||||
if (targetPlayer != null) {
|
||||
return getDestination("pl:" + targetPlayer.getName());
|
||||
}
|
||||
|
||||
if (CANNON_PATTERN.matcher(destinationName).matches()) {
|
||||
return getDestination(parseCannonDest(teleportee, destinationName));
|
||||
}
|
||||
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a cannon destination.
|
||||
*
|
||||
* @param teleportee The player that is going to be teleported.
|
||||
* @param destinationName The destination to parse.
|
||||
* @return A destination string.
|
||||
*/
|
||||
@NotNull
|
||||
private String parseCannonDest(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
String[] cannonSpeed = destinationName.split("-");
|
||||
try {
|
||||
double speed = Double.parseDouble(cannonSpeed[1]);
|
||||
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
|
||||
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
|
||||
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
|
||||
}
|
||||
catch (Exception e) {
|
||||
destinationName = "i:invalid";
|
||||
}
|
||||
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new destination from a string.
|
||||
* Returns a new InvalidDestination if the string could not be parsed.
|
||||
@@ -101,4 +167,13 @@ public class DestinationFactory {
|
||||
this.teleportCommand.addAdditonalPermission(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the {@link MVDestination} identifiers registered.
|
||||
*
|
||||
* @return A collection of destination identifiers.
|
||||
*/
|
||||
public Collection<String> getRegisteredIdentifiers() {
|
||||
return this.destList.keySet();
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,10 @@ import java.util.List;
|
||||
* An exact {@link MVDestination}.
|
||||
*/
|
||||
public class ExactDestination implements MVDestination {
|
||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
|
||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~)";
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private boolean relativeX, relativeY, relativeZ;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -88,7 +89,20 @@ public class ExactDestination implements MVDestination {
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return this.location;
|
||||
Location loc = this.location.clone();
|
||||
if (relativeX || relativeY || relativeZ) {
|
||||
Location eLoc = e.getLocation();
|
||||
loc.add(relativeX ? eLoc.getX() : 0, relativeY ? eLoc.getY() : 0, relativeZ ? eLoc.getZ() : 0);
|
||||
// Since the location is relative, it makes sense to use the entity's pitch and yaw unless those were
|
||||
// specified in the destination.
|
||||
if (loc.getPitch() == 0) {
|
||||
loc.setPitch(eLoc.getPitch());
|
||||
}
|
||||
if (loc.getYaw() == 0) {
|
||||
loc.setYaw(eLoc.getYaw());
|
||||
}
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,11 +148,42 @@ public class ExactDestination implements MVDestination {
|
||||
double[] coords = new double[3];
|
||||
String[] coordString = parsed.get(2).split(",");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
coords[i] = Double.parseDouble(coordString[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
String[] relSplit = coordString[i].split("~");
|
||||
boolean relative = false;
|
||||
if (relSplit.length == 0) {
|
||||
// coord is "~" form
|
||||
relative = true;
|
||||
coords[i] = 0;
|
||||
} else if (relSplit.length == 1) {
|
||||
// coord is "123" form
|
||||
try {
|
||||
coords[i] = Double.parseDouble(relSplit[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// coord is "~123" form
|
||||
relative = true;
|
||||
try {
|
||||
coords[i] = Double.parseDouble(relSplit[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (relative) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
relativeX = true;
|
||||
break;
|
||||
case 1:
|
||||
relativeY = true;
|
||||
break;
|
||||
case 2:
|
||||
relativeZ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.location.setX(coords[0]);
|
||||
@@ -184,11 +229,7 @@ public class ExactDestination implements MVDestination {
|
||||
* @param location The {@link Location}.
|
||||
*/
|
||||
public void setDestination(Location location) {
|
||||
if (location != null) {
|
||||
this.location = location;
|
||||
this.isValid = true;
|
||||
}
|
||||
this.isValid = false;
|
||||
this.isValid = (this.location = location) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PlayerDestination implements MVDestination {
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Player p = plugin.getServer().getPlayer(this.player);
|
||||
Player p = plugin.getServer().getPlayerExact(this.player);
|
||||
Player plLoc = null;
|
||||
if (e instanceof Player) {
|
||||
plLoc = (Player) e;
|
||||
|
||||
@@ -43,4 +43,8 @@ public enum AllowedPortalType {
|
||||
public PortalType getActualPortalType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isPortalAllowed(PortalType portalType) {
|
||||
return this != NONE && (getActualPortalType() == portalType || this == ALL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.onarandombox.MultiverseCore.enums;
|
||||
|
||||
public enum RespawnType {
|
||||
BED,
|
||||
ANCHOR,
|
||||
OTHER
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.onarandombox.MultiverseCore.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when Core's debug level is changed.
|
||||
*/
|
||||
public class MVDebugModeEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private final int level;
|
||||
|
||||
public MVDebugModeEvent(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the handler list. This is required by the event system.
|
||||
* @return A list of HANDLERS.
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current debug level of Core.
|
||||
*
|
||||
* @return the current debug level of Core.
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,29 @@
|
||||
package com.onarandombox.MultiverseCore.event;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Called when somebody requests version information about Multiverse.
|
||||
*/
|
||||
public class MVVersionEvent extends Event {
|
||||
|
||||
private final StringBuilder versionInfoBuilder;
|
||||
private final Map<String, String> detailedVersionInfo;
|
||||
|
||||
public MVVersionEvent(String versionInfo) {
|
||||
this.versionInfoBuilder = new StringBuilder(versionInfo);
|
||||
public MVVersionEvent() {
|
||||
versionInfoBuilder = new StringBuilder();
|
||||
detailedVersionInfo = new HashMap<>();
|
||||
}
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@@ -40,6 +52,21 @@ public class MVVersionEvent extends Event {
|
||||
return this.versionInfoBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key/value pair of the detailed version info.
|
||||
*
|
||||
* This information is used for advanced paste services that would prefer
|
||||
* to get the information as several files. Examples include config.yml or
|
||||
* portals.yml. Note that the map returned is immutable.
|
||||
*
|
||||
* The keys are filenames, the values are the contents of the files.
|
||||
*
|
||||
* @return The immutable key value mapping of files and the contents of those files.
|
||||
*/
|
||||
public Map<String, String> getDetailedVersionInfo() {
|
||||
return Collections.unmodifiableMap(this.detailedVersionInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends more version-info to the version-info currently saved in this event.
|
||||
* @param moreVersionInfo The version-info to add. Should end with '\n'.
|
||||
@@ -47,4 +74,46 @@ public class MVVersionEvent extends Event {
|
||||
public void appendVersionInfo(String moreVersionInfo) {
|
||||
this.versionInfoBuilder.append(moreVersionInfo);
|
||||
}
|
||||
|
||||
private String readFile(final String filename) {
|
||||
StringBuilder result;
|
||||
|
||||
try {
|
||||
FileReader reader = new FileReader(filename);
|
||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||
String line;
|
||||
result = new StringBuilder();
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
result.append(line).append("\n");
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Logging.severe("Unable to find %s. Here's the traceback: %s", filename, e.getMessage());
|
||||
e.printStackTrace();
|
||||
result = new StringBuilder(String.format("ERROR: Could not load: %s", filename));
|
||||
} catch (IOException e) {
|
||||
Logging.severe("Something bad happend when reading %s. Here's the traceback: %s", filename, e.getMessage());
|
||||
e.printStackTrace();
|
||||
result = new StringBuilder(String.format("ERROR: Could not load: %s", filename));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file to to the detailed version-info currently saved in this event.
|
||||
* @param fileName The name of the file.
|
||||
* @param contents The contents of the file.
|
||||
*/
|
||||
public void putDetailedVersionInfo(String fileName, String contents) {
|
||||
this.detailedVersionInfo.put(fileName, contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file to to the detailed version-info currently saved in this event.
|
||||
* @param filename The name of the file.
|
||||
* @param file The file.
|
||||
*/
|
||||
public void putDetailedVersionInfo(String filename, File file) {
|
||||
this.putDetailedVersionInfo(filename, readFile(file.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
@@ -20,7 +21,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
public class MVAsyncPlayerChatListener extends MVChatListener {
|
||||
public MVAsyncPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
|
||||
super(plugin, playerListener);
|
||||
plugin.log(Level.FINE, "Created AsyncPlayerChatEvent listener.");
|
||||
Logging.fine("Created AsyncPlayerChatEvent listener.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.onarandombox.MultiverseCore.listeners;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
@@ -45,8 +47,13 @@ public abstract class MVChatListener implements Listener {
|
||||
return;
|
||||
}
|
||||
prefix = mvworld.getColoredWorldString();
|
||||
String format = event.getFormat();
|
||||
event.setFormat("[" + prefix + "]" + format);
|
||||
String chat = event.getFormat();
|
||||
|
||||
String prefixChatFormat = plugin.getMVConfig().getPrefixChatFormat();
|
||||
prefixChatFormat = prefixChatFormat.replace("%world%", prefix).replace("%chat%", chat);
|
||||
prefixChatFormat = ChatColor.translateAlternateColorCodes('&', prefixChatFormat);
|
||||
|
||||
event.setFormat(prefixChatFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,11 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.CompatibilityLayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,6 +19,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityPortalEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
@@ -98,7 +101,7 @@ public class MVEntityListener implements Listener {
|
||||
* Handle people with non-standard animals: ie a patched craftbukkit.
|
||||
*/
|
||||
if (type == null || type.getName() == null) {
|
||||
this.plugin.log(Level.FINER, "Found a null typed creature.");
|
||||
Logging.finer("Found a null typed creature.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,4 +109,17 @@ public class MVEntityListener implements Listener {
|
||||
event.setCancelled(this.plugin.getMVWorldManager().getTheWorldPurger().shouldWeKillThisCreature(mvworld, event.getEntity()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles portal search radius adjustment.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void entityPortal(EntityPortalEvent event) {
|
||||
if (event.isCancelled() || event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) {
|
||||
CompatibilityLayer.setPortalSearchRadius(event, this.plugin.getMVConfig().getPortalSearchRadius());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.MapInitializeEvent;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
/**
|
||||
* A listener for bukkit map events.
|
||||
*/
|
||||
public class MVMapListener implements Listener {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
public MVMapListener(final MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a map is initialized.
|
||||
* @param event The event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void mapInitialize(final MapInitializeEvent event) {
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
if ((player.getItemInHand().getType() == Material.MAP
|
||||
|| player.getItemInHand().getType() == Material.FILLED_MAP)
|
||||
&& player.getItemInHand().getDurability() == event.getMap().getId()) {
|
||||
final Location playerLoc = player.getLocation();
|
||||
final MapView map = event.getMap();
|
||||
map.setCenterX(playerLoc.getBlockX());
|
||||
map.setCenterZ(playerLoc.getBlockZ());
|
||||
map.setWorld(playerLoc.getWorld());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
|
||||
@@ -21,7 +22,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
public class MVPlayerChatListener extends MVChatListener {
|
||||
public MVPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
|
||||
super(plugin, playerListener);
|
||||
plugin.log(Level.FINE, "Registered PlayerChatEvent listener.");
|
||||
Logging.fine("Registered PlayerChatEvent listener.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,8 +11,11 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.RespawnType;
|
||||
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.CompatibilityLayer;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -30,7 +33,6 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Multiverse's {@link Listener} for players.
|
||||
@@ -68,9 +70,16 @@ public class MVPlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
RespawnType respawnType = RespawnType.OTHER;
|
||||
if (event.isBedSpawn()) {
|
||||
respawnType = RespawnType.BED;
|
||||
}
|
||||
if (CompatibilityLayer.isAnchorSpawn(event)) {
|
||||
respawnType = RespawnType.ANCHOR;
|
||||
}
|
||||
|
||||
if (mvWorld.getBedRespawn() && event.isBedSpawn()) {
|
||||
this.plugin.log(Level.FINE, "Spawning " + event.getPlayer().getName() + " at their bed");
|
||||
if (mvWorld.getBedRespawn() && (respawnType == RespawnType.BED || respawnType == RespawnType.ANCHOR)) {
|
||||
Logging.fine("Spawning %s at their %s", event.getPlayer().getName(), respawnType);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,15 +118,15 @@ public class MVPlayerListener implements Listener {
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (!p.hasPlayedBefore()) {
|
||||
this.plugin.log(Level.FINER, "Player joined for the FIRST time!");
|
||||
Logging.finer("Player joined for the FIRST time!");
|
||||
if (plugin.getMVConfig().getFirstSpawnOverride()) {
|
||||
this.plugin.log(Level.FINE, "Moving NEW player to(firstspawnoverride): "
|
||||
Logging.fine("Moving NEW player to(firstspawnoverride): "
|
||||
+ worldManager.getFirstSpawnWorld().getSpawnLocation());
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
this.plugin.log(Level.FINER, "Player joined AGAIN!");
|
||||
Logging.finer("Player joined AGAIN!");
|
||||
if (this.plugin.getMVConfig().getEnforceAccess() // check this only if we're enforcing access!
|
||||
&& !this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
|
||||
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
@@ -125,7 +134,7 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(p.getName(), p.getWorld().getName());
|
||||
}
|
||||
|
||||
@@ -136,7 +145,7 @@ public class MVPlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void playerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
// Permissions now determine whether or not to handle a gamemode.
|
||||
this.handleGameMode(event.getPlayer(), event.getPlayer().getWorld());
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
|
||||
}
|
||||
|
||||
@@ -155,7 +164,7 @@ public class MVPlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void playerTeleport(PlayerTeleportEvent event) {
|
||||
this.plugin.log(Level.FINER, "Got teleport event for player '"
|
||||
Logging.finer("Got teleport event for player '"
|
||||
+ event.getPlayer().getName() + "' with cause '" + event.getCause() + "'");
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
@@ -165,21 +174,25 @@ public class MVPlayerListener implements Listener {
|
||||
String teleporterName = MultiverseCore.getPlayerTeleporter(teleportee.getName());
|
||||
if (teleporterName != null) {
|
||||
if (teleporterName.equals("CONSOLE")) {
|
||||
this.plugin.log(Level.FINER, "We know the teleporter is the console! Magical!");
|
||||
Logging.finer("We know the teleporter is the console! Magical!");
|
||||
teleporter = this.plugin.getServer().getConsoleSender();
|
||||
} else {
|
||||
teleporter = this.plugin.getServer().getPlayer(teleporterName);
|
||||
teleporter = this.plugin.getServer().getPlayerExact(teleporterName);
|
||||
}
|
||||
}
|
||||
this.plugin.log(Level.FINER, "Inferred sender '" + teleporter + "' from name '"
|
||||
Logging.finer("Inferred sender '" + teleporter + "' from name '"
|
||||
+ teleporterName + "', fetched from name '" + teleportee.getName() + "'");
|
||||
MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName());
|
||||
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
|
||||
if (fromWorld == null || toWorld == null)
|
||||
if (toWorld == null) {
|
||||
Logging.fine("Player '" + teleportee.getName() + "' is teleporting to world '"
|
||||
+ event.getTo().getWorld().getName() + "' which is not managed by Multiverse-Core. No further "
|
||||
+ "actions will be taken by Multiverse-Core.");
|
||||
return;
|
||||
}
|
||||
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
|
||||
// The player is Teleporting to the same world.
|
||||
this.plugin.log(Level.FINER, "Player '" + teleportee.getName() + "' is teleporting to the same world.");
|
||||
Logging.finer("Player '" + teleportee.getName() + "' is teleporting to the same world.");
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
return;
|
||||
}
|
||||
@@ -187,30 +200,50 @@ public class MVPlayerListener implements Listener {
|
||||
// Charge the teleporter
|
||||
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, teleporter, teleportee, true));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
Logging.fine("Player '" + teleportee.getName()
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because '" + teleporter.getName()
|
||||
+ "' don't have the FUNDS required to enter it.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if player is allowed to enter the world if we're enforcing permissions
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
Logging.fine("Player '" + teleportee.getName()
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because '" + teleporter.getName()
|
||||
+ "' don't have: multiverse.access." + event.getTo().getWorld().getName());
|
||||
} else {
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
Logging.fine("Player '" + teleportee.getName()
|
||||
+ "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
|
||||
}
|
||||
|
||||
// Does a limit actually exist?
|
||||
if (toWorld.getPlayerLimit() > -1) {
|
||||
// Are there equal or more people on the world than the limit?
|
||||
if (toWorld.getCBWorld().getPlayers().size() >= toWorld.getPlayerLimit()) {
|
||||
// Ouch the world is full, lets see if the player can bypass that limitation
|
||||
if (!pt.playerCanBypassPlayerLimit(toWorld, teleporter, teleportee)) {
|
||||
Logging.fine("Player '" + teleportee.getName()
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because the world is full and '" + teleporter.getName()
|
||||
+ "' doesn't have: mv.bypass.playerlimit." + event.getTo().getWorld().getName());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// By this point anything cancelling the event has returned on the method, meaning the teleport is a success \o/
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
}
|
||||
|
||||
private void stateSuccess(String playerName, String worldName) {
|
||||
this.plugin.log(Level.FINE, "MV-Core is allowing Player '" + playerName
|
||||
Logging.fine("MV-Core is allowing Player '" + playerName
|
||||
+ "' to go to '" + worldName + "'.");
|
||||
}
|
||||
|
||||
@@ -227,7 +260,7 @@ public class MVPlayerListener implements Listener {
|
||||
|
||||
// REMEMBER! getTo MAY be NULL HERE!!!
|
||||
// If the player was actually outside of the portal, adjust the from location
|
||||
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.PORTAL) {
|
||||
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.NETHER_PORTAL) {
|
||||
Location newloc = this.plugin.getSafeTTeleporter().findPortalBlockNextTo(event.getFrom());
|
||||
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
|
||||
// TODO: we want to do here.
|
||||
@@ -257,12 +290,12 @@ public class MVPlayerListener implements Listener {
|
||||
MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName());
|
||||
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
|
||||
// The player is Portaling to the same world.
|
||||
this.plugin.log(Level.FINER, "Player '" + event.getPlayer().getName() + "' is portaling to the same world.");
|
||||
Logging.finer("Player '" + event.getPlayer().getName() + "' is portaling to the same world.");
|
||||
return;
|
||||
}
|
||||
event.setCancelled(!pt.playerHasMoneyToEnter(fromWorld, toWorld, event.getPlayer(), event.getPlayer(), true));
|
||||
if (event.isCancelled()) {
|
||||
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
|
||||
Logging.fine("Player '" + event.getPlayer().getName()
|
||||
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
|
||||
+ "' because they don't have the FUNDS required to enter.");
|
||||
return;
|
||||
@@ -270,15 +303,18 @@ public class MVPlayerListener implements Listener {
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
|
||||
if (event.isCancelled()) {
|
||||
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
|
||||
Logging.fine("Player '" + event.getPlayer().getName()
|
||||
+ "' was DENIED ACCESS to '" + event.getTo().getWorld().getName()
|
||||
+ "' because they don't have: multiverse.access." + event.getTo().getWorld().getName());
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName()
|
||||
Logging.fine("Player '" + event.getPlayer().getName()
|
||||
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
|
||||
+ "' because enforceaccess is off.");
|
||||
}
|
||||
if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) {
|
||||
CompatibilityLayer.setPortalSearchRadius(event, this.plugin.getMVConfig().getPortalSearchRadius());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPlayerToDefaultWorld(final Player player) {
|
||||
@@ -293,13 +329,13 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// FOLLOWING 2 Methods and Private class handle Per Player GameModes.
|
||||
private void handleGameMode(Player player, World world) {
|
||||
private void handleGameModeAndFlight(Player player, World world) {
|
||||
|
||||
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
|
||||
if (mvWorld != null) {
|
||||
this.handleGameMode(player, mvWorld);
|
||||
this.handleGameModeAndFlight(player, mvWorld);
|
||||
} else {
|
||||
this.plugin.log(Level.FINER, "Not handling gamemode for world '" + world.getName()
|
||||
Logging.finer("Not handling gamemode and flight for world '" + world.getName()
|
||||
+ "' not managed by Multiverse.");
|
||||
}
|
||||
}
|
||||
@@ -309,27 +345,40 @@ public class MVPlayerListener implements Listener {
|
||||
* @param player The {@link Player}.
|
||||
* @param world The world the player is in.
|
||||
*/
|
||||
public void handleGameMode(final Player player, final MultiverseWorld world) {
|
||||
public void handleGameModeAndFlight(final Player player, final MultiverseWorld world) {
|
||||
// We perform this task one tick later to MAKE SURE that the player actually reaches the
|
||||
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
|
||||
if (!this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||
if (player.getWorld() == world.getCBWorld()) {
|
||||
Logging.fine("Handling gamemode for player: %s, Changing to %s", player.getName(), world.getGameMode().toString());
|
||||
Logging.finest("From World: %s", player.getWorld());
|
||||
Logging.finest("To World: %s", world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
if (!MVPlayerListener.this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||
if (player.getWorld() == world.getCBWorld()) {
|
||||
Logging.fine("Handling gamemode for player: %s, Changing to %s", player.getName(), world.getGameMode().toString());
|
||||
Logging.finest("From World: %s", player.getWorld());
|
||||
Logging.finest("To World: %s", world);
|
||||
player.setGameMode(world.getGameMode());
|
||||
// Check if their flight mode should change
|
||||
// TODO need a override permission for this
|
||||
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setAllowFlight(false);
|
||||
if (player.isFlying()) {
|
||||
player.setFlying(false);
|
||||
}
|
||||
} else if (world.getAllowFlight()) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Logging.fine("The gamemode/allowfly was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
|
||||
player.getName(), player.getWorld().getName(), world.getName());
|
||||
}
|
||||
} else {
|
||||
Logging.fine("The gamemode was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'", player.getName(), player.getWorld().getName(), world.getName());
|
||||
Logging.fine("Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||
}
|
||||
}
|
||||
}, 1L);
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.fernferret.allpay.AllPay;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Multiverse's Plugin {@link Listener}.
|
||||
*/
|
||||
public class MVPluginListener implements Listener {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
|
||||
public MVPluginListener(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep an eye out for Plugins which we can utilize.
|
||||
* @param event The event.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void pluginEnable(PluginEnableEvent event) {
|
||||
if (plugin.getVaultEconomy() != null) {
|
||||
// Don't hook 2 economy plugins.
|
||||
return;
|
||||
}
|
||||
// Let AllPay handle all econ plugin loadings, only go for econ plugins we support
|
||||
if (Arrays.asList(AllPay.getValidEconPlugins()).contains(event.getPlugin().getDescription().getName())) {
|
||||
this.plugin.setBank(this.plugin.getBanker().loadEconPlugin());
|
||||
}
|
||||
|
||||
/*
|
||||
if (event.getPlugin().getDescription().getName().equals("Spout")) {
|
||||
this.plugin.setSpout();
|
||||
this.plugin.log(Level.INFO, "Spout integration enabled.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* We'll check if any of the plugins we rely on decide to Disable themselves.
|
||||
* @param event The event.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void pluginDisable(PluginDisableEvent event) {
|
||||
// TODO: Disable econ when it disables.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,17 +7,20 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.PortalType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityCreatePortalEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A custom listener for portal related events.
|
||||
*/
|
||||
@@ -39,9 +42,9 @@ public class MVPortalListener implements Listener {
|
||||
if (event.isCancelled() || event.getBlocks().size() == 0) {
|
||||
return;
|
||||
}
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getEntity().getWorld());
|
||||
// We have to do it like this due to a bug in 1.1-R3
|
||||
if (cancelPortalEvent(world, event.getPortalType())) {
|
||||
if (world != null && !world.getAllowedPortals().isPortalAllowed(event.getPortalType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -50,36 +53,35 @@ public class MVPortalListener implements Listener {
|
||||
* This is called when a portal is created as the result of another world being linked.
|
||||
* @param event The event where a portal was formed due to a world link
|
||||
*/
|
||||
@EventHandler
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void portalForm(PortalCreateEvent event) {
|
||||
if (event.isCancelled() || event.getBlocks().size() == 0) {
|
||||
return;
|
||||
}
|
||||
// There's no type attribute (as of 1.1-R1), so we have to iterate.
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (b.getType() == Material.PORTAL) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(b.getWorld());
|
||||
if (cancelPortalEvent(world, PortalType.NETHER)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If We're here, then the Portal was an Ender type:
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getBlocks().get(0).getWorld());
|
||||
if (cancelPortalEvent(world, PortalType.ENDER)) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld());
|
||||
if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.NETHER)) {
|
||||
Logging.fine("Cancelling creation of nether portal because portalForm disallows.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean cancelPortalEvent(MultiverseWorld world, PortalType type) {
|
||||
if (world.getAllowedPortals() == AllowedPortalType.NONE) {
|
||||
return true;
|
||||
} else if (world.getAllowedPortals() != AllowedPortalType.ALL) {
|
||||
if (type != world.getAllowedPortals().getActualPortalType()) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* This method will prevent ender portals from being created in worlds where they are not allowed due to portalForm.
|
||||
*
|
||||
* @param event The player interact event.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void portalForm(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
if (event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) {
|
||||
return;
|
||||
}
|
||||
if (event.getItem() == null || event.getItem().getType() != Material.ENDER_EYE) {
|
||||
return;
|
||||
}
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld());
|
||||
if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) {
|
||||
Logging.fine("Cancelling creation of ender portal because portalForm disallows.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
|
||||
public class MVWorldInitListener implements Listener {
|
||||
|
||||
MultiverseCore plugin;
|
||||
|
||||
public MVWorldInitListener(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void initWorld(WorldInitEvent event) {
|
||||
if (!plugin.getMVWorldManager().isKeepingSpawnInMemory(event.getWorld())) {
|
||||
event.getWorld().setKeepSpawnInMemory(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
|
||||
/**
|
||||
* Multiverse's World {@link Listener}.
|
||||
*/
|
||||
public class MVWorldListener implements Listener {
|
||||
private MultiverseCore plugin;
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public MVWorldListener(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.worldManager = plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when Bukkit fires off a WorldUnloadEvent.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void unloadWorld(WorldUnloadEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (event.getWorld() instanceof World) {
|
||||
World world = (World) event.getWorld();
|
||||
if (world != null) {
|
||||
this.plugin.getMVWorldManager().unloadWorld(world.getName(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when Bukkit fires off a WorldLoadEvent.
|
||||
* @param event The Event that was fired.
|
||||
*/
|
||||
@EventHandler
|
||||
public void loadWorld(WorldLoadEvent event) {
|
||||
World world = event.getWorld();
|
||||
if (world != null) {
|
||||
if (this.plugin.getMVWorldManager().getUnloadedWorlds().contains(world.getName())) {
|
||||
this.plugin.getMVWorldManager().loadWorld(world.getName());
|
||||
}
|
||||
MultiverseWorld mvWorld = plugin.getMVWorldManager().getMVWorld(world);
|
||||
if (mvWorld != null) {
|
||||
// This is where we can temporarily fix those pesky property issues!
|
||||
world.setPVP(mvWorld.isPVPEnabled());
|
||||
world.setDifficulty(mvWorld.getDifficulty());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class AnchorManager {
|
||||
//world:x,y,z:pitch:yaw
|
||||
Location anchorLocation = plugin.getLocationManipulation().stringToLocation(anchorsSection.getString(key, ""));
|
||||
if (anchorLocation != null) {
|
||||
Logging.info("Loading anchor: '%s'...", key);
|
||||
Logging.config("Loading anchor: '%s'...", key);
|
||||
this.anchors.put(key, anchorLocation);
|
||||
} else {
|
||||
Logging.warning("The location for anchor '%s' is INVALID.", key);
|
||||
@@ -74,7 +74,7 @@ public class AnchorManager {
|
||||
this.anchorConfig.save(new File(this.plugin.getDataFolder(), "anchors.yml"));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
this.plugin.log(Level.SEVERE, "Failed to save anchors.yml. Please check your file permissions.");
|
||||
Logging.severe("Failed to save anchors.yml. Please check your file permissions.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -140,8 +140,17 @@ public class AnchorManager {
|
||||
if (ancLoc == null) {
|
||||
continue;
|
||||
}
|
||||
if (p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) {
|
||||
String worldPerm = "multiverse.access." + ancLoc.getWorld().getName();
|
||||
// Add to the list if we're not enforcing access
|
||||
// OR
|
||||
// We are enforcing access and the user has the permission.
|
||||
if (!this.plugin.getMVConfig().getEnforceAccess() ||
|
||||
(this.plugin.getMVConfig().getEnforceAccess() && p.hasPermission(worldPerm))) {
|
||||
myAnchors.add(anchor);
|
||||
} else {
|
||||
Logging.finer(String.format("Not adding anchor %s to the list, user %s doesn't have the %s " +
|
||||
"permission and 'enforceaccess' is enabled!",
|
||||
anchor, p.getName(), worldPerm));
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(myAnchors);
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
|
||||
/**
|
||||
* Used to determine block/location-related facts.
|
||||
*
|
||||
* @deprecated Use instead: {@link com.onarandombox.MultiverseCore.api.BlockSafety} and {@link SimpleBlockSafety}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class BlockSafety {
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the given coordinates are above air or not.
|
||||
* @param l The {@link Location} of the block.
|
||||
* @return True if the block at that {@link Location} is above air.
|
||||
*/
|
||||
public boolean isBlockAboveAir(Location l) {
|
||||
Location downOne = l.clone();
|
||||
downOne.setY(downOne.getY() - 1);
|
||||
return (downOne.getBlock().getType() == Material.AIR);
|
||||
}
|
||||
|
||||
// TODO maybe remove this?
|
||||
private boolean blockIsNotSafe(World world, double x, double y, double z) {
|
||||
return !playerCanSpawnHereSafely(world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player can spawn safely at the given coordinates.
|
||||
* @param world The {@link World}.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param z The z-coordinate.
|
||||
* @return True if a player can spawn safely at the given coordinates.
|
||||
*/
|
||||
public boolean playerCanSpawnHereSafely(World world, double x, double y, double z) {
|
||||
Location l = new Location(world, x, y, z);
|
||||
return playerCanSpawnHereSafely(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the coordinates given is safe or not by checking for Lava/Fire/Air
|
||||
* etc. This also ensures there is enough space for a player to spawn!
|
||||
*
|
||||
* @param l The {@link Location}
|
||||
* @return Whether the player can spawn safely at the given {@link Location}
|
||||
*/
|
||||
public boolean playerCanSpawnHereSafely(Location l) {
|
||||
if (l == null) {
|
||||
// Can't safely spawn at a null location!
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = l.getWorld();
|
||||
Location actual = l.clone();
|
||||
Location upOne = l.clone();
|
||||
Location downOne = l.clone();
|
||||
upOne.setY(upOne.getY() + 1);
|
||||
downOne.setY(downOne.getY() - 1);
|
||||
|
||||
if (this.isSolidBlock(world.getBlockAt(actual).getType())
|
||||
|| this.isSolidBlock(upOne.getBlock().getType())) {
|
||||
Logging.finer("Error Here (Actual)? (%s)[%s]", actual.getBlock().getType(),
|
||||
this.isSolidBlock(actual.getBlock().getType()));
|
||||
Logging.finer("Error Here (upOne)? (%s)[%s]", upOne.getBlock().getType(),
|
||||
this.isSolidBlock(upOne.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
|
||||
Logging.finer("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(),
|
||||
this.isSolidBlock(downOne.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.FIRE) {
|
||||
Logging.finer("There's fire below! (%s)[%s]", actual.getBlock().getType(),
|
||||
this.isSolidBlock(actual.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isBlockAboveAir(actual)) {
|
||||
Logging.finer("Is block above air [%s]", isBlockAboveAir(actual));
|
||||
Logging.finer("Has 2 blocks of water below [%s]", this.hasTwoBlocksofWaterBelow(actual));
|
||||
return this.hasTwoBlocksofWaterBelow(actual);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of the top block at the specified {@link Location}.
|
||||
* @param l Any {@link Location}.
|
||||
* @return The {@link Location} of the top-block.
|
||||
*/
|
||||
public Location getTopBlock(Location l) {
|
||||
Location check = l.clone();
|
||||
check.setY(127); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
while (check.getY() > 0) {
|
||||
if (this.playerCanSpawnHereSafely(check)) {
|
||||
return check;
|
||||
}
|
||||
check.setY(check.getY() - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of the top block at the specified {@link Location}.
|
||||
* @param l Any {@link Location}.
|
||||
* @return The {@link Location} of the top-block.
|
||||
*/
|
||||
public Location getBottomBlock(Location l) {
|
||||
Location check = l.clone();
|
||||
check.setY(0);
|
||||
while (check.getY() < 127) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
if (this.playerCanSpawnHereSafely(check)) {
|
||||
return check;
|
||||
}
|
||||
check.setY(check.getY() + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* If someone has a better way of this... Please either tell us, or submit a pull request!
|
||||
*/
|
||||
private boolean isSolidBlock(Material type) {
|
||||
switch (type) {
|
||||
case AIR:
|
||||
return false;
|
||||
case SNOW:
|
||||
return false;
|
||||
case TRAP_DOOR:
|
||||
return false;
|
||||
case TORCH:
|
||||
return false;
|
||||
case YELLOW_FLOWER:
|
||||
return false;
|
||||
case RED_ROSE:
|
||||
return false;
|
||||
case RED_MUSHROOM:
|
||||
return false;
|
||||
case BROWN_MUSHROOM:
|
||||
return false;
|
||||
case REDSTONE:
|
||||
return false;
|
||||
case REDSTONE_WIRE:
|
||||
return false;
|
||||
case RAILS:
|
||||
return false;
|
||||
case POWERED_RAIL:
|
||||
return false;
|
||||
case REDSTONE_TORCH_ON:
|
||||
return false;
|
||||
case REDSTONE_TORCH_OFF:
|
||||
return false;
|
||||
case DEAD_BUSH:
|
||||
return false;
|
||||
case SAPLING:
|
||||
return false;
|
||||
case STONE_BUTTON:
|
||||
return false;
|
||||
case LEVER:
|
||||
return false;
|
||||
case LONG_GRASS:
|
||||
return false;
|
||||
case PORTAL:
|
||||
return false;
|
||||
case STONE_PLATE:
|
||||
return false;
|
||||
case WOOD_PLATE:
|
||||
return false;
|
||||
case SEEDS:
|
||||
return false;
|
||||
case SUGAR_CANE_BLOCK:
|
||||
return false;
|
||||
case WALL_SIGN:
|
||||
return false;
|
||||
case SIGN_POST:
|
||||
return false;
|
||||
case WOODEN_DOOR:
|
||||
return false;
|
||||
case STATIONARY_WATER:
|
||||
return false;
|
||||
case WATER:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an entity would be on track at the specified {@link Location}.
|
||||
* @param l The {@link Location}.
|
||||
* @return True if an entity would be on tracks at the specified {@link Location}.
|
||||
*/
|
||||
public boolean isEntitiyOnTrack(Location l) {
|
||||
Material currentBlock = l.getBlock().getType();
|
||||
return (currentBlock == Material.POWERED_RAIL || currentBlock == Material.DETECTOR_RAIL || currentBlock == Material.RAILS);
|
||||
}
|
||||
|
||||
// TODO maybe remove this?
|
||||
private void showDangers(Location l) {
|
||||
Location actual = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
|
||||
Location upOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
|
||||
Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
|
||||
upOne.setY(upOne.getY() + 1);
|
||||
downOne.setY(downOne.getY() - 1);
|
||||
|
||||
System.out.print("Location Up: " + upOne.getBlock().getType());
|
||||
System.out.print(" " + upOne);
|
||||
System.out.print("Location: " + actual.getBlock().getType());
|
||||
System.out.print(" " + actual);
|
||||
System.out.print("Location Down: " + downOne.getBlock().getType());
|
||||
System.out.print(" " + downOne);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks recursively below a {@link Location} for 2 blocks of water.
|
||||
*
|
||||
* @param l The {@link Location}
|
||||
* @return Whether there are 2 blocks of water
|
||||
*/
|
||||
private boolean hasTwoBlocksofWaterBelow(Location l) {
|
||||
if (l.getBlockY() < 0) {
|
||||
return false;
|
||||
}
|
||||
Location oneBelow = l.clone();
|
||||
oneBelow.subtract(0, 1, 0);
|
||||
if (oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER) {
|
||||
Location twoBelow = oneBelow.clone();
|
||||
twoBelow.subtract(0, 1, 0);
|
||||
return (oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER);
|
||||
}
|
||||
if (oneBelow.getBlock().getType() != Material.AIR) {
|
||||
return false;
|
||||
}
|
||||
return hasTwoBlocksofWaterBelow(oneBelow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified {@link Minecart} can spawn safely.
|
||||
* @param cart The {@link Minecart}.
|
||||
* @return True if the minecart can spawn safely.
|
||||
*/
|
||||
public boolean canSpawnCartSafely(Minecart cart) {
|
||||
if (this.isBlockAboveAir(cart.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
if (this.isEntitiyOnTrack(LocationManipulation.getNextBlock(cart))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified {@link Vehicle} can spawn safely.
|
||||
* @param vehicle The {@link Vehicle}.
|
||||
* @return True if the vehicle can spawn safely.
|
||||
*/
|
||||
public boolean canSpawnVehicleSafely(Vehicle vehicle) {
|
||||
if (this.isBlockAboveAir(vehicle.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TravelAgent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
|
||||
public class BukkitTravelAgent implements TravelAgent {
|
||||
private final MVTravelAgent agent;
|
||||
|
||||
public BukkitTravelAgent(MVTravelAgent agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BukkitTravelAgent setSearchRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getSearchRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BukkitTravelAgent setCreationRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getCreationRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getCanCreatePortal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCanCreatePortal(boolean create) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findOrCreate(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findPortal(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean createPortal(Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Location getSafeLocation() {
|
||||
// At this time, these can never use the velocity.
|
||||
if (agent.destination instanceof CannonDestination) {
|
||||
Logging.fine("Using Stock TP method. This cannon will have 0 velocity");
|
||||
}
|
||||
SafeTTeleporter teleporter = agent.core.getSafeTTeleporter();
|
||||
Location newLoc = agent.destination.getLocation(agent.player);
|
||||
if (agent.destination.useSafeTeleporter()) {
|
||||
newLoc = teleporter.getSafeLocation(agent.player, agent.destination);
|
||||
}
|
||||
if (newLoc == null) {
|
||||
return agent.player.getLocation();
|
||||
}
|
||||
return newLoc;
|
||||
|
||||
}
|
||||
|
||||
public void setPortalEventTravelAgent(PlayerPortalEvent event) {
|
||||
event.setPortalTravelAgent(this);
|
||||
event.useTravelAgent(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.event.entity.EntityPortalEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Utility class to enable version specific minecraft features.
|
||||
*/
|
||||
public class CompatibilityLayer {
|
||||
|
||||
private static Method checkAnchorSpawn;
|
||||
private static boolean useTravelAgent;
|
||||
private static Method playerPortalSearchRadius;
|
||||
private static Method entityPortalSearchRadius;
|
||||
|
||||
/**
|
||||
* Initialise the reflection class, methods and fields.
|
||||
*/
|
||||
public static void init() {
|
||||
checkAnchorSpawn = ReflectHelper.getMethod(PlayerRespawnEvent.class, "isAnchorSpawn");
|
||||
useTravelAgent = ReflectHelper.hasClass("org.bukkit.TravelAgent");
|
||||
playerPortalSearchRadius = ReflectHelper.getMethod(PlayerPortalEvent.class, "setSearchRadius", int.class);
|
||||
entityPortalSearchRadius = ReflectHelper.getMethod(EntityPortalEvent.class, "setSearchRadius", int.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Check if the respawn point is of respawn anchor type.</p>
|
||||
* <p>Introduced in minecraft 1.16</p>
|
||||
*
|
||||
* @param event A player respawn event.
|
||||
* @return If the respawn location is an anchor point.
|
||||
*/
|
||||
public static boolean isAnchorSpawn(PlayerRespawnEvent event) {
|
||||
if (checkAnchorSpawn == null) {
|
||||
return false;
|
||||
}
|
||||
Boolean result = ReflectHelper.invokeMethod(event, checkAnchorSpawn);
|
||||
if (result == null) {
|
||||
Logging.warning("Unable to check if spawning at respawn anchor!");
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Gets if Travel Agent is supported on the server's minecraft version.</p>
|
||||
* <p>Removed in minecraft 1.14</p>
|
||||
*
|
||||
* @return True if Travel Agent is supported, else false.
|
||||
*/
|
||||
public static boolean isUseTravelAgent() {
|
||||
return useTravelAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets search radius for a PlayerPortalEvent.</p>
|
||||
*
|
||||
* <p>Use travel agent if available, else using new PlayerPortalEvent.setSearchRadius(int) method
|
||||
* introduced in minecraft 1.15</p>
|
||||
*
|
||||
* @param event A Player Portal Event.
|
||||
* @param searchRadius Target search radius to set to.
|
||||
*/
|
||||
public static void setPortalSearchRadius(PlayerPortalEvent event, int searchRadius) {
|
||||
if (useTravelAgent) {
|
||||
event.getPortalTravelAgent().setSearchRadius(searchRadius);
|
||||
event.useTravelAgent(true);
|
||||
Logging.finer("Used travel agent to set player portal search radius.");
|
||||
return;
|
||||
}
|
||||
if (playerPortalSearchRadius == null) {
|
||||
Logging.warning("Unable to set player portal search radius!");
|
||||
return;
|
||||
}
|
||||
ReflectHelper.invokeMethod(event, playerPortalSearchRadius, searchRadius);
|
||||
Logging.finer("Used new method to set player portal search radius.");
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets search radius for a EntityPortalEvent.</p>
|
||||
*
|
||||
* <p>Use travel agent if available, else using new EntityPortalEvent.setSearchRadius(int) method
|
||||
* introduced in minecraft 1.15</p>
|
||||
*
|
||||
* @param event A Entity Portal Event.
|
||||
* @param searchRadius Target search radius to set to.
|
||||
*/
|
||||
public static void setPortalSearchRadius(EntityPortalEvent event, int searchRadius) {
|
||||
if (useTravelAgent) {
|
||||
event.getPortalTravelAgent().setSearchRadius(searchRadius);
|
||||
event.useTravelAgent(true);
|
||||
Logging.finer("Used travel agent to set entity portal search radius.");
|
||||
return;
|
||||
}
|
||||
if (entityPortalSearchRadius == null) {
|
||||
Logging.warning("Unable to set entity portal search radius!");
|
||||
return;
|
||||
}
|
||||
ReflectHelper.invokeMethod(event, entityPortalSearchRadius, searchRadius);
|
||||
Logging.finer("Used new method to set entity portal search radius.");
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,9 @@ import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The Multiverse debug-logger.
|
||||
* @deprecated Deprecated in favor of new Logging lib. See {@link com.dumptruckman.minecraft.util.Logging}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DebugLog extends Logger {
|
||||
private FileHandler fh;
|
||||
private Logger standardLog = null;
|
||||
|
||||
@@ -22,9 +22,9 @@ public class FancyMessage implements FancyText {
|
||||
* Allows easy creation of an alternating colored list.
|
||||
* TODO: Documentation! Why does CheckStyle just ignore this?
|
||||
*
|
||||
* @param title
|
||||
* @param message
|
||||
* @param scheme
|
||||
* @param title The title.
|
||||
* @param message The body of the message.
|
||||
* @param scheme The color scheme to use for easy styling.
|
||||
*/
|
||||
public FancyMessage(String title, String message, FancyColorScheme scheme) {
|
||||
this.title = title;
|
||||
|
||||
@@ -7,14 +7,23 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
|
||||
/**
|
||||
* File-utilities.
|
||||
@@ -31,71 +40,96 @@ public class FileUtils {
|
||||
* @return true if the folder was successfully deleted.
|
||||
*/
|
||||
public static boolean deleteFolder(File file) {
|
||||
if (file.exists()) {
|
||||
boolean ret = true;
|
||||
// If the file exists, and it has more than one file in it.
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
ret = ret && deleteFolder(f);
|
||||
}
|
||||
}
|
||||
return ret && file.delete();
|
||||
} else {
|
||||
try (Stream<Path> files = Files.walk(file.toPath())) {
|
||||
files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int COPY_BLOCK_SIZE = 1024;
|
||||
/**
|
||||
* Used to delete the contents of a folder, without deleting the folder itself.
|
||||
*
|
||||
* @param file The folder whose contents to delete.
|
||||
* @return true if the contents were successfully deleted
|
||||
*/
|
||||
public static boolean deleteFolderContents(File file) {
|
||||
try (Stream<Path> files = Files.walk(file.toPath())){
|
||||
files.sorted(Comparator.reverseOrder())
|
||||
.map(Path::toFile)
|
||||
.filter(f -> !f.equals(file))
|
||||
.forEach(File::delete);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to copy the world-folder.
|
||||
* @param source Source-File
|
||||
* @param target Target-File
|
||||
* @param log A logger that logs the operation
|
||||
*
|
||||
* @return if it had success
|
||||
* @return true if it had success
|
||||
*/
|
||||
public static boolean copyFolder(File source, File target, Logger log) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
if (source.isDirectory()) {
|
||||
|
||||
if (!target.exists())
|
||||
target.mkdir();
|
||||
|
||||
String[] children = source.list();
|
||||
// for (int i=0; i<children.length; i++) {
|
||||
for (String child : children) {
|
||||
copyFolder(new File(source, child), new File(target, child), log);
|
||||
}
|
||||
} else {
|
||||
in = new FileInputStream(source);
|
||||
out = new FileOutputStream(target);
|
||||
|
||||
byte[] buf = new byte[COPY_BLOCK_SIZE];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.warning("Exception while copying file: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
log.warning("Exception while copying file: " + e.getMessage());
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public static boolean copyFolder(File source, File target) {
|
||||
return copyFolder(source, target, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to copy the world-folder.
|
||||
* @param source Source-File
|
||||
* @param target Target-File
|
||||
* @param excludeFiles files to ignore and not copy over to Target-File
|
||||
*
|
||||
* @return true if it had success
|
||||
*/
|
||||
public static boolean copyFolder(File source, File target, List<String> excludeFiles) {
|
||||
Path sourceDir = source.toPath();
|
||||
Path targetDir = target.toPath();
|
||||
|
||||
try {
|
||||
Files.walkFileTree(sourceDir, new CopyDirFileVisitor(sourceDir, targetDir, excludeFiles));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning("Unable to copy directory", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CopyDirFileVisitor extends SimpleFileVisitor<Path> {
|
||||
|
||||
private final Path sourceDir;
|
||||
private final Path targetDir;
|
||||
private final List<String> excludeFiles;
|
||||
|
||||
private CopyDirFileVisitor(Path sourceDir, Path targetDir, List<String> excludeFiles) {
|
||||
this.sourceDir = sourceDir;
|
||||
this.targetDir = targetDir;
|
||||
this.excludeFiles = excludeFiles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
Path newDir = targetDir.resolve(sourceDir.relativize(dir));
|
||||
if (!Files.isDirectory(newDir)) {
|
||||
Files.createDirectory(newDir);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
// Pass files that are set to ignore
|
||||
if (excludeFiles != null && excludeFiles.contains(file.getFileName().toString()))
|
||||
return FileVisitResult.CONTINUE;
|
||||
// Copy the files
|
||||
Path targetFile = targetDir.resolve(sourceDir.relativize(file));
|
||||
Files.copy(file, targetFile, COPY_ATTRIBUTES);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Multiverse's Friendly Economist. This is used to deal with external economies and also item costs for stuff in MV.
|
||||
*/
|
||||
public class MVEconomist {
|
||||
|
||||
private final VaultHandler vaultHandler;
|
||||
|
||||
public MVEconomist(Plugin plugin) {
|
||||
vaultHandler = new VaultHandler(plugin);
|
||||
}
|
||||
|
||||
private boolean isUsingVault(Material currency) {
|
||||
return !isItemCurrency(currency) && getVaultHandler().hasEconomy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an economy plugin is in use.
|
||||
*
|
||||
* @return true if an economy plugin is detected by Vault.
|
||||
*/
|
||||
public boolean isUsingEconomyPlugin() {
|
||||
return getVaultHandler().hasEconomy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the amount to a human readable currency string.
|
||||
*
|
||||
* @param amount the amount of currency.
|
||||
* @param currency the type of currency. Null indicates a non-item currency is used.
|
||||
* @return the human readable currency string.
|
||||
*/
|
||||
public String formatPrice(double amount, @Nullable Material currency) {
|
||||
if (isUsingVault(currency)) {
|
||||
return getVaultHandler().getEconomy().format(amount);
|
||||
} else {
|
||||
return ItemEconomy.getFormattedPrice(amount, currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the economy in use.
|
||||
*
|
||||
* @return the name of the economy in use.
|
||||
*/
|
||||
public String getEconomyName() {
|
||||
if (getVaultHandler().hasEconomy()) {
|
||||
return getVaultHandler().getEconomy().getName();
|
||||
} else {
|
||||
return ItemEconomy.getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a player has enough of a given currency.
|
||||
*
|
||||
* @param player the player to check for currency.
|
||||
* @param amount the amount of currency.
|
||||
* @param currency the type of currency. Null indicates non-item currency is used.
|
||||
* @return true if the player has enough of the given currency or the amount is 0 or less.
|
||||
*/
|
||||
public boolean isPlayerWealthyEnough(Player player, double amount, Material currency) {
|
||||
if (amount <= 0D) {
|
||||
return true;
|
||||
} else if (isUsingVault(currency)) {
|
||||
return getVaultHandler().getEconomy().has(player, amount);
|
||||
} else {
|
||||
return ItemEconomy.hasEnough(player, amount, currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a message for a player indicating they don't have enough currency.
|
||||
*
|
||||
* @param currency the type of currency. Null indicates a non-item currency is used.
|
||||
* @param message The more specific message to append to the generic message of not having enough.
|
||||
* @return the formatted insufficient funds message.
|
||||
*/
|
||||
public String getNSFMessage(Material currency, String message) {
|
||||
return "Sorry, you don't have enough " + (isItemCurrency(currency) ? "items" : "funds") + ". " + message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deposits a given amount of currency either into the player's economy account or inventory if the currency
|
||||
* is not null.
|
||||
*
|
||||
* @param player the player to give currency to.
|
||||
* @param amount the amount to give.
|
||||
* @param currency the type of currency.
|
||||
*/
|
||||
public void deposit(Player player, double amount, @Nullable Material currency) {
|
||||
if (isUsingVault(currency)) {
|
||||
getVaultHandler().getEconomy().depositPlayer(player, amount);
|
||||
} else {
|
||||
ItemEconomy.deposit(player, amount, currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraws a given amount of currency either from the player's economy account or inventory if the currency
|
||||
* is not null.
|
||||
*
|
||||
* @param player the player to take currency from.
|
||||
* @param amount the amount to take.
|
||||
* @param currency the type of currency.
|
||||
*/
|
||||
public void withdraw(Player player, double amount, @Nullable Material currency) {
|
||||
if (isUsingVault(currency)) {
|
||||
getVaultHandler().getEconomy().withdrawPlayer(player, amount);
|
||||
} else {
|
||||
ItemEconomy.withdraw(player, amount, currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the economy balance of the given player.
|
||||
*
|
||||
* @param player the player to get the balance for.
|
||||
* @return the economy balance of the given player.
|
||||
* @throws IllegalStateException thrown if this is used when no economy plugin is available.
|
||||
*/
|
||||
public double getBalance(Player player) throws IllegalStateException {
|
||||
return getBalance(player, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the economy balance of the given player in the given world. If the economy plugin does not have world
|
||||
* specific balances then the global balance will be returned.
|
||||
*
|
||||
* @param player the player to get the balance for.
|
||||
* @param world the world to get the balance for.
|
||||
* @return the economy balance of the given player in the given world.
|
||||
* @throws IllegalStateException thrown if this is used when no economy plugin is available.
|
||||
*/
|
||||
public double getBalance(Player player, World world) throws IllegalStateException {
|
||||
if (!isUsingEconomyPlugin()) {
|
||||
throw new IllegalStateException("getBalance is only available when using an economy plugin with Vault");
|
||||
}
|
||||
if (world != null) {
|
||||
return getVaultHandler().getEconomy().getBalance(player, world.getName());
|
||||
} else {
|
||||
return getVaultHandler().getEconomy().getBalance(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the economy balance for the given player.
|
||||
*
|
||||
* @param player the player to set the balance for.
|
||||
* @param amount the amount to set the player's balance to.
|
||||
* @throws IllegalStateException thrown if this is used when no economy plugin is available.
|
||||
*/
|
||||
public void setBalance(Player player, double amount) throws IllegalStateException {
|
||||
setBalance(player, null, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the economy balance for the given player in the given world. If the economy plugin does not have world
|
||||
* specific balances then the global balance will be set.
|
||||
*
|
||||
* @param player the player to set the balance for.
|
||||
* @param world the world to get the balance for.
|
||||
* @param amount the amount to set the player's balance to.
|
||||
* @throws IllegalStateException thrown if this is used when no economy plugin is available.
|
||||
*/
|
||||
public void setBalance(Player player, World world, double amount) throws IllegalStateException {
|
||||
if (!isUsingEconomyPlugin()) {
|
||||
throw new IllegalStateException("getBalance is only available when using an economy plugin with Vault");
|
||||
}
|
||||
if (world != null) {
|
||||
getVaultHandler().getEconomy().withdrawPlayer(player, world.getName(), getBalance(player, world));
|
||||
getVaultHandler().getEconomy().depositPlayer(player, world.getName(), amount);
|
||||
} else {
|
||||
getVaultHandler().getEconomy().withdrawPlayer(player, getBalance(player));
|
||||
getVaultHandler().getEconomy().depositPlayer(player, amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is public for backwards compatibility.
|
||||
*
|
||||
* @return the old VaultHandler.
|
||||
* @deprecated just use the other methods in this class for economy stuff.
|
||||
*/
|
||||
// TODO make private
|
||||
@Deprecated
|
||||
public VaultHandler getVaultHandler() {
|
||||
return vaultHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the currency type string given represents an item currency.
|
||||
*
|
||||
* @param currency the type of currency.
|
||||
* @return true if currency string matches a valid material.
|
||||
*/
|
||||
public static boolean isItemCurrency(Material currency) {
|
||||
return currency != null;
|
||||
}
|
||||
|
||||
private static class ItemEconomy {
|
||||
|
||||
private static final String ECONOMY_NAME = "Simple Item Economy";
|
||||
|
||||
private static String getFormattedPrice(double amount, Material currency) {
|
||||
if (isItemCurrency(currency)) {
|
||||
return amount + " " + currency.toString();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getName() {
|
||||
return ECONOMY_NAME;
|
||||
}
|
||||
|
||||
private static boolean hasEnough(Player player, double amount, Material currency) {
|
||||
if (currency != null) {
|
||||
return player.getInventory().contains(currency, (int) amount);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void deposit(Player player, double amount, Material currency) {
|
||||
if (isItemCurrency(currency)) {
|
||||
giveItem(player, amount, currency);
|
||||
}
|
||||
}
|
||||
|
||||
private static void withdraw(Player player, double amount, Material currency) {
|
||||
if (isItemCurrency(currency)) {
|
||||
takeItem(player, amount, currency);
|
||||
}
|
||||
}
|
||||
|
||||
private static void giveItem(Player player, double amount, Material type) {
|
||||
ItemStack item = new ItemStack(type, (int) amount);
|
||||
player.getInventory().addItem(item);
|
||||
showReceipt(player, (amount * -1), type);
|
||||
}
|
||||
|
||||
private static void takeItem(Player player, double amount, Material type) {
|
||||
int removed = 0;
|
||||
HashMap<Integer, ItemStack> items = (HashMap<Integer, ItemStack>) player.getInventory().all(type);
|
||||
for (int i : items.keySet()) {
|
||||
if (removed >= amount) {
|
||||
break;
|
||||
}
|
||||
int diff = (int) (amount - removed);
|
||||
int amt = player.getInventory().getItem(i).getAmount();
|
||||
if (amt - diff > 0) {
|
||||
player.getInventory().getItem(i).setAmount(amt - diff);
|
||||
break;
|
||||
} else {
|
||||
removed += amt;
|
||||
player.getInventory().clear(i);
|
||||
}
|
||||
}
|
||||
showReceipt(player, amount, type);
|
||||
}
|
||||
|
||||
private static void showReceipt(Player player, double price, Material item) {
|
||||
if (price > 0D) {
|
||||
player.sendMessage(String.format("%s%s%s %s",
|
||||
ChatColor.WHITE, "You have been charged", ChatColor.GREEN, getFormattedPrice(price, item)));
|
||||
} else if (price < 0D) {
|
||||
player.sendMessage(String.format("%s%s%s %s",
|
||||
ChatColor.DARK_GREEN, getFormattedPrice((price * -1), item),
|
||||
ChatColor.WHITE, "has been added to your inventory."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
@@ -100,7 +101,7 @@ public class MVPermissions implements PermissionsInterface {
|
||||
public boolean canEnterWorld(Player p, MultiverseWorld w) {
|
||||
// If we're not enforcing access, anyone can enter.
|
||||
if (!plugin.getMVConfig().getEnforceAccess()) {
|
||||
this.plugin.log(Level.FINEST, "EnforceAccess is OFF. Player was allowed in " + w.getAlias());
|
||||
Logging.finest("EnforceAccess is OFF. Player was allowed in " + w.getAlias());
|
||||
return true;
|
||||
}
|
||||
return this.hasPermission(p, "multiverse.access." + w.getName(), false);
|
||||
@@ -230,7 +231,7 @@ public class MVPermissions implements PermissionsInterface {
|
||||
*
|
||||
* @param sender Who is requesting the permission.
|
||||
* @param node The permission node in string format; multiverse.core.list.worlds for example.
|
||||
* @param isOpRequired @Deprecated. This is not used for anything anymore.
|
||||
* @param isOpRequired deprecated This is not used for anything anymore.
|
||||
* @return True if they have that permission or any parent.
|
||||
*/
|
||||
@Override
|
||||
@@ -257,14 +258,14 @@ public class MVPermissions implements PermissionsInterface {
|
||||
|
||||
boolean hasPermission = sender.hasPermission(node);
|
||||
if (!sender.isPermissionSet(node)) {
|
||||
this.plugin.log(Level.FINER, String.format("The node [%s%s%s] was %sNOT%s set for [%s%s%s].",
|
||||
Logging.finer(String.format("The node [%s%s%s] was %sNOT%s set for [%s%s%s].",
|
||||
ChatColor.RED, node, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, ChatColor.AQUA,
|
||||
player.getDisplayName(), ChatColor.WHITE));
|
||||
}
|
||||
if (hasPermission) {
|
||||
this.plugin.log(Level.FINER, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
|
||||
Logging.finer("Checking to see if player [" + player.getName() + "] has permission [" + node + "]... YES");
|
||||
} else {
|
||||
this.plugin.log(Level.FINER, "Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
|
||||
Logging.finer("Checking to see if player [" + player.getName() + "] has permission [" + node + "]... NO");
|
||||
}
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
@@ -9,114 +9,19 @@ package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TravelAgent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The Multiverse-{@link TravelAgent}.
|
||||
* The Multiverse TravelAgent.
|
||||
*/
|
||||
public class MVTravelAgent implements TravelAgent {
|
||||
private MVDestination destination;
|
||||
private MultiverseCore core;
|
||||
private Player player;
|
||||
public class MVTravelAgent {
|
||||
protected MVDestination destination;
|
||||
protected MultiverseCore core;
|
||||
protected Player player;
|
||||
|
||||
public MVTravelAgent(MultiverseCore multiverseCore, MVDestination d, Player p) {
|
||||
this.destination = d;
|
||||
this.core = multiverseCore;
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TravelAgent setSearchRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getSearchRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TravelAgent setCreationRadius(int radius) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getCreationRadius() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean getCanCreatePortal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setCanCreatePortal(boolean create) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findOrCreate(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location findPortal(Location location) {
|
||||
return this.getSafeLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean createPortal(Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Location getSafeLocation() {
|
||||
// At this time, these can never use the velocity.
|
||||
if (this.destination instanceof CannonDestination) {
|
||||
this.core.log(Level.FINE, "Using Stock TP method. This cannon will have 0 velocity");
|
||||
}
|
||||
SafeTTeleporter teleporter = this.core.getSafeTTeleporter();
|
||||
Location newLoc = this.destination.getLocation(this.player);
|
||||
if (this.destination.useSafeTeleporter()) {
|
||||
newLoc = teleporter.getSafeLocation(this.player, this.destination);
|
||||
}
|
||||
if (newLoc == null) {
|
||||
return this.player.getLocation();
|
||||
}
|
||||
return newLoc;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import de.themoep.idconverter.IdMappings;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A tool for converting values which may be an old type ID to a Material.
|
||||
*/
|
||||
public class MaterialConverter {
|
||||
|
||||
/**
|
||||
* Converts the value in the given config at the given path from a numeric id or flattened material name to a
|
||||
* Material.
|
||||
*
|
||||
* @param config The config with the value to convert.
|
||||
* @param path The path of the value in the config.
|
||||
* @return The converted Material type or null if no matching type.
|
||||
*/
|
||||
@Nullable
|
||||
public static Material convertConfigType(@NotNull ConfigurationSection config, @NotNull String path) {
|
||||
return convertTypeString(config.getString(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string representing a numeric id or flattened material name to a Material.
|
||||
*
|
||||
* @param value The value to convert.
|
||||
* @return The converted Material type or null if no matching type.
|
||||
*/
|
||||
@Nullable
|
||||
public static Material convertTypeString(@Nullable String value) {
|
||||
IdMappings.Mapping mapping = IdMappings.getById(value != null ? value : "");
|
||||
if (mapping != null) {
|
||||
return Material.matchMaterial(mapping.getFlatteningType());
|
||||
} else {
|
||||
return Material.matchMaterial(value != null ? value : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.fernferret.allpay.GenericBank;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -135,53 +136,52 @@ public class PermissionTools {
|
||||
|
||||
// Only check payments if it's a different world:
|
||||
if (!toWorld.equals(fromWorld)) {
|
||||
final double price = toWorld.getPrice();
|
||||
// Don't bother checking economy stuff if it doesn't even cost to enter.
|
||||
if (toWorld.getPrice() == 0D) {
|
||||
if (price == 0D) {
|
||||
return true;
|
||||
}
|
||||
// If the player does not have to pay, return now.
|
||||
if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) {
|
||||
return true;
|
||||
}
|
||||
final boolean usingVault;
|
||||
final String formattedAmount;
|
||||
if (toWorld.getCurrency() <= 0 && plugin.getVaultEconomy() != null) {
|
||||
usingVault = true;
|
||||
formattedAmount = plugin.getVaultEconomy().format(toWorld.getPrice());
|
||||
} else {
|
||||
usingVault = false;
|
||||
formattedAmount = this.plugin.getBank().getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
|
||||
}
|
||||
String errString = "You need " + formattedAmount + " to send " + teleportee + " to " + toWorld.getColoredWorldString();
|
||||
if (teleportee.equals(teleporter)) {
|
||||
errString = "You need " + formattedAmount + " to enter " + toWorld.getColoredWorldString();
|
||||
}
|
||||
if (usingVault) {
|
||||
if (!plugin.getVaultEconomy().has(teleporterPlayer.getName(), toWorld.getPrice())) {
|
||||
return false;
|
||||
} else if (pay) {
|
||||
if (toWorld.getPrice() < 0D) {
|
||||
plugin.getVaultEconomy().depositPlayer(teleporterPlayer.getName(), toWorld.getPrice() * -1D);
|
||||
|
||||
final MVEconomist economist = plugin.getEconomist();
|
||||
final Material currency = toWorld.getCurrency();
|
||||
final String formattedAmount = economist.formatPrice(price, currency);
|
||||
|
||||
if (economist.isPlayerWealthyEnough(teleporterPlayer, price, currency)) {
|
||||
if (pay) {
|
||||
if (price < 0D) {
|
||||
economist.deposit(teleporterPlayer, -price, currency);
|
||||
} else {
|
||||
plugin.getVaultEconomy().withdrawPlayer(teleporterPlayer.getName(), toWorld.getPrice());
|
||||
economist.withdraw(teleporterPlayer, price, currency);
|
||||
}
|
||||
sendTeleportPaymentMessage(economist, teleporterPlayer, teleportee, toWorld.getColoredWorldString(), price, currency);
|
||||
}
|
||||
} else {
|
||||
GenericBank bank = plugin.getBank();
|
||||
if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) {
|
||||
return false;
|
||||
} else if (pay) {
|
||||
if (toWorld.getPrice() < 0D) {
|
||||
bank.give(teleporterPlayer, toWorld.getPrice() * -1D, toWorld.getCurrency());
|
||||
} else {
|
||||
bank.take(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency());
|
||||
}
|
||||
if (teleportee.equals(teleporter)) {
|
||||
teleporterPlayer.sendMessage(economist.getNSFMessage(currency,
|
||||
"You need " + formattedAmount + " to enter " + toWorld.getColoredWorldString()));
|
||||
} else {
|
||||
teleporterPlayer.sendMessage(economist.getNSFMessage(currency,
|
||||
"You need " + formattedAmount + " to send " + teleportee.getName() + " to " + toWorld.getColoredWorldString()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendTeleportPaymentMessage (MVEconomist economist, Player teleporterPlayer, Player teleportee, String toWorld, double price, Material currency) {
|
||||
price = Math.abs(price);
|
||||
if (teleporterPlayer.equals(teleportee)) {
|
||||
teleporterPlayer.sendMessage("You were " + (price > 0D ? "charged " : "given ") + economist.formatPrice(price, currency) + " for teleporting to " + toWorld);
|
||||
} else {
|
||||
teleporterPlayer.sendMessage("You were " + (price > 0D ? "charged " : "given ") + economist.formatPrice(price, currency) + " for teleporting " + teleportee.getName() + " to " + toWorld);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks to see if player can go to a world given their current status.
|
||||
@@ -196,7 +196,7 @@ public class PermissionTools {
|
||||
* @return True if they can't go to the world, False if they can.
|
||||
*/
|
||||
public boolean playerCanGoFromTo(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) {
|
||||
this.plugin.log(Level.FINEST, "Checking '" + teleporter + "' can send '" + teleportee + "' somewhere");
|
||||
Logging.finest("Checking '" + teleporter + "' can send '" + teleportee + "' somewhere");
|
||||
|
||||
Player teleporterPlayer;
|
||||
if (plugin.getMVConfig().getTeleportIntercept()) {
|
||||
@@ -258,6 +258,32 @@ public class PermissionTools {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a player can bypass the player limit.
|
||||
*
|
||||
* @param toWorld The world travelling to.
|
||||
* @param teleporter The player that initiated the teleport.
|
||||
* @param teleportee The player travelling.
|
||||
* @return True if they can bypass the player limit.
|
||||
*/
|
||||
public boolean playerCanBypassPlayerLimit(MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) {
|
||||
if (teleporter == null) {
|
||||
teleporter = teleportee;
|
||||
}
|
||||
|
||||
if (!(teleporter instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MVPermissions perms = plugin.getMVPerms();
|
||||
if (perms.hasPermission(teleportee, "mv.bypass.playerlimit." + toWorld.getName(), false)) {
|
||||
return true;
|
||||
} else {
|
||||
teleporter.sendMessage("The world " + toWorld.getColoredWorldString() + " is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a player should bypass game mode restrictions.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Helper class to get {@link Player} from name, UUID or Selectors.
|
||||
*/
|
||||
public class PlayerFinder {
|
||||
|
||||
private static final Pattern UUID_REGEX = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
|
||||
private static final Pattern COMMA_SPLIT = Pattern.compile(",");
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on an identifier of name UUID or selector.
|
||||
*
|
||||
* @param playerIdentifier An identifier of name UUID or selector.
|
||||
* @param sender Target sender for selector.
|
||||
* @return The player if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Player get(@NotNull String playerIdentifier,
|
||||
@NotNull CommandSender sender) {
|
||||
|
||||
Player targetPlayer = getByName(playerIdentifier);
|
||||
if (targetPlayer != null) {
|
||||
return targetPlayer;
|
||||
}
|
||||
targetPlayer = getByUuid(playerIdentifier);
|
||||
if (targetPlayer != null) {
|
||||
return targetPlayer;
|
||||
}
|
||||
return getBySelector(playerIdentifier, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple {@link Player} based on many identifiers of name UUID or selector.
|
||||
*
|
||||
* @param playerIdentifiers An identifier of multiple names, UUIDs or selectors, separated by comma.
|
||||
* @param sender Target sender for selector.
|
||||
* @return A list of all the {@link Player} found.
|
||||
*/
|
||||
@Nullable
|
||||
public static List<Player> getMulti(@NotNull String playerIdentifiers,
|
||||
@NotNull CommandSender sender) {
|
||||
|
||||
String[] playerIdentifierArray = COMMA_SPLIT.split(playerIdentifiers);
|
||||
if (playerIdentifierArray == null || playerIdentifierArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Player> playerResults = new ArrayList<>();
|
||||
for (String playerIdentifier : playerIdentifierArray) {
|
||||
Player targetPlayer = getByName(playerIdentifier);
|
||||
if (targetPlayer != null) {
|
||||
playerResults.add(targetPlayer);
|
||||
continue;
|
||||
}
|
||||
targetPlayer = getByUuid(playerIdentifier);
|
||||
if (targetPlayer != null) {
|
||||
playerResults.add(targetPlayer);
|
||||
continue;
|
||||
}
|
||||
List<Player> targetPlayers = getMultiBySelector(playerIdentifier, sender);
|
||||
if (targetPlayers != null) {
|
||||
playerResults.addAll(targetPlayers);
|
||||
}
|
||||
}
|
||||
return playerResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on player name.
|
||||
*
|
||||
* @param playerName Name of a {@link Player}.
|
||||
* @return The player if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Player getByName(@NotNull String playerName) {
|
||||
return Bukkit.getPlayerExact(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on player UUID.
|
||||
*
|
||||
* @param playerUuid UUID of a player.
|
||||
* @return The player if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Player getByUuid(@NotNull String playerUuid) {
|
||||
if (!UUID_REGEX.matcher(playerUuid).matches()) {
|
||||
return null;
|
||||
}
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(playerUuid);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return getByUuid(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on playerUUID.
|
||||
*
|
||||
* @param playerUuid UUID of a player.
|
||||
* @return The player if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Player getByUuid(@NotNull UUID playerUuid) {
|
||||
return Bukkit.getPlayer(playerUuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on vanilla selectors.
|
||||
* https://minecraft.gamepedia.com/Commands#Target_selectors
|
||||
*
|
||||
* @param playerSelector A target selector, usually starts with an '@'.
|
||||
* @param sender Target sender for selector.
|
||||
* @return The player if only one found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Player getBySelector(@NotNull String playerSelector,
|
||||
@NotNull CommandSender sender) {
|
||||
|
||||
List<Player> matchedPlayers = getMultiBySelector(playerSelector, sender);
|
||||
if (matchedPlayers == null || matchedPlayers.isEmpty()) {
|
||||
Logging.fine("No player found with selector '%s' for %s.", playerSelector, sender.getName());
|
||||
return null;
|
||||
}
|
||||
if (matchedPlayers.size() > 1) {
|
||||
Logging.warning("Ambiguous selector result '%s' for %s (more than one player matched) - %s",
|
||||
playerSelector, sender.getName(), matchedPlayers.toString());
|
||||
return null;
|
||||
}
|
||||
return matchedPlayers.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple {@link Player} based on selector.
|
||||
* https://minecraft.gamepedia.com/Commands#Target_selectors
|
||||
*
|
||||
* @param playerSelector A target selector, usually starts with an '@'.
|
||||
* @param sender Target sender for selector.
|
||||
* @return A list of all the {@link Player} found.
|
||||
*/
|
||||
@Nullable
|
||||
public static List<Player> getMultiBySelector(@NotNull String playerSelector,
|
||||
@NotNull CommandSender sender) {
|
||||
|
||||
if (playerSelector.charAt(0) != '@') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Bukkit.selectEntities(sender, playerSelector).stream()
|
||||
.filter(e -> e instanceof Player)
|
||||
.map(e -> ((Player) e))
|
||||
.collect(Collectors.toList());
|
||||
} catch (IllegalArgumentException e) {
|
||||
Logging.warning("An error occurred while parsing selector '%s' for %s. Is it is the correct format?",
|
||||
playerSelector, sender.getName());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
@@ -27,7 +28,7 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* Utility class that removes animals from worlds that don't belong there.
|
||||
*
|
||||
* @deprecated Use instead: {@link WorldPurger} and {@link SimpleWorldPurger}.
|
||||
* @deprecated Use instead: {@link com.onarandombox.MultiverseCore.api.WorldPurger} and {@link SimpleWorldPurger}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class PurgeWorlds {
|
||||
@@ -86,7 +87,7 @@ public class PurgeWorlds {
|
||||
}
|
||||
int entitiesKilled = 0;
|
||||
for (Entity e : world.getEntities()) {
|
||||
this.plugin.log(Level.FINEST, "Entity list (aval for purge) from WORLD < " + mvworld.getName() + " >: " + e.toString());
|
||||
Logging.finest("Entity list (aval for purge) from WORLD < " + mvworld.getName() + " >: " + e.toString());
|
||||
|
||||
// Check against Monsters
|
||||
if (killMonster(mvworld, e, thingsToKill, negateMonsters)) {
|
||||
@@ -133,16 +134,16 @@ public class PurgeWorlds {
|
||||
entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
}
|
||||
if (e instanceof Slime || e instanceof Monster || e instanceof Ghast || e instanceof EnderDragon) {
|
||||
this.plugin.log(Level.FINEST, "Looking at a monster: " + e);
|
||||
Logging.finest("Looking at a monster: " + e);
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
Logging.finest("Removing a monster: " + e);
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing a monster: " + e);
|
||||
Logging.finest("Removing a monster: " + e);
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Utility class used to help in doing various reflection actions.
|
||||
*/
|
||||
public class ReflectHelper {
|
||||
|
||||
/**
|
||||
* Try to get the {@link Class} based on its classpath.
|
||||
*
|
||||
* @param classPath The target classpath.
|
||||
* @return A {@link Class} if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Class<?> getClass(String classPath) {
|
||||
try {
|
||||
return Class.forName(classPath);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the {@link Class} for a give classpath is present/valid.
|
||||
*
|
||||
* @param classPath Target classpath.
|
||||
* @return True if class path is a valid class, else false.
|
||||
*/
|
||||
public static boolean hasClass(String classPath) {
|
||||
return getClass(classPath) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get a {@link Method} from a given class.
|
||||
*
|
||||
* @param clazz The class to search the method on.
|
||||
* @param methodName Name of the method to get.
|
||||
* @param parameterTypes Parameters present for that method.
|
||||
* @param <C> The class type.
|
||||
* @return A {@link Method} if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static <C> Method getMethod(Class<C> clazz, String methodName, Class<?>... parameterTypes) {
|
||||
try {
|
||||
Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get a {@link Method} from a given class.
|
||||
*
|
||||
* @param classInstance Instance of the class to search the method on.
|
||||
* @param methodName Name of the method to get.
|
||||
* @param parameterTypes Parameters present for that method.
|
||||
* @param <C> The class type.
|
||||
* @return A {@link Method} if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static <C> Method getMethod(C classInstance, String methodName, Class<?>... parameterTypes) {
|
||||
return getMethod(classInstance.getClass(), methodName, parameterTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a {@link Method}.
|
||||
*
|
||||
* @param classInstance Instance of the class responsible for the method.
|
||||
* @param method The method to call.
|
||||
* @param parameters Parameters needed when calling the method.
|
||||
* @param <C> The class type.
|
||||
* @param <R> The return type.
|
||||
* @return Return value of the method call if any, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static <C, R> R invokeMethod(C classInstance, Method method, Object...parameters) {
|
||||
try {
|
||||
return (R) method.invoke(classInstance, parameters);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get a {@link Field} from a given class.
|
||||
*
|
||||
* @param clazz The class to search the field on.
|
||||
* @param fieldName Name of the field to get.
|
||||
* @param <C> The class type.
|
||||
* @return A {@link Field} if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static <C> Field getField(Class<C> clazz, String fieldName) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (NoSuchFieldException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get a {@link Field} from a given class.
|
||||
*
|
||||
* @param classInstance Instance of the class to search the field on.
|
||||
* @param fieldName Name of the field to get.
|
||||
* @param <C> The class type.
|
||||
* @return A {@link Field} if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static <C> Field getField(C classInstance, String fieldName) {
|
||||
return getField(classInstance.getClass(), fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of an {@link Field} from an instance of the class responsible.
|
||||
*
|
||||
* @param classInstance Instance of the class to get the field value from.
|
||||
* @param field The field to get value from.
|
||||
* @param <C> The class type.
|
||||
* @param <V> The field value type.
|
||||
* @return The field value if any, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static <C, V> V getFieldValue(C classInstance, Field field) {
|
||||
try {
|
||||
return (V) field.get(classInstance);
|
||||
} catch (IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,358 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The {@link SafeTTeleporter}.
|
||||
*
|
||||
* @deprecated Use instead: {@link com.onarandombox.MultiverseCore.api.SafeTTeleporter} and {@link SimpleSafeTTeleporter}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class SafeTTeleporter {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
private BlockSafety bs;
|
||||
|
||||
public SafeTTeleporter(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.bs = plugin.getBlockSafety();
|
||||
}
|
||||
|
||||
private static final int DEFAULT_TOLERANCE = 6;
|
||||
private static final int DEFAULT_RADIUS = 9;
|
||||
|
||||
/**
|
||||
* Gets the next safe location around the given location.
|
||||
* @param l A {@link Location}.
|
||||
* @return A safe {@link Location}.
|
||||
*/
|
||||
public Location getSafeLocation(Location l) {
|
||||
return this.getSafeLocation(l, DEFAULT_TOLERANCE, DEFAULT_RADIUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next safe location around the given location.
|
||||
* @param l A {@link Location}.
|
||||
* @param tolerance The tolerance.
|
||||
* @param radius The radius.
|
||||
* @return A safe {@link Location}.
|
||||
*/
|
||||
public Location getSafeLocation(Location l, int tolerance, int radius) {
|
||||
// Check around the player first in a configurable radius:
|
||||
Location safe = checkAboveAndBelowLocation(l, tolerance, radius);
|
||||
if (safe != null) {
|
||||
safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
safe.setZ(safe.getBlockZ() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.plugin.log(Level.FINE, "Hey! I found one: " + plugin.getLocationManipulation().strCoordsRaw(safe));
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Uh oh! No safe place found!");
|
||||
}
|
||||
return safe;
|
||||
}
|
||||
|
||||
private Location checkAboveAndBelowLocation(Location l, int tolerance, int radius) {
|
||||
// Tolerance must be an even number:
|
||||
if (tolerance % 2 != 0) {
|
||||
tolerance += 1;
|
||||
}
|
||||
// We want half of it, so we can go up and down
|
||||
tolerance /= 2;
|
||||
this.plugin.log(Level.FINER, "Given Location of: " + plugin.getLocationManipulation().strCoordsRaw(l));
|
||||
this.plugin.log(Level.FINER, "Checking +-" + tolerance + " with a radius of " + radius);
|
||||
|
||||
// For now this will just do a straight up block.
|
||||
Location locToCheck = l.clone();
|
||||
// Check the main level
|
||||
Location safe = this.checkAroundLocation(locToCheck, radius);
|
||||
if (safe != null) {
|
||||
return safe;
|
||||
}
|
||||
// We've already checked zero right above this.
|
||||
int currentLevel = 1;
|
||||
while (currentLevel <= tolerance) {
|
||||
// Check above
|
||||
locToCheck = l.clone();
|
||||
locToCheck.add(0, currentLevel, 0);
|
||||
safe = this.checkAroundLocation(locToCheck, radius);
|
||||
if (safe != null) {
|
||||
return safe;
|
||||
}
|
||||
|
||||
// Check below
|
||||
locToCheck = l.clone();
|
||||
locToCheck.subtract(0, currentLevel, 0);
|
||||
safe = this.checkAroundLocation(locToCheck, radius);
|
||||
if (safe != null) {
|
||||
return safe;
|
||||
}
|
||||
currentLevel++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* For my crappy algorithm, radius MUST be odd.
|
||||
*/
|
||||
private Location checkAroundLocation(Location l, int diameter) {
|
||||
if (diameter % 2 == 0) {
|
||||
diameter += 1;
|
||||
}
|
||||
Location checkLoc = l.clone();
|
||||
|
||||
// Start at 3, the min diameter around a block
|
||||
int loopcounter = 3;
|
||||
while (loopcounter <= diameter) {
|
||||
boolean foundSafeArea = checkAroundSpecificDiameter(checkLoc, loopcounter);
|
||||
// If a safe area was found:
|
||||
if (foundSafeArea) {
|
||||
// Return the checkLoc, it is the safe location.
|
||||
return checkLoc;
|
||||
}
|
||||
// Otherwise, let's reset our location
|
||||
checkLoc = l.clone();
|
||||
// And increment the radius
|
||||
loopcounter += 2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkAroundSpecificDiameter(Location checkLoc, int circle) {
|
||||
// Adjust the circle to get how many blocks to step out.
|
||||
// A radius of 3 makes the block step 1
|
||||
// A radius of 5 makes the block step 2
|
||||
// A radius of 7 makes the block step 3
|
||||
// ...
|
||||
int adjustedCircle = ((circle - 1) / 2);
|
||||
checkLoc.add(adjustedCircle, 0, 0);
|
||||
if (this.bs.playerCanSpawnHereSafely(checkLoc)) {
|
||||
return true;
|
||||
}
|
||||
// Now we go to the right that adjustedCircle many
|
||||
for (int i = 0; i < adjustedCircle; i++) {
|
||||
checkLoc.add(0, 0, 1);
|
||||
if (this.bs.playerCanSpawnHereSafely(checkLoc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then down adjustedCircle *2
|
||||
for (int i = 0; i < adjustedCircle * 2; i++) {
|
||||
checkLoc.add(-1, 0, 0);
|
||||
if (this.bs.playerCanSpawnHereSafely(checkLoc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then left adjustedCircle *2
|
||||
for (int i = 0; i < adjustedCircle * 2; i++) {
|
||||
checkLoc.add(0, 0, -1);
|
||||
if (this.bs.playerCanSpawnHereSafely(checkLoc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then up Then left adjustedCircle *2
|
||||
for (int i = 0; i < adjustedCircle * 2; i++) {
|
||||
checkLoc.add(1, 0, 0);
|
||||
if (this.bs.playerCanSpawnHereSafely(checkLoc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then finish up by doing adjustedCircle - 1
|
||||
for (int i = 0; i < adjustedCircle - 1; i++) {
|
||||
checkLoc.add(0, 0, 1);
|
||||
if (this.bs.playerCanSpawnHereSafely(checkLoc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param teleporter Person who performed the teleport command.
|
||||
* @param teleportee Entity to teleport
|
||||
* @param d Destination to teleport them to
|
||||
* @return true for success, false for failure
|
||||
*/
|
||||
public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d) {
|
||||
if (d instanceof InvalidDestination) {
|
||||
this.plugin.log(Level.FINER, "Entity tried to teleport to an invalid destination");
|
||||
return TeleportResult.FAIL_INVALID;
|
||||
}
|
||||
Player teleporteePlayer = null;
|
||||
if (teleportee instanceof Player) {
|
||||
teleporteePlayer = ((Player) teleportee);
|
||||
} else if (teleportee.getPassenger() instanceof Player) {
|
||||
teleporteePlayer = ((Player) teleportee.getPassenger());
|
||||
}
|
||||
|
||||
if (teleporteePlayer == null) {
|
||||
return TeleportResult.FAIL_INVALID;
|
||||
}
|
||||
MultiverseCore.addPlayerToTeleportQueue(teleporter.getName(), teleporteePlayer.getName());
|
||||
|
||||
Location safeLoc = d.getLocation(teleportee);
|
||||
if (d.useSafeTeleporter()) {
|
||||
safeLoc = this.getSafeLocation(teleportee, d);
|
||||
}
|
||||
|
||||
if (safeLoc != null) {
|
||||
if (teleportee.teleport(safeLoc)) {
|
||||
if (!d.getVelocity().equals(new Vector(0, 0, 0))) {
|
||||
teleportee.setVelocity(d.getVelocity());
|
||||
}
|
||||
return TeleportResult.SUCCESS;
|
||||
}
|
||||
return TeleportResult.FAIL_OTHER;
|
||||
}
|
||||
return TeleportResult.FAIL_UNSAFE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely teleport the entity to the Location. This may perform checks to
|
||||
* see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param teleporter Person who issued the teleport command.
|
||||
* @param teleportee Entity to teleport.
|
||||
* @param location Location to teleport them to.
|
||||
* @param safely Should the destination be checked for safety before teleport?
|
||||
* @return true for success, false for failure.
|
||||
*/
|
||||
public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, Location location, boolean safely) {
|
||||
if (safely) {
|
||||
location = this.getSafeLocation(location);
|
||||
}
|
||||
|
||||
if (location != null) {
|
||||
if (teleportee.teleport(location)) {
|
||||
return TeleportResult.SUCCESS;
|
||||
}
|
||||
return TeleportResult.FAIL_OTHER;
|
||||
}
|
||||
return TeleportResult.FAIL_UNSAFE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a safe location for the entity to spawn at.
|
||||
*
|
||||
* @param e The entity to spawn
|
||||
* @param d The MVDestination to take the entity to.
|
||||
* @return A new location to spawn the entity at.
|
||||
*/
|
||||
public Location getSafeLocation(Entity e, MVDestination d) {
|
||||
Location l = d.getLocation(e);
|
||||
if (this.bs.playerCanSpawnHereSafely(l)) {
|
||||
plugin.log(Level.FINE, "The first location you gave me was safe.");
|
||||
return l;
|
||||
}
|
||||
if (e instanceof Minecart) {
|
||||
Minecart m = (Minecart) e;
|
||||
if (!this.bs.canSpawnCartSafely(m)) {
|
||||
return null;
|
||||
}
|
||||
} else if (e instanceof Vehicle) {
|
||||
Vehicle v = (Vehicle) e;
|
||||
if (!this.bs.canSpawnVehicleSafely(v)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Location safeLocation = this.getSafeLocation(l);
|
||||
if (safeLocation != null) {
|
||||
// Add offset to account for a vehicle on dry land!
|
||||
if (e instanceof Minecart && !this.bs.isEntitiyOnTrack(safeLocation)) {
|
||||
safeLocation.setY(safeLocation.getBlockY() + .5);
|
||||
this.plugin.log(Level.FINER, "Player was inside a minecart. Offsetting Y location.");
|
||||
}
|
||||
this.plugin.log(Level.FINE, "Had to look for a bit, but I found a safe place for ya!");
|
||||
return safeLocation;
|
||||
}
|
||||
if (e instanceof Player) {
|
||||
Player p = (Player) e;
|
||||
this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false);
|
||||
this.plugin.log(Level.FINER, "No safe location found for " + p.getName());
|
||||
} else if (e.getPassenger() instanceof Player) {
|
||||
Player p = (Player) e.getPassenger();
|
||||
this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false);
|
||||
this.plugin.log(Level.FINER, "No safe location found for " + p.getName());
|
||||
}
|
||||
this.plugin.log(Level.FINE, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a portal-block next to the specified {@link Location}.
|
||||
* @param l The {@link Location}
|
||||
* @return The next portal-block's {@link Location}.
|
||||
*/
|
||||
public static Location findPortalBlockNextTo(Location l) {
|
||||
Block b = l.getWorld().getBlockAt(l);
|
||||
Location foundLocation = null;
|
||||
if (b.getType() == Material.PORTAL) {
|
||||
return l;
|
||||
}
|
||||
if (b.getRelative(BlockFace.NORTH).getType() == Material.PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.NORTH).getLocation(), foundLocation);
|
||||
}
|
||||
if (b.getRelative(BlockFace.SOUTH).getType() == Material.PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.SOUTH).getLocation(), foundLocation);
|
||||
}
|
||||
if (b.getRelative(BlockFace.EAST).getType() == Material.PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.EAST).getLocation(), foundLocation);
|
||||
}
|
||||
if (b.getRelative(BlockFace.WEST).getType() == Material.PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.WEST).getLocation(), foundLocation);
|
||||
}
|
||||
return foundLocation;
|
||||
}
|
||||
|
||||
private static Location getCloserBlock(Location source, Location blockA, Location blockB) {
|
||||
// If B wasn't given, return a.
|
||||
if (blockB == null) {
|
||||
return blockA;
|
||||
}
|
||||
// Center our calculations
|
||||
blockA.add(.5, 0, .5);
|
||||
blockB.add(.5, 0, .5);
|
||||
|
||||
// Retrieve the distance to the normalized blocks
|
||||
double testA = source.distance(blockA);
|
||||
double testB = source.distance(blockB);
|
||||
|
||||
// Compare and return
|
||||
if (testA <= testB) {
|
||||
return blockA;
|
||||
}
|
||||
return blockB;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,11 +14,12 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.material.Bed;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -27,10 +28,18 @@ import java.util.Set;
|
||||
*/
|
||||
public class SimpleBlockSafety implements BlockSafety {
|
||||
private final Core plugin;
|
||||
private final static Set<BlockFace> AROUND_BLOCK = new HashSet<BlockFace>(){{ add(BlockFace.NORTH); add(BlockFace.NORTH_EAST);
|
||||
add(BlockFace.EAST); add(BlockFace.SOUTH_EAST);
|
||||
add(BlockFace.SOUTH); add(BlockFace.SOUTH_WEST);
|
||||
add(BlockFace.WEST); add(BlockFace.NORTH_WEST); }};
|
||||
private static final Set<BlockFace> AROUND_BLOCK = EnumSet.noneOf(BlockFace.class);
|
||||
|
||||
static {
|
||||
AROUND_BLOCK.add(BlockFace.NORTH);
|
||||
AROUND_BLOCK.add(BlockFace.NORTH_EAST);
|
||||
AROUND_BLOCK.add(BlockFace.EAST);
|
||||
AROUND_BLOCK.add(BlockFace.SOUTH_EAST);
|
||||
AROUND_BLOCK.add(BlockFace.SOUTH);
|
||||
AROUND_BLOCK.add(BlockFace.SOUTH_WEST);
|
||||
AROUND_BLOCK.add(BlockFace.WEST);
|
||||
AROUND_BLOCK.add(BlockFace.NORTH_WEST);
|
||||
}
|
||||
|
||||
public SimpleBlockSafety(Core plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -81,7 +90,7 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
|
||||
if (downOne.getBlock().getType() == Material.LAVA) {
|
||||
Logging.finer("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(), isSolidBlock(downOne.getBlock().getType()));
|
||||
return false;
|
||||
}
|
||||
@@ -127,7 +136,7 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
*/
|
||||
private Location getSafeSpawnAroundABlock(Location l) {
|
||||
Iterator<BlockFace> checkblock = AROUND_BLOCK.iterator();
|
||||
while(checkblock.hasNext()) {
|
||||
while (checkblock.hasNext()) {
|
||||
final BlockFace face = checkblock.next();
|
||||
if (this.playerCanSpawnHereSafely(l.getBlock().getRelative(face).getLocation())) {
|
||||
// Don't forget to center the player.
|
||||
@@ -143,12 +152,13 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
* @return The location of the other bed piece, or null if it was a jacked up bed.
|
||||
*/
|
||||
private Location findOtherBedPiece(Location checkLoc) {
|
||||
if (checkLoc.getBlock().getType() != Material.BED_BLOCK) {
|
||||
BlockData data = checkLoc.getBlock().getBlockData();
|
||||
if (!(data instanceof Bed)) {
|
||||
return null;
|
||||
}
|
||||
// Construct a bed object at this location
|
||||
final Bed b = new Bed(Material.BED_BLOCK, checkLoc.getBlock().getData());
|
||||
if (b.isHeadOfBed()) {
|
||||
Bed b = (Bed) data;
|
||||
|
||||
if (b.getPart() == Bed.Part.HEAD) {
|
||||
return checkLoc.getBlock().getRelative(b.getFacing().getOppositeFace()).getLocation();
|
||||
}
|
||||
// We shouldn't ever be looking at the foot, but here's the code for it.
|
||||
@@ -191,69 +201,8 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
/*
|
||||
* If someone has a better way of this... Please either tell us, or submit a pull request!
|
||||
*/
|
||||
private static boolean isSolidBlock(Material type) {
|
||||
switch (type) {
|
||||
case AIR:
|
||||
return false;
|
||||
case SNOW:
|
||||
return false;
|
||||
case TRAP_DOOR:
|
||||
return false;
|
||||
case TORCH:
|
||||
return false;
|
||||
case YELLOW_FLOWER:
|
||||
return false;
|
||||
case RED_ROSE:
|
||||
return false;
|
||||
case RED_MUSHROOM:
|
||||
return false;
|
||||
case BROWN_MUSHROOM:
|
||||
return false;
|
||||
case REDSTONE:
|
||||
return false;
|
||||
case REDSTONE_WIRE:
|
||||
return false;
|
||||
case RAILS:
|
||||
return false;
|
||||
case POWERED_RAIL:
|
||||
return false;
|
||||
case REDSTONE_TORCH_ON:
|
||||
return false;
|
||||
case REDSTONE_TORCH_OFF:
|
||||
return false;
|
||||
case DEAD_BUSH:
|
||||
return false;
|
||||
case SAPLING:
|
||||
return false;
|
||||
case STONE_BUTTON:
|
||||
return false;
|
||||
case LEVER:
|
||||
return false;
|
||||
case LONG_GRASS:
|
||||
return false;
|
||||
case PORTAL:
|
||||
return false;
|
||||
case STONE_PLATE:
|
||||
return false;
|
||||
case WOOD_PLATE:
|
||||
return false;
|
||||
case SEEDS:
|
||||
return false;
|
||||
case SUGAR_CANE_BLOCK:
|
||||
return false;
|
||||
case WALL_SIGN:
|
||||
return false;
|
||||
case SIGN_POST:
|
||||
return false;
|
||||
case WOODEN_DOOR:
|
||||
return false;
|
||||
case STATIONARY_WATER:
|
||||
return false;
|
||||
case WATER:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
public static boolean isSolidBlock(Material type) {
|
||||
return type.isSolid();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +211,10 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
@Override
|
||||
public boolean isEntitiyOnTrack(Location l) {
|
||||
Material currentBlock = l.getBlock().getType();
|
||||
return (currentBlock == Material.POWERED_RAIL || currentBlock == Material.DETECTOR_RAIL || currentBlock == Material.RAILS);
|
||||
return (currentBlock == Material.POWERED_RAIL
|
||||
|| currentBlock == Material.DETECTOR_RAIL
|
||||
|| currentBlock == Material.RAIL
|
||||
|| currentBlock == Material.ACTIVATOR_RAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,10 +229,10 @@ public class SimpleBlockSafety implements BlockSafety {
|
||||
}
|
||||
Location oneBelow = l.clone();
|
||||
oneBelow.subtract(0, 1, 0);
|
||||
if (oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER) {
|
||||
if (oneBelow.getBlock().getType() == Material.WATER) {
|
||||
Location twoBelow = oneBelow.clone();
|
||||
twoBelow.subtract(0, 1, 0);
|
||||
return (oneBelow.getBlock().getType() == Material.WATER || oneBelow.getBlock().getType() == Material.STATIONARY_WATER);
|
||||
return (oneBelow.getBlock().getType() == Material.WATER);
|
||||
}
|
||||
if (oneBelow.getBlock().getType() != Material.AIR) {
|
||||
return false;
|
||||
|
||||
+11
-1
@@ -19,6 +19,7 @@ import com.onarandombox.MultiverseCore.api.LocationManipulation;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -39,6 +40,15 @@ public class SimpleLocationManipulation implements LocationManipulation {
|
||||
orientationInts.put("w", 90);
|
||||
orientationInts.put("nw", 135);
|
||||
|
||||
orientationInts.put("north", 180);
|
||||
orientationInts.put("northeast", 225);
|
||||
orientationInts.put("east", 270);
|
||||
orientationInts.put("southeast", 315);
|
||||
orientationInts.put("south", 0);
|
||||
orientationInts.put("southwest", 45);
|
||||
orientationInts.put("west", 90);
|
||||
orientationInts.put("northwest", 135);
|
||||
|
||||
// "freeze" the map:
|
||||
ORIENTATION_INTS = Collections.unmodifiableMap(orientationInts);
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
@@ -52,7 +62,7 @@ public class SimpleLocationManipulation implements LocationManipulation {
|
||||
if (location == null) {
|
||||
return "";
|
||||
}
|
||||
return String.format("%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(),
|
||||
return String.format(Locale.ENGLISH, "%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(),
|
||||
location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
@@ -30,7 +31,6 @@ import java.util.logging.Level;
|
||||
* The default-implementation of {@link SafeTTeleporter}.
|
||||
*/
|
||||
public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
|
||||
public SimpleSafeTTeleporter(MultiverseCore plugin) {
|
||||
@@ -59,9 +59,9 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
if (safe != null) {
|
||||
safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
safe.setZ(safe.getBlockZ() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.plugin.log(Level.FINE, "Hey! I found one: " + plugin.getLocationManipulation().strCoordsRaw(safe));
|
||||
Logging.fine("Hey! I found one: " + plugin.getLocationManipulation().strCoordsRaw(safe));
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Uh oh! No safe place found!");
|
||||
Logging.fine("Uh oh! No safe place found!");
|
||||
}
|
||||
return safe;
|
||||
}
|
||||
@@ -73,8 +73,8 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
}
|
||||
// We want half of it, so we can go up and down
|
||||
tolerance /= 2;
|
||||
this.plugin.log(Level.FINER, "Given Location of: " + plugin.getLocationManipulation().strCoordsRaw(l));
|
||||
this.plugin.log(Level.FINER, "Checking +-" + tolerance + " with a radius of " + radius);
|
||||
Logging.finer("Given Location of: " + plugin.getLocationManipulation().strCoordsRaw(l));
|
||||
Logging.finer("Checking +-" + tolerance + " with a radius of " + radius);
|
||||
|
||||
// For now this will just do a straight up block.
|
||||
Location locToCheck = l.clone();
|
||||
@@ -192,7 +192,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
@Override
|
||||
public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d) {
|
||||
if (d instanceof InvalidDestination) {
|
||||
this.plugin.log(Level.FINER, "Entity tried to teleport to an invalid destination");
|
||||
Logging.finer("Entity tried to teleport to an invalid destination");
|
||||
return TeleportResult.FAIL_INVALID;
|
||||
}
|
||||
Player teleporteePlayer = null;
|
||||
@@ -249,7 +249,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
public Location getSafeLocation(Entity e, MVDestination d) {
|
||||
Location l = d.getLocation(e);
|
||||
if (plugin.getBlockSafety().playerCanSpawnHereSafely(l)) {
|
||||
plugin.log(Level.FINE, "The first location you gave me was safe.");
|
||||
Logging.fine("The first location you gave me was safe.");
|
||||
return l;
|
||||
}
|
||||
if (e instanceof Minecart) {
|
||||
@@ -268,21 +268,21 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
// Add offset to account for a vehicle on dry land!
|
||||
if (e instanceof Minecart && !plugin.getBlockSafety().isEntitiyOnTrack(safeLocation)) {
|
||||
safeLocation.setY(safeLocation.getBlockY() + .5);
|
||||
this.plugin.log(Level.FINER, "Player was inside a minecart. Offsetting Y location.");
|
||||
Logging.finer("Player was inside a minecart. Offsetting Y location.");
|
||||
}
|
||||
this.plugin.log(Level.FINE, "Had to look for a bit, but I found a safe place for ya!");
|
||||
Logging.finer("Had to look for a bit, but I found a safe place for ya!");
|
||||
return safeLocation;
|
||||
}
|
||||
if (e instanceof Player) {
|
||||
Player p = (Player) e;
|
||||
this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false);
|
||||
this.plugin.log(Level.FINER, "No safe location found for " + p.getName());
|
||||
Logging.finer("No safe location found for " + p.getName());
|
||||
} else if (e.getPassenger() instanceof Player) {
|
||||
Player p = (Player) e.getPassenger();
|
||||
this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false);
|
||||
this.plugin.log(Level.FINER, "No safe location found for " + p.getName());
|
||||
Logging.finer("No safe location found for " + p.getName());
|
||||
}
|
||||
this.plugin.log(Level.FINE, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now.");
|
||||
Logging.fine("Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -293,19 +293,19 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
public Location findPortalBlockNextTo(Location l) {
|
||||
Block b = l.getWorld().getBlockAt(l);
|
||||
Location foundLocation = null;
|
||||
if (b.getType() == Material.PORTAL) {
|
||||
if (b.getType() == Material.NETHER_PORTAL) {
|
||||
return l;
|
||||
}
|
||||
if (b.getRelative(BlockFace.NORTH).getType() == Material.PORTAL) {
|
||||
if (b.getRelative(BlockFace.NORTH).getType() == Material.NETHER_PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.NORTH).getLocation(), foundLocation);
|
||||
}
|
||||
if (b.getRelative(BlockFace.SOUTH).getType() == Material.PORTAL) {
|
||||
if (b.getRelative(BlockFace.SOUTH).getType() == Material.NETHER_PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.SOUTH).getLocation(), foundLocation);
|
||||
}
|
||||
if (b.getRelative(BlockFace.EAST).getType() == Material.PORTAL) {
|
||||
if (b.getRelative(BlockFace.EAST).getType() == Material.NETHER_PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.EAST).getLocation(), foundLocation);
|
||||
}
|
||||
if (b.getRelative(BlockFace.WEST).getType() == Material.PORTAL) {
|
||||
if (b.getRelative(BlockFace.WEST).getType() == Material.NETHER_PORTAL) {
|
||||
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.WEST).getLocation(), foundLocation);
|
||||
}
|
||||
return foundLocation;
|
||||
@@ -331,4 +331,8 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
return blockB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeleportResult teleport(final CommandSender teleporter, final Player teleportee, final MVDestination destination) {
|
||||
return this.safelyTeleport(teleporter, teleportee, destination);
|
||||
}
|
||||
}
|
||||
@@ -7,23 +7,27 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Golem;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Phantom;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Squid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Utility class that removes animals from worlds that don't belong there.
|
||||
@@ -32,8 +36,16 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
|
||||
private MultiverseCore plugin;
|
||||
|
||||
private Class<Entity> ambientClass = null;
|
||||
|
||||
public SimpleWorldPurger(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
Class entityClass = Class.forName("org.bukkit.entity.Ambient");
|
||||
if (Entity.class.isAssignableFrom(entityClass)) {
|
||||
ambientClass = entityClass;
|
||||
}
|
||||
} catch (ClassNotFoundException ignore) { }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,18 +97,41 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
int projectilesKilled = 0;
|
||||
int entitiesKilled = 0;
|
||||
boolean specifiedAll = thingsToKill.contains("ALL");
|
||||
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
||||
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
||||
for (Entity e : world.getEntities()) {
|
||||
List<Entity> worldEntities = world.getEntities();
|
||||
List<LivingEntity> livingEntities = new ArrayList<LivingEntity>(worldEntities.size());
|
||||
List<Projectile> projectiles = new ArrayList<Projectile>(worldEntities.size());
|
||||
for (final Entity e : worldEntities) {
|
||||
if (e instanceof Projectile) {
|
||||
final Projectile p = (Projectile) e;
|
||||
if (p.getShooter() != null) {
|
||||
projectiles.add((Projectile) e);
|
||||
}
|
||||
} else if (e instanceof LivingEntity) {
|
||||
livingEntities.add((LivingEntity) e);
|
||||
}
|
||||
}
|
||||
for (final LivingEntity e : livingEntities) {
|
||||
if (killDecision(e, thingsToKill, negateAnimals, negateMonsters, specifiedAnimals, specifiedMonsters)) {
|
||||
final Iterator<Projectile> it = projectiles.iterator();
|
||||
while (it.hasNext()) {
|
||||
final Projectile p = it.next();
|
||||
if (p.getShooter().equals(e)) {
|
||||
p.remove();
|
||||
it.remove();
|
||||
projectilesKilled++;
|
||||
}
|
||||
}
|
||||
e.remove();
|
||||
entitiesKilled++;
|
||||
}
|
||||
}
|
||||
if (sender != null) {
|
||||
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'");
|
||||
sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "' along with " + projectilesKilled + " projectiles that belonged to them.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,19 +139,20 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
boolean negateMonsters, boolean specifiedAnimals, boolean specifiedMonsters) {
|
||||
boolean negate = false;
|
||||
boolean specified = false;
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
if (e instanceof Golem || e instanceof Squid || e instanceof Animals
|
||||
|| (ambientClass != null && ambientClass.isInstance(e))) {
|
||||
// it's an animal
|
||||
if (specifiedAnimals && !negateAnimals) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all animals: " + e);
|
||||
Logging.finest("Removing an entity because I was told to remove all animals in world %s: %s", e.getWorld().getName(), e);
|
||||
return true;
|
||||
}
|
||||
if (specifiedAnimals)
|
||||
specified = true;
|
||||
negate = negateAnimals;
|
||||
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
|
||||
} else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime || e instanceof Phantom) {
|
||||
// it's a monster
|
||||
if (specifiedMonsters && !negateMonsters) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because I was told to remove all monsters: " + e);
|
||||
Logging.finest("Removing an entity because I was told to remove all monsters in world %s: %s", e.getWorld().getName(), e);
|
||||
return true;
|
||||
}
|
||||
if (specifiedMonsters)
|
||||
@@ -128,14 +164,14 @@ public class SimpleWorldPurger implements WorldPurger {
|
||||
if (type != null && type.equals(e.getType())) {
|
||||
specified = true;
|
||||
if (!negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it WAS specified and we are NOT negating: " + e);
|
||||
Logging.finest("Removing an entity because it WAS specified and we are NOT negating in world %s: %s", e.getWorld().getName(), e);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!specified && negate) {
|
||||
this.plugin.log(Level.FINEST, "Removing an entity because it was NOT specified and we ARE negating: " + e);
|
||||
Logging.finest("Removing an entity because it was NOT specified and we ARE negating in world %s: %s", e.getWorld().getName(), e);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
/*
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
|
||||
/**
|
||||
* A helper-class holding the {@link SpoutManager}.
|
||||
* /
|
||||
public class SpoutInterface {
|
||||
private SpoutManager spoutManager;
|
||||
|
||||
public SpoutInterface() {
|
||||
this.spoutManager = SpoutManager.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link SpoutManager}.
|
||||
* @return The {@link SpoutManager}.
|
||||
* /
|
||||
public SpoutManager getManager() {
|
||||
return this.spoutManager;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
/**
|
||||
* A utility class that enables automated tests to flag Multiverse for testing. This allows Multiverse to not perform
|
||||
* certain behaviors such as enabled stats uploads.
|
||||
*/
|
||||
public class TestingMode {
|
||||
|
||||
private static boolean enabled = false;
|
||||
|
||||
public static void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
public static boolean isDisabled() {
|
||||
return !enabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Wraps calls that could result in exceptions that are not Multiverse's fault.
|
||||
*/
|
||||
public class UnsafeCallWrapper {
|
||||
private final Core core;
|
||||
|
||||
public UnsafeCallWrapper(Core core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps calls that could result in exceptions that are not Multiverse's fault.
|
||||
*
|
||||
* @param callable The potentially unsafe call.
|
||||
* @param plugin The plugin that's probably the culprit.
|
||||
* @param action What MV was attempting to do (error message, format string).
|
||||
* @param formatArgs The formatting arguments for the error message.
|
||||
* The exception that was thrown will be appended to these objects.
|
||||
* @param <T> The type of the return value.
|
||||
* @return The return value or null if the call failed.
|
||||
*/
|
||||
public <T> T wrap(Callable<T> callable, String plugin, String action, Object... formatArgs) {
|
||||
try {
|
||||
// We're ready to catch you! JUMP!
|
||||
return callable.call();
|
||||
} catch (Throwable t) {
|
||||
Object[] actualFormatArgs = new Object[formatArgs.length + 1];
|
||||
System.arraycopy(formatArgs, 0, actualFormatArgs, 0, formatArgs.length);
|
||||
actualFormatArgs[formatArgs.length] = t;
|
||||
Logging.warning(action, actualFormatArgs);
|
||||
Logging.warning("This is a bug in %s, NOT a bug in Multiverse!", plugin);
|
||||
if (core.getMVConfig().getGlobalDebug() >= 1)
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* Apparently this isn't used and I don't know if we'll ever use this,
|
||||
* so I'm just going to deprecate it for now and suppress the warnings.
|
||||
*
|
||||
* BEGIN CHECKSTYLE-SUPPRESSION: ALL
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated Currently unused.
|
||||
*/
|
||||
@Deprecated
|
||||
public class UpdateChecker {
|
||||
|
||||
public static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private Timer timer = new Timer(); // Create a new Timer.
|
||||
|
||||
private String name; // Hold the Plugins Name.
|
||||
private String cversion; // Hold the Plugins Current Version.
|
||||
|
||||
public UpdateChecker(String name, String version) {
|
||||
this.name = name;
|
||||
this.cversion = version;
|
||||
|
||||
int delay = 0; // No Delay, fire the first check instantly.
|
||||
int period = 1800; // Delay 30 Minutes
|
||||
|
||||
this.timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkUpdate();
|
||||
}
|
||||
}, delay * 1000, period * 1000);
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
BufferedReader rd = null;
|
||||
try {
|
||||
URL url = new URL("http://bukkit.onarandombox.com/multiverse/version.php?n=" + URLEncoder.encode(this.name, "UTF-8") + "&v=" + this.cversion);
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setReadTimeout(2000); // 2000 = 2 Seconds.
|
||||
|
||||
int code = ((HttpURLConnection) conn).getResponseCode();
|
||||
|
||||
if (code != 200) {
|
||||
return;
|
||||
}
|
||||
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
String version = null;
|
||||
|
||||
while ((line = rd.readLine()) != null) {
|
||||
if (version == null) {
|
||||
version = line;
|
||||
}
|
||||
}
|
||||
|
||||
if (version == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String v1 = normalisedVersion(version);
|
||||
String v2 = normalisedVersion(this.cversion);
|
||||
|
||||
int compare = v1.compareTo(v2);
|
||||
|
||||
if (compare > 0) {
|
||||
log.info("[" + this.name + "]" + " - Update Available (" + version + ")");
|
||||
}
|
||||
|
||||
rd.close();
|
||||
} catch (Exception e) {
|
||||
// No need to alert the user of any error here... it's not important.
|
||||
} finally {
|
||||
if (rd != null) {
|
||||
try {
|
||||
rd.close();
|
||||
} catch (IOException ignore) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given Version String to a Normalized Version String so we can compare it.
|
||||
*
|
||||
* @param version The version string
|
||||
* @return The normalized version string
|
||||
*/
|
||||
public static String normalisedVersion(String version) {
|
||||
return normalisedVersion(version, ".", 4);
|
||||
}
|
||||
|
||||
public static String normalisedVersion(String version, String sep, int maxWidth) {
|
||||
String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : split) {
|
||||
sb.append(String.format("%" + maxWidth + 's', s));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* END CHECKSTYLE-SUPPRESSION: ALL
|
||||
*/
|
||||
Loaded 100 of 133 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user