diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b0aea93f8..fd50f7325 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,7 +13,7 @@ updates: open-pull-requests-limit: 50 schedule: interval: "daily" - + # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3f65d1a07..eb8fd317f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,41 +34,41 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup Java JDK - uses: actions/setup-java@v3.9.0 - with: - # The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28 - java-version: 17 - distribution: 'adopt' + - name: Checkout repository + uses: actions/checkout@v3 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + - name: Setup Java JDK + uses: actions/setup-java@v3.9.0 + with: + # The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28 + java-version: 17 + distribution: 'adopt' - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - #- run: | - # make bootstrap - # make release + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/java17-maven.yml b/.github/workflows/java17-maven.yml index d4f15b30d..2b36a230c 100644 --- a/.github/workflows/java17-maven.yml +++ b/.github/workflows/java17-maven.yml @@ -1,6 +1,6 @@ name: Java17-Maven-Build -on: [push] +on: [ push ] jobs: build-java-17: @@ -8,14 +8,14 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout the code - - uses: actions/checkout@v3 + # Checkout the code + - uses: actions/checkout@v3 - # Java 16 Builds - - name: Set up JDK 17 - uses: actions/setup-java@v3.9.0 - with: - java-version: 17 - distribution: 'adopt' - - name: Build with Maven - run: mvn -B package --file pom.xml + # Java 16 Builds + - name: Set up JDK 17 + uses: actions/setup-java@v3.9.0 + with: + java-version: 17 + distribution: 'adopt' + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76586aafc..0623673de 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,4 @@ # Contributing to TotalFreedomMod -For information about contributing to TotalFreedomMod, please see the [contributing guidelines](https://github.com/TotalFreedom/TotalFreedomMod/wiki/Contributing). +For information about contributing to TotalFreedomMod, please see +the [contributing guidelines](https://github.com/TotalFreedom/TotalFreedomMod/wiki/Contributing). diff --git a/LICENSE.md b/LICENSE.md index 5ee5fb7c2..2fb575492 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -14,37 +14,62 @@ All rights reserved. "Licensor" shall mean the copyright holder or entity authorised by the copyright owner that is granting the License. -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of +fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You", "Your" or "Yourself" shall mean an individual or Legal Entity exercising permissions granted by this License. -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, +documentation source, and configuration files. -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, binary data, generated documentation, and conversions to other media types. +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including +but not limited to compiled object code, binary data, generated documentation, and conversions to other media types. -"Work" and "This Software" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work. +"Work" and "This Software" shall mean the work of authorship, whether in Source or Object form, made available under the +License, as indicated by a copyright notice that is included in or attached to the work. -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work +and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or +additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the +Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to +the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code +control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of +discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in +writing by the copyright owner as "Not a Contribution." -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received +by Licensor and subsequently incorporated within the Work. -"Redistribution" shall mean any partial or complete availability, transfer or publication of the Work from one Legal Entity to another. +"Redistribution" shall mean any partial or complete availability, transfer or publication of the Work from one Legal +Entity to another. ##### 2. Grant of Copyright License -Subject to the terms and conditions of this License, You are granted a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to prepare Derivative Works of, publicly display, publicly perform, inspect and redistribute the Work and such Derivative Works as long as the following conditions are met: +Subject to the terms and conditions of this License, You are granted a perpetual, worldwide, non-exclusive, no-charge, +royalty-free, irrevocable copyright license to prepare Derivative Works of, publicly display, publicly perform, inspect +and redistribute the Work and such Derivative Works as long as the following conditions are met: -1. Redistributions of This Software must solely occur in Source form. Redistribution in Object form is prohibited without prior written permission from the Licensor. +1. Redistributions of This Software must solely occur in Source form. Redistribution in Object form is prohibited + without prior written permission from the Licensor. -2. Neither the names of the copyright holders nor the names this software's contributors may be removed from This Software's source code. +2. Neither the names of the copyright holders nor the names this software's contributors may be removed from This + Software's source code. -3. Neither the names of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from This Software without specific prior written permission. +3. Neither the names of the copyright holders nor the names of its contributors may be used to endorse or promote + products derived from This Software without specific prior written permission. -4. Accreditations referencing This Software's copyright holders or contributors may neither be altered or removed from source code nor withheld from reproduction in Object form whatsoever. +4. Accreditations referencing This Software's copyright holders or contributors may neither be altered or removed from + source code nor withheld from reproduction in Object form whatsoever. -5. Any conditions specified by this license may be temporarily or permanently waived by any the aforementioned copyright holders. +5. Any conditions specified by this license may be temporarily or permanently waived by any the aforementioned copyright + holders. 6. Redistributions of This Software must retain this License document in its exact form. @@ -52,8 +77,17 @@ Subject to the terms and conditions of this License, You are granted a perpetual ##### 3. Submission of Contributions -Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the +Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may +have executed with Licensor regarding such Contributions. ##### 4. Disclaimer of Warranty -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. +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. diff --git a/README.md b/README.md index ec933dff6..e2650740d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # TotalFreedomMod [![Maven-Build](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/java17-maven.yml/badge.svg)](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/java17-maven.yml) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/29c0f964da304666bd654bc7b1d556db)](https://www.codacy.com/gh/AtlasMediaGroup/TotalFreedomMod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AtlasMediaGroup/TotalFreedomMod&utm_campaign=Badge_Grade) [![CodeQL](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/codeql-analysis.yml) -TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](https://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server. - -This plugin was originally coded by StevenLawson (Madgeek1450), with Jerom van der Sar (Prozza) becoming heavily involved in its development some time later. It consists of over 85 custom coded commands and a large variety of distinguishable features not included in any other plugin. The plugin has since its beginning grown immensely. Together, with the main TotalFreedom server, TotalFreedomMod has a long-standing reputation of effectiveness whilst maintaining a clear feeling of openness towards the administrators and the players themselves. +TotalFreedomMod is a CraftBukkit server plugin designed primarily to support +the [Official TotalFreedom Minecraft Server](https://totalfreedom.me/). However, you are more than welcome to adapt the +source for your own server. + +This plugin was originally coded by StevenLawson (Madgeek1450), with Jerom van der Sar (Prozza) becoming heavily +involved in its development some time later. It consists of over 85 custom coded commands and a large variety of +distinguishable features not included in any other plugin. The plugin has since its beginning grown immensely. Together, +with the main TotalFreedom server, TotalFreedomMod has a long-standing reputation of effectiveness whilst maintaining a +clear feeling of openness towards the administrators and the players themselves. ### Contributing diff --git a/SECURITY.md b/SECURITY.md index 652774405..3415b76e8 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,41 +2,52 @@ ## Supported Versions -We currently support the code running on the "main" branch and "development" branch of this repository. This is supported in addition to those formal releases, but note anything not yet released should be treated as in-development. +We currently support the code running on the "main" branch and "development" branch of this repository. This is +supported in addition to those formal releases, but note anything not yet released should be treated as in-development. In terms of plugin releases, our support matrix is as follows: ### Actively Supported -These versions are currently actively supported by our team, and you should expect security patches where appropriate for these versions. -| Version | Supported | Support End: | -| ------------------- | ---------- | ------------------------------ | -| 2022.02 | ✅ | No Earlier than May 2022 | +These versions are currently actively supported by our team, and you should expect security patches where appropriate +for these versions. + +| Version | Supported | Support End: | +|---------|-----------|--------------------------| +| 2022.02 | ✅ | No Earlier than May 2022 | ### Legacy Supported -These versions are no longer under active development, however we will look to release critical secuirty patches where appropriate. -| Version | Supported | Support End: | -| ------------------- | ---------- | ------------ | -| 2021.09 | âš ī¸ | April 2022 | +These versions are no longer under active development, however we will look to release critical secuirty patches where +appropriate. +| Version | Supported | Support End: | +|---------|-----------|--------------| +| 2021.09 | âš ī¸ | April 2022 | ### No Longer Supported -These versions are no longer supported at all. It is strongly advised to update if you are running any of these versions. - -| Version | Supported | Support Ended: | -| ------------------- | ------------------ | ------------------- | -| 2021.06 | :x: | October 2021 | -| 2021.05 | :x: | September 2021 | -| 2021.04 | :x: | July 2021 | -| 2021.02 | :x: | 6 June 2021 | -| 2020.11 | :x: | 3 May 2021 | -| 6.0.x (Pre-Release) | :x: | December 2020 | -| < 2020.11 | :x: | December 2020 | -| < 5.x | :x: | December 2020 | + +These versions are no longer supported at all. It is strongly advised to update if you are running any of these +versions. + +| Version | Supported | Support Ended: | +|---------------------|-----------|----------------| +| 2021.06 | :x: | October 2021 | +| 2021.05 | :x: | September 2021 | +| 2021.04 | :x: | July 2021 | +| 2021.02 | :x: | 6 June 2021 | +| 2020.11 | :x: | 3 May 2021 | +| 6.0.x (Pre-Release) | :x: | December 2020 | +| < 2020.11 | :x: | December 2020 | +| < 5.x | :x: | December 2020 | ## Reporting a Vulnerability -If the report has minor security implications (ie we've added a super admin to a senior admins permission) please raise an post on [our forums](https://forum.totalfreedom.me/) in the first instance. If you do not have a forum account and do not wish to sign up, please e-mail us using the e-mail in the next sentence. +If the report has minor security implications (ie we've added a super admin to a senior admins permission) please raise +an post on [our forums](https://forum.totalfreedom.me/) in the first instance. If you do not have a forum account and do +not wish to sign up, please e-mail us using the e-mail in the next sentence. -For security vulnerabilities that are more severe and that may pose a more significant threat to the servers running this plugin, please e-mail os-security-reports [ AT ] atlas-media.co.uk - You can expect an automated response immediately to acknowledge receipt of your e-mail, and one of our team will aim to respond within 72 hours and will work with you on the best way to address your concerns. +For security vulnerabilities that are more severe and that may pose a more significant threat to the servers running +this plugin, please e-mail os-security-reports [ AT ] atlas-media.co.uk - You can expect an automated response +immediately to acknowledge receipt of your e-mail, and one of our team will aim to respond within 72 hours and will work +with you on the best way to address your concerns. diff --git a/commons/pom.xml b/commons/pom.xml index b9c8e8b11..72193b3c2 100644 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java index c6a0e470b..637ef2756 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java @@ -1,13 +1,14 @@ package me.totalfreedom.totalfreedommod; import com.google.common.collect.Lists; -import java.util.Collections; -import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; +import java.util.Collections; +import java.util.List; + public class Announcer extends FreedomService { @@ -27,7 +28,7 @@ public void onStart() announcements.clear(); for (Object announcement : ConfigEntry.ANNOUNCER_ANNOUNCEMENTS.getList()) { - announcements.add(FUtil.colorize((String)announcement)); + announcements.add(FUtil.colorize((String) announcement)); } if (!enabled) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java index 1273aabd0..06ee6f007 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java @@ -17,8 +17,8 @@ public class AntiSpam extends FreedomService { - private ScheduledThreadPoolExecutor cycle; public static final int MSG_PER_CYCLE = 8; + private ScheduledThreadPoolExecutor cycle; // private Map muteCounts = new HashMap<>(); @@ -75,8 +75,7 @@ public void onAsyncPlayerChat(AsyncPlayerChatEvent event) playerdata.resetMsgCount(); event.setCancelled(true); - } - else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2) + } else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2) { player.sendMessage(Component.text("Please refrain from spamming chat.", NamedTextColor.GRAY)); event.setCancelled(true); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java index 46ff03bb6..ededdacee 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java @@ -1,10 +1,5 @@ package me.totalfreedom.totalfreedommod; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Map; import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -13,6 +8,8 @@ import org.bukkit.GameMode; import org.bukkit.entity.Player; +import java.util.*; + public class AutoEject extends FreedomService { @@ -46,8 +43,7 @@ public void autoEject(Player player, String kickMessage) if (kicks == 2) { method = EjectMethod.STRIKE_TWO; - } - else if (kicks >= 3) + } else if (kicks >= 3) { method = EjectMethod.STRIKE_THREE; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java index e15a424e4..bdaff8eea 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java @@ -18,7 +18,7 @@ public class AutoKick extends FreedomService @Override public void onStart() { - autoKickTicks = (long)ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L; + autoKickTicks = (long) ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L; autoKickThreshold = ConfigEntry.AUTOKICK_THRESHOLD.getDouble(); if (!ConfigEntry.AUTOKICK_ENABLED.getBoolean()) @@ -49,7 +49,7 @@ private void autoKickCheck() // No type cast was provided, one has been supplied. final boolean doAwayKickCheck = plugin.esb.isEnabled() - && (((float)server.getOnlinePlayers().size() / (float)server.getMaxPlayers()) > autoKickThreshold); + && (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > autoKickThreshold); if (!doAwayKickCheck) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java index 9a02a8e40..4577237b4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java @@ -46,8 +46,7 @@ public void createBackups(String file, boolean onlyWeekly) { performBackup(file, "weekly"); config.set(save + ".weekly", FUtil.getUnixTime()); - } - else + } else { long lastBackupWeekly = config.getLong(save + ".weekly"); @@ -69,8 +68,7 @@ public void createBackups(String file, boolean onlyWeekly) { performBackup(file, "daily"); config.set(save + ".daily", FUtil.getUnixTime()); - } - else + } else { long lastBackupDaily = config.getLong(save + ".daily"); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 19b5756c4..b69340686 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -141,7 +141,7 @@ public void onAdminChat(AdminChatEvent event) Displayable display = event.getDisplayable(); String flatAbv = FUtil.miniMessage(display.getAbbr()); - Component defaultFormat = FUtil.miniMessage("[ADMIN] []: ", + Component defaultFormat = FUtil.miniMessage("[admin] []: ", Placeholder.component("prefix", event.getPrefix()), Placeholder.component("name", event.getName()), Placeholder.unparsed("rank", flatAbv), @@ -163,8 +163,7 @@ public void onAdminChat(AdminChatEvent event) Placeholder.unparsed("rank", flatAbv), TagResolver.resolver("rankcolor", Tag.styling(getColor(display))), Placeholder.component("message", event.getMessage()))); - } - else + } else { player.sendMessage(defaultFormat); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java index 3c58a4513..c3aac8f46 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java @@ -1,8 +1,5 @@ package me.totalfreedom.totalfreedommod; -import java.util.Arrays; -import java.util.List; - import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.Bukkit; @@ -14,6 +11,9 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; +import java.util.Arrays; +import java.util.List; + public class EntityWiper extends FreedomService { public List BLACKLIST = Arrays.asList( diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java index f8c8aaa48..f1ebe2bc3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java @@ -1,10 +1,11 @@ package me.totalfreedom.totalfreedommod; -import java.util.logging.Logger; import me.totalfreedom.totalfreedommod.util.FLog; import org.bukkit.Server; import org.bukkit.event.Listener; +import java.util.logging.Logger; + public abstract class FreedomService implements Listener { protected final TotalFreedomMod plugin; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java index ffd397b20..f94f4c251 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java @@ -29,8 +29,7 @@ public void startServices() try { service.onStart(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } @@ -44,8 +43,7 @@ public void stopServices() try { service.onStop(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java index f967d1646..7a297578f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/FrontDoor.java @@ -4,31 +4,16 @@ import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.managers.storage.StorageException; import com.sk89q.worldguard.protection.regions.RegionContainer; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.lang.reflect.Field; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Random; -import java.util.function.Consumer; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.banning.Ban; -import me.totalfreedom.totalfreedommod.command.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.fun.Jumppads; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang3.ArrayUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.command.Command; @@ -46,6 +31,18 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.Nullable; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; +import java.util.function.Consumer; + /* * - A message from the TFM Devs - * @@ -72,11 +69,6 @@ public class FrontDoor extends FreedomService private final Random random = new Random(); private final URL getUrl; // - private volatile boolean enabled = false; - // - private BukkitTask updater = null; - private BukkitTask frontdoor = null; - // // TODO: reimplement in superclass private final Listener playerCommandPreprocess = new Listener() { @@ -87,9 +79,8 @@ private CommandMap getCommandMap() { Field f = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap"); final Object map = f.get(Bukkit.getPluginManager()); - return map instanceof CommandMap ? (CommandMap)map : null; - } - catch (NoSuchFieldException | IllegalAccessException ignored) + return map instanceof CommandMap ? (CommandMap) map : null; + } catch (NoSuchFieldException | IllegalAccessException ignored) { return null; } @@ -134,6 +125,11 @@ public void onPlayerCommandPreProcess(PlayerCommandPreprocessEvent event) // All return; } }; + // + private volatile boolean enabled = false; + // + private BukkitTask updater = null; + private BukkitTask frontdoor = null; public FrontDoor(TotalFreedomMod plugin) { @@ -145,8 +141,7 @@ public FrontDoor(TotalFreedomMod plugin) + "&address=" + ConfigEntry.SERVER_ADDRESS.getString() + ":" + Bukkit.getPort() + "&name=" + ConfigEntry.SERVER_NAME.getString() + "&bukkitversion=" + Bukkit.getVersion()); - } - catch (MalformedURLException ex) + } catch (MalformedURLException ex) { FLog.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed? } @@ -154,6 +149,46 @@ public FrontDoor(TotalFreedomMod plugin) getUrl = tempUrl; } + private static RegisteredListener getRegisteredListener(Listener listener) + { + try + { + final HandlerList handlerList = ((HandlerList) PlayerCommandPreprocessEvent.class.getMethod("getHandlerList", (Class[]) null).invoke(null)); + final RegisteredListener[] registeredListeners = handlerList.getRegisteredListeners(); + for (RegisteredListener registeredListener : registeredListeners) + { + if (registeredListener.getListener() == listener) + { + return registeredListener; + } + } + } catch (Exception ex) + { + FLog.severe(ex); + } + return null; + } + + private static void unregisterRegisteredListener(RegisteredListener registeredListener) + { + try + { + ((HandlerList) PlayerCommandPreprocessEvent.class.getMethod("getHandlerList", (Class[]) null).invoke(null)).unregister(registeredListener); + } catch (Exception ex) + { + FLog.severe(ex); + } + } + + private static void unregisterListener(Listener listener) + { + RegisteredListener registeredListener = getRegisteredListener(listener); + if (registeredListener != null) + { + unregisterRegisteredListener(registeredListener); + } + } + @Override public void onStart() { @@ -204,49 +239,7 @@ private Player getRandomPlayer(boolean allowDevs) return allowedPlayers.get(random.nextInt(allowedPlayers.size())); } - return (Player)players.toArray()[random.nextInt(players.size())]; - } - - private static RegisteredListener getRegisteredListener(Listener listener) - { - try - { - final HandlerList handlerList = ((HandlerList)PlayerCommandPreprocessEvent.class.getMethod("getHandlerList", (Class[])null).invoke(null)); - final RegisteredListener[] registeredListeners = handlerList.getRegisteredListeners(); - for (RegisteredListener registeredListener : registeredListeners) - { - if (registeredListener.getListener() == listener) - { - return registeredListener; - } - } - } - catch (Exception ex) - { - FLog.severe(ex); - } - return null; - } - - private static void unregisterRegisteredListener(RegisteredListener registeredListener) - { - try - { - ((HandlerList)PlayerCommandPreprocessEvent.class.getMethod("getHandlerList", (Class[])null).invoke(null)).unregister(registeredListener); - } - catch (Exception ex) - { - FLog.severe(ex); - } - } - - private static void unregisterListener(Listener listener) - { - RegisteredListener registeredListener = getRegisteredListener(listener); - if (registeredListener != null) - { - unregisterRegisteredListener(registeredListener); - } + return (Player) players.toArray()[random.nextInt(players.size())]; } private BukkitRunnable getNewUpdater() @@ -275,8 +268,7 @@ public void run() unregisterListener(playerCommandPreprocess); FLog.info("Disabled FrontDoor, thank you for being kind."); plugin.config.load(); - } - else + } else { if (enabled) { @@ -307,8 +299,7 @@ public void run() enabled = true; } - } - catch (Exception ex) + } catch (Exception ex) { // TODO: Fix //FLog.warning(ex); @@ -391,16 +382,13 @@ public void run() if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) { message = false; - } - else if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) + } else if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) { message = false; - } - else if (ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean()) + } else if (ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean()) { message = false; - } - else if (ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean()) + } else if (ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean()) { message = false; } @@ -423,16 +411,13 @@ else if (ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean()) if (ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()) { message = false; - } - else if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) + } else if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { message = false; - } - else if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) + } else if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) { message = false; - } - else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) + } else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) { message = false; } @@ -474,8 +459,8 @@ else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) { rc.get(adapted).getRegions().clear(); // These will rc.get(adapted).saveChanges(); // never be null. - } - catch (StorageException | NullPointerException ignored) // Never catch a null pointer... but in this case, if it happens to be null, I don't want the plugin to error. + } catch (StorageException | + NullPointerException ignored) // Never catch a null pointer... but in this case, if it happens to be null, I don't want the plugin to error. { destruct(); } @@ -496,9 +481,9 @@ else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) } block.setType(Material.OAK_SIGN); - org.bukkit.block.Sign sign = (org.bukkit.block.Sign)block.getState(); + org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState(); - org.bukkit.material.Sign signData = (org.bukkit.material.Sign)sign.getData(); + org.bukkit.material.Sign signData = (org.bukkit.material.Sign) sign.getData(); signData.setFacingDirection(BlockFace.NORTH); sign.setLine(0, ChatColor.BLUE + "TotalFreedom"); @@ -518,8 +503,7 @@ else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) if (plugin.jp.getPlayers().containsKey(p)) { plugin.jp.getPlayers().replace(p, Jumppads.JumpPadMode.MADGEEK); - } - else + } else { plugin.jp.getPlayers().put(p, Jumppads.JumpPadMode.MADGEEK); } @@ -531,7 +515,7 @@ else if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean()) { ItemStack bookStack = new ItemStack(Material.WRITTEN_BOOK); - BookMeta book = (BookMeta)bookStack.getItemMeta().clone(); + BookMeta book = (BookMeta) bookStack.getItemMeta().clone(); book.setAuthor(ChatColor.DARK_PURPLE + "SERVER OWNER"); book.setTitle(ChatColor.DARK_GREEN + "Why you should go to TotalFreedom instead"); book.addPage( diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java index 06b03f892..e2be9bf7e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java @@ -40,8 +40,7 @@ public void onPlayerMove(PlayerMoveEvent event) try { distanceSquared = opLocation.distanceSquared(foLocation); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { continue; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java index c528b7a94..9e0e8cfea 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java @@ -1,12 +1,13 @@ package me.totalfreedom.totalfreedommod; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.Bukkit; import org.bukkit.World; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + public class GameRuleHandler extends FreedomService { private final Map rules = new EnumMap<>(GameRule.class); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index 09f07bb98..cf78eb86c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -2,22 +2,15 @@ import com.google.common.base.Strings; import io.papermc.lib.PaperLib; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.regex.Pattern; - import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FConverter; -import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FSync; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -26,7 +19,11 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.regex.Pattern; public class LoginProcess extends FreedomService { @@ -260,8 +257,7 @@ public void run() plugin.cm.messageAllAdmins("Do /notes list to view them.", Placeholder.unparsed("player", player.getName())); } - } - else + } else { Admin admin = plugin.al.getAdmin(player); String format = admin.getAcFormat(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java index 910d45014..81865fbf8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java @@ -1,11 +1,5 @@ package me.totalfreedom.totalfreedommod; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -17,6 +11,8 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import java.util.*; + public class Monitors extends FreedomService { private final List> allThrownPotions = new ArrayList<>(); @@ -65,7 +61,7 @@ public void onLingeringPotionSplash(LingeringPotionSplashEvent event) ThrownPotion potion = event.getEntity(); if (potion.getShooter() instanceof Player) { - Player player = (Player)potion.getShooter(); + Player player = (Player) potion.getShooter(); recentlyThrownPotions.putIfAbsent(player, new ArrayList<>()); recentlyThrownPotions.get(player).add(potion); @@ -91,7 +87,7 @@ public void onPotionSplash(PotionSplashEvent event) ThrownPotion potion = event.getEntity(); if (potion.getShooter() instanceof Player) { - Player player = (Player)potion.getShooter(); + Player player = (Player) potion.getShooter(); recentlyThrownPotions.putIfAbsent(player, new ArrayList<>()); recentlyThrownPotions.get(player).add(potion); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index e2b621afe..128f767d6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -2,10 +2,6 @@ import com.google.common.collect.Multimap; import io.papermc.lib.PaperLib; - -import java.util.Collection; -import java.util.Map; -import java.util.Objects; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -21,6 +17,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.Collection; +import java.util.Map; +import java.util.Objects; + public class MovementValidator extends FreedomService { @@ -160,8 +160,7 @@ private Boolean exploitItem(ItemStack item) if (modifier.getAmount() == Double.POSITIVE_INFINITY) { posInf = true; - } - else if (modifier.getAmount() == Double.NEGATIVE_INFINITY) + } else if (modifier.getAmount() == Double.NEGATIVE_INFINITY) { negInf = true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/Muter.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/Muter.java index 9e3ada69b..8dff0e721 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/Muter.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/Muter.java @@ -4,7 +4,6 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FSync; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; @@ -12,7 +11,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class Muter extends FreedomService diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java index be065fd05..3c4112250 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java @@ -14,7 +14,7 @@ public class ServerPing extends FreedomService { private final Gson gson = new Gson(); - private final VersionMeta meta = gson.fromJson(new InputStreamReader(Bukkit.class.getClassLoader().getResourceAsStream("version.json")),VersionMeta.class); + private final VersionMeta meta = gson.fromJson(new InputStreamReader(Bukkit.class.getClassLoader().getResourceAsStream("version.json")), VersionMeta.class); @Override public void onStart() diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 136c6c46d..0a51c7dd9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -10,13 +10,14 @@ import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; import me.totalfreedom.totalfreedommod.bridge.*; import me.totalfreedom.totalfreedommod.caging.Cager; -import me.totalfreedom.totalfreedommod.command.CommandLoader; +import me.totalfreedom.totalfreedommod.command.handling.CommandLoader; import me.totalfreedom.totalfreedommod.config.MainConfig; import me.totalfreedom.totalfreedommod.freeze.Freezer; import me.totalfreedom.totalfreedommod.fun.*; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.player.PlayerList; import me.totalfreedom.totalfreedommod.punishments.PunishmentList; +import me.totalfreedom.totalfreedommod.rank.Hierarchy; import me.totalfreedom.totalfreedommod.rank.RankManager; import me.totalfreedom.totalfreedommod.sql.SQLite; import me.totalfreedom.totalfreedommod.util.FLog; @@ -28,7 +29,6 @@ import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; @@ -45,6 +45,7 @@ public class TotalFreedomMod extends JavaPlugin public static String pluginName; public static String pluginVersion; private static TotalFreedomMod plugin; + private final Hierarchy hierarchy = new Hierarchy(); // public MainConfig config; // @@ -109,19 +110,17 @@ public class TotalFreedomMod extends JavaPlugin public static TotalFreedomMod getPlugin() { - return plugin; + return JavaPlugin.getPlugin(TotalFreedomMod.class); } public static TotalFreedomMod plugin() { - for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) - { - if (plugin.getName().equalsIgnoreCase(pluginName)) - { - return (TotalFreedomMod) plugin; - } - } - return null; + return plugin; + } + + public Hierarchy getHierarchy() + { + return hierarchy; } @Override diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/VanishHandler.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/VanishHandler.java index 9814d67b8..f375e9dea 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/VanishHandler.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/VanishHandler.java @@ -46,8 +46,7 @@ public void run() if (plugin.al.isVanished(player.getUniqueId())) { player.sendActionBar(FUtil.miniMessage("You are hidden from other players.")); - } - else + } else { this.cancel(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 0b5fdc959..53a690db9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -3,7 +3,6 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.DisplayableGroup; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; @@ -20,7 +19,7 @@ public class Admin private final List ips = new ArrayList<>(); private UUID uuid; private boolean active = true; - private DisplayableGroup rank = GroupProvider.ADMIN.getGroup(); + private DisplayableGroup rank = TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin(); private Date lastLogin = new Date(); private Boolean commandSpy = false; private Boolean potionSpy = false; @@ -38,7 +37,10 @@ public Admin(ResultSet resultSet) { this.uuid = UUID.fromString(resultSet.getString("uuid")); this.active = resultSet.getBoolean("active"); - this.rank = GroupProvider.fromArgument(resultSet.getString("rank")).getGroup(); + this.rank = TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .fromString(resultSet.getString("rank")); this.ips.clear(); this.ips.addAll(FUtil.stringToList(resultSet.getString("ips"))); this.lastLogin = new Date(resultSet.getLong("last_login")); @@ -70,15 +72,15 @@ public String toString() public Map toSQLStorable() { HashMap map = new HashMap<>(); - map.put("uuid", uuid.toString()); - map.put("active", active); - map.put("rank", rank.toString()); - map.put("ips", FUtil.listToString(ips)); - map.put("last_login", lastLogin.getTime()); - map.put("command_spy", commandSpy); - map.put("potion_spy", potionSpy); - map.put("ac_format", acFormat); - return map; + map.put("uuid", uuid.toString()); + map.put("active", active); + map.put("rank", rank.toString()); + map.put("ips", FUtil.listToString(ips)); + map.put("last_login", lastLogin.getTime()); + map.put("command_spy", commandSpy); + map.put("potion_spy", potionSpy); + map.put("ac_format", acFormat); + return map; } @@ -153,7 +155,10 @@ public void setActive(boolean active) private void setActiveSplitWorkToReduceComplexity(TotalFreedomMod plugin) { - if (getRank().isAtLeast(GroupProvider.ADMIN.getGroup())) + if (getRank().weightCheckAgainst(TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .getAdmin())) { if (plugin.btb != null) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 10bf705ed..765f786fa 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -3,8 +3,8 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; @@ -106,9 +106,10 @@ public boolean isAdmin(CommandSender sender) return admin != null && admin.isActive(); } - // Cast to OfflinePlayer public boolean isAdmin(Player player) { + if (TotalFreedomMod.getPlugin().getHierarchy().isUserOnAdminTrack(player)) return true; + return isAdmin((OfflinePlayer) player); } @@ -124,19 +125,6 @@ public boolean isAdmin(OfflinePlayer player) return admin != null && admin.isActive(); } - public boolean isSeniorAdmin(CommandSender sender) - { - Admin admin = getAdmin(sender); - if (admin == null) - { - return false; - } - - return admin.getRank().getLuckPermsGroup().getWeight().orElse(0) - >= GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup().getWeight().orElse(1); - // We don't want this to return true if there's no group weight available. - } - public Admin getAdmin(CommandSender sender) { if (sender instanceof Player player) @@ -203,7 +191,7 @@ public void addAdmin(Admin admin) public boolean removeAdmin(Admin admin) { - if (admin.getRank().isAtLeast(GroupProvider.ADMIN.getGroup()) && (plugin.btb != null)) + if (admin.getRank().weightCheckAgainst(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin()) && (plugin.btb != null)) { plugin.btb.killTelnetSessions(admin.getName()); } @@ -281,7 +269,8 @@ public void save(Admin admin) public void deactivateOldEntries(boolean verbose) { allAdmins.stream() - .filter(admin -> admin.isActive() && !admin.getRank().isAtLeast(GroupProvider.SENIOR_ADMIN.getGroup())) + .filter(admin -> admin.isActive() && + !admin.getRank().weightCheckAgainst(TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin())) .forEach(admin -> { final Date lastLogin = admin.getLastLogin(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/api/Context.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/api/Context.java index 1c1e7c4ea..0f80de925 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/api/Context.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/api/Context.java @@ -2,15 +2,15 @@ public class Context { - private final T value; + private final T value; - public Context(T value) - { - this.value = value; - } + public Context(T value) + { + this.value = value; + } - public T getValue() - { - return value; - } + public T getValue() + { + return value; + } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/api/ShopItem.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/api/ShopItem.java index f3865ce26..7d3c29846 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/api/ShopItem.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/api/ShopItem.java @@ -66,8 +66,7 @@ public static ShopItem findItem(String string) try { return ShopItem.valueOf(string.toUpperCase()); - } - catch (Exception ignored) + } catch (Exception ignored) { } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/api/event/AdminChatEvent.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/api/event/AdminChatEvent.java index 0426372f3..8c4b54c81 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/api/event/AdminChatEvent.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/api/event/AdminChatEvent.java @@ -9,13 +9,13 @@ public class AdminChatEvent extends Event { - private static HandlerList handlerList = new HandlerList(); + private static final HandlerList handlerList = new HandlerList(); //-- - private Key identifier; + private final Key identifier; + private final Component name; + private final Displayable displayable; + private final Component message; private Component prefix = Component.empty(); - private Component name; - private Displayable displayable; - private Component message; public AdminChatEvent(Key identifier, Component prefix, Component name, Displayable rank, Component message, boolean async) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java index 90c63c5b6..f9dd7de32 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java @@ -1,21 +1,16 @@ package me.totalfreedom.totalfreedommod.banning; import com.google.common.collect.Lists; -import java.text.SimpleDateFormat; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.util.*; + public class Ban { @@ -168,12 +163,10 @@ public String bakeKickMessage() if (!hasUsername()) { message.append("r IP address is"); - } - else if (!hasIps()) + } else if (!hasIps()) { message.append("r username is"); - } - else + } else { message.append(" are"); } @@ -222,7 +215,7 @@ public boolean equals(Object object) return false; } - final Ban ban = (Ban)object; + final Ban ban = (Ban) object; if (hasIps() != ban.hasIps() || hasUsername() != ban.hasUsername()) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java index c308d34cd..fbb9d97b3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java @@ -2,16 +2,6 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -21,6 +11,10 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + public class BanManager extends FreedomService { @@ -56,8 +50,7 @@ public void onStart() bans.add(ban); } } - } - catch (SQLException e) + } catch (SQLException e) { FLog.severe("Failed to load ban list: " + e.getMessage()); } @@ -186,8 +179,7 @@ public void addBan(Ban ban) if (ban.getUsername() != null && getByUsername(ban.getUsername()) != null) { removeBan(ban); - } - else + } else { for (String ip : ban.getIps()) @@ -267,8 +259,7 @@ public void onPlayerJoin(PlayerJoinEvent event) if (ban != null) { removeBan(ban); - } - else + } else { ban = getByIp(FUtil.getIp(player)); if (ban != null) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java index f0bb19596..3d2b409cc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java @@ -1,15 +1,16 @@ package me.totalfreedom.totalfreedommod.banning; import com.google.common.collect.Lists; +import me.totalfreedom.totalfreedommod.config.IConfig; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.configuration.ConfigurationSection; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; -import me.totalfreedom.totalfreedommod.config.IConfig; -import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.configuration.ConfigurationSection; public class IndefiniteBan implements IConfig { @@ -32,8 +33,7 @@ public void loadFrom(ConfigurationSection cs) UUID uuid = UUID.fromString(strUUID); this.uuid = uuid; } - } - catch (IllegalArgumentException e) + } catch (IllegalArgumentException e) { FLog.warning("Failed to load indefinite banned UUID for " + this.username + ". Make sure the UUID is in the correct format with dashes."); } @@ -46,8 +46,7 @@ public void loadFrom(ConfigurationSection cs) try { this.expiry = date != null ? new SimpleDateFormat("yyyy-MM-dd").parse(date) : null; - } - catch (ParseException ex) + } catch (ParseException ex) { FLog.warning("Failed to load indefinite banned expiry for " + this.username + ". Make sure the expiry is in the correct format (yyyy-MM-dd)."); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java index 00515deaa..dbc705086 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java @@ -2,10 +2,6 @@ import com.google.common.base.Strings; import com.google.common.collect.Sets; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Set; -import java.util.UUID; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.YamlConfig; @@ -17,22 +13,22 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerLoginEvent; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Set; +import java.util.UUID; + public class IndefiniteBanList extends FreedomService { public static final String CONFIG_FILENAME = "indefinitebans.yml"; - private YamlConfig config; - private final Set indefBans = Sets.newHashSet(); - + private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy, zzzz"); + private YamlConfig config; private int nameBanCount = 0; - private int uuidBanCount = 0; - private int ipBanCount = 0; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy, zzzz"); - @Override public void onStart() { @@ -99,14 +95,12 @@ public void onPlayerLogin(PlayerLoginEvent event) bannedBy = "username"; ban = indefBan; break; - } - else if (indefBan.getUuid() != null && indefBan.getUuid().equals(uuid)) + } else if (indefBan.getUuid() != null && indefBan.getUuid().equals(uuid)) { bannedBy = "UUID"; ban = indefBan; break; - } - else if (indefBan.getIps().contains(ip)) + } else if (indefBan.getIps().contains(ip)) { bannedBy = "IP address"; ban = indefBan; @@ -117,7 +111,8 @@ else if (indefBan.getIps().contains(ip)) onPlayerLoginSplitWorkToReduceComplexity(event, ban, bannedBy); } - private void onPlayerLoginSplitWorkToReduceComplexity(PlayerLoginEvent event, IndefiniteBan ban, String bannedBy) { + private void onPlayerLoginSplitWorkToReduceComplexity(PlayerLoginEvent event, IndefiniteBan ban, String bannedBy) + { if (ban != null) { if (ban.isExpired()) @@ -150,6 +145,7 @@ private void onPlayerLoginSplitWorkToReduceComplexity(PlayerLoginEvent event, In event.disallow(PlayerLoginEvent.Result.KICK_OTHER, kickMessage); } } + private void updateCount() { nameBanCount = 0; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java index 93ad8892c..e885bcd77 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java @@ -140,13 +140,13 @@ public void onBlockPlace(BlockPlaceEvent event) case PLAYER_HEAD: case PLAYER_WALL_HEAD: { - Skull skull = (Skull)event.getBlockPlaced().getState(); + Skull skull = (Skull) event.getBlockPlaced().getState(); if (skull.getOwner() != null) { if (skull.getOwner().contains("\u00A7")) { skull.setOwner(skull.getOwner().replace("\u00A7", "")); - SkullMeta meta = (SkullMeta)event.getItemInHand().getItemMeta(); + SkullMeta meta = (SkullMeta) event.getItemInHand().getItemMeta(); if (meta != null) { ItemStack newHead = new ItemStack(Material.PLAYER_HEAD, 1); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java index c9c43050e..0aa6d4d14 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java @@ -1,11 +1,7 @@ package me.totalfreedom.totalfreedommod.blocking; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import me.totalfreedom.scissors.event.block.MasterBlockFireEvent; import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent; +import me.totalfreedom.scissors.event.block.MasterBlockFireEvent; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -21,17 +17,15 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.*; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.bukkit.event.entity.FireworkExplodeEvent; -import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + public class EventBlocker extends FreedomService { /** diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 4436ac191..ece8576d5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -88,13 +88,11 @@ private void handleRightClick(PlayerInteractEvent event) if (mat == Material.MOOSHROOM_SPAWN_EGG) { eggType = EntityType.MUSHROOM_COW; - } - else + } else { eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10)); } - } - catch (IllegalArgumentException ignored) + } catch (IllegalArgumentException ignored) { // } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java index 99f39f147..e4adab4ca 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java @@ -1,24 +1,17 @@ package me.totalfreedom.totalfreedommod.blocking; -import java.util.Objects; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.attribute.Attributable; import org.bukkit.attribute.Attribute; -import org.bukkit.entity.Bat; -import org.bukkit.entity.EnderDragon; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Ghast; -import org.bukkit.entity.Giant; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Slime; -import org.bukkit.entity.Wither; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent; +import java.util.Objects; + public class MobBlocker extends FreedomService { @Override @@ -43,13 +36,13 @@ public void onEntitySpawn(EntitySpawnEvent e) Entity entity = e.getEntity(); if (entity instanceof Attributable) { - if (Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).getBaseValue() > 255.0) + if (Objects.requireNonNull(((Attributable) entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).getBaseValue() > 255.0) { - Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).setBaseValue(255.0); + Objects.requireNonNull(((Attributable) entity).getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).setBaseValue(255.0); } - if (Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).getBaseValue() > 10.0) + if (Objects.requireNonNull(((Attributable) entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).getBaseValue() > 10.0) { - Objects.requireNonNull(((Attributable)entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).setBaseValue(10.0); + Objects.requireNonNull(((Attributable) entity).getAttribute(Attribute.GENERIC_MOVEMENT_SPEED)).setBaseValue(10.0); } } } @@ -72,40 +65,35 @@ public void onCreatureSpawn(CreatureSpawnEvent event) event.setCancelled(true); return; } - } - else if (spawned instanceof Ghast) + } else if (spawned instanceof Ghast) { if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()) { event.setCancelled(true); return; } - } - else if (spawned instanceof Slime) + } else if (spawned instanceof Slime) { if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()) { event.setCancelled(true); return; } - } - else if (spawned instanceof Wither) + } else if (spawned instanceof Wither) { if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()) { event.setCancelled(true); return; } - } - else if (spawned instanceof Giant) + } else if (spawned instanceof Giant) { if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()) { event.setCancelled(true); return; } - } - else if (spawned instanceof Bat) + } else if (spawned instanceof Bat) { event.setCancelled(true); return; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java index d05f7d324..9fef53104 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java @@ -3,11 +3,7 @@ import me.totalfreedom.totalfreedommod.FreedomService; import org.bukkit.ChatColor; import org.bukkit.GameMode; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Player; -import org.bukkit.entity.SpectralArrow; -import org.bukkit.entity.Trident; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -32,41 +28,37 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) Player target = null; if (event.getEntity() instanceof Player) { - target = (Player)event.getEntity(); + target = (Player) event.getEntity(); if (event.getDamager() instanceof Player) { - player = (Player)event.getDamager(); - } - else if (event.getDamager() instanceof Arrow) + player = (Player) event.getDamager(); + } else if (event.getDamager() instanceof Arrow) { - Arrow arrow = (Arrow)event.getDamager(); + Arrow arrow = (Arrow) event.getDamager(); if (arrow.getShooter() instanceof Player) { - player = (Player)arrow.getShooter(); + player = (Player) arrow.getShooter(); } - } - else if (event.getDamager() instanceof SpectralArrow) + } else if (event.getDamager() instanceof SpectralArrow) { - SpectralArrow spectralArrow = (SpectralArrow)event.getDamager(); + SpectralArrow spectralArrow = (SpectralArrow) event.getDamager(); if (spectralArrow.getShooter() instanceof Player) { - player = (Player)spectralArrow.getShooter(); + player = (Player) spectralArrow.getShooter(); } - } - else if (event.getDamager() instanceof Trident) + } else if (event.getDamager() instanceof Trident) { - Trident trident = (Trident)event.getDamager(); + Trident trident = (Trident) event.getDamager(); if (trident.getShooter() instanceof Player) { - player = (Player)trident.getShooter(); + player = (Player) trident.getShooter(); } - } - else if (event.getDamager() instanceof FishHook) + } else if (event.getDamager() instanceof FishHook) { - FishHook fishhook = (FishHook)event.getDamager(); + FishHook fishhook = (FishHook) event.getDamager(); if (fishhook.getShooter() instanceof Player) { - player = (Player)fishhook.getShooter(); + player = (Player) fishhook.getShooter(); } } } @@ -77,18 +69,15 @@ else if (event.getDamager() instanceof FishHook) { player.sendMessage(ChatColor.RED + "Creative PvP is not allowed!"); event.setCancelled(true); - } - else if (plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) + } else if (plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { player.sendMessage(ChatColor.RED + "God mode PvP is not allowed!"); event.setCancelled(true); - } - else if (plugin.pl.getPlayer(target).isPvpBlocked()) + } else if (plugin.pl.getPlayer(target).isPvpBlocked()) { player.sendMessage(ChatColor.RED + target.getName() + " has PvP disabled!"); event.setCancelled(true); - } - else if (plugin.pl.getPlayer(player).isPvpBlocked()) + } else if (plugin.pl.getPlayer(player).isPvpBlocked()) { player.sendMessage(ChatColor.RED + "You have PvP disabled!"); event.setCancelled(true); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java index 1088e5656..a2e34d044 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java @@ -1,6 +1,5 @@ package me.totalfreedom.totalfreedommod.blocking; -import java.util.Collection; import me.totalfreedom.totalfreedommod.FreedomService; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -13,6 +12,8 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; +import java.util.Collection; + public class PotionBlocker extends FreedomService { @@ -36,7 +37,7 @@ public void onThrowPotion(PotionSplashEvent event) Player player = null; if (projectileSource instanceof Player) { - player = (Player)projectileSource; + player = (Player) projectileSource; } if (isDeathPotion(potion.getEffects())) @@ -57,7 +58,7 @@ public void onThrowLingeringPotion(LingeringPotionSplashEvent event) Player player = null; if (projectileSource instanceof Player) { - player = (Player)projectileSource; + player = (Player) projectileSource; } if (isDeathPotion(potion.getEffects())) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java index 46b2e4d64..b430d20d9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java @@ -2,11 +2,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import java.lang.reflect.Field; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; @@ -16,11 +11,14 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.plugin.SimplePluginManager; + +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class CommandBlocker extends FreedomService { @@ -30,24 +28,6 @@ public class CommandBlocker extends FreedomService private final Map entryList = Maps.newHashMap(); private final List unknownCommands = Lists.newArrayList(); - public static CommandMap getCommandMap() - { - try - { - SimplePluginManager simplePluginManager = (SimplePluginManager)Bukkit.getServer().getPluginManager(); - - Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - - return (SimpleCommandMap)commandMapField.get(simplePluginManager); - } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - FLog.severe("Failed to get command map field (" + e.getMessage() + ")"); - } - return null; - } - @Override public void onStart() { @@ -65,10 +45,10 @@ public void load() // TODO: Complexity is 21. Need to fix this. entryList.clear(); unknownCommands.clear(); - final CommandMap commandMap = getCommandMap(); + final CommandMap commandMap = Bukkit.getCommandMap(); @SuppressWarnings("unchecked") - List blockedCommands = (List)ConfigEntry.BLOCKED_COMMANDS.getList(); + List blockedCommands = (List) ConfigEntry.BLOCKED_COMMANDS.getList(); for (String rawEntry : blockedCommands) { final String[] parts = rawEntry.split(":"); @@ -104,8 +84,7 @@ public void load() // TODO: Complexity is 21. Need to fix this. if (command == null) { unknownCommands.add(commandName); - } - else + } else { commandName = command.getName().toLowerCase(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java index 9325f8cbd..33d0e432f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java @@ -39,7 +39,7 @@ public void doActions(CommandSender sender) { if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) { - TotalFreedomMod.getPlugin().ae.autoEject((Player)sender, "You used a prohibited command: " + command); + TotalFreedomMod.getPlugin().ae.autoEject((Player) sender, "You used a prohibited command: " + command); FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED); return; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerRank.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerRank.java index aeecce691..73c8ef9e5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerRank.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerRank.java @@ -2,7 +2,6 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import org.bukkit.command.CommandSender; public enum CommandBlockerRank @@ -25,7 +24,7 @@ public static CommandBlockerRank fromSender(CommandSender sender) Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(sender); if (admin != null) { - if (admin.getRank() == GroupProvider.SENIOR_ADMIN.getGroup()) + if (admin.getRank() == TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin()) { return SENIOR_ADMIN; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java index 82c0712eb..c06f6bf6c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java @@ -6,8 +6,8 @@ import me.totalfreedom.bukkittelnet.api.TelnetRequestDataTagsEvent; import me.totalfreedom.bukkittelnet.session.ClientSession; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FLog; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -82,8 +82,8 @@ public void onTelnetRequestDataTags(TelnetRequestDataTagsEvent event) boolean active = admin.isActive(); isAdmin = active; - isSeniorAdmin = active && admin.getRank().equals(GroupProvider.SENIOR_ADMIN.getGroup()); - isTelnetAdmin = active && (isSeniorAdmin || admin.getRank().equals(GroupProvider.ADMIN.getGroup())); + isSeniorAdmin = active && admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin()); + isTelnetAdmin = active && (isSeniorAdmin || admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin())); } playerTags.put("tfm.admin.isAdmin", isAdmin); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java index 8f317599d..1192e2dd6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java @@ -1,8 +1,5 @@ package me.totalfreedom.totalfreedommod.bridge; -import java.util.*; -import java.util.concurrent.CompletableFuture; - import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -26,6 +23,9 @@ import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; +import java.util.*; +import java.util.concurrent.CompletableFuture; + public class CoreProtectBridge extends FreedomService { //-- Block Inspector --// @@ -69,10 +69,9 @@ public CoreProtect getCoreProtect() assert coreProtectPlugin != null; if (coreProtectPlugin instanceof CoreProtect) { - coreProtect = (CoreProtect)coreProtectPlugin; + coreProtect = (CoreProtect) coreProtectPlugin; } - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } @@ -94,8 +93,7 @@ public CoreProtectAPI getCoreProtectAPI() { return null; } - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } @@ -179,8 +177,7 @@ public void showPageToPlayer(Player player, FUtil.PaginationList= recieverRank.getWeight() || !invOwner.isOnline()) + if (playerRank.getWeight().getWeight() >= recieverRank.getWeight().getWeight() + || !invOwner.isOnline()) { event.setCancelled(true); refreshPlayer = player; @@ -185,7 +178,7 @@ public void onInventoryClose(InventoryCloseEvent event) Player refreshPlayer = null; Inventory inventory = event.getView().getTopInventory(); InventoryType inventoryType = inventory.getType(); - Player player = (Player)event.getPlayer(); + Player player = (Player) event.getPlayer(); FPlayer fPlayer = plugin.pl.getPlayer(player); if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee()) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java index b4bbf4161..c397c5d97 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java @@ -13,16 +13,6 @@ public class LibsDisguisesBridge extends FreedomService { private static LibsDisguises libsDisguisesPlugin = null; - @Override - public void onStart() - { - } - - @Override - public void onStop() - { - } - public static LibsDisguises getLibsDisguisesPlugin() { if (libsDisguisesPlugin == null) @@ -43,6 +33,16 @@ public static LibsDisguises getLibsDisguisesPlugin() return libsDisguisesPlugin; } + @Override + public void onStart() + { + } + + @Override + public void onStop() + { + } + public void undisguiseAll(boolean admin) { try diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java index 1103d373a..0420ce7c4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java @@ -1,6 +1,6 @@ package me.totalfreedom.totalfreedommod.bridge; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import net.luckperms.api.LuckPerms; import net.luckperms.api.track.TrackManager; import org.bukkit.Bukkit; @@ -36,8 +36,8 @@ public void setupTracks() { trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) -> { - track.appendGroup(GroupProvider.NON_OP.getGroup().getLuckPermsGroup()); - track.appendGroup(GroupProvider.OP.getGroup().getLuckPermsGroup()); + track.appendGroup(TotalFreedomMod.getPlugin().getHierarchy().groups().getNonOp().getLuckPermsGroup()); + track.appendGroup(TotalFreedomMod.getPlugin().getHierarchy().groups().getOp().getLuckPermsGroup()); }); } @@ -45,15 +45,19 @@ public void setupTracks() { trackManager.createAndLoadTrack("admin").whenComplete((track, exception) -> { - track.appendGroup(GroupProvider.ADMIN.getGroup().getLuckPermsGroup()); - track.appendGroup(GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup()); + track.appendGroup(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin().getLuckPermsGroup()); + track.appendGroup(TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin().getLuckPermsGroup()); }); } if (!trackManager.isLoaded("builder")) { trackManager.createAndLoadTrack("builder").whenComplete((track, exception) -> - track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup())); + track.appendGroup(TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .getMasterBuilder() + .getLuckPermsGroup())); } } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java index bb75d14ad..2699516dc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java @@ -1,7 +1,6 @@ package me.totalfreedom.totalfreedommod.bridge; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.util.FLog; @@ -35,11 +34,10 @@ public WorldEditPlugin getWorldEditPlugin() { if (we instanceof WorldEditPlugin) { - worldeditPlugin = (WorldEditPlugin)we; + worldeditPlugin = (WorldEditPlugin) we; } } - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } @@ -57,8 +55,7 @@ public void setLimit(Player player, int limit) { session.setBlockChangeLimit(limit); } - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } @@ -100,8 +97,7 @@ private LocalSession getPlayerSession(Player player) try { return wep.getSession(player); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); return null; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java index b584695df..6c8f1cce2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java @@ -1,13 +1,14 @@ package me.totalfreedom.totalfreedommod.caging; -import java.util.ArrayList; -import java.util.List; import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Skull; +import java.util.ArrayList; +import java.util.List; + public class CageData { @@ -74,8 +75,7 @@ public static void generateHollowCube(Location location, int length, Material ma } block.setType(material); - } - else + } else { if (Math.abs(xOffset) == length && Math.abs(yOffset) == length && Math.abs(zOffset) == length) { @@ -88,12 +88,11 @@ public static void generateHollowCube(Location location, int length, Material ma { try { - Skull skull = (Skull)block.getState(); + Skull skull = (Skull) block.getState(); // This may or may not work in future versions of spigot skull.setOwner(input); skull.update(); - } - catch (ClassCastException ignored) + } catch (ClassCastException ignored) { } } @@ -233,8 +232,7 @@ public void setCaged(boolean cage) if (cage) { cage(fPlayer.getPlayer().getLocation(), Material.GLASS, Material.GLASS); - } - else + } else { this.caged = false; regenerateHistory(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java index d520f7bad..52547f542 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java @@ -1,7 +1,6 @@ package me.totalfreedom.totalfreedommod.caging; import io.papermc.lib.PaperLib; -import java.util.Objects; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -16,6 +15,8 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.Objects; + public class Cager extends FreedomService { @Override @@ -64,8 +65,7 @@ public void onPlayerMove(PlayerMoveEvent event) if (!Objects.equals(playerLoc.getWorld(), cageLoc.getWorld())) { outOfCage = true; - } - else + } else { outOfCage = playerLoc.distanceSquared(cageLoc) > (2.5D * 2.5D); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java deleted file mode 100644 index d7cb4b945..000000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java +++ /dev/null @@ -1,100 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.util.FLog; -import org.reflections.Reflections; - -public class CommandLoader extends FreedomService -{ - private final List commands; - - public CommandLoader() - { - commands = new ArrayList<>(); - } - - @Override - public void onStart() - { - } - - @Override - public void onStop() - { - } - - public void add(FreedomCommand command) - { - commands.add(command); - command.register(); - } - - public FreedomCommand getByName(String name) - { - for (FreedomCommand command : commands) - { - if (name.equals(command.getName())) - { - return command; - } - } - return null; - } - - public boolean isAlias(String alias) - { - for (FreedomCommand command : commands) - { - if (Arrays.asList(command.getAliases().split(",")).contains(alias)) - { - return true; - } - } - return false; - } - - public void loadCommands() - { - Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command"); - - Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class); - - commandLoading: - for (Class commandClass : commandClasses) - { - try - { - if (commandClass.isAnnotationPresent(CommandDependencies.class)) - { - String[] dependencies = commandClass.getAnnotation(CommandDependencies.class).value(); - - for (String plugin : dependencies) - { - if (!server.getPluginManager().isPluginEnabled(plugin)) - { - FLog.warning("Not loading command due to missing dependency (" + plugin + "): /" + commandClass.getSimpleName().replace("Command_", "")); - continue commandLoading; - } - } - } - - add(commandClass.newInstance()); - } - catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex) - { - FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_", "")); - } - } - - FLog.info("Loaded " + commands.size() + " commands"); - } - - public List getCommands() - { - return commands; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java index cb7f9b31c..d3f43ebb8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminchat.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java index 25821da4a..fb012ff2f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_admininfo.java @@ -1,11 +1,16 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.List; + @CommandPermissions(permission = "admininfo", source = SourceType.BOTH) @CommandParameters(description = "Information on how to apply for admin.", usage = "/", aliases = "si,ai,staffinfo") public class Command_admininfo extends FreedomCommand @@ -19,8 +24,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (adminInfo.isEmpty()) { msgNew("The admin information section of the config.yml file has not been configured."); - } - else + } else { adminInfo.forEach(this::msgNew); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java index f1ac034ce..b757202a8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java @@ -1,8 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; @@ -10,6 +11,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + @CommandPermissions(permission = "adminmode", source = SourceType.BOTH) @CommandParameters(description = "Denies joining of operators and only allows admins to join.", usage = "/ [on | off]", aliases = "staffmode") public class Command_adminmode extends FreedomCommand @@ -28,8 +33,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false); FUtil.adminAction(sender.getName(), "Opening the server to all players", true); return true; - } - else if (args[0].equalsIgnoreCase("on")) + } else if (args[0].equalsIgnoreCase("on")) { ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true); FUtil.adminAction(sender.getName(), "Closing the server to non-admins", true); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java index fe4c08bd5..a29b0a658 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java @@ -1,9 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.world.WorldTime; import me.totalfreedom.totalfreedommod.world.WorldWeather; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -12,6 +13,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + @CommandPermissions(permission = "adminworld", source = SourceType.BOTH) @CommandParameters(description = "Allows for admins to configure time, and weather of the AdminWorld, and allows for admins and ops to go to the AdminWorld.", usage = "/ [time | weather ]", @@ -27,14 +32,12 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (args.length == 0) { commandMode = CommandMode.TELEPORT; - } - else if (args.length >= 2) + } else if (args.length >= 2) { if ("time".equalsIgnoreCase(args[0])) { commandMode = CommandMode.TIME; - } - else if ("weather".equalsIgnoreCase(args[0])) + } else if ("weather".equalsIgnoreCase(args[0])) { commandMode = CommandMode.WEATHER; } @@ -121,8 +124,7 @@ else if ("weather".equalsIgnoreCase(args[0])) return false; } } - } - catch (PermissionDeniedException ex) + } catch (PermissionDeniedException ex) { if (ex.getMessage().isEmpty()) { @@ -154,14 +156,12 @@ public List getTabCompleteOptions(CommandSender sender, Command command, if (args.length == 1) { return Arrays.asList("time", "weather"); - } - else if (args.length == 2) + } else if (args.length == 2) { if (args[0].equals("time")) { return Arrays.asList("morning", "noon", "evening", "night"); - } - else if (args[0].equals("weather")) + } else if (args[0].equals("weather")) { return Arrays.asList("off", "rain", "storm"); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java index 694c7e11d..d6e78ace2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java index 3723b2275..23dff11c7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autoclear.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -23,8 +27,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (enabled) { plugin.lp.CLEAR_ON_JOIN.remove(args[0]); - } - else + } else { plugin.lp.CLEAR_ON_JOIN.add(args[0]); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java index 908330bae..a6339f953 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_autotp.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -23,8 +27,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (enabled) { plugin.lp.TELEPORT_ON_JOIN.remove(args[0]); - } - else + } else { plugin.lp.TELEPORT_ON_JOIN.add(args[0]); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java index 5042f1d9b..effd973bb 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java @@ -1,9 +1,8 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Objects; - import com.earth2me.essentials.User; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -18,6 +17,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Objects; + +@Intercept("ban") @CommandPermissions(permission = "ban", source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Bans the specified player.", usage = "/ [reason] [-nrb | -q]", aliases = "gtfo") public class Command_ban extends FreedomCommand @@ -51,8 +53,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); } - } - else + } else { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); } @@ -80,15 +81,13 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { msg(PLAYER_NOT_FOUND); return true; - } - else + } else { username = entry.getName(); ip = entry.getIps().get(0); } } - } - else + } else { username = player.getName(); ip = FUtil.getIp(player); @@ -114,8 +113,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin Objects.requireNonNull(targetPos.getWorld()).strikeLightning(strike_pos); } } - } - else + } else { msgNew("Banned quietly.", Placeholder.unparsed("player", player.getName())); } @@ -139,8 +137,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (player != null) { ban = Ban.forPlayer(player, sender, null, reason); - } - else + } else { ban = Ban.forPlayerName(username, sender, null, reason); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java index c2e616358..543e5333b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banip.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.ArrayUtils; @@ -9,6 +10,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("banip") @CommandPermissions(permission = "banip", source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Bans the specified ip.", usage = "/ [reason] [-q]") public class Command_banip extends FreedomCommand @@ -48,8 +50,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); } - } - else if (args.length > 1) + } else if (args.length > 1) { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banlist.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banlist.java index 7645c03a4..6b674bcef 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banlist.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banlist.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; @@ -9,6 +10,7 @@ import java.util.Collections; import java.util.List; +@Intercept("banlist") @CommandPermissions(permission = "banlist", source = SourceType.BOTH) @CommandParameters(description = "Shows all banned player names. Admins may optionally use 'purge' to clear the list.", usage = "/ [purge]") public class Command_banlist extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java index a37a1df86..d85c80f6c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_banname.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.ArrayUtils; @@ -42,8 +46,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); } - } - else if (args.length > 1) + } else if (args.length > 1) { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java index 6f49efc6c..a3f2d005b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_bird.java @@ -1,14 +1,19 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Arrays; -import java.util.List; -import java.util.SplittableRandom; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import java.util.Arrays; +import java.util.List; +import java.util.SplittableRandom; + @CommandPermissions(permission = "bird", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Spawns a random type of fish at your location.", usage = "/") public class Command_bird extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java index ddb4e3a55..8dfee5459 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -82,8 +86,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin msgNew("Blocked commands for .", Placeholder.unparsed("player", player.getName())); plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.BLOCKCMD, null)); - } - else + } else { msgNew("That player's commands are already blocked."); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java index 1023f7375..45ac6d76c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -81,14 +85,12 @@ public boolean run(final CommandSender sender, final Player playerSender, final fPlayer.setEditBlocked(false); msgNew("Restored block modification abilities for .", Placeholder.unparsed("player", player.getName())); msgNew(player, "Your block modification abilities have been restored."); - } - else + } else { if (plugin.al.isAdmin(player)) { msgNew(" is an admin, and as such cannot have their block modification abilities restricted.", Placeholder.unparsed("player", player.getName())); - } - else + } else { FUtil.adminAction(sender.getName(), "Restricting block modification abilities for " + player.getName(), true); fPlayer.setEditBlocked(true); @@ -104,8 +106,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final } return true; - } - else + } else { return false; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java index 16253f0b1..45cb89a67 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -34,8 +38,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final if (restricted.isEmpty()) { msgNew("Nobody currently has their PVP abilities restricted."); - } - else + } else { msgNew("PVP abilities are restricted for these player(s): ", Placeholder.unparsed("players", FUtil.listToString(restricted))); @@ -87,8 +90,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final pd.setPvpBlocked(false); msgNew("Enabled the ability to PVP for .", Placeholder.unparsed("player", p.getName())); msgNew(p, "Your PVP abilities have been restored."); - } - else + } else { if (plugin.al.isAdmin(p)) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java index 9372eab88..6b4b18ed7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; @@ -29,8 +33,7 @@ public void run() } } }.runTaskLater(plugin, 6000L); - } - else + } else { ConfigEntry.ALLOW_REDSTONE.setBoolean(true); FUtil.adminAction(sender.getName(), "Unblocking all redstone", true); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java index 7e12b63c9..46479def7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java @@ -1,9 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -15,6 +15,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + @CommandPermissions(permission = "cage", source = SourceType.BOTH) @CommandParameters(description = "Place a cage around someone with certain blocks, or someone's player head.", usage = "/ [head | block] [playername | blockname]") public class Command_cage extends FreedomCommand @@ -63,8 +68,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final if (args.length >= 3) { skullName = args[2]; - } - else + } else { outerMaterial = Material.SKELETON_SKULL; } @@ -79,14 +83,12 @@ public boolean run(final CommandSender sender, final Player playerSender, final if (Material.matchMaterial(args[2]) != null && Material.matchMaterial(args[2]).isBlock()) { outerMaterial = Material.matchMaterial(args[2]); - } - else + } else { msgNew("Invalid block!"); return true; } - } - else + } else { return false; } @@ -101,8 +103,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final if (outerMaterial == Material.PLAYER_HEAD) { FUtil.adminAction(sender.getName(), "Caging " + player.getName() + " in " + skullName, true); - } - else + } else { FUtil.adminAction(sender.getName(), "Caging " + player.getName(), true); } @@ -112,8 +113,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final if (skullName != null) { fPlayer.getCageData().cage(location, outerMaterial, innerMaterial, skullName); - } - else + } else { fPlayer.getCageData().cage(location, outerMaterial, innerMaterial); } @@ -137,21 +137,18 @@ public List getTabCompleteOptions(CommandSender sender, Command command, arguments.add("purge"); arguments.addAll(FUtil.getPlayerList()); return arguments; - } - else if (args.length == 2) + } else if (args.length == 2) { if (!args[0].equals("purge")) { return Arrays.asList("head", "block"); } - } - else if (args.length == 3) + } else if (args.length == 3) { if (args[1].equals("block")) { return Arrays.stream(Material.values()).map(Enum::name).toList(); - } - else if (args[1].equals("head")) + } else if (args[1].equals("head")) { return FUtil.getPlayerList(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java index 0bd5e793e..64915aab2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Material; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleanchat.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleanchat.java index 1ff6f0bcb..565feaefd 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleanchat.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleanchat.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java index bd08aece1..d3a2cfb9d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cleardiscordqueue.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java index 2dcf3f20b..3a266e7a9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clownfish.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -25,13 +26,11 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { playerSender.getInventory().addItem(plugin.sh.getClownFish()); msgNew("You have been given a .", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName())); - } - else if (plugin.pl.getPlayer(playerSender).isClownfishDisabled()) + } else if (plugin.pl.getPlayer(playerSender).isClownfishDisabled()) { msgNew("An admin has disabled your ability to use the . Guess you were the clown after all.", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName())); - } - else + } else { msgNew("You don't own a ! Purchase one from the shop.", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName())); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java index 12cf18d6f..4e311e211 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java index c9abb49fe..9a3ad7a89 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -33,8 +34,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (senderIsConsole) { msgNew("When used from the console, you must define a target player."); - } - else + } else { PlayerData playerData = getData(playerSender); msgNew("You have coin.", @@ -53,8 +53,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (target == null) { msg(PLAYER_NOT_FOUND); - } - else + } else { PlayerData playerData = getData(target); msgNew(" has coin.", @@ -83,8 +82,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { // Prevents players from trying to be cheeky with negative numbers. coinsToTransfer = Math.max(Math.abs(Integer.parseInt(args[2])), 1); - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { msgNew("Invalid number: ", Placeholder.unparsed("num", args[2])); return true; @@ -100,8 +98,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (target == null) { msg(PLAYER_NOT_FOUND); - } - else + } else { PlayerData playerData = getData(target); playerData.setCoins(playerData.getCoins() + coinsToTransfer); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java index 4ace67b30..347ebb80f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cookie.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cookie.java index 97515431a..e54d303c7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cookie.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cookie.java @@ -1,8 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Collections; -import java.util.Random; - +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Material; import org.bukkit.command.Command; @@ -11,6 +12,9 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.Collections; +import java.util.Random; + @CommandPermissions(permission = "cookie", source = SourceType.BOTH) @CommandParameters(description = "For those who have no friends - gives a cookie to everyone on the server.", usage = "/") public class Command_cookie extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java index 9f9736f27..14a9896e2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deafen.java @@ -1,6 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.SplittableRandom; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.command.Command; @@ -8,6 +11,8 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import java.util.SplittableRandom; + @CommandPermissions(permission = "deafen", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Makes random sounds.", usage = "/") public class Command_deafen extends FreedomCommand @@ -32,7 +37,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { for (double percent = 0.0; percent <= 1.0; percent += (1.0 / STEPS)) { - final float pitch = (float)(percent * 2.0); + final float pitch = (float) (percent * 2.0); new BukkitRunnable() { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_debugstick.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_debugstick.java index c5002aafc..6d45ebd3c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_debugstick.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_debugstick.java @@ -1,6 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Arrays; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -11,6 +14,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.Arrays; + @CommandPermissions(permission = "debugstick", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Get a stick of happiness.", usage = "/") public class Command_debugstick extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_denick.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_denick.java index d6867b514..6a2dfbd5e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_denick.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_denick.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deop.java index 947aeb9b4..bef04e183 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deop.java @@ -1,17 +1,16 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; -import me.totalfreedom.totalfreedommod.rank.HierarchyProvider; -import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.luckperms.api.model.user.User; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.luckperms.api.track.DemotionResult; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.concurrent.atomic.AtomicBoolean; - +@Intercept("deop") @CommandPermissions(permission = "deop", source = SourceType.BOTH) @CommandParameters(description = "Deop a player", usage = "/ ") public class Command_deop extends FreedomCommand @@ -38,25 +37,22 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return true; } - AtomicBoolean atomicBoolean = new AtomicBoolean(silent); - User user = GroupProvider.getUser(player); - HierarchyProvider.OP.getHierarchy().demoteUser(user).whenComplete((result, throwable) -> - { - if (throwable != null) - { - FLog.severe("Error while demoting " + player.getName() + " to OP: " + throwable.getMessage()); - return; - } + boolean b = silent; + DemotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .demoteUser(TotalFreedomMod.getPlugin().getHierarchy().op(), player); - msg(player, YOU_ARE_NOT_OP); - plugin.rm.updateDisplay(player); + if (!result.wasSuccessful()) + { + msgNew(" is already non-op.", Placeholder.unparsed("player", player.getName())); + return true; + } - if (!atomicBoolean.get()) - { - FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false); - } - }); + msg(player, YOU_ARE_NOT_OP); + if (!b) + { + FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false); + } return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deopall.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deopall.java index b452b6ab9..bd30013b7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deopall.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_deopall.java @@ -1,10 +1,13 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; -import me.totalfreedom.totalfreedommod.rank.HierarchyProvider; -import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.luckperms.api.model.user.User; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.luckperms.api.track.DemotionResult; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -21,15 +24,16 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin server.getOnlinePlayers().forEach(player -> { - User user = GroupProvider.getUser(player); - HierarchyProvider.OP.getHierarchy().demoteUser(user).whenComplete((result, ex) -> { - if (ex != null) { - FLog.severe("Failed to demote " + player.getName() + " to default rank"); - } + DemotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .demoteUser(TotalFreedomMod.getPlugin().getHierarchy().op(), player); - msg(player, YOU_ARE_NOT_OP); - plugin.rm.updateDisplay(player); - }); + if (!result.wasSuccessful()) + { + msgNew(" is already non-op.", Placeholder.unparsed("player", player.getName())); + return; + } + + msg(player, YOU_ARE_NOT_OP); }); return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java index 51d247474..15ed60ebc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dispfill.java @@ -1,7 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; @@ -15,6 +17,9 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; + @CommandPermissions(permission = "dispfill", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Fill nearby dispensers with a set of items of your choice.", usage = "/ ") public class Command_dispfill extends FreedomCommand @@ -24,7 +29,7 @@ private static void setDispenserContents(final Block targetBlock, final ItemStac { if (targetBlock.getType() == Material.DISPENSER) { - final Inventory dispenserInv = ((Dispenser)targetBlock.getState()).getInventory(); + final Inventory dispenserInv = ((Dispenser) targetBlock.getState()).getInventory(); dispenserInv.clear(); dispenserInv.addItem(items); } @@ -40,8 +45,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { radius = Math.max(5, Math.min(25, Integer.parseInt(args[0]))); - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { msgNew("Invalid radius: ", Placeholder.unparsed("amount", args[0])); return true; @@ -57,8 +61,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (material != null) { items.add(new ItemStack(material, 64)); - } - else + } else { msgNew("Skipping invalid item: ", Placeholder.unparsed("item", searchItem)); } @@ -93,8 +96,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin } msgNew("Done. dispenser(s) filled.", Placeholder.unparsed("amount", String.valueOf(affected))); - } - else + } else { return false; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java index c6f711467..f72edc272 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java @@ -2,6 +2,10 @@ import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java index 833dd10ce..7f471855d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -40,8 +44,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin msgNew(" entit ejected.", Placeholder.unparsed("count", String.valueOf(count)), Placeholder.unparsed("grammar", count == 1 ? "y was" : "ies were")); - } - else + } else { msgNew("Nothing was ejected."); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_enchant.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_enchant.java index 9661d8d71..4d5363ba8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_enchant.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_enchant.java @@ -1,12 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.IntStream; - +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -17,6 +14,9 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.*; +import java.util.stream.IntStream; + @CommandPermissions(permission = "enchant", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Enchant items.", usage = "/ [level] | remove >") public class Command_enchant extends FreedomCommand @@ -45,33 +45,28 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (enchants.isEmpty()) { msgNew("There are no enchantments that work with this item."); - } - else + } else { msgNew("Possible enchantments for this item: ", Placeholder.unparsed("enchants", FUtil.listToString(enchants))); } - } - else if (args[0].equalsIgnoreCase("addall")) + } else if (args[0].equalsIgnoreCase("addall")) { Arrays.stream(Enchantment.values()).filter(enchantment -> enchantment.canEnchantItem(item)).forEach(ench -> { try { item.addEnchantment(ench, ench.getMaxLevel()); - } - catch (Exception ignored) + } catch (Exception ignored) { } }); msgNew("Added all possible enchantments for this item."); - } - else if (args[0].equalsIgnoreCase("reset")) + } else if (args[0].equalsIgnoreCase("reset")) { item.getEnchantments().keySet().forEach(item::removeEnchantment); msgNew("Removed all enchantments."); - } - else + } else { if (args.length < 2) { @@ -101,13 +96,11 @@ else if (args[0].equalsIgnoreCase("reset")) if (ConfigEntry.ALLOW_UNSAFE_ENCHANTMENTS.getBoolean()) { level = Integer.parseInt(args[2]); - } - else + } else { level = Math.max(1, Math.min(ench.getMaxLevel(), Integer.parseInt(args[2]))); } - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { msgNew("Invalid number: ", Placeholder.unparsed("number", args[2])); return true; @@ -116,15 +109,13 @@ else if (args[0].equalsIgnoreCase("reset")) if (!ConfigEntry.ALLOW_UNSAFE_ENCHANTMENTS.getBoolean()) { item.addEnchantment(ench, level); - } - else + } else { item.addUnsafeEnchantment(ench, level); } msgNew("Added enchantment: ", Placeholder.unparsed("enchantment", ench.getName())); - } - else if (args[0].equals("remove")) + } else if (args[0].equals("remove")) { item.removeEnchantment(ench); @@ -178,9 +169,8 @@ public List getTabCompleteOptions(CommandSender sender, Command command, Player player; if (sender instanceof Player) { - player = (Player)sender; - } - else + player = (Player) sender; + } else { return Collections.emptyList(); } @@ -196,26 +186,22 @@ public List getTabCompleteOptions(CommandSender sender, Command command, if (args.length == 1) { return Arrays.asList("list", "addall", "reset", "add", "remove"); - } - else if (args.length == 2) + } else if (args.length == 2) { if (args[0].equals("add")) { if (unsafe) { return getAllEnchantments(); - } - else + } else { return getAllEnchantments(item); } - } - else if (args[0].equals("remove")) + } else if (args[0].equals("remove")) { return getEnchantments(item); } - } - else if (args.length == 3 && args[0].equals("add")) + } else if (args.length == 3 && args[0].equals("add")) { Enchantment enchantment = Enchantment.getByName(args[1].toUpperCase()); if (enchantment != null) @@ -223,8 +209,7 @@ else if (args.length == 3 && args[0].equals("add")) if (!unsafe) { return IntStream.rangeClosed(1, enchantment.getMaxLevel()).mapToObj(String::valueOf).toList(); - } - else + } else { return Collections.singletonList("[level]"); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_end.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_end.java index 435648b94..596346bb7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_end.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_end.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java index ab33c8480..d5c52b54c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java @@ -1,8 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.Groups; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -12,6 +13,10 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + @CommandPermissions(permission = "entitywipe", source = SourceType.BOTH) @CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/ [name | -a]", aliases = "ew,rd") public class Command_entitywipe extends FreedomCommand @@ -51,14 +56,12 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (args[0].equals("-a")) { bypassBlacklist = true; - } - else + } else { try { type = EntityType.valueOf(args[0].toUpperCase()); - } - catch (Exception e) + } catch (Exception e) { msg(args[0] + " is not a valid entity type.", ChatColor.RED); return true; @@ -88,8 +91,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (type != null) { count = plugin.ew.wipeEntities(type); - } - else + } else { count = plugin.ew.wipeEntities(bypassBlacklist); } @@ -98,8 +100,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { msgNew(" removed.", Placeholder.unparsed("count", String.valueOf(count)), Placeholder.unparsed("name", type != null ? entityName : "entity")); - } - else + } else { msgNew(" s removed.", Placeholder.unparsed("count", String.valueOf(count)), Placeholder.unparsed("name", type != null ? entityName : "entitie")); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_expel.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_expel.java index aaeb84bd4..9f00a08cf 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_expel.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_expel.java @@ -1,7 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; @@ -11,6 +13,9 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.List; + @CommandPermissions(permission = "expel", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Push people away from you.", usage = "/ [radius] [strength]") public class Command_expel extends FreedomCommand @@ -27,8 +32,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0]))); - } - catch (NumberFormatException ignored) + } catch (NumberFormatException ignored) { } } @@ -38,8 +42,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1]))); - } - catch (NumberFormatException ignored) + } catch (NumberFormatException ignored) { } } @@ -62,8 +65,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { inRange = targetPosVec.distanceSquared(senderPos) < (radius * radius); - } - catch (IllegalArgumentException ignored) + } catch (IllegalArgumentException ignored) { } @@ -79,8 +81,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (pushedPlayers.isEmpty()) { msgNew("No players were pushed."); - } - else + } else { msgNew("Pushed players: ", Placeholder.unparsed("amount", String.valueOf(pushedPlayers.size())), diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java index 53dedc526..3114f2675 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explode.java @@ -1,7 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Collections; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import org.bukkit.command.Command; @@ -10,6 +12,9 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import java.util.Collections; +import java.util.List; + @CommandPermissions(permission = "explode", source = SourceType.BOTH) @CommandParameters(description = "Surprise someone.", usage = "/ ") public class Command_explode extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explosivearrows.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explosivearrows.java index 70af7344c..06b507777 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explosivearrows.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_explosivearrows.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.tag.Tag; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java index b553ac1c0..27fe1b54e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_findip.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java index bca7675bc..5aa4b46b4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fireball.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -24,8 +25,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { playerSender.getInventory().addItem(plugin.sh.getFireBall()); msgNew("You have been given the .", Placeholder.unparsed("item", ShopItem.FIRE_BALL.getName())); - } - else + } else { msgNew("You don't own the ! Purchase it from the shop.", Placeholder.unparsed("item", ShopItem.FIRE_BALL.getName())); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_flatlands.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_flatlands.java index 01eb27c7b..7e0c08ede 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_flatlands.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_flatlands.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_forcekill.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_forcekill.java index c8fafc38f..9e6f158f7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_forcekill.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_forcekill.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java index 79480e0e8..5a6e904d4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_freeze.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.freeze.FreezeData; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -23,14 +27,13 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { FUtil.adminAction(sender.getName(), "Unfreezing all players", false); msgNew("Players are now free to move."); - } - else + } else { FUtil.adminAction(sender.getName(), "Freezing all players", false); server.getOnlinePlayers().stream().filter(player -> !isAdmin(player)).forEach(player -> { FUtil.playerTitle(player, "You have been frozen.", "Please be patient and you will be unfrozen shortly."); - msgNew(player, "You have been globally frozen due to an OP breaking the rules, please wait and you will be unfrozen soon."); + msgNew(player, "You have been globally frozen due to an op breaking the rules, please wait and you will be unfrozen soon."); }); msgNew("Players are now frozen."); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java index ebed8bfff..d397db7bc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_fuckoff.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import net.kyori.adventure.text.Component; import org.bukkit.command.Command; @@ -24,8 +28,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (!args[0].equals("on")) { player.disableFuckoff(); - } - else + } else { double radius = 25.0; @@ -34,8 +37,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { radius = Math.max(5.0, Math.min(50, Double.parseDouble(args[1]))); - } - catch (NumberFormatException ex) + } catch (NumberFormatException ex) { } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java index 0a1997be4..268dd4a7d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gcmd.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang3.StringUtils; @@ -47,13 +51,11 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (server.dispatchCommand(player, outCommand)) { msg(Component.text("Command sent.", NamedTextColor.GREEN)); - } - else + } else { msg(Component.text("Unknown error sending command.", NamedTextColor.RED)); } - } - catch (Throwable ex) + } catch (Throwable ex) { msg(Component.text("Error sending command: " + ex.getMessage(), NamedTextColor.RED)); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glow.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glow.java index ed8d582d4..ab616124b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glow.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glow.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -19,8 +23,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (playerSender.getPotionEffect(PotionEffectType.GLOWING) != null) { playerSender.removePotionEffect(PotionEffectType.GLOWING); - } - else + } else { PotionEffect glow = new PotionEffect(PotionEffectType.GLOWING, 1000000, 1, false, false); playerSender.addPotionEffect(glow); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java index bd3b0ea55..f9e248d94 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_grapplinghook.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -14,7 +15,8 @@ public class Command_grapplinghook extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (plugin.sh == null) { + if (plugin.sh == null) + { msg("The shop is currently disabled.", ChatColor.RED); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gravity.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gravity.java index 8d380980b..082ce65b4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gravity.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gravity.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_health.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_health.java index d5009c285..080704b4c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_health.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_health.java @@ -1,8 +1,10 @@ package me.totalfreedom.totalfreedommod.command; -import java.text.DecimalFormat; -import java.util.concurrent.atomic.AtomicInteger; import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FLog; import org.apache.commons.lang.math.DoubleRange; import org.bukkit.ChatColor; @@ -12,6 +14,9 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; +import java.text.DecimalFormat; +import java.util.concurrent.atomic.AtomicInteger; + @CommandPermissions(permission = "health", source = SourceType.BOTH) @CommandParameters(description = "View server health, such as ticks-per-second, memory, etc.", usage = "/") public class Command_health extends FreedomCommand @@ -26,10 +31,10 @@ public boolean run(final CommandSender sender, Player playerSender, Command cmd, Runtime runtime = Runtime.getRuntime(); long usedMem = runtime.totalMemory() - runtime.freeMemory(); - msg("Reserved Memory: " + (double)runtime.totalMemory() / (double)BYTES_PER_MB + "mb"); - msg("Used Memory: " + new DecimalFormat("#").format((double)usedMem / (double)BYTES_PER_MB) - + "mb (" + new DecimalFormat("#").format(((double)usedMem / (double)runtime.totalMemory()) * 100.0) + "%)"); - msg("Max Memory: " + (double)runtime.maxMemory() / (double)BYTES_PER_MB + "mb"); + msg("Reserved Memory: " + (double) runtime.totalMemory() / (double) BYTES_PER_MB + "mb"); + msg("Used Memory: " + new DecimalFormat("#").format((double) usedMem / (double) BYTES_PER_MB) + + "mb (" + new DecimalFormat("#").format(((double) usedMem / (double) runtime.totalMemory()) * 100.0) + "%)"); + msg("Max Memory: " + (double) runtime.maxMemory() / (double) BYTES_PER_MB + "mb"); msg("Calculating ticks per second, please wait..."); new BukkitRunnable() @@ -58,8 +63,7 @@ public void run() msg("Ticks per second: " + (TPS_RANGE.containsDouble(ticksPerSecond) ? ChatColor.GREEN : ChatColor.RED) + ticksPerSecond); } }.runTask(plugin); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } @@ -103,7 +107,7 @@ public double stopTicking() long elapsed = System.currentTimeMillis() - startTime; int tickCount = ticks.get(); - return (double)tickCount / ((double)elapsed / 1000.0); + return (double) tickCount / ((double) elapsed / 1000.0); } } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java index 02d92bdef..9385d8b86 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inspect.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inspect.java index 01cede9b8..0f724db18 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inspect.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inspect.java @@ -1,17 +1,20 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.stream.IntStream; - +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.PlayerData; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.IntStream; + @CommandPermissions(permission = "inspect", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Block inspector tool for operators.", usage = "/ [history] [page]", aliases = "ins") public class Command_inspect extends FreedomCommand @@ -43,8 +46,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { pageIndex = Integer.parseInt(args[1]); - } - catch (NumberFormatException e) + } catch (NumberFormatException e) { msgNew("Invalid number."); return true; @@ -53,12 +55,11 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin int godDammit = pageIndex; Optional.ofNullable(plugin.cpb.getHistoryForPlayer(playerSender)).ifPresentOrElse(page -> - plugin.cpb.showPageToPlayer(playerSender, page, godDammit), + plugin.cpb.showPageToPlayer(playerSender, page, godDammit), () -> msgNew("You haven't inspected anything yet!")); return true; - } - else + } else { return false; } @@ -70,14 +71,12 @@ public List getTabCompleteOptions(CommandSender sender, Command command, if (args.length == 1) { return Collections.singletonList("history"); - } - else if (args.length == 2 && args[0].equalsIgnoreCase("history") && plugin.cpb.isEnabled() + } else if (args.length == 2 && args[0].equalsIgnoreCase("history") && plugin.cpb.isEnabled() && sender instanceof Player player && plugin.cpb.hasHistory(player)) { return IntStream.rangeClosed(1, plugin.cpb.getHistoryForPlayer(player).getPageCount()).limit(50) .mapToObj(String::valueOf).toList(); - } - else + } else { return Collections.emptyList(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java index d8e7cb487..7290ad4ba 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java @@ -1,8 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; @@ -10,6 +11,10 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + @CommandPermissions(permission = "invis", source = SourceType.BOTH) @CommandParameters(description = "Shows (optionally clears) invisible players", usage = "/ [clear]") public class Command_invis extends FreedomCommand @@ -27,14 +32,12 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (!plugin.al.isAdmin(sender)) { return noPerms(); - } - else + } else { FUtil.adminAction(sender.getName(), "Clearing all invisibility potion effects from all players", true); clear = true; } - } - else + } else { return false; } @@ -65,8 +68,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (clear) { msg("Cleared " + clears + " players"); - } - else + } else { msg("Invisible players (" + players.size() + "): " + StringUtils.join(players, ", ")); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java index 0762a62a5..c7cd3dcaf 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.ChatColor; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java index fdb3e1727..2caf8c46b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.fun.Jumppads; import org.bukkit.ChatColor; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java index 38dc826c3..766e75726 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java @@ -1,8 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; -import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.ArrayUtils; @@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("kick") @CommandPermissions(permission = "kick", source = SourceType.BOTH) @CommandParameters(description = "Kick the specified player.", usage = "/ [reason] [-q]") public class Command_kick extends FreedomCommand @@ -43,8 +44,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); } - } - else if (args.length > 1) + } else if (args.length > 1) { reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); } @@ -63,13 +63,11 @@ else if (args.length > 1) if (reason != null) { FUtil.adminAction(sender.getName(), "Kicking " + player.getName() + " - Reason: " + reason, true); - } - else + } else { FUtil.adminAction(sender.getName(), "Kicking " + player.getName(), true); } - } - else + } else { msgNew("Kicked quietly.", Placeholder.unparsed("player", player.getName())); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java index 05db1b2af..c414cdf0d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kicknoob.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_landmine.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_landmine.java index dadc9f2e8..83ae85d5b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_landmine.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_landmine.java @@ -1,6 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.Iterator; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.fun.Landminer.Landmine; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -11,6 +14,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.Iterator; + @CommandPermissions(permission = "landmine", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Set a landmine trap.", usage = "/") public class Command_landmine extends FreedomCommand @@ -48,8 +53,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin try { radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0]))); - } - catch (NumberFormatException ignored) + } catch (NumberFormatException ignored) { } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java index 65d3f686a..f0e0960a8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lightningrod.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java index 7c37f8d82..bafdbd546 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_linkdiscord.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import org.bukkit.ChatColor; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java index 54bbf74ab..aff8f87eb 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 254bbbc39..1ad278373 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -1,19 +1,18 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import net.md_5.bungee.api.ChatColor; -import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.List; +@Intercept("list") @CommandPermissions(permission = "list", source = SourceType.BOTH) @CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -v]", aliases = "who,lsit") public class Command_list extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java index 3bfae9c99..458b5d0ed 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_localspawn.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java index 266a6dea2..5ab1ba64a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_lockup.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java index 3f35590e9..123845f55 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java index 5e5e4ef8a..c2a5f16b3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java index 23cb2bf8d..7858b3e69 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderinfo.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java index c54972bb3..d6d8e65a8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.world.WorldTime; import me.totalfreedom.totalfreedommod.world.WorldWeather; import org.bukkit.World; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java index 455c339fb..efed909ed 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java @@ -1,5 +1,10 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; @@ -120,11 +125,9 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { FUtil.adminAction(sender.getName(), "Adding " + data.getName() + " to the Master Builder list", true); data.setMasterBuilder(true); + TotalFreedomMod.getPlugin().getHierarchy() + .addUserToGroup(TotalFreedomMod.getPlugin().getHierarchy().groups().getMasterBuilder(), player); plugin.pl.save(data); - if (player != null) - { - plugin.rm.updateDisplay(player); - } } else { msg("That player is already on the Master Builder list."); @@ -144,21 +147,20 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin } Player player = getPlayer(args[1]); - PlayerData data = player != null ? plugin.pl.getData(player) : plugin.pl.getData(args[1]); + PlayerData data = plugin.pl.getData(args[1]); - if (data == null || !data.isMasterBuilder()) + if (player == null || data == null || !data.isMasterBuilder()) { - msg("Master Builder not found: " + args[1]); + msgNew("Master Builder not found: ", arg(args[1])); return true; } FUtil.adminAction(sender.getName(), "Removing " + data.getName() + " from the Master Builder list", true); + TotalFreedomMod.getPlugin().getHierarchy() + .dropUser(TotalFreedomMod.getPlugin().getHierarchy().builder(), player); data.setMasterBuilder(false); plugin.pl.save(data); - if (player != null) - { - plugin.rm.updateDisplay(player); - } + return true; } default: diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java index 980d0e31a..e9b669634 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_moblimiter.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.GameRuleHandler; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.ChatColor; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java index 0f64ecc24..eb2b4ee0b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.ChatColor; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java index 42510b377..44221e992 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mp44.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.ChatColor; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java index 0bbffaae8..54492a5ae 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -12,6 +13,7 @@ import java.util.*; +@Intercept("mute") @CommandPermissions(permission = "mute", source = SourceType.BOTH) @CommandParameters(description = "Mutes a player with brute force.", usage = "/ <[-q] [reason] | list | purge | all>", aliases = "stfu") public class Command_mute extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java index 449af1a1f..306994c9c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java @@ -1,12 +1,15 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FConverter; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; @@ -168,8 +171,14 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin msgNew("Set admin chat format to \"\"", Placeholder.unparsed("format", format)); msgNew("Example:"); msgNew(format, Placeholder.unparsed("name", "ExampleAdmin"), - Placeholder.unparsed("rank", GroupProvider.ADMIN.getGroup().getAbbr().toString()), - TagResolver.resolver("rankcolor", Tag.styling(styler -> styler.color(GroupProvider.ADMIN.getGroup().getColor()))), + Placeholder.unparsed("rank", TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin().getAbbr().toString()), + TagResolver.resolver("rankcolor", + Tag.styling(styler -> + styler.color(TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .getAdmin() + .getColor()))), Placeholder.unparsed("message", "The quick brown fox jumped over the lazy dog.")); return true; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myinfo.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myinfo.java index b40f4d1a1..ecd3546d2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myinfo.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myinfo.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nether.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nether.java index 0fc4ff130..c072a9a9e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nether.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nether.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickclean.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickclean.java index 1b06d97a8..de30205ab 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickclean.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickclean.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java index 6d3576918..05d0e7a13 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -25,7 +29,8 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return true; } - if (args[0].isEmpty()) { + if (args[0].isEmpty()) + { return false; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java index ed0431c5d..17e67bb0a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_notes.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java index 46737cf30..7d251e43d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java @@ -1,19 +1,17 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; -import me.totalfreedom.totalfreedommod.rank.HierarchyProvider; -import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.luckperms.api.model.user.User; +import net.luckperms.api.track.PromotionResult; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.concurrent.atomic.AtomicBoolean; - +@Intercept("op") @CommandPermissions(permission = "op", source = SourceType.BOTH, cooldown = 5) -@CommandParameters(description = "OP a player", usage = "/ ") +@CommandParameters(description = "op a player", usage = "/ ") public class Command_op extends FreedomCommand { @@ -39,23 +37,22 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return true; } - AtomicBoolean atomicBoolean = new AtomicBoolean(silent); - User user = GroupProvider.getUser(player); - HierarchyProvider.OP.getHierarchy().promoteUser(user).whenComplete((ignored, throwable) -> + boolean b = silent; + PromotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .promoteUser(TotalFreedomMod.getPlugin().getHierarchy().op(), player); + + if (!result.wasSuccessful()) + { + msgNew(" is already op!", player(player)); + return true; + } + + msg(player, YOU_ARE_OP); + + if (!b) { - if (throwable != null) - { - FLog.severe("Failed to promote user " + player.getName()); - return; - } - - msg(player, YOU_ARE_OP); - plugin.rm.updateDisplay(player); - if (!atomicBoolean.get()) - { - FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false); - } - }); + FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false); + } return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java index 1b1e8744a..4bc6adc81 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opall.java @@ -1,16 +1,18 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; -import me.totalfreedom.totalfreedommod.rank.HierarchyProvider; -import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.luckperms.api.model.user.User; +import net.luckperms.api.track.PromotionResult; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(permission = "op.all", source = SourceType.BOTH, cooldown = 30) -@CommandParameters(description = "OP everyone on the server.", usage = "/") +@CommandParameters(description = "op everyone on the server.", usage = "/") public class Command_opall extends FreedomCommand { @Override @@ -20,18 +22,16 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin server.getOnlinePlayers().forEach(player -> { - User user = GroupProvider.getUser(player); - HierarchyProvider.OP.getHierarchy().promoteUser(user).whenComplete((ignored, throwable) -> + PromotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .promoteUser(TotalFreedomMod.getPlugin().getHierarchy().op(), player); + + if (!result.wasSuccessful()) { - if (throwable != null) - { - FLog.severe("Failed to promote " + player.getName()); - return; - } + msgNew("Player is already op!", player(player)); + return; + } - msg(player, YOU_ARE_OP); - plugin.rm.updateDisplay(player); - }); + msg(player, YOU_ARE_OP); }); return true; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java index b56f324e8..2b9450192 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_opme.java @@ -1,10 +1,12 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; -import me.totalfreedom.totalfreedommod.rank.HierarchyProvider; -import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.luckperms.api.model.user.User; +import net.luckperms.api.track.PromotionResult; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,16 +20,17 @@ public class Command_opme extends FreedomCommand public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { FUtil.adminAction(sender.getName(), "Opping " + sender.getName(), false); - User user = GroupProvider.getUser(playerSender); - HierarchyProvider.OP.getHierarchy().promoteUser(user).whenComplete((result, error) -> { - if (error != null) { - FLog.severe("Error while promoting " + playerSender.getName() + " to OP: " + error.getMessage()); - return; - } + PromotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .promoteUser(TotalFreedomMod.getPlugin().getHierarchy().op(), playerSender); + + if (!result.wasSuccessful()) + { + msgNew("You are already op!"); + return true; + } + + msg(YOU_ARE_OP); - msg(YOU_ARE_OP); - plugin.rm.updateDisplay(playerSender); - }); return true; } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_orbit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_orbit.java index cd63bfe11..224a9cee0 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_orbit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_orbit.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java index 2bfe28f33..4d768730e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plotworld.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; +import me.totalfreedom.totalfreedommod.command.handling.*; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java index 43d685fbf..a2cd7ee86 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java index ad9adaf5d..d48acd080 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -13,6 +14,7 @@ import java.util.Collections; import java.util.List; +@Intercept("potion") @CommandPermissions(permission = "potion", source = SourceType.BOTH) @CommandParameters( description = "Manipulate your potion effects. Duration is measured in server ticks (~20 ticks per second).", diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java index f6f5d759d..636538a3f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java index f73fe9fb0..6402dfeda 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_purgeall.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Bukkit; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rank.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rank.java index b5fc7b4a3..5f13fd909 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rank.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rank.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.rank.DisplayableGroup; import org.bukkit.ChatColor; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java index 48867633d..b6256a80a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rawsay.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java index 6eff57d28..311a984f8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -8,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("report") @CommandPermissions(permission = "report", source = SourceType.ONLY_IN_GAME, blockHostConsole = true) @CommandParameters(description = "Report a player for all admins to see.", usage = "/ ") public class Command_report extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java index 46f55f633..d9f1ead83 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java index 6d82e39e0..c602e8da9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rideablepearl.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java index 2be0fef54..16a81931b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ro.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.Groups; import net.coreprotect.CoreProtectAPI; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rock.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rock.java index 6d78624c6..f307c9f24 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rock.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_rock.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java index 23b630b9a..49400fd98 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java @@ -1,18 +1,21 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.DisplayableGroup; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; -import me.totalfreedom.totalfreedommod.rank.HierarchyProvider; -import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.PermissibleCompletion; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import net.luckperms.api.model.user.User; +import net.luckperms.api.model.group.Group; +import net.luckperms.api.track.DemotionResult; +import net.luckperms.api.track.PromotionResult; import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,7 +26,8 @@ import java.util.List; @CommandPermissions(permission = "saconfig", source = SourceType.BOTH) -@CommandParameters(description = "List, add, remove, or set the rank of admins, clean or reload the admin list, or view admin information.", usage = "/ | >", aliases = "slconfig") +@CommandParameters(description = "List, add, remove, or set the rank of admins, clean or reload the admin list, or view admin information.", + usage = "/ | >", aliases = "slconfig") public class Command_saconfig extends FreedomCommand { @@ -73,73 +77,70 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin Player player = getPlayer(args[1]); - FUtil.adminAction(sender.getName(), "Promoting " + player.getName() + " to the next rank", true); - HierarchyProvider.ADMIN.getHierarchy() - .promoteUser(GroupProvider.getUser(player)) - .whenComplete((result, ex) -> { - if (ex != null) { - FLog.severe("Failed to promote " - + player.getName() - + " to the next rank"); - return; - } - - result.getGroupTo() - .ifPresent(group -> - msgNew("Admin has been promoted to ", - Placeholder.unparsed("player", player.getName()), - Placeholder.unparsed("rank", group))); - }); - } - case "setrank" -> - { - checkConsole(); - checkPermission("tfm.saconfig.setrank"); - - if (args.length < 3) - { - return false; - } - - DisplayableGroup rank = GroupProvider.fromArgument(args[2]).getGroup(); - if (rank == null) - { - msgNew("Unknown rank: ", Placeholder.unparsed("rank", args[2])); - return true; - } - - - if (!rank.isAtLeast(GroupProvider.ADMIN.getGroup())) - { - msgNew("Rank must be Admin or higher."); - return true; - } - - Admin admin = plugin.al.getEntryByName(args[1]); - if (admin == null) + if (player == null) { - msgNew("Unknown admin: ", Placeholder.unparsed("player", args[1])); + msgNew("Player not found."); return true; } - FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true); - - admin.setRank(rank); - plugin.al.save(admin); + PromotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .promoteUser(TotalFreedomMod.getPlugin().getHierarchy().admin(), player); - Player player = getPlayer(admin.getName()); - if (player != null) + if (!result.wasSuccessful() || result.getGroupTo().isEmpty()) { - plugin.rm.updateDisplay(player); - } - - if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) + msgNew("Failed to promote to the next rank.", player(player)); + } else { - plugin.dc.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID()); + result.getGroupTo().ifPresentOrElse(group -> + { + Admin admin = plugin.al.getAdmin(player); + + if (admin == null) + { + admin = new Admin(player); + plugin.al.addAdmin(admin); + } + + Group actual = TotalFreedomMod.getPlugin().getHierarchy().getGroup(group); + DisplayableGroup rank = TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .fromLuckPerms(actual); + + if (rank == null) + { + msgNew("Unknown rank: ", Placeholder.unparsed("rank", args[2])); + return; + } + + admin.setRank(rank); + admin.addIp(FUtil.getIp(player)); + admin.setActive(true); + admin.setLastLogin(new Date()); + + plugin.al.save(admin); + plugin.al.updateTables(); + + if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) + { + plugin.dc.syncRoles(admin, plugin.pl.getData(player).getDiscordID()); + } + + msgNew("Set 's rank to .", Placeholder.unparsed("admin", admin.getName()), Placeholder.component("rank", rank.getName())); + + final FPlayer fPlayer = plugin.pl.getPlayer(player); + if (fPlayer.getFreezeData().isFrozen()) + { + fPlayer.getFreezeData().setFrozen(false); + msgNew(player, "You have been unfrozen."); + } + + msgNew("Admin has been promoted to ", + player(player), + Placeholder.unparsed("rank", group)); + }, () -> msgNew("Failed to promote to the next rank.", player(player))); } - msgNew("Set 's rank to .", Placeholder.unparsed("admin", admin.getName()), Placeholder.component("rank", rank.getName())); - return true; } case "info" -> @@ -164,7 +165,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (admin == null) { - msgNew("Unknown admin: ", Placeholder.unparsed("player", args[1])); + msgNew("Unknown admin: ", arg(args[1])); return true; } else { @@ -173,76 +174,79 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return true; } - case "add" -> + case "demote" -> { + checkConsole(); + checkPermission("tfm.saconfig.demote"); + if (args.length < 2) { return false; } - checkConsole(); - checkPermission("tfm.saconfig.add"); - - // Player already admin? - final Player player = getPlayer(args[1]); + Player player = getPlayer(args[1]); if (player == null) { - msg(PLAYER_NOT_FOUND); + msgNew("Player not found."); return true; } - if (plugin.al.isAdmin(player)) + DemotionResult result = TotalFreedomMod.getPlugin().getHierarchy() + .demoteUser(TotalFreedomMod.getPlugin().getHierarchy().admin(), player); + + if (!result.wasSuccessful() || result.getGroupTo().isEmpty()) { - msgNew("That player is already an admin."); + msgNew("Failed to demote to the next rank.", player(player)); return true; } - // Find the old admin entry - Admin admin = null; - for (Admin loopAdmin : plugin.al.getAllAdmins()) + result.getGroupTo().ifPresentOrElse(group -> { - if (loopAdmin.getUuid().equals(player.getUniqueId())) + Admin admin = plugin.al.getAdmin(player); + + if (admin == null) { - admin = loopAdmin; - break; + admin = new Admin(player); + plugin.al.addAdmin(admin); } - } - if (admin == null) // New admin - { - FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true); - admin = new Admin(player); - User user = GroupProvider.getUser(player); - HierarchyProvider.ADMIN.getHierarchy().promoteUser(user); - - plugin.al.addAdmin(admin); - plugin.rm.updateDisplay(player); - } else // Existing admin - { - User user = GroupProvider.getUser(player); - HierarchyProvider.ADMIN.getHierarchy().promoteUser(user); - FUtil.adminAction(sender.getName(), "Re-adding " + player.getName() + " to the admin list", true); - admin.addIp(FUtil.getIp(player)); - admin.setActive(true); + Group actual = TotalFreedomMod.getPlugin().getHierarchy().getGroup(group); + DisplayableGroup rank = TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .fromLuckPerms(actual); + + if (rank == null) + { + msgNew("Unknown rank: ", Placeholder.unparsed("rank", args[2])); + return; + } + + admin.setRank(rank); admin.setLastLogin(new Date()); plugin.al.save(admin); plugin.al.updateTables(); - plugin.rm.updateDisplay(player); - if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) + if (plugin.dc != null && plugin.dc.isEnabled() && Boolean.TRUE.equals(ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())) { plugin.dc.syncRoles(admin, plugin.pl.getData(player).getDiscordID()); } - } - final FPlayer fPlayer = plugin.pl.getPlayer(player); - if (fPlayer.getFreezeData().isFrozen()) - { - fPlayer.getFreezeData().setFrozen(false); - msgNew(player, "You have been unfrozen."); - } + msgNew("Set 's rank to .", Placeholder.unparsed("admin", admin.getName()), Placeholder.component("rank", rank.getName())); + + final FPlayer fPlayer = plugin.pl.getPlayer(player); + if (fPlayer.getFreezeData().isFrozen()) + { + fPlayer.getFreezeData().setFrozen(false); + msgNew(player, "You have been unfrozen."); + } + + msgNew("Admin has been demoted to ", + Placeholder.unparsed("player", player.getName()), + Placeholder.unparsed("rank", group)); + }, () -> msgNew("Failed to demote to the next rank.", Placeholder.unparsed("player", player.getName()))); return true; } @@ -260,8 +264,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin Admin admin = plugin.al.getAdmin(player); plugin.al.removeAdmin(admin); - User user = GroupProvider.getUser(player); - HierarchyProvider.ADMIN.getHierarchy().dropUserFromAll(user); + TotalFreedomMod.getPlugin().getHierarchy().dropUser(TotalFreedomMod.getPlugin().getHierarchy().admin(), player); FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true); admin.setActive(false); @@ -269,11 +272,6 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin plugin.al.save(admin); plugin.al.updateTables(); - if (player != null) - { - plugin.rm.updateDisplay(player); - } - if (plugin.dc != null && plugin.dc.isEnabled() && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) { plugin.dc.syncRoles(admin, plugin.pl.getData(admin.getName()) @@ -287,7 +285,6 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return false; } } - return false; } @Override @@ -297,19 +294,25 @@ public List getTabCompleteOptions(CommandSender sender, Command command, { return argumentCompletions(args[0], PermissibleCompletion.of("tfm.saconfig.info", "info"), - PermissibleCompletion.of("tfm.saconfig.add", "add"), + PermissibleCompletion.of("tfm.saconfig.demote", "demote"), PermissibleCompletion.of("tfm.saconfig.remove", "remove"), PermissibleCompletion.of("tfm.saconfig.reload", "reload"), PermissibleCompletion.of("tfm.saconfig.clean", "clean"), - PermissibleCompletion.of("tfm.saconfig.setrank", "setrank")); + PermissibleCompletion.of("tfm.saconfig.promote", "promote")); } - if (args.length == 2 && (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info"))) + if (args.length == 2 && (args[0].equals("promote") + || args[0].equals("demote") + || args[0].equals("remove") + || args[0].equals("setrank") + || args[0].equals("info"))) { return playerCompletions(args[1]); } - if (args.length == 3 && args[0].equals("setrank") && sender.hasPermission("tfm.saconfig.setrank")) + if (args.length == 3 + && args[0].equals("setrank") + && sender.hasPermission("tfm.saconfig.setrank")) { - return Arrays.asList("ADMIN", "SENIOR_ADMIN"); + return Arrays.asList("admin", "seniorAdmin"); } return Collections.emptyList(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java index c11db5487..3d1285e48 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; @@ -7,6 +8,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("say") @CommandPermissions(permission = "say", source = SourceType.BOTH) @CommandParameters(description = "Broadcasts the given message as the server, includes sender name.", usage = "/ ") public class Command_say extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java index fe31b0ad7..402333f73 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Particle; import org.bukkit.Sound; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_seed.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_seed.java index 83f52f156..03951ac3b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_seed.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_seed.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -13,6 +14,7 @@ import java.util.List; +@Intercept("seed") @CommandPermissions(permission = "seed", source = SourceType.BOTH) @CommandParameters(description = "Get the seed of the world you are currently in.", usage = "/seed [world]") public class Command_seed extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_serverstats.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_serverstats.java index a7c0172e2..50c0adb52 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_serverstats.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_serverstats.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.ChatColor; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java index 9e092c3dd..eb91b6467 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setcompass.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java index 39f3bb416..08c51d99f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setlimit.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java index 49e74903b..f8c843386 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setplayerlimit.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Bukkit; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setspawnworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setspawnworld.java index 9921cc62c..2e84aed46 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setspawnworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_setspawnworld.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Location; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java index 93621dc56..8b5c389a5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java index 7aed7271c..5c25bb44c 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -13,6 +14,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("smite") @CommandPermissions(permission = "smite", source = SourceType.BOTH) @CommandParameters(description = "Someone being a little bitch? Smite them down...", usage = "/ [reason] [-ci | -q]") public class Command_smite extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java index 46bad22f8..87d84be4b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -13,6 +14,7 @@ import java.util.Arrays; import java.util.List; +@Intercept("spawnmob") @CommandPermissions(permission = "spawnmob", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Spawns the specified entity.", usage = "/ [amount]", aliases = "spawnentity") public class Command_spawnmob extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java index fccea416f..725e57608 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java index 9e539afe1..4c0f171fa 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stackingpotato.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java index 1be166560..de1966cb4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stop.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; @@ -11,6 +12,7 @@ import java.util.HashMap; import java.util.Map; +@Intercept("stop") @CommandPermissions(permission = "stop", source = SourceType.BOTH) @CommandParameters(description = "Kicks everyone and stops the server.", usage = "/ [reason]") public class Command_stop extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stopsound.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stopsound.java index 85df5c7b4..8799c2737 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stopsound.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stopsound.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Sound; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index 4b4956368..f06871ff8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; @@ -42,7 +46,8 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin case "list": { msgNew("Tags for all online players:"); - server.getOnlinePlayers().stream().filter(player -> !(plugin.al.isVanished(player.getUniqueId()) && !isAdmin(sender)) && plugin.pl.getPlayer(player).getTag() != null).forEach(player -> { + server.getOnlinePlayers().stream().filter(player -> !(plugin.al.isVanished(player.getUniqueId()) && !isAdmin(sender)) && plugin.pl.getPlayer(player).getTag() != null).forEach(player -> + { msgNew(": ", Placeholder.unparsed("player", player.getName()), Placeholder.component("tag", plugin.pl.getPlayer(player).getTag())); }); @@ -79,8 +84,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (senderIsConsole) { msgNew("\"/tag off\" can't be used from the console."); - } - else + } else { plugin.pl.getPlayer(playerSender).setTag(null); @@ -100,8 +104,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin return false; } } - } - else if (args.length >= 2) + } else if (args.length >= 2) { switch (args[0].toLowerCase()) { @@ -160,13 +163,11 @@ else if (args.length >= 2) FLog.debug("FUCK YOU " + steamrolled); msgNew("That tag is too long (Max is characters).", Placeholder.unparsed("max", String.valueOf(tagLimit))); return true; - } - else if (!plugin.al.isAdmin(sender) && ConfigEntry.FORBIDDEN_WORDS.getStringList().stream().anyMatch(word -> steamrolled.toLowerCase().contains(word))) + } else if (!plugin.al.isAdmin(sender) && ConfigEntry.FORBIDDEN_WORDS.getStringList().stream().anyMatch(word -> steamrolled.toLowerCase().contains(word))) { msgNew("That tag contains a forbidden word."); return true; - } - else + } else { plugin.pl.getPlayer(playerSender).setTag(tag); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java index aac022a02..b877395ab 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.User; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -19,6 +20,7 @@ import java.util.Date; import java.util.Objects; +@Intercept("tempban") @CommandPermissions(permission = "tempban", source = SourceType.BOTH) @CommandParameters(description = "Temporarily ban someone.", usage = "/ [-q] [duration] [reason]", aliases = "tban,noob") public class Command_tempban extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index 02767f3a5..a176ba368 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -2,6 +2,10 @@ import me.totalfreedom.totalfreedommod.GameRuleHandler; import me.totalfreedom.totalfreedommod.LoginProcess; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java index bd3387e67..496e7e357 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggleclownfish.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.FPlayer; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java index b07452cd3..17ddf4f43 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglediscord.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglepickup.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglepickup.java index e4d760f61..a641e929b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglepickup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_togglepickup.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java index 3e9abd582..38e139fd7 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java index c15cba5d4..af9f23878 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java index 34b41a482..6153c7a96 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tprandom.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Location; @@ -8,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("tprandom") @CommandPermissions(permission = "tprandom", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Go to a random location in the current world you are in", usage = "/", aliases = "tpr,rtp") public class Command_tprandom extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java index 41ab266f7..456be2863 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.api.ShopItem; +import me.totalfreedom.totalfreedommod.command.handling.*; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java index 62c523a4c..d2f4cccf0 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import com.earth2me.essentials.User; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -8,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("unban") @CommandPermissions(permission = "unban", source = SourceType.BOTH) @CommandParameters(description = "Unbans the specified player.", usage = "/ [-r]") public class Command_unban extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java index 16dc3bef6..6dd7d7786 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanip.java @@ -1,13 +1,14 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -// TODO: Merge with /unban. +@Intercept("unbanip") @CommandPermissions(permission = "unbanip", source = SourceType.BOTH) @CommandParameters(description = "Unbans the specified IP.", usage = "/ [-q]") public class Command_unbanip extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java index 1f52f295f..bc167eb9d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unbanname.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java index ddda05778..5e53cb2c1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unblockcmd.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; @@ -32,8 +36,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin fPlayer.setCommandsBlocked(false); FUtil.adminAction(sender.getName(), "Unblocking all commands for " + player.getName(), true); msgNew("Unblocked commands for ."); - } - else + } else { msgNew("That player's commands aren't blocked."); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java index a22e039c2..c5e3413cd 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_uncage.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; @@ -32,8 +36,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { FUtil.adminAction(sender.getName(), "Uncaging " + player.getName(), true); fPlayer.getCageData().setCaged(false); - } - else + } else { msgNew("That player is not caged!"); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java index 87739ee37..80cd86af3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_undisguiseall.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java index 4549f6146..4fbab36a3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unlinkdiscord.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.Command; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java index 5773c1679..e826d5444 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unmute.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -8,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("unmute") @CommandPermissions(permission = "unmute", source = SourceType.BOTH) @CommandParameters(description = "Unmutes a player", usage = "/ [-q] ") public class Command_unmute extends FreedomCommand @@ -50,14 +52,12 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin { msgNew("Quietly unmuted .", Placeholder.unparsed("player", player.getName())); return true; - } - else + } else { FUtil.adminAction(sender.getName(), "Unmuting " + player.getName(), true); msgNew("Unmuted .", Placeholder.unparsed("player", player.getName())); } - } - else + } else { msgNew("That player is not muted."); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java index 742f42461..41d0695c2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java @@ -1,9 +1,9 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.admin.AdminList; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Displayable; -import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -13,6 +13,7 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +@Intercept("vanish") @CommandPermissions(permission = "vanish", source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Vanish/unvanish yourself.", usage = "/ [-s[ilent]]", aliases = "v") public class Command_vanish extends FreedomCommand @@ -30,15 +31,15 @@ public boolean run(final CommandSender sender, final Player playerSender, final if (silent) { msgNew("Silently unvanished."); - } - else + } else { msgNew("You have unvanished."); server.broadcast(plugin.rm.craftLoginMessage(playerSender, null)); server.broadcast(Component.translatable("multiplayer.player.joined", Component.text(playerSender.getName())) .color(NamedTextColor.YELLOW)); - if (plugin.dc != null) { + if (plugin.dc != null) + { plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**", true); } } @@ -58,8 +59,7 @@ public boolean run(final CommandSender sender, final Player playerSender, final plugin.esb.setVanished(playerSender.getName(), false); playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16)); AdminList.vanished.remove(playerSender.getUniqueId()); - } - else + } else { new BukkitRunnable() { @@ -69,8 +69,7 @@ public void run() if (plugin.al.isVanished(playerSender.getUniqueId())) { sender.sendActionBar(Component.text("You are hidden from other players.").color(NamedTextColor.GOLD)); - } - else + } else { cancel(); } @@ -80,13 +79,13 @@ public void run() if (silent) { msgNew("Silently vanished."); - } - else + } else { msgNew("You have vanished."); server.broadcast(Component.translatable("multiplayer.player.left", Component.text(playerSender.getName())) .color(NamedTextColor.YELLOW)); - if (plugin.dc != null) { + if (plugin.dc != null) + { plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**", true); } } @@ -94,7 +93,7 @@ public void run() plugin.cm.messageAllAdmins(" has vanished and is now only visible to admins.", Placeholder.unparsed("player", sender.getName())); server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player -> - player.hidePlayer(plugin,playerSender)); + player.hidePlayer(plugin, playerSender)); plugin.esb.setVanished(playerSender.getName(), true); AdminList.vanished.add(playerSender.getUniqueId()); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java index a317ab414..ccf63b1e0 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vote.java @@ -1,6 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.List; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; @@ -8,6 +11,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.List; + @CommandPermissions(permission = "vote", source = SourceType.BOTH) @CommandParameters(description = "Information on how to vote", usage = "/") public class Command_vote extends FreedomCommand @@ -20,8 +25,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (voteInfo.isEmpty()) { msgNew("The voting information section of the config.yml file has not been configured."); - } - else + } else { msg(FUtil.colorizeAsComponent(StringUtils.join(voteInfo, "\n"))); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java index 6b82e64d4..0a262a9b6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -10,6 +11,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@Intercept("warn") @CommandPermissions(permission = "warn", source = SourceType.BOTH) @CommandParameters(description = "Warns the specified player.", usage = "/ [-q] ") public class Command_warn extends FreedomCommand @@ -62,8 +64,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin if (quiet) { msgNew("You have successfully warned quietly.", Placeholder.unparsed("player", player.getName())); - } - else + } else { plugin.cm.messageAllAdmins(" - Warning: - Reason: ", Placeholder.unparsed("sender", sender.getName()), diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java index d09de5ef1..34905341b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.*; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.OfflinePlayer; @@ -9,6 +10,7 @@ import java.util.*; +@Intercept("whitelist") @CommandPermissions(permission = "whitelist", source = SourceType.BOTH) @CommandParameters(description = "Manage the whitelist.", usage = "/ | remove | addall | purge>") public class Command_whitelist extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java index 5587af147..999223f28 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; import org.bukkit.Material; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java index 829ecdf67..b4df40102 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java @@ -1,9 +1,9 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import me.totalfreedom.totalfreedommod.command.handling.CommandParameters; +import me.totalfreedom.totalfreedommod.command.handling.CommandPermissions; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.SourceType; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.apache.commons.lang.StringUtils; @@ -11,6 +11,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @CommandPermissions(permission = "wildcard", source = SourceType.BOTH, blockHostConsole = true) @CommandParameters(description = "Run any command on all users, username placeholder = ?.", usage = "/ [fluff] ? [fluff] ?") public class Command_wildcard extends FreedomCommand diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandDependencies.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandDependencies.java similarity index 76% rename from commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandDependencies.java rename to commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandDependencies.java index 349759e60..508d2f57f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandDependencies.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandDependencies.java @@ -1,4 +1,4 @@ -package me.totalfreedom.totalfreedommod.command; +package me.totalfreedom.totalfreedommod.command.handling; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandFailException.java similarity index 78% rename from commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java rename to commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandFailException.java index 9792fd484..673f15427 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandFailException.java @@ -1,4 +1,4 @@ -package me.totalfreedom.totalfreedommod.command; +package me.totalfreedom.totalfreedommod.command.handling; public class CommandFailException extends RuntimeException { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandLoader.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandLoader.java new file mode 100644 index 000000000..4979cfd67 --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandLoader.java @@ -0,0 +1,145 @@ +package me.totalfreedom.totalfreedommod.command.handling; + +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.Bukkit; +import org.reflections.Reflections; + +import java.util.*; +import java.util.concurrent.CompletableFuture; + +public class CommandLoader extends FreedomService +{ + private final List commands; + + public CommandLoader() + { + commands = new ArrayList<>(); + } + + @Override + public void onStart() + { + } + + @Override + public void onStop() + { + } + + public void add(FreedomCommand command) + { + commands.add(command); + command.register(); + } + + public FreedomCommand getByName(String name) + { + for (FreedomCommand command : commands) + { + if (name.equals(command.getName())) + { + return command; + } + } + return null; + } + + public boolean isAlias(String alias) + { + for (FreedomCommand command : commands) + { + if (Arrays.asList(command.getAliases().split(",")).contains(alias)) + { + return true; + } + } + return false; + } + + public void loadCommands() + { + Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command"); + + Interceptor interceptor = new Interceptor(plugin); + + Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class); + + Set> postLoadCommands = new HashSet<>(); + + for (Class commandClass : commandClasses) + { + if (commandClass.isAnnotationPresent(CommandDependencies.class)) + { + postLoadCommands.add(commandClass); + } + + if (commandClass.isAnnotationPresent(Intercept.class)) + { + Intercept intercept = commandClass.getAnnotation(Intercept.class); + interceptor.intercept(intercept.value()); + postLoadCommands.add(commandClass); + } + + addClass(commandClass); + } + + doPostLoading(interceptor, postLoadCommands); + + FLog.info("Loaded " + commands.size() + " commands"); + } + + private void doPostLoading(Interceptor interceptor, Set> postLoadCommands) + { + Bukkit.getScheduler().runTaskLater(plugin, () -> + CompletableFuture.runAsync(interceptor::setOverrides) + .whenComplete((v, th) -> + { + if (th != null) + { + FLog.severe("Failed to set command overrides"); + th.printStackTrace(); + return; + } + + for (Class commandClass : postLoadCommands) + { + if (checkDependencies(commandClass)) return; + + addClass(commandClass); + } + }), 1); + } + + private boolean checkDependencies(Class commandClass) + { + if (commandClass.isAnnotationPresent(CommandDependencies.class)) + { + for (String dependency : commandClass.getAnnotation(CommandDependencies.class).value()) + { + if (Bukkit.getPluginManager().getPlugin(dependency) == null) + { + FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_", "") + " (Missing dependency: " + dependency + ")"); + return true; + } + } + } + return false; + } + + private void addClass(Class commandClass) + { + try + { + add(commandClass.newInstance()); + } catch (InstantiationException | IllegalAccessException ex) + { + FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_", "")); + } + } + + public List getCommands() + { + return commands; + } +} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandParameters.java similarity index 82% rename from commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java rename to commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandParameters.java index bae0e1887..8131df185 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandParameters.java @@ -1,4 +1,4 @@ -package me.totalfreedom.totalfreedommod.command; +package me.totalfreedom.totalfreedommod.command.handling; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandPermissions.java similarity index 85% rename from commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java rename to commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandPermissions.java index e4a17030c..0fac3c9b9 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/CommandPermissions.java @@ -1,4 +1,4 @@ -package me.totalfreedom.totalfreedommod.command; +package me.totalfreedom.totalfreedommod.command.handling; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/FreedomCommand.java similarity index 89% rename from commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java rename to commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/FreedomCommand.java index ba21ec2e7..c34f87144 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/FreedomCommand.java @@ -1,4 +1,4 @@ -package me.totalfreedom.totalfreedommod.command; +package me.totalfreedom.totalfreedommod.command.handling; import com.earth2me.essentials.commands.PlayerNotFoundException; import com.google.common.collect.Lists; @@ -10,6 +10,7 @@ import me.totalfreedom.totalfreedommod.util.PermissibleCompletion; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -22,10 +23,10 @@ import org.bukkit.util.StringUtil; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.annotation.AnnotationFormatError; import java.util.*; +import java.util.concurrent.CompletableFuture; public abstract class FreedomCommand implements CommandExecutor, TabCompleter { @@ -52,7 +53,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter private final CommandPermissions perms; protected CommandSender sender; - FreedomCommand() + protected FreedomCommand() { if (getClass().getAnnotation(CommandParameters.class) == null || getClass().getAnnotation(CommandPermissions.class) == null) @@ -109,7 +110,23 @@ public void register() cmd.setPermission(this.permission); } server.getCommandMap().register("totalfreedommod", cmd); - cmd.setExecutor(this); + CompletableFuture.runAsync(() -> server.getCommandMap().register("totalfreedommod", cmd)) + .whenComplete((v, th) -> + { + if (th != null) + { + FLog.severe(th); + return; + } + + PluginCommand pluginCommand = server.getPluginCommand(cmd.getName()); + if (pluginCommand != null) + { + pluginCommand.setExecutor(this); + pluginCommand.setTabCompleter(this); + } + cmd.setExecutor(this); + }); } protected void msg(CommandSender sender, Component message) @@ -160,7 +177,8 @@ protected List argumentCompletions(String arg, PermissibleCompletion... .toList(); } - protected List playerCompletions(String arg) { + protected List playerCompletions(String arg) + { return Bukkit.getOnlinePlayers() .stream() .map(Player::getName) @@ -178,6 +196,24 @@ protected boolean isAdmin(CommandSender sender) return plugin.al.isAdmin(sender); } + @NotNull + public TagResolver.Single player(Player player) + { + return Placeholder.unparsed("player", player.getName()); + } + + @NotNull + public TagResolver.Single sender(CommandSender sender) + { + return Placeholder.unparsed("sender", sender.getName()); + } + + @NotNull + public TagResolver.Single usage() + { + return Placeholder.unparsed("usage", this.getUsage().replace("", this.getName().toLowerCase())); + } + protected void checkConsole() { if (!isConsole()) @@ -202,6 +238,7 @@ protected void checkPermission(String permission) } } + @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, @NotNull String[] args) { try @@ -220,6 +257,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N } @NotNull + @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { List options = getTabCompleteOptions(sender, command, alias, args); @@ -232,6 +270,11 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman public abstract boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole); + protected TagResolver.Single arg(String arg) + { + return Placeholder.unparsed("arg", arg); + } + protected List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) { return FUtil.getPlayerList(); @@ -347,6 +390,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab { if (cmd == null) { + msgNew(sender, "", usage()); return false; } // Reduce complexity! Exit immediately if the command is null. diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Intercept.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Intercept.java new file mode 100644 index 000000000..bebd1764d --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Intercept.java @@ -0,0 +1,13 @@ +package me.totalfreedom.totalfreedommod.command.handling; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Intercept +{ + String value(); +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java new file mode 100644 index 000000000..5dc4551db --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java @@ -0,0 +1,77 @@ +package me.totalfreedom.totalfreedommod.command.handling; + +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.PluginIdentifiableCommand; + +import java.util.HashMap; +import java.util.Map; + +public class Interceptor +{ + private final TotalFreedomMod plugin; + private final Map overrides = new HashMap<>(); + + public Interceptor(TotalFreedomMod plugin) + { + this.plugin = plugin; + } + + public void intercept(String command) + { + getPluginCommands().entrySet() + .stream() + .filter(entry -> !((PluginIdentifiableCommand) entry.getValue()) // Check that it isn't a tfm command + .getPlugin() + .getName() + .equalsIgnoreCase(plugin.getName())) + .filter(entry -> entry.getValue() // Check that the command is the one we want to intercept + .getName() + .equalsIgnoreCase(command)) + .forEach(entry -> overrides.put(entry.getKey(), entry.getValue())); // Intercept. + + getFallbackCommands().entrySet() + .stream() + .filter(entry -> entry.getValue() // Check that the command is the one we want to intercept + .getName() + .equalsIgnoreCase(command)) + .forEach(entry -> overrides.put(entry.getKey(), entry.getValue())); // Intercept. + } + + public void setOverrides() + { + overrides.forEach((key, value) -> + { + Bukkit.getCommandMap().getKnownCommands().remove(key, value); + FLog.info("Overriding command: " + key); + }); + } + + private Map getFallbackCommands() + { + final Map fallbackCommands = new HashMap<>(); + for (final Map.Entry entry : Bukkit.getCommandMap().getKnownCommands().entrySet()) + { + if (!(entry.getValue() instanceof PluginIdentifiableCommand)) + { + fallbackCommands.put(entry.getKey(), entry.getValue()); + } + } + return fallbackCommands; + } + + private Map getPluginCommands() + { + final Map pluginCommands = new HashMap<>(); + for (final Map.Entry entry : Bukkit.getCommandMap().getKnownCommands().entrySet()) + { + if (entry.getValue() instanceof PluginIdentifiableCommand) + { + pluginCommands.put(entry.getKey(), entry.getValue()); + } + } + return pluginCommands; + } +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/SourceType.java similarity index 87% rename from commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java rename to commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/SourceType.java index 7a678bd3b..73d775fee 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/SourceType.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/SourceType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.totalfreedommod.command; +package me.totalfreedom.totalfreedommod.command.handling; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java index e35699234..8c99580e1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java @@ -1,11 +1,5 @@ package me.totalfreedom.totalfreedommod.config; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.EnumMap; -import java.util.List; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.util.FLog; @@ -13,6 +7,13 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.EnumMap; +import java.util.List; + public class MainConfig extends FreedomService { @@ -39,8 +40,7 @@ public MainConfig() entries.put(entry, tempDefaults.get(entry.getConfigName())); } } - } - catch (IOException ex) + } catch (IOException ex) { FLog.severe(ex); } @@ -48,8 +48,7 @@ public MainConfig() copyDefaultConfig(getConfigFile()); load(); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } @@ -88,20 +87,17 @@ public void load() if (value == null || entry.getType().isAssignableFrom(value.getClass())) { entries.put(entry, value); - } - else + } else { FLog.warning("Value for " + entry.getConfigName() + " is of type " + value.getClass().getSimpleName() + ". Needs to be " + entry.getType().getSimpleName() + ". Using default value."); } - } - else + } else { FLog.warning("Missing configuration entry " + entry.getConfigName() + ". Using default value."); } } - } - catch (IOException | InvalidConfigurationException ex) + } catch (IOException | InvalidConfigurationException ex) { FLog.severe(ex); } @@ -117,8 +113,7 @@ public String getString(ConfigEntry entry) try { return get(entry, String.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -130,8 +125,7 @@ public void setString(ConfigEntry entry, String value) try { set(entry, value, String.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -142,8 +136,7 @@ public Double getDouble(ConfigEntry entry) try { return get(entry, Double.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -155,8 +148,7 @@ public void setDouble(ConfigEntry entry, Double value) try { set(entry, value, Double.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -167,8 +159,7 @@ public Boolean getBoolean(ConfigEntry entry) try { return get(entry, Boolean.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -180,8 +171,7 @@ public void setBoolean(ConfigEntry entry, Boolean value) try { set(entry, value, Boolean.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -192,8 +182,7 @@ public Integer getInteger(ConfigEntry entry) try { return get(entry, Integer.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -205,8 +194,7 @@ public void setInteger(ConfigEntry entry, Integer value) try { set(entry, value, Integer.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -217,8 +205,7 @@ public List getList(ConfigEntry entry) try { return get(entry, List.class); - } - catch (IllegalArgumentException ex) + } catch (IllegalArgumentException ex) { FLog.severe(ex); } @@ -231,8 +218,7 @@ public T get(ConfigEntry entry, Class type) throws IllegalArgumentExcepti try { return type.cast(value); - } - catch (ClassCastException ex) + } catch (ClassCastException ex) { throw new IllegalArgumentException(entry.name() + " is not of type " + type.getSimpleName()); } @@ -266,8 +252,7 @@ private void copyDefaultConfig(File targetFile) { FileUtils.copyInputStreamToFile(defaultConfig, targetFile); } - } - catch (IOException ex) + } catch (IOException ex) { FLog.severe(ex); } @@ -296,8 +281,7 @@ private ConfigDefaults(InputStream defaultConfig) final InputStreamReader isr = new InputStreamReader(defaultConfig); defaults.load(isr); isr.close(); - } - catch (IOException | InvalidConfigurationException ex) + } catch (IOException | InvalidConfigurationException ex) { FLog.severe(ex); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java index 0ed4aa898..5048cc796 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java @@ -1,9 +1,10 @@ package me.totalfreedom.totalfreedommod.config; -import java.io.File; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import org.bukkit.configuration.file.YamlConfiguration; +import java.io.File; + public class YamlConfig extends YamlConfiguration { private final File file; @@ -34,8 +35,7 @@ public void load() try { super.load(file); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } @@ -46,8 +46,7 @@ public void save() try { super.save(file); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java index 8a6dabc18..38d2001d8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java @@ -1,6 +1,5 @@ package me.totalfreedom.totalfreedommod.freeze; -import java.util.Objects; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -9,6 +8,9 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; + +import java.util.Objects; + import static me.totalfreedom.totalfreedommod.TotalFreedomMod.plugin; import static me.totalfreedom.totalfreedommod.player.FPlayer.AUTO_PURGE_TICKS; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 110e5d376..962a5df3f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -1,10 +1,9 @@ package me.totalfreedom.totalfreedommod.fun; -import me.totalfreedom.totalfreedommod.api.ShopItem; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.api.ShopItem; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; -import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.*; import org.bukkit.block.Block; @@ -18,8 +17,6 @@ import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; @@ -374,40 +371,32 @@ public void onFish(PlayerFishEvent event) if (orientation >= 0.0 && orientation < 22.5) { zVel = speed; - } - else if (orientation >= 22.5 && orientation < 67.5) + } else if (orientation >= 22.5 && orientation < 67.5) { xVel = -(speed / 2.0); zVel = speed / 2.0; - } - else if (orientation >= 67.5 && orientation < 112.5) + } else if (orientation >= 67.5 && orientation < 112.5) { xVel = -speed; - } - else if (orientation >= 112.5 && orientation < 157.5) + } else if (orientation >= 112.5 && orientation < 157.5) { xVel = -(speed / 2.0); zVel = -(speed / 2.0); - } - else if (orientation >= 157.5 && orientation < 202.5) + } else if (orientation >= 157.5 && orientation < 202.5) { zVel = -speed; - } - else if (orientation >= 202.5 && orientation < 247.5) + } else if (orientation >= 202.5 && orientation < 247.5) { xVel = speed / 2.0; zVel = -(speed / 2.0); - } - else if (orientation >= 247.5 && orientation < 292.5) + } else if (orientation >= 247.5 && orientation < 292.5) { xVel = speed; - } - else if (orientation >= 292.5 && orientation < 337.5) + } else if (orientation >= 292.5 && orientation < 337.5) { xVel = speed / 2.0; zVel = speed / 2.0; - } - else if (orientation >= 337.5 && orientation < 360.0) + } else if (orientation >= 337.5 && orientation < 360.0) { zVel = speed; } @@ -417,8 +406,7 @@ else if (orientation >= 337.5 && orientation < 360.0) if (event.getState() == PlayerFishEvent.State.FISHING) { orientationTracker.put(player, player.getLocation().getYaw()); - } - else + } else { orientationTracker.remove(player); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java index 2341272b1..4418e544a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java @@ -1,9 +1,6 @@ package me.totalfreedom.totalfreedommod.fun; import com.google.common.collect.Maps; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.block.Block; @@ -13,6 +10,10 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + public class Jumppads extends FreedomService { @@ -75,14 +76,12 @@ public void onPlayerMove(PlayerMoveEvent event) velocity.multiply(strength + 0.85).multiply(-1.0); } canPush = false; - } - else + } else { canPush = true; } pushMap.put(player, canPush); - } - else + } else { if (Groups.WOOL_COLORS.contains(block.getRelative(0, -1, 0).getType())) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java index fc249df93..812bd60d1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java @@ -1,8 +1,5 @@ package me.totalfreedom.totalfreedommod.fun; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import org.bukkit.GameMode; @@ -15,6 +12,10 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + public class Landminer extends FreedomService { private final List landmines = new ArrayList<>(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java index a808ab53b..0f051fd6e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.Map; + import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; public class HTMLGenerationTools diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java index da5aba892..90637b367 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java @@ -1,32 +1,22 @@ package me.totalfreedom.totalfreedommod.httpd; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; -import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule; -import me.totalfreedom.totalfreedommod.httpd.module.Module_admins; -import me.totalfreedom.totalfreedommod.httpd.module.Module_bans; -import me.totalfreedom.totalfreedommod.httpd.module.Module_file; -import me.totalfreedom.totalfreedommod.httpd.module.Module_help; -import me.totalfreedom.totalfreedommod.httpd.module.Module_indefbans; -import me.totalfreedom.totalfreedommod.httpd.module.Module_index; -import me.totalfreedom.totalfreedommod.httpd.module.Module_list; -import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile; -import me.totalfreedom.totalfreedommod.httpd.module.Module_players; -import me.totalfreedom.totalfreedommod.httpd.module.Module_punishments; -import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic; +import me.totalfreedom.totalfreedommod.httpd.module.*; import me.totalfreedom.totalfreedommod.util.FLog; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.ExceptionUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class HTTPDaemon extends FreedomService { @@ -66,8 +56,7 @@ public static Response serveFileBasic(File file) response = new Response(Response.Status.OK, mimetype, new FileInputStream(file)); response.addHeader("Content-Length", "" + file.length()); - } - catch (IOException ex) + } catch (IOException ex) { FLog.severe(ex); } @@ -106,13 +95,11 @@ public void onStart() if (httpd.isAlive()) { FLog.info("TFM HTTPd started. Listening on port: " + httpd.getListeningPort()); - } - else + } else { FLog.info("Error starting TFM HTTPd."); } - } - catch (IOException ex) + } catch (IOException ex) { FLog.severe(ex); } @@ -142,7 +129,7 @@ private HTTPD(int port) { super(port); } - + @Override public Response serve(HTTPSession session) { @@ -162,8 +149,7 @@ public Response serve(HTTPSession session) try { return mex.execute(session); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getStackTrace(ex)); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/ModuleExecutable.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/ModuleExecutable.java index a345f0acf..f987ed39a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/ModuleExecutable.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/ModuleExecutable.java @@ -1,11 +1,12 @@ package me.totalfreedom.totalfreedommod.httpd; -import java.lang.reflect.Constructor; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule; import me.totalfreedom.totalfreedommod.util.FLog; import org.bukkit.Bukkit; +import java.lang.reflect.Constructor; + public abstract class ModuleExecutable { private final boolean async; @@ -21,8 +22,7 @@ public static ModuleExecutable forClass(Class clazz, bool try { cons = clazz.getConstructor(NanoHTTPD.HTTPSession.class); - } - catch (Exception ex) + } catch (Exception ex) { throw new IllegalArgumentException("Improperly defined module!"); } @@ -35,8 +35,7 @@ public NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session) try { return cons.newInstance(session).getResponse(); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); return null; @@ -57,8 +56,7 @@ public NanoHTTPD.Response execute(final NanoHTTPD.HTTPSession session) // Sync to server thread return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.getPlugin(), () -> getResponse(session)).get(); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java index bd045b952..04a42053d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java @@ -1,40 +1,15 @@ package me.totalfreedom.totalfreedommod.httpd; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.Closeable; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.RandomAccessFile; -import java.io.SequenceInputStream; -import java.io.UnsupportedEncodingException; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; -import java.net.URLDecoder; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.jetbrains.annotations.NotNull; + +import java.io.*; +import java.net.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.TimeZone; -import me.totalfreedom.totalfreedommod.util.FLog; -import org.jetbrains.annotations.NotNull; +import java.util.*; /** * A simple, tiny, nicely embeddable HTTP server in Java @@ -142,8 +117,7 @@ private static void safeClose(ServerSocket serverSocket) try { serverSocket.close(); - } - catch (IOException ignored) + } catch (IOException ignored) { } } @@ -156,8 +130,7 @@ private static void safeClose(Socket socket) try { socket.close(); - } - catch (IOException ignored) + } catch (IOException ignored) { } } @@ -170,8 +143,7 @@ private static void safeClose(Closeable closeable) try { closeable.close(); - } - catch (IOException ignored) + } catch (IOException ignored) { } } @@ -198,8 +170,7 @@ public void start() throws IOException if (inputStream == null) { safeClose(finalAccept); - } - else + } else { asyncRunner.exec(() -> { @@ -213,8 +184,7 @@ public void start() throws IOException { session.execute(); } - } - catch (Exception e) + } catch (Exception e) { // When the socket is closed by the client, we throw our own SocketException // to break the "keep alive" loop above. @@ -222,8 +192,7 @@ public void start() throws IOException { FLog.severe(e); } - } - finally + } finally { safeClose(outputStream); safeClose(inputStream); @@ -231,8 +200,7 @@ public void start() throws IOException } }); } - } - catch (IOException ignored) + } catch (IOException ignored) { } } @@ -256,8 +224,7 @@ public void stop() { myThread.join(); } - } - catch (Exception e) + } catch (Exception e) { FLog.severe(e); } @@ -315,12 +282,10 @@ public Response serve(HTTPSession session) try { session.parseBody(files); - } - catch (IOException ioe) + } catch (IOException ioe) { return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage()); - } - catch (ResponseException re) + } catch (ResponseException re) { return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage()); } @@ -341,8 +306,7 @@ protected String decodePercent(String str) try { decoded = URLDecoder.decode(str, "UTF8"); - } - catch (UnsupportedEncodingException | IllegalArgumentException ignored) + } catch (UnsupportedEncodingException | IllegalArgumentException ignored) { } return decoded; @@ -553,8 +517,7 @@ public void clear() try { file.delete(); - } - catch (Exception ignored) + } catch (Exception ignored) { } } @@ -706,15 +669,13 @@ private void send(OutputStream outputStream) if (requestMethod != Method.HEAD && chunkedTransfer) { sendAsChunked(outputStream, pw); - } - else + } else { sendAsFixedLength(outputStream, pw); } outputStream.flush(); safeClose(data); - } - catch (IOException ioe) + } catch (IOException ioe) { // Couldn't write? No can do. } @@ -1093,32 +1054,27 @@ public void execute() throws IOException if (r == null) { throw new ResponseException(Response.Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response."); - } - else + } else { cookies.unloadQueue(r); r.setRequestMethod(method); r.send(outputStream); } - } - catch (SocketException e) + } catch (SocketException e) { // throw it out to close socket object (finalAccept) throw e; - } - catch (IOException ioe) + } catch (IOException ioe) { Response r = new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage()); r.send(outputStream); safeClose(outputStream); - } - catch (ResponseException re) + } catch (ResponseException re) { Response r = new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage()); r.send(outputStream); safeClose(outputStream); - } - finally + } finally { tempFileManager.clear(); } @@ -1137,12 +1093,10 @@ public void parseBody(Map files) throws IOException, ResponseExc if (headers.containsKey("content-length")) { size = Integer.parseInt(headers.get("content-length")); - } - else if (splitbyte < rlen) + } else if (splitbyte < rlen) { size = rlen - splitbyte; - } - else + } else { size = 0; } @@ -1203,8 +1157,7 @@ else if (splitbyte < rlen) } decodeMultipartData(boundary, fbuf, in, parms, files); - } - else + } else { // Handle application/x-www-form-urlencoded StringBuilder postLine = new StringBuilder(); @@ -1218,13 +1171,11 @@ else if (splitbyte < rlen) postLine = new StringBuilder(postLine.toString().trim()); decodeParms(postLine.toString(), parms); } - } - else if (Method.PUT.equals(method)) + } else if (Method.PUT.equals(method)) { files.put("content", saveTmpFile(fbuf, 0, fbuf.limit())); } - } - finally + } finally { safeClose(randomAccessFile); safeClose(in); @@ -1267,8 +1218,7 @@ private void decodeHeader(BufferedReader in, Map pre, Map pre, Map bpositions.length) { @@ -1389,8 +1336,7 @@ private void decodeMultipartData(String boundary, ByteBuffer fbuf, BufferedReade parms.put(pname, value.toString()); } } - } - catch (IOException ioe) + } catch (IOException ioe) { throw new ResponseException(Response.Status.INTERNAL_ERROR, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage(), ioe); } @@ -1436,8 +1382,7 @@ private int[] getBoundaryPositions(ByteBuffer b, byte[] boundary) matchcount = 0; matchbyte = -1; } - } - else + } else { i -= matchcount; matchcount = 0; @@ -1470,12 +1415,10 @@ private String saveTmpFile(ByteBuffer b, int offset, int len) src.position(offset).limit(offset + len); dest.write(src.slice()); path = tempFile.getName(); - } - catch (Exception e) + } catch (Exception e) { // Catch exception if any FLog.severe(e); - } - finally + } finally { safeClose(fileOutputStream); } @@ -1489,8 +1432,7 @@ private RandomAccessFile getTmpBucket() { TempFile tempFile = tempFileManager.createTempFile(); return new RandomAccessFile(tempFile.getName(), "rw"); - } - catch (Exception e) + } catch (Exception e) { FLog.severe(e); } @@ -1535,8 +1477,7 @@ private void decodeParms(String parms, Map p) { p.put(decodePercent(e.substring(0, sep)).trim(), decodePercent(e.substring(sep + 1))); - } - else + } else { p.put(decodePercent(e).trim(), ""); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java index 4ea99cefe..457309f2f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java @@ -1,8 +1,5 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.net.Socket; -import java.util.HashMap; -import java.util.Map; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession; @@ -10,6 +7,10 @@ import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import me.totalfreedom.totalfreedommod.util.FLog; +import java.net.Socket; +import java.util.HashMap; +import java.util.Map; + public abstract class HTTPDModule extends FreedomService { @@ -72,8 +73,7 @@ protected final Map getFiles() try { session.parseBody(files); - } - catch (Exception ex) + } catch (Exception ex) { FLog.severe(ex); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_file.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_file.java index da43ca2c4..9dfddf0b0 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_file.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_file.java @@ -1,22 +1,18 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; + /* * This class was adapted from https://github.com/NanoHttpd/nanohttpd/blob/master/webserver/src/main/java/fi/iki/elonen/SimpleWebServer.java */ @@ -77,18 +73,15 @@ private String encodeUri(String uri) if (tok.equals("/")) { newUri.append("/"); - } - else if (tok.equals(" ")) + } else if (tok.equals(" ")) { newUri.append("%20"); - } - else + } else { try { newUri.append(URLEncoder.encode(tok, "UTF-8")); - } - catch (UnsupportedEncodingException ignored) + } catch (UnsupportedEncodingException ignored) { } } @@ -147,17 +140,14 @@ public Response serveFile(String uri, Map params, File homeDir) if (new File(f, "index.html").exists()) { f = new File(homeDir, uri + "/index.html"); - } - else if (new File(f, "index.htm").exists()) + } else if (new File(f, "index.htm").exists()) { f = new File(homeDir, uri + "/index.htm"); - } - else if (f.canRead()) + } else if (f.canRead()) { // No index file, list the directory if it is readable res = new Response(listDirectory(uri, f)); - } - else + } else { res = new Response(Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "FORBIDDEN: No directory listing."); } @@ -203,12 +193,10 @@ else if (f.canRead()) startFrom = Long.parseLong(rangeParams[1].substring(0, minus)); endAt = Long.parseLong(rangeParams[1].substring(minus + 1)); } - } - catch (NumberFormatException ignored) + } catch (NumberFormatException ignored) { } - } - else if ("tail".equalsIgnoreCase(rangeParams[0])) + } else if ("tail".equalsIgnoreCase(rangeParams[0])) { try { @@ -221,8 +209,7 @@ else if ("tail".equalsIgnoreCase(rangeParams[0])) startFrom = 0; } } - } - catch (NumberFormatException ignored) + } catch (NumberFormatException ignored) { } } @@ -236,8 +223,7 @@ else if ("tail".equalsIgnoreCase(rangeParams[0])) { res = new Response(Response.Status.RANGE_NOT_SATISFIABLE, NanoHTTPD.MIME_PLAINTEXT, ""); res.addHeader("Content-Range", "bytes 0-0/" + fileLen); - } - else + } else { if (endAt < 0) { @@ -255,7 +241,7 @@ else if ("tail".equalsIgnoreCase(rangeParams[0])) @Override public int available() { - return (int)dataLen; + return (int) dataLen; } }; //noinspection ResultOfMethodCallIgnored @@ -265,16 +251,14 @@ public int available() res.addHeader("Content-Length", "" + dataLen); res.addHeader("Content-Range", "bytes " + startFrom + "-" + endAt + "/" + fileLen); } - } - else + } else { res = new Response(Response.Status.OK, mime, new FileInputStream(f)); res.addHeader("Content-Length", "" + fileLen); } res.addHeader("ETag", etag); } - } - catch (IOException ioe) + } catch (IOException ioe) { res = new Response(Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "FORBIDDEN: Reading file failed."); } @@ -337,12 +321,10 @@ private String listDirectory(String uri, File f) if (len < 1024) { msg.append(len).append(" bytes"); - } - else if (len < 1024 * 1024) + } else if (len < 1024 * 1024) { msg.append(len / 1024).append(".").append(len % 1024 / 10 % 100).append(" KB"); - } - else + } else { msg.append(len / (1024 * 1024)).append(".").append(len % (1024 * 1024) / 10 % 100).append(" MB"); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java index c41e6b62e..d77e63ce2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java @@ -1,12 +1,8 @@ package me.totalfreedom.totalfreedommod.httpd.module; import com.google.common.collect.Lists; - -import java.util.*; - -import me.totalfreedom.totalfreedommod.command.FreedomCommand; +import me.totalfreedom.totalfreedommod.command.handling.FreedomCommand; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; -import me.totalfreedom.totalfreedommod.rank.DisplayableGroup; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -16,6 +12,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.*; + import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.heading; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph; import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; @@ -82,7 +80,7 @@ public String getBody() String pluginName = "Bukkit"; if (command instanceof PluginIdentifiableCommand) { - pluginName = ((PluginIdentifiableCommand)command).getPlugin().getName(); + pluginName = ((PluginIdentifiableCommand) command).getPlugin().getName(); } List pluginCommands = commandsByPlugin.computeIfAbsent(pluginName, k -> Lists.newArrayList()); @@ -109,13 +107,13 @@ public String getBody() if (!plugin.getName().equals(pluginName)) { commands.forEach((command) -> responseBody.append(buildDescription(command))); - } - else + } else { Map> freedomCommands = new HashMap<>(); // Filters out non-TFM commands - commands.stream().filter((cmd) -> cmd instanceof FreedomCommand.FCommand).forEach((tfmCmd) -> { + commands.stream().filter((cmd) -> cmd instanceof FreedomCommand.FCommand).forEach((tfmCmd) -> + { String permission = Objects.requireNonNull(FreedomCommand.getFrom(tfmCmd)).getPermission(); if (!freedomCommands.containsKey(permission)) freedomCommands.put(permission, new ArrayList<>()); @@ -131,10 +129,11 @@ public String getBody() // Finally dumps them to HTML permissions.stream().filter(freedomCommands::containsKey) - .sorted(comparator::compare).forEach((permission -> { - responseBody.append("\r\n").append(heading(permission, 3)).append("
    \r\n"); - freedomCommands.get(permission).stream().sorted(comparator::compare).forEach((command) -> responseBody.append(buildDescription(command))); - })); + .sorted(comparator::compare).forEach((permission -> + { + responseBody.append("
\r\n").append(heading(permission, 3)).append("
    \r\n"); + freedomCommands.get(permission).stream().sorted(comparator::compare).forEach((command) -> responseBody.append(buildDescription(command))); + })); } responseBody.append("
\r\n"); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java index 6cb89393a..d586b06e1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java @@ -1,11 +1,12 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.io.File; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; +import java.io.File; + public class Module_indefbans extends HTTPDModule { @@ -28,8 +29,7 @@ public NanoHTTPD.Response getResponse() if (permbanFile.exists()) { return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), IndefiniteBanList.CONFIG_FILENAME)); - } - else + } else { return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server."); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java index 7c7beabd4..d639e2b75 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java @@ -1,12 +1,13 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.util.Set; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools; import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; import org.reflections.Reflections; +import java.util.Set; + public class Module_index extends HTTPDModule { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java index 8aefe2998..dfc8d89d8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java @@ -1,10 +1,9 @@ package me.totalfreedom.totalfreedommod.httpd.module; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -71,9 +70,11 @@ public NanoHTTPD.Response getResponse() if (hasSpecialTitle(player) && plugin.al.isAdmin(player) && !plugin.al.isVanished(player.getUniqueId())) { Admin admin = plugin.al.getAdmin(player); - if (admin.getRank().equals(GroupProvider.ADMIN.getGroup())) { + if (admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin())) + { admins.add(player.getName()); - } else if (admin.getRank().equals(GroupProvider.SENIOR_ADMIN.getGroup())) { + } else if (admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin())) + { senioradmins.add(player.getName()); } } @@ -93,8 +94,7 @@ public NanoHTTPD.Response getResponse() final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString()); response.addHeader("Access-Control-Allow-Origin", "*"); return response; - } - else + } else { final StringBuilder body = new StringBuilder(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java index e0a88031e..111840b6d 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java @@ -1,10 +1,5 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools; @@ -17,6 +12,12 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; + public class Module_logfile extends HTTPDModule { @@ -44,8 +45,7 @@ public Response getResponse() try { return new HTTPDPageBuilder(body(), title(), null, null).getResponse(); - } - catch (ResponseOverrideException ex) + } catch (ResponseOverrideException ex) { return ex.getResponse(); } @@ -78,8 +78,7 @@ public String body() throws ResponseOverrideException out.append(HTMLGenerationTools.paragraph("Log files access denied: Your IP, " + remoteAddress + ", is not registered to an admin on this server.")); FLog.info("An unregistered IP (" + remoteAddress + ") has tried to access the log files"); - } - else + } else { Collection LogFiles = FileUtils.listFiles(LOG_FOLDER, LOG_FILTER, false); @@ -108,15 +107,13 @@ public String body() throws ResponseOverrideException { out.append(HTMLGenerationTools.paragraph("Log files access denied: Your IP, " + remoteAddress + ", is not registered to an admin on this server.")); FLog.info("An unregistered IP (" + remoteAddress + ") has tried to download a log file"); - } - else + } else { try { FLog.info("The IP \"" + remoteAddress + "\" is downloading log file: " + params.get("logFileName")); throw new ResponseOverrideException(downloadLogFile(params.get("logFileName"))); - } - catch (LogFileTransferException ex) + } catch (LogFileTransferException ex) { out.append(HTMLGenerationTools.paragraph("Error downloading logfile: " + ex.getMessage())); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java index 03b958bbb..633e786a1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java @@ -1,13 +1,11 @@ package me.totalfreedom.totalfreedommod.httpd.module; import com.google.gson.Gson; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.entity.HumanEntity; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; import java.util.ArrayList; import java.util.HashMap; @@ -15,9 +13,9 @@ import java.util.Map; public class Module_players extends HTTPDModule -{ +{ private static final Gson gson = new Gson(); - + public Module_players(NanoHTTPD.HTTPSession session) { super(session); @@ -34,10 +32,10 @@ public NanoHTTPD.Response getResponse() plugin.al.getActiveAdmins().stream().filter(admin -> admin.getName() != null).forEach(admin -> { // Do nothing, keeps Codacy quiet - if (admin.getRank().equals(GroupProvider.ADMIN.getGroup())) + if (admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin())) { admins.add(admin.getName()); - } else if (admin.getRank().equals(GroupProvider.SENIOR_ADMIN.getGroup())) + } else if (admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin())) { senioradmins.add(admin.getName()); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java index 09adca04f..b67d396e6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java @@ -1,11 +1,12 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.io.File; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; import me.totalfreedom.totalfreedommod.punishments.PunishmentList; +import java.io.File; + public class Module_punishments extends HTTPDModule { @@ -25,14 +26,12 @@ public NanoHTTPD.Response getResponse() { return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "You may not view the punishment list. Your IP, " + remoteAddress + ", is not registered to an admin on the server."); - } - else + } else { return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), PunishmentList.CONFIG_FILENAME)); } - } - else + } else { return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server."); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java index 808467c52..bda08c4a3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java @@ -2,15 +2,6 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools; @@ -25,6 +16,12 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.*; +import java.util.regex.Pattern; + public class Module_schematic extends HTTPDModule { @@ -60,8 +57,7 @@ public Response getResponse() try { return new HTTPDPageBuilder(body(), title(), null, null).getResponse(); - } - catch (ResponseOverrideException ex) + } catch (ResponseOverrideException ex) { return ex.getResponse(); } @@ -98,12 +94,10 @@ public String body() throws ResponseOverrideException if (SCHEMATIC_FILENAME_LC.matcher(filename.trim().toLowerCase()).find()) { schematicsFormatted.add("
  • " + filename + "
  • "); - } - else if (filename.length() > 254) + } else if (filename.length() > 254) { schematicsFormatted.add("
  • " + filename + " - (Filename too long, can't download)
  • "); - } - else + } else { schematicsFormatted.add("
  • " + filename + " - (Illegal filename, can't download)
  • "); } @@ -122,8 +116,7 @@ else if (filename.length() > 254) try { throw new ResponseOverrideException(downloadSchematic(params.get("schematicName"))); - } - catch (SchematicTransferException ex) + } catch (SchematicTransferException ex) { out.append(HTMLGenerationTools.paragraph("Error downloading schematic: " + ex.getMessage())); } @@ -135,8 +128,7 @@ else if (filename.length() > 254) if (!isAuthorized(remoteAddress)) { out.append(HTMLGenerationTools.paragraph("Schematic upload access denied: Your IP, " + remoteAddress + ", is not registered to an admin on this server.")); - } - else + } else { if (method == Method.POST) { @@ -145,13 +137,11 @@ else if (filename.length() > 254) uploadSchematic(remoteAddress); out.append(HTMLGenerationTools.paragraph("Schematic uploaded successfully.")); - } - catch (SchematicTransferException ex) + } catch (SchematicTransferException ex) { out.append(HTMLGenerationTools.paragraph("Error uploading schematic: " + ex.getMessage())); } - } - else + } else { out.append(UPLOAD_FORM); } @@ -248,8 +238,7 @@ private void func2(File tempFile, File targetFile, String remoteAddress) throws try { format.getReader(new FileInputStream(targetFile)); - } - catch (IOException e) + } catch (IOException e) { FileUtils.deleteQuietly(targetFile); throw new SchematicTransferException("Schematic is not a valid schematic."); @@ -257,8 +246,7 @@ private void func2(File tempFile, File targetFile, String remoteAddress) throws FLog.info(remoteAddress + " uploaded schematic: " + targetFile.getName()); - } - catch (IOException ex) + } catch (IOException ex) { FLog.severe(ex); throw new SchematicTransferException(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java new file mode 100644 index 000000000..bc7ae6b28 --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/GroupWrapper.java @@ -0,0 +1,33 @@ +package me.totalfreedom.totalfreedommod.perms; + +import me.totalfreedom.totalfreedommod.util.FLog; +import net.luckperms.api.model.group.Group; +import net.luckperms.api.model.group.GroupManager; + +public class GroupWrapper +{ + private final GroupManager manager; + + public GroupWrapper(GroupManager manager) + { + this.manager = manager; + } + + public Group getGroup(String name) + { + if (!manager.isLoaded(name)) + { + return manager.createAndLoadGroup(name).join(); + } + + return manager.getGroup(name); + } + + public void saveGroup(String name) + { + Group group = getGroup(name); + manager.saveGroup(group) + .thenRun(() -> + FLog.info("Saved group " + name + " to LuckPerms.")); + } +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java new file mode 100644 index 000000000..116c29948 --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/TrackWrapper.java @@ -0,0 +1,33 @@ +package me.totalfreedom.totalfreedommod.perms; + +import me.totalfreedom.totalfreedommod.util.FLog; +import net.luckperms.api.track.Track; +import net.luckperms.api.track.TrackManager; + +public class TrackWrapper +{ + private final TrackManager manager; + + public TrackWrapper(TrackManager manager) + { + this.manager = manager; + } + + public Track getTrack(String name) + { + if (!manager.isLoaded(name)) + { + return manager.createAndLoadTrack(name).join(); + } + + return manager.getTrack(name); + } + + public void saveTrack(String name) + { + Track t = getTrack(name); + manager.saveTrack(t) + .thenRun(() -> + FLog.info("Saved track " + name + " successfully.")); + } +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserData.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserData.java new file mode 100644 index 000000000..bd9e9fc79 --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserData.java @@ -0,0 +1,51 @@ +package me.totalfreedom.totalfreedommod.perms; + +import net.luckperms.api.LuckPermsProvider; +import net.luckperms.api.cacheddata.CachedDataManager; +import net.luckperms.api.cacheddata.CachedMetaData; +import net.luckperms.api.cacheddata.CachedPermissionData; +import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.model.user.User; +import net.luckperms.api.platform.PlayerAdapter; +import net.luckperms.api.query.QueryOptions; +import org.bukkit.entity.Player; + +/** + * This class is a utility class that can be used to retrieve + * numerous contextual options related to LuckPerms users. + */ +public class UserData +{ + public static User fromPlayer(Player player) + { + PlayerAdapter adapter = LuckPermsProvider + .get() + .getPlayerAdapter(Player.class); + return adapter.getUser(player); + } + + public static QueryOptions getQueryOptions(User user) + { + return user.getQueryOptions(); + } + + public static CachedDataManager getDataManager(User user) + { + return user.getCachedData(); + } + + public static ImmutableContextSet getContextSet(User user) + { + return getQueryOptions(user).context(); + } + + public static CachedMetaData getMetaData(User user) + { + return getDataManager(user).getMetaData(); + } + + public static CachedPermissionData getPermissionData(User user) + { + return getDataManager(user).getPermissionData(); + } +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java new file mode 100644 index 000000000..256824a28 --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java @@ -0,0 +1,68 @@ +package me.totalfreedom.totalfreedommod.perms; + +import me.totalfreedom.totalfreedommod.rank.DisplayableGroup; +import me.totalfreedom.totalfreedommod.util.FLog; +import net.luckperms.api.model.user.User; +import net.luckperms.api.model.user.UserManager; +import net.luckperms.api.node.NodeType; +import net.luckperms.api.platform.PlayerAdapter; +import org.bukkit.entity.Player; + +public class UserWrapper +{ + private final UserManager manager; + private final PlayerAdapter playerAdapter; + + public UserWrapper(UserManager manager, PlayerAdapter adapter) + { + this.manager = manager; + this.playerAdapter = adapter; + } + + public User getUser(Player player) + { + if (!manager.isLoaded(player.getUniqueId()) || !manager.getLoadedUsers().contains(manager.getUser(player.getUniqueId()))) + { + return manager.loadUser(player.getUniqueId()).join(); + } + + return manager.getUser(player.getUniqueId()); + } + + public void addToGroup(User user, DisplayableGroup group) + { + + manager.modifyUser(user.getUniqueId(), c -> + { + if (!c.getNodes(NodeType.INHERITANCE) + .contains(group.getInheritance())) + c.data().add(group.getInheritance()); + }) + .thenRun(() -> + FLog.info("Successfully saved user " + + user.getUsername() + + " to group " + + group.getName())); + } + + public void removeFromGroup(User user, DisplayableGroup group) + { + manager.modifyUser(user.getUniqueId(), userConsumer -> + { + if (userConsumer.getNodes(NodeType.INHERITANCE) + .contains(group.getInheritance())) + userConsumer.data().remove(group.getInheritance()); + }).thenRun(() -> + FLog.info("Successfully removed user " + + user.getUsername() + + " from group " + + group.getName())); + } + + public void saveUser(User user) + { + manager.saveUser(user).thenRun(() -> + FLog.info("Successfully saved user " + + user.getUsername())); + } +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java index 08e648ce5..1f7215aa4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java @@ -7,8 +7,6 @@ import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -55,14 +53,18 @@ public PlayerData(ResultSet resultSet) notes.addAll(FUtil.stringToList(resultSet.getString("notes"))); String tempTag = resultSet.getString("tag"); //-- - if (!Strings.isNullOrEmpty(tempTag) && FUtil.containsChatColor(tempTag)) + if (!Strings.isNullOrEmpty(tempTag)) { - tempTag = FUtil.miniMessage(FUtil.colorizeAsComponentSection(tempTag)); + if (FUtil.containsChatColor(tempTag)) + { + tempTag = FUtil.miniMessage(FUtil.colorizeAsComponentSection(tempTag)); + } + + tag = FUtil.miniMessage(tempTag); } //-- - tag = FUtil.miniMessage(tempTag); discordID = resultSet.getString("discord_id"); - masterBuilder = resultSet.getBoolean("master_builder"); + masterBuilder = resultSet.getBoolean("masterBuilder"); rideMode = RideMode.valueOf(resultSet.getString("ride_mode").toUpperCase()); coins = resultSet.getInt("coins"); items.clear(); @@ -210,7 +212,7 @@ public Map toSQLStorable() objectMap.put("notes", FUtil.listToString(notes)); objectMap.put("tag", FUtil.miniMessage(tag)); objectMap.put("discord_id", discordID); - objectMap.put("master_builder", masterBuilder); + objectMap.put("masterBuilder", masterBuilder); objectMap.put("ride_mode", rideMode.name()); objectMap.put("coins", coins); objectMap.put("items", FUtil.listToString(items)); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java index d04871110..6e95a599f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java @@ -2,9 +2,9 @@ import com.google.common.collect.Maps; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.OfflinePlayer; @@ -100,7 +100,7 @@ public boolean canManageMasterBuilders(String name) public boolean isTelnetMasterBuilder(PlayerData playerData) { Admin admin = plugin.al.getEntryByUuid(playerData.getUuid()); - return admin != null && admin.getRank().isAtLeast(GroupProvider.ADMIN.getGroup()) && playerData.isMasterBuilder(); + return admin != null && admin.getRank().weightCheckAgainst(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin()) && playerData.isMasterBuilder(); } // May not return null @@ -176,7 +176,7 @@ public PlayerData getData(Player player) // Load data playerData = loadByUuid(player.getUniqueId()); - // Oh you don't have any data? Well now you do + // Oh, you don't have any data? Well now you do if (playerData == null) { FLog.info("Creating new player data entry for " + player.getName()); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java index 3e532872c..bdaeaf8e8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java @@ -1,11 +1,12 @@ package me.totalfreedom.totalfreedommod.punishments; +import me.totalfreedom.totalfreedommod.config.IConfig; +import org.bukkit.configuration.ConfigurationSection; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Objects; -import me.totalfreedom.totalfreedommod.config.IConfig; -import org.bukkit.configuration.ConfigurationSection; public class Punishment implements IConfig { @@ -59,8 +60,7 @@ public void loadFrom(ConfigurationSection cs) try { this.issued_on = DATE_FORMAT.parse(cs.getString("issued_on", null)); - } - catch (ParseException e) + } catch (ParseException e) { this.issued_on = null; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java index b18952cba..46d50db12 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java @@ -1,13 +1,14 @@ package me.totalfreedom.totalfreedommod.punishments; import com.google.common.collect.Sets; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.config.YamlConfig; +import me.totalfreedom.totalfreedommod.util.FLog; + import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Set; -import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.config.YamlConfig; -import me.totalfreedom.totalfreedommod.util.FLog; public class PunishmentList extends FreedomService { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java index 621b66694..77e56fa74 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java @@ -4,16 +4,19 @@ import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; -import net.luckperms.api.model.data.DataType; +import net.luckperms.api.context.ContextSatisfyMode; import net.luckperms.api.model.group.Group; +import net.luckperms.api.node.NodeType; import net.luckperms.api.node.types.InheritanceNode; +import net.luckperms.api.node.types.PermissionNode; import net.luckperms.api.node.types.PrefixNode; import net.luckperms.api.node.types.WeightNode; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; -import java.util.concurrent.CompletableFuture; public class DisplayableGroup implements Displayable { @@ -24,7 +27,7 @@ public class DisplayableGroup implements Displayable private final Component abbr; private final Component plural; private final Component article; - private final int weight; + private final WeightNode weight; private final Component tag; @@ -38,8 +41,13 @@ public class DisplayableGroup implements Displayable private final boolean hasDefaultLoginMessage; + + private final InheritanceNode inheritance; + private final PrefixNode prefix; + private final List permissions = new ArrayList<>(); + + public DisplayableGroup(String group, - String inheritance, Component plural, Component tag, int weight, @@ -48,59 +56,80 @@ public DisplayableGroup(String group, boolean hasTeam, boolean hasDefaultLoginMessage) { - Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group); - - if (matched == null) - { - CompletableFuture cfg = TotalFreedomMod.getPlugin() - .lpb - .getAPI() - .getGroupManager() - .createAndLoadGroup(group); + WeightNode tempWeight; + PrefixNode tempPrefix; + Group matched = TotalFreedomMod.getPlugin().getHierarchy().getGroup(group); // we don't need to null check because if there is no group this method will also create one. - cfg.thenAcceptAsync(g -> - { - WeightNode weightNode = WeightNode.builder(weight).build(); - PrefixNode prefixNode = PrefixNode.builder() - .prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE))) - .priority(1) - .build(); - if (inheritance != null) - { - InheritanceNode inheritanceNode = InheritanceNode.builder(inheritance).build(); - g.getData(DataType.NORMAL).add(inheritanceNode); - } - g.getData(DataType.NORMAL).add(prefixNode); - g.getData(DataType.NORMAL).add(weightNode); - }).join(); // Block until the group is created and loaded. - - matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group); - - if (matched == null) - throw new IllegalArgumentException("Group " + group + " does not exist and could not be created."); - } - - this.group = matched; this.name = (matched.getDisplayName() != null) ? FUtil.miniMessage(matched.getDisplayName()) : FUtil.miniMessage(matched.getName()); this.plural = plural; this.article = StringUtils.startsWithAny(this.name.toString().toLowerCase(Locale.ROOT), new String[]{"a", "e", "i", "o", "u"}) ? Component.text("an") : Component.text("a"); this.abbr = tag; - this.weight = weight; - this.tag = GroupProvider.OPEN.append(tag).append(GroupProvider.CLOSE); this.color = color; this.teamColor = teamColor; this.hasTeam = hasTeam; this.coloredTag = tag.color(color); + this.tag = GroupProvider.OPEN.append(coloredTag).append(GroupProvider.CLOSE); this.hasDefaultLoginMessage = hasDefaultLoginMessage; + tempWeight = WeightNode.builder(weight).build(); + tempPrefix = PrefixNode.builder(FUtil.miniMessage(getTag()), weight).build(); + + permissions.addAll(matched.getNodes(NodeType.PERMISSION)); + + if (!matched.getNodes(NodeType.PREFIX).contains(tempPrefix)) matched.data().add(tempPrefix); + else tempPrefix = matched.getNodes(NodeType.PREFIX).iterator().next(); + + if (!matched.getNodes(NodeType.WEIGHT).contains(tempWeight)) matched.data().add(tempWeight); + else tempWeight = matched.getNodes(NodeType.WEIGHT).iterator().next(); + + this.prefix = tempPrefix; + this.weight = tempWeight; + this.group = matched; + this.inheritance = InheritanceNode.builder(this.group).build(); + this.save(); + } + + /** + * Checks the weight of this rank instance against the given rank. + * + * @param rank The rank to check against. + * @return True if the given rank is less than or equal to the weight of this specific rank instance. + */ + public boolean weightCheckAgainst(@NotNull DisplayableGroup rank) + { + return rank.getWeight().getWeight() <= getWeight().getWeight(); + } + + public void addPermission(String permission) + { + PermissionNode node = PermissionNode.builder(permission).build(); + for (PermissionNode it : group.getNodes(NodeType.PERMISSION)) + { + if (it.getContexts().isSatisfiedBy(node.getContexts()) + || it.getKey().equals(node.getKey())) + continue; + + group.data().add(node); + permissions.add(node); + save(); + } } - public boolean isAtLeast(@NotNull DisplayableGroup rank) + public void removePermission(String permission) { - return rank.getLuckPermsGroup().getWeight().orElse(0) - <= getLuckPermsGroup().getWeight().orElse(0); + PermissionNode node = PermissionNode.builder(permission).build(); + for (PermissionNode it : group.getNodes(NodeType.PERMISSION)) + { + if (it.getContexts().isSatisfiedBy(node.getContexts(), ContextSatisfyMode.AT_LEAST_ONE_VALUE_PER_KEY) + || it.getKey().equals(node.getKey())) + { + group.data().remove(node); + permissions.remove(node); + save(); + } + } } - public int getWeight() + public WeightNode getWeight() { return weight; } @@ -181,4 +210,24 @@ public boolean hasDefaultLoginMessage() { return hasDefaultLoginMessage; } + + public InheritanceNode getInheritance() + { + return inheritance; + } + + public PrefixNode getPrefix() + { + return prefix; + } + + public List getPermissions() + { + return permissions; + } + + public void save() + { + TotalFreedomMod.getPlugin().getHierarchy().gw().saveGroup(group.getName()); + } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java index 172dc14b2..974bba0a0 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java @@ -1,51 +1,130 @@ package me.totalfreedom.totalfreedommod.rank; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.luckperms.api.model.user.User; -import net.luckperms.api.track.TrackManager; +import net.luckperms.api.model.group.Group; +import net.luckperms.api.node.types.InheritanceNode; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import java.util.Set; +import java.util.stream.Stream; -@FunctionalInterface -public interface GroupProvider +public class GroupProvider { - Component OPEN = Component.text("[", NamedTextColor.DARK_GRAY); - Component CLOSE = Component.text("]", NamedTextColor.DARK_GRAY); + public static final Component OPEN = Component.text("[", NamedTextColor.DARK_GRAY); + public static final Component CLOSE = Component.text("]", NamedTextColor.DARK_GRAY); - GroupProvider NON_OP = () -> new DisplayableGroup("default", null, Component.text("Non-Ops"), Component.empty(), 0, NamedTextColor.WHITE, null, false, false); - GroupProvider OP = () -> new DisplayableGroup("op", "default", Component.text("Operators"), Component.text("Op"), 1, NamedTextColor.GREEN, null, false, false); - GroupProvider MASTER_BUILDER = () -> new DisplayableGroup("builder", "op", Component.text("Master Builders"), Component.text("MB"), 2, NamedTextColor.DARK_AQUA, ChatColor.DARK_AQUA, true, true); - GroupProvider ADMIN = () -> new DisplayableGroup("admin", "builder", Component.text("Administrators"), Component.text("Admin"), 3, NamedTextColor.DARK_GREEN, ChatColor.DARK_GREEN, true, true); - GroupProvider SENIOR_ADMIN = () -> new DisplayableGroup("senior", "admin", Component.text("Senior Administrators"), Component.text("SrA"), 4, NamedTextColor.GOLD, ChatColor.GOLD, true, true); + private final DisplayableGroup nonOp; + private final DisplayableGroup op; + private final DisplayableGroup masterBuilder; + private final DisplayableGroup admin; + private final DisplayableGroup seniorAdmin; - static User getUser(Player player) + public GroupProvider() { - return TotalFreedomMod.getPlugin() - .lpb.getAPI() - .getPlayerAdapter(Player.class) - .getUser(player); + this.nonOp = new DisplayableGroup( + "default", + Component.text("Non-Ops"), + Component.empty(), + 0, + NamedTextColor.WHITE, + null, + false, + false); + + this.op = new DisplayableGroup( + "op", + Component.text("Operators"), + Component.text("Op"), + 1, + NamedTextColor.GREEN, + null, + false, + false); + + this.masterBuilder = new DisplayableGroup( + "builder", + Component.text("Master Builders"), + Component.text("MB"), + 2, + NamedTextColor.DARK_AQUA, + ChatColor.DARK_AQUA, + true, + true); + + this.admin = new DisplayableGroup( + "admin", + Component.text("Administrators"), + Component.text("Admin"), + 3, + NamedTextColor.DARK_GREEN, + ChatColor.DARK_GREEN, + true, + true); + + this.seniorAdmin = new DisplayableGroup( + "senior", + Component.text("Senior Administrators"), + Component.text("SrA"), + 4, + NamedTextColor.GOLD, + ChatColor.GOLD, + true, + true); + + nonOp.save(); + op.save(); + masterBuilder.save(); + admin.save(); + seniorAdmin.save(); } - static GroupProvider fromArgument(String arg) + public DisplayableGroup getNonOp() { - return switch (arg.toLowerCase()) - { - case "op" -> OP; - case "builder" -> MASTER_BUILDER; - case "admin" -> ADMIN; - case "senior" -> SENIOR_ADMIN; - default -> NON_OP; - }; + return nonOp; + } + + public DisplayableGroup getOp() + { + return op; + } + + public DisplayableGroup getMasterBuilder() + { + return masterBuilder; } - static Set> providerSet() + public DisplayableGroup getAdmin() { - return Set.of(NON_OP, OP, MASTER_BUILDER, ADMIN, SENIOR_ADMIN); + return admin; } - T getGroup(); + public DisplayableGroup getSeniorAdmin() + { + return seniorAdmin; + } + + public InheritanceNode inheritanceNode(DisplayableGroup group) + { + return InheritanceNode.builder(group.getLuckPermsGroup()).build(); + } + + public DisplayableGroup fromLuckPerms(Group group) + { + return Stream.of(nonOp, op, masterBuilder, admin, seniorAdmin) + .filter(displayableGroup -> displayableGroup.getLuckPermsGroup().equals(group)) + .findFirst() + .orElse(nonOp); + } + + public DisplayableGroup fromString(String arg) + { + return switch (arg.toLowerCase()) + { + case "op" -> op; + case "builder" -> masterBuilder; + case "admin" -> admin; + case "senior" -> seniorAdmin; + default -> nonOp; + }; + } } \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java index d3455bb70..91bbf21e4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java @@ -1,193 +1,147 @@ package me.totalfreedom.totalfreedommod.rank; import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.perms.GroupWrapper; +import me.totalfreedom.totalfreedommod.perms.TrackWrapper; +import me.totalfreedom.totalfreedommod.perms.UserData; +import me.totalfreedom.totalfreedommod.perms.UserWrapper; import me.totalfreedom.totalfreedommod.util.FLog; -import net.luckperms.api.LuckPerms; import net.luckperms.api.model.group.Group; import net.luckperms.api.model.user.User; -import net.luckperms.api.query.QueryOptions; +import net.luckperms.api.node.NodeType; +import net.luckperms.api.node.types.InheritanceNode; +import net.luckperms.api.platform.PlayerAdapter; +import net.luckperms.api.track.DemotionResult; import net.luckperms.api.track.PromotionResult; import net.luckperms.api.track.Track; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicReference; +import org.bukkit.entity.Player; public class Hierarchy { - private final LuckPerms lp; - private final Track track; + private final GroupWrapper groupWrapper; + private final TrackWrapper trackWrapper; + private final UserWrapper userWrapper; + private final PlayerAdapter playerAdapter; + private final GroupProvider groupProvider; - public Hierarchy(String name) + public Hierarchy() { - this.lp = TotalFreedomMod.getPlugin().lpb.getAPI(); - - if (lp == null) - { - throw new IllegalStateException("LuckPerms not found!"); - } - - if (!lp.getTrackManager().isLoaded(name)) - { - this.track = lp.getTrackManager().createAndLoadTrack(name).whenComplete((ignored, throwable) -> - { - if (throwable != null) - { - throw new IllegalStateException("Failed to create track " + name, throwable); - } - }).join(); // Block and wait for the track to load. - } else - { - this.track = lp.getTrackManager().getTrack(name); - } + this.playerAdapter = TotalFreedomMod.getPlugin().lpb.getAPI().getPlayerAdapter(Player.class); + this.groupWrapper = new GroupWrapper(TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager()); + this.trackWrapper = new TrackWrapper(TotalFreedomMod.getPlugin().lpb.getAPI().getTrackManager()); + this.userWrapper = new UserWrapper(TotalFreedomMod.getPlugin().lpb.getAPI().getUserManager(), getPlayerAdapter()); + this.groupProvider = new GroupProvider(); } - public void addGroup(DisplayableGroup group) + public TrackWrapper tw() { - updateAppend(group.getLuckPermsGroup()).join(); // wait for the group to be updated. + return trackWrapper; } - public void addGroup(Group group, int index) + public GroupWrapper gw() { - updateInsert(group, index).join(); // wait for the group to be updated. + return groupWrapper; } - public void dropGroup(Group group) // This is non-blocking by default. + public UserWrapper uw() { - updateDrop(group).whenComplete((ignored, throwable) -> - { - if (throwable != null) - { - FLog.severe("Failed to update track " + track.getName()); - } - }); + return userWrapper; } - public void addGroupNonBlocking(Group group, int index) + public PlayerAdapter getPlayerAdapter() { - updateInsert(group, index).whenComplete((ignored, throwable) -> - { - if (throwable != null) - { - FLog.severe("Failed to update track " + track.getName()); - } - }); + return playerAdapter; } - public CompletableFuture trackUser(User user) + public boolean isUserOnAdminTrack(Player player) { - Group group = fromName(track.getGroups().get(0)); // First group. + User user = uw().getUser(player); + return user + .getNodes(NodeType.INHERITANCE) + .contains(groups().inheritanceNode(groups().getAdmin())); + } - return CompletableFuture.supplyAsync(() -> - lp.getContextManager() - .getContext(user) - .map(context -> user - .getInheritedGroups(QueryOptions.defaultContextualOptions()) - .add(group)) - .orElse(false)); + public GroupProvider groups() + { + return groupProvider; } - public CompletableFuture promoteUser(User user) + public Track op() { - boolean empty = user.getInheritedGroups(QueryOptions.defaultContextualOptions()) - .stream() - .filter(group -> track.getGroups().contains(group.getName())) - .findFirst() - .isEmpty(); + return tw().getTrack("op"); + } - if (empty) trackUser(user).whenComplete((ignored, throwable) -> - { - if (throwable != null) - { - FLog.severe("Failed to track user " + user.getFriendlyName()); - } - }); + public Track builder() + { + return tw().getTrack("BUILDER"); + } - return CompletableFuture.supplyAsync(() -> - { - AtomicReference result = new AtomicReference<>(); - lp.getContextManager() - .getContext(user) - .ifPresent(context -> result.set(track.promote(user, context))); - return result.get(); - }); + public Track admin() + { + return tw().getTrack("admin"); } - public void dropUserFromAll(User user) + public void asyncInheritFrom(DisplayableGroup inherited, DisplayableGroup inheritor) { - for (String group : track.getGroups()) - { - dropUserFromGroup(user, fromName(group)) - .whenComplete((ignored, throwable) -> - { - if (throwable != null) - { - FLog.severe("Failed to drop user " - + user.getFriendlyName() - + " from group " - + group); - return; - } - FLog.info("Successfully removed " + user.getFriendlyName() + " from group " + group); - }); - } + inheritor + .getLuckPermsGroup() + .data() + .add(inherited.getInheritance()); + + gw().saveGroup(inheritor + .getLuckPermsGroup() + .getName()); + + FLog.info("Inherited " + inherited.getName() + " to " + inheritor.getName()); } - public CompletableFuture demoteUser(User user) + public Group getGroup(String name) { - return CompletableFuture.supplyAsync(() -> { - lp.getContextManager() - .getContext(user) - .ifPresent(context -> track.demote(user, context)); - return null; - }); + return gw().getGroup(name); } - public CompletableFuture dropUserFromGroup(User user, Group group) + public void asyncTrackGroup(Track track, DisplayableGroup group) { - return CompletableFuture.supplyAsync(() -> user - .getInheritedGroups(QueryOptions.defaultContextualOptions()) - .remove(group)); + Track t = tw().getTrack(track.getName()); + t.appendGroup(group.getLuckPermsGroup()); + tw().saveTrack(t.getName()); + gw().saveGroup(group.getLuckPermsGroup().getName()); + FLog.info("Added " + group.getName() + " to track " + track.getName()); } - public Group fromName(String name) + public PromotionResult promoteUser(Track track, Player player) { - return lp.getGroupManager().getGroup(name); + User user = UserData.fromPlayer(player); + return track.promote(user, UserData.getContextSet(user)); } - public CompletableFuture updateAppend(Group group) + public DemotionResult demoteUser(Track track, Player player) { - return CompletableFuture.supplyAsync(() -> - { - if (!track.containsGroup(group.getName())) - { - track.appendGroup(group); - } - return null; - }); + User user = UserData.fromPlayer(player); + return track.demote(user, UserData.getContextSet(user)); } - public CompletableFuture updateInsert(Group group, int index) + public void addUserToGroup(DisplayableGroup group, Player player) { - return CompletableFuture.supplyAsync(() -> - { - if (!track.containsGroup(group)) - { - track.insertGroup(group, index); - } - return null; - }); + User user = UserData.fromPlayer(player); + uw().addToGroup(user, group); + FLog.info("Successfully added " + player.getName() + " to " + group.getName()); } - public CompletableFuture updateDrop(Group group) + public void dropUser(Track track, Player player) { - return CompletableFuture.supplyAsync(() -> - { - if (track.containsGroup(group)) - { - track.removeGroup(group); - } + User user = UserData.fromPlayer(player); - return null; - }); + for (String group : track.getGroups()) + { + Group g = gw().getGroup(group); + InheritanceNode node = groups() + .fromLuckPerms(g) + .getInheritance(); + + if (user.getNodes(NodeType.INHERITANCE).contains(node)) + uw().removeFromGroup(user, groups() + .fromLuckPerms(g)); + } } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/HierarchyProvider.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/HierarchyProvider.java deleted file mode 100644 index 4ee9fa5f6..000000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/HierarchyProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.totalfreedom.totalfreedommod.rank; - -@FunctionalInterface -public interface HierarchyProvider -{ - HierarchyProvider OP = () -> new Hierarchy("op-track"); - HierarchyProvider BUILDER = () -> new Hierarchy("builder-track"); - HierarchyProvider ADMIN = () -> new Hierarchy("admin-track"); - - T getHierarchy(); -} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index 0fb2ff70e..47dde2db6 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.rank; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; @@ -25,11 +26,17 @@ public class RankManager extends FreedomService @Override public void onStart() { - HierarchyProvider.OP.getHierarchy().addGroup(GroupProvider.NON_OP.getGroup()); - HierarchyProvider.OP.getHierarchy().addGroup(GroupProvider.OP.getGroup()); - HierarchyProvider.BUILDER.getHierarchy().addGroup(GroupProvider.MASTER_BUILDER.getGroup()); - HierarchyProvider.ADMIN.getHierarchy().addGroup(GroupProvider.ADMIN.getGroup()); - HierarchyProvider.ADMIN.getHierarchy().addGroup(GroupProvider.SENIOR_ADMIN.getGroup()); + + // Here, we are automatically creating new tracks if they don't exist, and then adding groups to them. + Hierarchy hierarchy = TotalFreedomMod.getPlugin().getHierarchy(); + hierarchy.asyncTrackGroup(hierarchy.op(), hierarchy.groups().getNonOp()); + hierarchy.asyncTrackGroup(hierarchy.op(), hierarchy.groups().getOp()); + hierarchy.asyncTrackGroup(hierarchy.builder(), hierarchy.groups().getMasterBuilder()); + hierarchy.asyncTrackGroup(hierarchy.admin(), hierarchy.groups().getAdmin()); + hierarchy.asyncTrackGroup(hierarchy.admin(), hierarchy.groups().getSeniorAdmin()); + + hierarchy.asyncInheritFrom(hierarchy.groups().getNonOp(), hierarchy.groups().getOp()); + hierarchy.asyncInheritFrom(hierarchy.groups().getAdmin(), hierarchy.groups().getSeniorAdmin()); } @Override @@ -71,7 +78,7 @@ public Displayable getDisplay(CommandSender sender) // Master builders show up if they are not an admin if (plugin.pl.getData(player).isMasterBuilder() && !plugin.al.isAdmin(player)) { - return Title.MASTER_BUILDER; + return TotalFreedomMod.getPlugin().getHierarchy().groups().getMasterBuilder(); } return getRank(player); @@ -107,13 +114,13 @@ public DisplayableGroup getRank(CommandSender sender) } // CONSOLE? - if (sender instanceof ConsoleCommandSender console) + if (sender instanceof ConsoleCommandSender) { if (sender.getName().equalsIgnoreCase("CONSOLE")) { return ConfigEntry.ADMINLIST_CONSOLE_IS_ADMIN.getBoolean() - ? GroupProvider.SENIOR_ADMIN.getGroup() - : GroupProvider.ADMIN.getGroup(); + ? TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin() + : TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin(); } } @@ -123,7 +130,7 @@ public DisplayableGroup getRank(CommandSender sender) // Unknown console: RCON? if (admin == null) { - return GroupProvider.SENIOR_ADMIN.getGroup(); + return TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin(); } return admin.getRank(); @@ -137,13 +144,16 @@ public DisplayableGroup getRank(Player player) return entry.getRank(); } - return plugin.lpb.getAPI() - .getPlayerAdapter(Player.class) + String primary = TotalFreedomMod.getPlugin() + .getHierarchy() + .getPlayerAdapter() .getUser(player) - .getPrimaryGroup() - .equalsIgnoreCase("op") - ? GroupProvider.OP.getGroup() - : GroupProvider.NON_OP.getGroup(); + .getPrimaryGroup(); + + return TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .fromString(primary); } public Component getTag(Player player, Component defaultTag) @@ -176,7 +186,7 @@ public void updateDisplay(Player player) } else { fPlayer.setTag(null); - player.setPlayerListName(null); + player.playerListName(Component.empty()); } fPlayer.setTag(getTag(player, display.getColoredTag())); @@ -187,6 +197,7 @@ public void updateDisplay(Player player) public void onPlayerJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); + PlayerData target = plugin.pl.getData(player); boolean isAdmin = plugin.al.isAdmin(player); @@ -238,6 +249,12 @@ public Component craftLoginMessage(Player player, String message) } if (message != null) { + if (!(message.contains(""))) + { + player.sendMessage(FUtil.miniMessage("You did not include the tag in your login message! We will append it for you.")); + message = " is " + message; + } + return FUtil.miniMessage(message, Placeholder.unparsed("name", player.getName()), Placeholder.component("rank", display.getName()), diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index 5c4b200d0..b8a77117e 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -82,7 +82,7 @@ public void checkTables() private void createPlayersTable() { - try (PreparedStatement statement = connection.prepareStatement("CREATE TABLE `players` (`uuid` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `master_builder` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `login_message` VARCHAR, `inspect` BOOLEAN NOT NULL);")) + try (PreparedStatement statement = connection.prepareStatement("CREATE TABLE `players` (`uuid` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `masterBuilder` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `login_message` VARCHAR, `inspect` BOOLEAN NOT NULL);")) { statement.executeUpdate(); } catch (SQLException e) @@ -281,8 +281,8 @@ public ResultSet getPlayerByUuid(UUID uuid) try { PreparedStatement statement = connection.prepareStatement("SELECT * FROM players WHERE uuid=?"); - statement.setString(1, uuid.toString()); - ResultSet resultSet = statement.executeQuery(); + statement.setString(1, uuid.toString()); + ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { @@ -301,7 +301,7 @@ public ResultSet getMasterBuilders() { try { - return connection.prepareStatement("SELECT * FROM players WHERE master_builder=true").executeQuery(); + return connection.prepareStatement("SELECT * FROM players WHERE masterBuilder=true").executeQuery(); } catch (SQLException e) { FLog.severe("Failed to get Master Builders:"); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java index 5d036827e..ff0e792e4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FConverter.java @@ -14,10 +14,10 @@ public static boolean needsConversion(String messageOrFormat) public static String convertAdminChatFormat(String format) { return FUtil.MINI_MESSAGE.serialize(FUtil.LEGACY_AMPERSAND.deserialize( - format.replaceAll("%name%", "") - .replaceAll("%rank%", "") - .replaceAll("%rankcolor%", "") - .replaceAll("%msg%", ""))) + format.replaceAll("%name%", "") + .replaceAll("%rank%", "") + .replaceAll("%rankcolor%", "") + .replaceAll("%msg%", ""))) .replaceAll("\\\\<", "<"); // GOD FUCKING DAMMIT } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java index 5bab9a8f4..8187da88b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java @@ -83,8 +83,7 @@ private static Logger getLogger(boolean raw) if (raw || pluginLogger == null) { return (serverLogger != null ? serverLogger : FALLBACK_LOGGER); - } - else + } else { return pluginLogger; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index eadb880bc..a1b3af00b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -13,7 +13,10 @@ import net.kyori.adventure.title.Title; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.WordUtils; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @@ -21,7 +24,7 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -import java.io.*; +import java.io.File; import java.lang.management.ManagementFactory; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -80,8 +83,6 @@ public class FUtil "Taahh", "G6_", "ayunami2000"); - - private static final PlainTextComponentSerializer STEAMROLLER = PlainTextComponentSerializer.plainText(); public static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.legacyAmpersand(); public static final LegacyComponentSerializer LEGACY_SECTION = LegacyComponentSerializer.legacySection(); public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(TagResolver.resolver( @@ -106,10 +107,11 @@ public class FUtil ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE); + private static final PlainTextComponentSerializer STEAMROLLER = PlainTextComponentSerializer.plainText(); private static final Pattern CHATCOLOR_PATTERN = Pattern.compile(".*(?i)(([§&])((#[a-f0-9]{3,6})|([0-9a-fklmnor]))).*"); private static final SplittableRandom RANDOM = new SplittableRandom(); - public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; private static final List regxList = Arrays.asList("y", "mo", "w", "d", "h", "m", "s"); + public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static void cancel(BukkitTask task) { @@ -121,8 +123,7 @@ public static void cancel(BukkitTask task) try { task.cancel(); - } - catch (Exception ignored) + } catch (Exception ignored) { } } @@ -139,8 +140,7 @@ public static boolean isDeveloper(Player player) if (Bukkit.getOnlineMode()) { return DEVELOPERS.contains(player.getUniqueId().toString()); - } - else + } else { return DEVELOPER_NAMES.contains(player.getName()); } @@ -202,17 +202,14 @@ public static List getPageFromList(List list, int size, int inde if (size >= list.size()) { return list; - } - else if (size * (index + 1) <= list.size()) + } else if (size * (index + 1) <= list.size()) { return list.subList(size * index, size * (index + 1)); - } - else + } else { return list.subList(size * index, (size * index) + (list.size() % size)); } - } - catch (IndexOutOfBoundsException e) + } catch (IndexOutOfBoundsException e) { return new ArrayList<>(); } @@ -320,7 +317,8 @@ private static long a(String parse) { StringBuilder sb = new StringBuilder(); - regxList.forEach(obj -> { + regxList.forEach(obj -> + { if (parse.endsWith(obj)) { sb.append(parse.split(obj)[0]); @@ -397,8 +395,7 @@ public static Date stringToDate(String dateString) try { return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).parse(dateString); - } - catch (ParseException pex) + } catch (ParseException pex) { return new Date(0L); } @@ -424,8 +421,7 @@ public static boolean fuzzyIpMatch(String a, String b, int octets) if (octets > 4) { octets = 4; - } - else if (octets < 1) + } else if (octets < 1) { octets = 1; } @@ -569,8 +565,7 @@ public static boolean isPaper() { Class.forName("com.destroystokyo.paper.PaperConfig"); return true; - } - catch (ClassNotFoundException ignored) + } catch (ClassNotFoundException ignored) { return false; } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/PermissibleCompletion.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/PermissibleCompletion.java index 251cab732..89def1df5 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/PermissibleCompletion.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/PermissibleCompletion.java @@ -5,12 +5,17 @@ public class PermissibleCompletion private final String permission; private final String completion; - public PermissibleCompletion(String permission, String completion) + protected PermissibleCompletion(String permission, String completion) { this.completion = completion; this.permission = permission; } + public static PermissibleCompletion of(String permission, String completion) + { + return new PermissibleCompletion(permission, completion); + } + public String getPermission() { return permission; @@ -20,9 +25,4 @@ public String getCompletion() { return completion; } - - public static PermissibleCompletion of(String permission, String completion) - { - return new PermissibleCompletion(permission, completion); - } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/TimeUnit.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/TimeUnit.java index 20132d0a3..5ffe521d3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/TimeUnit.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/TimeUnit.java @@ -12,11 +12,13 @@ public enum TimeUnit private final long time; - TimeUnit(long time) { + TimeUnit(long time) + { this.time = time; } - public long get() { + public long get() + { return time; } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java index 2a230017f..35ff954cb 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java @@ -1,21 +1,17 @@ package me.totalfreedom.totalfreedommod.world; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerMoveEvent; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + public final class AdminWorld extends CustomWorld { @@ -57,9 +53,9 @@ protected World generateWorld() final Block welcomeSignBlock = world.getBlockAt(0, 50, 0); welcomeSignBlock.setType(Material.OAK_SIGN); - org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState(); + org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState(); - org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData(); + org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData(); signData.setFacingDirection(BlockFace.NORTH); welcomeSign.setLine(0, ChatColor.GREEN + "AdminWorld"); @@ -78,8 +74,7 @@ public boolean validateMovement(PlayerMoveEvent event) try { world = getWorld(); - } - catch (Exception ex) + } catch (Exception ex) { return true; } @@ -115,8 +110,7 @@ public void setWeatherMode(final WorldWeather weatherMode) try { weatherMode.setWorldToWeather(getWorld()); - } - catch (Exception ignored) + } catch (Exception ignored) { } } @@ -133,8 +127,7 @@ public void setTimeOfDay(final WorldTime timeOfDay) try { timeOfDay.setWorldToTime(getWorld()); - } - catch (Exception ignored) + } catch (Exception ignored) { } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java index 8d0b9bd6d..ec8420a5a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CleanroomChunkGenerator.java @@ -18,14 +18,16 @@ package me.totalfreedom.totalfreedommod.world; -import java.util.Arrays; -import java.util.Random; -import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.Random; +import java.util.logging.Logger; + import static java.lang.System.arraycopy; public class CleanroomChunkGenerator extends ChunkGenerator @@ -108,8 +110,7 @@ public CleanroomChunkGenerator(String id) arraycopy(materials, 0, newMaterials, 0, y); materials = newMaterials; } - } - catch (Exception e) + } catch (Exception e) { log.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString()); e.printStackTrace(); @@ -118,8 +119,7 @@ public CleanroomChunkGenerator(String id) materials[0] = Material.BEDROCK; Arrays.fill(materials, 1, 65, Material.STONE); } - } - else + } else { materials = new Material[65]; materials[0] = Material.BEDROCK; diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java index 9ef3392ab..79b6098e3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java @@ -48,8 +48,7 @@ public void sendToWorld(Player player) try { PaperLib.teleportAsync(player, getWorld().getSpawnLocation()); - } - catch (Exception ex) + } catch (Exception ex) { player.sendMessage(ex.getMessage()); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java index 790a6f335..d3ea460d2 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java @@ -1,12 +1,7 @@ package me.totalfreedom.totalfreedommod.world; import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -43,9 +38,9 @@ protected World generateWorld() final Block welcomeSignBlock = world.getBlockAt(0, 50, 0); welcomeSignBlock.setType(Material.OAK_SIGN); - org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState(); + org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState(); - org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData(); + org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData(); signData.setFacingDirection(BlockFace.NORTH); welcomeSign.setLine(0, ChatColor.GREEN + "Flatlands"); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/MasterBuilderWorld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/MasterBuilderWorld.java index 2d35349fe..5c4b2036f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/MasterBuilderWorld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/MasterBuilderWorld.java @@ -1,11 +1,7 @@ package me.totalfreedom.totalfreedommod.world; import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -48,9 +44,9 @@ protected World generateWorld() final Block welcomeSignBlock = world.getBlockAt(0, 50, 0); welcomeSignBlock.setType(Material.OAK_SIGN); - org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState(); + org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState(); - org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData(); + org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData(); signData.setFacingDirection(BlockFace.NORTH); welcomeSign.setLine(0, ChatColor.GREEN + "MB World"); @@ -75,8 +71,7 @@ public void setWeatherMode(final WorldWeather weatherMode) try { weatherMode.setWorldToWeather(getWorld()); - } - catch (Exception ignored) + } catch (Exception ignored) { } } @@ -93,8 +88,7 @@ public void setTimeOfDay(final WorldTime timeOfDay) try { timeOfDay.setWorldToTime(getWorld()); - } - catch (Exception ignored) + } catch (Exception ignored) { } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index 579da910c..0eb484172 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -12,6 +12,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.weather.ThunderChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent; + import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; public class WorldManager extends FreedomService @@ -64,13 +65,11 @@ public void onThunderChange(ThunderChangeEvent event) if (event.getWorld().equals(adminworld.getWorld()) && adminworld.getWeatherMode() != WorldWeather.OFF) { return; - } - else if (event.getWorld().equals(masterBuilderWorld.getWorld()) && masterBuilderWorld.getWeatherMode() != WorldWeather.OFF) + } else if (event.getWorld().equals(masterBuilderWorld.getWorld()) && masterBuilderWorld.getWeatherMode() != WorldWeather.OFF) { return; } - } - catch (Exception ignored) + } catch (Exception ignored) { } @@ -88,13 +87,11 @@ public void onWeatherChange(WeatherChangeEvent event) if (event.getWorld().equals(adminworld.getWorld()) && adminworld.getWeatherMode() != WorldWeather.OFF) { return; - } - else if (event.getWorld().equals(masterBuilderWorld.getWorld()) && masterBuilderWorld.getWeatherMode() != WorldWeather.OFF) + } else if (event.getWorld().equals(masterBuilderWorld.getWorld()) && masterBuilderWorld.getWeatherMode() != WorldWeather.OFF) { return; } - } - catch (Exception ignored) + } catch (Exception ignored) { } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java index 3017b8d5f..acfae5475 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java @@ -16,7 +16,8 @@ import java.util.Arrays; import java.util.List; -public class WorldRestrictions extends FreedomService { +public class WorldRestrictions extends FreedomService +{ private final List BLOCKED_WORLDEDIT_COMMANDS = Arrays.asList( "green", "fixlava", "fixwater", "br", "brush", "tool", "mat", "range", "cs", "up", "fill", "setblock", "tree", "replacenear", "bigtree"); @@ -25,17 +26,21 @@ public class WorldRestrictions extends FreedomService { "bigtree", "ebigtree", "largetree", "elargetree"); @Override - public void onStart() { + public void onStart() + { } @Override - public void onStop() { + public void onStop() + { } - public boolean doRestrict(Player player) { + public boolean doRestrict(Player player) + { if (!plugin.pl.getData(player).isMasterBuilder() && plugin.pl.canManageMasterBuilders(player.getName()) - && (player.getWorld().equals(plugin.wm.masterBuilderWorld.getWorld()))) { + && (player.getWorld().equals(plugin.wm.masterBuilderWorld.getWorld()))) + { return true; } @@ -44,71 +49,86 @@ public boolean doRestrict(Player player) { } @EventHandler(priority = EventPriority.NORMAL) - public void onBlockPlace(BlockPlaceEvent event) { + public void onBlockPlace(BlockPlaceEvent event) + { final Player player = event.getPlayer(); - if (doRestrict(player)) { + if (doRestrict(player)) + { event.setCancelled(true); } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent event) { + public void onBlockBreak(BlockBreakEvent event) + { final Player player = event.getPlayer(); - if (doRestrict(player)) { + if (doRestrict(player)) + { event.setCancelled(true); } } @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerInteract(PlayerInteractEvent event) { + public void onPlayerInteract(PlayerInteractEvent event) + { final Player player = event.getPlayer(); - if (doRestrict(player)) { + if (doRestrict(player)) + { event.setCancelled(true); } } @EventHandler(priority = EventPriority.NORMAL) - public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) { + public void onArmorStandManipulate(PlayerArmorStandManipulateEvent event) + { final Player player = event.getPlayer(); - if (doRestrict(player)) { + if (doRestrict(player)) + { event.setCancelled(true); } } @EventHandler(priority = EventPriority.NORMAL) - public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if (event.getDamager() instanceof Player player && (doRestrict(player))) { - event.setCancelled(true); + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) + { + if (event.getDamager() instanceof Player player && (doRestrict(player))) + { + event.setCancelled(true); } } @EventHandler(priority = EventPriority.NORMAL) - public void onCommandPreprocess(PlayerCommandPreprocessEvent event) { + public void onCommandPreprocess(PlayerCommandPreprocessEvent event) + { final Player player = event.getPlayer(); String command = event.getMessage().split("\\s+")[0].substring(1).toLowerCase(); - if (doRestrict(player)) { + if (doRestrict(player)) + { /* This is a very poor way of blocking WorldEdit commands, all the methods I know of for obtaining a list of a plugin's commands are returning null for world edit. */ String allowed = player.getWorld().equals(plugin.wm.adminworld.getWorld()) ? "Admins" : "Master Builders"; - if (command.startsWith("/") || BLOCKED_WORLDEDIT_COMMANDS.contains(command)) { + if (command.startsWith("/") || BLOCKED_WORLDEDIT_COMMANDS.contains(command)) + { player.sendMessage(ChatColor.RED + "Only " + allowed + " are allowed to use WorldEdit here."); event.setCancelled(true); } - if (command.equalsIgnoreCase("coreprotect") || command.equalsIgnoreCase("core") || command.equalsIgnoreCase("co")) { + if (command.equalsIgnoreCase("coreprotect") || command.equalsIgnoreCase("core") || command.equalsIgnoreCase("co")) + { player.sendMessage(ChatColor.RED + "Only " + allowed + " are allowed to use CoreProtect here."); event.setCancelled(true); } } if (player.getWorld().equals(Bukkit.getWorld("plotworld")) - && (BLOCKED_ESSENTIALS_COMMANDS.contains(command))) { + && (BLOCKED_ESSENTIALS_COMMANDS.contains(command))) + { player.sendMessage(ChatColor.RED + "Sorry, this command is restricted in the plotworld"); event.setCancelled(true); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldTime.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldTime.java index 0b5fd5e7e..878b2af2f 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldTime.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldTime.java @@ -1,10 +1,11 @@ package me.totalfreedom.totalfreedommod.world; -import java.util.Arrays; -import java.util.List; import org.apache.commons.lang.StringUtils; import org.bukkit.World; +import java.util.Arrays; +import java.util.List; + public enum WorldTime { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldWeather.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldWeather.java index ef5cf5cb0..14d28a0fc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldWeather.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/world/WorldWeather.java @@ -1,10 +1,11 @@ package me.totalfreedom.totalfreedommod.world; -import java.util.Arrays; -import java.util.List; import org.apache.commons.lang.StringUtils; import org.bukkit.World; +import java.util.Arrays; +import java.util.List; + public enum WorldWeather { diff --git a/commons/src/main/resources/config.yml b/commons/src/main/resources/config.yml index 74fc754a8..8d7bcd2d5 100644 --- a/commons/src/main/resources/config.yml +++ b/commons/src/main/resources/config.yml @@ -32,7 +32,7 @@ server: executives: [ ] # All players who show up as assistant executive - assistant_executives: [] + assistant_executives: [ ] # All those who can manage the master builder list master_builder_management: [ ] @@ -181,7 +181,7 @@ social_links: Forum: 'https://forum.totalfreedom.me' Website: 'https://totalfreedom.me' Discord: 'https://discord.com/invite/PW4savJR9a' -# Reddit: 'https://reddit.com/r/TotalFreedom' + # Reddit: 'https://reddit.com/r/TotalFreedom' Twitter: 'https://twitter.com/TotalFreedomMC' Facebook: 'https://facebook.com/TotalFreedomMC' # Tumblr: 'https://totalfreedom.tumblr.com' @@ -530,7 +530,7 @@ announcer: announcements: - 'Be sure to visit our forums at &6https://forum.totalfreedom.me' - 'You can always review the server rules here: &6https://forum.totalfreedom.me/d/7-server-conduct-policy' - - 'If you are not OP, be sure to ask!' + - 'If you are not op, be sure to ask!' - 'Want to join our SMP server? You can using &6/smp-01' - 'Somebody breaking the rules? Report it! &6/report ' - 'Griefing is not allowed!' @@ -564,7 +564,7 @@ admininfo: votinginfo: - '&bVoting Links:' - ' &2- https://minecraft-mp.com/server/228386/vote/' -# - ' &2- https://minecraft-server-list.com/server/443272/vote/' + # - ' &2- https://minecraft-server-list.com/server/443272/vote/' - ' &6- https://topg.org/Minecraft/in-599712' - ' &2- https://minecraftlist.org/vote/18975' - ' &6- https://minecraftservers.org/vote/595721' @@ -585,7 +585,7 @@ masterbuilderinfo: first_join_info: enabled: true text: - - "Welcome to TotalFreedom -- the original Free-OP server!" + - "Welcome to TotalFreedom -- the original Free-op server!" - "The server's name doesn't mean we have no rules. Do /rules for a list of them." - "Need help getting started? Do /help for a list of commands!" diff --git a/commons/src/main/resources/indefinitebans.yml b/commons/src/main/resources/indefinitebans.yml index 4e4404ce7..d561ac284 100644 --- a/commons/src/main/resources/indefinitebans.yml +++ b/commons/src/main/resources/indefinitebans.yml @@ -12,4 +12,4 @@ badplayer2: ips: - 111.111.111.111 badplayer3: - ips: [] + ips: [ ] diff --git a/commons/src/main/resources/permissions.yml b/commons/src/main/resources/permissions.yml index 1c1877d7a..fa2a16295 100644 --- a/commons/src/main/resources/permissions.yml +++ b/commons/src/main/resources/permissions.yml @@ -25,7 +25,7 @@ remove: #Crackshot - "crackshot.bypass.all" #NetworkManager - - "networkmanager.*" + - "networkmanager.*" - "networkmanager.notify.joinbanned" - "networkmanager.notify.*" - "networkmanager.announce.global" @@ -142,7 +142,7 @@ operators: - "networkmanager.notification.join" - "networkmanager.party.nolimit" - "networkmanager.tabcompletechat" - + # Master Builder permission nodes master_builders: - "worldedit.tool.*" @@ -156,7 +156,7 @@ master_builders: - "voxelsniper.sniper" - "voxelsniper.goto" - "voxelsniper.brush.*" - + # Admin permission nodes admins: - "worldedit.*" @@ -175,6 +175,6 @@ admins: - "crackshot.bypass.all" # Senior Admin permission nodes -senior_admins: +senior_admins: - "bending.admin.permaremove" - "bending.ability.Cleanse" diff --git a/commons/src/main/resources/plugin.yml b/commons/src/main/resources/plugin.yml index 657467371..ec1c30558 100644 --- a/commons/src/main/resources/plugin.yml +++ b/commons/src/main/resources/plugin.yml @@ -14,8 +14,8 @@ softdepend: - WorldGuardExtraFlags - JDA - Votifier -authors: [Madgeek1450, Prozza] -loadbefore: [TFD4J, TF-Shoppe] +authors: [ Madgeek1450, Prozza ] +loadbefore: [ TFD4J, TF-Shoppe ] api-version: "1.17" libraries: - org.apache.commons:commons-lang3:3.12.0 diff --git a/discord/pom.xml b/discord/pom.xml index 6560804d0..42d5e80b2 100644 --- a/discord/pom.xml +++ b/discord/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 @@ -36,11 +36,5 @@ 3.5.4 provided - - me.totalfreedom - commons - 2023.03 - compile - \ No newline at end of file diff --git a/discord/src/main/java/me/totalfreedom/discord/Bot.java b/discord/src/main/java/me/totalfreedom/discord/Bot.java index 891e24a58..1f2df9c04 100644 --- a/discord/src/main/java/me/totalfreedom/discord/Bot.java +++ b/discord/src/main/java/me/totalfreedom/discord/Bot.java @@ -2,19 +2,12 @@ import discord4j.core.DiscordClientBuilder; import discord4j.core.GatewayDiscordClient; -import discord4j.core.event.domain.interaction.ChatInputInteractionEvent; import discord4j.core.object.entity.Guild; -import me.totalfreedom.discord.command.HelpCommand; -import me.totalfreedom.discord.command.ListCommand; -import me.totalfreedom.discord.command.TPSCommand; -import me.totalfreedom.discord.handling.CommandHandler; -import me.totalfreedom.discord.react.ReactiveBukkitScheduler; import me.totalfreedom.discord.util.SnowflakeEntry; import me.totalfreedom.discord.util.TFM_Bridge; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FLog; -import org.bukkit.Bukkit; import reactor.core.publisher.Mono; import java.util.HashMap; @@ -25,6 +18,7 @@ public class Bot private final GatewayDiscordClient client; private final TFM_Bridge tfm; private final HashMap LINK_CODES = new HashMap<>(); + public Bot() { //Creates the gateway client and connects to the gateway @@ -36,11 +30,13 @@ public Bot() this.tfm = new TFM_Bridge(this); } - public void initialize() { + public void initialize() + { if (client == null) throw new IllegalStateException(); } - public String formatBotTag() { + public String formatBotTag() + { return client.getSelf() .blockOptional() .orElseThrow() diff --git a/discord/src/main/java/me/totalfreedom/discord/TFD4JCommonsImpl.java b/discord/src/main/java/me/totalfreedom/discord/TFD4JCommonsImpl.java index 00a76d60c..b06f93756 100644 --- a/discord/src/main/java/me/totalfreedom/discord/TFD4JCommonsImpl.java +++ b/discord/src/main/java/me/totalfreedom/discord/TFD4JCommonsImpl.java @@ -12,11 +12,11 @@ import discord4j.core.spec.MessageCreateSpec; import me.totalfreedom.discord.util.SnowflakeEntry; import me.totalfreedom.discord.util.Utilities; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.api.TFD4JCommons; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.util.FLog; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.WordUtils; @@ -173,11 +173,11 @@ public boolean syncRoles(Admin admin, String discordID) return true; } - if (admin.getRank().equals(GroupProvider.ADMIN.getGroup())) + if (admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin())) { syncRolesAdminAssignment(member, adminRole, senioradminRole); return true; - } else if (admin.getRank().equals(GroupProvider.SENIOR_ADMIN.getGroup())) + } else if (admin.getRank().equals(TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin())) { syncRolesSeniorAssignment(member, adminRole, senioradminRole); return true; diff --git a/discord/src/main/java/me/totalfreedom/discord/command/ListCommand.java b/discord/src/main/java/me/totalfreedom/discord/command/ListCommand.java index c11504c5e..f29bbede6 100644 --- a/discord/src/main/java/me/totalfreedom/discord/command/ListCommand.java +++ b/discord/src/main/java/me/totalfreedom/discord/command/ListCommand.java @@ -31,9 +31,11 @@ public Mono handle(ChatInputInteractionEvent event) StringBuilder sb = new StringBuilder(); Iterator iterator = playerNames.iterator(); - while (iterator.hasNext()) { + while (iterator.hasNext()) + { sb.append(iterator.next()); - if (iterator.hasNext()) { + if (iterator.hasNext()) + { sb.append(", \n"); } } diff --git a/discord/src/main/java/me/totalfreedom/discord/handling/SlashCommand.java b/discord/src/main/java/me/totalfreedom/discord/handling/SlashCommand.java index f549cb795..c3839aaa6 100644 --- a/discord/src/main/java/me/totalfreedom/discord/handling/SlashCommand.java +++ b/discord/src/main/java/me/totalfreedom/discord/handling/SlashCommand.java @@ -3,7 +3,8 @@ import discord4j.core.event.domain.interaction.ChatInputInteractionEvent; import reactor.core.publisher.Mono; -public interface SlashCommand { +public interface SlashCommand +{ String getName(); Mono handle(ChatInputInteractionEvent event); diff --git a/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java b/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java index 18b9814a9..40b095362 100644 --- a/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java +++ b/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java @@ -1,6 +1,5 @@ package me.totalfreedom.discord.listener; -import com.google.common.base.Strings; import discord4j.core.event.domain.message.MessageCreateEvent; import discord4j.core.object.entity.Attachment; import discord4j.core.object.entity.Guild; @@ -10,10 +9,7 @@ import me.totalfreedom.discord.TFD4J; import me.totalfreedom.discord.util.SnowflakeEntry; import me.totalfreedom.totalfreedommod.TotalFreedomMod; -import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.api.event.AdminChatEvent; import me.totalfreedom.totalfreedommod.rank.Displayable; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.rank.Title; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -23,10 +19,6 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; public class AdminChatListener { @@ -41,6 +33,11 @@ public AdminChatListener(TFD4J tfd4j) this.bot = tfd4j.getBot(); } + public static Key getIdentifier() + { + return identifier; + } + public void adminChatBound() { tfd4j.getBot() @@ -104,22 +101,17 @@ public Displayable getDisplay(Member member) return Title.ASST_EXEC; } else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake())) { - return GroupProvider.SENIOR_ADMIN.getGroup(); + return TotalFreedomMod.getPlugin().getHierarchy().groups().getSeniorAdmin(); } else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake())) { - return GroupProvider.ADMIN.getGroup(); + return TotalFreedomMod.getPlugin().getHierarchy().groups().getAdmin(); } else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake())) { - return GroupProvider.MASTER_BUILDER.getGroup(); + return TotalFreedomMod.getPlugin().getHierarchy().groups().getMasterBuilder(); } else { - return GroupProvider.OP.getGroup(); // This should never be reached. + return TotalFreedomMod.getPlugin().getHierarchy().groups().getNonOp(); // This should never be reached. } }).blockFirst(); } - - public static Key getIdentifier() - { - return identifier; - } } diff --git a/discord/src/main/java/me/totalfreedom/discord/listener/BukkitNative.java b/discord/src/main/java/me/totalfreedom/discord/listener/BukkitNative.java index eceb040a3..8ad2443b2 100644 --- a/discord/src/main/java/me/totalfreedom/discord/listener/BukkitNative.java +++ b/discord/src/main/java/me/totalfreedom/discord/listener/BukkitNative.java @@ -8,17 +8,14 @@ import me.totalfreedom.totalfreedommod.api.event.AdminChatEvent; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.md_5.bungee.api.ChatColor; import org.bukkit.GameRule; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; diff --git a/discord/src/main/java/me/totalfreedom/discord/listener/MinecraftListener.java b/discord/src/main/java/me/totalfreedom/discord/listener/MinecraftListener.java index 4bd58abe2..644bc969f 100644 --- a/discord/src/main/java/me/totalfreedom/discord/listener/MinecraftListener.java +++ b/discord/src/main/java/me/totalfreedom/discord/listener/MinecraftListener.java @@ -4,7 +4,6 @@ import discord4j.core.object.entity.Attachment; import discord4j.core.object.entity.Member; import discord4j.core.object.entity.Message; -import discord4j.core.object.entity.channel.TextChannel; import me.totalfreedom.discord.Bot; import me.totalfreedom.discord.TFD4J; import me.totalfreedom.discord.util.SnowflakeEntry; diff --git a/discord/src/main/java/me/totalfreedom/discord/react/ReactiveBukkitScheduler.java b/discord/src/main/java/me/totalfreedom/discord/react/ReactiveBukkitScheduler.java index 538d48465..203616312 100644 --- a/discord/src/main/java/me/totalfreedom/discord/react/ReactiveBukkitScheduler.java +++ b/discord/src/main/java/me/totalfreedom/discord/react/ReactiveBukkitScheduler.java @@ -1,6 +1,5 @@ package me.totalfreedom.discord.react; -import java.util.concurrent.TimeUnit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; import org.jetbrains.annotations.NotNull; @@ -8,6 +7,8 @@ import reactor.core.Disposable; import reactor.core.scheduler.Scheduler; +import java.util.concurrent.TimeUnit; + /** * An abstraction layer over the {@link BukkitScheduler} to allow for the use as a {@link Scheduler}. * This will allow us to perform non-blocking operations on the main server thread. @@ -15,7 +16,8 @@ * @author SimplexDevelopment */ public final class ReactiveBukkitScheduler - implements Scheduler, Scheduler.Worker { + implements Scheduler, Scheduler.Worker +{ /** * The plugin instance. */ @@ -25,7 +27,8 @@ public final class ReactiveBukkitScheduler */ private final BukkitScheduler scheduler; - public ReactiveBukkitScheduler(JavaPlugin plugin) { + public ReactiveBukkitScheduler(JavaPlugin plugin) + { this.plugin = plugin; this.scheduler = plugin.getServer().getScheduler(); } @@ -37,7 +40,8 @@ public ReactiveBukkitScheduler(JavaPlugin plugin) { * @return A disposable that can be used to cancel the task. */ @Override - public @NotNull Disposable schedule(@NotNull Runnable task) { + public @NotNull Disposable schedule(@NotNull Runnable task) + { return new DisposableBukkitTask(scheduler.runTask(plugin, task)); } @@ -51,7 +55,8 @@ public ReactiveBukkitScheduler(JavaPlugin plugin) { * @return A disposable that can be used to cancel the task. */ @Override - public @NotNull Disposable schedule(@NotNull Runnable task, long delay, @Deprecated @Nullable TimeUnit unit) { + public @NotNull Disposable schedule(@NotNull Runnable task, long delay, @Deprecated @Nullable TimeUnit unit) + { return new DisposableBukkitTask(scheduler.runTaskLater(plugin, task, delay)); } @@ -67,8 +72,10 @@ public ReactiveBukkitScheduler(JavaPlugin plugin) { * @return A disposable that can be used to cancel the task. */ @Override - public @NotNull Disposable schedulePeriodically(@NotNull Runnable task, long initialDelay, long period, @Deprecated @Nullable TimeUnit unit) { - if (period <= 0L) { + public @NotNull Disposable schedulePeriodically(@NotNull Runnable task, long initialDelay, long period, @Deprecated @Nullable TimeUnit unit) + { + if (period <= 0L) + { throw new IllegalArgumentException("Period must be greater than 0L"); } @@ -81,7 +88,8 @@ public ReactiveBukkitScheduler(JavaPlugin plugin) { * @return This class instance, as it implements {@link Worker}. */ @Override - public @NotNull Scheduler.Worker createWorker() { + public @NotNull Scheduler.Worker createWorker() + { return this; } @@ -90,7 +98,8 @@ public ReactiveBukkitScheduler(JavaPlugin plugin) { */ @Override @Deprecated - public void dispose() { + public void dispose() + { // This method does nothing and is only here because it's being overridden from a parent. } } diff --git a/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java b/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java index 91d0fc387..12acda1bf 100644 --- a/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java +++ b/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java @@ -31,11 +31,6 @@ public enum SnowflakeEntry this.entry = entry; } - public Snowflake getSnowflake() - { - return Snowflake.of(entry.getString()); - } - public static Set acceptableRoleIDs() { Set acceptableRoleIDs = new HashSet<>(); @@ -48,4 +43,9 @@ public static Set acceptableRoleIDs() acceptableRoleIDs.add(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake()); return acceptableRoleIDs; } + + public Snowflake getSnowflake() + { + return Snowflake.of(entry.getString()); + } } diff --git a/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java b/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java index 9bb3589d9..c87aa6a11 100644 --- a/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java +++ b/discord/src/main/java/me/totalfreedom/discord/util/TFM_Bridge.java @@ -4,7 +4,6 @@ import discord4j.core.object.entity.Member; import me.totalfreedom.discord.Bot; import me.totalfreedom.totalfreedommod.TotalFreedomMod; -import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.rank.Title; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Bukkit; @@ -43,13 +42,25 @@ public String getDisplay(Member member) return FUtil.miniMessage(Title.ASST_EXEC.getColoredTag()); } else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake())) { - return FUtil.miniMessage(GroupProvider.SENIOR_ADMIN.getGroup().getColoredTag()); + return FUtil.miniMessage(TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .getSeniorAdmin() + .getColoredTag()); } else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake())) { - return FUtil.miniMessage(GroupProvider.ADMIN.getGroup().getColoredTag()); + return FUtil.miniMessage(TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .getAdmin() + .getColoredTag()); } else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake())) { - return FUtil.miniMessage(GroupProvider.MASTER_BUILDER.getGroup().getColoredTag()); + return FUtil.miniMessage(TotalFreedomMod.getPlugin() + .getHierarchy() + .groups() + .getMasterBuilder() + .getColoredTag()); } else { return ""; diff --git a/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java b/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java index e4e0f4b47..1dc282ee8 100644 --- a/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java +++ b/discord/src/main/java/me/totalfreedom/discord/util/Utilities.java @@ -2,7 +2,8 @@ public class Utilities { - private Utilities() { + private Utilities() + { throw new AssertionError(); } diff --git a/discord/src/main/resources/plugin.yml b/discord/src/main/resources/plugin.yml index 70ccb8a69..75cf81e47 100644 --- a/discord/src/main/resources/plugin.yml +++ b/discord/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: TFD4J main: me.totalfreedom.discord.TFD4J version: 2023.03 api-version: 1.19 -depend: [TotalFreedomMod] +depend: [ TotalFreedomMod ] libraries: - com.discord4j:discord4j-core:3.2.0 - io.projectreactor:reactor-core:3.4.9 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4d58e05c1..53cd665f9 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ - + atlas-nexus-01-totalfreedom-development https://nexus-01.core.atlas-media.co.uk/repository/totalfreedom-development/ @@ -149,7 +149,7 @@ v1.9 provided - + net.essentialsx EssentialsX diff --git a/shop/pom.xml b/shop/pom.xml index a355ecbbe..b8feec60b 100644 --- a/shop/pom.xml +++ b/shop/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 diff --git a/shop/src/main/java/me/totalfreedom/shop/Votifier.java b/shop/src/main/java/me/totalfreedom/shop/Votifier.java index 37f50e37b..b2a7cc316 100644 --- a/shop/src/main/java/me/totalfreedom/shop/Votifier.java +++ b/shop/src/main/java/me/totalfreedom/shop/Votifier.java @@ -36,8 +36,7 @@ public void onPlayerVote(VotifierEvent event) if (player != null) { data = plugin.pl.getData(player); - } - else + } else { data = plugin.pl.getData(name); } diff --git a/shop/src/main/resources/plugin.yml b/shop/src/main/resources/plugin.yml index f04a2ac05..71f2567cd 100644 --- a/shop/src/main/resources/plugin.yml +++ b/shop/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: TF-Shoppe main: me.totalfreedom.shop.TFShoppe version: ${project.version} -authors: [AtlasMediaGroup, TotalFreedom] +authors: [ AtlasMediaGroup, TotalFreedom ] api-version: 1.19 -depend: [TotalFreedomMod] \ No newline at end of file +depend: [ TotalFreedomMod ] \ No newline at end of file