Compare commits

...
Author SHA1 Message Date
Ben Woo 981b682aff Merge branch 'MV5' into spawnlocation_changes 2023-02-03 23:19:24 +08:00
Ben Woo 3377c1dbe5 refactor!: Remove deprecated logging (#2523) 2023-02-03 22:45:55 +08:00
Ben Woo 3ec22fc578 refactor!: Remove deprecated WorldManager methods (#2526) 2023-02-03 22:40:42 +08:00
Ben Woo 17351e66c1 refactor!: Remove deprecated getStaticConfig (#2525) 2023-02-03 22:39:23 +08:00
Ben Woo 0166b8d139 refactor!: Remove deprecated LocationManipulation class (#2528) 2023-02-03 22:38:51 +08:00
Ben Woo 2acca7f330 refactor!: Remove deprecated PlayChatEvent option (#2828) 2023-02-03 22:33:44 +08:00
Ben Woo 4ad6c53ba9 refactor!: Remove redundant MapInitializeEvent (#2507) 2023-02-03 22:11:38 +08:00
Ben Woo 0117159159 feat: @benwoo1110 Revamp content display API
commit 1211dfb057
Author: Ben Woo <30431861+benwoo1110@users.noreply.github.com>
Date:   Tue Aug 17 16:29:31 2021 +0800

    Implement suggested improvements.

    * Use singleton pattern for DefaultContentFilter with getInstance method.
    * Have a default SendHandler.
    * Don't need streams for small dataset.
    * Private WorldListContentParser class to improve readability.

commit 562eed8255
Author: Ben Woo <30431861+benwoo1110@users.noreply.github.com>
Date:   Tue Aug 17 00:26:57 2021 +0800

    Revamp content display API.
2023-02-03 20:23:53 +08:00
Ben Woo ccf802e32f perf: Update to use json-smart 2023-02-03 20:15:46 +08:00
Ben Woo 83f5a4a701 fix: Remove unused TravelAgent class 2023-02-03 19:50:04 +08:00
Ben Woo a034eaa555 feat: Implement basic localisation 2023-02-02 17:06:36 +08:00
Ben Woo 3fb99bc156 feat: Add ACF dependency and prep command migration 2023-02-02 16:49:45 +08:00
Ben Woo 9d34e5d75c fix: Replace deprecated EntityCreatePortalEvent with PortalCreateEvent
Use PortalCreateEvent which allows better checking of nether portal creation.
2023-02-02 15:13:00 +08:00
Ben Woo 27c2f7b9e9 feat: Update to 1.16.5-R0.1-SNAPSHOT dependency 2023-02-02 15:01:07 +08:00
Ben Woo 697fee8c4c chore: Bump version to 5.0.0-SNAPSHOT for continued development. 2023-02-02 14:21:11 +08:00
Ben Woo 20ce469aec Merge pull request #2765 from Multiverse/java17
Bump notnull-instrumenter-maven-plugin
2022-03-07 12:19:25 +08:00
Kermina Awad 70c91f777f bump notnull-instrumenter-maven-plugin
fixes compiling on Java 17
2022-03-06 22:42:38 -05:00
Ben Woo cc24f38d83 Merge pull request #2763 from Multiverse/bitly_domain
Remove j.mp Domain from BitlyURLShortener
2022-03-06 13:55:25 +08:00
nicegamer7 5ec27db284 remove j.mp domain from BitlyURLShortener 2022-03-05 09:35:10 -05:00
Ben Woo 5d6bc806f0 Merge pull request #2747 from KisaragiEffective/feature/use-collections-static-methods
use Collections' factory method instead of static field
2022-01-17 16:42:18 +08:00
Kisaragi 5868ad64b4 use Collections' factory method instead of static field
this resolves some unchecked generics warning
2021-12-31 00:46:21 +09:00
nicegamer7 ac6fcf5ed6 Merge pull request #2728 from Multiverse/benwoo1110-patch-2
More typo fixes to issue template.
2021-10-11 22:38:00 -04:00
Ben Woo 231824fd34 More typo fixes to issue template. 2021-10-08 11:58:43 +08:00
Ben Woo a3e7efcc58 Merge pull request #2727 from Artuto/fix-bug-report-issue-template
Fix Bug Report issue template
2021-10-08 11:53:30 +08:00
Artuto a649307a29 Fix Bug Report issue template 2021-10-07 22:52:22 -05:00
nicegamer7 b0235757cc Merge pull request #2719 from Multiverse/issue-forms
Use new issue forms.
2021-10-07 22:41:15 -04:00
Ben Wooandnicegamer7 06ee82a745 Update .github/ISSUE_TEMPLATE/feature-request.yml
Co-authored-by: nicegamer7 <kerminaawad@gmail.com>
2021-10-08 10:38:06 +08:00
Ben Wooandnicegamer7 d2cad7ca8d Update .github/ISSUE_TEMPLATE/feature-request.yml
Co-authored-by: nicegamer7 <kerminaawad@gmail.com>
2021-10-08 10:38:00 +08:00
nicegamer7 2390aa8f92 Merge pull request #2717 from Multiverse/fix-dest-velocity
Fix velocity not applying.
2021-10-07 22:36:47 -04:00
nicegamer7 674c4a4a06 Merge pull request #2720 from Multiverse/link-license
Link licence to LICENSE.md and add badge.
2021-10-07 21:48:05 -04:00
Ben Woo 768402088a Link licence to LICENSE.md and add badge. 2021-10-01 21:47:31 +08:00
Ben Woo 084033cc90 Use new issue forms. 2021-10-01 21:34:18 +08:00
Ben Woo 51801b1b36 Fix velocity not apply. 2021-10-01 15:11:03 +08:00
Jeremy Wood 71054197f2 Bump version to 4.3.2-SNAPSHOT for continued development. 2021-09-18 01:27:33 -04:00
Jeremy Wood 610f96415f Release version 4.3.1. 2021-09-18 01:18:40 -04:00
Jeremy Wood 34fa336f00 Revert "Add pipeline stuff."
This reverts commit 719ade19f7.
2021-08-25 09:40:58 -04:00
Jeremy Wood d92d62bce9 Revert "Fix task file path."
This reverts commit cf14d41d19.
2021-08-25 09:40:58 -04:00
Jeremy Wood cf14d41d19 Fix task file path. 2021-08-25 09:38:13 -04:00
Jeremy Wood 719ade19f7 Add pipeline stuff. 2021-08-25 09:37:22 -04:00
Ben Woo 1a8a97daf1 Merge pull request #2675 from Multiverse/replace_travis_badge
Replace Travis Badge with Github Actions.
2021-07-22 10:12:35 +08:00
nicegamer7 d9dffa8e6d replace travis badge 2021-07-21 22:11:09 -04:00
nicegamer7 973588defb Merge pull request #2175 from JLLeitschuh/fix/JLL/use_https_to_resolve_dependencies
[SECURITY] Use HTTPS to resolve dependencies in Maven Build
2021-07-19 20:14:17 -04:00
nicegamer7 c704c1ca3a Merge branch 'main' into fix/JLL/use_https_to_resolve_dependencies 2021-07-19 20:12:25 -04:00
Ben Woo c33a268b91 Merge pull request #2672 from Multiverse/fix_java16_tests
Fix Tests on Java 16 and code cleanup.
2021-07-19 10:31:31 +08:00
Kermina Awad 9821f1d9c8 clean up test files 2021-07-18 13:51:53 -04:00
Kermina Awad be6e0b67be don't run tests in parallel 2021-07-18 13:22:04 -04:00
Kermina Awad b9b1fa6164 remove PowerMockito 2021-07-18 13:17:15 -04:00
Kermina Awad 28585dd6f9 remove unnecessary stub 2021-07-18 13:12:09 -04:00
Ben Woo 47ca7b821b Move to GitHub actions (#2671)
* Remove use of travis.

* Add basic github action maven build.
2021-07-17 09:31:20 +08:00
nicegamer7 9ce2dfd100 Merge pull request #2445 from benwoo1110/fix-help
Fix issue where special chars cause PatternSyntaxException
2021-07-16 09:51:21 -04:00
Ben Woo 473ccd09d7 Don't need to toLowerCase filter. 2021-07-16 21:38:57 +08:00
Ben WooandJeremy Wood cc2e1d44b2 Implement new content display system. (#2584)
* Implement new content display system.

* Add @FunctionalInterface annotation to displaytools interfaces.

* Use static factory method to create Builder with contents.

* Use T for generic type since it's static method.

* Rename Builder#display to show and require CommandSender.

* Rename package from displaytools to display.

* Move DisplayHandler impls into their own package.

* Overload ContentDisplay#forContent with defaults for list and map.

* Pass CommandSender to send command.

This system is much more versatile when a single ContentDisplay instance
can be used for multiple players.

* Rename ContentDisplay#send to #show.

* Split DisplaySettings into separate classes.

Co-authored-by: Jeremy Wood <farachan@gmail.com>
2021-07-07 10:25:07 +08:00
Jeremy Wood 2e8f159d38 Merge pull request #2666 from Multiverse/https
Ensure https is used for repository.
2021-07-06 14:12:46 -04:00
Jeremy Wood 6581d16125 Merge pull request #2519 from Multiverse/readme-update
Update readme with more project details
2021-07-06 13:59:35 -04:00
Jeremy Wood 562bc56e83 Merge pull request #2664 from ccuser44/main
Create LICENSE.md
2021-07-06 13:56:16 -04:00
Ben Woo 4493cd7916 Ensure https is used for repository. 2021-07-06 23:27:53 +08:00
nicegamer7 1cd9e45915 Merge pull request #2663 from Multiverse/fix-portal-search
Set defaultportalsearch to true by default.
2021-07-05 15:16:01 -04:00
ccuser44 acb6bc6dd6 Create LICENSE.md 2021-07-05 11:39:50 +03:00
Ben Woo b7b17c5d21 Set defaultportalsearch to true by default. 2021-07-05 11:28:52 +08:00
Jeremy Wood bbd9211845 Bump version to 4.3.1-SNAPSHOT for continued development. 2021-06-23 15:47:52 -04:00
Jeremy Wood fc6796e20f Release version 4.3.0. 2021-06-23 08:56:24 -04:00
Jeremy Wood 6040a27126 Merge pull request #2635 from Multiverse/fix/version_cmd_perms
Change default permission for version command. Seriously wth.
2021-06-04 13:00:39 -04:00
Jeremy Wood 1c483148dc Change default permission for version command. Seriously wth. 2021-06-04 13:00:04 -04:00
nicegamer7 128442c062 Merge pull request #2622 from Multiverse/queue-system-cleanup
Queue system cleanup
2021-05-16 11:29:23 -04:00
Kermina Awad 141854f076 correct some javadoc typos 2021-05-16 11:21:20 -04:00
xSavior_of_God f72cc6764b Fix creation and import Exploit (#2353)
Through this fix you can avoid deleting of important folders.
2021-05-16 12:56:14 +08:00
benwoo1110 d95ecfaa8e Update some CommandQueueManager docs to be clearer. 2021-04-28 14:01:30 +08:00
benwoo1110 6c96f4e974 Ensure DummyCommandBlockSender isnt used for Op. 2021-04-28 13:58:43 +08:00
Ben Woo 28cee291c6 Merge pull request #2581 from Multiverse/regen-keep-gamerules
Add ability to keep gamerules setting on world regen.
2021-04-28 10:43:09 +08:00
Ben Woo 155f32c00f Add ability to keep gamerules on world regen. 2021-04-27 23:44:24 +08:00
Ben Woo 071ba05d81 Merge pull request #2585 from Multiverse/Revamp-queue-command-
Implement new queue command system.
2021-04-27 23:10:59 +08:00
Ben Woo 2ee5aea06b Merge pull request #2580 from Multiverse/per-search-and-reflect
Improve portal search radius
2021-04-27 10:57:46 +08:00
Ben Woo 3bb8de6d33 Improve portal search radius.
* Fix portal search radius not respected after travel agent removed.
* Set portal search radius for entity entering portals.
2021-04-26 22:52:24 +08:00
Ben Woo 79ac01da34 Merge pull request #2619 from Multiverse/general_cleanup
General Cleanup
2021-04-25 11:55:56 +08:00
Kermina Awad 6e4fbb0ece correct a copy-paste error introduced in #2588 2021-04-24 14:51:24 -04:00
Kermina Awad 167ed5e0d3 update VaultAPI repo 2021-04-24 14:49:28 -04:00
Kermina Awad 91f3304f78 add to Buscript failed to load message 2021-04-24 14:13:40 -04:00
Kermina Awad 7928e73a32 enable minimizeJar for maven-shade-plugin 2021-04-24 14:08:25 -04:00
Kermina Awad d61d186544 update bStats Metrics class 2021-04-24 14:08:09 -04:00
nicegamer7 dc356e88d0 Merge pull request #2582 from Multiverse/unload-message
Update unload message logging.
2021-04-24 13:49:12 -04:00
Kermina Awad d0d5574580 update unload message logging another time 2021-04-24 13:48:09 -04:00
Ben Woo 29617059b3 Merge pull request #2611 from Turbotailz/patch-1
Make prefixchat config option default to 'false'
2021-04-06 13:10:02 +08:00
Sam Goodger bf05fc81dd Make prefixchat config option default to 'false'
This may seem like a really negligible change but having this option default to `true` actually causes a lot of pain for support in other plugins that deal with prefixes (LuckPerms and Essentials being the main victims). Users always come in guns blazing, screaming at us because they don't know how to remove the world name from their chat. It's such a simple solution, yet no one thinks that of all plugins, it would be Multiverse that is tainting their beloved chat format.

Please consider updating this default setting. It will save a lot of us trouble in the future 🙏
2021-04-06 14:19:38 +10:00
nicegamer7 a2c5bf70f0 Merge pull request #2597 from Multiverse/cleanup
Cleanup
2021-03-18 10:52:28 -04:00
benwoo1110 ea19006465 Fix selector log level. 2021-03-18 16:40:47 +08:00
benwoo1110 89f685ff9a Add missing javadocs in DestinationFactory. 2021-03-10 17:45:39 +08:00
benwoo1110 ecc76033dc Remove redundant line that was moved to WorldNameChecker. 2021-03-10 17:41:56 +08:00
benwoo1110 cc3996ca76 Implement new queue command system. 2021-03-09 20:54:42 +08:00
benwoo1110 b23c1ae606 Update unload message logging. 2021-03-04 16:00:53 +08:00
benwoo1110 9741b1794c Update readme with more project details 2020-12-31 00:42:22 +08:00
benwoo1110 5d3d732c25 Fix issue where special chars cause PatternSyntaxException
Escape regex special chars for help command
2020-10-09 12:19:32 +08:00
Kermina Awad 6882660286 use Location's World 2020-07-09 09:48:40 -04:00
Jonathan Leitschuh 59b6522d59 Use HTTPS instead of HTTP to resolve dependencies
This fixes a security vulnerability in this project where the `pom.xml`
files were configuring Maven to resolve dependencies over HTTP instead of
HTTPS.

Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
2020-02-11 09:04:52 -05:00
120 changed files with 2393 additions and 1833 deletions

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
name: 🐛 Report a Bug
description: Report a problem with Multiverse-Core.
title: "[Bug]: "
labels: ["Bug: Unconfirmed"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
If you are having issues with other submodules of Multiverse, please go to their respective git repo:
Multiverse-Portals: https://github.com/Multiverse/Multiverse-Portals/issues/new/choose
Multiverse-NetherPortals: https://github.com/Multiverse/Multiverse-NetherPortals/issues/new/choose
Multiverse-Inventories: https://github.com/Multiverse/Multiverse-Inventories/issues/new/choose
Multiverse-SignPortals: https://github.com/Multiverse/Multiverse-SignPortals/issues/new/choose
Not sure if this is a bug with Multiverse-Core? Feel free to ask on our Discord server: https://discord.gg/NZtfKky
When completing the report, please ensure all fields are filled with the correct details requested. Failure to do so will result in your issue being closed.
- type: input
id: mutliverse-version-info
attributes:
label: '`/mv version -p` output'
description: Run `/mv version -p` in the console, then copy and paste the link from the output of the command into this box.
validations:
required: true
- type: input
id: server-logs
attributes:
label: Server logs
description: >
Include full startup log and console error (if any). upload all relevant logs to either https://paste.gg
or https://gist.github.com, save and the paste the link in this box.
validations:
required: true
- type: textarea
id: server-version
attributes:
label: Server Version
description: Output of `/version` command.
placeholder: server version info
render: shell
validations:
required: true
- type: textarea
id: bug-description
attributes:
label: Bug Description
description: Describe in detail what the bug is about. Include the expected behaviour and actual behaviour.
placeholder: "Example: When running `/mv` it cause the server to crash..."
validations:
required: true
- type: textarea
id: reproduce-steps
attributes:
label: Steps to reproduce
description: Provide detailed intructions to trigger the bug.
placeholder: |
Example:
1. Start a server with only multiverse installed.
2. Run `/mv` command.
3. Players all get kicked with a "server closed" message.
...
validations:
required: true
- type: checkboxes
id: agreements
attributes:
label: Agreements
description: Ensure you have done the following being submitting this issue.
options:
- label: I have searched for and ensured there isn't already an open or resolved issue(s) regarding this.
required: true
- label: >
I was 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.
required: true
+1 -1
View File
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: 💬 ​Multiverse Discord Server
- 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,41 @@
name: 💡 Request a Feature
description: Suggest a feature you want to see in Multiverse-Core!
title: "[Idea]: "
labels: ["Type: Idea"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to share your ideas!
If you are look for other submodules of Multiverse, go to their respective git repo:
Multiverse-Portals: https://github.com/Multiverse/Multiverse-Portals/issues/new/choose
Multiverse-NetherPortals: https://github.com/Multiverse/Multiverse-NetherPortals/issues/new/choose
Multiverse-Inventories: https://github.com/Multiverse/Multiverse-Inventories/issues/new/choose
Multiverse-SignPortals: https://github.com/Multiverse/Multiverse-SignPortals/issues/new/choose
Not sure if your feature fits in Multiverse-Core? Feel free to ask on our Discord server: https://discord.gg/NZtfKky
- type: textarea
id: feature-description
attributes:
label: Describe the feature
description: What feature are you suggesting?
placeholder: "Example: I hope multiverse can implement random teleport feature..."
validations:
required: true
- type: textarea
id: feature-reasoning
attributes:
label: How is the feature useful to all Multiverse users?
description: How is the feature useful to all players, server owners and/or developers?
placeholder: "Example: Random teleporting can be integrated into many multiverse modules such as mv-portals..."
validations:
required: true
- type: checkboxes
id: agreements
attributes:
label: Agreements
description: Ensure you have done the following being submitting this issue.
options:
- label: I have searched for and ensured there isn't already an open issue regarding this.
required: true
-56
View File
@@ -1,56 +0,0 @@
---
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. -->
-59
View File
@@ -1,59 +0,0 @@
---
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. -->
@@ -1,54 +0,0 @@
---
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? -->
+22
View File
@@ -0,0 +1,22 @@
name: Maven CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
-6
View File
@@ -1,6 +0,0 @@
language: java
jdk:
- oraclejdk8
notifications:
email: false
dist: trusty
+6
View File
@@ -0,0 +1,6 @@
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.
+37 -9
View File
@@ -1,16 +1,44 @@
![Multiverse 2](config/multiverse2-long.png)
[![Maven CI/CD](https://github.com/Multiverse/Multiverse-Core/actions/workflows/build.yml/badge.svg)](https://github.com/Multiverse/Multiverse-Core/actions/workflows/build.yml)
[![Release](https://img.shields.io/nexus/r/com.onarandombox.multiversecore/Multiverse-Core?label=release&server=https%3A%2F%2Frepo.onarandombox.com%2F)](https://dev.bukkit.org/projects/multiverse-core)
[![Dev builds](https://img.shields.io/nexus/s/com.onarandombox.multiversecore/Multiverse-Core?label=dev%20builds&server=http%3A%2F%2Frepo.onarandombox.com%2F)](https://ci.onarandombox.com/job/Multiverse-Core/)
[![Discord](https://img.shields.io/discord/325459248047980545?label=discord&logo=discord)](https://discord.gg/NZtfKky)
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Ddumptruckman%26type%3Dpatrons&style=flat)](https://patreon.com/dumptruckman)
[![License](https://img.shields.io/github/license/Multiverse/Multiverse-Core)](LICENSE.md)
About
========
[Multiverse](https://dev.bukkit.org/projects/multiverse-core) was created at the dawn of Bukkit multiworld support. It has since then grown into a **complete world management solution!** Multiverse provides the easiest to use world management solution for your Minecraft server, big or small, and with great addons like [Portals](https://dev.bukkit.org/projects/multiverse-portals) and [NetherPortals](https://dev.bukkit.org/projects/multiverse-netherportals/), what's not to love!
<br><br>
Now it's time to create your very own Multiverse server, do check out our [Wiki](https://github.com/Multiverse/Multiverse-Core/wiki) and [Usage Guide](https://github.com/Multiverse/Multiverse-Core/wiki/Basics) to get started. Feel free to hop onto our [Discord](https://discord.gg/NZtfKky) if you have any question or just want to have a chat with us!
### Amazing sub-modules available:
* [Multiverse-NetherPortals](https://github.com/Multiverse/Multiverse-NetherPortals) -> Have separate nether and end worlds for each of your overworlds!
* [Multiverse-Portals](https://github.com/Multiverse/Multiverse-Portals) -> Make custom portals to go to any destination!
* [Multiverse-Inventories](https://github.com/Multiverse/Multiverse-Inventories) -> Have separated players stats and inventories per world or per group of worlds.
* [Multiverse-SignPortals](https://github.com/Multiverse/Multiverse-SignPortals) -> Signs as teleprompters!
Building
========
Simply build the source with maven:
$ mvn install
```
$ mvn install
```
More details are available on the [build instructions wiki page](https://github.com/Multiverse/Multiverse-Core/wiki/Building).
Contributing
=======
**Want to help improve Multiverse?** There are several ways you can support and contribute to the project.
* Take a look at our "Bug: Unconfirmed" issues, where you can find issues that need extra testing and investigation.
* Want others to love Multiverse too? You can join the [Multiverse Discord community](https://discord.gg/NZtfKky) and help others with issues and setup!
* A Multiverse guru? You can update our [Wiki](https://github.com/Multiverse/Multiverse-Core/wiki) with your latest tip, tricks and guides! The wiki open for all to edit and improve.
* Love coding? You could look at ["State: Open to PR"](https://github.com/Multiverse/Multiverse-Core/labels/State%3A%20Open%20to%20PR) and ["Resolution: Accepted"](https://github.com/Multiverse/Multiverse-Core/labels/Resolution%3A%20Accepted) issues. We're always happy to receive bug fixes and feature additions as [pull requests](https://www.freecodecamp.org/news/how-to-make-your-first-pull-request-on-github-3/).
* If you'd like to make a financial contribution to the project, do consider joining our [patreon](https://www.patreon.com/dumptruckman) or make a one-time donation [here](https://paypal.me/dumptruckman)!
Additionally, we would like to give a big thanks to everyone that has supported Multiverse over the years, as well as those in the years to come. Thank you!
License
=======
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.
Multiverse-Core is licensed under BSD-3-Clause License. Please see [LICENSE.md](LICENSE.md) for more info.
+1 -1
View File
@@ -69,7 +69,7 @@
<module name="TypeName"/>
<module name="AvoidStarImport">
<property name="severity" value="warning"/>
<property name="excludes" value="com.onarandombox.MultiverseCore.utils,com.onarandombox.MultiverseCore.configuration,com.onarandombox.MultiverseCore.commands,com.onarandombox.MultiverseCore.destination"/>
<property name="excludes" value="com.onarandombox.MultiverseCore.utils,com.onarandombox.MultiverseCore.configuration,com.onarandombox.MultiverseCore.commandsold,com.onarandombox.MultiverseCore.destination"/>
</module>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
+41 -49
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>4.2.3-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<name>Multiverse-Core</name>
<description>World Management Plugin</description>
<properties>
@@ -20,23 +20,23 @@
</repository>
<repository>
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public</url>
<url>https://repo.onarandombox.com/content/groups/public</url>
</repository>
<repository>
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>minebench-repo</id>
<url>https://repo.minebench.de/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
</repositories>
@@ -44,7 +44,7 @@
<pluginRepository>
<id>doodleproject-repo</id>
<name>DoodleProject Maven 2 Repository</name>
<url>http://doodleproject.sourceforge.net/maven2/release</url>
<url>https://doodleproject.sourceforge.net/maven2/release</url>
<releases>
<enabled>true</enabled>
</releases>
@@ -53,7 +53,7 @@
<ciManagement>
<system>jenkins</system>
<url>http://ci.onarandombox.com</url>
<url>https://ci.onarandombox.com</url>
</ciManagement>
<!-- Profiles are used to detect whether this is a local or Jenkins build
@@ -158,8 +158,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<skipTests>true</skipTests>
<excludes>
<exclude>**/TestCommandSender.java</exclude>
<exclude>**/TestInstanceCreator.java</exclude>
@@ -223,6 +222,7 @@
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>me.main__.util</pattern>
@@ -256,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>
@@ -264,7 +272,7 @@
<plugin>
<groupId>se.eris</groupId>
<artifactId>notnull-instrumenter-maven-plugin</artifactId>
<version>1.0.0</version>
<version>1.1.1</version>
<executions>
<execution>
<goals>
@@ -285,10 +293,10 @@
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- SerializationConfig Dependency -->
<dependency>
@@ -305,18 +313,29 @@
<!-- End of SerializationConfig Dependency -->
<!-- Start of Economy Dependency -->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<!-- End of Economy Dependency -->
<!-- Start of CommandHandler Dependency -->
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.pneumaticraft.commandhandler</groupId>
<artifactId>CommandHandler</artifactId>
<version>11</version>
</dependency>
<!-- End of CommandHandler Dependency -->
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>buscript</artifactId>
@@ -325,13 +344,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
</exclusions>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.dumptruckman.minecraft</groupId>
@@ -357,30 +370,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<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.9</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.9</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>4.0.2</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -393,11 +385,11 @@
<distributionManagement>
<repository>
<id>OnARandomBox</id>
<url>http://repo.onarandombox.com/content/repositories/multiverse</url>
<url>https://repo.onarandombox.com/content/repositories/multiverse</url>
</repository>
<snapshotRepository>
<id>OnARandomBox</id>
<url>http://repo.onarandombox.com/content/repositories/multiverse-snapshots/</url>
<url>https://repo.onarandombox.com/content/repositories/multiverse-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;
@@ -346,7 +345,7 @@ public class MVWorld implements MultiverseWorld {
@SerializableAs("MVNullLocation (It's a bug if you see this in your config file)")
public static final class NullLocation extends SpawnLocation {
public NullLocation() {
super(0, -1, 0);
super(null, 0, -1, 0);
}
@Override
@@ -356,7 +355,7 @@ public class MVWorld implements MultiverseWorld {
@Override
public Map<String, Object> serialize() {
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
/**
@@ -7,21 +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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import buscript.Buscript;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MVWorld.NullLocation;
@@ -33,41 +18,43 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig;
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
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.commandsold.AnchorCommand;
import com.onarandombox.MultiverseCore.commandsold.CheckCommand;
import com.onarandombox.MultiverseCore.commandsold.CloneCommand;
import com.onarandombox.MultiverseCore.commandsold.ConfigCommand;
import com.onarandombox.MultiverseCore.commandsold.ConfirmCommand;
import com.onarandombox.MultiverseCore.commandsold.CoordCommand;
import com.onarandombox.MultiverseCore.commandsold.CreateCommand;
import com.onarandombox.MultiverseCore.commandsold.DeleteCommand;
import com.onarandombox.MultiverseCore.commandsold.EnvironmentCommand;
import com.onarandombox.MultiverseCore.commandsold.GameruleCommand;
import com.onarandombox.MultiverseCore.commandsold.GamerulesCommand;
import com.onarandombox.MultiverseCore.commandsold.GeneratorCommand;
import com.onarandombox.MultiverseCore.commandsold.HelpCommand;
import com.onarandombox.MultiverseCore.commandsold.ImportCommand;
import com.onarandombox.MultiverseCore.commandsold.InfoCommand;
import com.onarandombox.MultiverseCore.commandsold.ListCommand;
import com.onarandombox.MultiverseCore.commandsold.LoadCommand;
import com.onarandombox.MultiverseCore.commandsold.ModifyAddCommand;
import com.onarandombox.MultiverseCore.commandsold.ModifyClearCommand;
import com.onarandombox.MultiverseCore.commandsold.ModifyCommand;
import com.onarandombox.MultiverseCore.commandsold.ModifyRemoveCommand;
import com.onarandombox.MultiverseCore.commandsold.ModifySetCommand;
import com.onarandombox.MultiverseCore.commandsold.PurgeCommand;
import com.onarandombox.MultiverseCore.commandsold.RegenCommand;
import com.onarandombox.MultiverseCore.commandsold.ReloadCommand;
import com.onarandombox.MultiverseCore.commandsold.RemoveCommand;
import com.onarandombox.MultiverseCore.commandsold.ScriptCommand;
import com.onarandombox.MultiverseCore.commandsold.SetSpawnCommand;
import com.onarandombox.MultiverseCore.commandsold.SilentCommand;
import com.onarandombox.MultiverseCore.commandsold.SpawnCommand;
import com.onarandombox.MultiverseCore.commandsold.TeleportCommand;
import com.onarandombox.MultiverseCore.commandsold.UnloadCommand;
import com.onarandombox.MultiverseCore.commandsold.VersionCommand;
import com.onarandombox.MultiverseCore.commandsold.WhoCommand;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
import com.onarandombox.MultiverseCore.destination.BedDestination;
import com.onarandombox.MultiverseCore.destination.CannonDestination;
@@ -77,31 +64,27 @@ import com.onarandombox.MultiverseCore.destination.PlayerDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination;
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
import com.onarandombox.MultiverseCore.listeners.MVMapListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
import com.onarandombox.MultiverseCore.listeners.MVPortalListener;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener;
import com.onarandombox.MultiverseCore.listeners.MVWorldInitListener;
import com.onarandombox.MultiverseCore.listeners.MVWorldListener;
import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.CompatibilityLayer;
import com.onarandombox.MultiverseCore.utils.MVEconomist;
import com.onarandombox.MultiverseCore.utils.MVMessaging;
import com.onarandombox.MultiverseCore.utils.MVPermissions;
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
import com.onarandombox.MultiverseCore.utils.MaterialConverter;
import com.onarandombox.MultiverseCore.utils.TestingMode;
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.TestingMode;
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
import com.onarandombox.MultiverseCore.utils.VaultHandler;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator;
import com.pneumaticraft.commandhandler.CommandHandler;
import me.main__.util.SerializationConfig.NoSuchPropertyException;
import me.main__.util.SerializationConfig.SerializationConfig;
@@ -122,6 +105,20 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* The implementation of the Multiverse-{@link Core}.
*/
@@ -204,6 +201,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup our Map for our Commands using the CommandHandler.
private CommandHandler commandHandler;
private MVCommandManager commandManager;
private CommandQueueManager commandQueueManager;
private static final String LOG_TAG = "[Multiverse-Core]";
@@ -255,8 +254,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup our SafeTTeleporter
this.safeTTeleporter = new SimpleSafeTTeleporter(this);
this.unsafeCallWrapper = new UnsafeCallWrapper(this);
// Setup our CompatibilityLayer
CompatibilityLayer.init();
}
@@ -288,6 +285,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// Setup the command manager
this.commandHandler = new CommandHandler(this, this.ph);
this.commandManager = new MVCommandManager(this);
this.commandQueueManager = new CommandQueueManager(this);
// Call the Function to assign all the Commands to their Class.
this.registerCommands();
@@ -321,17 +320,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// A test that had no worlds loaded was being run. This should never happen in production
}
this.saveMVConfig();
// Register async or sync player chat according to config
try {
Class.forName("org.bukkit.event.player.AsyncPlayerChatEvent");
} catch (ClassNotFoundException e) {
getMVConfig().setUseAsyncChat(false);
}
if (getMVConfig().getUseAsyncChat()) {
this.chatListener = new MVAsyncPlayerChatListener(this, this.playerListener);
} else {
this.chatListener = new MVPlayerChatListener(this, this.playerListener);
}
this.chatListener = new MVChatListener(this, this.playerListener);
getServer().getPluginManager().registerEvents(this.chatListener, this);
this.initializeBuscript();
@@ -364,7 +354,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
// 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!");
Logging.warning("Buscript failed to load! The script command will be disabled! " +
"If you would like not to see this message, " +
"use `/mv conf enablebuscript false` to disable Buscript from loading.");
}
}
}
@@ -389,9 +381,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);
}
/**
@@ -529,7 +519,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
} else if (entry.getValue() instanceof ConfigurationSection) {
Logging.fine("Migrating: " + entry.getKey());
// we have to migrate this
WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
WorldProperties world = new WorldProperties(Collections.emptyMap());
ConfigurationSection section = (ConfigurationSection) entry.getValue();
// migrate animals and monsters
@@ -780,13 +770,16 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.commandHandler.registerCommand(new AnchorCommand(this));
// Misc Commands
this.commandHandler.registerCommand(new EnvironmentCommand(this));
this.commandHandler.registerCommand(new DebugCommand(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));
//**NEW ACF COMMAND HANDLER**
this.commandManager.registerCommand(new DebugCommand(this));
}
/**
@@ -843,47 +836,6 @@ 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
@Deprecated
public void log(Level level, String msg) {
Logging.log(level, msg);
}
/**
* Logs a message at the specified level.
*
* @param level The Log-{@link Level}.
* @param msg The message to log.
*
* @deprecated Replaced by {@link Logging}. Please refrain from using this from a third party plugin as the
* messages will appear to originate from Multiverse-Core.
*/
@Deprecated
public static void staticLog(Level level, String msg) {
Logging.log(level, msg);
}
/**
* Print messages to the Debug Log, if the servers in Debug Mode then we also want to print the messages to the
* standard Server Console.
*
* @param level The Log-{@link Level}
* @param msg The message
*
* @deprecated Replaced by {@link Logging}. Please refrain from using this from a third party plugin as the
* messages will appear to originate from Multiverse-Core.
*/
@Deprecated
public static void staticDebugLog(Level level, String msg) {
Logging.log(level, msg);
}
/**
* {@inheritDoc}
*/
@@ -918,13 +870,20 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
}
/**
* Gets the log-tag.
*
* @return The log-tag
* {@inheritDoc}
*/
// TODO this should be static!
public String getTag() {
return MultiverseCore.LOG_TAG;
@Override
public MVCommandManager getCommandManager() {
return this.commandManager;
}
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public CommandQueueManager getCommandQueueManager() {
return commandQueueManager;
}
/**
@@ -1112,17 +1071,27 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
* @return True if success, false if fail.
*/
public Boolean cloneWorld(String oldName, String newName, String generator) {
return this.worldManager.cloneWorld(oldName, newName, generator);
return this.worldManager.cloneWorld(oldName, newName);
}
/**
* {@inheritDoc}
* @deprecated This is deprecated!
* @deprecated This is deprecated! Do not use!
*/
@Override
@Deprecated
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed) {
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed);
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed, false);
}
/**
* {@inheritDoc}
* @deprecated This is deprecated! Do not use!
*/
@Override
@Deprecated
public Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed, Boolean keepGameRules) {
return this.worldManager.regenWorld(name, useNewSeed, randomSeed, seed, keepGameRules);
}
/**
@@ -1192,17 +1161,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
return config;
}
/**
* This method is currently used by other plugins.
* It will be removed in 2.4
* @return The Multiverse config.
* @deprecated This is deprecated.
*/
@Deprecated
public static MultiverseCoreConfiguration getStaticConfig() {
return MultiverseCoreConfiguration.getInstance();
}
@Override
public Buscript getScriptAPI() {
return buscript;
@@ -48,8 +48,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
@Property
private volatile String prefixchatformat;
@Property
private volatile boolean useasyncchat;
@Property
private volatile boolean teleportintercept;
@Property
private volatile boolean firstspawnoverride;
@@ -95,8 +93,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
protected void setDefaults() {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
enforceaccess = false;
useasyncchat = true;
prefixchat = true;
prefixchat = false;
prefixchatformat = "[%world%]%chat%";
teleportintercept = true;
firstspawnoverride = true;
@@ -107,7 +104,7 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
teleportcooldown = 1000;
this.version = 2.9;
silentstart = false;
defaultportalsearch = false;
defaultportalsearch = true;
portalsearchradius = 128;
autopurge = true;
idonotwanttodonate = false;
@@ -322,16 +319,6 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements
this.teleportcooldown = teleportCooldown;
}
@Override
public void setUseAsyncChat(boolean useAsyncChat) {
this.useasyncchat = useAsyncChat;
}
@Override
public boolean getUseAsyncChat() {
return this.useasyncchat;
}
@Override
public void setSilentStart(boolean silentStart) {
Logging.setShowingConfig(!silentStart);
@@ -8,6 +8,8 @@
package com.onarandombox.MultiverseCore.api;
import buscript.Buscript;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
import com.onarandombox.MultiverseCore.utils.AnchorManager;
import com.onarandombox.MultiverseCore.utils.MVEconomist;
@@ -86,6 +88,23 @@ public interface Core {
*/
CommandHandler getCommandHandler();
/**
* Multiverse uses {@link MVCommandManager} to make adding and using commands
* a piece of cake.
*
* @return A non-null {@link MVCommandManager}.
*/
MVCommandManager getCommandManager();
/**
* Manager for command that requires /mv confirm before execution.
*
* @return A non-null {@link CommandQueueManager}.
* @deprecated To be moved to new command manager in 5.0.0
*/
@Deprecated
CommandQueueManager getCommandQueueManager();
/**
* Gets the factory class responsible for loading many different destinations
* on demand.
@@ -116,20 +135,38 @@ public interface Core {
AnchorManager getAnchorManager();
/**
* Used by queued commands to regenerate a world on a delay.
* Previously used by queued commands to regenerate a world on a delay.
* Do not use api method for any other purpose.
*
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed IF the new seed should be random
* @param seed The seed of the world.
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed If the new seed should be random
* @param seed The seed of the world.
*
* @return True if success, false if fail.
*
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String)} instead.
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String, boolean)} instead.
*/
@Deprecated
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed);
/**
* Used by queued commands to regenerate a world on a delay.
* Do not use api method for any other purpose.
*
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed If the new seed should be random
* @param seed The seed of the world.
* @param keepGameRules If GameRules should be kept on world regen.
*
* @return True if success, false if fail.
*
* @deprecated Use {@link MVWorldManager#regenWorld(String, boolean, boolean, String, boolean)} instead.
*/
@Deprecated
Boolean regenWorld(String name, Boolean useNewSeed, Boolean randomSeed, String seed, Boolean keepGameRules);
/**
* Decrements the number of plugins that have specifically hooked into core.
*/
@@ -1,36 +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;
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.
*
* @deprecated Replaced by {@link Logging}.
* */
@Deprecated
public interface LoggablePlugin {
/**
* Logs a message at the specified level.
*
* @param level The Log-{@link Level}.
* @param msg The message to log.
*/
void log(Level level, String msg);
/**
* Gets the server instance that this plugin is attached to.
*
* @return A {@link Server} instance.
*/
Server getServer();
}
@@ -13,7 +13,7 @@ import com.onarandombox.MultiverseCore.event.MVVersionEvent;
/**
* This interface is implemented by every official Multiverse-plugin.
*/
public interface MVPlugin extends LoggablePlugin {
public interface MVPlugin {
/**
* Adds This plugin's version information to the buffer and returns the new string.
*
@@ -59,18 +59,6 @@ public interface MVWorldManager {
boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures,
String generator, boolean useSpawnAdjust);
/**
* Make a copy of a world.
*
* @param oldName Name of world to be copied
* @param newName Name of world to be created
* @param generator The Custom generator plugin to use. Ignored.
* @return True if the world is copied successfully, false if not.
* @deprecated Use {@link #cloneWorld(String, String)} instead.
*/
@Deprecated
boolean cloneWorld(String oldName, String newName, String generator);
/**
* Make a copy of a world.
*
@@ -234,19 +222,9 @@ public interface MVWorldManager {
*/
void loadDefaultWorlds();
/**
* Return the World Purger.
*
* @return A valid {@link PurgeWorlds}.
* @deprecated {@link PurgeWorlds} is deprecated!
*/
@Deprecated
PurgeWorlds getWorldPurger();
/**
* Gets the {@link WorldPurger}.
* <p>
* TODO: Remove {@link #getWorldPurger()} and replace it with this method.
* @return The {@link WorldPurger} this {@link MVWorldManager} is using.
* @see WorldPurger
* @see SimpleWorldPurger
@@ -313,15 +291,28 @@ public interface MVWorldManager {
/**
* Regenerates a world.
*
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed IF the new seed should be random
* @param seed The seed of the world.
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed If the new seed should be random
* @param seed The seed of the world.
*
* @return True if success, false if fail.
*/
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed);
/**
* Regenerates a world.
*
* @param name Name of the world to regenerate
* @param useNewSeed If a new seed should be used
* @param randomSeed If the new seed should be random
* @param seed The seed of the world.
* @param keepGameRules If GameRules should be kept on world regen.
*
* @return True if success, false if fail.
*/
boolean regenWorld(String name, boolean useNewSeed, boolean randomSeed, String seed, boolean keepGameRules);
boolean isKeepingSpawnInMemory(World world);
/**
@@ -158,18 +158,6 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable {
*/
boolean getEnforceAccess();
/**
* Sets useasyncchat.
* @param useAsyncChat The new value.
*/
void setUseAsyncChat(boolean useAsyncChat);
/**
* Gets useasyncchat.
* @return useasyncchat.
*/
boolean getUseAsyncChat();
/**
* Sets whether to suppress startup messages.
*
@@ -115,33 +115,6 @@ public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin {
return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs);
}
@Override
public void log(Level level, String msg) {
int debugLevel = this.getCore().getMVConfig().getGlobalDebug();
if ((level == Level.FINE && debugLevel >= 1) || (level == Level.FINER && debugLevel >= 2)
|| (level == Level.FINEST && debugLevel >= 3)) {
debugLog.log(level, msg);
} else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) {
String message = new StringBuilder(getLogTag()).append(msg).toString();
this.getServer().getLogger().log(level, message);
debugLog.log(level, message);
}
}
private String getLogTag() {
if (logTag == null)
logTag = String.format("[%s]", this.getDescription().getName());
return logTag;
}
/**
* Sets the debug log-tag.
* @param tag The new tag.
*/
protected final void setDebugLogTag(String tag) {
this.debugLog.setTag(tag);
}
@Override
public final String dumpVersionInfo(String buffer) {
throw new UnsupportedOperationException("This is gone.");
@@ -1,67 +1,57 @@
/******************************************************************************
* 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 co.aikar.commands.CommandIssuer;
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.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.locale.MVCorei18n;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.logging.Level;
/**
* Enables debug-information.
*/
@CommandAlias("mv")
public class DebugCommand extends MultiverseCommand {
public DebugCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Turn Debug on/off?");
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|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();
}
this.displayDebugMode(sender);
@Subcommand("debug")
@CommandPermission("multiverse.core.debug")
@Description("{@@mv-core.debug_info_description}")
public void onShowDebugCommand(@NotNull CommandIssuer issuer) {
this.displayDebugMode(issuer);
}
private void displayDebugMode(CommandSender sender) {
final int debugLevel = plugin.getMVConfig().getGlobalDebug();
@Subcommand("debug")
@CommandPermission("multiverse.core.debug")
@Syntax("<{@@mv-core.debug_change_syntax}>")
@CommandCompletion("@range:3")
@Description("{@@mv-core.debug_change_description}")
public void onChangeDebugCommand(@NotNull CommandIssuer issuer,
@Conditions("debuglevel")
@Syntax("<{@@mv-core.debug_change_syntax}>")
@Description("{@@mv-core.debug_change_level_description}")
int level) {
this.plugin.getMVConfig().setGlobalDebug(level);
this.plugin.saveMVConfigs();
this.displayDebugMode(issuer);
}
private void displayDebugMode(@NotNull CommandIssuer issuer) {
final 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);
Logging.fine("Multiverse Debug ENABLED");
issuer.sendInfo(MVCorei18n.DEBUG_INFO_OFF);
return;
}
issuer.sendInfo(MVCorei18n.DEBUG_INFO_ON, "{level}", String.valueOf(debugLevel));
Logging.fine("Multiverse Debug ENABLED.");
}
}
@@ -1,130 +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.MultiverseWorld;
import org.bukkit.ChatColor;
import org.bukkit.World.Environment;
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 listing of all worlds that a player can enter.
*/
public class ListCommand extends PaginatedCoreCommand<String> {
public ListCommand(MultiverseCore plugin) {
super(plugin);
this.setName("World Listing");
this.setCommandUsage("/mv list [page]");
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()) {
if (p != null && (!this.plugin.getMVPerms().canEnterWorld(p, world))) {
continue;
}
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;
}
@Override
protected String getItemText(String item) {
return item;
}
@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;
}
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);
}
}
@@ -1,40 +1,13 @@
/******************************************************************************
* 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 co.aikar.commands.BaseCommand;
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;
public class MultiverseCommand extends BaseCommand {
/**
* A generic Multiverse-command.
*/
public abstract class MultiverseCommand extends Command {
protected final MultiverseCore plugin;
/**
* The reference to the core.
*/
protected MultiverseCore plugin;
/**
* The reference to {@link MultiverseMessaging}.
*/
protected MultiverseMessaging messaging;
public MultiverseCommand(MultiverseCore plugin) {
super(plugin);
protected MultiverseCommand(MultiverseCore plugin) {
this.plugin = plugin;
this.messaging = this.plugin.getMessaging();
}
@Override
public abstract void runCommand(CommandSender sender, List<String> args);
}
@@ -1,4 +0,0 @@
/**
* This package contains all Commands.
*/
package com.onarandombox.MultiverseCore.commands;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import java.util.List;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.command.CommandSender;
@@ -33,7 +33,7 @@ public class ConfirmCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
this.plugin.getCommandHandler().confirmQueuedCommand(sender);
this.plugin.getCommandQueueManager().runQueuedCommand(sender);
}
}
@@ -5,13 +5,12 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -46,10 +46,15 @@ public class CreateCommand extends MultiverseCommand {
this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon");
this.worldManager = this.plugin.getMVWorldManager();
}
private String trimWorldName(String userInput) {
// Removes relative paths.
return userInput.replaceAll("^[./\\\\]+", "");
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
String worldName = args.get(0);
String worldName = trimWorldName(args.get(0));
File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
String env = args.get(1);
String seed = CommandHandler.getFlag("-s", args);
@@ -66,7 +71,13 @@ public class CreateCommand extends MultiverseCommand {
useSpawnAdjust = false;
}
}
// Make sure the world name doesn't contain the words 'plugins' and '.dat'
if(worldName.contains("plugins")||worldName.contains(".dat")){
sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'");
return;
}
if (this.worldManager.isMVWorld(worldName)) {
sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
+ "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName);
@@ -117,4 +128,4 @@ public class CreateCommand extends MultiverseCommand {
Command.broadcastCommandMessage(sender, "FAILED.");
}
}
}
}
@@ -0,0 +1,66 @@
/******************************************************************************
* 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.commandsold;
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 java.util.List;
/**
* Enables debug-information.
*/
public class DebugCommand extends MultiverseCommand {
public DebugCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Turn Debug on/off?");
this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|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();
}
this.displayDebugMode(sender);
}
private void displayDebugMode(CommandSender sender) {
final int debugLevel = plugin.getMVConfig().getGlobalDebug();
if (debugLevel == 0) {
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
} else {
sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel);
Logging.fine("Multiverse Debug ENABLED");
}
}
}
@@ -5,14 +5,15 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
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;
/**
@@ -35,11 +36,24 @@ public class DeleteCommand extends MultiverseCommand {
public void runCommand(CommandSender sender, List<String> args) {
String worldName = args.get(0);
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!");
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
sender,
deleteRunnable(sender, worldName),
String.format("Are you sure you want to delete world '%s'? You cannot undo this action.", worldName)
));
}
private Runnable deleteRunnable(@NotNull CommandSender sender,
@NotNull String worldName) {
return () -> {
sender.sendMessage(String.format("Deleting world '%s'...", worldName));
if (this.plugin.getMVWorldManager().deleteWorld(worldName)) {
sender.sendMessage(String.format("%sWorld %s was deleted!", ChatColor.GREEN, worldName));
return;
}
sender.sendMessage(String.format("%sThere was an issue deleting '%s'! Please check console for errors.",
ChatColor.RED, worldName));
};
}
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Bukkit;
@@ -5,9 +5,15 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.display.ContentDisplay;
import com.onarandombox.MultiverseCore.display.filters.ContentFilter;
import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter;
import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter;
import com.onarandombox.MultiverseCore.display.handlers.InlineSendHandler;
import com.onarandombox.MultiverseCore.display.parsers.MapContentParser;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameRule;
@@ -16,7 +22,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Allows management of Anchor Destinations.
@@ -26,8 +34,8 @@ 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.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD] [FILTER]");
this.setArgRange(0, 2);
this.addKey("mv gamerules");
this.addKey("mv rules");
this.addKey("mvgamerules");
@@ -37,11 +45,13 @@ public class GamerulesCommand extends MultiverseCommand {
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;
Player p;
World world;
ContentFilter filter = DefaultContentFilter.getInstance();
if (sender instanceof Player) {
p = (Player) sender;
} else {
@@ -56,9 +66,20 @@ public class GamerulesCommand extends MultiverseCommand {
return;
}
final World world;
// Not the best way, need to fix with ACF soon...
if (args.size() == 0) {
world = p.getWorld();
} else if (args.size() == 1) {
world = Bukkit.getWorld(args.get(0));
if (world == null) {
if (p == null) {
sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0)
+ ChatColor.WHITE + " does not exist.");
return;
}
world = p.getWorld();
filter = RegexContentFilter.fromString(args.get(0));
}
} else {
world = Bukkit.getWorld(args.get(0));
if (world == null) {
@@ -66,17 +87,25 @@ public class GamerulesCommand extends MultiverseCommand {
+ ChatColor.WHITE + " does not exist.");
return;
}
filter = RegexContentFilter.fromString(args.get(1));
}
final StringBuilder gameRules = new StringBuilder();
for (final String gameRule : world.getGameRules()) {
if (gameRules.length() != 0) {
gameRules.append(ChatColor.WHITE).append(", ");
}
gameRules.append(ChatColor.AQUA).append(gameRule).append(ChatColor.WHITE).append(": ");
gameRules.append(ChatColor.GREEN).append(world.getGameRuleValue(GameRule.getByName(gameRule)));
ContentDisplay.create()
.addContentParser(MapContentParser.forContent(getGameRuleMap(world))
.withKeyColor(ChatColor.GREEN)
.withValueColor(ChatColor.YELLOW))
.withSendHandler(InlineSendHandler.create()
.withHeader("====[ Gamerules for %s%s%s ]====", ChatColor.AQUA, world.getName(), ChatColor.WHITE)
.withFilter(filter))
.send(sender);
}
private Map<String, Object> getGameRuleMap(World world) {
Map<String, Object> gameRuleMap = new HashMap<>();
for (GameRule<?> rule : GameRule.values()) {
Object value = world.getGameRuleValue(rule);
gameRuleMap.put(rule.getName(), value);
}
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
sender.sendMessage(gameRules.toString());
return gameRuleMap;
}
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.pneumaticraft.commandhandler.Command;
@@ -40,24 +40,16 @@ public class HelpCommand extends PaginatedCoreCommand<Command> {
@Override
protected List<Command> getFilteredItems(List<Command> availableItems, String filter) {
String expression = "(?i).*" + cleanFilter(filter) + ".*";
List<Command> filtered = new ArrayList<Command>();
for (Command c : availableItems) {
if (stitchThisString(c.getKeyStrings()).matches("(?i).*" + filter + ".*")) {
if (stitchThisString(c.getKeyStrings()).matches(expression)
|| c.getCommandName().matches(expression)
|| c.getCommandDesc().matches(expression)
|| c.getCommandUsage().matches(expression)
|| c.getCommandExamples().stream().anyMatch(eg -> eg.matches(expression))) {
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;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -81,6 +81,12 @@ public class ImportCommand extends MultiverseCommand {
this.showHelp(sender);
return;
}
// Make sure the world name doesn't contain the words 'plugins' and '.dat'
if(worldName.contains("plugins")||worldName.contains(".dat")){
sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'");
return;
}
// Make sure we don't already know about this world.
if (this.worldManager.isMVWorld(worldName)) {
@@ -128,4 +134,4 @@ public class ImportCommand extends MultiverseCommand {
Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!");
}
}
}
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.FancyText;
@@ -0,0 +1,120 @@
/******************************************************************************
* 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.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.display.ContentDisplay;
import com.onarandombox.MultiverseCore.display.filters.ContentFilter;
import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter;
import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter;
import com.onarandombox.MultiverseCore.display.handlers.PagedSendHandler;
import com.onarandombox.MultiverseCore.display.parsers.ContentParser;
import org.bukkit.ChatColor;
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.List;
/**
* Displays a listing of all worlds that a player can enter.
*/
public class ListCommand extends MultiverseCommand {
public ListCommand(MultiverseCore plugin) {
super(plugin);
this.setName("World Listing");
this.setCommandUsage("/mv list [filter] [page]");
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);
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
ContentFilter filter = DefaultContentFilter.getInstance();
int page = 1;
// Either page or filter.
if (args.size() == 1) {
try {
page = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignore) {
filter = RegexContentFilter.fromString(args.get(0));
}
}
// Filter then page.
if (args.size() == 2) {
filter = RegexContentFilter.fromString(args.get(0));
try {
page = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignore) {
sender.sendMessage(ChatColor.RED + args.get(1) + " is not valid number!");
}
}
ContentDisplay.create()
.addContentParser(new WorldListContentParser())
.withSendHandler(PagedSendHandler.create()
.withHeader("%s====[ Multiverse World List ]====", ChatColor.GOLD)
.withFilter(filter)
.withTargetPage(page))
.send(sender);
}
private class WorldListContentParser implements ContentParser {
@Override
public void parse(@NotNull CommandSender sender, @NotNull List<String> content) {
Player player = (sender instanceof Player) ? (Player) sender : null;
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()))
.forEach(content::add);
plugin.getMVWorldManager().getUnloadedWorlds().stream()
.filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true))
.map(world -> ChatColor.GRAY + world + " - UNLOADED")
.forEach(content::add);
}
private boolean canSeeWorld(Player player, MultiverseWorld world) {
return !world.isHidden()
|| player == null
|| plugin.getMVPerms().hasPermission(player, "multiverse.core.modify", true);
}
private String hiddenText(MultiverseWorld world) {
return (world.isHidden()) ? String.format("%s[H] ", ChatColor.GRAY) : "";
}
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;
}
return color + env.toString();
}
}
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.enums.Action;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -0,0 +1,40 @@
/******************************************************************************
* 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.commandsold;
import java.util.List;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
import com.pneumaticraft.commandhandler.Command;
import org.bukkit.command.CommandSender;
/**
* 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);
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.pneumaticraft.commandhandler.Command;
import org.bukkit.command.CommandSender;
@@ -13,12 +13,14 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.regex.Pattern;
/**
* A generic paginated command.
* @param <T> The type of items on the page.
*/
public abstract class PaginatedCommand<T> extends Command {
private final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
private static final int DEFAULT_ITEMS_PER_PAGE = 9;
/**
* The number of items per page.
@@ -40,12 +42,23 @@ public abstract class PaginatedCommand<T> extends Command {
/**
* 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);
/**
* Escape regex special characters from filter
*
* @param filter The filter-{@link String}.
* @return String with regex characters escaped
*/
protected String cleanFilter(String filter) {
return REGEX_SPECIAL_CHARS.matcher(filter).replaceAll("\\\\$0");
}
/**
* Constructs a single string from a list of strings.
*
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -5,14 +5,16 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
import com.pneumaticraft.commandhandler.CommandHandler;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionDefault;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
@@ -23,8 +25,8 @@ public class RegenCommand extends MultiverseCommand {
public RegenCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Regenerates a World");
this.setCommandUsage("/mv regen" + ChatColor.GREEN + " {WORLD}" + ChatColor.GOLD + " [-s [SEED]]");
this.setArgRange(1, 3);
this.setCommandUsage("/mv regen" + ChatColor.GREEN + " {WORLD}" + ChatColor.GOLD + " [-s [SEED]] [--keep-gamerules]");
this.setArgRange(1, 4);
this.addKey("mvregen");
this.addKey("mv regen");
this.addCommandExample("You can use the -s with no args to get a new seed:");
@@ -37,17 +39,31 @@ public class RegenCommand extends MultiverseCommand {
@Override
public void runCommand(CommandSender sender, List<String> args) {
Boolean useseed = (!(args.size() == 1));
Boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s"));
String worldName = args.get(0);
boolean useseed = (!(args.size() == 1));
boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s"));
String seed = (args.size() == 3) ? args.get(2) : "";
boolean keepGamerules = CommandHandler.hasFlag("--keep-gamerules", args);
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
sender,
doWorldRegen(sender, worldName, useseed, randomseed, seed, keepGamerules),
String.format("Are you sure you want to regen '%s'? You cannot undo this action.", worldName)
));
}
Class<?>[] paramTypes = {String.class, Boolean.class, Boolean.class, String.class};
List<Object> objectArgs = new ArrayList<Object>();
objectArgs.add(args.get(0));
objectArgs.add(useseed);
objectArgs.add(randomseed);
objectArgs.add(seed);
this.plugin.getCommandHandler().queueCommand(sender, "mvregen", "regenWorld", objectArgs,
paramTypes, ChatColor.GREEN + "World Regenerated!", ChatColor.RED + "World could NOT be regenerated!");
private Runnable doWorldRegen(@NotNull CommandSender sender,
@NotNull String worldName,
boolean useSeed,
boolean randomSeed,
@NotNull String seed,
boolean keepGamerules) {
return () -> {
if (this.plugin.getMVWorldManager().regenWorld(worldName, useSeed, randomSeed, seed, keepGamerules)) {
sender.sendMessage(ChatColor.GREEN + "World Regenerated!");
return;
}
sender.sendMessage(ChatColor.RED + "World could NOT be regenerated!");
};
}
}
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.BlockSafety;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.command.CommandSender;
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
@@ -5,12 +5,13 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.Teleporter;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination;
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
@@ -27,7 +28,6 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import java.util.ArrayList;
import java.util.List;
/**
@@ -152,24 +152,27 @@ public class TeleportCommand extends MultiverseCommand {
if (result == TeleportResult.FAIL_UNSAFE) {
Logging.fine("Could not teleport " + teleportee.getName()
+ " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee)));
Logging.fine("Queueing Command");
Class<?>[] paramTypes = { CommandSender.class, Player.class, Location.class };
List<Object> items = new ArrayList<Object>();
items.add(teleporter);
items.add(teleportee);
items.add(d.getLocation(teleportee));
String player = "you";
if (!teleportee.equals(teleporter)) {
player = teleportee.getName();
}
String message = String.format("%sMultiverse %sdid not teleport %s%s %sto %s%s %sbecause it was unsafe.",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE);
this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "teleportPlayer", items,
paramTypes, message, "Would you like to try anyway?", "", "", UNSAFE_TELEPORT_EXPIRE_DELAY);
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
sender,
doUnsafeTeleport(teleporter, teleportee, d.getLocation(teleportee)),
String.format("%sMultiverse %sdid not teleport %s%s %sto %s%s %sbecause it was unsafe. Would you like to try anyway?",
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE),
UNSAFE_TELEPORT_EXPIRE_DELAY
));
}
// else: Player was teleported successfully (or the tp event was fired I should say)
}
private Runnable doUnsafeTeleport(CommandSender teleporter, Player player, Location location) {
return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, player, location, false);
}
private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) {
if (teleporter.equals(teleportee)) {
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) {
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
@@ -5,7 +5,11 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import java.io.File;
import java.util.List;
import java.util.Map;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
@@ -26,10 +30,6 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* Dumps version info to the console.
*/
@@ -45,8 +45,11 @@ public class VersionCommand extends MultiverseCommand {
this.addKey("mvver");
this.addKey("mvv");
this.addKey("mvversion");
this.setPermission("multiverse.core.version",
"Dumps version info to the console, optionally to pastebin.com with -b, to hastebin.com using -h, or to paste.gg with -p.", PermissionDefault.TRUE);
this.setPermission(
"multiverse.core.version",
"Dumps version info to the console, optionally to pastebin.com with -b, to hastebin.com using -h, or to paste.gg with -p.",
PermissionDefault.OP)
;
}
private String getLegacyString() {
@@ -60,7 +63,6 @@ public class VersionCommand extends MultiverseCommand {
+ "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + '\n'
+ "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + '\n'
+ "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + '\n'
+ "[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + '\n'
+ "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + '\n'
+ "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + '\n'
+ "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + '\n'
@@ -5,7 +5,7 @@
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.commandsold;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
@@ -0,0 +1,4 @@
/**
* This package contains all Commands.
*/
package com.onarandombox.MultiverseCore.commandsold;
@@ -0,0 +1,9 @@
package com.onarandombox.MultiverseCore.commandtools;
import co.aikar.commands.PaperCommandCompletions;
public class MVCommandCompletions extends PaperCommandCompletions {
public MVCommandCompletions(MVCommandManager mvCommandManager) {
super(mvCommandManager);
}
}
@@ -0,0 +1,9 @@
package com.onarandombox.MultiverseCore.commandtools;
import co.aikar.commands.PaperCommandContexts;
public class MVCommandContexts extends PaperCommandContexts {
public MVCommandContexts(MVCommandManager mvCommandManager) {
super(mvCommandManager);
}
}
@@ -0,0 +1,54 @@
package com.onarandombox.MultiverseCore.commandtools;
import java.util.Locale;
import co.aikar.commands.BukkitCommandCompletionContext;
import co.aikar.commands.BukkitCommandExecutionContext;
import co.aikar.commands.CommandCompletions;
import co.aikar.commands.CommandContexts;
import co.aikar.commands.PaperCommandManager;
import com.onarandombox.MultiverseCore.MultiverseCore;
/**
* Main class to manage permissions.
*/
public class MVCommandManager extends PaperCommandManager {
private final MultiverseCore plugin;
public MVCommandManager(MultiverseCore plugin) {
super(plugin);
this.plugin = plugin;
// Setup locale
this.addSupportedLanguage(Locale.ENGLISH);
this.locales.addMessageBundles("multiverse-core");
this.locales.loadLanguages();
}
/**
* Gets class responsible for parsing string args into objects.
*
* @return A not-null {@link CommandContexts}.
*/
@Override
public synchronized CommandContexts<BukkitCommandExecutionContext> getCommandContexts() {
if (this.contexts == null) {
this.contexts = new MVCommandContexts(this);
}
return this.contexts;
}
/**
* Gets class responsible for tab-completion handling.
*
* @return A not-null {@link CommandCompletions}.
*/
@Override
public synchronized CommandCompletions<BukkitCommandCompletionContext> getCommandCompletions() {
if (this.completions == null) {
this.completions = new MVCommandCompletions(this);
}
return this.completions;
}
}
@@ -0,0 +1,161 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2020. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commandtools.queue;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.block.data.type.CommandBlock;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.WeakHashMap;
/**
* <p>Manages the queuing of dangerous commands that require {@code /mv confirm} before executing.</p>
*
* <p>Each sender can only have one command in queue at any given time. When a queued command is added
* for a sender that already has a command in queue, it will replace the old queued command.</p>
*/
public class CommandQueueManager {
private static final long TICKS_PER_SECOND = 20;
private static final DummyCommandBlockSender COMMAND_BLOCK = new DummyCommandBlockSender();
private final MultiverseCore plugin;
private final Map<CommandSender, QueuedCommand> queuedCommandMap;
public CommandQueueManager(@NotNull MultiverseCore plugin) {
this.plugin = plugin;
this.queuedCommandMap = new WeakHashMap<>();
}
/**
* Adds a {@link QueuedCommand} into queue.
*
* @param queuedCommand The queued command to add.
*/
public void addToQueue(QueuedCommand queuedCommand) {
CommandSender targetSender = parseSender(queuedCommand.getSender());
// Since only one command is stored in queue per sender, we remove the old one.
this.removeFromQueue(targetSender);
Logging.finer("Add new command to queue for sender %s.", targetSender);
this.queuedCommandMap.put(targetSender, queuedCommand);
queuedCommand.setExpireTask(runExpireLater(queuedCommand));
queuedCommand.getSender().sendMessage(queuedCommand.getPrompt());
queuedCommand.getSender().sendMessage(String.format("Run %s/mv confirm %sto continue. This will expire in %s seconds.",
ChatColor.GREEN, ChatColor.WHITE, queuedCommand.getValidDuration()));
}
/**
* Expire task that removes a {@link QueuedCommand} from queue after valid duration defined.
*
* @param queuedCommand Command to run the expire task on.
* @return The expire {@link BukkitTask}.
*/
@NotNull
private BukkitTask runExpireLater(@NotNull QueuedCommand queuedCommand) {
return Bukkit.getScheduler().runTaskLater(
this.plugin,
expireRunnable(queuedCommand),
queuedCommand.getValidDuration() * TICKS_PER_SECOND
);
}
/**
* Runnable responsible for expiring the queued command.
*
* @param queuedCommand Command to create the expire task on.
* @return The expire runnable.
*/
@NotNull
private Runnable expireRunnable(@NotNull QueuedCommand queuedCommand) {
return () -> {
CommandSender targetSender = parseSender(queuedCommand.getSender());
QueuedCommand matchingQueuedCommand = this.queuedCommandMap.get(targetSender);
if (!queuedCommand.equals(matchingQueuedCommand) || queuedCommand.getExpireTask().isCancelled()) {
// To be safe, but this shouldn't happen since we cancel old commands before add new once.
Logging.finer("This is an old queue command already.");
return;
}
queuedCommand.getSender().sendMessage("Your queued command has expired.");
this.queuedCommandMap.remove(queuedCommand.getSender());
};
}
/**
* Runs the command in queue for the given sender, if any.
*
* @param sender {@link CommandSender} that confirmed the command.
* @return True if queued command ran successfully, else false.
*/
public boolean runQueuedCommand(@NotNull CommandSender sender) {
CommandSender targetSender = parseSender(sender);
QueuedCommand queuedCommand = this.queuedCommandMap.get(targetSender);
if (queuedCommand == null) {
sender.sendMessage(ChatColor.RED + "You do not have any commands in queue.");
return false;
}
Logging.finer("Running queued command...");
queuedCommand.getAction().run();
return removeFromQueue(targetSender);
}
/**
* Since only one command is stored in queue per sender, we remove the old one.
*
* @param sender The {@link CommandSender} that executed the command.
* @return True if queue command is removed from sender successfully, else false.
*/
public boolean removeFromQueue(@NotNull CommandSender sender) {
CommandSender targetSender = parseSender(sender);
QueuedCommand previousCommand = this.queuedCommandMap.remove(targetSender);
if (previousCommand == null) {
Logging.finer("No queue command to remove for sender %s.", targetSender.getName());
return false;
}
previousCommand.getExpireTask().cancel();
Logging.finer("Removed queue command for sender %s.", targetSender.getName());
return true;
}
/**
* To allow all CommandBlocks to be a common sender with use of {@link DummyCommandBlockSender}.
* So confirm command can be used for a queued command on another command block.
*
* @param sender The sender to parse.
* @return The sender, or if its a command block, a {@link DummyCommandBlockSender}.
*/
@NotNull
private CommandSender parseSender(@NotNull CommandSender sender) {
Logging.fine(sender.getClass().getName());
if (isCommandBlock(sender)) {
Logging.finer("Is command block.");
return COMMAND_BLOCK;
}
return sender;
}
/**
* Checks if the sender is a command block.
*
* @param sender The sender to check.
* @return True if sender is a command block, else false.
*/
private boolean isCommandBlock(@NotNull CommandSender sender) {
return sender instanceof BlockCommandSender
&& ((BlockCommandSender) sender).getBlock().getBlockData() instanceof CommandBlock;
}
}
@@ -0,0 +1,121 @@
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;
import java.util.UUID;
/**
* 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 void sendMessage(@Nullable UUID uuid, @NotNull String s) {
throw new UnsupportedOperationException();
}
@Override
public void sendMessage(@Nullable UUID uuid, @NotNull String[] strings) {
throw new UnsupportedOperationException();
}
@Override
public @NotNull Server getServer() {
return Bukkit.getServer();
}
@Override
public @NotNull String getName() {
return "DummyCommandBlockSender";
}
@NotNull
@Override
public Spigot spigot() {
throw new UnsupportedOperationException();
}
@Override
public boolean isPermissionSet(@NotNull String name) {
throw new UnsupportedOperationException();
}
@Override
public boolean isPermissionSet(@NotNull Permission perm) {
throw new UnsupportedOperationException();
}
@Override
public boolean hasPermission(@NotNull String name) {
throw new UnsupportedOperationException();
}
@Override
public boolean hasPermission(@NotNull Permission perm) {
throw new UnsupportedOperationException();
}
@Override
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) {
throw new UnsupportedOperationException();
}
@Override
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin) {
throw new UnsupportedOperationException();
}
@Override
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) {
throw new UnsupportedOperationException();
}
@Override
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) {
throw new UnsupportedOperationException();
}
@Override
public void removeAttachment(@NotNull PermissionAttachment attachment) {
throw new UnsupportedOperationException();
}
@Override
public void recalculatePermissions() {
throw new UnsupportedOperationException();
}
@Override
public @NotNull Set<PermissionAttachmentInfo> getEffectivePermissions() {
throw new UnsupportedOperationException();
}
@Override
public boolean isOp() {
throw new UnsupportedOperationException();
}
@Override
public void setOp(boolean value) {
throw new UnsupportedOperationException();
}
}
@@ -0,0 +1,86 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2020. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.commandtools.queue;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
/**
* Represents a single command used in {@link CommandQueueManager} for confirming before running potentially
* dangerous action.
*/
public class QueuedCommand {
private static final String DEFAULT_PROMPT_MESSAGE = "The command you are trying to run is deemed dangerous.";
private static final int DEFAULT_VALID_TIME = 10;
private final CommandSender sender;
private final Runnable action;
private final String prompt;
private final int validDuration;
private BukkitTask expireTask;
public QueuedCommand(CommandSender sender, Runnable action) {
this(sender, action, DEFAULT_PROMPT_MESSAGE, DEFAULT_VALID_TIME);
}
public QueuedCommand(CommandSender sender, Runnable action, String prompt) {
this(sender, action, prompt, DEFAULT_VALID_TIME);
}
public QueuedCommand(CommandSender sender, Runnable action, int validDuration) {
this(sender, action, DEFAULT_PROMPT_MESSAGE, validDuration);
}
/**
* Creates a new queue command, to be registered at {@link CommandQueueManager#addToQueue(QueuedCommand)}.
*
* @param sender The sender that ran the command needed for confirmation.
* @param action The logic to execute upon confirming.
* @param prompt Question to ask sender to confirm.
* @param validDuration Duration in which the command is valid for confirm in seconds.
*/
public QueuedCommand(CommandSender sender, Runnable action, String prompt, int validDuration) {
this.sender = sender;
this.action = action;
this.prompt = prompt;
this.validDuration = validDuration;
}
@NotNull
CommandSender getSender() {
return sender;
}
@NotNull
String getPrompt() {
return prompt;
}
int getValidDuration() {
return validDuration;
}
@NotNull
Runnable getAction() {
return action;
}
@NotNull
BukkitTask getExpireTask() {
return expireTask;
}
void setExpireTask(@NotNull BukkitTask expireTask) {
if (this.expireTask != null) {
throw new IllegalStateException("This queue command already has an expire task. You can't register twice!");
}
this.expireTask = expireTask;
}
}
@@ -0,0 +1,4 @@
/**
* Manager queuing of dangerous commands in need of confirmation.
*/
package com.onarandombox.MultiverseCore.commandtools.queue;
@@ -1,14 +1,10 @@
package com.onarandombox.MultiverseCore.configuration;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
@@ -18,54 +14,16 @@ import org.bukkit.configuration.serialization.SerializableAs;
*/
@SerializableAs("MVSpawnLocation")
public class SpawnLocation extends Location implements ConfigurationSerializable {
private Reference<World> worldRef;
public SpawnLocation(double x, double y, double z) {
super(null, x, y, z);
public SpawnLocation(World world, double x, double y, double z) {
super(world, x, y, z);
}
public SpawnLocation(double x, double y, double z, float yaw, float pitch) {
super(null, x, y, z, yaw, pitch);
public SpawnLocation(World world, double x, double y, double z, float yaw, float pitch) {
super(world, x, y, z, yaw, pitch);
}
public SpawnLocation(Location loc) {
this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
}
/**
* {@inheritDoc}
*/
@Override
public World getWorld() {
return (this.worldRef != null) ? this.worldRef.get() : null;
}
/**
* {@inheritDoc}
*/
@Override
public void setWorld(World world) {
this.worldRef = new WeakReference<World>(world);
}
/**
* {@inheritDoc}
*/
@Override
public Chunk getChunk() {
if ((this.worldRef != null) && (this.worldRef.get() != null))
return this.worldRef.get().getChunkAt(this);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Block getBlock() {
if ((this.worldRef != null) && (this.worldRef.get() != null))
return this.worldRef.get().getBlockAt(this);
return null;
super(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
}
/**
@@ -93,6 +51,6 @@ public class SpawnLocation extends Location implements ConfigurationSerializable
double z = ((Number) args.get("z")).doubleValue();
float pitch = ((Number) args.get("pitch")).floatValue();
float yaw = ((Number) args.get("yaw")).floatValue();
return new SpawnLocation(x, y, z, yaw, pitch);
return new SpawnLocation(null, x, y, z, yaw, pitch);
}
}
@@ -9,17 +9,15 @@ package com.onarandombox.MultiverseCore.destination;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
import com.onarandombox.MultiverseCore.commandsold.TeleportCommand;
import com.onarandombox.MultiverseCore.utils.PermissionTools;
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
import com.pneumaticraft.commandhandler.Command;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
@@ -27,7 +25,9 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
/** A factory class that will create destinations from specific strings. */
/**
* A factory class that will create destinations from specific strings.
*/
public class DestinationFactory {
private static final Pattern CANNON_PATTERN = Pattern.compile("(?i)cannon-[\\d]+(\\.[\\d]+)?");
@@ -165,7 +165,12 @@ public class DestinationFactory {
this.teleportCommand.addAdditonalPermission(other);
return true;
}
/**
* Gets all the {@link MVDestination} identifiers registered.
*
* @return A collection of destination identifiers.
*/
public Collection<String> getRegisteredIdentifiers() {
return this.destList.keySet();
}
@@ -0,0 +1,69 @@
package com.onarandombox.MultiverseCore.display;
import com.onarandombox.MultiverseCore.display.handlers.DefaultSendHandler;
import com.onarandombox.MultiverseCore.display.handlers.SendHandler;
import com.onarandombox.MultiverseCore.display.parsers.ContentParser;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Helps to display contents such as list and maps in a nicely formatted fashion.
*/
public class ContentDisplay {
/**
* Makes a new {@link ContentDisplay} instance to use.
*
* @return New {@link ContentDisplay} instance.
*/
@NotNull
public static ContentDisplay create() {
return new ContentDisplay();
}
private final List<ContentParser> contentParsers = new ArrayList<>();
private SendHandler sendHandler = DefaultSendHandler.getInstance();
public ContentDisplay() {
}
/**
* Adds content to be displayed.
*
* @param parser The content parser to add.
* @return Same {@link ContentDisplay} for method chaining.
*/
@NotNull
public ContentDisplay addContentParser(@NotNull ContentParser parser) {
contentParsers.add(parser);
return this;
}
/**
* Sets the handler for displaying the message to command sender.
*
* @param handler The send handler to use.
* @return Same {@link ContentDisplay} for method chaining.
*/
@NotNull
public ContentDisplay withSendHandler(@NotNull SendHandler handler) {
sendHandler = handler;
return this;
}
/**
* Format and display the message to command sender.
*
* @param sender The target command sender to show the display to.
*/
public void send(@NotNull CommandSender sender) {
Objects.requireNonNull(sendHandler, "No send handler set for content display");
List<String> parsedContent = new ArrayList<>();
contentParsers.forEach(parser -> parser.parse(sender, parsedContent));
sendHandler.send(sender, parsedContent);
}
}
@@ -0,0 +1,21 @@
package com.onarandombox.MultiverseCore.display.filters;
/**
* Filter display content for it show only certain string.
*/
public interface ContentFilter {
/**
* Checks if a particular string should be displayed.
*
* @param value String to check on.
* @return True if should be display, false otherwise.
*/
boolean checkMatch(String value);
/**
* Gets whether content needs to be filtered by this filter.
*
* @return True if content should be filtered, false otherwise.
*/
boolean needToFilter();
}
@@ -0,0 +1,35 @@
package com.onarandombox.MultiverseCore.display.filters;
/**
* Default implementation of {@link ContentFilter} that doesn't filter anything.
*/
public class DefaultContentFilter implements ContentFilter {
public static DefaultContentFilter instance;
public static DefaultContentFilter getInstance() {
if (instance == null) {
instance = new DefaultContentFilter();
}
return instance;
}
private DefaultContentFilter() {
}
/**
* {@inheritDoc}
*/
@Override
public boolean checkMatch(String value) {
return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean needToFilter() {
return false;
}
}
@@ -0,0 +1,99 @@
package com.onarandombox.MultiverseCore.display.filters;
import com.dumptruckman.minecraft.util.Logging;
import com.google.common.base.Strings;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/**
* Filter content and text based on regex matching.
*/
public class RegexContentFilter implements ContentFilter {
private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]");
/**
* Compile regex pattern to create a regex filter.
*
* When prefixed with 'r=', filter string is used as the full regex pattern.
* Else, set to regex that contains the filterString.
*
* @param filterString The target string to create filter.
* @return A new instance of {@link RegexContentFilter} with filter applied.
*/
@NotNull
public static RegexContentFilter fromString(@Nullable String filterString) {
if (filterString == null) {
return new RegexContentFilter(null);
}
if (filterString.startsWith("r=")) {
return new RegexContentFilter(filterString.substring(2));
}
String cleanedFilter = REGEX_SPECIAL_CHARS.matcher(filterString.toLowerCase()).replaceAll("\\\\$0");
return new RegexContentFilter("(?i).*" + cleanedFilter + ".*");
}
private final String regexString;
private Pattern regexPattern;
public RegexContentFilter(@Nullable String regexString) {
this.regexString = regexString;
convertToPattern();
}
/**
* Try to compile and store the regex into a {@link Pattern}.
*/
private void convertToPattern() {
if (Strings.isNullOrEmpty(regexString)) {
return;
}
try {
regexPattern = Pattern.compile(regexString);
} catch (PatternSyntaxException ignored) {
regexPattern = null;
Logging.fine("Error parsing regex: %s", regexString);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean checkMatch(String value) {
if (!hasValidRegex()) {
return false;
}
String text = ChatColor.stripColor(String.valueOf(value));
return regexPattern.matcher(text).find();
}
/**
* {@inheritDoc}
*/
@Override
public boolean needToFilter() {
return hasValidRegex();
}
public boolean hasValidRegex() {
return regexPattern != null;
}
public String getRegexString() {
return regexString;
}
public Pattern getRegexPattern() {
return regexPattern;
}
@Override
public String toString() {
return regexString;
}
}
@@ -0,0 +1,99 @@
package com.onarandombox.MultiverseCore.display.handlers;
import com.google.common.base.Strings;
import com.onarandombox.MultiverseCore.display.filters.ContentFilter;
import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
/**
* Base implementation of {@link SendHandler} with some common parameters.
*
* @param <T> The subclass that inherited this baseclass.
*/
public abstract class BaseSendHandler<T extends BaseSendHandler<?>> implements SendHandler {
protected String header = "";
protected ContentFilter filter = DefaultContentFilter.getInstance();
/**
* {@inheritDoc}
*/
@Override
public void send(@NotNull CommandSender sender, @NotNull List<String> content) {
sendHeader(sender);
List<String> filteredContent = filterContent(content);
if (filteredContent.isEmpty()) {
sender.sendMessage(String.format("%sThere is no content to display.", ChatColor.RED));
return;
}
sendContent(sender, filteredContent);
}
/**
* Sends the header if header is present.
*
* @param sender The target which the header will be displayed to.
*/
protected void sendHeader(CommandSender sender) {
if (!Strings.isNullOrEmpty(header)) {
sender.sendMessage(header);
}
}
/**
* Filter to keep only contents that matches the filter.
*
* @param content The content to filter on.
* @return The filtered list of content.
*/
protected List<String> filterContent(@NotNull List<String> content) {
if (filter.needToFilter()) {
return content.stream().filter(filter::checkMatch).collect(Collectors.toList());
}
return content;
}
/**
* Display the contents.
*
* @param sender The target which the content will be displayed to.
* @param content The content to display.
*/
protected abstract void sendContent(@NotNull CommandSender sender, @NotNull List<String> content);
/**
* Sets header to be displayed.
*
* @param header The header text.
* @param replacements String formatting replacements.
* @return Same {@link T} for method chaining.
*/
public T withHeader(@NotNull String header, @NotNull Object...replacements) {
this.header = String.format(header, replacements);
return (T) this;
}
/**
* Sets content filter used to match specific content to be displayed.
*
* @param filter The filter to use.
* @return Same {@link T} for method chaining.
*/
public T withFilter(@NotNull ContentFilter filter) {
this.filter = filter;
return (T) this;
}
public String getHeader() {
return header;
}
public ContentFilter getFilter() {
return filter;
}
}
@@ -0,0 +1,29 @@
package com.onarandombox.MultiverseCore.display.handlers;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class DefaultSendHandler implements SendHandler {
private static DefaultSendHandler instance;
public static DefaultSendHandler getInstance() {
if (instance == null) {
instance = new DefaultSendHandler();
}
return instance;
}
private DefaultSendHandler() {
}
/**
* {@inheritDoc}
*/
@Override
public void send(@NotNull CommandSender sender, @NotNull List<String> content) {
sender.sendMessage(content.toArray(new String[0]));
}
}
@@ -0,0 +1,53 @@
package com.onarandombox.MultiverseCore.display.handlers;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Display the contents in a single line.
*/
public class InlineSendHandler extends BaseSendHandler<InlineSendHandler> {
/**
* Makes a new {@link InlineSendHandler} instance to use.
*
* @return New {@link InlineSendHandler} instance.
*/
public static InlineSendHandler create() {
return new InlineSendHandler();
}
private String delimiter = ChatColor.WHITE + ", ";
public InlineSendHandler() {
}
/**
* {@inheritDoc}
*/
@Override
public void sendContent(@NotNull CommandSender sender, @NotNull List<String> content) {
if (filter.needToFilter()) {
sender.sendMessage(String.format("%s[Filter '%s']", ChatColor.GRAY, filter));
}
sender.sendMessage(String.join(delimiter, content));
}
/**
* Sets the delimiter. A sequence of characters that is used to separate each of the elements in content.
*
* @param delimiter The delimiter to use.
* @return Same {@link InlineSendHandler} for method chaining.
*/
public InlineSendHandler withDelimiter(String delimiter) {
this.delimiter = delimiter;
return this;
}
public String getDelimiter() {
return delimiter;
}
}
@@ -0,0 +1,170 @@
package com.onarandombox.MultiverseCore.display.handlers;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Display content as a list with optional pagination.
*/
public class PagedSendHandler extends BaseSendHandler<PagedSendHandler> {
/**
* Makes a new {@link PagedSendHandler} instance to use.
*
* @return New {@link PagedSendHandler} instance.
*/
public static PagedSendHandler create() {
return new PagedSendHandler();
}
private boolean paginate = true;
private boolean paginateInConsole = false;
private boolean padEnd = true;
private int linesPerPage = 8;
private int targetPage = 1;
public PagedSendHandler() {
}
/**
* {@inheritDoc}
*/
@Override
public void sendContent(@NotNull CommandSender sender,
@NotNull List<String> content) {
if (!paginate || (sender instanceof ConsoleCommandSender && !paginateInConsole)) {
sendNormal(sender, content);
return;
}
sendPaged(sender, content);
}
/**
* Send content list without pagination.
*
* @param sender The target which the content will be displayed to.
* @param content The content to display.
*/
private void sendNormal(@NotNull CommandSender sender,
@NotNull List<String> content) {
if (filter.needToFilter()) {
sender.sendMessage(String.format("%s[Filter '%s']", ChatColor.GRAY, filter));
}
sender.sendMessage(content.toArray(new String[0]));
}
/**
* Send content list with pagination.
*
* @param sender The target which the content will be displayed to.
* @param content The content to display.
*/
private void sendPaged(@NotNull CommandSender sender,
@NotNull List<String> content) {
int totalPages = (content.size() + linesPerPage - 1) / linesPerPage; // Basically just divide round up
if (targetPage < 1 || targetPage > totalPages) {
sender.sendMessage(String.format("%sInvalid page number. Please enter a page number between 1 and %s", ChatColor.RED, totalPages));
return;
}
if (filter.needToFilter()) {
sender.sendMessage(String.format("%s[Page %s of %s] [Filter '%s']", ChatColor.GRAY, targetPage, totalPages, filter));
} else {
sender.sendMessage(String.format("%s[Page %s of %s]", ChatColor.GRAY, targetPage, totalPages));
}
int startIndex = (targetPage - 1) * linesPerPage;
int pageEndIndex = startIndex + linesPerPage;
int endIndex = Math.min(pageEndIndex, content.size());
List<String> pageContent = content.subList(startIndex, endIndex);
if (padEnd) {
for (int i = 0; i < (pageEndIndex - endIndex); i++) {
pageContent.add("");
}
}
sender.sendMessage(pageContent.toArray(new String[0]));
}
/**
* Sets whether display output should be paginated.
*
* @param paginate State of doing pagination.
* @return Same {@link PagedSendHandler} for method chaining.
*/
public PagedSendHandler doPagination(boolean paginate) {
this.paginate = paginate;
return this;
}
/**
* Sets whether display output should be paginated if is for console output.
* This option will be useless of {@link PagedSendHandler#paginate} is set to false.
*
* @param paginateInConsole State of doing pagination in console.
* @return Same {@link PagedSendHandler} for method chaining.
*/
public PagedSendHandler doPaginationInConsole(boolean paginateInConsole) {
this.paginateInConsole = paginateInConsole;
return this;
}
/**
* Sets whether empty lines should be added if content lines shown is less that {@link PagedSendHandler#linesPerPage}.
*
* @param padEnd State of doing end padding.
* @return Same {@link PagedSendHandler} for method chaining.
*/
public PagedSendHandler doEndPadding(boolean padEnd) {
this.padEnd = padEnd;
return this;
}
/**
* Sets the max number of lines per page. This excludes header.
*
* @param linesPerPage The number of lines per page.
* @return Same {@link PagedSendHandler} for method chaining.
*/
public PagedSendHandler withLinesPerPage(int linesPerPage) {
this.linesPerPage = linesPerPage;
return this;
}
/**
* Sets the page number to display.
*
* @param targetPage The target page number to display.
* @return Same {@link PagedSendHandler} for method chaining.
*/
public PagedSendHandler withTargetPage(int targetPage) {
this.targetPage = targetPage;
return this;
}
public boolean isPaginate() {
return paginate;
}
public boolean isPaginateInConsole() {
return paginateInConsole;
}
public boolean isPadEnd() {
return padEnd;
}
public int getLinesPerPage() {
return linesPerPage;
}
public int getTargetPage() {
return targetPage;
}
}
@@ -0,0 +1,20 @@
package com.onarandombox.MultiverseCore.display.handlers;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Handles the sending of all content to the command sender.
*/
@FunctionalInterface
public interface SendHandler {
/**
* Sends all the content to the given command sender.
*
* @param sender The target which the content will be displayed to.
* @param content The content to display.
*/
void send(@NotNull CommandSender sender, @NotNull List<String> content);
}
@@ -0,0 +1,20 @@
package com.onarandombox.MultiverseCore.display.parsers;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Parse objects into string or list of strings.
*/
@FunctionalInterface
public interface ContentParser {
/**
* Parse the object to string(s) and add it to the content.
*
* @param sender The target which the content will be displayed to.
* @param content The content to display.
*/
void parse(@NotNull CommandSender sender, @NotNull List<String> content);
}
@@ -0,0 +1,60 @@
package com.onarandombox.MultiverseCore.display.parsers;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Simple parser for list object.
*
* @param <T> List element type.
*/
public class ListContentParser<T> implements ContentParser {
/**
* New list content parser for the given list.
*
* @param list The list object to parse.
* @param <T> List element type.
* @return New {@link MapContentParser} instance.
*/
public static <T> ListContentParser<T> forContent(List<T> list) {
return new ListContentParser<>(list);
}
private final List<T> list;
private String format = "%s";
public ListContentParser(List<T> list) {
this.list = list;
}
/**
* {@inheritDoc}
*/
@Override
public void parse(@NotNull CommandSender sender, @NotNull List<String> content) {
list.forEach(element -> content.add(String.format(format, element)));
}
/**
* Sets the format that will be used to parse each list entry. Uses java string format pattern.
*
* @param format The format to use.
* @return Same {@link ListContentParser} for method chaining.
*/
public ListContentParser<T> withFormat(String format) {
this.format = format;
return this;
}
public List<T> getList() {
return list;
}
public String getFormat() {
return format;
}
}
@@ -0,0 +1,112 @@
package com.onarandombox.MultiverseCore.display.parsers;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
/**
* Simple parser for map object.
*
* @param <K> Key type.
* @param <V> Value type.
*/
public class MapContentParser<K, V> implements ContentParser {
/**
* New map content parser for the given map.
*
* @param map The map object to parse.
* @param <K> Key type.
* @param <V> Value type.
* @return New {@link MapContentParser} instance.
*/
public static <K, V> MapContentParser<K, V> forContent(Map<K, V> map) {
return new MapContentParser<>(map);
}
private final Map<K, V> map;
private String format = "%s%s%s%s%s";
private ChatColor keyColor = ChatColor.WHITE;
private ChatColor valueColor = ChatColor.WHITE;
private String separator = ": ";
public MapContentParser(Map<K, V> map) {
this.map = map;
}
/**
* {@inheritDoc}
*/
@Override
public void parse(@NotNull CommandSender sender, @NotNull List<String> content) {
map.forEach((k, v) -> content.add(String.format(format, keyColor, k, separator, valueColor, v)));
}
/**
* Sets the format that will be used to parse each map entry. Uses java string format pattern.
*
* @param format The format to use.
* @return Same {@link MapContentParser} for method chaining.
*/
public MapContentParser<K, V> withFormat(String format) {
this.format = format;
return this;
}
/**
* Sets the color for the key text.
*
* @param keyColor The color to use.
* @return Same {@link MapContentParser} for method chaining.
*/
public MapContentParser<K, V> withKeyColor(ChatColor keyColor) {
this.keyColor = keyColor;
return this;
}
/**
* Sets the color for the value text.
*
* @param valueColor The color to use.
* @return Same {@link MapContentParser} for method chaining.
*/
public MapContentParser<K, V> withValueColor(ChatColor valueColor) {
this.valueColor = valueColor;
return this;
}
/**
* Sets the separator between each key value pairing.
*
* @param separator The separator to use.
* @return Same {@link MapContentParser} for method chaining.
*/
public MapContentParser<K, V> withSeparator(String separator) {
this.separator = separator;
return this;
}
public Map<K, V> getMap() {
return map;
}
public String getFormat() {
return format;
}
public ChatColor getKeyColor() {
return keyColor;
}
public ChatColor getValueColor() {
return valueColor;
}
public String getSeparator() {
return separator;
}
}
@@ -1,35 +0,0 @@
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
/**
* A wrapper for the {@link AsyncPlayerChatEvent}.
*/
public class AsyncChatEvent implements ChatEvent {
private final AsyncPlayerChatEvent event;
public AsyncChatEvent(AsyncPlayerChatEvent event) {
this.event = event;
}
@Override
public boolean isCancelled() {
return event.isCancelled();
}
@Override
public String getFormat() {
return event.getFormat();
}
@Override
public void setFormat(String s) {
event.setFormat(s);
}
@Override
public Player getPlayer() {
return event.getPlayer();
}
}
@@ -1,29 +0,0 @@
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.entity.Player;
/**
* A wrapper for the two chat-events in Bukkit.
*/
public interface ChatEvent {
/**
* @return Whether this event is cancelled.
*/
boolean isCancelled();
/**
* @return The format.
*/
String getFormat();
/**
* Sets the format.
* @param s The new format.
*/
void setFormat(String s);
/**
* @return The player.
*/
Player getPlayer();
}
@@ -1,35 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.listeners;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.onarandombox.MultiverseCore.MultiverseCore;
/**
* Multiverse's {@link org.bukkit.event.Listener} for players.
*/
public class MVAsyncPlayerChatListener extends MVChatListener {
public MVAsyncPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
super(plugin, playerListener);
Logging.fine("Created AsyncPlayerChatEvent listener.");
}
/**
* This method is called when a player wants to chat.
* @param event The Event that was fired.
*/
@EventHandler
public void playerChat(AsyncPlayerChatEvent event) {
this.playerChat(new AsyncChatEvent(event));
}
}
@@ -5,12 +5,14 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
/**
* Multiverse's {@link org.bukkit.event.Listener} for players.
*/
public abstract class MVChatListener implements Listener {
public class MVChatListener implements Listener {
private final MultiverseCore plugin;
private final MVWorldManager worldManager;
private final MVPlayerListener playerListener;
@@ -22,10 +24,11 @@ public abstract class MVChatListener implements Listener {
}
/**
* This handles a {@link ChatEvent}.
* @param event The {@link ChatEvent}.
* This handles a {@link AsyncPlayerChatEvent}.
* @param event The {@link AsyncPlayerChatEvent}.
*/
public void playerChat(ChatEvent event) {
@EventHandler
public void playerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
@@ -18,12 +18,11 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import java.util.logging.Level;
/**
* Multiverse's Entity {@link Listener}.
*/
@@ -107,4 +106,17 @@ public class MVEntityListener implements Listener {
event.setCancelled(this.plugin.getMVWorldManager().getTheWorldPurger().shouldWeKillThisCreature(mvworld, event.getEntity()));
}
/**
* Handles portal search radius adjustment.
* @param event The Event that was fired.
*/
@EventHandler
public void entityPortal(EntityPortalEvent event) {
if (event.isCancelled() || event.getTo() == null) {
return;
}
if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) {
event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius());
}
}
}
@@ -1,43 +0,0 @@
package com.onarandombox.MultiverseCore.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.MapInitializeEvent;
import org.bukkit.map.MapView;
/**
* A listener for bukkit map events.
*/
public class MVMapListener implements Listener {
private final MultiverseCore plugin;
public MVMapListener(final MultiverseCore plugin) {
this.plugin = plugin;
}
/**
* This method is called when a map is initialized.
* @param event The event that was fired.
*/
@EventHandler
public void mapInitialize(final MapInitializeEvent event) {
for (final Player player : Bukkit.getOnlinePlayers()) {
if ((player.getItemInHand().getType() == Material.MAP
|| player.getItemInHand().getType() == Material.FILLED_MAP)
&& player.getItemInHand().getDurability() == event.getMap().getId()) {
final Location playerLoc = player.getLocation();
final MapView map = event.getMap();
map.setCenterX(playerLoc.getBlockX());
map.setCenterZ(playerLoc.getBlockZ());
map.setWorld(playerLoc.getWorld());
return;
}
}
}
}
@@ -1,36 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.listeners;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerChatEvent;
import com.onarandombox.MultiverseCore.MultiverseCore;
/**
* Multiverse's {@link org.bukkit.event.Listener} for players.
*/
@SuppressWarnings("deprecation") // this exists only for downwards compatibility
public class MVPlayerChatListener extends MVChatListener {
public MVPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) {
super(plugin, playerListener);
Logging.fine("Registered PlayerChatEvent listener.");
}
/**
* This method is called when a player wants to chat.
* @param event The Event that was fired.
*/
@EventHandler
public void playerChat(PlayerChatEvent event) {
this.playerChat(new NormalChatEvent(event));
}
}
@@ -9,15 +9,12 @@ package com.onarandombox.MultiverseCore.listeners;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.enums.RespawnType;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.utils.CompatibilityLayer;
import com.onarandombox.MultiverseCore.utils.PermissionTools;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -71,16 +68,8 @@ public class MVPlayerListener implements Listener {
return;
}
RespawnType respawnType = RespawnType.OTHER;
if (event.isBedSpawn()) {
respawnType = RespawnType.BED;
}
if (CompatibilityLayer.isAnchorSpawn(event)) {
respawnType = RespawnType.ANCHOR;
}
if (mvWorld.getBedRespawn() && (respawnType == RespawnType.BED || respawnType == RespawnType.ANCHOR)) {
Logging.fine("Spawning %s at their %s", event.getPlayer().getName(), respawnType);
if (mvWorld.getBedRespawn() && (event.isBedSpawn() || event.isAnchorSpawn())) {
Logging.fine("Spawning %s at their %s.", event.getPlayer().getName(), event.isBedSpawn() ? "BED" : "ANCHOR");
return;
}
@@ -313,16 +302,8 @@ public class MVPlayerListener implements Listener {
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
+ "' because enforceaccess is off.");
}
if (!plugin.getMVConfig().isUsingDefaultPortalSearch()) {
try {
Class.forName("org.bukkit.TravelAgent");
if (event.getPortalTravelAgent() != null) {
event.getPortalTravelAgent().setSearchRadius(plugin.getMVConfig().getPortalSearchRadius());
}
} catch (ClassNotFoundException ignore) {
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
}
if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) {
event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius());
}
}
@@ -12,15 +12,13 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.Material;
import org.bukkit.PortalType;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityCreatePortalEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.PortalCreateEvent;
import java.util.logging.Level;
/**
* A custom listener for portal related events.
*/
@@ -33,31 +31,48 @@ public class MVPortalListener implements Listener {
}
/**
* This is called when an entity creates a portal.
*
* @param event The event where an entity created a portal.
*/
@EventHandler
public void entityPortalCreate(EntityCreatePortalEvent event) {
if (event.isCancelled() || event.getBlocks().size() == 0) {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getEntity().getWorld());
// We have to do it like this due to a bug in 1.1-R3
if (world != null && !world.getAllowedPortals().isPortalAllowed(event.getPortalType())) {
event.setCancelled(true);
}
}
/**
* This is called when a portal is created as the result of another world being linked.
* @param event The event where a portal was formed due to a world link
* This is called when a portal is formed.
* @param event The event where a portal was created or formed due to a world link
*/
@EventHandler(ignoreCancelled = true)
public void portalForm(PortalCreateEvent event) {
Logging.fine("Attempting to create portal at '%s' with reason: %s", event.getWorld().getName(), event.getReason());
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld());
if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.NETHER)) {
Logging.fine("Cancelling creation of nether portal because portalForm disallows.");
if (world == null) {
Logging.fine("World '%s' is not managed by Multiverse! Ignoring at PortalCreateEvent.", event.getWorld().getName());
return;
}
PortalType targetType;
switch (event.getReason()) {
case FIRE:
// Ensure portal by flint and steel actually creates nether
boolean isNether = false;
for (BlockState block : event.getBlocks()) {
if (block.getType() == Material.NETHER_PORTAL) {
isNether = true;
break;
}
}
if (!isNether) {
return;
}
targetType = PortalType.NETHER;
break;
case NETHER_PAIR:
targetType = PortalType.NETHER;
break;
case END_PLATFORM:
targetType = PortalType.ENDER;
break;
default:
Logging.fine("Portal created is not NETHER or ENDER type. Ignoring...");
return;
}
if (!world.getAllowedPortals().isPortalAllowed(targetType)) {
Logging.fine("Cancelling creation of %s portal because portalForm disallows.", targetType);
event.setCancelled(true);
}
}
@@ -72,15 +87,22 @@ public class MVPortalListener implements Listener {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
if (event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) {
if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) {
return;
}
if (event.getItem() == null || event.getItem().getType() != Material.ENDER_EYE) {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld());
if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) {
Logging.fine("Cancelling creation of ender portal because portalForm disallows.");
if (world == null) {
Logging.fine("World '%s' is not managed by Multiverse! Ignoring at PlayerInteractEvent.",
event.getPlayer().getWorld().getName());
return;
}
if (!world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) {
Logging.fine("Cancelling creation of ENDER portal because portalForm disallows.");
event.setCancelled(true);
}
}
@@ -1,37 +0,0 @@
package com.onarandombox.MultiverseCore.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
/**
* A wrapper for the {@link PlayerChatEvent}.
* @deprecated This is deprecated like the {@link PlayerChatEvent}.
*/
@Deprecated
public class NormalChatEvent implements ChatEvent {
private final PlayerChatEvent event;
public NormalChatEvent(PlayerChatEvent event) {
this.event = event;
}
@Override
public boolean isCancelled() {
return event.isCancelled();
}
@Override
public String getFormat() {
return event.getFormat();
}
@Override
public void setFormat(String s) {
event.setFormat(s);
}
@Override
public Player getPlayer() {
return event.getPlayer();
}
}
@@ -0,0 +1,18 @@
package com.onarandombox.MultiverseCore.locale;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
public enum MVCorei18n implements MessageKeyProvider {
CONFIG_SAVE_FAILED,
DEBUG_INFO_OFF,
DEBUG_INFO_ON;
private final MessageKey key = MessageKey.of("mv-core." + this.name().toLowerCase());
@Override
public MessageKey getMessageKey() {
return this.key;
}
}
@@ -1,111 +0,0 @@
package com.onarandombox.MultiverseCore.utils;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.destination.CannonDestination;
import org.bukkit.Location;
import org.bukkit.TravelAgent;
import org.bukkit.event.player.PlayerPortalEvent;
public class BukkitTravelAgent implements TravelAgent {
private final MVTravelAgent agent;
public BukkitTravelAgent(MVTravelAgent agent) {
this.agent = agent;
}
/**
* {@inheritDoc}
*/
@Override
public BukkitTravelAgent setSearchRadius(int radius) {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int getSearchRadius() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public BukkitTravelAgent setCreationRadius(int radius) {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int getCreationRadius() {
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean getCanCreatePortal() {
return false;
}
/**
* {@inheritDoc}
*/
@Override
public void setCanCreatePortal(boolean create) {
}
/**
* {@inheritDoc}
*/
@Override
public Location findOrCreate(Location location) {
return this.getSafeLocation();
}
/**
* {@inheritDoc}
*/
@Override
public Location findPortal(Location location) {
return this.getSafeLocation();
}
/**
* {@inheritDoc}
*/
@Override
public boolean createPortal(Location location) {
return false;
}
private Location getSafeLocation() {
// At this time, these can never use the velocity.
if (agent.destination instanceof CannonDestination) {
Logging.fine("Using Stock TP method. This cannon will have 0 velocity");
}
SafeTTeleporter teleporter = agent.core.getSafeTTeleporter();
Location newLoc = agent.destination.getLocation(agent.player);
if (agent.destination.useSafeTeleporter()) {
newLoc = teleporter.getSafeLocation(agent.player, agent.destination);
}
if (newLoc == null) {
return agent.player.getLocation();
}
return newLoc;
}
public void setPortalEventTravelAgent(PlayerPortalEvent event) {
event.setPortalTravelAgent(this);
event.useTravelAgent(true);
}
}
@@ -1,46 +0,0 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerRespawnEvent;
import java.lang.reflect.Method;
/**
* A utility class to enable version specific minecraft features.
*/
public class CompatibilityLayer {
private static Method checkAnchorSpawn;
/**
* Initialise the reflection methods.
*/
public static void init() {
try {
checkAnchorSpawn = PlayerRespawnEvent.class.getDeclaredMethod("isAnchorSpawn");
} catch (NoSuchMethodException e) {
Logging.fine("%s does not support respawn anchors.", Bukkit.getVersion());
}
}
/**
* Check if the respawn point is of respawn anchor type.
* Introduced in minecraft 1.16
*
* @param event A player respawn event.
* @return If the respawn location is an anchor point.
*/
public static boolean isAnchorSpawn(PlayerRespawnEvent event) {
if (checkAnchorSpawn == null) {
return false;
}
try {
return (boolean) checkAnchorSpawn.invoke(event);
} catch (Exception e) {
Logging.warning("Error checking for: %s", checkAnchorSpawn);
e.printStackTrace();
}
return false;
}
}
@@ -1,285 +0,0 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.utils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* Utility class to manipulate locations.
*
* @deprecated Use instead: {@link com.onarandombox.MultiverseCore.api.LocationManipulation} and {@link SimpleLocationManipulation}.
*/
@Deprecated
public class LocationManipulation {
private LocationManipulation() { }
private static Map<String, Integer> orientationInts = new HashMap<String, Integer>();
static {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
orientationInts.put("n", 180);
orientationInts.put("ne", 225);
orientationInts.put("e", 270);
orientationInts.put("se", 315);
orientationInts.put("s", 0);
orientationInts.put("sw", 45);
orientationInts.put("w", 90);
orientationInts.put("nw", 135);
// "freeze" the map:
orientationInts = Collections.unmodifiableMap(orientationInts);
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
}
/**
* Convert a Location into a Colon separated string to allow us to store it in text.
* <p>
* WORLD:X,Y,Z:yaw:pitch
* <p>
* The corresponding String2Loc function is {@link #stringToLocation}
*
* @param location The Location to save.
* @return The location as a string in this format: WORLD:x,y,z:yaw:pitch
*/
public static String locationToString(Location location) {
if (location == null) {
return "";
}
// We set the locale to ENGLISH here so we always save with the format:
// world:1.2,5.4,3.6:1.8:21.3
// Otherwise we blow up when parsing!
return String.format(Locale.ENGLISH, "%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(),
location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
/**
* This method simply does some rounding, rather than forcing a call to the server to get the blockdata.
*
* @param l The location to round to the block location
* @return A rounded location.
*/
public static Location getBlockLocation(Location l) {
l.setX(l.getBlockX());
l.setY(l.getBlockY());
l.setZ(l.getBlockZ());
return l;
}
/**
* Returns a new location from a given string. The format is as follows:
* <p>
* WORLD:X,Y,Z:yaw:pitch
* <p>
* The corresponding Location2String function is {@link #stringToLocation}
*
* @param locationString The location represented as a string (WORLD:X,Y,Z:yaw:pitch)
* @return A new location defined by the string or null if the string was invalid.
*/
public static Location stringToLocation(String locationString) {
//format:
//world:x,y,z:pitch:yaw
if (locationString == null) {
return null;
}
// Split the whole string, format is:
// {'world', 'x,y,z'[, 'pitch', 'yaw']}
String[] split = locationString.split(":");
if (split.length < 2 || split.length > 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
return null;
}
// Split the xyz string, format is:
// {'x', 'y', 'z'}
String[] xyzsplit = split[1].split(",");
if (xyzsplit.length != 3) {
return null;
}
// Verify the world is valid
World w = Bukkit.getWorld(split[0]);
if (w == null) {
return null;
}
try {
float pitch = 0;
float yaw = 0;
if (split.length >= 3) {
yaw = (float) Double.parseDouble(split[2]);
}
if (split.length == 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
pitch = (float) Double.parseDouble(split[3]);
}
return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch);
} catch (NumberFormatException e) {
return null;
}
}
/**
* Returns a colored string with the coords.
*
* @param l The {@link Location}
* @return The {@link String}
*/
public static String strCoords(Location l) {
String result = "";
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(0);
df.setMaximumFractionDigits(2);
result += ChatColor.WHITE + "X: " + ChatColor.AQUA + df.format(l.getX()) + " ";
result += ChatColor.WHITE + "Y: " + ChatColor.AQUA + df.format(l.getY()) + " ";
result += ChatColor.WHITE + "Z: " + ChatColor.AQUA + df.format(l.getZ()) + " ";
result += ChatColor.WHITE + "P: " + ChatColor.GOLD + df.format(l.getPitch()) + " ";
result += ChatColor.WHITE + "Y: " + ChatColor.GOLD + df.format(l.getYaw()) + " ";
return result;
}
/**
* Converts a location to a printable readable formatted string including pitch/yaw.
*
* @param l The {@link Location}
* @return The {@link String}
*/
public static String strCoordsRaw(Location l) {
if (l == null) {
return "null";
}
String result = "";
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(0);
df.setMaximumFractionDigits(2);
result += "X: " + df.format(l.getX()) + " ";
result += "Y: " + df.format(l.getY()) + " ";
result += "Z: " + df.format(l.getZ()) + " ";
result += "P: " + df.format(l.getPitch()) + " ";
result += "Y: " + df.format(l.getYaw()) + " ";
return result;
}
/**
* Return the NESW Direction a Location is facing.
*
* @param location The {@link Location}
* @return The NESW Direction
*/
public static String getDirection(Location location) {
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
double r = (location.getYaw() % 360) + 180;
// Remember, these numbers are every 45 degrees with a 22.5 offset, to detect boundaries.
String dir;
if (r < 22.5)
dir = "n";
else if (r < 67.5)
dir = "ne";
else if (r < 112.5)
dir = "e";
else if (r < 157.5)
dir = "se";
else if (r < 202.5)
dir = "s";
else if (r < 247.5)
dir = "sw";
else if (r < 292.5)
dir = "w";
else if (r < 337.5)
dir = "nw";
else
dir = "n";
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
return dir;
}
/**
* Returns the float yaw position for the given cardinal direction.
*
* @param orientation The cardinal direction
* @return The yaw
*/
public static float getYaw(String orientation) {
if (orientation == null) {
return 0;
}
if (orientationInts.containsKey(orientation.toLowerCase())) {
return orientationInts.get(orientation.toLowerCase());
}
return 0;
}
/**
* Returns a speed float from a given vector.
*
* @param v The {@link Vector}
* @return The speed
*/
public static float getSpeed(Vector v) {
return (float) Math.sqrt(v.getX() * v.getX() + v.getZ() * v.getZ());
}
// X, Y, Z
// -W/+E,0, -N/+S
/**
* Returns a translated vector from the given direction.
*
* @param v The old {@link Vector}
* @param direction The new direction
* @return The translated {@link Vector}
*/
public static Vector getTranslatedVector(Vector v, String direction) {
if (direction == null) {
return v;
}
float speed = getSpeed(v);
float halfSpeed = (float) (speed / 2.0);
if (direction.equalsIgnoreCase("n")) {
return new Vector(0, 0, -1 * speed);
} else if (direction.equalsIgnoreCase("ne")) {
return new Vector(halfSpeed, 0, -1 * halfSpeed);
} else if (direction.equalsIgnoreCase("e")) {
return new Vector(speed, 0, 0);
} else if (direction.equalsIgnoreCase("se")) {
return new Vector(halfSpeed, 0, halfSpeed);
} else if (direction.equalsIgnoreCase("s")) {
return new Vector(0, 0, speed);
} else if (direction.equalsIgnoreCase("sw")) {
return new Vector(-1 * halfSpeed, 0, halfSpeed);
} else if (direction.equalsIgnoreCase("w")) {
return new Vector(-1 * speed, 0, 0);
} else if (direction.equalsIgnoreCase("nw")) {
return new Vector(-1 * halfSpeed, 0, -1 * halfSpeed);
}
return v;
}
/**
* Returns the next Location that a {@link Vehicle} is traveling at.
*
* @param v The {@link Vehicle}
* @return The {@link Location}
*/
public static Location getNextBlock(Vehicle v) {
Vector vector = v.getVelocity();
Location location = v.getLocation();
int x = vector.getX() < 0 ? vector.getX() == 0 ? 0 : -1 : 1;
int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1;
return location.add(x, 0, z);
}
}
Loaded 100 of 120 files, more files were not shown because too many files have changed in this diff. Show more