Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74b04070ab | ||
|
|
1c1245a711 | ||
|
|
ddcd325c21 | ||
|
|
198abf55ea | ||
|
|
139ddd1bb2 | ||
|
|
c10cd5c45a | ||
|
|
7d80b89b02 | ||
|
|
e25e12737a | ||
|
|
e80d3909e0 | ||
|
|
85aa931ae3 | ||
|
|
b7baeb4d3e | ||
|
|
8f4f89b804 | ||
|
|
a478fac019 | ||
|
|
1f87175716 | ||
|
|
650f2022b9 | ||
|
|
51c642b71c | ||
|
|
77faf2bddc | ||
|
|
826fe08cfc | ||
|
|
7a86227a94 | ||
|
|
a6d4e21b85 | ||
|
|
55cf19b1d8 | ||
|
|
2fc6f3dc26 | ||
|
|
8f250011b7 | ||
|
|
b8a0729715 | ||
|
|
40b260feb5 | ||
|
|
b3b8a5ed73 | ||
|
|
03d1b3682d | ||
|
|
7c59dcbcb9 | ||
|
|
15cacba7c9 | ||
|
|
adbe88daa6 | ||
|
|
5350c012f7 | ||
|
|
a91f377cf5 | ||
|
|
c3ae5ac210 | ||
|
|
f4ce740c06 | ||
|
|
3ff8d34053 | ||
|
|
f362f09380 | ||
|
|
84a9db597a | ||
|
|
2c9d2d0fe7 | ||
|
|
2c98fc7d90 | ||
|
|
89fd700e32 | ||
|
|
035f3644ad | ||
|
|
e1bcff732f | ||
|
|
4a90a6a1c7 | ||
|
|
4a4a2505e7 | ||
|
|
e2bf1a2bbe | ||
|
|
835ca69b78 | ||
|
|
2eb4ce6807 | ||
|
|
197764622c | ||
|
|
cde7ab961f | ||
|
|
0f23deeca1 | ||
|
|
6b7089eec0 | ||
|
|
e90f1bb986 | ||
|
|
16878f002a | ||
|
|
8ec08fd26a | ||
|
|
c9cf25c4e3 | ||
|
|
bfffc8c94e | ||
|
|
6e7328a407 | ||
|
|
617b0b5900 | ||
|
|
e7bcdbe64b | ||
|
|
cdfe317517 | ||
|
|
6987208241 | ||
|
|
e1dc90b65d | ||
|
|
fd10eec765 | ||
|
|
54a2e270a8 | ||
|
|
73d1035f84 | ||
|
|
c874a98bac | ||
|
|
b73a4e552f | ||
|
|
cd5a4c69f9 | ||
|
|
9dd9444248 | ||
|
|
942555f380 | ||
|
|
21d775d8a2 | ||
|
|
fd5e9485e9 | ||
|
|
ebe420be15 | ||
|
|
7b3e6ee07d | ||
|
|
808c4ce704 | ||
|
|
04802f2fda | ||
|
|
1ffa1ece2d | ||
|
|
95cce25453 | ||
|
|
d0c280506c | ||
|
|
3b9f1849d7 | ||
|
|
b3517ad9ce | ||
|
|
d0f6434592 | ||
|
|
36e0d34695 | ||
|
|
6771bb6c44 | ||
|
|
3962f23691 | ||
|
|
ef073b0403 | ||
|
|
c8432b9b57 | ||
|
|
3f8e514f51 | ||
|
|
942f8a99ab | ||
|
|
81f6014e94 | ||
|
|
fee822a2fe | ||
|
|
161478f05a | ||
|
|
e9ec1275fe | ||
|
|
fc6415af8c | ||
|
|
e88828f420 | ||
|
|
22afd094b2 | ||
|
|
8f99d2c560 | ||
|
|
6b47164726 | ||
|
|
455b04ce8c | ||
|
|
cf05044b13 | ||
|
|
44cbdc3baf | ||
|
|
114400e77b | ||
|
|
ff5498313b | ||
|
|
7198a5a421 | ||
|
|
793bbe3858 | ||
|
|
90937d6322 | ||
|
|
8c18caf30b | ||
|
|
39e4b5c528 | ||
|
|
ee2e7d3a70 | ||
|
|
5efcda37a5 | ||
|
|
17d5313981 | ||
|
|
31494e2876 | ||
|
|
8304e7a4ef | ||
|
|
2dedffa353 | ||
|
|
3e1d3e776b | ||
|
|
538cdb1a69 | ||
|
|
611af12ba6 | ||
|
|
b5b9e19cff | ||
|
|
20b492fa3c | ||
|
|
e4a6e8a9ec | ||
|
|
b0cbd5b840 | ||
|
|
4b45779cd1 | ||
|
|
cee6f68439 | ||
|
|
b953f1a011 | ||
|
|
29dcef5330 | ||
|
|
b0c4d72828 | ||
|
|
10c1040ead | ||
|
|
b6a784dc1b | ||
|
|
5fad1e0623 | ||
|
|
052194ca64 | ||
|
|
dcadf23677 | ||
|
|
0c61dfff3a | ||
|
|
026dd2f444 | ||
|
|
305cf50c9c | ||
|
|
8292af84b9 | ||
|
|
904e29ed1b | ||
|
|
a76c61301e | ||
|
|
a05d4581f6 | ||
|
|
a783f773b3 | ||
|
|
620203fbb7 | ||
|
|
56b881dcda | ||
|
|
408a66c4b1 | ||
|
|
5f37bb629b | ||
|
|
a7921a9074 | ||
|
|
f99d083347 | ||
|
|
096bcde439 | ||
|
|
b6fbcf9e40 | ||
|
|
ff5f9e0691 | ||
|
|
65c332f93d | ||
|
|
94c8189d2e | ||
|
|
a66e804f05 | ||
|
|
8e00ba11ac | ||
|
|
3ca9de69f0 | ||
|
|
1302a1efb8 | ||
|
|
013c39fd53 | ||
|
|
4720bfe308 | ||
|
|
45e7db7abd | ||
|
|
001a6000f8 | ||
|
|
14fc5c85a7 | ||
|
|
bf61069fed | ||
|
|
42f0965eca | ||
|
|
532469145d | ||
|
|
c0b36fefd8 | ||
|
|
c6baeea5f9 | ||
|
|
dce2cf5601 | ||
|
|
52c210f755 | ||
|
|
23241572df | ||
|
|
fbe0138fa2 | ||
|
|
4b4474b1a9 | ||
|
|
28304baa6e | ||
|
|
7b2a14c31f | ||
|
|
da6d6d64c2 | ||
|
|
bb92aa57a8 | ||
|
|
5709278722 | ||
|
|
e4f043216e | ||
|
|
3809f47a54 | ||
|
|
0641099055 | ||
|
|
1b65a91de4 | ||
|
|
ad40caecef | ||
|
|
e518ea4e47 | ||
|
|
519e449a54 | ||
|
|
23ed7cb6ed | ||
|
|
391ba7b4fa | ||
|
|
5413b92ce2 | ||
|
|
a77ad6d7ab | ||
|
|
7493ce5dd8 | ||
|
|
07bfa44ecc | ||
|
|
c8d1aa467d | ||
|
|
d494017186 | ||
|
|
5483988276 | ||
|
|
6f12290a01 | ||
|
|
df3c9574aa | ||
|
|
9cda6556c9 | ||
|
|
1cda2a18a5 | ||
|
|
15810c9404 | ||
|
|
d93def8b5b | ||
|
|
d8ff083418 | ||
|
|
540394e266 | ||
|
|
425b1c80cc | ||
|
|
47ae6f5378 | ||
|
|
48601e4215 | ||
|
|
ed80083fe8 | ||
|
|
d041e0a8d1 | ||
|
|
de85be5832 | ||
|
|
81d59d8bf5 | ||
|
|
0c2d2f4e0a | ||
|
|
3d9108fb48 | ||
|
|
f41337f8a8 | ||
|
|
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 |
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? -->
|
||||
+1
-2
@@ -3,5 +3,4 @@ jdk:
|
||||
- oraclejdk8
|
||||
notifications:
|
||||
email: false
|
||||
before_install:
|
||||
- sed -i.bak -e 's|https://nexus.codehaus.org/snapshots/|https://oss.sonatype.org/content/repositories/codehaus-snapshots/|g' ~/.m2/settings.xml
|
||||
dist: trusty
|
||||
@@ -13,4 +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.
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
machine:
|
||||
java:
|
||||
version: oraclejdk8
|
||||
@@ -3,16 +3,17 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.onarandombox.multiversecore</groupId>
|
||||
<artifactId>Multiverse-Core</artifactId>
|
||||
<version>4.1.1-1.8.8-SNAPSHOT</version>
|
||||
<version>5.0.0-SNAPSHOT</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 -->
|
||||
<!-- Spigot -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
@@ -33,10 +34,13 @@
|
||||
<id>minebench-repo</id>
|
||||
<url>https://repo.minebench.de/</url>
|
||||
</repository>
|
||||
<!-- Has a copy of metrics R8-SNAPSHOT !-->
|
||||
<repository>
|
||||
<id>elmakers-repo</id>
|
||||
<url>http://maven.elmakers.com/repository/</url>
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>aikar</id>
|
||||
<url>https://repo.aikar.co/content/groups/aikar/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -70,6 +74,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>
|
||||
@@ -91,21 +106,44 @@
|
||||
<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>
|
||||
@@ -181,7 +219,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -194,17 +232,13 @@
|
||||
<pattern>me.main__.util</pattern>
|
||||
<shadedPattern>com.onarandombox.serializationconfig</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.pneumaticraft.commandhandler</pattern>
|
||||
<shadedPattern>com.onarandombox.commandhandler</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>buscript</pattern>
|
||||
<shadedPattern>com.onarandombox.buscript</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>com.onarandombox.mcstats</shadedPattern>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>com.onarandombox.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.dumptruckman.minecraft.util.Logging</pattern>
|
||||
@@ -222,6 +256,14 @@
|
||||
<pattern>de.themoep.idconverter</pattern>
|
||||
<shadedPattern>com.onarandombox.idconverter</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.commands</pattern>
|
||||
<shadedPattern>com.onarandombox.acf</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.locales</pattern>
|
||||
<shadedPattern>com.onarandombox.locales</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
@@ -230,13 +272,19 @@
|
||||
<plugin>
|
||||
<groupId>se.eris</groupId>
|
||||
<artifactId>notnull-instrumenter-maven-plugin</artifactId>
|
||||
<version>0.6.8</version>
|
||||
<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>
|
||||
@@ -247,7 +295,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- SerializationConfig Dependency -->
|
||||
@@ -267,15 +315,15 @@
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.5</version>
|
||||
<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>11</version>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-paper</artifactId>
|
||||
<version>0.5.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dumptruckman.minecraft</groupId>
|
||||
@@ -283,9 +331,9 @@
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R6</version>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>1.8</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
@@ -319,21 +367,21 @@
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
@@ -352,12 +400,12 @@
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>OnARandomBox</id>
|
||||
<url>http://repo.onarandombox.com/content/repositories/multiverse</url>
|
||||
<id>benergy10</id>
|
||||
<url>http://repo.benergy10.dev/repository/minecraft/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>OnARandomBox</id>
|
||||
<url>http://repo.onarandombox.com/content/repositories/multiverse-snapshots/</url>
|
||||
<id>benergy10</id>
|
||||
<url>http://repo.benergy10.dev/repository/minecraft-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -28,7 +28,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@@ -37,11 +36,11 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The implementation of a Multiverse handled world.
|
||||
@@ -214,7 +213,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
public Double validateChange(String property, Double newValue, Double oldValue,
|
||||
MVWorld object) throws ChangeDeniedException {
|
||||
if (newValue <= 0) {
|
||||
plugin.log(Level.FINE, "Someone tried to set a scale <= 0, aborting!");
|
||||
Logging.fine("Someone tried to set a scale <= 0, aborting!");
|
||||
throw new ChangeDeniedException();
|
||||
}
|
||||
return super.validateChange(property, newValue, oldValue, object);
|
||||
@@ -297,7 +296,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
public GameMode validateChange(String property, GameMode newValue, GameMode oldValue,
|
||||
MVWorld object) throws ChangeDeniedException {
|
||||
for (Player p : plugin.getServer().getWorld(getName()).getPlayers()) {
|
||||
plugin.log(Level.FINER, String.format("Setting %s's GameMode to %s",
|
||||
Logging.finer(String.format("Setting %s's GameMode to %s",
|
||||
p.getName(), newValue.toString()));
|
||||
plugin.getPlayerListener().handleGameModeAndFlight(p, MVWorld.this);
|
||||
}
|
||||
@@ -319,16 +318,16 @@ public class MVWorld implements MultiverseWorld {
|
||||
// verify that the location is safe
|
||||
if (!bs.playerCanSpawnHereSafely(newValue)) {
|
||||
// it's not ==> find a better one!
|
||||
plugin.log(Level.WARNING, String.format("Somebody tried to set the spawn location for '%s' to an unsafe value! Adjusting...", getAlias()));
|
||||
plugin.log(Level.WARNING, "Old Location: " + plugin.getLocationManipulation().strCoordsRaw(oldValue));
|
||||
plugin.log(Level.WARNING, "New (unsafe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue));
|
||||
Logging.warning(String.format("Somebody tried to set the spawn location for '%s' to an unsafe value! Adjusting...", getAlias()));
|
||||
Logging.warning("Old Location: " + plugin.getLocationManipulation().strCoordsRaw(oldValue));
|
||||
Logging.warning("New (unsafe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue));
|
||||
SafeTTeleporter teleporter = plugin.getSafeTTeleporter();
|
||||
newValue = teleporter.getSafeLocation(newValue, SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
|
||||
if (newValue == null) {
|
||||
plugin.log(Level.WARNING, "Couldn't fix the location. I have to abort the spawn location-change :/");
|
||||
Logging.warning("Couldn't fix the location. I have to abort the spawn location-change :/");
|
||||
throw new ChangeDeniedException();
|
||||
}
|
||||
plugin.log(Level.WARNING, "New (safe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue));
|
||||
Logging.warning("New (safe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue));
|
||||
}
|
||||
}
|
||||
return super.validateChange(property, newValue, oldValue, object);
|
||||
@@ -411,7 +410,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
// Add limit bypass to it's parent
|
||||
this.limitbypassperm.addParent("mv.bypass.playerlimit.*", true);
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name);
|
||||
Logging.finer("Permissions nodes were already added for " + this.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,16 +421,16 @@ public class MVWorld implements MultiverseWorld {
|
||||
// Verify that location was safe
|
||||
if (!bs.playerCanSpawnHereSafely(location)) {
|
||||
if (!this.getAdjustSpawn()) {
|
||||
this.plugin.log(Level.FINE, "Spawn location from world.dat file was unsafe!!");
|
||||
this.plugin.log(Level.FINE, "NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to.");
|
||||
this.plugin.log(Level.FINE, "To turn on spawn adjustment for this world simply type:");
|
||||
this.plugin.log(Level.FINE, "/mvm set adjustspawn true " + this.getAlias());
|
||||
Logging.fine("Spawn location from world.dat file was unsafe!!");
|
||||
Logging.fine("NOT adjusting spawn for '" + this.getAlias() + "' because you told me not to.");
|
||||
Logging.fine("To turn on spawn adjustment for this world simply type:");
|
||||
Logging.fine("/mvm set adjustspawn true " + this.getAlias());
|
||||
return location;
|
||||
}
|
||||
// If it's not, find a better one.
|
||||
SafeTTeleporter teleporter = this.plugin.getSafeTTeleporter();
|
||||
this.plugin.log(Level.WARNING, "Spawn location from world.dat file was unsafe. Adjusting...");
|
||||
this.plugin.log(Level.WARNING, "Original Location: " + plugin.getLocationManipulation().strCoordsRaw(location));
|
||||
Logging.warning("Spawn location from world.dat file was unsafe. Adjusting...");
|
||||
Logging.warning("Original Location: " + plugin.getLocationManipulation().strCoordsRaw(location));
|
||||
Location newSpawn = teleporter.getSafeLocation(location,
|
||||
SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
|
||||
// I think we could also do this, as I think this is what Notch does.
|
||||
@@ -450,7 +449,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
this.getName(), plugin.getLocationManipulation().locationToString(newerSpawn));
|
||||
return newerSpawn;
|
||||
} else {
|
||||
this.plugin.log(Level.SEVERE, "Safe spawn NOT found!!!");
|
||||
Logging.severe("Safe spawn NOT found!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1133,6 +1132,14 @@ public class MVWorld implements MultiverseWorld {
|
||||
return this.props.getBedRespawn();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getAllPropertyTypes() {
|
||||
return this.props.serialize().keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -7,23 +7,6 @@
|
||||
|
||||
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.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
|
||||
@@ -34,43 +17,9 @@ 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;
|
||||
import com.onarandombox.MultiverseCore.commands.CloneCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ConfigCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ConfirmCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CoordCommand;
|
||||
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;
|
||||
import com.onarandombox.MultiverseCore.commands.InfoCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ListCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.LoadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyAddCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyClearCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyRemoveCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifySetCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.PurgeCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RegenCommand;
|
||||
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.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CoreFlags;
|
||||
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.BedDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
@@ -91,6 +40,7 @@ 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;
|
||||
@@ -99,18 +49,17 @@ import com.onarandombox.MultiverseCore.utils.MaterialConverter;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.TestingMode;
|
||||
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
|
||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||
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;
|
||||
@@ -122,7 +71,19 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
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.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The implementation of the Multiverse-{@link Core}.
|
||||
@@ -205,7 +166,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
}
|
||||
|
||||
// Setup our Map for our Commands using the CommandHandler.
|
||||
private CommandHandler commandHandler;
|
||||
private MVCommandManager commandManager;
|
||||
|
||||
private static final String LOG_TAG = "[Multiverse-Core]";
|
||||
|
||||
@@ -257,6 +218,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Setup our SafeTTeleporter
|
||||
this.safeTTeleporter = new SimpleSafeTTeleporter(this);
|
||||
this.unsafeCallWrapper = new UnsafeCallWrapper(this);
|
||||
// Setup our static classes
|
||||
CompatibilityLayer.init();
|
||||
CoreFlags.setCoreInstance(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -286,12 +250,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
|
||||
this.ph = new MVPermissions(this);
|
||||
|
||||
// Setup the command manager
|
||||
this.commandHandler = new CommandHandler(this, this.ph);
|
||||
// Call the Function to assign all the Commands to their Class.
|
||||
this.registerCommands();
|
||||
|
||||
// Initialize the Destination factor AFTER the commands
|
||||
// Initialize the Destination factory
|
||||
this.initializeDestinationFactory();
|
||||
|
||||
this.playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
@@ -309,7 +268,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.worldManager.loadDefaultWorlds();
|
||||
this.worldManager.loadWorlds(true);
|
||||
} 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();
|
||||
|
||||
@@ -337,110 +296,38 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.initializeBuscript();
|
||||
this.setupMetrics();
|
||||
|
||||
// Setup commands
|
||||
this.commandManager = new MVCommandManager(this);
|
||||
|
||||
// Output a little snippet to show it's enabled.
|
||||
Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), PROTOCOL, getAuthors());
|
||||
|
||||
getLogger().info("Help dumptruckman keep this project alive. Become a patron! https://www.patreon.com/dumptruckman");
|
||||
getLogger().info("One time donations are also appreciated: https://www.paypal.me/dumptruckman");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
if (TestingMode.isDisabled()) {
|
||||
MetricsConfigurator.configureMetrics(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the buscript javascript library.
|
||||
*/
|
||||
private void initializeBuscript() {
|
||||
buscript = new Buscript(this);
|
||||
// Add global variable "multiverse" to javascript environment
|
||||
buscript.setScriptVariable("multiverse", 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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,6 +351,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
pm.registerEvents(this.entityListener, 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);
|
||||
}
|
||||
@@ -582,13 +470,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
try {
|
||||
wconf.load(worldsFile);
|
||||
} catch (IOException e) {
|
||||
log(Level.WARNING, "Cannot load worlds.yml");
|
||||
Logging.warning("Cannot load worlds.yml");
|
||||
} catch (InvalidConfigurationException e) {
|
||||
log(Level.WARNING, "Your worlds.yml is invalid!");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -601,7 +489,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
// 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
|
||||
WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
|
||||
ConfigurationSection section = (ConfigurationSection) entry.getValue();
|
||||
@@ -767,8 +655,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
try {
|
||||
difficulty = Difficulty.valueOf(section.getString("difficulty").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.log(Level.WARNING, "Could not parse difficulty: " + section.getString("difficulty"));
|
||||
this.log(Level.WARNING, "Setting world " + entry.getKey() + " difficulty to NORMAL");
|
||||
Logging.warning("Could not parse difficulty: " + section.getString("difficulty"));
|
||||
Logging.warning("Setting world " + entry.getKey() + " difficulty to NORMAL");
|
||||
difficulty = Difficulty.NORMAL;
|
||||
}
|
||||
if (difficulty != null) {
|
||||
@@ -785,7 +673,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
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;
|
||||
}
|
||||
@@ -818,51 +706,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
return this.messaging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Multiverse-Core commands to Command Manager.
|
||||
*/
|
||||
private void registerCommands() {
|
||||
// Intro Commands
|
||||
this.commandHandler.registerCommand(new HelpCommand(this));
|
||||
this.commandHandler.registerCommand(new VersionCommand(this));
|
||||
this.commandHandler.registerCommand(new ListCommand(this));
|
||||
this.commandHandler.registerCommand(new InfoCommand(this));
|
||||
this.commandHandler.registerCommand(new CreateCommand(this));
|
||||
this.commandHandler.registerCommand(new CloneCommand(this));
|
||||
this.commandHandler.registerCommand(new ImportCommand(this));
|
||||
this.commandHandler.registerCommand(new ReloadCommand(this));
|
||||
this.commandHandler.registerCommand(new SetSpawnCommand(this));
|
||||
this.commandHandler.registerCommand(new CoordCommand(this));
|
||||
this.commandHandler.registerCommand(new TeleportCommand(this));
|
||||
this.commandHandler.registerCommand(new WhoCommand(this));
|
||||
this.commandHandler.registerCommand(new SpawnCommand(this));
|
||||
// Dangerous Commands
|
||||
this.commandHandler.registerCommand(new UnloadCommand(this));
|
||||
this.commandHandler.registerCommand(new LoadCommand(this));
|
||||
this.commandHandler.registerCommand(new RemoveCommand(this));
|
||||
this.commandHandler.registerCommand(new DeleteCommand(this));
|
||||
this.commandHandler.registerCommand(new RegenCommand(this));
|
||||
this.commandHandler.registerCommand(new ConfirmCommand(this));
|
||||
// Modification commands
|
||||
this.commandHandler.registerCommand(new ModifyCommand(this));
|
||||
this.commandHandler.registerCommand(new PurgeCommand(this));
|
||||
this.commandHandler.registerCommand(new ModifyAddCommand(this));
|
||||
this.commandHandler.registerCommand(new ModifySetCommand(this));
|
||||
this.commandHandler.registerCommand(new ModifyRemoveCommand(this));
|
||||
this.commandHandler.registerCommand(new ModifyClearCommand(this));
|
||||
this.commandHandler.registerCommand(new ConfigCommand(this));
|
||||
this.commandHandler.registerCommand(new AnchorCommand(this));
|
||||
// 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -895,32 +738,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated This is now deprecated, nobody needs it any longer.
|
||||
* All logging is now done with {@link Logging}.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if (!this.isEnabled()) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
return true;
|
||||
}
|
||||
ArrayList<String> allArgs = new ArrayList<String>(Arrays.asList(args));
|
||||
allArgs.add(0, command.getName());
|
||||
try {
|
||||
return this.commandHandler.locateAndRunCommand(sender, allArgs, getMVConfig().getDisplayPermErrors());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sender.sendMessage(ChatColor.RED + "An internal error occurred when attempting to perform this command.");
|
||||
if (sender.isOp())
|
||||
sender.sendMessage(ChatColor.RED + "Details were printed to the server console and logs, please add that to your bug report.");
|
||||
else
|
||||
sender.sendMessage(ChatColor.RED + "Try again and contact the server owner or an admin if this problem persists.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void log(Level level, String msg) {
|
||||
Logging.log(level, msg);
|
||||
}
|
||||
@@ -981,10 +804,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CommandHandler getCommandHandler() {
|
||||
return this.commandHandler;
|
||||
public MVCommandManager getMVCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1051,18 +875,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
return this.destFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a convenience method to allow the QueuedCommand system to call it. You should NEVER call this directly.
|
||||
*
|
||||
* @param teleporter The Person requesting that the teleport should happen.
|
||||
* @param p Player The Person being teleported.
|
||||
* @param l The potentially unsafe location.
|
||||
*/
|
||||
public void teleportPlayer(CommandSender teleporter, Player p, Location l) {
|
||||
// This command is the override, and MUST NOT TELEPORT SAFELY
|
||||
this.getSafeTTeleporter().safelyTeleport(teleporter, p, l, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server's root-folder as {@link File}.
|
||||
*
|
||||
@@ -1139,7 +951,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1161,40 +973,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
return this.saveMVConfig() && this.saveWorldConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT deprecated for the time as queued commands use this.
|
||||
* However, this is not in the API and other plugins should therefore not use it.
|
||||
*
|
||||
* @param name World to delete
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
public Boolean deleteWorld(String name) {
|
||||
return this.worldManager.deleteWorld(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOT deprecated for the time as queued commands use this.
|
||||
* However, this is not in the API and other plugins should therefore not use it.
|
||||
*
|
||||
* @param oldName World to copy
|
||||
* @param newName World to create
|
||||
* @param generator The Custom generator plugin to use.
|
||||
* @return True if success, false if fail.
|
||||
*/
|
||||
public Boolean cloneWorld(String oldName, String newName, String generator) {
|
||||
return this.worldManager.cloneWorld(oldName, newName, generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This is deprecated!
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed) {
|
||||
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.onarandombox.MultiverseCore;
|
||||
|
||||
import com.dumptruckman.minecraft.util.*;
|
||||
import com.onarandombox.MultiverseCore.api.*;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import me.main__.util.SerializationConfig.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.*;
|
||||
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 org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Our configuration.
|
||||
@@ -54,6 +56,8 @@ 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;
|
||||
@@ -71,6 +75,8 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
private volatile int portalsearchradius;
|
||||
@Property
|
||||
private volatile boolean autopurge;
|
||||
@Property
|
||||
private volatile boolean idonotwanttodonate;
|
||||
|
||||
public MultiverseCoreConfiguration() {
|
||||
super();
|
||||
@@ -95,6 +101,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
teleportintercept = true;
|
||||
firstspawnoverride = true;
|
||||
displaypermerrors = true;
|
||||
enablebuscript = true;
|
||||
globaldebug = 0;
|
||||
messagecooldown = 5000;
|
||||
teleportcooldown = 1000;
|
||||
@@ -103,6 +110,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
defaultportalsearch = false;
|
||||
portalsearchradius = 128;
|
||||
autopurge = true;
|
||||
idonotwanttodonate = false;
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
}
|
||||
|
||||
@@ -208,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}
|
||||
*/
|
||||
@@ -348,4 +372,14 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
|
||||
public void setAutoPurgeEnabled(boolean autopurge) {
|
||||
this.autopurge = autopurge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowingDonateMessage() {
|
||||
return !idonotwanttodonate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowDonateMessage(boolean showDonateMessage) {
|
||||
this.idonotwanttodonate = !showDonateMessage;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import buscript.Buscript;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVEconomist;
|
||||
@@ -17,7 +18,6 @@ import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
@@ -79,12 +79,12 @@ public interface Core {
|
||||
MVPermissions getMVPerms();
|
||||
|
||||
/**
|
||||
* Multiverse uses {@link CommandHandler} to make adding and using commands
|
||||
* Multiverse uses {@link MVCommandManager} to make adding and using commands
|
||||
* a piece of cake.
|
||||
*
|
||||
* @return A non-null {@link CommandHandler}.
|
||||
* @return A non-null {@link MVCommandManager}.
|
||||
*/
|
||||
CommandHandler getCommandHandler();
|
||||
MVCommandManager getMVCommandManager();
|
||||
|
||||
/**
|
||||
* Gets the factory class responsible for loading many different destinations
|
||||
@@ -115,21 +115,6 @@ public interface Core {
|
||||
*/
|
||||
AnchorManager getAnchorManager();
|
||||
|
||||
/**
|
||||
* Used by queued commands to regenerate a world on a delay.
|
||||
*
|
||||
* @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
|
||||
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed);
|
||||
|
||||
/**
|
||||
* Decrements the number of plugins that have specifically hooked into core.
|
||||
*/
|
||||
|
||||
@@ -1,20 +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.api;
|
||||
|
||||
/**
|
||||
* A fancy text.
|
||||
*/
|
||||
public interface FancyText {
|
||||
/**
|
||||
* Gets the {@link String}-representation of this {@link FancyText}.
|
||||
*
|
||||
* @return The {@link String}-representation of this {@link FancyText}.
|
||||
*/
|
||||
String getFancyText();
|
||||
}
|
||||
@@ -40,6 +40,14 @@ public interface LocationManipulation {
|
||||
*/
|
||||
Location stringToLocation(String locationString);
|
||||
|
||||
/**
|
||||
* Returns a colored string with x, y, z axis.
|
||||
*
|
||||
* @param l The {@link Location}
|
||||
* @return The {@link String}
|
||||
*/
|
||||
String strAxis(Location l);
|
||||
|
||||
/**
|
||||
* Returns a colored string with the coords.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.WorldValidationResult;
|
||||
import com.onarandombox.MultiverseCore.utils.PurgeWorlds;
|
||||
import com.onarandombox.MultiverseCore.utils.SimpleWorldPurger;
|
||||
import org.bukkit.World;
|
||||
@@ -314,4 +315,20 @@ public interface MVWorldManager {
|
||||
* does not exist. {@code includeLoaded} if the world exists and is loaded.
|
||||
*/
|
||||
boolean hasUnloadedWorld(String name, boolean includeLoaded);
|
||||
|
||||
/**
|
||||
* Check if a world name is a possible importable world folder.
|
||||
*
|
||||
* @param worldName Name of the world you want to check.
|
||||
* @return True if world is valid, false otherwise.
|
||||
*/
|
||||
boolean isValidWorld(String worldName);
|
||||
|
||||
/**
|
||||
* Check if a world name is a possible importable world folder.
|
||||
*
|
||||
* @param worldName Name of the world you want to check.
|
||||
* @return WorldValidationResult.VALID if world is valid, else the reason why its not valid.
|
||||
*/
|
||||
WorldValidationResult validateWorld(String worldName);
|
||||
}
|
||||
@@ -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.
|
||||
@@ -213,4 +225,18 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
|
||||
* @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);
|
||||
}
|
||||
@@ -1,19 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.DebugLog;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Make things easier for MV-Plugins!
|
||||
@@ -96,25 +90,6 @@ public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
|
||||
*/
|
||||
protected abstract void onPluginEnable();
|
||||
|
||||
/**
|
||||
* You can register commands here.
|
||||
* @param handler The CommandHandler.
|
||||
*/
|
||||
protected abstract void registerCommands(CommandHandler handler);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!this.isEnabled()) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<String> allArgs = new ArrayList<String>(args.length + 1);
|
||||
allArgs.add(command.getName());
|
||||
allArgs.addAll(Arrays.asList(args));
|
||||
return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
int debugLevel = this.getCore().getMVConfig().getGlobalDebug();
|
||||
|
||||
@@ -16,10 +16,10 @@ 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.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -651,6 +651,13 @@ public interface MultiverseWorld {
|
||||
*/
|
||||
List<String> getWorldBlacklist();
|
||||
|
||||
/**
|
||||
* Gets all the names of all properties that can be SET.
|
||||
*
|
||||
* @return All property names in list.
|
||||
*/
|
||||
Collection<String> getAllPropertyTypes();
|
||||
|
||||
/**
|
||||
* Gets all the names of all properties that can be SET.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PermissionsInterface {
|
||||
public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired);
|
||||
|
||||
public boolean hasAnyPermission(CommandSender sender, List<String> allPermissionStrings, boolean opRequired);
|
||||
|
||||
public boolean hasAllPermission(CommandSender sender, List<String> allPermissionStrings, boolean opRequired);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,156 +7,127 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Allows management of Anchor Destinations.
|
||||
*/
|
||||
public class AnchorCommand extends PaginatedCoreCommand<String> {
|
||||
@CommandAlias("mv")
|
||||
@Subcommand("anchors")
|
||||
public class AnchorCommand extends MultiverseCoreCommand {
|
||||
|
||||
private final AnchorManager anchorManager;
|
||||
|
||||
public AnchorCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Create, Delete and Manage Anchor Destinations.");
|
||||
this.setCommandUsage("/mv anchor " + ChatColor.GREEN + "{name}" + ChatColor.GOLD + " [-d]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv anchor");
|
||||
this.addKey("mv anchors");
|
||||
this.addKey("mvanchor");
|
||||
this.addKey("mvanchors");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "otherthing");
|
||||
this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d");
|
||||
this.addCommandExample("/mv anchors ");
|
||||
this.setPermission("multiverse.core.anchor.list", "Allows a player to list all anchors.", PermissionDefault.OP);
|
||||
this.addAdditonalPermission(new Permission("multiverse.core.anchor.create",
|
||||
"Allows a player to create anchors.", PermissionDefault.OP));
|
||||
this.addAdditonalPermission(new Permission("multiverse.core.anchor.delete",
|
||||
"Allows a player to delete anchors.", PermissionDefault.OP));
|
||||
this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.anchorManager = plugin.getAnchorManager();
|
||||
}
|
||||
|
||||
private List<String> getFancyAnchorList(Player p) {
|
||||
List<String> anchorList = new ArrayList<String>();
|
||||
ChatColor color = ChatColor.GREEN;
|
||||
for (String anchor : this.plugin.getAnchorManager().getAnchors(p)) {
|
||||
anchorList.add(color + anchor);
|
||||
color = (color == ChatColor.GREEN) ? ChatColor.GOLD : ChatColor.GREEN;
|
||||
}
|
||||
return anchorList;
|
||||
@Subcommand("create")
|
||||
@CommandPermission("multiverse.core.anchor.create")
|
||||
@Syntax("<name>")
|
||||
@Description("Create a new anchor point.")
|
||||
public void onCreateAnchorCommand(@NotNull Player player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<name>")
|
||||
@Description("Name of your new anchor.")
|
||||
@Flags("type=anchor name")
|
||||
@Single String anchorName) {
|
||||
|
||||
player.sendMessage((this.plugin.getAnchorManager().saveAnchorLocation(anchorName, player.getLocation()))
|
||||
|
||||
? String.format("Anchor '%s%s%s' was successfully %s created!",
|
||||
ChatColor.AQUA, anchorName, ChatColor.WHITE, ChatColor.GREEN)
|
||||
|
||||
: String.format("%sThere was an error creating anchor '%s'! Check console for errors.",
|
||||
ChatColor.RED, anchorName));
|
||||
|
||||
}
|
||||
|
||||
private void showList(CommandSender sender, List<String> args) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.list", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to list anchors!");
|
||||
return;
|
||||
}
|
||||
@Subcommand("delete")
|
||||
@CommandPermission("multiverse.core.anchor.delete")
|
||||
@Syntax("<anchor>")
|
||||
@CommandCompletion("@anchors")
|
||||
@Description("Delete an existing anchor point.")
|
||||
public void onDeleteAnchorCommand(@NotNull CommandSender sender,
|
||||
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]====");
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("<name>")
|
||||
@Description("Name of anchor you want to delete.")
|
||||
@Flags("type=anchor name")
|
||||
@Single String anchorName) {
|
||||
|
||||
sender.sendMessage((this.plugin.getAnchorManager().deleteAnchor(anchorName))
|
||||
|
||||
FilterObject filterObject = this.getPageAndFilter(args);
|
||||
? String.format("Anchor '%s%s%s' was successfully %s deleted!",
|
||||
ChatColor.AQUA, anchorName, ChatColor.WHITE, ChatColor.RED)
|
||||
|
||||
List<String> availableAnchors = new ArrayList<String>(this.getFancyAnchorList(p));
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter());
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (availableAnchors.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors were defined.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
for (String c : availableAnchors) {
|
||||
sender.sendMessage(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil(availableAnchors.size() / (this.itemsPerPage + 0.0));
|
||||
|
||||
if (filterObject.getPage() > totalPages) {
|
||||
filterObject.setPage(totalPages);
|
||||
} else if (filterObject.getPage() < 1) {
|
||||
filterObject.setPage(1);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableAnchors);
|
||||
: String.format("%sThere was an error deleting anchor '%s'! Check console for errors.",
|
||||
ChatColor.RED, anchorName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
this.showList(sender, args);
|
||||
return;
|
||||
}
|
||||
if (args.size() == 1 && (this.getPageAndFilter(args).getPage() != 1 || args.get(0).equals("1"))) {
|
||||
this.showList(sender, args);
|
||||
return;
|
||||
}
|
||||
if (args.size() == 2 && args.get(1).equalsIgnoreCase("-d")) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.delete", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to delete anchors!");
|
||||
} else {
|
||||
if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@Subcommand("list")
|
||||
@CommandPermission("multiverse.core.anchor.list")
|
||||
@Syntax("[filter] [page]")
|
||||
@Description("View a list of current anchors.")
|
||||
public void onListAnchorCommand(@NotNull CommandSender sender,
|
||||
@NotNull PageFilter pageFilter) {
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to create Anchors.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.create", true)) {
|
||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to create anchors!");
|
||||
} else {
|
||||
Player player = (Player) sender;
|
||||
if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!");
|
||||
} else {
|
||||
sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!");
|
||||
}
|
||||
}
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.header("%s====[ Multiverse Anchor List ]====", ChatColor.LIGHT_PURPLE)
|
||||
.contents(buildAnchorList(sender))
|
||||
.emptyMessage("You do not any anchors set. See /mv anchors create to get started!")
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
.colorTool(ColorAlternator.with(ChatColor.YELLOW, ChatColor.DARK_AQUA))
|
||||
.setting(DisplaySettings.SHOW_PAGE, pageFilter.getPage())
|
||||
.display();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFilteredItems(List<String> availableItems, String filter) {
|
||||
List<String> filtered = new ArrayList<String>();
|
||||
for (String s : availableItems) {
|
||||
if (s.matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(s);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
private List<String> buildAnchorList(@NotNull CommandSender sender) {
|
||||
Set<String> anchors = (sender instanceof Player)
|
||||
? this.anchorManager.getAnchors((Player) sender)
|
||||
: this.anchorManager.getAllAnchors();
|
||||
|
||||
@Override
|
||||
protected String getItemText(String item) {
|
||||
return item;
|
||||
List<String> anchorContent = new ArrayList<>();
|
||||
for (String anchor : anchors) {
|
||||
Location anchorLocation = this.anchorManager.getAnchorLocation(anchor);
|
||||
World world = anchorLocation.getWorld(); // this.plugin.getMVWorldManager().getMVWorld();
|
||||
|
||||
String locationString = ChatColor.RED + "!!INVALID!!";
|
||||
if (world != null) {
|
||||
MultiverseWorld mvWorld = this.plugin.getMVWorldManager().getMVWorld(world);
|
||||
locationString = (mvWorld == null)
|
||||
? String.format("%s%s !!NOT MULTIVERSE WORLD!!", ChatColor.RED, world.getName())
|
||||
: String.format("%s - %s", mvWorld.getColoredWorldString(), this.plugin.getLocationManipulation().strAxis(anchorLocation));
|
||||
}
|
||||
anchorContent.add(String.format("%s: %s", anchor, locationString));
|
||||
}
|
||||
|
||||
return anchorContent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/******************************************************************************
|
||||
* 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.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.RequiredPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandAlias("mv")
|
||||
public class BedCommand extends MultiverseCoreCommand {
|
||||
|
||||
public BedCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand("bed")
|
||||
@CommandPermission("multiverse.core.bed.self")
|
||||
@Description("Takes your current respawn point.")
|
||||
public void onBedCommand(@NotNull Player player) {
|
||||
doBedRespawn(player, player);
|
||||
}
|
||||
|
||||
@Subcommand("bed")
|
||||
@CommandPermission("multiverse.core.bed.other")
|
||||
@Syntax("[player]")
|
||||
@CommandCompletion("@players")
|
||||
@Description("Takes another player to their respawn location.")
|
||||
public void onOtherBedCommand(@NotNull CommandSender sender,
|
||||
|
||||
@Syntax("[player]")
|
||||
@Description("Target player to teleport to respawn location.")
|
||||
@NotNull RequiredPlayer player) {
|
||||
|
||||
doBedRespawn(sender, player.get());
|
||||
}
|
||||
|
||||
private void doBedRespawn(@NotNull CommandSender sender,
|
||||
@NotNull Player player) {
|
||||
|
||||
Location bedLocation = player.getBedSpawnLocation();
|
||||
if (bedLocation == null) {
|
||||
sender.sendMessage(String.format("%sYou do not have a respawn point set!", ChatColor.RED));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage((player.teleport(bedLocation))
|
||||
? "You have been teleported to your respawn point!"
|
||||
: String.format("%sThere was an error teleporting you to your respawn point.", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,51 +7,42 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import org.bukkit.ChatColor;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.RequiredPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* Checks to see if a player can go to a destination.
|
||||
*/
|
||||
public class CheckCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class CheckCommand extends MultiverseCoreCommand {
|
||||
|
||||
public CheckCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Help you validate your multiverse settings");
|
||||
this.setCommandUsage("/mv check " + ChatColor.GREEN + "{PLAYER} {DESTINATION}");
|
||||
this.setArgRange(2, 2);
|
||||
this.addKey("mv check");
|
||||
this.addKey("mvcheck");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "fernferret " + ChatColor.LIGHT_PURPLE + "w:MyWorld");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "Rigby90 " + ChatColor.LIGHT_PURPLE + "p:MyPortal");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "lithium3141 " + ChatColor.LIGHT_PURPLE + "ow:WarpName");
|
||||
this.setPermission("multiverse.core.debug", "Checks to see if a player can go to a destination. Prints debug if false.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = this.plugin.getServer().getPlayer(args.get(0));
|
||||
if (p == null) {
|
||||
sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0));
|
||||
sender.sendMessage("Are they online?");
|
||||
return;
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,",
|
||||
args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE));
|
||||
sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?");
|
||||
return;
|
||||
}
|
||||
@Subcommand("check")
|
||||
@CommandPermission("multiverse.core.debug")
|
||||
@Syntax("<player> <destination>")
|
||||
@CommandCompletion("@players @destinations|@MVWorlds")
|
||||
@Description("Checks to see if a player can go to a destination. Prints debug if false.")
|
||||
public void onCheckCommand(@NotNull CommandSender sender,
|
||||
|
||||
MVPermissions perms = this.plugin.getMVPerms();
|
||||
perms.tellMeWhyICantDoThis(sender, p, dest);
|
||||
@NotNull
|
||||
@Syntax("<player>")
|
||||
@Description("Player to check destination on.")
|
||||
RequiredPlayer player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<destination>")
|
||||
@Description("A destination location, e.g. a world name.")
|
||||
MVDestination destination) {
|
||||
|
||||
this.plugin.getMVPerms().tellMeWhyICantDoThis(sender, player.get(), destination);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,49 +7,46 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
|
||||
/**
|
||||
* Creates a clone of a world.
|
||||
*/
|
||||
public class CloneCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class CloneCommand extends MultiverseCoreCommand {
|
||||
|
||||
public CloneCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Clone World");
|
||||
this.setCommandUsage("/mv clone" + ChatColor.GREEN + " {TARGET} {NAME}" + ChatColor.GOLD + " -g [GENERATOR[:ID]]");
|
||||
this.setArgRange(2, 4); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvclone");
|
||||
this.addKey("mvcl");
|
||||
this.addKey("mv cl");
|
||||
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.setPermission("multiverse.core.clone", "Clones a world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
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 " + oldName + ", so we can't clone it!");
|
||||
sender.sendMessage("Check the " + ChatColor.GREEN + "/mv list" + ChatColor.WHITE + " command to verify it is listed.");
|
||||
return;
|
||||
}
|
||||
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!");
|
||||
}
|
||||
@Subcommand("clone")
|
||||
@CommandPermission("multiverse.core.clone")
|
||||
@Syntax("<world> <name>")
|
||||
@CommandCompletion("@MVWorlds|@unloadedWorlds @empty")
|
||||
@Description("Clones a world.")
|
||||
public void onCloneCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<world>")
|
||||
@Description("Current multiverse world.")
|
||||
@Conditions("isWorldInConfig") String worldName,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<name>")
|
||||
@Description("New cloned world name.")
|
||||
@Single @Flags("trim") @Conditions("creatableWorldName") String newWorldName) {
|
||||
|
||||
sender.sendMessage((this.plugin.getMVWorldManager().cloneWorld(worldName, newWorldName))
|
||||
? String.format("%sWorld cloned!", ChatColor.GREEN)
|
||||
: String.format("%sWorld could not be cloned! See console for more details.", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,66 +7,88 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import co.aikar.commands.annotation.Values;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Allows you to set Global MV Variables.
|
||||
*/
|
||||
public class ConfigCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
@Subcommand("config")
|
||||
@CommandPermission("multiverse.core.config")
|
||||
public class ConfigCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ConfigCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Configuration");
|
||||
this.setCommandUsage("/mv config " + ChatColor.GREEN + "{PROPERTY} {VALUE}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mv config");
|
||||
this.addKey("mvconfig");
|
||||
this.addKey("mv conf");
|
||||
this.addKey("mvconf");
|
||||
this.addCommandExample("/mv config show");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false");
|
||||
this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Map<String, Object> serializedConfig = this.plugin.getMVConfig().serialize();
|
||||
for (Map.Entry<String, Object> entry : serializedConfig.entrySet()) {
|
||||
builder.append(ChatColor.GREEN);
|
||||
builder.append(entry.getKey());
|
||||
builder.append(ChatColor.WHITE).append(" = ").append(ChatColor.GOLD);
|
||||
builder.append(entry.getValue().toString());
|
||||
builder.append(ChatColor.WHITE).append(", ");
|
||||
}
|
||||
String message = builder.toString();
|
||||
message = message.substring(0, message.length() - 2);
|
||||
sender.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
if (!this.plugin.getMVConfig().setConfigProperty(args.get(0).toLowerCase(), args.get(1))) {
|
||||
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1)));
|
||||
@Subcommand("list")
|
||||
@Syntax("[filter]")
|
||||
@Description("Show multiverse config values.")
|
||||
public void onShowCommand(@NotNull CommandSender sender,
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
new ContentDisplay.Builder<Map<String, Object>>()
|
||||
.sender(sender)
|
||||
.header("%s===[ Multiverse Config ]===", ChatColor.LIGHT_PURPLE)
|
||||
.contents(this.plugin.getMVConfig().serialize())
|
||||
.emptyMessage("No config values found.")
|
||||
.displayHandler(DisplayHandlers.INLINE_MAP)
|
||||
.colorTool(ColorAlternator.with(ChatColor.GREEN, ChatColor.GOLD))
|
||||
.filter(filter)
|
||||
.display();
|
||||
}
|
||||
|
||||
@Subcommand("set")
|
||||
@Syntax("<property> <value>")
|
||||
@CommandCompletion("@MVConfigs")
|
||||
@Description("Set Global MV Variables.")
|
||||
public void onSetCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<property>")
|
||||
@Description("Config option.")
|
||||
@Values("@MVConfigs") String property,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<value>")
|
||||
@Description("New value for the given config option.")
|
||||
@Single String value) {
|
||||
|
||||
property = property.toLowerCase();
|
||||
|
||||
if (!this.plugin.getMVConfig().setConfigProperty(property, value)) {
|
||||
sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, property, value));
|
||||
return;
|
||||
}
|
||||
|
||||
// special rule
|
||||
if (args.get(0).equalsIgnoreCase("firstspawnworld")) {
|
||||
// Don't forget to set the world!
|
||||
this.plugin.getMVWorldManager().setFirstSpawnWorld(args.get(1));
|
||||
if (!this.plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(String.format("%sFailed to save config! Check your console for details.", ChatColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!");
|
||||
this.plugin.loadConfigs();
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!");
|
||||
// special rule, don't forget to set the world!
|
||||
//TODO API: Potentially should move to MultiverseCore#loadConfigs method
|
||||
if (property.equalsIgnoreCase("firstspawnworld")) {
|
||||
this.plugin.getMVWorldManager().setFirstSpawnWorld(value);
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%sSuccess! %sConfig option %s%s %sis now set to %s%s%s.",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, property, ChatColor.WHITE, ChatColor.GREEN, value, ChatColor.WHITE));
|
||||
|
||||
this.plugin.loadConfigs();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,33 +7,25 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Confirms actions.
|
||||
*/
|
||||
public class ConfirmCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class ConfirmCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ConfirmCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
// Any command that is dangerous should require op
|
||||
this.setName("Confirms a command that could destroy life, the universe and everything.");
|
||||
this.setCommandUsage("/mv confirm");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvconfirm");
|
||||
this.addKey("mv confirm");
|
||||
this.addCommandExample("/mv confirm");
|
||||
this.setPermission("multiverse.core.confirm", "If you have not been prompted to use this, it will not do anything.", PermissionDefault.OP);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
this.plugin.getCommandHandler().confirmQueuedCommand(sender);
|
||||
@Subcommand("confirm")
|
||||
@CommandPermission("multiverse.core.confirm")
|
||||
@Description("Confirms dangerous commands before executing them.")
|
||||
public void onConfirmCommand(@NotNull CommandSender sender) {
|
||||
this.plugin.getMVCommandManager().getQueueManager().runQueuedCommand(sender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,64 +7,69 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.RequiredPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Returns detailed information on the Players where abouts.
|
||||
*/
|
||||
public class CoordCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class CoordCommand extends MultiverseCoreCommand {
|
||||
|
||||
public CoordCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Coordinates");
|
||||
this.setCommandUsage("/mv coord");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv coord");
|
||||
this.addKey("mvcoord");
|
||||
this.addKey("mvco");
|
||||
this.addCommandExample("/mv coord");
|
||||
this.setPermission("multiverse.core.coord", "Returns detailed information on the Players where abouts.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
World world = p.getWorld();
|
||||
@Subcommand("coord|coordinate")
|
||||
@CommandPermission("multiverse.core.coord.self")
|
||||
@Description("Detailed information on your own where abouts.")
|
||||
public void onCoordCommand(@NotNull Player player) {
|
||||
showCoordInfo(player, player);
|
||||
}
|
||||
|
||||
if (!this.worldManager.isMVWorld(world.getName())) {
|
||||
this.plugin.showNotMVWorldMessage(sender, world.getName());
|
||||
return;
|
||||
}
|
||||
@Subcommand("coord|coordinate")
|
||||
@CommandPermission("multiverse.core.coord.other")
|
||||
@Syntax("[player]")
|
||||
@CommandCompletion("@players")
|
||||
@Description("Detailed information on the player's where abouts.")
|
||||
public void onOtherCoordCommand(@NotNull CommandSender sender,
|
||||
|
||||
MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName());
|
||||
@NotNull
|
||||
@Syntax("[player]")
|
||||
@Description("Player you want coordinate info of.")
|
||||
RequiredPlayer player) {
|
||||
|
||||
p.sendMessage(ChatColor.AQUA + "--- Location Information ---");
|
||||
p.sendMessage(ChatColor.AQUA + "World: " + ChatColor.WHITE + world.getName());
|
||||
p.sendMessage(ChatColor.AQUA + "Alias: " + mvworld.getColoredWorldString());
|
||||
p.sendMessage(ChatColor.AQUA + "World Scale: " + ChatColor.WHITE + mvworld.getScaling());
|
||||
DecimalFormat df = new DecimalFormat();
|
||||
df.setMinimumFractionDigits(0);
|
||||
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 + world.getBlockAt(p.getLocation()).getType());
|
||||
} else {
|
||||
sender.sendMessage("This command needs to be used from a Player.");
|
||||
showCoordInfo(sender, player.get());
|
||||
}
|
||||
|
||||
private void showCoordInfo(@NotNull CommandSender sender,
|
||||
@NotNull Player player) {
|
||||
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld());
|
||||
if (world == null) {
|
||||
throw new InvalidCommandArgument("Player is not in a multiverse world.");
|
||||
}
|
||||
|
||||
String name = player.equals(sender)
|
||||
? ""
|
||||
: String.format("for %s%s%s",ChatColor.YELLOW, player.getName(), ChatColor.AQUA);
|
||||
|
||||
sender.sendMessage(String.format("%s--- Location Information %s---", ChatColor.AQUA, name));
|
||||
sender.sendMessage(String.format("%sWorld: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getName()));
|
||||
sender.sendMessage(String.format("%sAlias: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getColoredWorldString()));
|
||||
sender.sendMessage(String.format("%sWorld Scale: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getScaling()));
|
||||
sender.sendMessage(String.format("%sCoordinates: %s%s", ChatColor.AQUA, ChatColor.WHITE, this.plugin.getLocationManipulation().strCoords(player.getLocation())));
|
||||
sender.sendMessage(String.format("%sWorld Scale: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getScaling()));
|
||||
sender.sendMessage(String.format("%sDirection: %s%s", ChatColor.AQUA, ChatColor.WHITE, this.plugin.getLocationManipulation().getDirection(player.getLocation())));
|
||||
sender.sendMessage(String.format("%sBlock: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getCBWorld().getBlockAt(player.getLocation()).getType()));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,114 +7,77 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagGroup;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagResult;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CoreFlags;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.bukkit.World.*;
|
||||
|
||||
/**
|
||||
* Creates a new world and loads it.
|
||||
*/
|
||||
public class CreateCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class CreateCommand extends MultiverseCoreCommand {
|
||||
|
||||
public CreateCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Create World");
|
||||
this.setCommandUsage(String.format("/mv create %s{NAME} {ENV} %s-s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n] -a [true|false]",
|
||||
ChatColor.GREEN, ChatColor.GOLD));
|
||||
this.setArgRange(2, 11); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvcreate");
|
||||
this.addKey("mvc");
|
||||
this.addKey("mv create");
|
||||
this.setPermission("multiverse.core.create", "Creates a new world and loads it.", PermissionDefault.OP);
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel");
|
||||
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
this.setFlagGroup(FlagGroup.of(
|
||||
CoreFlags.WORLD_TYPE,
|
||||
CoreFlags.SEED,
|
||||
CoreFlags.GENERATOR,
|
||||
CoreFlags.GENERATE_STRUCTURES,
|
||||
CoreFlags.SPAWN_ADJUST
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = args.get(0);
|
||||
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
String env = args.get(1);
|
||||
String seed = CommandHandler.getFlag("-s", args);
|
||||
String generator = CommandHandler.getFlag("-g", args);
|
||||
boolean allowStructures = true;
|
||||
String structureString = CommandHandler.getFlag("-a", args);
|
||||
if (structureString != null) {
|
||||
allowStructures = Boolean.parseBoolean(structureString);
|
||||
}
|
||||
String typeString = CommandHandler.getFlag("-t", args);
|
||||
boolean useSpawnAdjust = true;
|
||||
for (String s : args) {
|
||||
if (s.equalsIgnoreCase("-n")) {
|
||||
useSpawnAdjust = false;
|
||||
}
|
||||
}
|
||||
@Subcommand("create")
|
||||
@CommandPermission("multiverse.core.create")
|
||||
@Syntax("<name> <env> -s [seed] -g [generator[:id]] -t [worldtype] [-n] -a [true|false]")
|
||||
@CommandCompletion("@empty @environments @flags")
|
||||
@Description("Creates a new world and loads it.")
|
||||
public void onCreateCommand(@NotNull CommandSender sender,
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
|
||||
+ "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
|
||||
return;
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("<name>")
|
||||
@Description("New world name.")
|
||||
@Flags("trim")
|
||||
@Conditions("creatableWorldName") String worldName,
|
||||
|
||||
if (worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
|
||||
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
||||
return;
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("<env>")
|
||||
@Description("The world's environment. See: /mv env")
|
||||
Environment environment,
|
||||
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
return;
|
||||
}
|
||||
@Nullable
|
||||
@Syntax("[world-flags]")
|
||||
@Description("Other world settings. See: http://gg.gg/nn8bl")
|
||||
String[] flagsArray) {
|
||||
|
||||
// If they didn't specify a type, default to NORMAL
|
||||
if (typeString == null) {
|
||||
typeString = "NORMAL";
|
||||
}
|
||||
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
|
||||
EnvironmentCommand.showWorldTypes(sender);
|
||||
return;
|
||||
}
|
||||
// Determine if the generator is valid. #918
|
||||
if (generator != null) {
|
||||
List<String> genarray = new ArrayList<String>(Arrays.asList(generator.split(":")));
|
||||
if (genarray.size() < 2) {
|
||||
// If there was only one arg specified, pad with another empty one.
|
||||
genarray.add("");
|
||||
}
|
||||
if (this.worldManager.getChunkGenerator(genarray.get(0), genarray.get(1), "test") == null) {
|
||||
// We have an invalid generator.
|
||||
sender.sendMessage("Invalid generator! '" + generator + "'. " + ChatColor.RED + "Aborting world creation.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'...");
|
||||
FlagResult flags = this.getFlagGroup().calculateResult(flagsArray);
|
||||
|
||||
if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) {
|
||||
Command.broadcastCommandMessage(sender, "Complete!");
|
||||
} else {
|
||||
Command.broadcastCommandMessage(sender, "FAILED.");
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting creation of world '%s'...", worldName));
|
||||
Command.broadcastCommandMessage(sender, (this.plugin.getMVWorldManager().addWorld(
|
||||
worldName,
|
||||
environment,
|
||||
// TODO API: Should Allow FlagResult object to be passed directly
|
||||
flags.getValue(CoreFlags.SEED),
|
||||
flags.getValue(CoreFlags.WORLD_TYPE),
|
||||
flags.getValue(CoreFlags.GENERATE_STRUCTURES),
|
||||
flags.getValue(CoreFlags.GENERATOR),
|
||||
flags.getValue(CoreFlags.SPAWN_ADJUST))
|
||||
)
|
||||
? String.format("%sComplete!", ChatColor.GREEN)
|
||||
: String.format("%sFailed! See console for errors.", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,60 +7,85 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Enables debug-information.
|
||||
*/
|
||||
public class DebugCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
@CommandPermission("multiverse.core.debug")
|
||||
public class DebugCommand extends MultiverseCoreCommand {
|
||||
|
||||
public DebugCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Turn Debug on/off?");
|
||||
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv debug");
|
||||
this.addKey("mv d");
|
||||
this.addKey("mvdebug");
|
||||
this.addCommandExample("/mv debug " + ChatColor.GOLD + "2");
|
||||
this.setPermission("multiverse.core.debug", "Spams the console a bunch.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("off")) {
|
||||
plugin.getMVConfig().setGlobalDebug(0);
|
||||
} else {
|
||||
try {
|
||||
int debugLevel = Integer.parseInt(args.get(0));
|
||||
if (debugLevel > 3 || debugLevel < 0) {
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
plugin.getMVConfig().setGlobalDebug(debugLevel);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE
|
||||
+ " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)");
|
||||
}
|
||||
}
|
||||
plugin.saveMVConfigs();
|
||||
@Subcommand("debug")
|
||||
@CommandPermission("multiverse.core.debug")
|
||||
@Description("Show the current debug level.")
|
||||
public void onShowDebugCommand(@NotNull CommandSender sender) {
|
||||
displayDebugMode(sender);
|
||||
}
|
||||
|
||||
@Subcommand("debug")
|
||||
@CommandPermission("multiverse.core.debug")
|
||||
@Syntax("<level>")
|
||||
@CommandCompletion("@toggles|@range:3")
|
||||
@Description("Change debug level.")
|
||||
public void onChangeDebugCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<level>")
|
||||
@Description("Set debug mode level, 0 to 3.")
|
||||
@Single String debugLevel) {
|
||||
|
||||
int parsedLevel = parseDebugLevel(debugLevel);
|
||||
if (parsedLevel == -1) {
|
||||
throw new InvalidCommandArgument("No such debug level. Please use a number from 0 to 3.");
|
||||
}
|
||||
this.displayDebugMode(sender);
|
||||
|
||||
this.plugin.getMVConfig().setGlobalDebug(parsedLevel);
|
||||
if (!this.plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(String.format("%sError saving changes to config! See console for more info.", ChatColor.RED));
|
||||
}
|
||||
|
||||
displayDebugMode(sender);
|
||||
}
|
||||
|
||||
private void displayDebugMode(CommandSender sender) {
|
||||
final int debugLevel = plugin.getMVConfig().getGlobalDebug();
|
||||
private int parseDebugLevel(@NotNull String debugLevel) {
|
||||
if (debugLevel.equalsIgnoreCase("off")) {
|
||||
return 0;
|
||||
}
|
||||
if (debugLevel.equalsIgnoreCase("on")) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
int parsedLevel = Integer.parseInt(debugLevel);
|
||||
return (parsedLevel > 3 || parsedLevel < 0) ? -1 : parsedLevel;
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void displayDebugMode(@NotNull CommandSender sender) {
|
||||
int debugLevel = this.plugin.getMVConfig().getGlobalDebug();
|
||||
if (debugLevel == 0) {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
|
||||
} else {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel);
|
||||
this.plugin.log(Level.FINE, "Multiverse Debug ENABLED");
|
||||
sender.sendMessage(String.format("Multiverse Debug mode is %soff", ChatColor.RED));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(String.format("Multiverse Debug mode at level %s%s", ChatColor.GREEN, debugLevel));
|
||||
Logging.fine("Multiverse debug mode enabled!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,39 +7,58 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Deletes worlds.
|
||||
*/
|
||||
public class DeleteCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class DeleteCommand extends MultiverseCoreCommand {
|
||||
|
||||
public DeleteCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Delete World");
|
||||
this.setCommandUsage("/mv delete" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvdelete");
|
||||
this.addKey("mv delete");
|
||||
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) {
|
||||
String worldName = args.get(0);
|
||||
@Subcommand("delete")
|
||||
@CommandPermission("multiverse.core.delete")
|
||||
@Syntax("<world>")
|
||||
@CommandCompletion("@MVWorlds|@unloadedWorlds")
|
||||
@Description("Deletes a world on your server PERMANENTLY.")
|
||||
public void onDeleteCommand(@NotNull CommandSender sender,
|
||||
|
||||
Class<?>[] paramTypes = {String.class};
|
||||
List<Object> objectArgs = new ArrayList<Object>(args);
|
||||
this.plugin.getCommandHandler()
|
||||
.queueCommand(sender, "mvdelete", "deleteWorld", objectArgs,
|
||||
paramTypes, ChatColor.GREEN + "World '" + worldName + "' Deleted!",
|
||||
ChatColor.RED + "World '" + worldName + "' could NOT be deleted!");
|
||||
@NotNull
|
||||
@Syntax("<world>")
|
||||
@Description("Multiverse world you want to delete.")
|
||||
@Flags("trim")
|
||||
@Conditions("isWorldInConfig|validWorldFolder")
|
||||
@Single String worldName) {
|
||||
|
||||
this.plugin.getMVCommandManager().getQueueManager().addToQueue(new QueuedCommand.Builder()
|
||||
.sender(sender)
|
||||
.action(deleteRunnable(sender, worldName))
|
||||
.prompt("Are you sure you want to delete world '%s'?", worldName)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private Runnable deleteRunnable(@NotNull CommandSender sender,
|
||||
@NotNull String worldName) {
|
||||
|
||||
return () -> {
|
||||
sender.sendMessage(String.format("Deleting world '%s'...", worldName));
|
||||
sender.sendMessage((this.plugin.getMVWorldManager().deleteWorld(worldName))
|
||||
? String.format("%sWorld %s was deleted!", ChatColor.GREEN, worldName)
|
||||
: String.format("%sThere was an issue deleting '%s'! Please check console for errors.", ChatColor.RED, worldName));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,32 +7,28 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Lists valid known environments.
|
||||
*/
|
||||
public class EnvironmentCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class EnvironmentCommand extends MultiverseCoreCommand {
|
||||
|
||||
public EnvironmentCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("List Environments");
|
||||
this.setCommandUsage("/mv env");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvenv");
|
||||
this.addKey("mv env");
|
||||
this.addKey("mv type");
|
||||
this.addKey("mv environment");
|
||||
this.addKey("mv environments");
|
||||
this.addCommandExample("/mv env");
|
||||
this.setPermission("multiverse.core.list.environments", "Lists valid known environments/world types.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Subcommand("env|environments")
|
||||
@CommandPermission("multiverse.core.list.environments")
|
||||
@Description("Lists valid known environments and world types.")
|
||||
public void onEnvironmentCommand(CommandSender sender) {
|
||||
showEnvironments(sender);
|
||||
sender.sendMessage("");
|
||||
showWorldTypes(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,78 +37,19 @@ public class EnvironmentCommand extends MultiverseCommand {
|
||||
* @param sender The {@link CommandSender}.
|
||||
*/
|
||||
public static void showEnvironments(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:");
|
||||
sender.sendMessage(ChatColor.GREEN + "NORMAL");
|
||||
sender.sendMessage(ChatColor.RED + "NETHER");
|
||||
sender.sendMessage(ChatColor.AQUA + "END");
|
||||
sender.sendMessage(String.format("%sValid Environments are:", ChatColor.YELLOW));
|
||||
sender.sendMessage(String.format("%sNORMAL%s, %sNETHER %sor %sEND",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, ChatColor.AQUA));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows all valid known world types to a {@link CommandSender}.
|
||||
*
|
||||
* @param sender The {@link CommandSender}.
|
||||
*/
|
||||
public static void showWorldTypes(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:");
|
||||
sender.sendMessage(String.format("%sNORMAL%s, %sFLAT, %sLARGEBIOMES %sor %sVERSION_1_1",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.RED, ChatColor.WHITE, ChatColor.GOLD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
EnvironmentCommand.showWorldTypes(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link String} into a {@link WorldType}.
|
||||
*
|
||||
* @param type The WorldType as a {@link String}
|
||||
* @return The WorldType as a {@link WorldType}
|
||||
*/
|
||||
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")) {
|
||||
type = "NORMAL";
|
||||
} else if (type.equalsIgnoreCase("flat")) {
|
||||
type = "FLAT";
|
||||
} 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
|
||||
// to a friendly one, get it from the ENUM!
|
||||
return WorldType.valueOf(type);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link String} into an {@link org.bukkit.World.Environment}.
|
||||
*
|
||||
* @param env The environment as {@link String}
|
||||
* @return The environment as {@link org.bukkit.World.Environment}
|
||||
*/
|
||||
public static World.Environment getEnvFromString(String env) {
|
||||
env = env.toUpperCase();
|
||||
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
|
||||
if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER"))
|
||||
env = "NETHER";
|
||||
|
||||
if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS"))
|
||||
env = "THE_END";
|
||||
|
||||
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
|
||||
env = "NORMAL";
|
||||
|
||||
try {
|
||||
// Now that we've converted a potentially unfriendly value
|
||||
// to a friendly one, get it from the ENUM!
|
||||
return World.Environment.valueOf(env);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
sender.sendMessage(String.format("%sValid World Types are:", ChatColor.YELLOW));
|
||||
sender.sendMessage(String.format("%sNORMAL%s, %sFLAT%s, %sLARGEBIOMES %sor %sAMPLIFIED",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, ChatColor.GOLD));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/******************************************************************************
|
||||
* 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.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.GameRuleProperty;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@CommandAlias("mv")
|
||||
@Subcommand("gamerule")
|
||||
public class GameRuleCommand extends MultiverseCoreCommand {
|
||||
|
||||
public GameRuleCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand("list")
|
||||
@CommandPermission("multiverse.core.gamerule.list")
|
||||
@Syntax("[world] [filter]")
|
||||
@CommandCompletion("@MVWorlds")
|
||||
@Description("See the list gamerules values for a given world.")
|
||||
public void onGameRulesCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World you want to see game rule info.")
|
||||
@Flags("other,defaultself, fallbackself") MultiverseWorld world,
|
||||
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
new ContentDisplay.Builder<Map<String, Object>>()
|
||||
.sender(sender)
|
||||
.header("=== Gamerules for %s%s%s ===", ChatColor.AQUA, world.getName(), ChatColor.WHITE)
|
||||
.contents(getGameRuleMap(world))
|
||||
.displayHandler(DisplayHandlers.INLINE_MAP)
|
||||
.colorTool(ColorAlternator.with(ChatColor.GREEN, ChatColor.GOLD))
|
||||
.setting(DisplaySettings.OPERATOR, ": ")
|
||||
.filter(filter)
|
||||
.display();
|
||||
}
|
||||
|
||||
private Map<String, Object> getGameRuleMap(MultiverseWorld world) {
|
||||
return new HashMap<String, Object>() {{
|
||||
Arrays.stream(GameRule.values())
|
||||
.forEach(gr -> {
|
||||
Object value = world.getCBWorld().getGameRuleValue(gr);
|
||||
if (value != null) {
|
||||
put(gr.getName(), value.toString());
|
||||
}
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
||||
@Subcommand("set")
|
||||
@CommandPermission("multiverse.core.gamerule.set")
|
||||
@Syntax("<rule> <value> [world]")
|
||||
@CommandCompletion("@gameRules @empty @MVWorlds")
|
||||
@Description("Allows a player to set a gamerule for a given world.")
|
||||
public <T> void onGameRuleChangeCommand(@NotNull CommandSender sender,
|
||||
@NotNull Player player,
|
||||
|
||||
@Syntax("<rule> <value>")
|
||||
@Description("Game rule property and value you want to change to.")
|
||||
@NotNull GameRuleProperty<T> property,
|
||||
|
||||
@Syntax("[world]")
|
||||
@Description("World you want to set this game rule.")
|
||||
@NotNull @Flags("other,defaultself") MultiverseWorld world) {
|
||||
|
||||
sender.sendMessage((world.getCBWorld().setGameRule(property.getGameRule(), property.getValue()))
|
||||
|
||||
? String.format("%sSuccess! %sGamerule %s%s%s was set to %s%s%s.",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, property.getGameRule().getName(),
|
||||
ChatColor.WHITE, ChatColor.GREEN, property.getValue(), ChatColor.WHITE)
|
||||
|
||||
: String.format("%sFailure! Gamerule %s%s%s could not be set to %s%s%s.",
|
||||
ChatColor.RED, ChatColor.AQUA, property.getGameRule().getName(),
|
||||
ChatColor.RED, ChatColor.DARK_RED, property.getValue(), ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -1,75 +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.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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 String gameRule = 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.setGameRuleValue(gameRule, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule
|
||||
+ ChatColor.WHITE + " cannot be set to " + ChatColor.RED + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +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.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
|
||||
sender.sendMessage(gameRules.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,54 +7,39 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CoreFlags;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Returns a list of loaded generator plugins.
|
||||
*/
|
||||
public class GeneratorCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class GeneratorCommand extends MultiverseCoreCommand {
|
||||
|
||||
public GeneratorCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Information");
|
||||
this.setCommandUsage("/mv generators");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv generators");
|
||||
this.addKey("mvgenerators");
|
||||
this.addKey("mv gens");
|
||||
this.addKey("mvgens");
|
||||
this.addCommandExample("/mv generators");
|
||||
this.setPermission("multiverse.core.generator", "Returns a list of Loaded Generator Plugins.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
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) {
|
||||
if (p.isEnabled() && p.getDefaultWorldGenerator("world", "") != null) {
|
||||
generators.add(p.getDescription().getName());
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Loaded Generator Plugins ---");
|
||||
String loadedGens = "";
|
||||
boolean altColor = false;
|
||||
for (String s : generators) {
|
||||
loadedGens += (altColor ? ChatColor.YELLOW : ChatColor.WHITE) + s + " ";
|
||||
altColor = !altColor;
|
||||
}
|
||||
if (loadedGens.length() == 0) {
|
||||
loadedGens = ChatColor.RED + "No Generator Plugins found.";
|
||||
}
|
||||
sender.sendMessage(loadedGens);
|
||||
@Subcommand("gens|generators")
|
||||
@CommandPermission("multiverse.core.generator")
|
||||
@Description("Shows a list of Loaded Generator Plugins.")
|
||||
public void onGeneratorCommand(@NotNull CommandSender sender) {
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.header("%s--- Available Generator Plugins ---", ChatColor.GOLD)
|
||||
.contents(CoreFlags.GENERATOR.suggestValue())
|
||||
.emptyMessage("%sYou do not have any generator plugins installed.", ChatColor.RED)
|
||||
.displayHandler(DisplayHandlers.INLINE_LIST)
|
||||
.colorTool(ColorAlternator.with(ChatColor.AQUA, ChatColor.WHITE))
|
||||
.display();
|
||||
}
|
||||
}
|
||||
@@ -1,106 +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 com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Displays a nice help menu.
|
||||
*/
|
||||
public class HelpCommand extends PaginatedCoreCommand<Command> {
|
||||
|
||||
public HelpCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Get Help with Multiverse");
|
||||
this.setCommandUsage("/mv " + ChatColor.GOLD + "[FILTER] [PAGE #]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv");
|
||||
this.addKey("mvh");
|
||||
this.addKey("mvhelp");
|
||||
this.addKey("mv help");
|
||||
this.addKey("mvsearch");
|
||||
this.addKey("mv search");
|
||||
this.addCommandExample("/mv help ?");
|
||||
this.setPermission("multiverse.help", "Displays a nice help menu.", PermissionDefault.TRUE);
|
||||
this.setItemsPerPage(7); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Command> getFilteredItems(List<Command> availableItems, String filter) {
|
||||
List<Command> filtered = new ArrayList<Command>();
|
||||
|
||||
for (Command c : availableItems) {
|
||||
if (stitchThisString(c.getKeyStrings()).matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
} else if (c.getCommandName().matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
} else if (c.getCommandDesc().matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
} else if (c.getCommandUsage().matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
} else {
|
||||
for (String example : c.getCommandExamples()) {
|
||||
if (example.matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemText(Command item) {
|
||||
return ChatColor.AQUA + item.getCommandUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "====[ Multiverse Help ]====");
|
||||
|
||||
FilterObject filterObject = this.getPageAndFilter(args);
|
||||
|
||||
List<Command> availableCommands = new ArrayList<Command>(this.plugin.getCommandHandler().getCommands(sender));
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableCommands = this.getFilteredItems(availableCommands, filterObject.getFilter());
|
||||
if (availableCommands.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No commands matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.AQUA + " Add a '" + ChatColor.DARK_PURPLE + "?" + ChatColor.AQUA + "' after a command to see more about it.");
|
||||
for (Command c : availableCommands) {
|
||||
sender.sendMessage(ChatColor.AQUA + c.getCommandUsage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil(availableCommands.size() / (this.itemsPerPage + 0.0));
|
||||
|
||||
if (filterObject.getPage() > totalPages) {
|
||||
filterObject.setPage(totalPages);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
sender.sendMessage(ChatColor.AQUA + " Add a '" + ChatColor.DARK_PURPLE + "?" + ChatColor.AQUA + "' after a command to see more about it.");
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableCommands);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,165 +7,66 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagGroup;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagResult;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CoreFlags;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import static org.bukkit.World.*;
|
||||
|
||||
/**
|
||||
* Imports a new world of the specified type.
|
||||
*/
|
||||
public class ImportCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class ImportCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ImportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Import World");
|
||||
this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n]");
|
||||
this.setArgRange(1, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.addKey("mvimport");
|
||||
this.addKey("mvim");
|
||||
this.addKey("mv import");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether");
|
||||
this.addCommandExample("To import a world that uses a generator, you'll need the generator:");
|
||||
this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator");
|
||||
this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
this.setFlagGroup(FlagGroup.of(CoreFlags.GENERATOR, CoreFlags.SPAWN_ADJUST));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.toLowerCase().endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (files != null && files.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Subcommand("import")
|
||||
@CommandPermission("multiverse.core.import")
|
||||
@Syntax("<name> <env> -g [generator[:id]] [-n]")
|
||||
@CommandCompletion("@potentialWorlds @environments @flags")
|
||||
@Description("Imports a new world into multiverse.")
|
||||
public void onImportCommand(@NotNull CommandSender sender,
|
||||
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return worldList;
|
||||
}
|
||||
|
||||
private String trimWorldName(String userInput) {
|
||||
// Removes relative paths.
|
||||
return userInput.replaceAll("^[./\\\\]+", "");
|
||||
}
|
||||
@Syntax("<name>")
|
||||
@Description("Folder name of the world.")
|
||||
@NotNull @co.aikar.commands.annotation.Flags("trim") @Conditions("importableWorldName") String worldName,
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
String worldName = trimWorldName(args.get(0));
|
||||
@NotNull
|
||||
@Syntax("<env>")
|
||||
@Description("The world's environment. See: /mv env")
|
||||
Environment environment,
|
||||
|
||||
if (worldName.toLowerCase().equals("--list") || worldName.toLowerCase().equals("-l")) {
|
||||
String worldList = this.getPotentialWorlds();
|
||||
if (worldList.length() > 2) {
|
||||
sender.sendMessage(ChatColor.AQUA + "====[ These look like worlds ]====");
|
||||
sender.sendMessage(worldList);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "No potential worlds found. Sorry!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 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 || worldName.length() < 1) {
|
||||
this.showHelp(sender);
|
||||
return;
|
||||
}
|
||||
@Nullable
|
||||
@Syntax("-g [generator[:id]] [-n]")
|
||||
@Description("Other world settings. See: http://gg.gg/nn8c2")
|
||||
String[] flagsArray) {
|
||||
|
||||
// Make sure we don't already know about this world.
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Multiverse" + ChatColor.WHITE
|
||||
+ " already knows about '" + ChatColor.AQUA + worldName + ChatColor.WHITE + "'!");
|
||||
return;
|
||||
}
|
||||
FlagResult flags = this.getFlagGroup().calculateResult(flagsArray);
|
||||
|
||||
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
|
||||
String generator = CommandHandler.getFlag("-g", args);
|
||||
boolean useSpawnAdjust = true;
|
||||
for (String s : args) {
|
||||
if (s.equalsIgnoreCase("-n")) {
|
||||
useSpawnAdjust = false;
|
||||
}
|
||||
}
|
||||
|
||||
String env = args.get(1);
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!worldFile.exists()) {
|
||||
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);
|
||||
} else if (!checkIfIsWorld(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 {
|
||||
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!");
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName));
|
||||
Command.broadcastCommandMessage(sender, (this.plugin.getMVWorldManager().addWorld(worldName,
|
||||
environment,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
flags.getValue(CoreFlags.GENERATOR),
|
||||
flags.getValue(CoreFlags.SPAWN_ADJUST))
|
||||
)
|
||||
? String.format("%sComplete!", ChatColor.GREEN)
|
||||
: String.format("%sFailed! See console for more details.", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,266 +7,141 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.FancyText;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.FancyColorScheme;
|
||||
import com.onarandombox.MultiverseCore.utils.FancyHeader;
|
||||
import com.onarandombox.MultiverseCore.utils.FancyMessage;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
// Will use when we can compile with JDK 6
|
||||
//import com.sun.xml.internal.ws.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Returns detailed information about a world.
|
||||
*/
|
||||
public class InfoCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class InfoCommand extends MultiverseCoreCommand {
|
||||
|
||||
public InfoCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Information");
|
||||
this.setCommandUsage("/mv info" + ChatColor.GOLD + " [WORLD] [PAGE]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mvinfo");
|
||||
this.addKey("mvi");
|
||||
this.addKey("mv info");
|
||||
this.addCommandExample("/mv info " + ChatColor.GOLD + "1");
|
||||
this.addCommandExample("/mv info " + ChatColor.GOLD + "3");
|
||||
this.setPermission("multiverse.core.info", "Returns detailed information on the world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
String worldName = "";
|
||||
int pageNum = 0;
|
||||
@Subcommand("info")
|
||||
@CommandPermission("multiverse.core.info")
|
||||
@Syntax("[world] [page]")
|
||||
@CommandCompletion("@MVWorlds @range:1-5")
|
||||
@Description("Display detailed information of the world.")
|
||||
public void onInfoCommand(@NotNull CommandSender sender,
|
||||
|
||||
if (args.size() == 0) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
worldName = p.getWorld().getName();
|
||||
} else {
|
||||
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
|
||||
return;
|
||||
}
|
||||
} else if (args.size() == 1) {
|
||||
if (this.worldManager.isMVWorld(args.get(0))) {
|
||||
// then we have a world!
|
||||
worldName = args.get(0);
|
||||
} else if (this.worldManager.getUnloadedWorlds().contains(args.get(0))) {
|
||||
sender.sendMessage("That world exists, but it is unloaded!");
|
||||
sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, args.get(0)));
|
||||
return;
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
worldName = p.getWorld().getName();
|
||||
try {
|
||||
pageNum = Integer.parseInt(args.get(0)) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("That world does not exist.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (args.size() == 2) {
|
||||
worldName = args.get(0);
|
||||
try {
|
||||
pageNum = Integer.parseInt(args.get(1)) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
pageNum = 0;
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World you want to see info.")
|
||||
@Flags("other,defaultself,fallbackself") MultiverseWorld world,
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
showPage(pageNum, sender, this.buildEntireCommand(this.worldManager.getMVWorld(worldName), p));
|
||||
} else if (this.worldManager.getUnloadedWorlds().contains(worldName)) {
|
||||
sender.sendMessage("That world exists, but it is unloaded!");
|
||||
sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, worldName));
|
||||
} else if (this.plugin.getServer().getWorld(worldName) != null) {
|
||||
sender.sendMessage("That world exists, but Multiverse does not know about it!");
|
||||
sender.sendMessage("You can import it with" + ChatColor.AQUA + "/mv import " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}");
|
||||
sender.sendMessage("For available environments type " + ChatColor.GREEN + "/mv env");
|
||||
}
|
||||
@Syntax("[page]")
|
||||
@Description("Info page to display.")
|
||||
@Default("1") int page) {
|
||||
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.contents(buildWorldInfoContent(world))
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
.colorTool(ColorAlternator.with(ChatColor.YELLOW, ChatColor.AQUA)).setting(DisplaySettings.SHOW_PAGE, page)
|
||||
.display();
|
||||
}
|
||||
|
||||
private List<List<FancyText>> buildEntireCommand(MultiverseWorld world, Player p) {
|
||||
List<FancyText> message = new ArrayList<FancyText>();
|
||||
List<List<FancyText>> worldInfo = new ArrayList<List<FancyText>>();
|
||||
private List<String> buildWorldInfoContent(MultiverseWorld world) {
|
||||
List<String> contents = new ArrayList<>(38);
|
||||
|
||||
// Page 1
|
||||
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 Alias: ", world.getColoredWorldString(), colors));
|
||||
message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors));
|
||||
message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors));
|
||||
contents.add(parseHeader("General Info"));
|
||||
contents.add(String.format("World Name: %s%s", ChatColor.WHITE, world.getName()));
|
||||
contents.add(String.format("World Alias: %s%s", ChatColor.WHITE, world.getColoredWorldString()));
|
||||
contents.add(String.format("Game Mode: %s%s", ChatColor.WHITE, world.getGameMode().toString()));
|
||||
contents.add(String.format("Difficulty: %s%s", ChatColor.WHITE, world.getDifficulty().toString()));
|
||||
contents.add(String.format("Spawn Location: %s%s", ChatColor.WHITE, this.plugin.getLocationManipulation().strCoords(world.getSpawnLocation())));
|
||||
contents.add(String.format("World Seed: %s%s", ChatColor.WHITE, world.getSeed()));
|
||||
String priceString = (world.getPrice() == 0)
|
||||
? String.format("%sFREE!", ChatColor.GREEN)
|
||||
: plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency());
|
||||
contents.add(String.format((world.getPrice() >= 0)
|
||||
? "Price to enter this world: %s%s"
|
||||
: "Reward for entering this world: %s%s", ChatColor.WHITE, priceString));
|
||||
World respawnWorld = world.getRespawnToWorld();
|
||||
MultiverseWorld respawn = this.plugin.getMVWorldManager().getMVWorld(respawnWorld);
|
||||
String respawnWorldString = (respawn != null)
|
||||
? respawn.getColoredWorldString()
|
||||
: ChatColor.RED + "!!INVALID!!";
|
||||
contents.add(String.format("Players will respawn in: %s%s", ChatColor.WHITE, respawnWorldString));
|
||||
contents.add(ContentDisplay.LINE_BREAK);
|
||||
|
||||
//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: ", String.valueOf(world.getScaling()), colors));
|
||||
message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors));
|
||||
if (world.getPrice() > 0) {
|
||||
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));
|
||||
}
|
||||
|
||||
if (world.getRespawnToWorld() != null) {
|
||||
MultiverseWorld respawn = this.worldManager.getMVWorld(world.getRespawnToWorld());
|
||||
if (respawn != null) {
|
||||
message.add(new FancyMessage("Players will respawn in: ", respawn.getColoredWorldString(), colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Players will respawn in: ", ChatColor.RED + "!!INVALID!!", colors));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
worldInfo.add(message);
|
||||
// Page 2
|
||||
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("Structures: ", world.getCBWorld().canGenerateStructures() + "", colors));
|
||||
message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors));
|
||||
message.add(new FancyMessage("Keep spawn in memory: ", world.isKeepingSpawnInMemory() + "", colors));
|
||||
message.add(new FancyHeader("PVP Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.isPVPEnabled() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors));
|
||||
worldInfo.add(message);
|
||||
contents.add(parseHeader("More World Settings"));
|
||||
contents.add(String.format("World UID: %s%s", ChatColor.WHITE, world.getCBWorld().getUID()));
|
||||
contents.add(String.format("World Type: %s%s", ChatColor.WHITE, world.getWorldType().toString()));
|
||||
contents.add(String.format("World Scale: %s%s", ChatColor.WHITE, world.getScaling()));
|
||||
contents.add(String.format("Generator: %s%s", ChatColor.WHITE, world.getGenerator()));
|
||||
contents.add(String.format("Structures: %s%s", ChatColor.WHITE, world.getCBWorld().canGenerateStructures()));
|
||||
contents.add(String.format("Weather: %s%s", ChatColor.WHITE, world.isWeatherEnabled()));
|
||||
contents.add(String.format("Players will get hungry: %s%s", ChatColor.WHITE, world.getHunger()));
|
||||
contents.add(String.format("Keep spawn in memory: %s%s", ChatColor.WHITE, world.isKeepingSpawnInMemory()));
|
||||
contents.add(ContentDisplay.LINE_BREAK);
|
||||
|
||||
// Page 3
|
||||
message = new ArrayList<FancyText>();
|
||||
message.add(new FancyHeader("Monster Settings", colors));
|
||||
message.add(new FancyMessage("Multiverse Setting: ", world.canMonstersSpawn() + "", colors));
|
||||
message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors));
|
||||
if (world.getMonsterList().size() > 0) {
|
||||
if (world.canMonstersSpawn()) {
|
||||
message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT "
|
||||
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors));
|
||||
}
|
||||
} else {
|
||||
message.add(new FancyMessage("Monsters that CAN spawn: ", world.canMonstersSpawn() ? "ALL" : "NONE", colors));
|
||||
}
|
||||
worldInfo.add(message);
|
||||
contents.add(parseHeader("PVP Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.isPVPEnabled()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getPVP()));
|
||||
contents.add(ContentDisplay.LINE_BREAK);
|
||||
|
||||
// Page 4
|
||||
message = new ArrayList<FancyText>();
|
||||
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.getAnimalList().size() > 0) {
|
||||
if (world.canAnimalsSpawn()) {
|
||||
message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT "
|
||||
+ ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors));
|
||||
} else {
|
||||
message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getAnimalList()), colors));
|
||||
}
|
||||
} else {
|
||||
message.add(new FancyMessage("Animals that CAN spawn: ", world.canAnimalsSpawn() ? "ALL" : "NONE", colors));
|
||||
}
|
||||
worldInfo.add(message);
|
||||
contents.add(parseHeader("Monster Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canMonstersSpawn()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowMonsters()));
|
||||
contents.add((world.canMonstersSpawn())
|
||||
? String.format("Monsters that %scannot spawn: %s%s", ChatColor.RED, ChatColor.WHITE, toCommaSeparated(world.getMonsterList()))
|
||||
: String.format("Monsters that %scan spawn: %s%s", ChatColor.GREEN, ChatColor.WHITE, toCommaSeparated(world.getMonsterList())));
|
||||
contents.add(ContentDisplay.LINE_BREAK);
|
||||
|
||||
return worldInfo;
|
||||
// Page 5
|
||||
contents.add(parseHeader("Animal Settings"));
|
||||
contents.add(String.format("Multiverse Setting: %s%s", ChatColor.WHITE, world.canAnimalsSpawn()));
|
||||
contents.add(String.format("Bukkit Setting: %s%s", ChatColor.WHITE, world.getCBWorld().getAllowAnimals()));
|
||||
contents.add((world.canAnimalsSpawn())
|
||||
? String.format("Animals that %scannot spawn: %s%s", ChatColor.RED, ChatColor.WHITE, toCommaSeparated(world.getAnimalList()))
|
||||
: String.format("Animals that %scan spawn: %s%s", ChatColor.GREEN, ChatColor.WHITE, toCommaSeparated(world.getAnimalList())));
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
private static String toCommaSeperated(List<String> list) {
|
||||
private String parseHeader(String header) {
|
||||
return String.format("%s===[ %s %s]===", ChatColor.AQUA, header, ChatColor.AQUA);
|
||||
}
|
||||
|
||||
private static String toCommaSeparated(List<String> list) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return "";
|
||||
return ChatColor.GRAY + ChatColor.ITALIC.toString() + "none";
|
||||
}
|
||||
if (list.size() == 1) {
|
||||
return list.get(0);
|
||||
}
|
||||
String result = list.get(0);
|
||||
|
||||
StringBuilder result = new StringBuilder(list.get(0));
|
||||
for (int i = 1; i < list.size() - 1; i++) {
|
||||
result += ", " + list.get(i);
|
||||
result.append(", ").append(list.get(i));
|
||||
}
|
||||
result += " and " + list.get(list.size() - 1);
|
||||
return result;
|
||||
result.append(" and ").append(list.get(list.size() - 1));
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a "positive" or "negative" {@link ChatColor}.
|
||||
*
|
||||
* @param positive Whether this {@link ChatColor} should be "positive".
|
||||
* @return The {@link ChatColor}.
|
||||
*/
|
||||
protected ChatColor getChatColor(boolean positive) {
|
||||
return positive ? ChatColor.GREEN : ChatColor.RED;
|
||||
}
|
||||
|
||||
private static void showPage(int page, CommandSender sender, List<List<FancyText>> doc) {
|
||||
page = page < 0 ? 0 : page;
|
||||
page = page > doc.size() - 1 ? doc.size() - 1 : page;
|
||||
boolean altColor = false;
|
||||
boolean appendedPageNum = false;
|
||||
if (sender instanceof Player) {
|
||||
List<FancyText> list = doc.get(page);
|
||||
for (FancyText fancyT : list) {
|
||||
if (fancyT instanceof FancyMessage) {
|
||||
FancyMessage text = (FancyMessage) fancyT;
|
||||
text.setAltColor(altColor);
|
||||
altColor = !altColor;
|
||||
sender.sendMessage(text.getFancyText());
|
||||
} else if (fancyT instanceof FancyHeader) {
|
||||
FancyHeader text = (FancyHeader) fancyT;
|
||||
if (!appendedPageNum) {
|
||||
text.appendText(ChatColor.DARK_PURPLE + " [ Page " + (page + 1) + " of " + doc.size() + " ]");
|
||||
appendedPageNum = true;
|
||||
}
|
||||
sender.sendMessage(text.getFancyText());
|
||||
altColor = false;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (List<FancyText> list : doc) {
|
||||
for (FancyText fancyT : list) {
|
||||
if (fancyT instanceof FancyMessage) {
|
||||
FancyMessage text = (FancyMessage) fancyT;
|
||||
text.setAltColor(altColor);
|
||||
altColor = !altColor;
|
||||
sender.sendMessage(text.getFancyText());
|
||||
} else {
|
||||
FancyText text = fancyT;
|
||||
if (appendedPageNum) {
|
||||
sender.sendMessage(" ");
|
||||
} else {
|
||||
appendedPageNum = true;
|
||||
}
|
||||
sender.sendMessage(text.getFancyText());
|
||||
altColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,124 +7,96 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Displays a listing of all worlds that a player can enter.
|
||||
*/
|
||||
public class ListCommand extends PaginatedCoreCommand<String> {
|
||||
@CommandAlias("mv")
|
||||
public class ListCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ListCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("World Listing");
|
||||
this.setCommandUsage("/mv list");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mvlist");
|
||||
this.addKey("mvl");
|
||||
this.addKey("mv list");
|
||||
this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP);
|
||||
this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
}
|
||||
|
||||
private List<String> getFancyWorldList(Player p) {
|
||||
List<String> worldList = new ArrayList<String>();
|
||||
for (MultiverseWorld world : this.plugin.getMVWorldManager().getMVWorlds()) {
|
||||
@Subcommand("list")
|
||||
@CommandPermission("multiverse.core.list.worlds")
|
||||
@Syntax("[filter] [page]")
|
||||
@Description("Displays a listing of all worlds that you can enter.")
|
||||
public void onListCommand(@NotNull CommandSender sender,
|
||||
|
||||
if (p != null && (!this.plugin.getMVPerms().canEnterWorld(p, world))) {
|
||||
continue;
|
||||
}
|
||||
@NotNull PageFilter pageFilter) {
|
||||
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.header("%s====[ Multiverse World List ]====", ChatColor.GOLD)
|
||||
.contents(getListContents(sender))
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
.colorTool(ColorAlternator.with(ChatColor.AQUA, ChatColor.GOLD))
|
||||
.setting(DisplaySettings.SHOW_PAGE, pageFilter.getPage())
|
||||
.display();
|
||||
}
|
||||
|
||||
private List<String> getListContents(@NotNull CommandSender sender) {
|
||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
List<String> worldList = new ArrayList<>();
|
||||
|
||||
this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.filter(world -> canSeeWorld(player, world))
|
||||
.map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment()))
|
||||
.sorted()
|
||||
.forEach(worldList::add);
|
||||
|
||||
this.plugin.getMVWorldManager().getUnloadedWorlds().stream()
|
||||
.filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true))
|
||||
.map(world -> ChatColor.GRAY + world + " - UNLOADED")
|
||||
.sorted()
|
||||
.forEach(worldList::add);
|
||||
|
||||
ChatColor color = ChatColor.GOLD;
|
||||
Environment env = world.getEnvironment();
|
||||
if (env == Environment.NETHER) {
|
||||
color = ChatColor.RED;
|
||||
} else if (env == Environment.NORMAL) {
|
||||
color = ChatColor.GREEN;
|
||||
} else if (env == Environment.THE_END) {
|
||||
color = ChatColor.AQUA;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(world.getColoredWorldString()).append(ChatColor.WHITE);
|
||||
builder.append(" - ").append(color).append(world.getEnvironment());
|
||||
if (world.isHidden()) {
|
||||
if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.core.modify", true)) {
|
||||
// Prefix hidden worlds with an "[H]"
|
||||
worldList.add(ChatColor.GRAY + "[H]" + builder.toString());
|
||||
}
|
||||
} else {
|
||||
worldList.add(builder.toString());
|
||||
}
|
||||
}
|
||||
for (String name : this.plugin.getMVWorldManager().getUnloadedWorlds()) {
|
||||
if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + name, true)) {
|
||||
worldList.add(ChatColor.GRAY + name + " - UNLOADED");
|
||||
}
|
||||
}
|
||||
return worldList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFilteredItems(List<String> availableItems, String filter) {
|
||||
List<String> filtered = new ArrayList<String>();
|
||||
|
||||
for (String s : availableItems) {
|
||||
if (s.matches("(?i).*" + filter + ".*")) {
|
||||
filtered.add(s);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
private boolean canSeeWorld(Player player, MultiverseWorld world) {
|
||||
return !world.isHidden()
|
||||
|| player == null
|
||||
|| this.plugin.getMVPerms().hasPermission(player, "multiverse.core.modify", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemText(String item) {
|
||||
return item;
|
||||
private String hiddenText(MultiverseWorld world) {
|
||||
return (world.isHidden()) ? String.format("%s[H] ", ChatColor.GRAY) : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse World List ]====");
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
private String parseColouredEnvironment(World.Environment env) {
|
||||
ChatColor color = ChatColor.GOLD;
|
||||
switch (env) {
|
||||
case NETHER:
|
||||
color = ChatColor.RED;
|
||||
break;
|
||||
case NORMAL:
|
||||
color = ChatColor.GREEN;
|
||||
break;
|
||||
case THE_END:
|
||||
color = ChatColor.AQUA;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
FilterObject filterObject = this.getPageAndFilter(args);
|
||||
|
||||
List<String> availableWorlds = new ArrayList<String>(this.getFancyWorldList(p));
|
||||
if (filterObject.getFilter().length() > 0) {
|
||||
availableWorlds = this.getFilteredItems(availableWorlds, filterObject.getFilter());
|
||||
if (availableWorlds.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE
|
||||
+ "No worlds matched your filter: " + ChatColor.AQUA + filterObject.getFilter());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
for (String c : availableWorlds) {
|
||||
sender.sendMessage(c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int totalPages = (int) Math.ceil(availableWorlds.size() / (this.itemsPerPage + 0.0));
|
||||
|
||||
if (filterObject.getPage() > totalPages) {
|
||||
filterObject.setPage(totalPages);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages);
|
||||
|
||||
this.showPage(filterObject.getPage(), sender, availableWorlds);
|
||||
return color + env.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,36 +7,43 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Loads a world into Multiverse.
|
||||
*/
|
||||
public class LoadCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class LoadCommand extends MultiverseCoreCommand {
|
||||
|
||||
public LoadCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Load World");
|
||||
this.setCommandUsage("/mv load" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvload");
|
||||
this.addKey("mv load");
|
||||
this.addCommandExample("/mv load " + ChatColor.GREEN + "MyUnloadedWorld");
|
||||
this.setPermission("multiverse.core.load", "Loads a world into Multiverse.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.getMVWorldManager().loadWorld(args.get(0))) {
|
||||
Command.broadcastCommandMessage(sender, "Loaded world '" + args.get(0) + "'!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to load world '" + args.get(0) + "'!");
|
||||
@Subcommand("load")
|
||||
@CommandPermission("multiverse.core.load")
|
||||
@Syntax("<world>")
|
||||
@CommandCompletion("@unloadedWorlds")
|
||||
@Description("Loads a world. World must be already in worlds.yml, else please use /mv import.")
|
||||
public void onLoadCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<world>")
|
||||
@Description("Name of world you want to load.")
|
||||
@Flags("type=world name")
|
||||
@Conditions("isUnloadedWorld") String worldName) {
|
||||
|
||||
if (!this.plugin.getMVWorldManager().loadWorld(worldName)) {
|
||||
sender.sendMessage(String.format("Error trying to load world '%s'!", worldName));
|
||||
return;
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, String.format("Loaded world '%s'!", worldName));
|
||||
}
|
||||
}
|
||||
@@ -1,95 +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 com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// This will contain all the properties that support the ADD/REMOVE
|
||||
// Anything not in here will only support the SET action
|
||||
|
||||
/**
|
||||
* Used to modify various aspects of worlds.
|
||||
*/
|
||||
public class ModifyAddCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifyAddCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World (Add a value)");
|
||||
this.setCommandUsage("/mv modify " + ChatColor.GREEN + "add {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] ");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mvm add");
|
||||
this.addKey("mvmadd");
|
||||
this.addKey("mv modify add");
|
||||
this.addKey("mvmodify add");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist");
|
||||
this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
|
||||
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "From the console, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String value = args.get(0);
|
||||
String property = args.get(1);
|
||||
|
||||
if (args.size() == 2) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
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: https://goo.gl/OMGwzx");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO fix this
|
||||
if (world.addToVariable(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA
|
||||
+ value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property);
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(value + " could not be added to " + property);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +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 com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Removes all values from a world-property.
|
||||
*/
|
||||
public class ModifyClearCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifyClearCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World (Clear a property)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " clear {PROPERTY}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvm clear");
|
||||
this.addKey("mvmclear");
|
||||
this.addKey("mv modify clear");
|
||||
this.addKey("mvmodify clear");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "animals");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "monsters");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "worldblacklist");
|
||||
this.setPermission("multiverse.core.modify.clear",
|
||||
"Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
if (args.size() == 1 && p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "From the console, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String property = args.get(0);
|
||||
|
||||
if (args.size() == 1) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(1));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
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: https://goo.gl/q1h01S");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
if (world.clearList(property)) {
|
||||
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was "
|
||||
+ ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now.");
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property
|
||||
+ ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,70 +7,228 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to modify various aspects of worlds.
|
||||
*/
|
||||
public class ModifyCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
@Subcommand("modify")
|
||||
//TODO API: Think why properties method for MultiverseWorld is deprecated.
|
||||
public class ModifyCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ModifyCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " {set|add|remove|clear} ...");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mvm");
|
||||
this.addKey("mvmodify");
|
||||
this.addKey("mv modify");
|
||||
Map<String, Boolean> children = new HashMap<String, Boolean>();
|
||||
children.put("multiverse.core.modify.add", true);
|
||||
children.put("multiverse.core.modify.modify", true);
|
||||
children.put("multiverse.core.modify.clear", true);
|
||||
children.put("multiverse.core.modify.remove", true);
|
||||
Permission modify = new Permission("multiverse.core.modify",
|
||||
"Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children);
|
||||
this.addCommandExample(ChatColor.AQUA + "/mv modify set ?");
|
||||
this.addCommandExample(ChatColor.GREEN + "/mv modify add ?");
|
||||
this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?");
|
||||
this.addCommandExample(ChatColor.RED + "/mv modify remove ?");
|
||||
this.setPermission(modify);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the specified action.
|
||||
*
|
||||
* @param action The {@link Action}.
|
||||
* @param property The property.
|
||||
* @return Whether this action is valid.
|
||||
*/
|
||||
protected static boolean validateAction(Action action, String property) {
|
||||
if (action != Action.Set) {
|
||||
try {
|
||||
AddProperties.valueOf(property);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
@Subcommand("set")
|
||||
@CommandPermission("multiverse.core.modify.set")
|
||||
@Syntax("<property> <value> [world]")
|
||||
@CommandCompletion("@setProperties @empty @MVWorlds")
|
||||
@Description("Modify various aspects of worlds by setting a property. For more info; https://tinyurl.com/nehhzp6")
|
||||
public void onModifySetCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<property>")
|
||||
@Description("Property option key.")
|
||||
@Flags("type=property")
|
||||
@Conditions("validAddProperty:set") String property,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<value>")
|
||||
@Description("New property value.")
|
||||
@Flags("type=property value") String value,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World that you want property change to apply.")
|
||||
@Flags("other,defaultself") MultiverseWorld world) {
|
||||
|
||||
if ((property.equalsIgnoreCase("aliascolor")
|
||||
|| property.equalsIgnoreCase("color"))
|
||||
&& !EnglishChatColor.isValidAliasColor(value)) {
|
||||
sender.sendMessage(String.format("%s'%s' is not a valid color. Please pick one of the following:",
|
||||
ChatColor.RED, value));
|
||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!world.setPropertyValue(property, value)) {
|
||||
sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property));
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
catch (PropertyDoesNotExistException e) {
|
||||
sender.sendMessage(String.format("%sSorry, You can't set '%s%s%s'!", ChatColor.RED, ChatColor.GRAY, property, ChatColor.RED));
|
||||
sender.sendMessage(String.format("Valid world-properties: %s", world.getAllPropertyNames()));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%sSuccess! %sProperty %s%s %swas set to %s%s%s.",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, property, ChatColor.WHITE, ChatColor.GREEN, value, ChatColor.WHITE));
|
||||
saveWorldConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// This is just a place holder. The real commands are in:
|
||||
// ModifyAddCommand
|
||||
// ModifyRemoveCommand
|
||||
// ModifySetCommand
|
||||
// ModifyClearCommand
|
||||
@Subcommand("add")
|
||||
@CommandPermission("multiverse.core.modify.add")
|
||||
@Syntax("<property> <value> [world]")
|
||||
@CommandCompletion("@addProperties @empty @MVWorlds")
|
||||
@Description("Modify various aspects of worlds by adding a property. For more info: https://tinyurl.com/nehhzp6")
|
||||
public void onModifyAddCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<property>")
|
||||
@Description("Property option key.")
|
||||
@Flags("type=property")
|
||||
@Conditions("validAddProperty:add") String property,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<value>")
|
||||
@Description("Property value to add.")
|
||||
@Flags("type=property value") String value,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World that you want property change to apply.")
|
||||
@Flags("other,defaultself") MultiverseWorld world) {
|
||||
|
||||
if (!world.addToVariable(property, value)) {
|
||||
sender.sendMessage(String.format("%s %scould not be added to %s%s%s.",
|
||||
value, ChatColor.RED, ChatColor.AQUA, property, ChatColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%sSuccess! %s%s%s was added to %s%s%s.",
|
||||
ChatColor.GREEN, ChatColor.AQUA, value, ChatColor.WHITE, ChatColor.GREEN, property, ChatColor.WHITE));
|
||||
|
||||
saveWorldConfig();
|
||||
}
|
||||
|
||||
@Subcommand("remove")
|
||||
@CommandPermission("multiverse.core.modify.remove")
|
||||
@Syntax("<property> <value> [world]")
|
||||
@CommandCompletion("@addProperties @empty @MVWorlds")
|
||||
@Description("Modify various aspects of worlds by removing a property. For more info: https://tinyurl.com/nehhzp6")
|
||||
public void onModifyRemoveCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<property>")
|
||||
@Description("Property option key.")
|
||||
@Flags("type=property")
|
||||
@Conditions("validAddProperty:remove") String property,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<value>")
|
||||
@Description("Property value to remove.")
|
||||
@Flags("type=property value") String value,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World that you want property change to apply.")
|
||||
@Flags("other,defaultself") MultiverseWorld world) {
|
||||
|
||||
if (!world.removeFromVariable(property, value)) {
|
||||
sender.sendMessage(String.format("%sThere was an error removing %s%s%s from %s%s%s!",
|
||||
ChatColor.RED, ChatColor.GRAY, value, ChatColor.RED, ChatColor.GRAY, property, ChatColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%sSuccess! %s%s%s was %sremoved %sfrom %s%s%s.",
|
||||
ChatColor.GREEN, ChatColor.AQUA, value, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, ChatColor.GREEN, property, ChatColor.WHITE));
|
||||
|
||||
saveWorldConfig();
|
||||
}
|
||||
|
||||
@Subcommand("clear")
|
||||
@CommandPermission("multiverse.core.modify.clear")
|
||||
@Syntax("<property> <value> [world]")
|
||||
@CommandCompletion("@addProperties @empty @MVWorlds")
|
||||
@Description("Modify various aspects of worlds by clearing a property. For more info: https://tinyurl.com/nehhzp6")
|
||||
public void onModifyClearCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<property>")
|
||||
@Description("Property option key.")
|
||||
@Flags("type=property") @Conditions("validAddProperty:clear") String property,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World that you want property be cleared.")
|
||||
@Flags("other,defaultself") MultiverseWorld world) {
|
||||
|
||||
if (!world.clearList(property)) {
|
||||
sender.sendMessage(String.format("%sThere was an error clearing %s%s%s.",
|
||||
ChatColor.RED, ChatColor.GOLD, property, ChatColor.RED));
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%s%s%s was cleared. It contains 0 values now.",
|
||||
ChatColor.GOLD, property, ChatColor.WHITE));
|
||||
|
||||
saveWorldConfig();
|
||||
}
|
||||
|
||||
@Subcommand("list")
|
||||
@CommandPermission("multiverse.core.modify.list")
|
||||
@Syntax("[world] [filter]")
|
||||
@CommandCompletion("@MVWorlds")
|
||||
@Description("Show properties available to set.")
|
||||
public void onModifyListCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World that you want to see current property values set.")
|
||||
@Flags("other,defaultself,fallbackself") MultiverseWorld world,
|
||||
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
new ContentDisplay.Builder<Map<String, Object>>()
|
||||
.sender(sender)
|
||||
.header("%s===[ Property Values for %s%s ]===", ChatColor.GOLD, world.getColoredWorldString(), ChatColor.GOLD)
|
||||
.contents(generateModifyList(world))
|
||||
.emptyMessage("No properties found.")
|
||||
.displayHandler(DisplayHandlers.INLINE_MAP)
|
||||
.filter(filter)
|
||||
.display();
|
||||
}
|
||||
|
||||
private Map<String, Object> generateModifyList(MultiverseWorld world) {
|
||||
Collection<String> properties = world.getAllPropertyTypes();
|
||||
Map<String, Object> propMap = new HashMap<>(properties.size());
|
||||
for (String property : properties) {
|
||||
String value;
|
||||
try {
|
||||
value = world.getPropertyValue(property);
|
||||
} catch (PropertyDoesNotExistException ignored) {
|
||||
value = String.format("%s!!INAVLID!!", ChatColor.RED);
|
||||
}
|
||||
propMap.put(property, value);
|
||||
}
|
||||
return propMap;
|
||||
}
|
||||
|
||||
private void saveWorldConfig() {
|
||||
if (!this.plugin.saveWorldConfig()) {
|
||||
throw new InvalidCommandArgument("There was an issue saving worlds.yml! Your changes will only be temporary.", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +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 com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.Action;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Removes values from a world-property.
|
||||
*/
|
||||
public class ModifyRemoveCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifyRemoveCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Modify a World (Remove a value)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " remove {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(2, 3);
|
||||
this.addKey("mvm remove");
|
||||
this.addKey("mvmremove");
|
||||
this.addKey("mv modify remove");
|
||||
this.addKey("mvmodify remove");
|
||||
this.addKey("mvm delete");
|
||||
this.addKey("mvmdelete");
|
||||
this.addKey("mv modify delete");
|
||||
this.addKey("mvmodify delete");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist");
|
||||
this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
|
||||
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.size() == 2 && p == null) {
|
||||
sender.sendMessage(ChatColor.RED + "From the console, WORLD is required.");
|
||||
sender.sendMessage(this.getCommandDesc());
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String value = args.get(0);
|
||||
String property = args.get(1);
|
||||
|
||||
if (args.size() == 2) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
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: https://goo.gl/OMGwzx");
|
||||
return;
|
||||
}
|
||||
// TODO fix this
|
||||
if (world.removeFromVariable(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE
|
||||
+ " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property);
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY
|
||||
+ value + ChatColor.WHITE + " from " + ChatColor.GOLD + property);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +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 com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to set world-properties.
|
||||
*/
|
||||
public class ModifySetCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
|
||||
public ModifySetCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
this.setName("Modify a World (Set a value)");
|
||||
this.setCommandUsage("/mv modify" + ChatColor.GREEN + " set {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]");
|
||||
this.setArgRange(1, 3);
|
||||
this.addKey("mvm set");
|
||||
this.addKey("mvmset");
|
||||
this.addKey("mv modify set");
|
||||
this.addKey("mvmodify set");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "mode " + ChatColor.RED + "creative");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "animals " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "monsters " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "alias " + ChatColor.RED + "MyWorld");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "color " + ChatColor.RED + "green");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "curr " + ChatColor.RED + "3");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "price " + ChatColor.RED + "5");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "scale " + ChatColor.RED + "1.2");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "memory " + ChatColor.RED + "true");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "diff " + ChatColor.RED + "hard");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hunger " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hidden " + ChatColor.RED + "true");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "pvp " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false");
|
||||
this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn");
|
||||
this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. "
|
||||
+ "If you do not include a world, the current world will be used.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// Special case for spawn:
|
||||
if (args.size() == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You must be a player to set the" + ChatColor.GREEN + " spawn");
|
||||
return;
|
||||
}
|
||||
if (args.get(0).equalsIgnoreCase("spawn")) {
|
||||
SetSpawnCommand c = new SetSpawnCommand(this.plugin);
|
||||
c.setWorldSpawn(sender);
|
||||
|
||||
} else {
|
||||
sender.sendMessage("Spawn is the only param with no" + ChatColor.GREEN + " VALUE");
|
||||
sender.sendMessage("Type " + ChatColor.GREEN + "/mv modify ?" + ChatColor.WHITE + " For help.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
String value = args.get(1);
|
||||
String property = args.get(0);
|
||||
|
||||
if (args.size() == 2) {
|
||||
world = this.worldManager.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.worldManager.getMVWorld(args.get(2));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !EnglishChatColor.isValidAliasColor(value)) {
|
||||
sender.sendMessage(value + " is not a valid color. Please pick one of the following:");
|
||||
sender.sendMessage(EnglishChatColor.getAllColors());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (world.setPropertyValue(property, value)) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property
|
||||
+ ChatColor.WHITE + " was set to " + ChatColor.GREEN + value);
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property));
|
||||
}
|
||||
} catch (PropertyDoesNotExistException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'");
|
||||
sender.sendMessage("Valid world-properties: " + world.getAllPropertyNames());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +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 com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A generic Multiverse-command.
|
||||
*/
|
||||
public abstract class MultiverseCommand extends Command {
|
||||
|
||||
/**
|
||||
* The reference to the core.
|
||||
*/
|
||||
protected MultiverseCore plugin;
|
||||
/**
|
||||
* The reference to {@link MultiverseMessaging}.
|
||||
*/
|
||||
protected MultiverseMessaging messaging;
|
||||
|
||||
public MultiverseCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
this.messaging = this.plugin.getMessaging();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void runCommand(CommandSender sender, List<String> args);
|
||||
|
||||
}
|
||||
+6
-12
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -8,19 +8,13 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
|
||||
/**
|
||||
* A generic paginated Multiverse-command.
|
||||
* @param <T> The type of items on the page.
|
||||
*/
|
||||
public abstract class PaginatedCoreCommand<T> extends PaginatedCommand<T> {
|
||||
/**
|
||||
* The reference to the core.
|
||||
*/
|
||||
protected MultiverseCore plugin;
|
||||
public abstract class MultiverseCoreCommand extends MultiverseCommand {
|
||||
|
||||
public PaginatedCoreCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
protected final MultiverseCore plugin;
|
||||
|
||||
protected MultiverseCoreCommand(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
@@ -1,164 +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.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A generic paginated command.
|
||||
* @param <T> The type of items on the page.
|
||||
*/
|
||||
public abstract class PaginatedCommand<T> extends Command {
|
||||
private static final int DEFAULT_ITEMS_PER_PAGE = 9;
|
||||
/**
|
||||
* The number of items per page.
|
||||
*/
|
||||
protected int itemsPerPage = DEFAULT_ITEMS_PER_PAGE;
|
||||
|
||||
public PaginatedCommand(JavaPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of items per page.
|
||||
*
|
||||
* @param items The new number of items per page.
|
||||
*/
|
||||
protected void setItemsPerPage(int items) {
|
||||
itemsPerPage = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets filtered items.
|
||||
* @param availableItems All available items.
|
||||
* @param filter The filter-{@link String}.
|
||||
* @return A list of items that match the filter.
|
||||
*/
|
||||
protected abstract List<T> getFilteredItems(List<T> availableItems, String filter);
|
||||
|
||||
/**
|
||||
* Constructs a single string from a list of strings.
|
||||
*
|
||||
* @param list The {@link List} of strings.
|
||||
* @return A single {@link String}.
|
||||
*/
|
||||
protected String stitchThisString(List<String> list) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : list) {
|
||||
builder.append(s);
|
||||
builder.append(' ');
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a page.
|
||||
*
|
||||
* @param page The number of the page to show.
|
||||
* @param sender The {@link CommandSender} that wants to see the page.
|
||||
* @param cmds The items that should be displayed on the page.
|
||||
*/
|
||||
protected void showPage(int page, CommandSender sender, List<T> cmds) {
|
||||
// Ensure the page is at least 1.
|
||||
page = (page <= 0) ? 1 : page;
|
||||
int start = (page - 1) * itemsPerPage;
|
||||
int end = start + itemsPerPage;
|
||||
|
||||
for (int i = start; i < end; i++) {
|
||||
// For consistancy, print some extra lines if it's a player:
|
||||
if (i < cmds.size()) {
|
||||
sender.sendMessage(this.getItemText(cmds.get(i)));
|
||||
} else if (sender instanceof Player) {
|
||||
sender.sendMessage(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an item into a string.
|
||||
*
|
||||
* @param item The item.
|
||||
* @return A {@link String}.
|
||||
*/
|
||||
protected abstract String getItemText(T item);
|
||||
|
||||
/**
|
||||
* Constructs a {@link FilterObject} from a {@link List} of arguments.
|
||||
*
|
||||
* @param args The {@link List} of arguments.
|
||||
* @return The {@link FilterObject}.
|
||||
*/
|
||||
protected FilterObject getPageAndFilter(List<String> args) {
|
||||
int page = 1;
|
||||
|
||||
String filter = "";
|
||||
|
||||
if (args.size() == 0) {
|
||||
filter = "";
|
||||
page = 1;
|
||||
} else if (args.size() == 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ex) {
|
||||
filter = args.get(0);
|
||||
page = 1;
|
||||
}
|
||||
} else if (args.size() == 2) {
|
||||
filter = args.get(0);
|
||||
try {
|
||||
page = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException ex) {
|
||||
page = 1;
|
||||
}
|
||||
}
|
||||
return new FilterObject(page, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Key-Object" containing information about the page and the filter that were requested.
|
||||
*/
|
||||
protected class FilterObject {
|
||||
private Integer page;
|
||||
private String filter;
|
||||
|
||||
public FilterObject(Integer page, String filter) {
|
||||
this.page = page;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page.
|
||||
* @return The page.
|
||||
*/
|
||||
public Integer getPage() {
|
||||
return this.page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page.
|
||||
*
|
||||
* @param page The new page.
|
||||
*/
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter.
|
||||
* @return The filter.
|
||||
*/
|
||||
public String getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,86 +7,77 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Split;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Removes a type of mob from a world.
|
||||
*/
|
||||
public class PurgeCommand extends MultiverseCommand {
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class PurgeCommand extends MultiverseCoreCommand {
|
||||
|
||||
public PurgeCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Purge World of Creatures");
|
||||
this.setCommandUsage("/mv purge" + ChatColor.GOLD + " [WORLD|all] " + ChatColor.GREEN + "{all|animals|monsters|MOBNAME}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvpurge");
|
||||
this.addKey("mv purge");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GREEN + "all");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "all " + ChatColor.GREEN + "all");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GREEN + "monsters");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "all " + ChatColor.GREEN + "animals");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "MyWorld " + ChatColor.GREEN + "squid");
|
||||
this.addCommandExample("/mv purge " + ChatColor.GOLD + "MyWorld_nether " + ChatColor.GREEN + "ghast");
|
||||
this.setPermission("multiverse.core.purge", "Removed the specified type of mob from the specified world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
if (args.size() == 1 && p == null) {
|
||||
sender.sendMessage("This command requires a WORLD when being run from the console!");
|
||||
sender.sendMessage(this.getCommandUsage());
|
||||
return;
|
||||
}
|
||||
String worldName = null;
|
||||
String deathName = null;
|
||||
if (args.size() == 1) {
|
||||
worldName = p.getWorld().getName();
|
||||
deathName = args.get(0);
|
||||
} else {
|
||||
worldName = args.get(0);
|
||||
deathName = args.get(1);
|
||||
}
|
||||
@Subcommand("purgeall")
|
||||
@CommandPermission("multiverse.core.purge.all")
|
||||
@Syntax("<all|animals|monsters|mobname>")
|
||||
@CommandCompletion("all|animals|monsters|@livingEntities")
|
||||
@Description("Removed the specified type of mob from all worlds.")
|
||||
public void onPurgeAllCommand(@NotNull CommandSender sender,
|
||||
|
||||
if (!worldName.equalsIgnoreCase("all") && !this.worldManager.isMVWorld(worldName)) {
|
||||
this.plugin.showNotMVWorldMessage(sender, worldName);
|
||||
sender.sendMessage("It cannot be purged.");
|
||||
return;
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("<entities>")
|
||||
@Description("Entity types that you want to remove from all worlds.")
|
||||
@Split(",") String[] targetEntities) {
|
||||
|
||||
List<MultiverseWorld> worldsToRemoveEntitiesFrom = new ArrayList<MultiverseWorld>();
|
||||
// Handle all case any user who names a world "all" should know better...
|
||||
if (worldName.equalsIgnoreCase("all")) {
|
||||
worldsToRemoveEntitiesFrom.addAll(this.worldManager.getMVWorlds());
|
||||
} else {
|
||||
worldsToRemoveEntitiesFrom.add(this.worldManager.getMVWorld(worldName));
|
||||
}
|
||||
doPurge(sender, this.plugin.getMVWorldManager().getMVWorlds(), targetEntities);
|
||||
}
|
||||
|
||||
WorldPurger purger = this.worldManager.getTheWorldPurger();
|
||||
ArrayList<String> thingsToKill = new ArrayList<String>();
|
||||
if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) {
|
||||
thingsToKill.add(deathName.toUpperCase());
|
||||
} else {
|
||||
Collections.addAll(thingsToKill, deathName.toUpperCase().split(","));
|
||||
}
|
||||
for (MultiverseWorld w : worldsToRemoveEntitiesFrom) {
|
||||
purger.purgeWorld(w, thingsToKill, false, false, sender);
|
||||
}
|
||||
@Subcommand("purge")
|
||||
@CommandPermission("multiverse.core.purge")
|
||||
@Syntax("<all|animals|monsters|mobname>")
|
||||
@CommandCompletion("@MVWorlds|all|animals|monsters|@livingEntities all|animals|monsters|@livingEntities")
|
||||
@Description("Removed the specified type of mob from the specified world.")
|
||||
public void onPurgeCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World that you want to remove entities.")
|
||||
@Flags("other,defaultself,fallbackself") MultiverseWorld world,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<entities>")
|
||||
@Description("Entity types that you want to remove from a world.")
|
||||
@Split(",") String[] targetEntities) {
|
||||
|
||||
doPurge(sender, Collections.singleton(world), targetEntities);
|
||||
}
|
||||
|
||||
private void doPurge(@NotNull CommandSender sender,
|
||||
@NotNull Collection<MultiverseWorld> targetWorlds,
|
||||
@NotNull String[] targetEntities) {
|
||||
|
||||
List<String> thingsToKill = Arrays.stream(targetEntities)
|
||||
.map(String::toUpperCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
targetWorlds.forEach(w -> this.plugin.getMVWorldManager()
|
||||
.getTheWorldPurger()
|
||||
.purgeWorld(w, thingsToKill, false, false, sender));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,47 +7,75 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagGroup;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagResult;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CoreFlags;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Regenerates a world.
|
||||
*/
|
||||
public class RegenCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class RegenCommand extends MultiverseCoreCommand {
|
||||
|
||||
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.addKey("mvregen");
|
||||
this.addKey("mv regen");
|
||||
this.addCommandExample("You can use the -s with no args to get a new seed:");
|
||||
this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s");
|
||||
this.addCommandExample("or specifiy a seed to get that one:");
|
||||
this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s" + ChatColor.AQUA + " gargamel");
|
||||
this.setPermission("multiverse.core.regen", "Regenerates a world on your server. The previous state will be lost "
|
||||
+ ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP);
|
||||
this.setFlagGroup(FlagGroup.of(CoreFlags.RANDOM_SEED));
|
||||
}
|
||||
|
||||
@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 seed = (args.size() == 3) ? args.get(2) : "";
|
||||
@Subcommand("regen")
|
||||
@CommandPermission("multiverse.core.regen")
|
||||
@Syntax("<world> [-s [seed]]")
|
||||
@CommandCompletion("@MVWorlds @worldFlags:-s")
|
||||
@Description("Regenerates a world on your server. The previous state will be lost PERMANENTLY.")
|
||||
public void onRegenCommand(@NotNull CommandSender sender,
|
||||
|
||||
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!");
|
||||
@NotNull
|
||||
@Syntax("<world>")
|
||||
@Description("World that you want to regen.")
|
||||
@Flags("other") MultiverseWorld world,
|
||||
|
||||
@Nullable
|
||||
@Syntax("[-s [seed]]")
|
||||
@Description("Other world settings. See: http://gg.gg/nn8lk")
|
||||
String[] flagsArray) {
|
||||
|
||||
FlagResult flags = this.getFlagGroup().calculateResult(flagsArray);
|
||||
|
||||
this.plugin.getMVCommandManager().getQueueManager().addToQueue(new QueuedCommand.Builder()
|
||||
.sender(sender)
|
||||
.action(regenRunnable(sender, world, flags))
|
||||
.prompt("Are you sure you want to regen world '%s'?", world.getColoredWorldString())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private Runnable regenRunnable(@NotNull CommandSender sender,
|
||||
@NotNull MultiverseWorld world,
|
||||
@NotNull FlagResult flags) {
|
||||
|
||||
return () -> {
|
||||
sender.sendMessage(String.format("Regening world '%s'...", world.getName()));
|
||||
|
||||
//TODO: API should allow regen of unloaded worlds.
|
||||
sender.sendMessage((this.plugin.getMVWorldManager().regenWorld(
|
||||
world.getName(),
|
||||
!flags.isDefaulted(CoreFlags.RANDOM_SEED),
|
||||
!flags.isByUserInput(CoreFlags.RANDOM_SEED),
|
||||
flags.getValue(CoreFlags.RANDOM_SEED))
|
||||
)
|
||||
? String.format("%sWorld Regenerated!", ChatColor.GREEN)
|
||||
: String.format("%sWorld could not be regenerated!", ChatColor.RED));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,51 +7,44 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Reloads worlds.yml and config.yml.
|
||||
*/
|
||||
public class ReloadCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class ReloadCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ReloadCommand(MultiverseCore plugin) {
|
||||
public ReloadCommand(@NotNull MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Reload Configs");
|
||||
this.setCommandUsage("/mv reload");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mvreload");
|
||||
this.addKey("mv reload");
|
||||
this.addCommandExample("/mv reload");
|
||||
this.setPermission("multiverse.core.reload", "Reloads worlds.yml and config.yml.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
@Subcommand("reload")
|
||||
@CommandPermission("multiverse.core.reload")
|
||||
@Description("Reloads config files for all multiverse modules.")
|
||||
public void onReloadCommand(@NotNull CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Reloading all Multiverse Plugin configs...");
|
||||
this.plugin.loadConfigs();
|
||||
this.plugin.getAnchorManager().loadAnchors();
|
||||
this.plugin.getMVWorldManager().loadWorlds(true);
|
||||
|
||||
List<String> configsLoaded = new ArrayList<String>();
|
||||
List<String> configsLoaded = new ArrayList<>();
|
||||
configsLoaded.add("Multiverse-Core - config.yml");
|
||||
configsLoaded.add("Multiverse-Core - worlds.yml");
|
||||
configsLoaded.add("Multiverse-Core - anchors.yml");
|
||||
// Create the event
|
||||
|
||||
MVConfigReloadEvent configReload = new MVConfigReloadEvent(configsLoaded);
|
||||
// Fire it off
|
||||
this.plugin.getServer().getPluginManager().callEvent(configReload);
|
||||
for (String s : configReload.getAllConfigsLoaded()) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Reload Complete!");
|
||||
configReload.getAllConfigsLoaded().forEach(sender::sendMessage);
|
||||
sender.sendMessage(String.format("%sReload Complete!", ChatColor.GREEN));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,36 +7,43 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unloads a world and removes it from the config.
|
||||
*/
|
||||
public class RemoveCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class RemoveCommand extends MultiverseCoreCommand {
|
||||
|
||||
public RemoveCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Remove World");
|
||||
this.setCommandUsage("/mv remove" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvremove");
|
||||
this.addKey("mv remove");
|
||||
this.addCommandExample("/mv remove " + ChatColor.GREEN + "MyWorld");
|
||||
this.setPermission("multiverse.core.remove",
|
||||
"Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.getMVWorldManager().removeWorldFromConfig(args.get(0))) {
|
||||
sender.sendMessage("World removed from config!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to remove world from config!");
|
||||
}
|
||||
@Subcommand("remove")
|
||||
@CommandPermission("multiverse.core.remove")
|
||||
@CommandCompletion("@MVWorlds|@unloadedWorlds")
|
||||
@Syntax("<world>")
|
||||
@Description("Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.")
|
||||
public void onRemoveCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<world>")
|
||||
@Description("World you want to remove from mv's knowledge.")
|
||||
@Flags("type=world name")
|
||||
@Conditions("isWorldInConfig")
|
||||
@Single String worldName) {
|
||||
|
||||
sender.sendMessage((this.plugin.getMVWorldManager().removeWorldFromConfig(worldName))
|
||||
? String.format("World '%s' is removed from config!", worldName)
|
||||
: String.format("%sError trying to remove world from config!", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RootCommand extends MultiverseCoreCommand {
|
||||
|
||||
public RootCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@CommandAlias("mv")
|
||||
public void onRootCommand(@NotNull CommandSender sender) {
|
||||
this.plugin.getMVCommandManager().showPluginInfo(
|
||||
sender,
|
||||
this.plugin.getDescription(),
|
||||
ColorAlternator.with(ChatColor.GOLD, ChatColor.YELLOW),
|
||||
"mv"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,48 +7,57 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import buscript.Buscript;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.RequiredPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* States who is in what world.
|
||||
*/
|
||||
public class ScriptCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class ScriptCommand extends MultiverseCoreCommand {
|
||||
|
||||
public ScriptCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Runs a script.");
|
||||
this.setCommandUsage("/mv script" + ChatColor.GOLD + " {script} [target]");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mv script");
|
||||
this.addKey("mvscript");
|
||||
this.addCommandExample(String.format("/mv script %sscript.txt", ChatColor.GOLD));
|
||||
this.addCommandExample(String.format("/mv script %stest.txt %ssomeplayer", ChatColor.GOLD, ChatColor.GREEN));
|
||||
this.setPermission("multiverse.core.script", "Runs a script.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0));
|
||||
@Subcommand("script")
|
||||
@CommandPermission("multiverse.core.script")
|
||||
@Syntax("<script> <player>")
|
||||
@CommandCompletion("@scripts @players")
|
||||
@Description("Runs a script.")
|
||||
public void onScriptCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<script>")
|
||||
@Description("Script name that you want to run.")
|
||||
String targetScript,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<player>")
|
||||
@Description("Player that you want to execute the script on.")
|
||||
RequiredPlayer player) {
|
||||
|
||||
Buscript scriptAPI = this.plugin.getScriptAPI();
|
||||
if (scriptAPI == null) {
|
||||
throw new InvalidCommandArgument("Buscript failed to load while server was starting! Scripts cannot be run.", false);
|
||||
}
|
||||
|
||||
File file = new File(scriptAPI.getScriptFolder(), targetScript);
|
||||
if (!file.exists()) {
|
||||
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
|
||||
return;
|
||||
throw new InvalidCommandArgument("That script file does not exist in the Multiverse-Core scripts directory!");
|
||||
}
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
String target = null;
|
||||
if (args.size() == 2) {
|
||||
target = args.get(1);
|
||||
}
|
||||
plugin.getScriptAPI().executeScript(file, target, player);
|
||||
|
||||
scriptAPI.executeScript(file, targetScript, player.get());
|
||||
sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,6 +7,16 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.BlockSafety;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
@@ -15,133 +25,146 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
public class SetSpawnCommand extends MultiverseCoreCommand {
|
||||
|
||||
/**
|
||||
* Sets the spawn for a world.
|
||||
*/
|
||||
public class SetSpawnCommand extends MultiverseCommand {
|
||||
public SetSpawnCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Set World Spawn");
|
||||
this.setCommandUsage("/mv setspawn");
|
||||
this.setArgRange(0, 6);
|
||||
this.addKey("mvsetspawn");
|
||||
this.addKey("mvss");
|
||||
this.addKey("mv set spawn");
|
||||
this.addKey("mv setspawn");
|
||||
this.addKey("mvset spawn");
|
||||
this.addCommandExample("/mv set spawn");
|
||||
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) {
|
||||
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!");
|
||||
@CommandAlias("mv")
|
||||
public class SetSpawn extends BaseCommand {
|
||||
|
||||
@Subcommand("setspawn")
|
||||
@CommandPermission("multiverse.core.spawn.set")
|
||||
@Syntax("[world x y z [yaw pitch]]")
|
||||
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch")
|
||||
@Description("Sets the spawn for the current world.")
|
||||
public void onSetSpawnCommand(@NotNull CommandSender sender,
|
||||
@Nullable @Optional Player player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world x y z [yaw pitch]]")
|
||||
@Description("New location of spawn.")
|
||||
@Flags("other,defaultself") MultiverseWorld world,
|
||||
|
||||
@Nullable @Optional Double x,
|
||||
@Nullable @Optional Double y,
|
||||
@Nullable @Optional Double z,
|
||||
@Nullable @Optional Float yaw,
|
||||
@Nullable @Optional Float pitch) {
|
||||
|
||||
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
|
||||
}
|
||||
|
||||
@Subcommand("modify set spawn")
|
||||
@CommandPermission("multiverse.core.spawn.set")
|
||||
@Syntax("[world x y z [yaw pitch]]")
|
||||
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch")
|
||||
@Description("Sets the spawn for the current world.")
|
||||
public void onModifySetSpawnCommand(@NotNull CommandSender sender,
|
||||
@Nullable @Optional Player player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world x y z [yaw pitch]]")
|
||||
@Description("New location of spawn.")
|
||||
@Flags("other,defaultself") MultiverseWorld world,
|
||||
|
||||
@Nullable @Optional Double x,
|
||||
@Nullable @Optional Double y,
|
||||
@Nullable @Optional Double z,
|
||||
@Nullable @Optional Float yaw,
|
||||
@Nullable @Optional Float pitch) {
|
||||
|
||||
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
setWorldSpawn(sender, w, l);
|
||||
} else {
|
||||
sender.sendMessage("You need to give coordinates to use this command from the console!");
|
||||
@CommandAlias("mvsetspawn")
|
||||
public class AliasSetSpawn extends BaseCommand {
|
||||
|
||||
@CommandAlias("mvsetspawn")
|
||||
@CommandPermission("multiverse.core.spawn.set")
|
||||
@Syntax("[world x y z [yaw pitch]]")
|
||||
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch @empty")
|
||||
@Description("Sets the spawn for the current world.")
|
||||
public void onAliasSetSpawnCommand(@NotNull CommandSender sender,
|
||||
@Nullable @Optional Player player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world x y z [yaw pitch]]")
|
||||
@Description("New location of spawn.")
|
||||
@Flags("other,defaultself") MultiverseWorld world,
|
||||
|
||||
@Nullable @Optional Double x,
|
||||
@Nullable @Optional Double y,
|
||||
@Nullable @Optional Double z,
|
||||
@Nullable @Optional Float yaw,
|
||||
@Nullable @Optional Float pitch) {
|
||||
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
|
||||
@NotNull
|
||||
private Location parseLocation(@Nullable Player player,
|
||||
@NotNull MultiverseWorld world,
|
||||
@Nullable Double x,
|
||||
@Nullable Double y,
|
||||
@Nullable Double z,
|
||||
@Nullable Float yaw,
|
||||
@Nullable Float pitch) {
|
||||
|
||||
if (x == null) {
|
||||
if (player == null) {
|
||||
throw new InvalidCommandArgument("You need to specify a location from console.");
|
||||
}
|
||||
return player.getLocation();
|
||||
}
|
||||
if (y == null) {
|
||||
throw new InvalidCommandArgument("You need to specify y and z axis as well.");
|
||||
}
|
||||
if (z == null) {
|
||||
throw new InvalidCommandArgument("You need to specify z axis as well.");
|
||||
}
|
||||
if (yaw == null) {
|
||||
return new Location(world.getCBWorld(), x, y, z);
|
||||
}
|
||||
if (pitch == null) {
|
||||
throw new InvalidCommandArgument("You need to specify pitch as well.");
|
||||
}
|
||||
|
||||
return new Location(world.getCBWorld(), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
private void doSpawnSet(@NotNull CommandSender sender,
|
||||
@NotNull MultiverseWorld world,
|
||||
@NotNull Location location) {
|
||||
|
||||
World bukkitWorld = location.getWorld();
|
||||
if (bukkitWorld == null) {
|
||||
sender.sendMessage("World " + world + " is unknown!");
|
||||
sender.sendMessage("No world found for the spawn location your tried to set.");
|
||||
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).");
|
||||
world.setSpawnLocation(location);
|
||||
BlockSafety blockSafety = this.plugin.getBlockSafety();
|
||||
if (!blockSafety.playerCanSpawnHereSafely(location) && world.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(String.format("If you want turn this back on, just do %s/mv modify set adjustspawn true %s", ChatColor.AQUA, world.getName()));
|
||||
world.setAdjustSpawn(false);
|
||||
}
|
||||
|
||||
sender.sendMessage((sender instanceof Player && ((Player) sender).getWorld().equals(world.getCBWorld()))
|
||||
? "Spawn of this world is set to:"
|
||||
: String.format("Spawn for %s is set to:", world.getColoredWorldString()));
|
||||
|
||||
sender.sendMessage(plugin.getLocationManipulation().strCoords(location));
|
||||
|
||||
if (!plugin.saveWorldConfig()) {
|
||||
sender.sendMessage(String.format("%sThere was an issue saving worlds.yml! Your changes will only be temporary!", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,46 +7,50 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Enables debug-information.
|
||||
*/
|
||||
public class SilentCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class SilentCommand extends MultiverseCoreCommand {
|
||||
|
||||
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();
|
||||
@Subcommand("silent")
|
||||
@CommandPermission("multiverse.core.silent")
|
||||
@Description("Show current state of silent mode.")
|
||||
public void onShowSilentCommand(@NotNull CommandSender sender) {
|
||||
displaySilentMode(sender);
|
||||
}
|
||||
|
||||
@Subcommand("silent")
|
||||
@CommandPermission("multiverse.core.silent")
|
||||
@Syntax("<true|false>")
|
||||
@CommandCompletion("true|false")
|
||||
@Description("Reduces the amount of startup messages.")
|
||||
public void onChangeSilentCommand(@NotNull CommandSender sender,
|
||||
boolean silent) {
|
||||
|
||||
plugin.getMVConfig().setSilentStart(silent);
|
||||
if (!plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(String.format("%sFailed to save config! Check your console for details.", ChatColor.RED));
|
||||
}
|
||||
this.displaySilentMode(sender);
|
||||
|
||||
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");
|
||||
}
|
||||
sender.sendMessage((plugin.getMVConfig().getSilentStart())
|
||||
? String.format("Multiverse Silent Start mode is %sOn", ChatColor.GREEN)
|
||||
: String.format("Multiverse Silent Start mode is %sOff", ChatColor.RED));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Takes the player to the latest bed he's slept in.
|
||||
*/
|
||||
public class SleepCommand extends MultiverseCommand {
|
||||
|
||||
public SleepCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Go to Sleep");
|
||||
this.setCommandUsage("/mv sleep");
|
||||
this.setArgRange(0, 0);
|
||||
this.addKey("mv sleep");
|
||||
this.setPermission("multiverse.core.sleep", "Takes you the latest bed you've slept in (Currently BROKEN).", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = null;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,84 +7,68 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.RequiredPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Teleports a player to the spawn.
|
||||
*/
|
||||
public class SpawnCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class SpawnCommand extends MultiverseCoreCommand {
|
||||
|
||||
public SpawnCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
Permission otherPerm = new Permission("multiverse.core.spawn.other",
|
||||
"Teleports another player to the spawn of the world they are in.", PermissionDefault.OP);
|
||||
this.setName("Spawn");
|
||||
this.setCommandUsage("/mv spawn" + ChatColor.GOLD + " [PLAYER]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mvspawn");
|
||||
this.addKey("mv spawn");
|
||||
this.addKey("mvs");
|
||||
this.setPermission("multiverse.core.spawn.self", "Teleports you to the Spawn Point of the world you are in.", PermissionDefault.OP);
|
||||
this.addAdditonalPermission(otherPerm);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
// If a persons name was passed in, you must be A. the console, or B have permissions
|
||||
if (args.size() == 1) {
|
||||
if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.other", true)) {
|
||||
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));
|
||||
if (target != null) {
|
||||
target.sendMessage("Teleporting to this world's spawn...");
|
||||
spawnAccurately(target);
|
||||
|
||||
if (player != null) {
|
||||
target.sendMessage("You were teleported by: " + ChatColor.YELLOW + player.getName());
|
||||
} else {
|
||||
target.sendMessage("You were teleported by: " + ChatColor.LIGHT_PURPLE + "the console");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(args.get(0) + " is not logged on right now!");
|
||||
}
|
||||
} else {
|
||||
if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.self", true)) {
|
||||
sender.sendMessage("You don't have permission to teleport yourself to spawn. (multiverse.core.spawn.self)");
|
||||
return;
|
||||
}
|
||||
if (player != null) {
|
||||
player.sendMessage("Teleporting to this world's spawn...");
|
||||
spawnAccurately(player);
|
||||
} else {
|
||||
sender.sendMessage("From the console, you must provide a PLAYER.");
|
||||
}
|
||||
}
|
||||
@Subcommand("spawn")
|
||||
@CommandPermission("multiverse.core.spawn.self")
|
||||
@Description("Teleport yourself to the spawn of the world.")
|
||||
public void onSpawnCommand(@NotNull Player player) {
|
||||
doSpawn(player, player);
|
||||
}
|
||||
|
||||
private void spawnAccurately(Player player) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld().getName());
|
||||
Location spawnLocation;
|
||||
if (world != null) {
|
||||
spawnLocation = world.getSpawnLocation();
|
||||
} else {
|
||||
spawnLocation = player.getWorld().getSpawnLocation();
|
||||
}
|
||||
@CommandAlias("spawn")
|
||||
@CommandPermission("multiverse.core.spawn.other")
|
||||
@Syntax("[player]")
|
||||
@CommandCompletion("@players")
|
||||
@Description("Teleport another player to the spawn of the world they are in.")
|
||||
public void onSpawnCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[player]")
|
||||
@Description("Target player to teleport to spawn.")
|
||||
RequiredPlayer player) {
|
||||
|
||||
doSpawn(sender, player.get());
|
||||
}
|
||||
|
||||
private void doSpawn(@NotNull CommandSender sender,
|
||||
@NotNull Player player) {
|
||||
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld());
|
||||
Location spawnLocation = (world == null) ? player.getWorld().getSpawnLocation() : world.getSpawnLocation();
|
||||
|
||||
this.plugin.getSafeTTeleporter().safelyTeleport(player, player, spawnLocation, false);
|
||||
|
||||
if (sender.equals(player)) {
|
||||
player.sendMessage("Teleported to this world's spawn.");
|
||||
return;
|
||||
}
|
||||
|
||||
String senderName = (sender instanceof ConsoleCommandSender)
|
||||
? String.format("%sconsole%s", ChatColor.LIGHT_PURPLE, ChatColor.RESET)
|
||||
: String.format("%s%s%s", ChatColor.YELLOW, sender.getName(), ChatColor.RESET);
|
||||
|
||||
player.sendMessage("You were teleported by " + senderName + "to spawn.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.HelpCommand;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SubModulesCommand {
|
||||
|
||||
public static class NetherPortals extends BaseCommand {
|
||||
|
||||
@HelpCommand
|
||||
@CommandAlias("mvnp")
|
||||
@CommandPermission("multiverse.core.submodules")
|
||||
@Description("Suggest download for Multiverse-NetherPortals.")
|
||||
public void onSuggestCommand(@NotNull CommandSender sender,
|
||||
@NotNull CommandHelp help) {
|
||||
|
||||
suggestDownload(
|
||||
sender,
|
||||
"Multiverse-NetherPortals",
|
||||
ColorAlternator.with(ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE),
|
||||
"https://dev.bukkit.org/projects/multiverse-netherportals"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Portals extends BaseCommand {
|
||||
|
||||
@HelpCommand
|
||||
@CommandAlias("mvp")
|
||||
@CommandPermission("multiverse.core.submodules")
|
||||
@Description("Suggest download for Multiverse-Portals.")
|
||||
public void onSuggestCommand(@NotNull CommandSender sender,
|
||||
@NotNull CommandHelp help) {
|
||||
|
||||
suggestDownload(
|
||||
sender,
|
||||
"Multiverse-Portals",
|
||||
ColorAlternator.with(ChatColor.DARK_RED, ChatColor.RED),
|
||||
"https://dev.bukkit.org/projects/multiverse-portals"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Inventories extends BaseCommand {
|
||||
|
||||
@HelpCommand
|
||||
@CommandAlias("mvinv")
|
||||
@CommandPermission("multiverse.core.submodules")
|
||||
@Description("Suggest download for Multiverse-Inventories.")
|
||||
public void onSuggestCommand(@NotNull CommandSender sender,
|
||||
@NotNull CommandHelp help) {
|
||||
|
||||
suggestDownload(
|
||||
sender,
|
||||
"Multiverse-Inventories",
|
||||
ColorAlternator.with(ChatColor.DARK_AQUA, ChatColor.AQUA),
|
||||
"https://dev.bukkit.org/projects/multiverse-inventories"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void suggestDownload(@NotNull CommandSender sender,
|
||||
@NotNull String pluginName,
|
||||
@NotNull ColorAlternator colours,
|
||||
@NotNull String downloadLink) {
|
||||
|
||||
sender.sendMessage(String.format("%s%s%s is not installed on this server. You can learn more and download it at:",
|
||||
colours.getThisColor(), pluginName, ChatColor.WHITE));
|
||||
sender.sendMessage(String.format("%s%s", colours.getThatColor(), downloadLink));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,201 +7,215 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
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.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
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 org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Used to teleport players.
|
||||
*/
|
||||
public class TeleportCommand extends MultiverseCommand {
|
||||
private SafeTTeleporter playerTeleporter;
|
||||
public class TeleportCommand extends MultiverseCoreCommand {
|
||||
|
||||
private final SafeTTeleporter playerTeleporter;
|
||||
|
||||
private static final int UNSAFE_TELEPORT_EXPIRE_DELAY = 300; // In ticks
|
||||
|
||||
public TeleportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
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.setArgRange(1, 2);
|
||||
this.addKey("mvtp");
|
||||
this.addKey("mv tp");
|
||||
this.playerTeleporter = this.plugin.getSafeTTeleporter();
|
||||
this.setPermission(menu);
|
||||
}
|
||||
|
||||
private static final int UNSAFE_TELEPORT_EXPIRE_DELAY = 15;
|
||||
@CommandAlias("mv")
|
||||
public class Teleport extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
CommandSender teleporter = sender;
|
||||
Player teleportee = null;
|
||||
@Subcommand("tp|teleport")
|
||||
@Syntax("[player] <destination>")
|
||||
@CommandCompletion("@players|@MVWorlds:playerOnly|@destinations:playerOnly @players|@MVWorlds|@destinations")
|
||||
@Description("Allows you to the teleport to a location on your server!")
|
||||
public void doTeleportCommand(@NotNull CommandSender sender,
|
||||
|
||||
String destinationName;
|
||||
@Syntax("[player]")
|
||||
@Description("Target player to teleport.")
|
||||
@NotNull @Flags("other,defaultself,fallbackself") Player player,
|
||||
|
||||
if (args.size() == 2) {
|
||||
teleportee = this.plugin.getServer().getPlayer(args.get(0));
|
||||
if (teleportee == null) {
|
||||
this.messaging.sendMessage(sender, String.format("Sorry, I couldn't find player: %s%s",
|
||||
ChatColor.GOLD, args.get(0)), false);
|
||||
return;
|
||||
}
|
||||
destinationName = args.get(1);
|
||||
@Syntax("<destination>")
|
||||
@Description("Location, can be a world name.")
|
||||
@NotNull @Flags("type=destination") String destinationName) {
|
||||
|
||||
} else {
|
||||
destinationName = args.get(0);
|
||||
if (!(sender instanceof Player)) {
|
||||
this.messaging.sendMessage(sender, String.format("From the console, you must specify a player to teleport"), false);
|
||||
return;
|
||||
}
|
||||
teleportee = (Player) sender;
|
||||
doTeleport(sender, player, destinationName);
|
||||
}
|
||||
// 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";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRequiredPermissions() {
|
||||
return destPerms();
|
||||
}
|
||||
DestinationFactory df = this.plugin.getDestFactory();
|
||||
MVDestination d = df.getDestination(destinationName);
|
||||
}
|
||||
|
||||
public class AliasTeleport extends BaseCommand {
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter, true);
|
||||
@CommandAlias("mvtp")
|
||||
@Syntax("[player] <destination>")
|
||||
@CommandCompletion("@players|@MVWorlds:playerOnly|@destinations:playerOnly @MVWorlds|@destinations")
|
||||
@Description("Alias for /mv tp")
|
||||
public void doTeleportCommand(@NotNull CommandSender sender,
|
||||
|
||||
@Syntax("[player]")
|
||||
@Description("Target player to teleport.")
|
||||
@NotNull @Flags("other,defaultself,fallbackself") Player player,
|
||||
|
||||
@Syntax("<destination>")
|
||||
@Description("Location, can be a world name.")
|
||||
@NotNull @Flags("type=destination") String destinationName) {
|
||||
|
||||
doTeleport(sender, player, destinationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRequiredPermissions() {
|
||||
return destPerms();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> destPerms() {
|
||||
return this.plugin.getDestFactory().getPermissions();
|
||||
}
|
||||
|
||||
private void doTeleport(@NotNull CommandSender teleporter,
|
||||
@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
MVDestination destination = this.plugin.getDestFactory().getPlayerAwareDestination(teleportee, destinationName);
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(destination, 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;
|
||||
}
|
||||
|
||||
if (d != null && d instanceof InvalidDestination) {
|
||||
this.messaging.sendMessage(sender, String.format("Multiverse does not know how to take you to %s%s",
|
||||
ChatColor.RED, destinationName), false);
|
||||
if (destination instanceof InvalidDestination) {
|
||||
teleporter.sendMessage(String.format("Multiverse does not know how to take you to %s%s", ChatColor.RED, destinationName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.checkSendPermissions(teleporter, teleportee, d)) {
|
||||
if (!this.checkSendPermissions(teleporter, teleportee, destination)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getMVConfig().getEnforceAccess() && teleporter != null && !this.plugin.getMVPerms().canEnterDestination(teleporter, d)) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there...");
|
||||
} else {
|
||||
teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD
|
||||
+ teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there...");
|
||||
}
|
||||
return;
|
||||
} else if (teleporter != null && !this.plugin.getMVPerms().canTravelFromLocation(teleporter, d.getLocation(teleportee))) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like you can get to %s%s %sfrom where you are...",
|
||||
ChatColor.GREEN, d.toString(), ChatColor.WHITE), false);
|
||||
} else {
|
||||
this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like %s%s %scan get to %sTHERE from where they are...",
|
||||
ChatColor.GREEN, ((Player) teleporter).getWorld().getName(), ChatColor.WHITE, ChatColor.RED), false);
|
||||
}
|
||||
if (this.plugin.getMVConfig().getEnforceAccess() && !this.plugin.getMVPerms().canEnterDestination(teleportee, destination)) {
|
||||
teleporter.sendMessage((teleportee.equals(teleporter))
|
||||
? "Doesn't look like you're allowed to go " + ChatColor.RED + "there..."
|
||||
: "Doesn't look like you're allowed to send " + ChatColor.GOLD + teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there...");
|
||||
return;
|
||||
}
|
||||
|
||||
// Special check to verify if players are tryint to teleport to the same
|
||||
// WORLDDestination as the world they're in, that they ALSO have multiverse.core.spawn.self
|
||||
|
||||
if (d instanceof WorldDestination) {
|
||||
World w = d.getLocation(teleportee).getWorld();
|
||||
if (teleportee.getWorld().equals(w)) {
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("Sorry you don't have permission to go to the world spawn!"),
|
||||
String.format("%s (multiverse.core.spawn.self)",
|
||||
ChatColor.RED) }, false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("Sorry you don't have permission to send %s to the world spawn!",
|
||||
teleportee.getDisplayName()),
|
||||
String.format("%s (multiverse.core.spawn.other)",
|
||||
ChatColor.RED) }, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d.getLocation(teleportee) == null) {
|
||||
this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false);
|
||||
if (!this.plugin.getMVPerms().canTravelFromLocation(teleporter, destination.getLocation(teleportee))) {
|
||||
teleporter.sendMessage((teleportee.equals(teleporter))
|
||||
? String.format("Doh! Doesn't look like you can get to %s%s %sfrom where you are...",
|
||||
ChatColor.GREEN, destination.toString(), ChatColor.WHITE)
|
||||
: String.format("Doh! Doesn't look like %s%s %scan get to %sTHERE from where they are...",
|
||||
ChatColor.GREEN, ((Player) teleporter).getWorld().getName(), ChatColor.WHITE, ChatColor.RED));
|
||||
return;
|
||||
}
|
||||
Teleporter teleportObject = (d instanceof CustomTeleporterDestination) ?
|
||||
((CustomTeleporterDestination)d).getTeleporter() : this.playerTeleporter;
|
||||
TeleportResult result = teleportObject.teleport(teleporter, teleportee, d);
|
||||
|
||||
// Special check to verify if players are trying to teleport to the same WORLD Destination
|
||||
// as the world they're in, that they ALSO have multiverse.core.spawn.self
|
||||
if (destination instanceof WorldDestination
|
||||
&& teleportee.getWorld().equals(destination.getLocation(teleportee).getWorld())
|
||||
&& !checkSpawnPermissions(teleporter, teleportee)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (destination.getLocation(teleportee) == null) {
|
||||
teleporter.sendMessage("Sorry Boss, I tried everything, but just couldn't teleport ya there!");
|
||||
return;
|
||||
}
|
||||
|
||||
Teleporter teleportObject = (destination instanceof CustomTeleporterDestination)
|
||||
? ((CustomTeleporterDestination) destination).getTeleporter()
|
||||
: this.playerTeleporter;
|
||||
|
||||
TeleportResult result = teleportObject.teleport(teleporter, teleportee, destination);
|
||||
if (result == TeleportResult.FAIL_UNSAFE) {
|
||||
this.plugin.log(Level.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);
|
||||
Logging.fine("Could not teleport %s to %s.",
|
||||
teleportee.getName(), this.plugin.getLocationManipulation().strCoordsRaw(destination.getLocation(teleportee)));
|
||||
|
||||
this.plugin.getMVCommandManager().getQueueManager().addToQueue(new QueuedCommand.Builder()
|
||||
.sender(teleporter)
|
||||
.action(unsafeTeleportRunnable(teleporter, teleportee, destination.getLocation(teleportee)))
|
||||
.prompt("The location you are trying to teleport to is deemed unsafe, do you still want to try?")
|
||||
.validDuration(UNSAFE_TELEPORT_EXPIRE_DELAY)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
// else: Player was teleported successfully (or the tp event was fired I should say)
|
||||
}
|
||||
|
||||
private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) {
|
||||
private boolean checkSendPermissions(@NotNull CommandSender teleporter,
|
||||
@NotNull Player teleportee,
|
||||
@NotNull MVDestination destination) {
|
||||
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("%sYou don't have permission to teleport %syourself %sto a %s%s %sDestination",
|
||||
ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, destination.getType(), ChatColor.WHITE),
|
||||
String.format("%s (multiverse.teleport.self.%s)",
|
||||
ChatColor.RED, destination.getIdentifier()) }, false);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("You don't have permission to teleport another player to a %s%s Destination.",
|
||||
ChatColor.GREEN, destination.getType()),
|
||||
String.format("%s(multiverse.teleport.other.%s)",
|
||||
ChatColor.RED, destination.getIdentifier()) }, false);
|
||||
teleporter.sendMessage(String.format("%sYou don't have permission to teleport %syourself %sto a %s%s %sDestination", ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, destination.getType(), ChatColor.WHITE));
|
||||
teleporter.sendMessage(String.format("%s (multiverse.teleport.self.%s)", ChatColor.RED, destination.getIdentifier()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) {
|
||||
teleporter.sendMessage(String.format("You don't have permission to teleport another player to a %s%s Destination.", ChatColor.GREEN, destination.getType()));
|
||||
teleporter.sendMessage(String.format("%s(multiverse.teleport.other.%s)", ChatColor.RED, destination.getIdentifier()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkSpawnPermissions(@NotNull CommandSender teleporter,
|
||||
@NotNull Player teleportee) {
|
||||
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) {
|
||||
teleporter.sendMessage(String.format("Sorry you don't have permission to go to the world spawn!"));
|
||||
teleporter.sendMessage(String.format("%s (multiverse.core.spawn.self)", ChatColor.RED));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) {
|
||||
teleporter.sendMessage(String.format("Sorry you don't have permission to send %s to the world spawn!", teleportee.getDisplayName()));
|
||||
teleporter.sendMessage(String.format("%s (multiverse.core.spawn.other)", ChatColor.RED));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Runnable unsafeTeleportRunnable(@NotNull CommandSender teleporter,
|
||||
@NotNull Player teleportee,
|
||||
@NotNull Location location) {
|
||||
|
||||
return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, teleportee, location, false);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,36 +7,44 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.ChatColor;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unloads worlds from Multiverse.
|
||||
*/
|
||||
public class UnloadCommand extends MultiverseCommand {
|
||||
@CommandAlias("mv")
|
||||
public class UnloadCommand extends MultiverseCoreCommand {
|
||||
|
||||
public UnloadCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Unload World");
|
||||
this.setCommandUsage("/mv unload" + ChatColor.GREEN + " {WORLD}");
|
||||
this.setArgRange(1, 1);
|
||||
this.addKey("mvunload");
|
||||
this.addKey("mv unload");
|
||||
this.setPermission("multiverse.core.unload",
|
||||
"Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.getMVWorldManager().unloadWorld(args.get(0))) {
|
||||
Command.broadcastCommandMessage(sender, "Unloaded world '" + args.get(0) + "'!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to unload world '" + args.get(0) + "'!");
|
||||
@Subcommand("unload")
|
||||
@CommandPermission("multiverse.core.unload")
|
||||
@Syntax("<world>")
|
||||
@CommandCompletion("@MVWorlds")
|
||||
@Description("Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.")
|
||||
public void onUnloadCommand(@NotNull CommandSender sender,
|
||||
|
||||
@NotNull
|
||||
@Syntax("<world>")
|
||||
@Description("Name of world you want to unload.")
|
||||
@Flags("other") MultiverseWorld world) {
|
||||
|
||||
//TODO API: Should be able to use MVWorld object directly
|
||||
if (!this.plugin.getMVWorldManager().unloadWorld(world.getName())) {
|
||||
sender.sendMessage(String.format("Error unloading world '%s'! See console for more details.",
|
||||
world.getColoredWorldString()));
|
||||
return;
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, String.format("Unloaded world '%s'!", world.getColoredWorldString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* 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.commands;
|
||||
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.HelpCommand;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandAlias("mv")
|
||||
public class UsageCommand extends MultiverseCoreCommand {
|
||||
|
||||
public UsageCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@HelpCommand
|
||||
@Subcommand("help")
|
||||
@CommandPermission("multiverse.core.help")
|
||||
@Syntax("[filter] [page]")
|
||||
@CommandCompletion("@subCommands:mv")
|
||||
@Description("Show Multiverse-Core Command usage.")
|
||||
public void onUsageCommand(@NotNull CommandHelp help) {
|
||||
this.plugin.getMVCommandManager().showUsage(help);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,187 +7,89 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagGroup;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagResult;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CoreFlags;
|
||||
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.pneumaticraft.commandhandler.CommandHandler;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerFactory;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerType;
|
||||
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 org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Dumps version info to the console.
|
||||
*/
|
||||
public class VersionCommand extends MultiverseCommand {
|
||||
private static final URLShortener SHORTENER = new BitlyURLShortener();
|
||||
@CommandAlias("mv")
|
||||
public class VersionCommand extends MultiverseCoreCommand {
|
||||
|
||||
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 + "-[bh] [--include-plugin-list]");
|
||||
this.setArgRange(0, 2);
|
||||
this.addKey("mv version");
|
||||
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.setFlagGroup(FlagGroup.of(
|
||||
CoreFlags.PASTE_SERVICE_TYPE,
|
||||
CoreFlags.INCLUDE_PLUGIN_LIST
|
||||
));
|
||||
}
|
||||
|
||||
private String getLegacyString() {
|
||||
StringBuilder legacyFile = new StringBuilder();
|
||||
legacyFile.append("[Multiverse-Core] Multiverse-Core Version: ").append(this.plugin.getDescription().getVersion()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Bukkit Version: ").append(this.plugin.getServer().getVersion()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Loaded Worlds: ").append(this.plugin.getMVWorldManager().getMVWorlds()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Multiverse Plugins Loaded: ").append(this.plugin.getPluginCount()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Economy being used: ").append(plugin.getEconomist().getEconomyName()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Permissions Plugin: ").append(this.plugin.getMVPerms().getType()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Dumping Config Values: (version ")
|
||||
.append(this.plugin.getMVConfig().getVersion()).append(")").append('\n');
|
||||
legacyFile.append("[Multiverse-Core] messagecooldown: ").append(plugin.getMessaging().getCooldown()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] teleportcooldown: ").append(plugin.getMVConfig().getTeleportCooldown()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] worldnameprefix: ").append(plugin.getMVConfig().getPrefixChat()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] worldnameprefixFormat: ").append(plugin.getMVConfig().getPrefixChatFormat()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] enforceaccess: ").append(plugin.getMVConfig().getEnforceAccess()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] displaypermerrors: ").append(plugin.getMVConfig().getDisplayPermErrors()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] teleportintercept: ").append(plugin.getMVConfig().getTeleportIntercept()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] firstspawnoverride: ").append(plugin.getMVConfig().getFirstSpawnOverride()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] firstspawnworld: ").append(plugin.getMVConfig().getFirstSpawnWorld()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] debug: ").append(plugin.getMVConfig().getGlobalDebug()).append('\n');
|
||||
legacyFile.append("[Multiverse-Core] Special Code: FRN002").append('\n');
|
||||
return legacyFile.toString();
|
||||
}
|
||||
@Subcommand("version")
|
||||
@CommandPermission("multiverse.core.version")
|
||||
@Syntax("--paste [pastebin|hastebin|pastegg] [--include-plugin-list]")
|
||||
@CommandCompletion("@flags")
|
||||
@Description("Dumps version info to the console, optionally to pastal service.")
|
||||
public void onVersionCommand(@NotNull CommandSender sender,
|
||||
|
||||
private String getMarkdownString() {
|
||||
StringBuilder markdownString = new StringBuilder();
|
||||
markdownString.append("# Multiverse-Core\n");
|
||||
markdownString.append("## Overview\n");
|
||||
markdownString.append("| Name | Value |\n");
|
||||
markdownString.append("| --- | --- |\n");
|
||||
markdownString.append("| Multiverse-Core Version | `").append(this.plugin.getDescription().getVersion()).append("` |\n");
|
||||
markdownString.append("| Bukkit Version | `").append(this.plugin.getServer().getVersion()).append("` |\n");
|
||||
//markdownString.append("| Loaded Worlds | `").append(this.plugin.getMVWorldManager().getMVWorlds()).append("` |\n");
|
||||
markdownString.append("| Multiverse Plugins Loaded | `").append(this.plugin.getPluginCount()).append("` |\n");
|
||||
markdownString.append("| Economy being used | `").append(plugin.getEconomist().getEconomyName()).append("` |\n");
|
||||
markdownString.append("| Permissions Plugin | `").append(this.plugin.getMVPerms().getType()).append("` |\n");
|
||||
markdownString.append("## Parsed Config\n");
|
||||
markdownString.append("These are what Multiverse thought the in-memory values of the config were.\n\n");
|
||||
markdownString.append("| Config Key | Value |\n");
|
||||
markdownString.append("| --- | --- |\n");
|
||||
markdownString.append("| version | `").append(this.plugin.getMVConfig().getVersion()).append("` |\n");
|
||||
markdownString.append("| messagecooldown | `").append(plugin.getMessaging().getCooldown()).append("` |\n");
|
||||
markdownString.append("| teleportcooldown | `").append(plugin.getMVConfig().getTeleportCooldown()).append("` |\n");
|
||||
markdownString.append("| worldnameprefix | `").append(plugin.getMVConfig().getPrefixChat()).append("` |\n");
|
||||
markdownString.append("| worldnameprefixFormat | `").append(plugin.getMVConfig().getPrefixChatFormat()).append("` |\n");
|
||||
markdownString.append("| enforceaccess | `").append(plugin.getMVConfig().getEnforceAccess()).append("` |\n");
|
||||
markdownString.append("| displaypermerrors | `").append(plugin.getMVConfig().getDisplayPermErrors()).append("` |\n");
|
||||
markdownString.append("| teleportintercept | `").append(plugin.getMVConfig().getTeleportIntercept()).append("` |\n");
|
||||
markdownString.append("| firstspawnoverride | `").append(plugin.getMVConfig().getFirstSpawnOverride()).append("` |\n");
|
||||
markdownString.append("| firstspawnworld | `").append(plugin.getMVConfig().getFirstSpawnWorld()).append("` |\n");
|
||||
markdownString.append("| debug | `").append(plugin.getMVConfig().getGlobalDebug()).append("` |\n");
|
||||
return markdownString.toString();
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("[paste-service]")
|
||||
@Description("Website to upload your version info to.")
|
||||
String[] flagsArray) {
|
||||
|
||||
private String readFile(final String filename) {
|
||||
String result;
|
||||
try {
|
||||
FileReader reader = new FileReader(filename);
|
||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||
String line;
|
||||
result = "";
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
result += line + '\n';
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Logging.severe("Unable to find %s. Here's the traceback: %s", filename, e.getMessage());
|
||||
e.printStackTrace();
|
||||
result = 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 = String.format("ERROR: Could not load: %s", filename);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
FlagResult flags = FlagResult.parse(flagsArray, this.getFlagGroup());
|
||||
|
||||
private Map<String, String> getVersionFiles() {
|
||||
Map<String, String> files = new HashMap<String, String>();
|
||||
|
||||
// Add the legacy file, but as markdown so it's readable
|
||||
files.put("version.md", this.getMarkdownString());
|
||||
|
||||
// Add the config.yml
|
||||
File configFile = new File(this.plugin.getDataFolder(), "config.yml");
|
||||
files.put(configFile.getName(), this.readFile(configFile.getAbsolutePath()));
|
||||
|
||||
// Add the config.yml
|
||||
File worldConfig = new File(this.plugin.getDataFolder(), "worlds.yml");
|
||||
files.put(worldConfig.getName(), this.readFile(worldConfig.getAbsolutePath()));
|
||||
return files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(final CommandSender sender, final List<String> args) {
|
||||
// Check if the command was sent from a Player.
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage("Version info dumped to console. Please check your server logs.");
|
||||
}
|
||||
|
||||
MVVersionEvent versionEvent = new MVVersionEvent(this.getLegacyString(), this.getVersionFiles());
|
||||
final Map<String, String> files = this.getVersionFiles();
|
||||
MVVersionEvent versionEvent = new MVVersionEvent();
|
||||
this.addVersionInfoToEvent(versionEvent);
|
||||
this.plugin.getServer().getPluginManager().callEvent(versionEvent);
|
||||
|
||||
String versionInfo = versionEvent.getVersionInfo();
|
||||
|
||||
if (CommandHandler.hasFlag("--include-plugin-list", args)) {
|
||||
versionInfo = versionInfo + "\nPlugins: " + getPluginList();
|
||||
if (flags.getValue(CoreFlags.INCLUDE_PLUGIN_LIST)) {
|
||||
versionEvent.appendVersionInfo('\n' + "Plugins: " + getPluginList());
|
||||
versionEvent.putDetailedVersionInfo("plugins.txt", "Plugins: " + getPluginList());
|
||||
}
|
||||
|
||||
final String data = versionInfo;
|
||||
String versionInfo = versionEvent.getVersionInfo();
|
||||
versionEvent.putDetailedVersionInfo("version.txt", versionInfo);
|
||||
|
||||
// log to console
|
||||
String[] lines = data.split("\n");
|
||||
for (String line : lines) {
|
||||
if (!line.isEmpty()) {
|
||||
Logging.info(line);
|
||||
}
|
||||
Map<String, String> files = versionEvent.getDetailedVersionInfo();
|
||||
|
||||
logToConsole(versionInfo);
|
||||
|
||||
PasteServiceType pasteType = flags.getValue(CoreFlags.PASTE_SERVICE_TYPE);
|
||||
if (pasteType == PasteServiceType.NONE && !(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage("Version info dumped to console! Please check your server logs.");
|
||||
return;
|
||||
}
|
||||
|
||||
BukkitRunnable logPoster = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.size() > 0) {
|
||||
String pasteUrl;
|
||||
if (CommandHandler.hasFlag("-b", args)) {
|
||||
// private post to pastebin
|
||||
pasteUrl = postToService(PasteServiceType.PASTEBIN, true, data, files);
|
||||
} else if (CommandHandler.hasFlag("-h", args)) {
|
||||
// private post to pastebin
|
||||
pasteUrl = postToService(PasteServiceType.HASTEBIN, true, data, files);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
}
|
||||
Logging.info("Version info dumped here: %s", pasteUrl);
|
||||
}
|
||||
String pasteUrl = postToService(pasteType, true, versionInfo, files);
|
||||
sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -195,6 +97,29 @@ public class VersionCommand extends MultiverseCommand {
|
||||
logPoster.runTaskAsynchronously(this.plugin);
|
||||
}
|
||||
|
||||
private void logToConsole(String versionInfo) {
|
||||
Arrays.stream(versionInfo.split("\\r?\\n"))
|
||||
.filter(line -> !line.isEmpty())
|
||||
.forEach(this.plugin.getServer().getLogger()::info);
|
||||
}
|
||||
|
||||
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 API: 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current contents of this.pasteBinBuffer to a web service.
|
||||
*
|
||||
@@ -204,24 +129,55 @@ public class VersionCommand extends MultiverseCommand {
|
||||
* @param pasteFiles Map of filenames/contents of debug info.
|
||||
* @return URL of visible paste
|
||||
*/
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData,
|
||||
Map<String, String> pasteFiles) {
|
||||
private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData, Map<String, String> pasteFiles) {
|
||||
PasteService ps = PasteServiceFactory.getService(type, isPrivate);
|
||||
|
||||
try {
|
||||
String result;
|
||||
if (ps.supportsMultiFile()) {
|
||||
result = ps.postData(ps.encodeData(pasteFiles), ps.getPostURL());
|
||||
} else {
|
||||
result = ps.postData(ps.encodeData(pasteData), ps.getPostURL());
|
||||
}
|
||||
return SHORTENER.shorten(result);
|
||||
} catch (PasteFailedException e) {
|
||||
System.out.print(e);
|
||||
return "Error posting to service";
|
||||
String result = (ps.supportsMultiFile())
|
||||
? ps.postData(pasteFiles)
|
||||
: ps.postData(pasteData);
|
||||
|
||||
return (SHORTENER != null) ? SHORTENER.shorten(result) : result;
|
||||
}
|
||||
catch (PasteFailedException e) {
|
||||
e.printStackTrace();
|
||||
return String.format("%sError posting to service.", ChatColor.RED);
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
return String.format("%sThat service isn't supported yet.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
|
||||
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: " + this.plugin.getMVConfig().getEnforceAccess() + '\n'
|
||||
+ "[Multiverse-Core] prefixchat: " + this.plugin.getMVConfig().getPrefixChat() + '\n'
|
||||
+ "[Multiverse-Core] prefixchatformat: " + this.plugin.getMVConfig().getPrefixChatFormat() + '\n'
|
||||
+ "[Multiverse-Core] useasyncchat: " + this.plugin.getMVConfig().getUseAsyncChat() + '\n'
|
||||
+ "[Multiverse-Core] teleportintercept: " + this.plugin.getMVConfig().getTeleportIntercept() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnoverride: " + this.plugin.getMVConfig().getFirstSpawnOverride() + '\n'
|
||||
+ "[Multiverse-Core] displaypermerrors: " + this.plugin.getMVConfig().getDisplayPermErrors() + '\n'
|
||||
+ "[Multiverse-Core] globaldebug: " + this.plugin.getMVConfig().getGlobalDebug() + '\n'
|
||||
+ "[Multiverse-Core] enablebuscript: " + plugin.getMVConfig().getEnableBuscript() + '\n'
|
||||
+ "[Multiverse-Core] silentstart: " + this.plugin.getMVConfig().getSilentStart() + '\n'
|
||||
+ "[Multiverse-Core] messagecooldown: " + this.plugin.getMessaging().getCooldown() + '\n'
|
||||
+ "[Multiverse-Core] version: " + this.plugin.getMVConfig().getVersion() + '\n'
|
||||
+ "[Multiverse-Core] firstspawnworld: " + this.plugin.getMVConfig().getFirstSpawnWorld() + '\n'
|
||||
+ "[Multiverse-Core] teleportcooldown: " + this.plugin.getMVConfig().getTeleportCooldown() + '\n'
|
||||
+ "[Multiverse-Core] defaultportalsearch: " +this. plugin.getMVConfig().isUsingDefaultPortalSearch() + '\n'
|
||||
+ "[Multiverse-Core] portalsearchradius: " + this.plugin.getMVConfig().getPortalSearchRadius() + '\n'
|
||||
+ "[Multiverse-Core] autopurge: " +this. plugin.getMVConfig().isAutoPurgeEnabled() + '\n'
|
||||
+ "[Multiverse-Core] Special Code: FRN002" + '\n';
|
||||
}
|
||||
|
||||
private String getPluginList() {
|
||||
return StringUtils.join(plugin.getServer().getPluginManager().getPlugins(), ", ");
|
||||
return StringUtils.join(this.plugin.getServer().getPluginManager().getPlugins(), ", ");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* 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. *
|
||||
@@ -7,112 +7,123 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentDisplay;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplayHandlers;
|
||||
import com.onarandombox.MultiverseCore.displaytools.DisplaySettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* States who is in what world.
|
||||
*/
|
||||
public class WhoCommand extends MultiverseCommand {
|
||||
|
||||
private MVWorldManager worldManager;
|
||||
@CommandAlias("mv")
|
||||
public class WhoCommand extends MultiverseCoreCommand {
|
||||
|
||||
public WhoCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Who?");
|
||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD|--all]");
|
||||
this.setArgRange(0, 1);
|
||||
this.addKey("mv who");
|
||||
this.addKey("mvw");
|
||||
this.addKey("mvwho");
|
||||
this.addCommandExample("/mv who");
|
||||
this.addCommandExample(String.format("/mv who %s--all", ChatColor.GREEN));
|
||||
this.addCommandExample(String.format("/mv who %smyworld", ChatColor.GOLD));
|
||||
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// If this command was sent from a Player then we need to check Permissions
|
||||
Player p = null;
|
||||
// By default, show all from the console
|
||||
boolean showAll = true;
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
showAll = false;
|
||||
}
|
||||
@Subcommand("whoall")
|
||||
@CommandPermission("multiverse.core.list.who.all")
|
||||
@Syntax("[filter]")
|
||||
public void onWhoAllCommand(@NotNull CommandSender sender,
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
@Syntax("[filter] [page]")
|
||||
@Description("Filter and paging.")
|
||||
PageFilter pageFilter) {
|
||||
|
||||
if (args.size() == 1) {
|
||||
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
|
||||
showAll = true;
|
||||
} else {
|
||||
// single world mode
|
||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||
if (world == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That world does not exist.");
|
||||
return;
|
||||
}
|
||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
Set<Player> visiblePlayers = getVisiblePlayers(player);
|
||||
|
||||
if (!this.plugin.getMVPerms().canEnterWorld(p, world)) {
|
||||
sender.sendMessage(ChatColor.RED + "You aren't allowed to access to this world!");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
|
||||
world.getColoredWorldString(), ChatColor.AQUA));
|
||||
sender.sendMessage(this.buildPlayerString(world, p, visiblePlayers));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// multiworld mode
|
||||
sender.sendMessage(ChatColor.AQUA + "--- Worlds and their players --- "
|
||||
+ visiblePlayers.size() + "/" + plugin.getServer().getMaxPlayers());
|
||||
boolean shownOne = false;
|
||||
for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
|
||||
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
|
||||
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
|
||||
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, p, visiblePlayers)));
|
||||
shownOne = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!shownOne) {
|
||||
sender.sendMessage("No worlds found.");
|
||||
}
|
||||
return;
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.header("%s--- Worlds and their players --- %s%s/%s", ChatColor.GOLD, ChatColor.AQUA, visiblePlayers.size(), this.plugin.getServer().getMaxPlayers())
|
||||
.contents(buildAllWorlds(player, visiblePlayers))
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
.filter(pageFilter.getFilter())
|
||||
.setting(DisplaySettings.SHOW_PAGE, pageFilter.getPage())
|
||||
.display();
|
||||
}
|
||||
|
||||
private static String buildPlayerString(MultiverseWorld world, Player viewer, final Collection<Player> visiblePlayers) {
|
||||
// Retrieve the players in this world
|
||||
List<Player> players = world.getCBWorld().getPlayers();
|
||||
StringBuilder playerBuilder = new StringBuilder();
|
||||
for (Player player : players) {
|
||||
// If the viewer is the console or the viewier is allowed to see the player, show them.
|
||||
// Make sure we're also ONLY showing online players.
|
||||
// Since we already checked visible players, we'll just make sure who we're about to show is in that.
|
||||
if (visiblePlayers.contains(player))
|
||||
playerBuilder.append(player.getDisplayName()).append(", ");
|
||||
}
|
||||
String bString = playerBuilder.toString();
|
||||
return (bString.length() == 0) ? "No players found." : bString.substring(0, bString.length() - 2);
|
||||
@Subcommand("who")
|
||||
@CommandPermission("multiverse.core.list.who")
|
||||
@Syntax("[world] [filter]")
|
||||
@CommandCompletion("@MVWorlds")
|
||||
public void onWhoCommand(@NotNull CommandSender sender,
|
||||
@Nullable @Optional Player player,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[world]")
|
||||
@Description("World to show player list.")
|
||||
@Flags("other,defaultself,fallbackself")
|
||||
@Conditions("hasWorldAccess") MultiverseWorld world,
|
||||
|
||||
@NotNull
|
||||
@Syntax("[filter]")
|
||||
@Description("Filter the player names.")
|
||||
ContentFilter filter) {
|
||||
|
||||
Set<Player> visiblePlayers = getVisiblePlayers(player);
|
||||
|
||||
new ContentDisplay.Builder<Collection<String>>()
|
||||
.sender(sender)
|
||||
.header("%s===[ Players in %s%s ]===", ChatColor.AQUA, world.getColoredWorldString(), ChatColor.AQUA)
|
||||
.contents(buildPlayerList(world, visiblePlayers))
|
||||
.emptyMessage("%sNo players found.", ChatColor.GRAY)
|
||||
.displayHandler(DisplayHandlers.PAGE_LIST)
|
||||
//TODO: Filter
|
||||
.display();
|
||||
}
|
||||
|
||||
private List<String> buildAllWorlds(@Nullable Player player,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
return this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || this.plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.map(world -> getPLayersInWorld(world, visiblePlayers))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String getPLayersInWorld(@NotNull MultiverseWorld world,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
return String.format("%s%s - %s",
|
||||
world.getColoredWorldString(), ChatColor.WHITE, buildPlayerList(world, visiblePlayers));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> buildPlayerList(@NotNull MultiverseWorld world,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
return world.getCBWorld().getPlayers().stream()
|
||||
.filter(visiblePlayers::contains)
|
||||
.map(Player::getDisplayName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Set<Player> getVisiblePlayers(@Nullable Player player) {
|
||||
return this.plugin.getServer().getOnlinePlayers().stream()
|
||||
.filter(targetPLayer -> player == null || player.canSee(targetPLayer))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
* This package contains all Commands.
|
||||
* Where all the commands are.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
@@ -0,0 +1,323 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import buscript.Buscript;
|
||||
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.PaperCommandCompletions;
|
||||
import co.aikar.commands.RegisteredCommand;
|
||||
import co.aikar.commands.RootCommand;
|
||||
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.commandtools.flag.CommandFlag;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.CommandFlag.ValueRequirement;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagGroup;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Generate tab-complete suggestion.
|
||||
*/
|
||||
public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final MVWorldManager worldManager;
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat();
|
||||
|
||||
static {
|
||||
df.setMinimumFractionDigits(0);
|
||||
df.setMaximumFractionDigits(2);
|
||||
}
|
||||
|
||||
public MVCommandCompletions(@NotNull MVCommandManager manager,
|
||||
@NotNull MultiverseCore plugin) {
|
||||
super(manager);
|
||||
this.plugin = plugin;
|
||||
this.worldManager = plugin.getMVWorldManager();
|
||||
|
||||
registerAsyncCompletion("flags", this::suggestFlags);
|
||||
registerAsyncCompletion("scripts", this::suggestScripts);
|
||||
registerAsyncCompletion("subCommands", this::suggestSubCommands);
|
||||
registerAsyncCompletion("MVWorlds", this::suggestMVWorlds);
|
||||
registerAsyncCompletion("unloadedWorlds", this::suggestUnloadedWorlds);
|
||||
registerAsyncCompletion("potentialWorlds", this::suggestPotentialWorlds);
|
||||
registerAsyncCompletion("location", this::suggestLocation);
|
||||
registerAsyncCompletion("destinations", this::suggestDestinations);
|
||||
registerAsyncCompletion("anchors", this::suggestAnchors);
|
||||
registerStaticCompletion("MVConfigs", this::suggestMVConfig);
|
||||
registerStaticCompletion("gameRules", this::suggestGameRules);
|
||||
registerStaticCompletion("environments", this::suggestEnvironments);
|
||||
registerStaticCompletion("setProperties", this::suggestSetProperties);
|
||||
registerStaticCompletion("addProperties", this::suggestAddProperties);
|
||||
registerStaticCompletion("livingEntities", this::suggestEntities);
|
||||
registerStaticCompletion("pasteTypes", this::suggestPasteTypes);
|
||||
registerStaticCompletion("toggles", this::suggestToggles);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestFlags(@NotNull BukkitCommandCompletionContext context) {
|
||||
final MultiverseCommand command = MVCommandReflect.getCommandCompletionContextCommand(context);
|
||||
if (command == null) {
|
||||
Logging.warning("Unable to parse flags as MultiverseCommand not found!");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
FlagGroup flagGroup = command.getFlagGroup();
|
||||
String[] args = context.getContextValue(String[].class);
|
||||
CommandFlag<?> flag = (args.length <= 1) ? null : flagGroup.getByKey(args[args.length - 2]);
|
||||
|
||||
if (flag == null || flag.getValueRequirement() == ValueRequirement.NONE) {
|
||||
// suggest new flags.
|
||||
return getRemainingFlagIdentifiers(flagGroup, args);
|
||||
}
|
||||
|
||||
Collection<String> flagSuggestions = flag.suggestValue();
|
||||
|
||||
if (flag.getValueRequirement() == ValueRequirement.OPTIONAL) {
|
||||
// suggest new flags and values.
|
||||
flagSuggestions.addAll(getRemainingFlagIdentifiers(flagGroup, args));
|
||||
return flagSuggestions;
|
||||
}
|
||||
// suggest new values.
|
||||
return flagSuggestions == null ? Collections.emptySet() : flagSuggestions;
|
||||
}
|
||||
|
||||
private Collection<String> getRemainingFlagIdentifiers(FlagGroup flagGroup, String[] args) {
|
||||
Set<String> identifiersRemaining = new HashSet<>(flagGroup.getFlagIdentifiers());
|
||||
identifiersRemaining.removeAll(Arrays.asList(args));
|
||||
return identifiersRemaining;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestScripts(@NotNull BukkitCommandCompletionContext context) {
|
||||
Buscript scriptAPI = this.plugin.getScriptAPI();
|
||||
if (scriptAPI == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Arrays.stream(scriptAPI.getScriptFolder().listFiles())
|
||||
.unordered()
|
||||
.filter(File::isFile)
|
||||
.map(File::getName)
|
||||
.filter(fileName -> !fileName.equals("scripts.bin"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestSubCommands(@NotNull BukkitCommandCompletionContext context) {
|
||||
String rootCmdName = context.getConfig();
|
||||
if (rootCmdName == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
RootCommand rootCommand = this.plugin.getMVCommandManager().getRegisteredRootCommands().stream()
|
||||
.unordered()
|
||||
.filter(c -> c.getCommandName().equals(rootCmdName))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (rootCommand == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return rootCommand.getSubCommands().entries().stream()
|
||||
.unordered()
|
||||
.filter(entry -> checkPerms(context.getIssuer(), entry.getValue()))
|
||||
.map(Map.Entry::getKey)
|
||||
.filter(cmdName -> !cmdName.startsWith("__"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean checkPerms(@NotNull CommandIssuer issuer,
|
||||
@NotNull RegisteredCommand<?> cmd) {
|
||||
|
||||
return this.plugin.getMVCommandManager().hasPermission(issuer, cmd.getRequiredPermissions());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestMVWorlds(@NotNull BukkitCommandCompletionContext context) {
|
||||
if (isPlayerOnly(context)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.worldManager.getMVWorlds().parallelStream()
|
||||
.unordered()
|
||||
.map(MultiverseWorld::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestUnloadedWorlds(@NotNull BukkitCommandCompletionContext context) {
|
||||
if (isPlayerOnly(context)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.worldManager.getUnloadedWorlds();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestPotentialWorlds(@NotNull BukkitCommandCompletionContext context) {
|
||||
if (isPlayerOnly(context)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Collection<MultiverseWorld> worlds = this.worldManager.getMVWorlds();
|
||||
Set<String> knownWorlds = worlds.parallelStream()
|
||||
.unordered()
|
||||
.map(MultiverseWorld::getName)
|
||||
.collect(Collectors.toCollection(() -> new HashSet<>(worlds.size())));
|
||||
|
||||
return Arrays.stream(this.plugin.getServer().getWorldContainer().listFiles()).parallel()
|
||||
.unordered()
|
||||
.filter(File::isDirectory)
|
||||
.filter(file -> !knownWorlds.contains(file.getName()))
|
||||
.map(File::getName)
|
||||
.filter(this.worldManager::isValidWorld)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestLocation(@NotNull BukkitCommandCompletionContext context) {
|
||||
if (isPlayerOnly(context)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Player player = context.getPlayer();
|
||||
if (player == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat();
|
||||
df.setMinimumFractionDigits(0);
|
||||
df.setMaximumFractionDigits(2);
|
||||
|
||||
Location playerLocation = player.getLocation();
|
||||
double coordValue;
|
||||
switch (context.getConfig()) {
|
||||
case "x":
|
||||
coordValue = playerLocation.getX();
|
||||
break;
|
||||
case "y":
|
||||
coordValue = playerLocation.getY();
|
||||
break;
|
||||
case "z":
|
||||
coordValue = playerLocation.getZ();
|
||||
break;
|
||||
case "yaw":
|
||||
coordValue = playerLocation.getYaw();
|
||||
break;
|
||||
case "pitch":
|
||||
coordValue = playerLocation.getPitch();
|
||||
break;
|
||||
default:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Collections.singletonList(df.format(coordValue));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestDestinations(@NotNull BukkitCommandCompletionContext context) {
|
||||
if (isPlayerOnly(context)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.plugin.getDestFactory().getIdentifiers().parallelStream()
|
||||
.unordered()
|
||||
.filter(id -> !id.isEmpty())
|
||||
.map(id -> id + ":")
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestAnchors(@NotNull BukkitCommandCompletionContext context) {
|
||||
if (isPlayerOnly(context)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.plugin.getAnchorManager().getAnchors(context.getPlayer());
|
||||
}
|
||||
|
||||
private boolean isPlayerOnly(@NotNull BukkitCommandCompletionContext context) {
|
||||
String config = context.getConfig();
|
||||
return config != null && context.getPlayer() == null && config.equals("playerOnly");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestMVConfig() {
|
||||
final Set<String> configOptions = this.plugin.getMVConfig().serialize().keySet();
|
||||
configOptions.remove("version");
|
||||
return configOptions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestGameRules() {
|
||||
return Arrays.stream(GameRule.values())
|
||||
.map(GameRule::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestEnvironments() {
|
||||
return Arrays.stream(World.Environment.values())
|
||||
.map(e -> e.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Collection<String> suggestSetProperties() {
|
||||
return this.worldManager.getMVWorlds().iterator().next().getAllPropertyTypes();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestAddProperties() {
|
||||
return Arrays.stream(AddProperties.values())
|
||||
.map(p -> p.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestEntities() {
|
||||
return Arrays.stream(EntityType.values())
|
||||
.filter(e -> e.isAlive() && e.isSpawnable())
|
||||
.map(e -> e.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestPasteTypes() {
|
||||
return Arrays.stream(PasteServiceType.values())
|
||||
.filter(pt -> pt != PasteServiceType.GITHUB && pt != PasteServiceType.NONE)
|
||||
.map(p -> p.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestToggles() {
|
||||
return Arrays.asList("on", "off");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import co.aikar.commands.BukkitConditionContext;
|
||||
import co.aikar.commands.CommandConditions;
|
||||
import co.aikar.commands.ConditionContext;
|
||||
import co.aikar.commands.ConditionFailedException;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import com.onarandombox.MultiverseCore.enums.WorldValidationResult;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Args input validation.
|
||||
*/
|
||||
public class MVCommandConditions {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final MVWorldManager worldManager;
|
||||
|
||||
public MVCommandConditions(@NotNull MultiverseCore plugin,
|
||||
@NotNull CommandConditions<BukkitCommandIssuer, BukkitCommandExecutionContext, BukkitConditionContext> conditions) {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.worldManager = plugin.getMVWorldManager();
|
||||
|
||||
conditions.addCondition(String.class, "isMVWorld", this::checkIsMVWorld);
|
||||
conditions.addCondition(String.class, "isUnloadedWorld", this::checkIsUnloadedWorld);
|
||||
conditions.addCondition(String.class, "isWorldInConfig", this::checkIsWorldInConfig);
|
||||
conditions.addCondition(String.class, "creatableWorldName", this::checkCreatableWorldName);
|
||||
conditions.addCondition(String.class, "importableWorldName", this::checkImportableWorldName);
|
||||
conditions.addCondition(String.class, "validWorldFolder", this::checkValidWorldFolder);
|
||||
conditions.addCondition(String.class, "validAddProperty", this::checkValidAddProperty);
|
||||
conditions.addCondition(MultiverseWorld.class, "hasWorldAccess", this::checkHasWorldAccess);
|
||||
}
|
||||
|
||||
private void checkIsMVWorld(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
if (!this.worldManager.isMVWorld(worldName)) {
|
||||
throw new ConditionFailedException(String.format("World '%s' not found.", worldName));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIsUnloadedWorld(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
throw new ConditionFailedException(String.format("World '%s' is already loaded.", worldName));
|
||||
}
|
||||
|
||||
if (!this.worldManager.getUnloadedWorlds().contains(worldName)) {
|
||||
if (this.worldManager.isValidWorld(worldName)) {
|
||||
CommandSender sender = executionContext.getSender();
|
||||
sender.sendMessage(String.format("%sMultiverse does not know about world '%s' yet. Please import it with %s/mv import %s <env>%s.",
|
||||
ChatColor.RED, worldName, ChatColor.AQUA, worldName, ChatColor.RED));
|
||||
sender.sendMessage(String.format("See %s/mv help import %sfor more info.",
|
||||
ChatColor.AQUA, ChatColor.WHITE));
|
||||
throw new ConditionFailedException();
|
||||
}
|
||||
throw new ConditionFailedException(String.format("World '%s' not found.", worldName));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIsWorldInConfig(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
if (!this.worldManager.hasUnloadedWorld(worldName, true)) {
|
||||
throw new ConditionFailedException(String.format("World '%s' not found.", worldName));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCreatableWorldName(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
throw new ConditionFailedException(String.format("%sMultiverse cannot create %sanother %s%sworld named '%s'.",
|
||||
ChatColor.RED, ChatColor.GOLD, ChatColor.RESET, ChatColor.RED, worldName));
|
||||
}
|
||||
|
||||
WorldValidationResult validationResult = this.worldManager.validateWorld(worldName);
|
||||
validateWorldNameResult(validationResult);
|
||||
|
||||
if (validationResult != WorldValidationResult.DOES_NOT_EXIST && validationResult != WorldValidationResult.NOT_A_DIRECTORY) {
|
||||
CommandSender sender = executionContext.getSender();
|
||||
if (validationResult == WorldValidationResult.VALID) {
|
||||
sender.sendMessage(String.format("%sWorld Folder '%s' already look like a world to me! You can try importing it with %s/mv import%s.",
|
||||
ChatColor.RED, worldName, ChatColor.AQUA, ChatColor.RED));
|
||||
sender.sendMessage(String.format("See %s/mv help import %sfor more info.",
|
||||
ChatColor.AQUA, ChatColor.WHITE));
|
||||
throw new ConditionFailedException();
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("%sA folder already exists with this name!", ChatColor.RED));
|
||||
throw new ConditionFailedException();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkImportableWorldName(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
executionContext.getSender().sendMessage(String.format("%sMultiverse %s already knows about %s%s%s!",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, worldName, ChatColor.WHITE));
|
||||
throw new ConditionFailedException();
|
||||
}
|
||||
|
||||
checkValidWorldFolder(context, executionContext, worldName);
|
||||
}
|
||||
|
||||
private void checkValidWorldFolder(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
WorldValidationResult validationResult = this.worldManager.validateWorld(worldName);
|
||||
validateWorldNameResult(validationResult);
|
||||
validateWorldFolderResult(validationResult, worldName);
|
||||
}
|
||||
|
||||
private void validateWorldNameResult(WorldValidationResult validationResult) {
|
||||
switch (validationResult) {
|
||||
case NAME_BLACKLISTED:
|
||||
throw new ConditionFailedException("World should not be in reserved server folders.");
|
||||
case NAME_CONTAINS_DAT:
|
||||
throw new ConditionFailedException("Multiverse cannot have a world name that contains '.dat'.");
|
||||
case NAME_INVALID:
|
||||
throw new ConditionFailedException("World name should not contain spaces or special characters! Please rename your world folder.");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateWorldFolderResult(@NotNull WorldValidationResult validationResult,
|
||||
@NotNull String worldName) {
|
||||
switch (validationResult) {
|
||||
case DOES_NOT_EXIST:
|
||||
case NOT_A_DIRECTORY:
|
||||
throw new ConditionFailedException(String.format("World folder '%s' does not exist.", worldName));
|
||||
case FOLDER_LACK_DAT:
|
||||
throw new ConditionFailedException(String.format("'%s' does not appear to be a world! It is lacking .dat file.", worldName));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkValidAddProperty (@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String property) {
|
||||
|
||||
String actionType = context.getConfig();
|
||||
if (actionType.equalsIgnoreCase("set")) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AddProperties.valueOf(property);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
CommandSender sender = executionContext.getSender();
|
||||
sender.sendMessage(String.format("%sSorry, you can't use %s with '%s'.",
|
||||
ChatColor.RED, actionType, property));
|
||||
sender.sendMessage(String.format("%sPlease visit our Github Wiki for more information: https://goo.gl/q1h01S",
|
||||
ChatColor.AQUA));
|
||||
throw new ConditionFailedException();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkHasWorldAccess(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull MultiverseWorld world) {
|
||||
|
||||
Player player = executionContext.getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.plugin.getMVPerms().canEnterWorld(player, world)) {
|
||||
throw new ConditionFailedException(String.format("You aren't allowed to access to world '%s%s'!",
|
||||
world.getColoredWorldString(), ChatColor.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.PaperCommandContexts;
|
||||
import co.aikar.commands.annotation.Values;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.GameRuleProperty;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.PageFilter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.RequiredPlayer;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
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.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Parse args into objects.
|
||||
*/
|
||||
public class MVCommandContexts extends PaperCommandContexts {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final MVWorldManager worldManager;
|
||||
|
||||
private static final Pattern UUID_REGEX = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}");
|
||||
private static final Pattern TRIM_REGEX = Pattern.compile("^[./\\\\]+");
|
||||
|
||||
public MVCommandContexts(@NotNull MVCommandManager manager,
|
||||
@NotNull MultiverseCore plugin) {
|
||||
|
||||
super(manager);
|
||||
this.plugin = plugin;
|
||||
this.worldManager = plugin.getMVWorldManager();
|
||||
|
||||
registerContext(RequiredPlayer.class, this::deriveRequiredPlayer);
|
||||
registerIssuerOnlyContext(Player.class, this::derivePlayer);
|
||||
|
||||
registerIssuerAwareContext(MultiverseWorld.class, this::deriveMultiverseWorld);
|
||||
registerContext(World.Environment.class, this::deriveEnvironment);
|
||||
registerIssuerAwareContext(GameRuleProperty.class, this::deriveGameRuleProperty);
|
||||
registerIssuerAwareContext(MVDestination.class, this::deriveMVDestination);
|
||||
registerIssuerAwareContext(PasteServiceType.class, this::derivePasteServiceType);
|
||||
registerOptionalContext(String.class, this::deriveString);
|
||||
registerIssuerAwareContext(ContentFilter.class, this::deriveContentFilter);
|
||||
registerOptionalContext(PageFilter.class, this::derivePageFilter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Player derivePlayer(@NotNull BukkitCommandExecutionContext context) {
|
||||
Player player = context.getPlayer();
|
||||
if (player == null) {
|
||||
throw new InvalidCommandArgument("You must be a player to run this command.");
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private RequiredPlayer deriveRequiredPlayer(BukkitCommandExecutionContext context) {
|
||||
String playerIdentifier = context.getFirstArg();
|
||||
Player player = getPlayerFromValue(context.getSender(), playerIdentifier);
|
||||
if (player == null) {
|
||||
throw new InvalidCommandArgument("Invalid player name '" + playerIdentifier + "'!");
|
||||
}
|
||||
return new RequiredPlayer(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MultiverseWorld deriveMultiverseWorld(@NotNull BukkitCommandExecutionContext context) {
|
||||
if (!context.hasFlag("other")) {
|
||||
return getPlayerWorld(
|
||||
context.getPlayer(),
|
||||
context.isOptional()
|
||||
, "You cannot run this command from console."
|
||||
);
|
||||
}
|
||||
|
||||
String worldName = context.getFirstArg();
|
||||
if (worldName == null) {
|
||||
if (context.hasFlag("defaultself")) {
|
||||
return getPlayerWorld(
|
||||
context.getPlayer(),
|
||||
context.isOptional()
|
||||
, "You need to specific a world name from console."
|
||||
);
|
||||
}
|
||||
if (context.isOptional()) {
|
||||
return null;
|
||||
}
|
||||
throw new InvalidCommandArgument("You need to specific a world name.");
|
||||
}
|
||||
|
||||
MultiverseWorld world = getWorld(context.getSender(), worldName, !context.hasFlag("ignoreunload"));
|
||||
if (world == null) {
|
||||
if (context.hasFlag("fallbackself")) {
|
||||
return getPlayerWorld(context.getPlayer(),
|
||||
context.isOptional(),
|
||||
String.format("World '%s' not found.", worldName));
|
||||
}
|
||||
if (this.worldManager.isValidWorld(worldName)) {
|
||||
CommandSender sender = context.getSender();
|
||||
sender.sendMessage(String.format("%sMultiverse does not know about world '%s' yet. Please import it with %s/mv import %s <env>%s.",
|
||||
ChatColor.RED, worldName, ChatColor.AQUA, worldName, ChatColor.RED));
|
||||
sender.sendMessage(String.format("See %s/mv help import %sfor more info.",
|
||||
ChatColor.AQUA, ChatColor.WHITE));
|
||||
throw new InvalidCommandArgument();
|
||||
}
|
||||
throw new InvalidCommandArgument(String.format("World '%s' not found.", worldName), false);
|
||||
}
|
||||
|
||||
context.popFirstArg();
|
||||
return world;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MultiverseWorld getWorld(@NotNull CommandSender sender,
|
||||
@NotNull String worldName,
|
||||
boolean checkUnloaded) {
|
||||
|
||||
MultiverseWorld targetWorld = this.worldManager.getMVWorld(worldName);
|
||||
if (targetWorld != null) {
|
||||
return targetWorld;
|
||||
}
|
||||
|
||||
//TODO: API should have a isUnloadedWorld method.
|
||||
if (checkUnloaded && this.worldManager.getUnloadedWorlds().contains(worldName)) {
|
||||
sender.sendMessage(String.format("%sWorld '%s' exists, but it is unloaded!", ChatColor.RED, worldName));
|
||||
sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, worldName));
|
||||
throw new InvalidCommandArgument();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MultiverseWorld getPlayerWorld(@Nullable Player player,
|
||||
boolean allowNull,
|
||||
@NotNull String errorReason) {
|
||||
|
||||
if (player == null) {
|
||||
if (allowNull) {
|
||||
return null;
|
||||
}
|
||||
throw new InvalidCommandArgument(errorReason, false);
|
||||
}
|
||||
|
||||
MultiverseWorld targetWorld = this.worldManager.getMVWorld(player.getWorld());
|
||||
if (targetWorld == null) {
|
||||
player.sendMessage(String.format("%sMultiverse doesn't know about world '%s%s%s' that '%s%s%s' is in.",
|
||||
ChatColor.RED, ChatColor.DARK_AQUA, player.getWorld().getName(), ChatColor.RED,
|
||||
ChatColor.AQUA, player.getName(), ChatColor.RED));
|
||||
|
||||
player.sendMessage(String.format("You need to import the world with %s/mv import %s %s",
|
||||
ChatColor.DARK_AQUA, player.getWorld().getName(), player.getWorld().getEnvironment()));
|
||||
|
||||
throw new InvalidCommandArgument();
|
||||
}
|
||||
|
||||
return targetWorld;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Player getPlayerFromSelf(@NotNull BukkitCommandExecutionContext context, String errorReason) {
|
||||
Player self = context.getPlayer();
|
||||
if (self == null && !context.isOptional()) {
|
||||
throw new InvalidCommandArgument(errorReason);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Player from string.
|
||||
* Supports player name, UUID and selectors.
|
||||
*
|
||||
* @param sender Sender use to parse vanilla selectors.
|
||||
* @param playerIdentifier Text to parse into a Player object.
|
||||
* @return A Player object if found, null otherwise.
|
||||
*/
|
||||
@Nullable
|
||||
public Player getPlayerFromValue(@NotNull CommandSender sender,
|
||||
@Nullable String playerIdentifier) {
|
||||
|
||||
if (playerIdentifier == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = getPlayerBySelector(sender, playerIdentifier);
|
||||
if (player == null) {
|
||||
player = Bukkit.getPlayerExact(playerIdentifier);
|
||||
}
|
||||
if (player == null) {
|
||||
player = getPlayerByUUID(playerIdentifier);
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Player getPlayerBySelector(@NotNull CommandSender sender,
|
||||
@NotNull String playerIdentifier) {
|
||||
|
||||
if (playerIdentifier.charAt(0) != '@') {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Player> matchedPlayers;
|
||||
try {
|
||||
matchedPlayers = this.plugin.getServer().selectEntities(sender, playerIdentifier).parallelStream()
|
||||
.unordered()
|
||||
.filter(e -> e instanceof Player)
|
||||
.map(e -> ((Player) e))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidCommandArgument(String.format("Error parsing selector '%s' for %s! See console for more details",
|
||||
playerIdentifier, sender.getName()));
|
||||
}
|
||||
if (matchedPlayers.isEmpty()) {
|
||||
throw new InvalidCommandArgument(String.format("No player found with selector '%s' for %s",
|
||||
playerIdentifier, sender.getName()));
|
||||
}
|
||||
if (matchedPlayers.size() > 1) {
|
||||
throw new InvalidCommandArgument(String.format("Error parsing selector '%s' for %s. ambiguous result (more than one player matched) - %s",
|
||||
playerIdentifier, sender.getName(), matchedPlayers.toString()));
|
||||
}
|
||||
|
||||
return matchedPlayers.get(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Player getPlayerByUUID(@NotNull String playerIdentifier) {
|
||||
if (!UUID_REGEX.matcher(playerIdentifier).matches()) {
|
||||
return null;
|
||||
}
|
||||
UUID playerUUID;
|
||||
try {
|
||||
playerUUID = UUID.fromString(playerIdentifier);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return Bukkit.getPlayer(playerUUID);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private World.Environment deriveEnvironment(@NotNull BukkitCommandExecutionContext context) {
|
||||
String env = context.popFirstArg();
|
||||
|
||||
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD")) {
|
||||
env = "NORMAL";
|
||||
}
|
||||
else if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER")) {
|
||||
env = "NETHER";
|
||||
}
|
||||
else if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS")) {
|
||||
env = "THE_END";
|
||||
}
|
||||
|
||||
try {
|
||||
return World.Environment.valueOf(env);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
CommandSender sender = context.getSender();
|
||||
sender.sendMessage(String.format("%s'%s' is not a valid environment.", ChatColor.RED, env));
|
||||
EnvironmentCommand.showEnvironments(sender);
|
||||
throw new InvalidCommandArgument(false);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private GameRuleProperty<?> deriveGameRuleProperty(@NotNull BukkitCommandExecutionContext context) {
|
||||
int argLength = context.getArgs().size();
|
||||
if (argLength == 0) {
|
||||
throw new InvalidCommandArgument("You need to specify a game rule property and value to set.");
|
||||
}
|
||||
if (argLength == 1) {
|
||||
throw new InvalidCommandArgument("You need to specify a value to set.");
|
||||
}
|
||||
|
||||
String ruleString = context.popFirstArg();
|
||||
GameRule<?> gameRule = GameRule.getByName(ruleString);
|
||||
if (gameRule == null) {
|
||||
throw new InvalidCommandArgument(String.format("'%s' is not a valid gamerule.", ruleString));
|
||||
}
|
||||
|
||||
Class<?> ruleType = gameRule.getType();
|
||||
String value = context.getFirstArg();
|
||||
Object result = getResolver(ruleType).getContext(context);
|
||||
if (result == null) {
|
||||
context.getSender().sendMessage(String.format("%s'%s' is not a valid value.", ChatColor.RED, value));
|
||||
context.getSender().sendMessage(String.format("%sValue need to be a %s", ChatColor.RED, ruleType.getTypeName()));
|
||||
throw new InvalidCommandArgument();
|
||||
}
|
||||
if (result instanceof Integer && ((int) result) < 0) {
|
||||
throw new InvalidCommandArgument("Value need to be a positive number.");
|
||||
}
|
||||
|
||||
return new GameRuleProperty(gameRule, result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private MVDestination deriveMVDestination(@NotNull BukkitCommandExecutionContext context) {
|
||||
String destString = context.popFirstArg();
|
||||
if (destString == null) {
|
||||
throw new InvalidCommandArgument("Please specify a destination.");
|
||||
}
|
||||
|
||||
MVDestination destination = this.plugin.getDestFactory().getDestination(destString);
|
||||
if (destination instanceof InvalidDestination) {
|
||||
throw new InvalidCommandArgument(String.format("No such destination '%s' found.", destString));
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String deriveString(@NotNull BukkitCommandExecutionContext context) {
|
||||
if (context.hasAnnotation(Values.class)) {
|
||||
return context.popFirstArg();
|
||||
}
|
||||
|
||||
String string = context.popFirstArg();
|
||||
if (string == null) {
|
||||
if (!context.isOptional()) {
|
||||
String argType = context.getFlagValue("type", "string");
|
||||
throw new InvalidCommandArgument(String.format("You need to specify a %s.", argType));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (context.hasFlag("trim")) {
|
||||
return trimWorldName(string);
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String trimWorldName(@NotNull String worldName) {
|
||||
// Removes relative paths.
|
||||
return TRIM_REGEX.matcher(worldName).replaceAll("");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PasteServiceType derivePasteServiceType(BukkitCommandExecutionContext context) {
|
||||
String pasteType = context.popFirstArg();
|
||||
if (pasteType == null) {
|
||||
return PasteServiceType.NONE;
|
||||
}
|
||||
|
||||
try {
|
||||
return PasteServiceType.valueOf(pasteType.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new InvalidCommandArgument(String.format("Invalid paste service type '%s'.", pasteType));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ContentFilter deriveContentFilter(@NotNull BukkitCommandExecutionContext context) {
|
||||
String filterString = context.popFirstArg();
|
||||
return (filterString == null) ? ContentFilter.DEFAULT : new ContentFilter(filterString);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PageFilter derivePageFilter(@NotNull BukkitCommandExecutionContext context) {
|
||||
int argLength = context.getArgs().size();
|
||||
if (argLength == 0) {
|
||||
return new PageFilter(ContentFilter.DEFAULT, 1);
|
||||
}
|
||||
if (argLength == 1) {
|
||||
String pageOrFilter = context.popFirstArg();
|
||||
Optional<Integer> page = tryParseInt(pageOrFilter);
|
||||
return page.map(pageNum -> new PageFilter(ContentFilter.DEFAULT, pageNum))
|
||||
.orElseGet(() -> new PageFilter(new ContentFilter(pageOrFilter), 1));
|
||||
}
|
||||
|
||||
String filter = context.popFirstArg();
|
||||
String pageString = context.popFirstArg();
|
||||
Optional<Integer> page = tryParseInt(pageString);
|
||||
if (!page.isPresent()) {
|
||||
throw new InvalidCommandArgument(String.format("'%s' is not a number.", pageString), false);
|
||||
}
|
||||
return new PageFilter(new ContentFilter(filter), page.get());
|
||||
}
|
||||
|
||||
private Optional<Integer> tryParseInt(String value) {
|
||||
try {
|
||||
return Optional.of(Integer.parseInt(value));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.HelpEntry;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commands.AnchorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.BedCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CheckCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CloneCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ConfigCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ConfirmCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.CoordCommand;
|
||||
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.GeneratorCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ImportCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.InfoCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ListCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.LoadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ModifyCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.PurgeCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RegenCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.ReloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RemoveCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.RootCommand;
|
||||
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.SubModulesCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.UnloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.UsageCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.VersionCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.WhoCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.displaytools.ColorAlternator;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Heart of Multiverse Command Handler.
|
||||
*/
|
||||
public class MVCommandManager extends PaperCommandManager {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final CommandQueueManager commandQueueManager;
|
||||
private final Map<String, BaseCommand> subModuleRootCommands;
|
||||
|
||||
private static final Pattern PERMISSION_SPLIT = Pattern.compile(",");
|
||||
|
||||
public MVCommandManager(@NotNull MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
this.commandQueueManager = new CommandQueueManager(plugin);
|
||||
this.subModuleRootCommands = new HashMap<>(3);
|
||||
new MVCommandConditions(plugin, getCommandConditions());
|
||||
|
||||
// Setup help command
|
||||
enableUnstableAPI("help");
|
||||
setDefaultHelpPerPage(6);
|
||||
|
||||
// General plugin command
|
||||
registerCommand(new RootCommand(this.plugin));
|
||||
registerCommand(new UsageCommand(this.plugin));
|
||||
registerCommand(new VersionCommand(this.plugin));
|
||||
|
||||
// World commands
|
||||
registerCommand(new CreateCommand(this.plugin));
|
||||
registerCommand(new ImportCommand(this.plugin));
|
||||
registerCommand(new LoadCommand(this.plugin));
|
||||
registerCommand(new UnloadCommand(this.plugin));
|
||||
registerCommand(new RemoveCommand(this.plugin));
|
||||
registerCommand(new CloneCommand(this.plugin));
|
||||
registerCommand(new RegenCommand(this.plugin));
|
||||
registerCommand(new DeleteCommand(this.plugin));
|
||||
registerCommand(new ConfirmCommand(this.plugin));
|
||||
|
||||
// Properties management commands
|
||||
registerCommand(new ConfigCommand(this.plugin));
|
||||
registerCommand(new GameRuleCommand(this.plugin));
|
||||
registerCommand(new ModifyCommand(this.plugin));
|
||||
registerCommand(new SetSpawnCommand(this.plugin));
|
||||
registerCommand(new PurgeCommand(this.plugin));
|
||||
|
||||
// Show information commands
|
||||
registerCommand(new InfoCommand(this.plugin));
|
||||
registerCommand(new CoordCommand(this.plugin));
|
||||
registerCommand(new EnvironmentCommand(this.plugin));
|
||||
registerCommand(new GeneratorCommand(this.plugin));
|
||||
registerCommand(new ListCommand(this.plugin));
|
||||
registerCommand(new WhoCommand(this.plugin));
|
||||
|
||||
// Teleport commands
|
||||
registerCommand(new TeleportCommand(this.plugin));
|
||||
registerCommand(new AnchorCommand(this.plugin));
|
||||
registerCommand(new BedCommand(this.plugin));
|
||||
registerCommand(new SpawnCommand(this.plugin));
|
||||
|
||||
// Misc commands
|
||||
registerCommand(new DebugCommand(this.plugin));
|
||||
registerCommand(new CheckCommand(this.plugin));
|
||||
registerCommand(new ReloadCommand(this.plugin));
|
||||
registerCommand(new SilentCommand(this.plugin));
|
||||
registerCommand(new ScriptCommand(this.plugin));
|
||||
|
||||
// Sub-modules
|
||||
addAvailableSubModule("mvnp", new SubModulesCommand.NetherPortals());
|
||||
addAvailableSubModule("mvp", new SubModulesCommand.Portals());
|
||||
addAvailableSubModule("mvinv", new SubModulesCommand.Inventories());
|
||||
}
|
||||
|
||||
/**
|
||||
* Use for download link suggestion for sub-module
|
||||
*
|
||||
* @param moduleName A sub-module for Multiverse.
|
||||
* @param cmd Command to register.
|
||||
*/
|
||||
private void addAvailableSubModule(@NotNull String moduleName,
|
||||
@NotNull BaseCommand cmd) {
|
||||
|
||||
subModuleRootCommands.put(moduleName, cmd);
|
||||
registerCommand(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace suggest download with actual command from sub-module.
|
||||
*
|
||||
* @param moduleName A sub-module for Multiverse.
|
||||
* @param cmd Command to register.
|
||||
*/
|
||||
public void registerSubModule(@NotNull String moduleName,
|
||||
@NotNull BaseCommand cmd) {
|
||||
|
||||
unregisterCommand(subModuleRootCommands.remove(moduleName));
|
||||
registerCommand(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized MVCommandContexts getCommandContexts() {
|
||||
if (this.contexts == null) {
|
||||
this.contexts = new MVCommandContexts(this, plugin);
|
||||
}
|
||||
return (MVCommandContexts) this.contexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized MVCommandCompletions getCommandCompletions() {
|
||||
if (this.completions == null) {
|
||||
this.completions = new MVCommandCompletions(this, plugin);
|
||||
}
|
||||
return (MVCommandCompletions) this.completions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change default implementation to be able to choose from OR / AND
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull CommandIssuer issuer,
|
||||
@Nullable Set<String> permissions) {
|
||||
|
||||
if (permissions == null || permissions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (permissions.contains("AND"))
|
||||
? andPermissionCheck(issuer, permissions)
|
||||
: orPermissionCheck(issuer, permissions);
|
||||
}
|
||||
|
||||
private boolean orPermissionCheck(@NotNull CommandIssuer issuer,
|
||||
@NotNull Set<String> permissions) {
|
||||
|
||||
return permissions.stream()
|
||||
.unordered()
|
||||
.anyMatch(permission -> hasPermission(issuer, permission));
|
||||
}
|
||||
|
||||
private boolean andPermissionCheck(@NotNull CommandIssuer issuer,
|
||||
@NotNull Set<String> permissions) {
|
||||
|
||||
return permissions.stream()
|
||||
.unordered()
|
||||
.allMatch(permission -> hasPermission(issuer, permission));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change default implementation to be able to choose from OR / AND
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull CommandIssuer issuer,
|
||||
@Nullable String permission) {
|
||||
|
||||
if (permission == null || permission.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (permission.startsWith("AND:")) {
|
||||
return Arrays.stream(PERMISSION_SPLIT.split(permission.substring(4)))
|
||||
.unordered()
|
||||
.allMatch(issuer::hasPermission);
|
||||
}
|
||||
return Arrays.stream(PERMISSION_SPLIT.split(permission))
|
||||
.unordered()
|
||||
.anyMatch(issuer::hasPermission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link CommandQueueManager}.
|
||||
*
|
||||
* @return {@link CommandQueueManager}.
|
||||
*/
|
||||
public CommandQueueManager getQueueManager() {
|
||||
return commandQueueManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardise usage command formatting for all mv modules.
|
||||
*
|
||||
* @param help The target {@link CommandHelp}.
|
||||
*/
|
||||
public void showUsage(@NotNull CommandHelp help) {
|
||||
List<HelpEntry> entries = help.getHelpEntries();
|
||||
|
||||
if (entries.size() == 1) {
|
||||
this.plugin.getMVCommandManager().getHelpFormatter().showDetailedHelp(help, entries.get(0));
|
||||
return;
|
||||
}
|
||||
|
||||
help.showHelp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardise root command for all mv modules.
|
||||
*
|
||||
* @param sender Sender to send the info to.
|
||||
* @param description mv-module's description and info.
|
||||
* @param color Special colour for each mv-module.
|
||||
* @param rootCmd mv-module's root command name.
|
||||
*/
|
||||
public void showPluginInfo(@NotNull CommandSender sender,
|
||||
@NotNull PluginDescriptionFile description,
|
||||
@NotNull ColorAlternator color,
|
||||
@NotNull String rootCmd) {
|
||||
|
||||
sender.sendMessage(String.format("%s%s %s| %sv%s",
|
||||
color.getThisColor(), description.getName(), ChatColor.DARK_GRAY,
|
||||
color.getThatColor(), description.getVersion()));
|
||||
|
||||
sender.sendMessage(String.format("%sSee %s/%s help %sfor commands available.",
|
||||
ChatColor.DARK_GREEN, ChatColor.GREEN, rootCmd, ChatColor.DARK_GREEN));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools;
|
||||
|
||||
import co.aikar.commands.CommandCompletionContext;
|
||||
import co.aikar.commands.RegisteredCommand;
|
||||
import com.onarandombox.MultiverseCore.utils.ReflectHelper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class MVCommandReflect {
|
||||
|
||||
private static final Field commandScope;
|
||||
private static final Field commandField;
|
||||
|
||||
static {
|
||||
commandField = ReflectHelper.getField(CommandCompletionContext.class, "command");
|
||||
commandScope = ReflectHelper.getField(RegisteredCommand.class, "scope");
|
||||
}
|
||||
|
||||
public static MultiverseCommand getCommandCompletionContextCommand(CommandCompletionContext context) {
|
||||
RegisteredCommand registeredCommand = ReflectHelper.getFieldValue(context, commandField);
|
||||
return ReflectHelper.getFieldValue(registeredCommand, commandScope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.flag.FlagGroup;
|
||||
|
||||
public class MultiverseCommand extends BaseCommand {
|
||||
|
||||
private FlagGroup flagGroup;
|
||||
|
||||
public MultiverseCommand() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FlagGroup getFlagGroup() {
|
||||
return flagGroup;
|
||||
}
|
||||
|
||||
public void setFlagGroup(FlagGroup flagGroup) {
|
||||
this.flagGroup = flagGroup;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/******************************************************************************
|
||||
* 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.context;
|
||||
|
||||
import org.bukkit.GameRule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Single key value pair for a game rule.
|
||||
*
|
||||
* @param <T> Type of GameRule property.
|
||||
*/
|
||||
public class GameRuleProperty<T> {
|
||||
|
||||
private final GameRule<T> gameRule;
|
||||
private final T value;
|
||||
|
||||
public GameRuleProperty(@NotNull GameRule<T> gameRule,
|
||||
@NotNull T value) {
|
||||
|
||||
this.gameRule = gameRule;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GameRule<T> getGameRule() {
|
||||
return gameRule;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
* 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.context;
|
||||
|
||||
import com.onarandombox.MultiverseCore.displaytools.ContentFilter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Filter and paging.
|
||||
*/
|
||||
public class PageFilter {
|
||||
private final ContentFilter filter;
|
||||
private final int page;
|
||||
|
||||
public PageFilter(@NotNull ContentFilter filter,
|
||||
int page) {
|
||||
this.filter = filter;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ContentFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.context;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RequiredPlayer {
|
||||
|
||||
private final Player player;
|
||||
|
||||
public RequiredPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player get() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Classes derived from parsing command args and context.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools.context;
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* <p>Represents a flag that can be used in commands. This works as a key value pair.</p>
|
||||
*
|
||||
* <p>Key is the {@link #identifier} and {@link #aliases} set.</p>
|
||||
* <p>Value is the {@link T} parsed based on 3 scenarios during command input:</p>
|
||||
* <ol>
|
||||
* <li>Flag completely not present. {@link #getDefaultValue()}</li>
|
||||
* <li>Flag key present but no value. {@link #getValue()}</li>
|
||||
* <li>Flag key and value present. {@link #getValue(String)}</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param <T> The flag Type.
|
||||
*/
|
||||
public abstract class CommandFlag<T> {
|
||||
|
||||
protected final String name;
|
||||
protected final String identifier;
|
||||
protected final Class<T> type;
|
||||
protected final ValueRequirement valueRequirement;
|
||||
protected final Collection<String> aliases;
|
||||
|
||||
protected CommandFlag(@NotNull String name,
|
||||
@NotNull String identifier,
|
||||
@NotNull Class<T> type,
|
||||
@NotNull ValueRequirement valueRequirement) {
|
||||
|
||||
this.name = name;
|
||||
this.identifier = identifier;
|
||||
this.type = type;
|
||||
this.valueRequirement = valueRequirement;
|
||||
this.aliases = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets name of the Command Flag.
|
||||
*
|
||||
* @return The Command Flag name.
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets identifier of the Command Flag.
|
||||
*
|
||||
* @return The Command Flag identifier.
|
||||
*/
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link T} Type of the Command Flag.
|
||||
*
|
||||
* @return The Command Flag type.
|
||||
*/
|
||||
@NotNull
|
||||
public Class<T> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the requirements of this Command Flag user input value.
|
||||
*
|
||||
* @return The {@link ValueRequirement}.
|
||||
*/
|
||||
@NotNull
|
||||
public ValueRequirement getValueRequirement() {
|
||||
return this.valueRequirement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the alternative key identifiers set for this Command Flag.
|
||||
*
|
||||
* @return Collection of aliases.
|
||||
*/
|
||||
@NotNull
|
||||
public Collection<String> getAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add alternative key identifiers for this Command Flag.
|
||||
*
|
||||
* @param aliases Alias(es) to be added.
|
||||
* @return A {@link CommandFlag}.
|
||||
*/
|
||||
public CommandFlag<T> addAliases(String...aliases) {
|
||||
Collections.addAll(this.aliases, aliases);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab-complete suggestion for this Command Flag values.
|
||||
*
|
||||
* @return Collection of suggested values available.
|
||||
*/
|
||||
public abstract Collection<String> suggestValue();
|
||||
|
||||
/**
|
||||
* When this Command Flag can get value by a user input.
|
||||
*
|
||||
* @return The {@link T} value.
|
||||
*/
|
||||
public abstract T getValue(@NotNull String input) throws FlagParseFailedException;
|
||||
|
||||
/**
|
||||
* When this Command Flag user input value is null/not present.
|
||||
*
|
||||
* @return The {@link T} value.
|
||||
*/
|
||||
public T getValue() throws FlagParseFailedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* When this Command Flag is not present in command input.
|
||||
*
|
||||
* @return The {@link T} value.
|
||||
*/
|
||||
public T getDefaultValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CommandFlag{" +
|
||||
"name='" + name + '\'' +
|
||||
", identifier='" + identifier + '\'' +
|
||||
", type=" + type +
|
||||
", valueRequirement=" + valueRequirement +
|
||||
", aliases=" + aliases +
|
||||
'}';
|
||||
}
|
||||
|
||||
public enum ValueRequirement {
|
||||
/**
|
||||
* No user input needed for value.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* User input for value is optional.
|
||||
*/
|
||||
OPTIONAL,
|
||||
|
||||
/**
|
||||
* User input is required for Command Flag value.
|
||||
*/
|
||||
REQUIRED
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CoreFlags {
|
||||
|
||||
private static MultiverseCore multiverse;
|
||||
|
||||
public static void setCoreInstance(MultiverseCore plugin) {
|
||||
multiverse = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag for custom seed.
|
||||
*/
|
||||
public static final CommandFlag<String> SEED = new RequiredCommandFlag<String>
|
||||
("Seed", "--seed", String.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Collections.singleton(String.valueOf(new Random().nextLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
return input;
|
||||
}
|
||||
}.addAliases("-s");
|
||||
|
||||
/**
|
||||
* Flag for custom seed. No value means random seed.
|
||||
*/
|
||||
public static final CommandFlag<String> RANDOM_SEED = new OptionalCommandFlag<String>
|
||||
("Seed", "--seed", String.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Collections.singletonList(String.valueOf(new Random().nextLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
return input;
|
||||
}
|
||||
}.addAliases("-s");
|
||||
|
||||
/**
|
||||
* Flag for world type used.
|
||||
*/
|
||||
public static final CommandFlag<WorldType> WORLD_TYPE = new RequiredCommandFlag<WorldType>
|
||||
("WorldType", "--type", WorldType.class) {
|
||||
|
||||
private final Map<String, WorldType> typeAlias = new HashMap<String, WorldType>(4){{
|
||||
put("normal", WorldType.NORMAL);
|
||||
put("flat", WorldType.FLAT);
|
||||
put("largebiomes", WorldType.LARGE_BIOMES);
|
||||
put("amplified", WorldType.AMPLIFIED);
|
||||
}};
|
||||
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return typeAlias.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
WorldType type = typeAlias.get(input);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
try {
|
||||
return WorldType.valueOf(input.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new FlagParseFailedException("'%s' is not a valid. See /mv env for available World Type.", input);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getDefaultValue() {
|
||||
return WorldType.NORMAL;
|
||||
}
|
||||
}.addAliases("-t");
|
||||
|
||||
/**
|
||||
* Flag for world generator.
|
||||
*/
|
||||
public static final CommandFlag<String> GENERATOR = new RequiredCommandFlag<String>
|
||||
("Generator", "--gen", String.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins())
|
||||
.filter(Plugin::isEnabled)
|
||||
.filter(plugin -> multiverse.getUnsafeCallWrapper().wrap(
|
||||
() -> plugin.getDefaultWorldGenerator("world", ""),
|
||||
plugin.getName(),
|
||||
"Get generator"
|
||||
) != null)
|
||||
.map(plugin -> plugin.getDescription().getName())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
String[] genArray = input.split(":");
|
||||
String generator = genArray[0];
|
||||
String generatorId = (genArray.length > 1) ? genArray[1] : "";
|
||||
try {
|
||||
if (multiverse.getMVWorldManager().getChunkGenerator(generator, generatorId, "test") == null) {
|
||||
throw new Exception();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new FlagParseFailedException("Invalid generator string '%s'. See /mv gens for available generators.", input);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}.addAliases("-g");
|
||||
|
||||
/**
|
||||
* Flag to toggle if world should generate structures.
|
||||
*/
|
||||
public static final CommandFlag<Boolean> GENERATE_STRUCTURES = new RequiredCommandFlag<Boolean>
|
||||
("GenerateStructures", "--structures", Boolean.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Arrays.asList("true", "false");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
return input.equalsIgnoreCase("true");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getDefaultValue() {
|
||||
return true;
|
||||
}
|
||||
}.addAliases("--structure", "-a");
|
||||
|
||||
/**
|
||||
* Flag to toggle if world spawn should be adjusted.
|
||||
*/
|
||||
public static final CommandFlag<Boolean> SPAWN_ADJUST = new NoValueCommandFlag<Boolean>
|
||||
("AdjustSpawn", "--dont-adjust-spawn", Boolean.class) {
|
||||
@Override
|
||||
public Boolean getValue() throws FlagParseFailedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getDefaultValue() {
|
||||
return true;
|
||||
}
|
||||
}.addAliases("-n");
|
||||
|
||||
/**
|
||||
* Flag to specify a paste service.
|
||||
*/
|
||||
public static final CommandFlag<PasteServiceType> PASTE_SERVICE_TYPE = new OptionalCommandFlag<PasteServiceType>
|
||||
("PasteServiceType", "--paste", PasteServiceType.class) {
|
||||
|
||||
private final List<String> pasteTypes = Arrays.stream(PasteServiceType.values())
|
||||
.filter(pt -> pt != PasteServiceType.NONE)
|
||||
.map(p -> p.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return pasteTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PasteServiceType getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
try {
|
||||
return PasteServiceType.valueOf(input.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new InvalidCommandArgument(String.format("Invalid paste service type '%s'.", input));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PasteServiceType getValue() throws FlagParseFailedException {
|
||||
return PasteServiceType.PASTEGG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PasteServiceType getDefaultValue() {
|
||||
return PasteServiceType.NONE;
|
||||
}
|
||||
}.addAliases("-p");
|
||||
|
||||
/**
|
||||
* Flag to toggle if plugin list should be included.
|
||||
*/
|
||||
public static final CommandFlag<Boolean> INCLUDE_PLUGIN_LIST = new NoValueCommandFlag<Boolean>
|
||||
("IncludePlugins", "--include-plugin-list", Boolean.class) {
|
||||
@Override
|
||||
public Boolean getValue() throws FlagParseFailedException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getDefaultValue() {
|
||||
return true;
|
||||
}
|
||||
}.addAliases("-pl");
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FlagGroup {
|
||||
|
||||
public static FlagGroup of(CommandFlag<?>...flags) {
|
||||
return new FlagGroup(flags);
|
||||
}
|
||||
|
||||
private final List<String> flagIdentifiers;
|
||||
private final Map<String, CommandFlag<?>> flagKeyMap;
|
||||
|
||||
private FlagGroup(CommandFlag<?>[] commandFlags) {
|
||||
this.flagIdentifiers = new ArrayList<>(commandFlags.length);
|
||||
this.flagKeyMap = new HashMap<>();
|
||||
for (CommandFlag<?> flag : commandFlags) {
|
||||
addFlag(flag);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFlag(CommandFlag<?> flag) {
|
||||
this.flagIdentifiers.add(flag.getIdentifier());
|
||||
this.flagKeyMap.put(flag.getIdentifier(), flag);
|
||||
for (String flagAlias : flag.getAliases()) {
|
||||
this.flagKeyMap.put(flagAlias, flag);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FlagResult calculateResult(String[] args) {
|
||||
return FlagResult.parse(args,this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CommandFlag<?> getByKey(String key) {
|
||||
return this.flagKeyMap.get(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<String> getFlagIdentifiers() {
|
||||
return flagIdentifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FlagGroup{" +
|
||||
"flagIdentifiers=" + flagIdentifiers +
|
||||
", keyFlagMap=" + flagKeyMap +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
|
||||
public class FlagParseFailedException extends InvalidCommandArgument {
|
||||
|
||||
public FlagParseFailedException() {
|
||||
}
|
||||
|
||||
public FlagParseFailedException(String message, Object...replacements) {
|
||||
super(String.format(message, replacements), true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.onarandombox.MultiverseCore.commandtools.flag.CommandFlag.ValueRequirement;
|
||||
|
||||
public class FlagResult {
|
||||
|
||||
public static FlagResult parse(@Nullable String[] args,
|
||||
@NotNull FlagGroup flagGroup) throws FlagParseFailedException {
|
||||
|
||||
FlagResult flagResult = new FlagResult();
|
||||
|
||||
// No args to parse.
|
||||
if (args == null || args.length <= 0) {
|
||||
return flagResult;
|
||||
}
|
||||
|
||||
// First arg must be a flag.
|
||||
CommandFlag<?> currentFlag = flagGroup.getByKey(args[0]);
|
||||
boolean completed = false;
|
||||
|
||||
// Parse the arguments.
|
||||
for (int i = 1, argsLength = args.length; i <= argsLength; i++) {
|
||||
// Don't allow null flag obviously.
|
||||
if (currentFlag == null) {
|
||||
throw new FlagParseFailedException("%s is not a valid flag.", args[i-1]);
|
||||
}
|
||||
// THis ensures that flag is not null during final parse.
|
||||
if (i >= argsLength) {
|
||||
break;
|
||||
}
|
||||
|
||||
CommandFlag<?> nextFlag = flagGroup.getByKey(args[i]);
|
||||
|
||||
switch (currentFlag.getValueRequirement()) {
|
||||
case NONE:
|
||||
// Arg must be a flag key.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(), false);
|
||||
currentFlag = nextFlag;
|
||||
break;
|
||||
case OPTIONAL:
|
||||
// Arg can be a flag key or value.
|
||||
if (nextFlag != null) {
|
||||
// It's a key.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(), false);
|
||||
currentFlag = nextFlag;
|
||||
break;
|
||||
}
|
||||
// It's a value.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(args[i]), true);
|
||||
if (i == argsLength - 1) {
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
currentFlag = flagGroup.getByKey(args[++i]);
|
||||
break;
|
||||
case REQUIRED:
|
||||
// Arg must be a flag value.
|
||||
if (nextFlag != null) {
|
||||
// It's a key.
|
||||
throw new FlagParseFailedException("%s flag '%s' requires a value input.",
|
||||
currentFlag.getName(), currentFlag.getIdentifier());
|
||||
}
|
||||
// It's a value.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(args[i]), true);
|
||||
if (i == argsLength - 1) {
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
currentFlag = flagGroup.getByKey(args[++i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse final flag.
|
||||
if (!completed) {
|
||||
if (currentFlag.getValueRequirement() == ValueRequirement.REQUIRED) {
|
||||
throw new FlagParseFailedException("%s flag '%s' requires a value input.",
|
||||
currentFlag.getName(), currentFlag.getIdentifier());
|
||||
}
|
||||
flagResult.add(currentFlag, currentFlag.getValue(), false);
|
||||
}
|
||||
|
||||
return flagResult;
|
||||
}
|
||||
|
||||
private final Map<CommandFlag<?>, SingleFlagResult<?>> resultMap;
|
||||
|
||||
public FlagResult() {
|
||||
resultMap = new HashMap<>();
|
||||
}
|
||||
|
||||
private void add(CommandFlag<?> flag, Object value, boolean fromInput) {
|
||||
resultMap.put(flag, new SingleFlagResult<>(value, fromInput));
|
||||
}
|
||||
|
||||
public <T> T getValue(CommandFlag<T> flag) {
|
||||
SingleFlagResult<?> result = resultMap.get(flag);
|
||||
if (result == null) {
|
||||
return flag.getDefaultValue();
|
||||
}
|
||||
return (T) result.value;
|
||||
}
|
||||
|
||||
public boolean isByUserInput(CommandFlag<?> flag) {
|
||||
SingleFlagResult<?> result = resultMap.get(flag);
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
return result.fromInput;
|
||||
}
|
||||
|
||||
public boolean isDefaulted(CommandFlag<?> flag) {
|
||||
return resultMap.get(flag) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FlagResult{" +
|
||||
"resultMap=" + resultMap +
|
||||
'}';
|
||||
}
|
||||
|
||||
private class SingleFlagResult<T> {
|
||||
private final T value;
|
||||
private final boolean fromInput;
|
||||
|
||||
private SingleFlagResult(T value, boolean fromInput) {
|
||||
this.fromInput = fromInput;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SingleFlagResult{" +
|
||||
"value=" + value +
|
||||
", fromInput=" + fromInput +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Command Flag with {@link ValueRequirement#NONE}.
|
||||
* This flag will always not require a user input to parse value.
|
||||
*
|
||||
* @param <T> The flag Type.
|
||||
*/
|
||||
public abstract class NoValueCommandFlag<T> extends CommandFlag<T> {
|
||||
|
||||
public NoValueCommandFlag(String name, String identifier, Class<T> type) {
|
||||
super(name, identifier, type, ValueRequirement.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link NoValueCommandFlag} will always not require a user input to parse value.
|
||||
* Thus, no value suggestion needed.
|
||||
*/
|
||||
@Override
|
||||
public final Collection<String> suggestValue() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link NoValueCommandFlag} will always not require a user input to parse value.
|
||||
* Thus, this operation is not allowed.
|
||||
*/
|
||||
@Override
|
||||
public final T getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
throw new FlagParseFailedException("%s flag '%s' does not require a value.", this.name, this.identifier);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
/**
|
||||
* Command Flag with {@link ValueRequirement#OPTIONAL}.
|
||||
*
|
||||
* @param <T> The flag Type.
|
||||
*/
|
||||
public abstract class OptionalCommandFlag<T> extends CommandFlag<T> {
|
||||
|
||||
public OptionalCommandFlag(String name, String identifier, Class<T> type) {
|
||||
super(name, identifier, type, ValueRequirement.OPTIONAL);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools.flag;
|
||||
|
||||
/**
|
||||
* Command Flag with {@link ValueRequirement#REQUIRED}.
|
||||
* This flag will always require a user input to parse value.
|
||||
*
|
||||
* @param <T> The flag Type.
|
||||
*/
|
||||
public abstract class RequiredCommandFlag<T> extends CommandFlag<T> {
|
||||
|
||||
public RequiredCommandFlag(String name, String identifier, Class<T> type) {
|
||||
super(name, identifier, type, ValueRequirement.REQUIRED);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link RequiredCommandFlag} will always require a user input to parse value.
|
||||
* Thus, this operation is not allowed.
|
||||
*/
|
||||
@Override
|
||||
public final T getValue() throws FlagParseFailedException {
|
||||
throw new FlagParseFailedException("%s flag '%s' requires a value input.", this.name, this.identifier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Main classes used to manage commands.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools;
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
/******************************************************************************
|
||||
* 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.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Queue dangerous commands, with the need to use '/mv confirm' before executing.
|
||||
*/
|
||||
public class CommandQueueManager {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final Map<CommandSender, QueuedCommand> queuedCommandMap;
|
||||
|
||||
public CommandQueueManager(@NotNull MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.queuedCommandMap = new WeakHashMap<>();
|
||||
}
|
||||
|
||||
public void addToQueue(QueuedCommand queuedCommand) {
|
||||
CommandSender sender = queuedCommand.getSender();
|
||||
this.cancelPreviousInQueue(sender);
|
||||
this.queuedCommandMap.put(sender, queuedCommand);
|
||||
|
||||
queuedCommand.setExpireTask(runExpireLater(queuedCommand));
|
||||
|
||||
sender.sendMessage(queuedCommand.getPrompt());
|
||||
sender.sendMessage(String.format("Run %s/mv confirm %sto continue.", ChatColor.GREEN, ChatColor.WHITE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Since only one command is stored in queue per sender, we remove the old one.
|
||||
*
|
||||
* @param sender {@link CommandSender} that executed the command.
|
||||
*/
|
||||
private void cancelPreviousInQueue(@NotNull CommandSender sender) {
|
||||
QueuedCommand previousCommand = queuedCommandMap.get(sender);
|
||||
if (previousCommand == null) {
|
||||
return;
|
||||
}
|
||||
previousCommand.getExpireTask().cancel();
|
||||
this.queuedCommandMap.remove(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expire task that remove {@link QueuedCommand} from queue after expiry.
|
||||
*
|
||||
* @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()
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Runnable expireRunnable(@NotNull QueuedCommand queuedCommand) {
|
||||
return () -> {
|
||||
QueuedCommand matchingQueuedCommand = this.queuedCommandMap.get(queuedCommand.getSender());
|
||||
if (!queuedCommand.equals(matchingQueuedCommand)) {
|
||||
Logging.finer("This is an old command already.");
|
||||
return;
|
||||
}
|
||||
Logging.finer("Command has expired, removing...");
|
||||
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 of queued command ran successfully, false otherwise.
|
||||
*/
|
||||
public boolean runQueuedCommand(@NotNull CommandSender sender) {
|
||||
CommandSender targetSender = QueuedCommand.parseSender(sender);
|
||||
QueuedCommand queuedCommand = this.queuedCommandMap.get(targetSender);
|
||||
if (queuedCommand == null) {
|
||||
sender.sendMessage("You do not have any commands in queue.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Logging.finer("Running queued command...");
|
||||
queuedCommand.getAction().run();
|
||||
queuedCommand.getExpireTask().cancel();
|
||||
this.queuedCommandMap.remove(targetSender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+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() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
* 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 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;
|
||||
|
||||
/**
|
||||
* Represents a single command in {@link CommandQueueManager}.
|
||||
*/
|
||||
public class QueuedCommand {
|
||||
|
||||
private static final DummyCommandBlockSender COMMAND_BLOCK = new DummyCommandBlockSender();
|
||||
private static final String DEFAULT_PROMPT_MESSAGE = "The command you are trying to run is deemed dangerous.";
|
||||
private static final int DEFAULT_VALID_TIME = 200; // In ticks, 20 ticks = 1s
|
||||
|
||||
/**
|
||||
* To allow all CommandBlocks to be a common sender with use of {@link DummyCommandBlockSender}.
|
||||
* So confirm command can be used for a queue command on another command block.
|
||||
*/
|
||||
@NotNull
|
||||
static CommandSender parseSender(@NotNull CommandSender sender) {
|
||||
Logging.fine(sender.getClass().getName());
|
||||
if (isCommandBlock(sender)) {
|
||||
Logging.finer("Is command block.");
|
||||
return COMMAND_BLOCK;
|
||||
}
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if sender is a command block.
|
||||
*/
|
||||
static boolean isCommandBlock(@NotNull CommandSender sender) {
|
||||
return sender instanceof BlockCommandSender
|
||||
&& ((BlockCommandSender) sender).getBlock().getBlockData() instanceof CommandBlock;
|
||||
}
|
||||
|
||||
private CommandSender sender;
|
||||
private String prompt = DEFAULT_PROMPT_MESSAGE;
|
||||
private int validDuration = DEFAULT_VALID_TIME;
|
||||
private Runnable action;
|
||||
private BukkitTask expireTask;
|
||||
|
||||
private QueuedCommand() { }
|
||||
|
||||
@NotNull
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
public int getValidDuration() {
|
||||
return validDuration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Runnable getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitTask getExpireTask() {
|
||||
return expireTask;
|
||||
}
|
||||
|
||||
public void setExpireTask(@NotNull BukkitTask expireTask) {
|
||||
this.expireTask = expireTask;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final QueuedCommand command;
|
||||
|
||||
@NotNull
|
||||
public Builder() {
|
||||
this.command = new QueuedCommand();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder sender(@NotNull CommandSender sender) {
|
||||
this.command.sender = sender;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder action(@NotNull Runnable action) {
|
||||
this.command.action = action;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder prompt(@NotNull String prompt, Object...replacements) {
|
||||
this.command.prompt = String.format(prompt, replacements);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Builder validDuration(int validDuration) {
|
||||
this.command.validDuration = validDuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public QueuedCommand build() {
|
||||
return this.command;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Manager queuing of dangerous commands in need of confirmation.
|
||||
*/
|
||||
package com.onarandombox.MultiverseCore.commandtools.queue;
|
||||
@@ -22,6 +22,8 @@ public class EntryFee extends SerializationConfig {
|
||||
@Nullable
|
||||
private Material currency;
|
||||
|
||||
private final Material DISABLED_MATERIAL = Material.AIR;
|
||||
|
||||
public EntryFee() {
|
||||
super();
|
||||
}
|
||||
@@ -51,6 +53,9 @@ public class EntryFee extends SerializationConfig {
|
||||
*/
|
||||
@Nullable
|
||||
public Material getCurrency() {
|
||||
if (currency == null || currency.equals(DISABLED_MATERIAL)) {
|
||||
return null;
|
||||
}
|
||||
return currency;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.bukkit.util.Vector;
|
||||
* A bed-{@link MVDestination}.
|
||||
*/
|
||||
public class BedDestination implements MVDestination {
|
||||
public static final String OLD_BED_STRING = "b:playerbed";
|
||||
public static final String OWN_BED_STRING = "playerbed";
|
||||
private String playername = "";
|
||||
private boolean isValid;
|
||||
private Location knownBedLoc;
|
||||
@@ -46,11 +46,11 @@ public class BedDestination implements MVDestination {
|
||||
boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
||||
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]);
|
||||
boolean validPlayer = (p != null);
|
||||
boolean validPlayer = p.getName() != null && !p.getName().equals(OWN_BED_STRING);
|
||||
|
||||
if (validFormat && validPlayer) this.playername = p.getName();
|
||||
|
||||
this.isValid = destination.equals(OLD_BED_STRING) || (validFormat && validPlayer);
|
||||
this.isValid = destination.equals("b:" + OWN_BED_STRING) || (validFormat && validPlayer);
|
||||
|
||||
return this.isValid;
|
||||
}
|
||||
@@ -136,6 +136,6 @@ public class BedDestination implements MVDestination {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return playername.isEmpty() ? OLD_BED_STRING : ("b:" + playername);
|
||||
return "b:" + (playername.isEmpty() ? OWN_BED_STRING : playername);
|
||||
}
|
||||
}
|
||||
@@ -7,33 +7,76 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
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.pneumaticraft.commandhandler.Command;
|
||||
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.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** A factory class that will create destinations from specific strings. */
|
||||
public class DestinationFactory {
|
||||
private MultiverseCore plugin;
|
||||
private Map<String, Class<? extends MVDestination>> destList;
|
||||
private Command teleportCommand;
|
||||
private final MultiverseCore plugin;
|
||||
private final Map<String, Class<? extends MVDestination>> destList;
|
||||
private final Set<String> destPermissions;
|
||||
private final PermissionTools permTools;
|
||||
|
||||
private static final Pattern CANNON_PATTERN = Pattern.compile("(?i)cannon-[\\d]+(\\.[\\d]+)?");
|
||||
|
||||
public DestinationFactory(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.destList = new HashMap<String, Class<? extends MVDestination>>();
|
||||
List<Command> cmds = this.plugin.getCommandHandler().getAllCommands();
|
||||
for (Command c : cmds) {
|
||||
if (c instanceof TeleportCommand) {
|
||||
this.teleportCommand = c;
|
||||
}
|
||||
this.destList = new HashMap<>();
|
||||
this.destPermissions = new HashSet<>();
|
||||
this.permTools = new PermissionTools(plugin);
|
||||
}
|
||||
|
||||
public MVDestination getPlayerAwareDestination(@Nullable Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
if (teleportee == null) {
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
if (CANNON_PATTERN.matcher(destinationName).matches()) {
|
||||
return getDestination(parseCannonDest(teleportee, destinationName));
|
||||
}
|
||||
|
||||
Player targetPlayer = this.plugin.getMVCommandManager()
|
||||
.getCommandContexts()
|
||||
.getPlayerFromValue(teleportee, destinationName);
|
||||
|
||||
if (targetPlayer != null) {
|
||||
return getDestination("pl:" + targetPlayer.getName());
|
||||
}
|
||||
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,23 +125,32 @@ public class DestinationFactory {
|
||||
if (identifier.equals("")) {
|
||||
identifier = "w";
|
||||
}
|
||||
Permission self = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.self." + identifier);
|
||||
Permission other = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.other." + identifier);
|
||||
PermissionTools pt = new PermissionTools(this.plugin);
|
||||
if (self == null) {
|
||||
self = new Permission("multiverse.teleport.self." + identifier,
|
||||
"Permission to teleport yourself for the " + identifier + " destination.", PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(self);
|
||||
pt.addToParentPerms("multiverse.teleport.self." + identifier);
|
||||
}
|
||||
if (other == null) {
|
||||
other = new Permission("multiverse.teleport.other." + identifier,
|
||||
"Permission to teleport others for the " + identifier + " destination.", PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(other);
|
||||
pt.addToParentPerms("multiverse.teleport.other." + identifier);
|
||||
}
|
||||
this.teleportCommand.addAdditonalPermission(self);
|
||||
this.teleportCommand.addAdditonalPermission(other);
|
||||
|
||||
addDestPerm("multiverse.teleport.self." + identifier,
|
||||
"Permission to teleport yourself for the " + identifier + " destination.");
|
||||
addDestPerm("multiverse.teleport.other." + identifier,
|
||||
"Permission to teleport other for the " + identifier + " destination.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addDestPerm(String permNode, String description) {
|
||||
if (this.plugin.getServer().getPluginManager().getPermission(permNode) != null) {
|
||||
Logging.fine("Destination permission node " + permNode + " already added.");
|
||||
return;
|
||||
}
|
||||
|
||||
Permission perm = new Permission(permNode, description, PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(perm);
|
||||
permTools.addToParentPerms(permNode);
|
||||
destPermissions.add(permNode);
|
||||
}
|
||||
|
||||
public Collection<String> getIdentifiers() {
|
||||
return destList.keySet();
|
||||
}
|
||||
|
||||
public Set<String> getPermissions() {
|
||||
return destPermissions;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Helper class to switch between 2 {@link ChatColor}.
|
||||
*/
|
||||
public class ColorAlternator implements ColorTool {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ColorAlternator} with 2 {@link ChatColor}s.
|
||||
*
|
||||
* @param colorThis The first color.
|
||||
* @param colorThat The second color.
|
||||
* @return The {@link ColorAlternator} created for you.
|
||||
*/
|
||||
public static ColorAlternator with(@NotNull ChatColor colorThis,
|
||||
@NotNull ChatColor colorThat) {
|
||||
|
||||
return new ColorAlternator(colorThis, colorThat);
|
||||
}
|
||||
|
||||
private boolean switcher;
|
||||
private final ChatColor thisColor;
|
||||
private final ChatColor thatColor;
|
||||
|
||||
/**
|
||||
* @param colorThis The first color.
|
||||
* @param colorThat The second color.
|
||||
*/
|
||||
public ColorAlternator(@NotNull ChatColor colorThis,
|
||||
@NotNull ChatColor colorThat) {
|
||||
|
||||
this.thisColor = colorThis;
|
||||
this.thatColor = colorThat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color. Everytime this method is called, it swaps the color that it returns.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
@Override
|
||||
public ChatColor get() {
|
||||
return (this.switcher ^= true) ? this.thisColor : this.thatColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The first color.
|
||||
*/
|
||||
public ChatColor getThisColor() {
|
||||
return thisColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The second color.
|
||||
*/
|
||||
public ChatColor getThatColor() {
|
||||
return thatColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Tools to allow customisation.
|
||||
*/
|
||||
public interface ColorTool {
|
||||
|
||||
/**
|
||||
* Gets a chat color.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
ChatColor get();
|
||||
|
||||
/**
|
||||
* Default implementation of this interface. Returns a default white color.
|
||||
*/
|
||||
ColorTool DEFAULT = () -> ChatColor.WHITE;
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Helps to display contents such as list and maps in a nicely formatted fashion.
|
||||
*
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
public class ContentDisplay<T> {
|
||||
|
||||
public static final String LINE_BREAK = "%br%";
|
||||
|
||||
private CommandSender sender;
|
||||
private String header;
|
||||
private T contents;
|
||||
private String emptyMessage = "No matching content to display.";
|
||||
private DisplayHandler<T> displayHandler;
|
||||
private ColorTool colorTool = ColorTool.DEFAULT;
|
||||
private ContentFilter filter = ContentFilter.DEFAULT;
|
||||
private final Map<DisplaySetting<?>, Object> settingsMap = new WeakHashMap<>();
|
||||
|
||||
private ContentDisplay() { }
|
||||
|
||||
/**
|
||||
* Do the actual displaying of contents to the sender.
|
||||
*/
|
||||
public void send() {
|
||||
Collection<String> formattedContent = (this.contents == null) ? null : this.displayHandler.format(this);
|
||||
this.displayHandler.sendHeader(this);
|
||||
this.displayHandler.sendSubHeader(this);
|
||||
this.displayHandler.sendBody(this, formattedContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the target sender.
|
||||
*/
|
||||
@NotNull
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the header to display.
|
||||
*/
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the header text.
|
||||
*/
|
||||
public void setHeader(@NotNull String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the contents to display.
|
||||
*/
|
||||
public T getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the message to display when no content is shown.
|
||||
*/
|
||||
@NotNull
|
||||
public String getEmptyMessage() {
|
||||
return emptyMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the display handler that formats and sends content to sender.
|
||||
*/
|
||||
@NotNull
|
||||
public DisplayHandler<T> getDisplayHandler() {
|
||||
return displayHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the color tool used.
|
||||
*/
|
||||
@NotNull
|
||||
public ColorTool getColorTool() {
|
||||
return colorTool;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets the filter used.
|
||||
*/
|
||||
@NotNull
|
||||
public ContentFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value for a given setting option.
|
||||
*
|
||||
* @param setting The setting option.
|
||||
* @param <S> The setting type.
|
||||
* @return Value set for the given setting.
|
||||
*/
|
||||
public <S> S getSetting(@NotNull DisplaySetting<S> setting) {
|
||||
return (S) settingsMap.getOrDefault(setting, setting.defaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets other specific settings that may be used by the {@link DisplayHandler}.
|
||||
*
|
||||
* @param setting The settings option.
|
||||
* @param value The value to set.
|
||||
* @param <S> The type of setting.
|
||||
*/
|
||||
public <S> void setSetting(@NotNull DisplaySetting<S> setting, S value) {
|
||||
this.settingsMap.put(setting, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@link ContentDisplay}.
|
||||
*
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
public static class Builder<T> {
|
||||
|
||||
private final ContentDisplay<T> display;
|
||||
|
||||
public Builder() {
|
||||
this.display = new ContentDisplay<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets target sender to display message to. <b>Required.</b>
|
||||
*
|
||||
* @param sender The target sender.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> sender(@NotNull CommandSender sender) {
|
||||
this.display.sender = sender;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets header to be displayed.
|
||||
*
|
||||
* @param header The header text.
|
||||
* @param replacements String formatting replacements.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> header(@NotNull String header, Object...replacements) {
|
||||
this.display.header = String.format(header, replacements);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets content to be displayed.
|
||||
*
|
||||
* @param contents The contents.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> contents(@Nullable T contents) {
|
||||
this.display.contents = contents;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message to show when no content is available for display.
|
||||
*
|
||||
* @param emptyMessage The message text.
|
||||
* @param replacements String formatting replacements.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> emptyMessage(@NotNull String emptyMessage, Object...replacements) {
|
||||
this.display.emptyMessage = String.format(emptyMessage, replacements);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display handler that does the formatting and sending of content. <b>Required.</b>
|
||||
*
|
||||
* @param displayHandler The display handler for the given content type.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> displayHandler(@NotNull DisplayHandler<T> displayHandler) {
|
||||
this.display.displayHandler = displayHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color tool used to make messages more colourful.
|
||||
*
|
||||
* @param colorTool The color tool to use.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> colorTool(@NotNull ColorTool colorTool) {
|
||||
this.display.colorTool = colorTool;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets content filter used to match specific content to be displayed.
|
||||
*
|
||||
* @param filter The filter to use.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public Builder<T> filter(@NotNull ContentFilter filter) {
|
||||
this.display.filter = filter;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets other specific settings that may be used by the {@link DisplayHandler}.
|
||||
*
|
||||
* @param setting The settings option.
|
||||
* @param value The value to set.
|
||||
* @param <S> The type of setting.
|
||||
* @return The builder.
|
||||
*/
|
||||
@NotNull
|
||||
public <S> Builder<T> setting(@NotNull DisplaySetting<S> setting, S value) {
|
||||
this.display.settingsMap.put(setting, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and build the content display.
|
||||
*
|
||||
* @return The content display.
|
||||
*/
|
||||
@NotNull
|
||||
public ContentDisplay<T> build() {
|
||||
Objects.requireNonNull(this.display.sender);
|
||||
Objects.requireNonNull(this.display.displayHandler);
|
||||
return this.display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and send the contents to the sender.
|
||||
*/
|
||||
public void display() {
|
||||
this.build().send();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* <p>Filter content and text based on regex matching.</p>
|
||||
*
|
||||
* <p>Compile regex pattern based on {@link ContentFilter#filterString}. When prefixed with 'r=',
|
||||
* use {@link ContentFilter#filterString} as the full regex pattern. Else, set to any match that
|
||||
* contains the {@link ContentFilter#filterString}.<p>
|
||||
*/
|
||||
public class ContentFilter {
|
||||
|
||||
public static final ContentFilter DEFAULT = new ContentFilter();
|
||||
private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
|
||||
|
||||
private String filterString;
|
||||
private Pattern filterPattern;
|
||||
private boolean exactMatch;
|
||||
|
||||
private ContentFilter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filterString The text to do matching, either plaintext or regex.
|
||||
*/
|
||||
public ContentFilter(@NotNull String filterString) {
|
||||
this(filterString, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filterString The text to do matching, else plaintext or regex.
|
||||
* @param exactMatch Should check for exact match when doing regex matching.
|
||||
*/
|
||||
public ContentFilter(@NotNull String filterString,
|
||||
boolean exactMatch) {
|
||||
|
||||
this.filterString = filterString;
|
||||
this.exactMatch = exactMatch;
|
||||
parseFilter();
|
||||
}
|
||||
|
||||
private void parseFilter() {
|
||||
if (filterString == null) {
|
||||
return;
|
||||
}
|
||||
if (filterString.startsWith("r=")) {
|
||||
convertToMatcher(filterString.substring(2));
|
||||
return;
|
||||
}
|
||||
String cleanedFilter = REGEX_SPECIAL_CHARS.matcher(filterString.toLowerCase()).replaceAll("\\\\$0");
|
||||
convertToMatcher("(?i).*" + cleanedFilter + ".*");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile and store the regex into a {@link Pattern}.
|
||||
*
|
||||
* @param regex The regex text.
|
||||
*/
|
||||
private void convertToMatcher(@NotNull String regex) {
|
||||
try {
|
||||
this.filterPattern = Pattern.compile(regex);
|
||||
Logging.finest("Parsed regex pattern: %s", this.filterPattern.toString());
|
||||
}
|
||||
catch (PatternSyntaxException ignored) {
|
||||
Logging.warning("Error parsing regex: %s", filterString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do regex matching.
|
||||
*
|
||||
* @param text String to check regex on.
|
||||
* @return True of matches regex pattern, false otherwise.
|
||||
*/
|
||||
public boolean checkMatch(@Nullable Object text) {
|
||||
if (!hasFilter()) {
|
||||
return true;
|
||||
}
|
||||
if (text == null || !hasValidPattern()) {
|
||||
return false;
|
||||
}
|
||||
text = ChatColor.stripColor(String.valueOf(text));
|
||||
return (exactMatch)
|
||||
? filterPattern.matcher((CharSequence) text).matches()
|
||||
: filterPattern.matcher((CharSequence) text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a filter string is present.
|
||||
*
|
||||
* @return True if there is a filter string, else false.
|
||||
*/
|
||||
public boolean hasFilter() {
|
||||
return filterString != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if regex pattern syntax is valid.
|
||||
*
|
||||
* @return True if valid, else false.
|
||||
*/
|
||||
public boolean hasValidPattern() {
|
||||
return filterPattern != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The filter string.
|
||||
*/
|
||||
@Nullable
|
||||
public String getString() {
|
||||
return filterString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The regex pattern.
|
||||
*/
|
||||
@Nullable
|
||||
public Pattern getPattern() {
|
||||
return filterPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if filter is set to do exact matching, else false.
|
||||
*/
|
||||
public boolean isExactMatch() {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nicely format the filter string to be used for showing the sender.
|
||||
*
|
||||
* @return The formatted filter string.
|
||||
*/
|
||||
public @NotNull String getFormattedString() {
|
||||
return String.format("%sFilter: '%s'%s", ChatColor.ITALIC, filterString, ChatColor.RESET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContentFilter{" +
|
||||
"filterString='" + filterString + '\'' +
|
||||
", filterPattern=" + filterPattern +
|
||||
", exactMatch=" + exactMatch +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Handles the formatting and sending of all content by the {@link ContentDisplay}.
|
||||
*
|
||||
* @param <T> Type of content to display.
|
||||
*/
|
||||
public interface DisplayHandler<T> {
|
||||
|
||||
/**
|
||||
* Formats the raw content into a {@link Collection<String>} for displaying to sender.
|
||||
*
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
* @return The formatted content.
|
||||
*/
|
||||
Collection<String> format(@NotNull ContentDisplay<T> display);
|
||||
|
||||
/**
|
||||
* Sends the header.
|
||||
*
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
*/
|
||||
default void sendHeader(@NotNull ContentDisplay<T> display) {
|
||||
if (!Strings.isNullOrEmpty(display.getHeader())) {
|
||||
display.getSender().sendMessage(display.getHeader());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends info such as filter and page.
|
||||
*
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
*/
|
||||
default void sendSubHeader(@NotNull ContentDisplay<T> display) {
|
||||
if (display.getFilter().hasFilter()) {
|
||||
display.getSender().sendMessage(String.format("%s[ %s ]",
|
||||
ChatColor.GRAY, display.getFilter().getFormattedString()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the content.
|
||||
*
|
||||
* @param display The responsible {@link ContentDisplay}.
|
||||
* @param formattedContent The content after being formatted by {@link #format(ContentDisplay)}
|
||||
*/
|
||||
default void sendBody(@NotNull ContentDisplay<T> display, Collection<String> formattedContent) {
|
||||
if (formattedContent == null || formattedContent.size() == 0) {
|
||||
display.getSender().sendMessage(display.getEmptyMessage());
|
||||
return;
|
||||
}
|
||||
display.getSender().sendMessage(formattedContent.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* Various implementations of {@link DisplayHandler}.
|
||||
*/
|
||||
public class DisplayHandlers {
|
||||
|
||||
/**
|
||||
* Standard list display.
|
||||
*
|
||||
* Supported settings: none.
|
||||
*/
|
||||
public static final DisplayHandler<Collection<String>> LIST = display -> display.getContents().stream()
|
||||
.filter(display.getFilter()::checkMatch)
|
||||
.map(s -> (ContentDisplay.LINE_BREAK.equals(s)) ? "" : display.getColorTool().get() + s)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
/**
|
||||
* List display with paging.
|
||||
*
|
||||
* Supported settings: {@link DisplaySettings#SHOW_PAGE}, {@link DisplaySettings#LINES_PER_PAGE},
|
||||
* {@link DisplaySettings#PAGE_IN_CONSOLE}, {@link DisplaySettings#DO_END_PADDING}.
|
||||
*/
|
||||
public static final DisplayHandler<Collection<String>> PAGE_LIST = new DisplayHandler<Collection<String>>() {
|
||||
@Override
|
||||
public Collection<String> format(@NotNull ContentDisplay<Collection<String>> display) {
|
||||
if (dontNeedPaging(display)) {
|
||||
return LIST.format(display);
|
||||
}
|
||||
|
||||
int pages = 1;
|
||||
int currentLength = 0;
|
||||
int targetPage = display.getSetting(DisplaySettings.SHOW_PAGE);
|
||||
int linesPerPage = display.getSetting(DisplaySettings.LINES_PER_PAGE);
|
||||
List<String> content = new ArrayList<>(linesPerPage);
|
||||
|
||||
// Calculate the paging.
|
||||
for (String line : display.getContents()) {
|
||||
if (!display.getFilter().checkMatch(line)) {
|
||||
continue;
|
||||
}
|
||||
// When it's the next page.
|
||||
boolean isLineBreak = ContentDisplay.LINE_BREAK.equals(line);
|
||||
if (isLineBreak || currentLength++ > linesPerPage) {
|
||||
pages++;
|
||||
currentLength = 0;
|
||||
if (isLineBreak) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (pages == targetPage) {
|
||||
// Let first line be the header when no header is defined.
|
||||
if (display.getHeader() == null) {
|
||||
display.setHeader(line);
|
||||
currentLength--;
|
||||
continue;
|
||||
}
|
||||
content.add(display.getColorTool().get() + line);
|
||||
}
|
||||
}
|
||||
|
||||
// Page out of range.
|
||||
if (targetPage < 1 || targetPage > pages) {
|
||||
if (pages == 1) {
|
||||
throw new InvalidCommandArgument("There is only 1 page!");
|
||||
}
|
||||
throw new InvalidCommandArgument("Please enter a page from 1 to " + pages + ".");
|
||||
}
|
||||
|
||||
// Add empty lines to make output length consistent.
|
||||
if (display.getSetting(DisplaySettings.DO_END_PADDING)) {
|
||||
IntStream.range(0, linesPerPage - content.size()).forEach(i -> content.add(""));
|
||||
}
|
||||
display.setSetting(DisplaySettings.TOTAL_PAGE, pages);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSubHeader(@NotNull ContentDisplay<Collection<String>> display) {
|
||||
if (dontNeedPaging(display)) {
|
||||
LIST.sendSubHeader(display);
|
||||
return;
|
||||
}
|
||||
|
||||
if (display.getFilter().hasFilter()) {
|
||||
display.getSender().sendMessage(String.format("%s[ Page %s of %s, %s ]",
|
||||
ChatColor.GRAY,
|
||||
display.getSetting(DisplaySettings.SHOW_PAGE),
|
||||
display.getSetting(DisplaySettings.TOTAL_PAGE),
|
||||
display.getFilter().getFormattedString())
|
||||
);
|
||||
return;
|
||||
}
|
||||
display.getSender().sendMessage(String.format("%s[ Page %s of %s ]",
|
||||
ChatColor.GRAY,
|
||||
display.getSetting(DisplaySettings.SHOW_PAGE),
|
||||
display.getSetting(DisplaySettings.TOTAL_PAGE))
|
||||
);
|
||||
}
|
||||
|
||||
private boolean dontNeedPaging(ContentDisplay<Collection<String>> display) {
|
||||
return display.getSender() instanceof ConsoleCommandSender
|
||||
&& !display.getSetting(DisplaySettings.PAGE_IN_CONSOLE);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Display a list inline.
|
||||
*
|
||||
* Supported settings: {@link DisplaySettings#SEPARATOR}.
|
||||
*/
|
||||
public static final DisplayHandler<Collection<String>> INLINE_LIST = display -> {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String separator = display.getSetting(DisplaySettings.SEPARATOR);
|
||||
|
||||
for (Iterator<String> iterator = display.getContents().iterator(); iterator.hasNext(); ) {
|
||||
String content = iterator.next();
|
||||
if (!display.getFilter().checkMatch(content)) {
|
||||
continue;
|
||||
}
|
||||
builder.append(display.getColorTool().get()).append(content);
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(separator);
|
||||
}
|
||||
}
|
||||
return (builder.length() == 0)
|
||||
? Collections.singletonList(display.getEmptyMessage())
|
||||
: Collections.singleton(builder.toString());
|
||||
};
|
||||
|
||||
/**
|
||||
* Display key value pair inline.
|
||||
*
|
||||
* Supported settings: {@link DisplaySettings#SEPARATOR}, {@link DisplaySettings#OPERATOR}.
|
||||
*/
|
||||
public static final DisplayHandler<Map<String, Object>> INLINE_MAP = display -> {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String separator = display.getSetting(DisplaySettings.SEPARATOR);
|
||||
String operator = display.getSetting(DisplaySettings.OPERATOR);
|
||||
|
||||
for (Iterator<Entry<String, Object>> iterator = display.getContents().entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Entry<String, Object> entry = iterator.next();
|
||||
if (!display.getFilter().checkMatch(entry.getKey()) && !display.getFilter().checkMatch(entry.getValue())) {
|
||||
continue;
|
||||
}
|
||||
builder.append(display.getColorTool().get())
|
||||
.append(entry.getKey())
|
||||
.append(operator)
|
||||
.append(display.getColorTool().get())
|
||||
.append(entry.getValue());
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(separator);
|
||||
}
|
||||
}
|
||||
return (builder.length() == 0)
|
||||
? Collections.singletonList(display.getEmptyMessage())
|
||||
: Collections.singleton(builder.toString());
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
/**
|
||||
* Represents a setting option that can be used by {@link DisplayHandler}.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface DisplaySetting<T> {
|
||||
|
||||
/**
|
||||
* Gets the default value of this Display Setting.
|
||||
*
|
||||
* @return The default value.
|
||||
*/
|
||||
T defaultValue();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.onarandombox.MultiverseCore.displaytools;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Collection of {@link DisplaySetting} that are used by various {@link DisplayHandler}.
|
||||
*/
|
||||
public class DisplaySettings {
|
||||
|
||||
/**
|
||||
* Page to display.
|
||||
*/
|
||||
public static final DisplaySetting<Integer> SHOW_PAGE = () -> 1;
|
||||
|
||||
/**
|
||||
* Total pages available to display.
|
||||
*/
|
||||
public static final DisplaySetting<Integer> TOTAL_PAGE = () -> 1;
|
||||
|
||||
/**
|
||||
* The max number of lines per page. This excludes header.
|
||||
*/
|
||||
public static final DisplaySetting<Integer> LINES_PER_PAGE = () -> 8;
|
||||
|
||||
/**
|
||||
* Should add empty lines if content lines shown is less that {@link #LINES_PER_PAGE}.
|
||||
*/
|
||||
public static final DisplaySetting<Boolean> DO_END_PADDING = () -> true;
|
||||
|
||||
/**
|
||||
* Should display with paging when it's sent to console.
|
||||
*/
|
||||
public static final DisplaySetting<Boolean> PAGE_IN_CONSOLE = () -> false;
|
||||
|
||||
/**
|
||||
* Inline separator. E.g. '1, 2, 3'
|
||||
*/
|
||||
public static final DisplaySetting<String> SEPARATOR = () -> ChatColor.WHITE + ", ";
|
||||
|
||||
/**
|
||||
* The thing between a key value pair. E.g. 'Me = Smart'
|
||||
*/
|
||||
public static final DisplaySetting<String> OPERATOR = () -> ChatColor.WHITE + " = ";
|
||||
}
|
||||
Loaded 100 of 154 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user