├── .documentation ├── ACTIONS.md ├── JAVADOC-README.md ├── README.md └── images │ ├── README.md │ ├── banner.png │ ├── logo 96x96.png │ ├── logo.png │ ├── team-logo.png │ └── using-example.png ├── .github ├── ISSUE_TEMPLATE │ ├── bugs_report.md │ └── feature_issues.md └── workflows │ ├── codeql-analysis.yml │ ├── deploy.yml │ └── maven.yml ├── .gitignore ├── LICENSE ├── README-en.md ├── README.md ├── pom.xml ├── renovate.json └── src ├── main ├── java │ └── cc │ │ └── carm │ │ └── plugin │ │ └── userprefix │ │ ├── Main.java │ │ ├── UserPrefixAPI.java │ │ ├── command │ │ ├── AdminCommand.java │ │ ├── UserCommand.java │ │ └── admin │ │ │ ├── ListCommand.java │ │ │ ├── ReloadCommand.java │ │ │ └── SetCommand.java │ │ ├── conf │ │ ├── PluginConfig.java │ │ ├── PluginMessages.java │ │ ├── gui │ │ │ └── GUIItems.java │ │ └── prefix │ │ │ └── PrefixConfig.java │ │ ├── event │ │ ├── UserPrefixChangeEvent.java │ │ ├── UserPrefixEvent.java │ │ └── UserPrefixExpireEvent.java │ │ ├── folia │ │ ├── FoliaScheduler.java │ │ └── MajorUtil.java │ │ ├── hooker │ │ ├── UserNameTag.java │ │ └── UserPrefixExpansion.java │ │ ├── listener │ │ ├── ChatListener.java │ │ ├── UserListener.java │ │ └── UserPermListener.java │ │ ├── manager │ │ ├── ConfigManager.java │ │ ├── PrefixManager.java │ │ ├── ServiceManager.java │ │ └── UserManager.java │ │ └── ui │ │ └── PrefixSelectGUI.java └── resources │ ├── PLUGIN_INFO │ ├── i18n │ ├── en_US │ │ └── example-prefix.yml │ └── es_ES │ │ └── ejemplo-prefijo.yml │ ├── plugin.yml │ └── prefixes │ └── example-prefix.yml └── test └── java └── ColorParseTest.java /.documentation/ACTIONS.md: -------------------------------------------------------------------------------- 1 | # UserPrefix Actions 操作 2 | 3 | ## 使用方式 4 | 5 | 在 `actions` 配置节点下,可以配置多个操作,格式为 `[操作类型] {操作参数}`,例如: 6 | 7 | - `[CHAT] HELLO %player_name%!` 8 | - `[SOUND] ENTITY_PLAYER_LEVELUP` 9 | 10 | ## 操作类型 11 | 12 | 目前支持以下操作类型: 13 | - `CHAT` 以玩家聊天的形式发送,若需要发送指令则添加“/”前缀 14 | - `CONSOLE` 以后台的形式发送指令 15 | - `MESSAGE` 向玩家发送一条消息 16 | - `SOUND` 向玩家发送声音 17 | - `CLOSE` 关闭当前打开的GUI 18 | 19 | 所有需要键入文本的类型均支持 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 变量 。 20 | 21 | ## 限定点击类型 22 | 23 | 若您需要限定玩家点击的类型,如左键、右键等,则可以添加在操作类型后,以“`:`”分割,如: 24 | 25 | - `[CLOSE:LEFT]` 代表左键点击关闭 26 | - `[MESSAGE:MIDDLE] HELLO WORLD` 代表鼠标中间点击发送消息 27 | 28 | 详细点击类型见 [`org.bukkit.event.inventory.ClickType`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/inventory/ClickType.html) 。 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /.documentation/JAVADOC-README.md: -------------------------------------------------------------------------------- 1 | # UserPrefix Javadoc 2 | 3 | 基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UserPrefix) 。 4 | 5 | ## 如何实现? 6 | 7 | 若您也想通过 [Github Actions](https://docs.github.com/en/actions/learn-github-actions) 8 | 自动部署项目的Javadoc到 [Github Pages](https://pages.github.com/) , 9 | 可以参考我的文章 [《自动部署Javadoc到Github Pages》](https://pages.carm.cc/doc/javadoc-in-github.html) 。 -------------------------------------------------------------------------------- /.documentation/README.md: -------------------------------------------------------------------------------- 1 | ```text 2 | _ _ _____ __ _ 3 | | | | | | __ \ / _|(_) 4 | | | | | ___ ___ _ __ | |__) |_ __ ___ | |_ _ __ __ 5 | | | | |/ __| / _ \| '__|| ___/| '__|/ _ \| _|| |\ \/ / 6 | | |__| |\__ \| __/| | | | | | | __/| | | | > < 7 | \____/ |___/ \___||_| |_| |_| \___||_| |_|/_/\_\ 8 | ``` 9 | 10 | # UserPrefix 帮助介绍文档 11 | 12 | ## 插件介绍目录 13 | 14 | - 使用示例 15 | - [前缀配置文件预设示例](../src/main/resources/prefixes/example-prefix.yml) 16 | - [操作(Actions)配置](ACTIONS.md) 17 | 18 | ## [开发文档](JAVADOC-README.md) 19 | 20 | 基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/UltraDepository) 。 21 | 22 | ## 依赖方式 23 | 24 | ### Maven 依赖 25 | 26 | ```xml 27 | 28 | 29 | 30 | 31 | 32 | 33 | UserPrefix 34 | GitHub Packages 35 | https://maven.pkg.github.com/CarmJos/UserPrefix 36 | 37 | 38 | 39 | 40 | carm-repo 41 | Carm's Repo 42 | https://repo.carm.cc/repository/maven-public/ 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | cc.carm.plugin 51 | userprefix 52 | [LATEST RELEASE] 53 | provided 54 | 55 | 56 | 57 | 58 | ``` 59 | 60 | ### Gradle 依赖 61 | 62 | ```groovy 63 | repositories { 64 | // 采用github依赖库,安全稳定,但需要配置 (推荐) 65 | maven { url 'https://maven.pkg.github.com/CarmJos/UserPrefix' } 66 | 67 | // 采用我的私人依赖库,简单方便,但可能因为变故而无法使用 68 | maven { url 'https://repo.carm.cc/repository/maven-public/' } 69 | } 70 | 71 | dependencies { 72 | compileOnly "cc.carm.plugin:userprefix:[LATEST RELEASE]" 73 | } 74 | ``` -------------------------------------------------------------------------------- /.documentation/images/README.md: -------------------------------------------------------------------------------- 1 | # 图片文件夹 2 | 3 | 用于存放相关介绍图片。 4 | 5 | 图片保留版权,未经授权禁止使用。 6 | -------------------------------------------------------------------------------- /.documentation/images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarmJos/UserPrefix/748335a9623e53996537169b89c8fb494e90ae75/.documentation/images/banner.png -------------------------------------------------------------------------------- /.documentation/images/logo 96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarmJos/UserPrefix/748335a9623e53996537169b89c8fb494e90ae75/.documentation/images/logo 96x96.png -------------------------------------------------------------------------------- /.documentation/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarmJos/UserPrefix/748335a9623e53996537169b89c8fb494e90ae75/.documentation/images/logo.png -------------------------------------------------------------------------------- /.documentation/images/team-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarmJos/UserPrefix/748335a9623e53996537169b89c8fb494e90ae75/.documentation/images/team-logo.png -------------------------------------------------------------------------------- /.documentation/images/using-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarmJos/UserPrefix/748335a9623e53996537169b89c8fb494e90ae75/.documentation/images/using-example.png -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bugs_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 问题提交 3 | about: 描述问题并提交,帮助我们对其进行检查与修复。 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### **问题简述** 11 | 12 | 13 | ### **问题来源** 14 | 15 | 21 | 22 | ### **预期结果**(可选) 23 | 24 | 25 | ### **问题截图/问题报错** 26 | 27 | 28 | ### **操作环境** 29 | 30 | 31 | ### **其他补充** 32 | 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 功能需求 3 | about: 希望我们提供更多的功能。 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### **功能简述** 11 | 12 | 13 | ### **需求来源** 14 | 15 | 16 | ### **功能参考**(可选) 17 | 18 | 19 | ### **附加内容** 20 | 21 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL Analysis" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '44 6 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v4 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v3 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v3 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v3 71 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Deploy & Upload 5 | 6 | on: 7 | # 支持手动触发构建 8 | workflow_dispatch: 9 | release: 10 | # 创建release的时候触发 11 | types: [ published ] 12 | 13 | jobs: 14 | build: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | - name: "Set up JDK" 21 | uses: actions/setup-java@v4 22 | with: 23 | java-version: '11' 24 | distribution: 'adopt' 25 | cache: maven 26 | server-id: github 27 | server-username: MAVEN_USERNAME 28 | server-password: MAVEN_TOKEN 29 | 30 | - name: "Maven Deploy" 31 | run: mvn -B deploy --file pom.xml -DskipTests 32 | env: 33 | MAVEN_USERNAME: ${{ github.repository_owner }} 34 | MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}} 35 | 36 | - name: "Release Asset Upload" 37 | id: upload-release-asset 38 | uses: shogo82148/actions-upload-release-asset@v1 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | with: 42 | upload_url: ${{ github.event.release.upload_url }} 43 | asset_path: asset/*.jar 44 | asset_content_type: application/java-archive 45 | 46 | - name: "Javadoc Deploy Staging" 47 | run: | 48 | rm -rf docs 49 | mkdir -vp docs 50 | cp -vrf target/reports/apidocs/* docs/ 51 | cp -vrf .documentation/JAVADOC-README.md docs/README.md 52 | 53 | - name: "Generate the Javadoc sitemap" 54 | id: sitemap 55 | uses: cicirello/generate-sitemap@v1 56 | with: 57 | base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }} 58 | path-to-root: docs 59 | 60 | - name: "Output Javadoc stats" 61 | run: | 62 | echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}" 63 | echo "url-count = ${{ steps.sitemap.outputs.url-count }}" 64 | echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}" 65 | 66 | - name: "Configure Git" 67 | env: 68 | DEPLOY_PRI: ${{secrets.DEPLOY_PRI}} 69 | run: | 70 | sudo timedatectl set-timezone "Asia/Shanghai" 71 | mkdir -p ~/.ssh/ 72 | echo "$DEPLOY_PRI" > ~/.ssh/id_rsa 73 | chmod 600 ~/.ssh/id_rsa 74 | ssh-keyscan github.com >> ~/.ssh/known_hosts 75 | git config --global user.name 'CarmJos' 76 | git config --global user.email 'carm@carm.cc' 77 | 78 | - name: "Commit Javadocs" 79 | run: | 80 | cd docs 81 | git init 82 | git remote add origin git@github.com:${{ github.repository }}.git 83 | git checkout -b gh-pages 84 | git add -A 85 | git commit -m "API Document generated." 86 | 87 | - name: "Push javadocs" 88 | run: | 89 | cd docs 90 | git push origin HEAD:gh-pages --force -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Build & Tests 5 | 6 | on: 7 | # 支持手动触发构建 8 | workflow_dispatch: 9 | push: 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: "Set up JDK" 19 | uses: actions/setup-java@v4 20 | with: 21 | java-version: '11' 22 | distribution: 'adopt' 23 | cache: maven 24 | server-id: github 25 | server-username: MAVEN_USERNAME 26 | server-password: MAVEN_TOKEN 27 | - name: "Package" 28 | run: mvn -B package --file pom.xml 29 | env: 30 | MAVEN_USERNAME: ${{ github.repository_owner }} 31 | MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}} 32 | 33 | - name: "Target Staging" 34 | run: | 35 | mkdir artifacts 36 | cp -vrf target/ artifacts/target/ 37 | cp -vrf asset/*.jar artifacts 38 | 39 | - name: "Upload artifact" 40 | uses: actions/upload-artifact@v4 41 | with: 42 | name: Artifact 43 | path: artifacts 44 | include-hidden-files: true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | /target/ 3 | ./*.iml 4 | *.iml 5 | asset/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README-en.md: -------------------------------------------------------------------------------- 1 | ![BANNER](.documentation/images/banner.png) 2 | 3 | README LANGUAGES [ [中文](README.md) | [**English**](README-en.md) ] 4 | 5 | # UserPrefix Plugin 6 | 7 | [![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix) 8 | ![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/UserPrefix) 9 | [![License](https://img.shields.io/github/license/CarmJos/UserPrefix)](https://opensource.org/licenses/GPL-3.0) 10 | [![Java CI with Maven](https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml) 11 | ![Support](https://img.shields.io/badge/Minecraft-Java%201.8--Latest-yellow) 12 | ![](https://visitor-badge.glitch.me/badge?page_id=userprefix.readme) 13 | 14 | Lightweight, efficient, and real-time user prefix system. 15 | 16 | This plugin is implemented based on Spigot ,**Theoretically** support ALL MineCraft Versions. 17 | 18 | The development of this plugin is based on Chinese which purpose is to help Chinese developers learn Bukkit plugin 19 | development. 20 | 21 | > This plugin has been published on [SpigotMC](https://www.spigotmc.org/resources/userprefix.96277/) . 22 | 23 | > 本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503) 上发布,欢迎中文用户来这里下载。 24 | 25 | ## Examples 26 | 27 | ![example](.documentation/images/using-example.png) 28 | 29 | ## Dependencies 30 | 31 | - **[Necessary]** Plugin developed based on [Spigot-API](https://hub.spigotmc.org/stash/projects/SPIGOT) 32 | and [BukkitAPI](http://bukkit.org/). 33 | - **[Necessary]** Plugin data storage base on [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/). 34 | - **[Recommend]** Placeholders based on [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) . 35 | 36 | For development dependencies, please see [Dependencies](https://github.com/CarmJos/UserPrefix/network/dependencies) . 37 | 38 | ## Features 39 | 40 | - **Theoretically** support ALL MineCraft Versions. 41 | - Reloading the configuration will automatically refresh the prefix of all players. 42 | - Real-time judgment and feedback to the player when permissions are changed. 43 | - Configurable sounds and messages. 44 | - The prefix icon can be configured as "Selected", "Has Permission" and “No Permission”. 45 | - TabList is automatically sorted according to the weight of the prefix (if there is a conflict, it can be turned off) 46 | - The prefix display on the player name (can be turned off if there has any conflict) 47 | - Simple Chat Format Placeholder support. (Not Recommended) 48 | - GUI with automatic sorting and page turning! 49 | - Support PlaceholderAPI variables! 50 | - Support [Hex Color](https://www.hexcolortool.com/)! (Version 1.16 and above) `&(#Color)` 51 | - Example: LightSlateBlue `&(#8470FF)` 、 DarkSlateBlue `&(#483D8B)` 52 | - Support Gradient Color! (Version 1.16 and above) `&<#Color1>Message&<#Color2>` 53 | - Example: `&<#8470FF>Hello World!&<#483D8B>` 54 | 55 | ## Notice 56 | 57 | ### 1. Version support issues 58 | 59 | This plugin theoretically supports all versions. 60 | 61 | If the icon does not load, the sound cannot be played, etc., please check whether the type of the item and sound in the 62 | configuration file exists in the current version. 63 | 64 | Take the SOUND as an example. The sound that the villager said "OK" is "`VILLAGER_YES`" in the lower version, but it 65 | becomes "`ENTITY_VILLAGER_YES`" in the higher version. 66 | 67 | ### 2. Scoreboard exception problem 68 | 69 | The display of the prefix on the head and the sorting of the TabList both use the scoreboard API. 70 | 71 | Please turn of the `functions.on-name-prefix` in the configuration if there is a conflict. 72 | 73 | ## Commands 74 | 75 | This plugin's Commands are based on Chinese! 76 | **May support multi-language in the future.** 77 | 78 | ```text 79 | /UserPrefix or /prefix #Open prefix GUI 80 | /UserPrefixAdmin # View Admin Command Help 81 | /UserPrefixAdmin reload # Reload Config 82 | /UserPrefixAdmin list # List all configured prefixes. 83 | ``` 84 | 85 | ## Placeholders (PlaceholderAPI) 86 | 87 | After installed the [PlaceholderAPI](https://github.com/PlaceholderAPI/PlaceholderAPI) , you can 88 | type `/papi info UserPrefix` to see all the placeholders. 89 | 90 | ```text 91 | # %UserPrefix_prefix% 92 | - Get the content of the current prefix 93 | # %UserPrefix_weight% 94 | - Get the weight of the current prefix. 95 | # %UserPrefix_identifier% 96 | - Get the identifier of the current prefix. 97 | # %UserPrefix_name% 98 | - Get the name of the current prefix. 99 | # %UserPrefix_has_% 100 | - Determine whether the player has a certain prefix(true/false) 101 | ``` 102 | 103 | ## Configuration files 104 | 105 | ### Plugin Configuration ([`config.yml`]() . 106 | 107 | Will be generated on the first boot up. 108 | 109 | ### Messages Configuration ([`messages.yml`]()) 110 | 111 | Will be generated on the first boot up. 112 | 113 | ### Prefixes Configuration ([`prefixes/*.yml`](src/main/resources/en_US/example-prefix.yml)) 114 | 115 | All prefixes are separate configuration files, stored in the `/prefixes/` for easy management. 116 | 117 | Some symbols in file name may affect reading, please avoid using them. 118 | 119 | ## Support and Donation 120 | 121 | This project is support by the [YourCraft(你的世界)](https://www.ycraft.cn) . 122 | ![TeamLogo](.documentation/images/team-logo.png) 123 | 124 | ## Open source agreement 125 | 126 | The source code of this project uses [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 127 | License. 128 | 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![BANNER](.documentation/images/banner.png) 2 | 3 | README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ] 4 | 5 | # 用户前缀系统插件 6 | 7 | [![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix) 8 | ![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/UserPrefix) 9 | [![Download](https://img.shields.io/github/downloads/CarmJos/UserPrefix/total)](https://github.com/CarmJos/UserPrefix/releases) 10 | [![Java CI with Maven](https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml) 11 | ![Support](https://img.shields.io/badge/Minecraft-Java%201.8--Latest-green) 12 | ![](https://visitor-badge.glitch.me/badge?page_id=userprefix.readme) 13 | 14 | 轻便、高效、实时的用户前缀系统。 15 | 16 | 本插件基于Spigot实现,**理论上支持全版本**。 17 | 18 | > 本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503) 19 | > 与 [SpigotMC](https://www.spigotmc.org/resources/userprefix-hex-color-support-all-version.96277/) 上发布。 20 | 21 | ## 示例 22 | 23 | ![example](.documentation/images/using-example.png) 24 | 25 | ## 依赖 26 | 27 | - **[必须]** 插件本体基于 [Spigot-API](https://hub.spigotmc.org/stash/projects/SPIGOT)、[BukkitAPI](http://bukkit.org/) 实现。 28 | - **[必须]** 数据部分基于 [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/) 实现。 29 | - **[推荐]** 变量部分基于 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 实现。 30 | 31 | 详细依赖列表可见 [Dependencies](https://github.com/CarmJos/UserPrefix/network/dependencies) 。 32 | 33 | ## 特性 34 | 35 | - 理论上全版本支持! 36 | - 游戏内重载配置文件并实时更新到玩家! 37 | - 当玩家权限变更时会实时监测前缀,若权限不足则自动更换前缀并提示 38 | - 可配置的声音、消息! 39 | - 前缀图标可配置“选中”、“有权限”与“无权限”三种状态的物品 40 | - TabList自动按照前缀的权重排序 (如有冲突可关掉) 41 | - 玩家头顶前缀显示 (如有冲突可关掉) 42 | - 简单的聊天变量修改功能!(不推荐使用) `[自 v2.1.0 版本起]` 43 | - 自动排序,且可翻页的GUI! 44 | - 支持PlaceholderAPI变量!(凡支持的都可以使用,如BungeeTabListPlus) 45 | - 支持[Hex颜色](https://www.hexcolortool.com/)!(1.16以上版本) `[自 v1.2.3 版本起]` 46 | - 格式: `&(#颜色代码)` 47 | - 示例: LightSlateBlue `&(#8470FF)` 、 DarkSlateBlue `&(#483D8B)` 48 | - 支持渐变色!(1.16以上版本) `[自 v1.2.3 版本起]` 49 | - 格式: `&<#颜色代码1>消息内容&<#颜色代码2>` 50 | - 示例: `&<#8470FF>Hello World!&<#483D8B>` 51 | 52 | ## 注意事项 53 | 54 | ### 1. 版本支持问题 55 | 56 | 本插件理论全版本支持,如果出现图标不加载、声音无法播放等问题请检查配置文件中物品与声音的type在当前版本是否存在。 57 | 58 | 以声音举例,村民表示可以的声音在低版本中为 “`VILLAGER_YES`”,而在高版本中则变为了“`ENTITY_VILLAGER_YES`”。 59 | 60 | ### 2. 计分板异常问题 61 | 62 | 头顶上前缀的显示与TabList的排序均使用到了计分板API。 63 | 64 | 如有冲突导致其他插件的计分板无法显示,请关掉配置文件中`functions.on-name-prefix`。 65 | 66 | ## 指令 67 | 68 | 本插件指令部分较为简单。 69 | 70 | ```text 71 | /UserPrefix 或 /prefix 打开前缀更换GUI 72 | /UserPrefixAdmin 查看管理员指令帮助 73 | /UserPrefixAdmin reload 重载配置文件 74 | /UserPrefixAdmin list 查看已配置的前缀内容 75 | ``` 76 | 77 | ## 变量 (PlaceholderAPI) 78 | 79 | 安装 [PlaceholderAPI](https://github.com/PlaceholderAPI/PlaceholderAPI) 后,可以输入 `/papi info UserPrefix` 查看相关变量。 80 | 81 | 变量内容如下 82 | 83 | ```text 84 | # %UserPrefix_prefix% 85 | - 得到当前正在使用的前缀 86 | # %UserPrefix_weight% 87 | - 得到当前正在使用的前缀权重 88 | # %UserPrefix_identifier% 89 | - 得到当前正在使用的前缀标识 90 | # %UserPrefix_name% 91 | - 得到当前正在使用的前缀名 92 | # %UserPrefix_has_% 93 | - 判断玩家是否拥有某个前缀(true/false) 94 | ``` 95 | 96 | ## 配置文件示例 97 | 98 | ### 基础配置文件 ([`config.yml`](src/main/java/cc/carm/plugin/userprefix/conf/PluginConfig.java)) 99 | 100 | 将会在服务器首次启动时生成,如果您想要修改配置,请在服务器启动后打开配置文件。 101 | 102 | ### 消息配置文件 ([`messages.yml`](src/main/java/cc/carm/plugin/userprefix/conf/PluginMessages.java)) 103 | 104 | 将会在服务器首次启动时生成,如果您想要修改配置,请在服务器启动后打开配置文件 。 105 | 106 | ### 前缀配置文件 ([`prefixes/*.yml`](src/main/resources/prefixes/example-prefix.yml)) 107 | 108 | 所有前缀均为单独的配置文件,存放于 `插件配置目录/prefixes` 下,便于管理。 109 | 110 | 文件名理论上可以随便取,推荐使用英文,部分符号可能会影响正常读取,请避免使用。 111 | 112 | 您可以 [点击这里](src/main/resources/prefixes/example-prefix.yml) 查看示例前缀配置文件。 113 | 114 | ## 使用统计 115 | 116 | [![bStats](https://bstats.org/signatures/bukkit/UserPrefix.svg)](https://bstats.org/plugin/bukkit/UserPrefix/13776) 117 | 118 | ## 支持与捐赠 119 | 120 | 本项目由 [YourCraft(你的世界)](https://www.ycraft.cn) 团队提供长期支持与维护。 121 | ![TeamLogo](.documentation/images/team-logo.png) 122 | 123 | 若您觉得本插件做的不错,您可以捐赠支持我!感谢您成为开源项目的支持者! 124 | 125 | Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects. 126 | [![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/CarmJos/UserPrefix) 127 | 128 | ## 开源协议 129 | 130 | 本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。 131 | 132 |
133 | 关于 GPL 协议 134 | 135 | > GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利: 136 | > 137 | > #### 可自由复制 138 | > 你可以将软件复制到你的电脑,你客户的电脑,或者任何地方。复制份数没有任何限制。 139 | > #### 可自由分发 140 | > 在你的网站提供下载,拷贝到U盘送人,或者将源代码打印出来从窗户扔出去(环保起见,请别这样做)。 141 | > #### 可以用来盈利 142 | > 你可以在分发软件的时候收费,但你必须在收费前向你的客户提供该软件的 GNU GPL 许可协议,以便让他们知道,他们可以从别的渠道免费得到这份软件,以及你收费的理由。 143 | > #### 可自由修改 144 | > 如果你想添加或删除某个功能,没问题,如果你想在别的项目中使用部分代码,也没问题,唯一的要求是,使用了这段代码的项目也必须使用 GPL 协议。 145 | > 146 | > 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 147 | > 协议,你必须在源代码代码中包含相应信息,以及协议本身。 148 | > 149 | > *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。* 150 |
151 | 152 | ## Project supported by JetBrains 153 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | 8 9 | cc.carm.plugin.userprefix 10 | 11 | ${project.jdk.version} 12 | ${project.jdk.version} 13 | UTF-8 14 | UTF-8 15 | 16 | 1.5.12 17 | 3.1.1 18 | 19 | 20 | cc.carm.plugin 21 | userprefix 22 | 3.2.6 23 | 24 | UserPrefix 25 | 轻便、高效、实时的用户前缀系统。 26 | https://github.com/CarmJos/UserPrefix 27 | 28 | 29 | GitHub Issues 30 | https://github.com/CarmJos/UserPrefix/issues 31 | 32 | 33 | 34 | GitHub Actions 35 | https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml 36 | 37 | 38 | 39 | 40 | CarmJos 41 | Carm Jos 42 | carm@carm.cc 43 | https://work.carm.cc 44 | 45 | Main Developer 46 | 47 | 48 | 49 | 50 | 51 | YourCraft你的世界 52 | https://www.ycraft.cn/ 53 | 54 | 55 | 56 | 57 | GNU General Public License v3.0 58 | https://opensource.org/licenses/GPL-3.0 59 | 60 | 61 | 62 | 63 | 64 | 65 | maven-central 66 | https://repo1.maven.org/maven2/ 67 | 68 | 69 | 70 | sonatype 71 | https://oss.sonatype.org/content/repositories/public/ 72 | 73 | 74 | 75 | spigot-repo 76 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 77 | 78 | 79 | 80 | luck-repo 81 | https://repo.lucko.me/ 82 | 83 | 84 | 85 | minecraft-libraries 86 | Minecraft Libraries 87 | https://libraries.minecraft.net/ 88 | 89 | 90 | 91 | EasyPlugin 92 | https://raw.githubusercontent.com/CarmJos/EasyPlugin/repo/ 93 | 94 | 95 | 96 | carm-repo 97 | Carm's Repo 98 | https://repo.carm.cc/repository/maven-public/ 99 | 100 | 101 | 102 | 103 | 104 | https://github.com/CarmJos/UserPrefix/releases 105 | 106 | github 107 | GitHub Packages 108 | https://maven.pkg.github.com/CarmJos/UserPrefix 109 | 110 | 111 | 112 | 113 | 114 | 115 | cc.carm.lib 116 | easyplugin-main 117 | ${deps.easyplugin.version} 118 | compile 119 | true 120 | 121 | 122 | 123 | cc.carm.lib 124 | easyplugin-command 125 | ${deps.easyplugin.version} 126 | compile 127 | true 128 | 129 | 130 | 131 | cc.carm.lib 132 | easyplugin-gui 133 | ${deps.easyplugin.version} 134 | compile 135 | true 136 | 137 | 138 | 139 | 140 | cc.carm.lib 141 | easyplugin-githubchecker 142 | ${deps.easyplugin.version} 143 | compile 144 | true 145 | 146 | 147 | 148 | cc.carm.lib 149 | easyplugin-placeholderapi 150 | ${deps.easyplugin.version} 151 | compile 152 | true 153 | 154 | 155 | 156 | cc.carm.lib 157 | mineconfiguration-bukkit 158 | ${deps.mineconfig.version} 159 | compile 160 | true 161 | 162 | 163 | com.cryptomorin.xseries 164 | XSeries 165 | 166 | 167 | com.github.cryptomorin 168 | XSeries 169 | 170 | 171 | 172 | 173 | 174 | com.github.cryptomorin 175 | XSeries 176 | 13.2.0 177 | compile 178 | true 179 | 180 | 181 | 182 | com.mojang 183 | authlib 184 | 6.0.54 185 | provided 186 | 187 | 188 | 189 | org.spigotmc 190 | spigot-api 191 | 1.17-R0.1-SNAPSHOT 192 | provided 193 | 194 | 195 | 196 | me.clip 197 | placeholderapi 198 | 2.11.6 199 | provided 200 | 201 | 202 | 203 | net.luckperms 204 | api 205 | 5.4 206 | provided 207 | 208 | 209 | 210 | org.bstats 211 | bstats-bukkit 212 | 3.1.0 213 | compile 214 | 215 | 216 | 217 | org.jetbrains 218 | annotations 219 | 26.0.2 220 | provided 221 | 222 | 223 | 224 | junit 225 | junit 226 | 4.13.2 227 | test 228 | 229 | 230 | 231 | 232 | 233 | 234 | org.apache.maven.plugins 235 | maven-clean-plugin 236 | 3.4.1 237 | 238 | 239 | 240 | ${project.basedir}/asset/ 241 | true 242 | 243 | **/* 244 | 245 | 246 | 247 | ${project.basedir}/api-docs/ 248 | true 249 | 250 | **/* 251 | 252 | 253 | 254 | 255 | 256 | 257 | org.apache.maven.plugins 258 | maven-compiler-plugin 259 | 3.14.0 260 | 261 | ${project.jdk.version} 262 | ${project.jdk.version} 263 | UTF-8 264 | -parameters 265 | 266 | 267 | 268 | org.apache.maven.plugins 269 | maven-jar-plugin 270 | 3.4.2 271 | 272 | 273 | org.apache.maven.plugins 274 | maven-source-plugin 275 | 3.3.1 276 | 277 | 278 | package 279 | 280 | jar-no-fork 281 | 282 | 283 | 284 | 285 | 286 | org.apache.maven.plugins 287 | maven-shade-plugin 288 | 3.6.0 289 | 290 | 291 | package 292 | 293 | shade 294 | 295 | 296 | 297 | 298 | ${project.name}-${project.version} 299 | ${project.basedir}/asset/ 300 | false 301 | true 302 | 303 | 304 | org.bstats 305 | ${project.package}.bstats 306 | 307 | 308 | cc.carm.lib 309 | ${project.package}.lib 310 | 311 | 312 | org.json 313 | ${project.package}.lib.json 314 | 315 | 316 | com.cryptomorin.xseries 317 | ${project.package}.lib.xseries 318 | 319 | 320 | 321 | 322 | *:* 323 | 324 | META-INF/MANIFEST.MF 325 | META-INF/*.txt 326 | 327 | 328 | 329 | 330 | 331 | 332 | org.apache.maven.plugins 333 | maven-javadoc-plugin 334 | 3.11.2 335 | 336 | javadoc 337 | 338 | https://javadoc.io/doc/org.jetbrains/annotations/ 339 | https://hub.spigotmc.org/javadocs/bukkit/ 340 | https://carmjos.github.io/EasyPlugin/ 341 | https://carmjos.github.io/MineConfiguration/ 342 | 343 | true 344 | UTF-8 345 | UTF-8 346 | UTF-8 347 | zh_CN 348 | 349 | 350 | 351 | attach-javadocs 352 | 353 | jar 354 | 355 | 356 | 357 | 358 | 359 | org.apache.maven.plugins 360 | maven-surefire-plugin 361 | 3.5.3 362 | 363 | false 364 | 365 | 366 | 367 | 368 | 369 | src/main/resources 370 | true 371 | 372 | 373 | 374 | 375 | 376 | 377 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base","mergeConfidence:all-badges" 5 | ], 6 | "packageRules": [ 7 | { 8 | "description": "Automerge non-major updates", 9 | "matchUpdateTypes": ["minor", "patch"], 10 | "automerge": true 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/Main.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix; 2 | 3 | import cc.carm.lib.easyplugin.EasyPlugin; 4 | import cc.carm.lib.easyplugin.gui.GUI; 5 | import cc.carm.lib.easyplugin.gui.paged.AutoPagedGUI; 6 | import cc.carm.lib.easyplugin.updatechecker.GHUpdateChecker; 7 | import cc.carm.lib.easyplugin.utils.MessageUtils; 8 | import cc.carm.plugin.userprefix.command.AdminCommand; 9 | import cc.carm.plugin.userprefix.command.UserCommand; 10 | import cc.carm.plugin.userprefix.conf.PluginConfig; 11 | import cc.carm.plugin.userprefix.folia.FoliaScheduler; 12 | import cc.carm.plugin.userprefix.hooker.UserPrefixExpansion; 13 | import cc.carm.plugin.userprefix.listener.ChatListener; 14 | import cc.carm.plugin.userprefix.listener.UserListener; 15 | import cc.carm.plugin.userprefix.listener.UserPermListener; 16 | import cc.carm.plugin.userprefix.manager.ConfigManager; 17 | import cc.carm.plugin.userprefix.manager.PrefixManager; 18 | import cc.carm.plugin.userprefix.manager.ServiceManager; 19 | import cc.carm.plugin.userprefix.manager.UserManager; 20 | import cc.carm.plugin.userprefix.ui.PrefixSelectGUI; 21 | import net.luckperms.api.event.user.UserDataRecalculateEvent; 22 | import org.bstats.bukkit.Metrics; 23 | import org.bstats.charts.SimplePie; 24 | import org.bstats.charts.SingleLineChart; 25 | import org.bukkit.Bukkit; 26 | import org.bukkit.plugin.Plugin; 27 | 28 | public class Main extends EasyPlugin { 29 | 30 | private static Main instance; 31 | 32 | protected FoliaScheduler foliaScheduler; 33 | protected boolean onFolia; 34 | 35 | protected ConfigManager configManager; 36 | protected PrefixManager prefixManager; 37 | protected UserManager userManager; 38 | 39 | @Override 40 | protected boolean initialize() { 41 | instance = this; 42 | 43 | try { 44 | Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent"); 45 | this.onFolia = true; 46 | } catch (ClassNotFoundException e) { 47 | this.onFolia = false; 48 | } 49 | this.foliaScheduler = new FoliaScheduler(this, this.onFolia); 50 | 51 | log("加载插件配置..."); 52 | this.configManager = new ConfigManager(getDataFolder()); 53 | this.prefixManager = new PrefixManager(); 54 | 55 | log("加载前缀配置..."); 56 | int loaded = prefixManager.loadPrefixes(); 57 | log(" 成功加载了 " + loaded + " 个前缀配置。"); 58 | 59 | log("加载用户管理器..."); 60 | this.userManager = new UserManager(); 61 | 62 | log("注册指令..."); 63 | registerCommand("UserPrefix", new UserCommand()); 64 | registerCommand("UserPrefixAdmin", new AdminCommand(this)); 65 | 66 | log("注册监听器..."); 67 | registerListener(new UserListener()); 68 | registerListener(new ChatListener()); 69 | ServiceManager.getService().getEventBus().subscribe( 70 | this, UserDataRecalculateEvent.class, 71 | UserPermListener::process 72 | ); 73 | 74 | log("初始化GUI管理器..."); 75 | GUI.initialize(this); 76 | AutoPagedGUI.defaultNextPage = (PluginConfig.GUI.BOTTOMS.NEXT_PAGE::get); 77 | AutoPagedGUI.defaultPreviousPage = (PluginConfig.GUI.BOTTOMS.PREV_PAGE::get); 78 | 79 | if (MessageUtils.hasPlaceholderAPI()) { 80 | log("注册变量..."); 81 | new UserPrefixExpansion(this, getName()).register(); 82 | } else { 83 | log("未安装 PlaceholderAPI ,跳过变量注册..."); 84 | log("若您想使用变量进行前缀的显示,请安装PlaceholderAPI!"); 85 | } 86 | 87 | if (PluginConfig.METRICS.getNotNull()) { 88 | log("启用统计数据..."); 89 | Metrics metrics = new Metrics(this, 13776); 90 | metrics.addCustomChart(new SingleLineChart("active_prefixes", () -> prefixManager.getPrefixes().size())); 91 | metrics.addCustomChart(new SimplePie("custom_storage", () -> PluginConfig.CUSTOM_STORAGE.ENABLE.getNotNull() ? "ENABLE" : "DISABLE")); 92 | metrics.addCustomChart(new SimplePie("lp_version", () -> ServiceManager.getService().getPluginMetadata().getVersion())); 93 | metrics.addCustomChart(new SimplePie("papi_version", () -> { 94 | Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); 95 | if (plugin == null) return "Not installed"; 96 | else return plugin.getDescription().getVersion(); 97 | })); 98 | } 99 | 100 | if (PluginConfig.CHECK_UPDATE.getNotNull()) { 101 | log("开始检查更新..."); 102 | this.foliaScheduler.runAsync(GHUpdateChecker.runner(this)); 103 | } else { 104 | log("已禁用检查更新,跳过。"); 105 | } 106 | 107 | if (PluginConfig.FUNCTIONS.NAME_PREFIX.ENABLE.getNotNull() && this.isOnFolia()) { 108 | log("插件正运行在 Folia 服务端上,头顶前缀功能不可用"); 109 | } 110 | Bukkit.getOnlinePlayers().forEach(userManager::initPlayer); // 适配热重载 111 | 112 | log("&7感谢您使用 &3&lUserPrefix " + getDescription().getVersion() + "&7!"); 113 | log("&7本插件由 &b&lYourCraft &7提供长期支持与维护。"); 114 | return true; 115 | } 116 | 117 | @Override 118 | protected void shutdown() { 119 | 120 | log("关闭已被打开的GUI..."); 121 | Bukkit.getOnlinePlayers().stream().filter(GUI::hasOpenedGUI).forEach(player -> { 122 | player.closeInventory(); 123 | GUI.removeOpenedGUI(player); 124 | PrefixSelectGUI.removeOpening(player); 125 | }); 126 | 127 | log("&7感谢您使用 &3&lUserPrefix " + getDescription().getVersion() + "&7!"); 128 | log("&7本插件由 &b&lYourCraft &7提供长期支持与维护。"); 129 | } 130 | 131 | public boolean isOnFolia() { 132 | return this.onFolia; 133 | } 134 | 135 | public FoliaScheduler getFoliaScheduler() { 136 | return this.foliaScheduler; 137 | } 138 | 139 | @Override 140 | public boolean isDebugging() { 141 | return PluginConfig.DEBUG.getNotNull(); 142 | } 143 | 144 | public static void info(String... message) { 145 | getInstance().log(message); 146 | } 147 | 148 | public static void debugging(String... message) { 149 | getInstance().debug(message); 150 | } 151 | 152 | public static void severe(String... message) { 153 | getInstance().error(message); 154 | } 155 | 156 | public static Main getInstance() { 157 | return instance; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/UserPrefixAPI.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix; 2 | 3 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 4 | import cc.carm.plugin.userprefix.manager.ConfigManager; 5 | import cc.carm.plugin.userprefix.manager.PrefixManager; 6 | import cc.carm.plugin.userprefix.manager.UserManager; 7 | 8 | public class UserPrefixAPI { 9 | 10 | public static PrefixManager getPrefixManager() { 11 | return Main.getInstance().prefixManager; 12 | } 13 | 14 | public static ConfigManager getConfigManager() { 15 | return Main.getInstance().configManager; 16 | } 17 | 18 | public static UserManager getUserManager() { 19 | return Main.getInstance().userManager; 20 | } 21 | 22 | public static PrefixConfig getDefaultPrefix(){ 23 | return getPrefixManager().getDefaultPrefix(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/command/AdminCommand.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.command; 2 | 3 | import cc.carm.lib.easyplugin.command.CommandHandler; 4 | import cc.carm.plugin.userprefix.command.admin.ListCommand; 5 | import cc.carm.plugin.userprefix.command.admin.ReloadCommand; 6 | import cc.carm.plugin.userprefix.command.admin.SetCommand; 7 | import cc.carm.plugin.userprefix.conf.PluginMessages; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.plugin.java.JavaPlugin; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | public class AdminCommand extends CommandHandler { 13 | 14 | 15 | public AdminCommand(@NotNull JavaPlugin plugin) { 16 | super(plugin); 17 | registerSubCommand(new ListCommand(this, "list", "l")); 18 | registerSubCommand(new SetCommand(this, "set")); 19 | registerSubCommand(new ReloadCommand(this, "reload")); 20 | } 21 | 22 | @Override 23 | public Void noArgs(CommandSender sender) { 24 | return help(sender); 25 | } 26 | 27 | @Override 28 | public Void noPermission(CommandSender sender) { 29 | PluginMessages.COMMAND_USAGE.NO_PERM.sendTo(sender); 30 | return null; 31 | } 32 | 33 | public static Void help(CommandSender sender) { 34 | PluginMessages.COMMAND_USAGE.ADMIN.sendTo(sender); 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/command/UserCommand.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.command; 2 | 3 | import cc.carm.plugin.userprefix.conf.PluginMessages; 4 | import cc.carm.plugin.userprefix.ui.PrefixSelectGUI; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.command.CommandExecutor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | public class UserCommand implements CommandExecutor { 13 | 14 | 15 | @Override 16 | public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { 17 | if (sender instanceof Player) { 18 | PrefixSelectGUI.open((Player) sender); 19 | } else { 20 | if (strings.length != 1) { 21 | PluginMessages.COMMAND_USAGE.CONSOLE.sendTo(sender); 22 | } else { 23 | Player player = Bukkit.getPlayer(strings[0]); 24 | if (player != null) { 25 | PrefixSelectGUI.open(player); 26 | } 27 | } 28 | } 29 | return true; 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/command/admin/ListCommand.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.command.admin; 2 | 3 | import cc.carm.lib.easyplugin.command.SubCommand; 4 | import cc.carm.plugin.userprefix.UserPrefixAPI; 5 | import cc.carm.plugin.userprefix.command.AdminCommand; 6 | import cc.carm.plugin.userprefix.conf.PluginMessages; 7 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.plugin.java.JavaPlugin; 10 | import org.jetbrains.annotations.NotNull; 11 | 12 | public class ListCommand extends SubCommand { 13 | 14 | public ListCommand(@NotNull AdminCommand parent, String name, String... aliases) { 15 | super(parent, name, aliases); 16 | } 17 | 18 | @Override 19 | public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) { 20 | PluginMessages.LIST.HEADER.sendTo(sender); 21 | for (PrefixConfig value : UserPrefixAPI.getPrefixManager().getPrefixes().values()) { 22 | PluginMessages.LIST.VALUE.sendTo(sender, 23 | value.getWeight(), value.getIdentifier(), 24 | value.getName(), value.getPermission(), 25 | value.getContent(sender), sender.getName() 26 | ); 27 | } 28 | return null; 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/command/admin/ReloadCommand.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.command.admin; 2 | 3 | import cc.carm.lib.easyplugin.command.SubCommand; 4 | import cc.carm.plugin.userprefix.UserPrefixAPI; 5 | import cc.carm.plugin.userprefix.command.AdminCommand; 6 | import cc.carm.plugin.userprefix.conf.PluginMessages; 7 | import cc.carm.plugin.userprefix.ui.PrefixSelectGUI; 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.command.CommandSender; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | public class ReloadCommand extends SubCommand { 15 | 16 | public ReloadCommand(@NotNull AdminCommand parent, String name, String... aliases) { 17 | super(parent, name, aliases); 18 | } 19 | 20 | @Override 21 | public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) { 22 | long s1 = System.currentTimeMillis(); 23 | PrefixSelectGUI.closeAll(); // 关掉所有正在显示的前缀列表 24 | try { 25 | UserPrefixAPI.getConfigManager().reload(); // 重载配置文件 26 | int num = UserPrefixAPI.getPrefixManager().loadPrefixes(); //加载重载后了的前缀配置 27 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 28 | UserPrefixAPI.getUserManager().checkPrefix(onlinePlayer, false); 29 | /* 30 | * 这里关掉loadOthers(为其他玩家更新)了。 31 | * 因为每个玩家更新的时候会为其他人更新自己, 32 | * 全部走完一遍后,所有玩家都会加载最新的前缀内容。 33 | */ 34 | UserPrefixAPI.getUserManager().updatePrefixView(onlinePlayer, false); 35 | } 36 | PluginMessages.RELOAD.SUCCESS.sendTo(sender, System.currentTimeMillis() - s1, num); 37 | } catch (Exception e) { 38 | PluginMessages.RELOAD.FAILED.sendTo(sender, e.getMessage()); 39 | e.printStackTrace(); 40 | } 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/command/admin/SetCommand.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.command.admin; 2 | 3 | import cc.carm.lib.easyplugin.command.SubCommand; 4 | import cc.carm.plugin.userprefix.UserPrefixAPI; 5 | import cc.carm.plugin.userprefix.command.AdminCommand; 6 | import cc.carm.plugin.userprefix.conf.PluginMessages; 7 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.command.CommandSender; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | public class SetCommand extends SubCommand { 15 | 16 | public SetCommand(@NotNull AdminCommand parent, String name, String... aliases) { 17 | super(parent, name, aliases); 18 | } 19 | 20 | @Override 21 | public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) { 22 | if (args.length < 2) return getParent().noArgs(sender); 23 | 24 | Player target = Bukkit.getPlayer(args[0]); 25 | if (target == null) { 26 | PluginMessages.NOT_ONLINE.sendTo(sender, args[0]); 27 | return null; 28 | } 29 | 30 | 31 | PrefixConfig prefixConfig; 32 | String prefixInput = args[1]; 33 | if (prefixInput.equalsIgnoreCase("default")) { 34 | prefixConfig = UserPrefixAPI.getDefaultPrefix(); 35 | } else { 36 | prefixConfig = UserPrefixAPI.getPrefixManager().getPrefix(prefixInput); 37 | } 38 | 39 | if (prefixConfig == null) { 40 | PluginMessages.SET.PREFIX_NOT_FOUND.sendTo(sender, prefixInput); 41 | return null; 42 | } 43 | 44 | if (!prefixConfig.checkPermission(target)) { 45 | PluginMessages.SET.NO_PERM.sendTo(sender, target.getName(), prefixConfig.getName()); 46 | return null; 47 | } 48 | 49 | UserPrefixAPI.getUserManager().setPrefix(target, prefixConfig, true); 50 | PluginMessages.SET.SUCCESS.sendTo(sender, target.getName(), prefixConfig.getName()); 51 | return null; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/conf/PluginConfig.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.conf; 2 | 3 | import cc.carm.lib.configuration.Configuration; 4 | import cc.carm.lib.configuration.annotation.ConfigPath; 5 | import cc.carm.lib.configuration.annotation.HeaderComments; 6 | import cc.carm.lib.configuration.value.standard.ConfiguredList; 7 | import cc.carm.lib.configuration.value.standard.ConfiguredValue; 8 | import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredSound; 9 | import cc.carm.lib.mineconfiguration.bukkit.value.item.ConfiguredItem; 10 | import cc.carm.plugin.userprefix.conf.gui.GUIItems; 11 | import cc.carm.plugin.userprefix.folia.MajorUtil; 12 | import org.bukkit.Material; 13 | import org.bukkit.inventory.ItemFlag; 14 | 15 | public class PluginConfig implements Configuration { 16 | 17 | @HeaderComments({"开发者查错模式"}) 18 | public static final ConfiguredValue DEBUG = ConfiguredValue.of(Boolean.class, false); 19 | 20 | @HeaderComments({ 21 | "统计数据设定", 22 | " 该选项用于帮助开发者统计插件版本与使用情况,且绝不会影响性能与使用体验。", 23 | " 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。" 24 | }) 25 | public static final ConfiguredValue METRICS = ConfiguredValue.of(Boolean.class, true); 26 | 27 | @HeaderComments({ 28 | "检查更新设定", 29 | "该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。", 30 | "检查更新为异步操作,绝不会影响性能与使用体验。" 31 | }) 32 | public static final ConfiguredValue CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true); 33 | 34 | @HeaderComments({"自定义存储位置设定", "可以规定到远程文件夹中去加载前缀配置"}) 35 | public static final class CUSTOM_STORAGE implements Configuration { 36 | 37 | @HeaderComments({"是否启用自定义存储位置"}) 38 | public static final ConfiguredValue ENABLE = ConfiguredValue.of(Boolean.class, false); 39 | 40 | @HeaderComments({ 41 | "目标存储路径,必须指向一个文件夹。", 42 | "默认存储位置为 “插件文件夹”/prefixes", 43 | "支持绝对文件路径,如 \"/etc/minecraft/configurations/prefixes/\"" 44 | }) 45 | public static final ConfiguredValue PATH = ConfiguredValue.of(String.class, "prefixes/"); 46 | 47 | } 48 | 49 | @HeaderComments("功能设定") 50 | public static class FUNCTIONS implements Configuration { 51 | 52 | @ConfigPath("on-name-prefix") 53 | @HeaderComments({"头顶与TabList前缀功能,该方法用到了玩家名计分板接口,如有冲突请关掉哦~"}) 54 | public static final class NAME_PREFIX implements Configuration { 55 | 56 | @HeaderComments("是否开启本功能") 57 | public static final ConfiguredValue ENABLE = ConfiguredValue.of(Boolean.class, true); 58 | 59 | @HeaderComments("是否按降序排列,即权重越高的前缀显示在越上面;若为false则按升序排列。") 60 | public static final ConfiguredValue ORDER_DESC = ConfiguredValue.of(Boolean.class, true); 61 | 62 | } 63 | 64 | @ConfigPath("auto-prefix-use") 65 | @HeaderComments("自动使用前缀,即当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个") 66 | public static final ConfiguredValue AUTO_USE = ConfiguredValue.of(Boolean.class, true); 67 | 68 | 69 | @HeaderComments({ 70 | "聊天功能设定", 71 | "- 我不推荐使用本插件的聊天功能,而是建议使用其他的聊天插件。", 72 | "- 本插件仅仅提供了**最基本**的格式变量支持,不包含其他任何功能。", 73 | "- 注意聊天格式需要遵守Bukkit原格式,即不得缺失 “%1$s” 和 “%2$s” 。", 74 | "- 本插件的聊天功能不影响其他插件对聊天事件的操作。" 75 | }) 76 | public static final class CHAT implements Configuration { 77 | 78 | @HeaderComments("是否开启本功能") 79 | public static final ConfiguredValue ENABLE = ConfiguredValue.of(Boolean.class, false); 80 | @HeaderComments({ 81 | "聊天的格式,注意 “%1$s” 和 “%2$s” 不可缺少。", 82 | "- %1$s -> 玩家名", "- %2$s -> 聊天内容" 83 | }) 84 | public static final ConfiguredValue FORMAT = ConfiguredValue.of(String.class, "<%1$s> %2$s"); 85 | 86 | } 87 | 88 | } 89 | 90 | @HeaderComments({"前缀GUI界面设定"}) 91 | public static class GUI implements Configuration { 92 | 93 | @HeaderComments("GUI的标题") 94 | public static final ConfiguredValue TITLE = ConfiguredValue.of(String.class, "&f&l我的前缀 &8| 列表"); 95 | 96 | @HeaderComments("GUI中的基本按钮物品") 97 | public static final class BOTTOMS implements Configuration { 98 | 99 | @HeaderComments("前往下一页的物品 (只有存在下一页时才会显示)") 100 | public static final ConfiguredItem NEXT_PAGE = ConfiguredItem.create() 101 | .defaultType(Material.ARROW) 102 | .defaultName("下一页") 103 | .defaultLore("&7&o右键可前往最后一页哦") 104 | .build(); 105 | 106 | @ConfigPath("previous-page") 107 | @HeaderComments({"前往上一页时的物品 (只有当前页不是第一页时才会显示)"}) 108 | public static final ConfiguredItem PREV_PAGE = ConfiguredItem.create() 109 | .defaultType(Material.ARROW) 110 | .defaultName("上一页") 111 | .defaultLore("&7&o右键可前往第一页哦") 112 | .build(); 113 | 114 | } 115 | 116 | @HeaderComments("GUI中的其他按钮物品 (若与现有物品位置冲突,将被覆盖)") 117 | public static final ConfiguredValue ITEMS = ConfiguredValue 118 | .builderOf(GUIItems.class).fromSection() 119 | .defaults(GUIItems::defaults) 120 | .serialize(GUIItems::serialize) 121 | .parse(GUIItems::parse) 122 | .build(); 123 | 124 | } 125 | 126 | @HeaderComments({"相关的声音,留空则不播放声音", "格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】"}) 127 | public static final class SOUNDS implements Configuration { 128 | 129 | public static final ConfiguredSound GUI_OPEN = ConfiguredSound.of("BLOCK_NOTE_BLOCK_PLING", 0.5F, 0.8F); 130 | public static final ConfiguredSound GUI_CLICK = ConfiguredSound.of("UI_BUTTON_CLICK"); 131 | public static final ConfiguredSound PREFIX_CHANGE = ConfiguredSound.of("ENTITY_VILLAGER_YES"); 132 | public static final ConfiguredSound PREFIX_EXPIRED = ConfiguredSound.of("ENTITY_VILLAGER_NO"); 133 | 134 | } 135 | 136 | @HeaderComments({"默认前缀配置"}) 137 | public static final class DEFAULT_PREFIX implements Configuration { 138 | 139 | @HeaderComments("默认前缀的显示名称,用于在消息提示中显示。") 140 | public static final ConfiguredValue NAME = ConfiguredValue.of(String.class, "默认前缀"); 141 | 142 | @HeaderComments({"默认前缀的权重,默认为0。"}) 143 | public static final ConfiguredValue WEIGHT = ConfiguredValue.of(Integer.class, 0); 144 | 145 | @HeaderComments({"默认前缀的内容,即用于显示的实际前缀"}) 146 | public static final ConfiguredValue CONTENT = ConfiguredValue.of(String.class, "&r"); 147 | 148 | @HeaderComments({"选择默认前缀时执行的操作"}) 149 | public static final ConfiguredList ACTIONS = ConfiguredList.builderOf(String.class).fromString() 150 | .defaults("[CONSOLE] " + "say %player_name% 选择了默认前缀") 151 | .build(); 152 | 153 | @HeaderComments({"默认前缀的显示物品"}) 154 | public static final class ITEM implements Configuration { 155 | 156 | @HeaderComments({"当未选择默认前缀时显示的物品"}) 157 | public static final ConfiguredItem NOT_USING = ConfiguredItem.create() 158 | .defaultType(Material.NAME_TAG) 159 | .defaultName("&f默认玩家前缀 &f(点击切换)") 160 | .defaultLore("", "&a➥ 点击切换到该前缀") 161 | .build(); 162 | 163 | @HeaderComments({"当选择了默认前缀时显示的物品"}) 164 | public static final ConfiguredItem USING = ConfiguredItem.create() 165 | .defaultType(Material.NAME_TAG) 166 | .defaultEnchant(MajorUtil.getEnchantProtection(), 1) // 附魔改过名 167 | .defaultFlags(ItemFlag.HIDE_ENCHANTS) 168 | .defaultName("&f默认玩家前缀") 169 | .defaultLore("", "&a✔ 您正在使用该前缀") 170 | .build(); 171 | 172 | } 173 | 174 | 175 | } 176 | 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/conf/PluginMessages.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.conf; 2 | 3 | import cc.carm.lib.configuration.Configuration; 4 | import cc.carm.lib.configuration.annotation.HeaderComments; 5 | import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage; 6 | 7 | public class PluginMessages implements Configuration { 8 | 9 | public static final class COMMAND_USAGE implements Configuration { 10 | 11 | public static final ConfiguredMessage CONSOLE = ConfiguredMessage.asString().defaults( 12 | "&f请输入 &b/prefix <玩家ID> &f为指定玩家打开前缀GUI。" 13 | ).build(); 14 | 15 | public static final ConfiguredMessage ADMIN = ConfiguredMessage.asString().defaults( 16 | "&3&l用户前缀系统 &f帮助", 17 | "&8# &f/upa list", 18 | "&8- &7查看当前前缀列表。", 19 | "&8# &f/upa set &b<玩家ID> &b<前缀ID>", 20 | "&8- &7为玩家设定指定前缀。", 21 | "&8- &7&o注意:玩家必须拥有指定前缀的权限。", 22 | "&8# &f/upa reload", 23 | "&8- &7重载前缀配置。" 24 | ).build(); 25 | 26 | public static final ConfiguredMessage NO_PERM = ConfiguredMessage.asString() 27 | .defaults("&c&l抱歉!&f但您没有权限使用该指令。") 28 | .build(); 29 | 30 | } 31 | 32 | public static final ConfiguredMessage NOT_ONLINE = ConfiguredMessage.asString() 33 | .defaults("&7玩家 &b%(player) &7并不在线。") 34 | .params("player").build(); 35 | 36 | public static final ConfiguredMessage SELECTED = ConfiguredMessage.asString() 37 | .defaults("&7您选择了 &f%(name) &7作为当前显示的前缀。") 38 | .params("name").build(); 39 | 40 | public static final ConfiguredMessage EXPIRED = ConfiguredMessage.asString() 41 | .defaults( 42 | "&7您先前使用的前缀 &f%(oldName) &7已到期。", 43 | "&7现在已为您重新调整为 &f%(newName) &7。" 44 | ).params("oldName", "newName").build(); 45 | 46 | public static final ConfiguredMessage REMOVED = ConfiguredMessage.asString() 47 | .defaults("&7您先前使用的前缀已被移除,现在已为您重新调整为 &f%(newName) &7。") 48 | .params("newName").build(); 49 | 50 | public static final class RELOAD implements Configuration { 51 | 52 | public static final ConfiguredMessage SUCCESS = ConfiguredMessage.asString() 53 | .defaults("&a&l重载完成!&7耗时 &f%(time)ms&7,共加载了 &b%(count) &7个前缀。") 54 | .params("time", "count").build(); 55 | 56 | public static final ConfiguredMessage FAILED = ConfiguredMessage.asString() 57 | .defaults("&c&l重载出错!&7错误提示为 &8“&r%(error)&8”。") 58 | .params("error").build(); 59 | } 60 | 61 | public static final class SET implements Configuration { 62 | 63 | public static final ConfiguredMessage SUCCESS = ConfiguredMessage.asString() 64 | .defaults("&a&l设置成功!&7成功设定玩家 &b%(player) &f的前缀为 &r%(prefix) &f。") 65 | .params("player", "prefix").build(); 66 | 67 | public static final ConfiguredMessage PREFIX_NOT_FOUND = ConfiguredMessage.asString() 68 | .defaults("&c&l无法设置!&7不存在ID为 &b%(prefix) &7的前缀。") 69 | .params("prefix").build(); 70 | 71 | public static final ConfiguredMessage NO_PERM = ConfiguredMessage.asString() 72 | .defaults("&c&l无法设置!&7玩家 &b%(player) &7并没有前缀 &r%(prefix) &7的前缀。") 73 | .params("player", "prefix") 74 | .build(); 75 | 76 | } 77 | 78 | 79 | @HeaderComments("管理员使用的 “/upa list” 指令的格式") 80 | public static final class LIST implements Configuration { 81 | 82 | public static final ConfiguredMessage HEADER = ConfiguredMessage.asString() 83 | .defaults("&3&l用户前缀系统 &f前缀列表").build(); 84 | 85 | public static final ConfiguredMessage VALUE = ConfiguredMessage.asString().defaults( 86 | "&8#%(weight) &f%(identifier)", 87 | "&8- &7显示名 &r%(name) &7权限 &r%(permission)", 88 | "&8- &7内容示例&r %(content) %(sender_name)" 89 | ).params("weight", "identifier", "name", "permission", "content", "sender_name").build(); 90 | 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/conf/gui/GUIItems.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.conf.gui; 2 | 3 | import cc.carm.lib.configuration.source.section.ConfigureSection; 4 | import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration; 5 | import cc.carm.lib.easyplugin.gui.configuration.GUIActionType; 6 | import cc.carm.lib.easyplugin.gui.configuration.GUIConfiguration; 7 | import cc.carm.lib.easyplugin.gui.configuration.GUIItemConfiguration; 8 | import cc.carm.lib.mineconfiguration.bukkit.source.BukkitSection; 9 | import cc.carm.plugin.userprefix.Main; 10 | import org.bukkit.Material; 11 | 12 | import java.util.Collections; 13 | import java.util.LinkedHashMap; 14 | import java.util.Map; 15 | import java.util.stream.Collectors; 16 | 17 | public class GUIItems { 18 | 19 | protected final Map items; 20 | 21 | public GUIItems(Map items) { 22 | this.items = items; 23 | } 24 | 25 | public Map getItems() { 26 | return items; 27 | } 28 | 29 | public Map serialize() { 30 | return items.entrySet().stream().collect(Collectors.toMap( 31 | Map.Entry::getKey, 32 | entry -> entry.getValue().serialize(), (a, b) -> b, 33 | LinkedHashMap::new 34 | )); 35 | } 36 | 37 | public static GUIItems parse(ConfigureSection section) { 38 | if (!(section instanceof BukkitSection)) { 39 | Main.severe("Unknown configure source, it should never happened!"); 40 | Main.severe("Required: " + BukkitSection.class.getSimpleName()); 41 | Main.severe("Found: " + section.getClass().getSimpleName()); 42 | return new GUIItems(new LinkedHashMap<>()); 43 | } 44 | BukkitSection craft = (BukkitSection) section; 45 | return new GUIItems(GUIConfiguration.readItems(craft.data())); 46 | } 47 | 48 | public static GUIItems defaults() { 49 | LinkedHashMap map = new LinkedHashMap<>(); 50 | map.put("back", new GUIItemConfiguration( 51 | Material.BARRIER, 1, 0, "&c&l返回", 52 | Collections.singletonList("&f点击即可返回上一菜单"), 53 | Collections.singletonList(GUIActionConfiguration.of(GUIActionType.CHAT, "/menu")), 54 | Collections.singletonList(49) 55 | )); 56 | return new GUIItems(map); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/conf/prefix/PrefixConfig.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.conf.prefix; 2 | 3 | import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration; 4 | import cc.carm.lib.easyplugin.gui.configuration.GUIActionType; 5 | import cc.carm.lib.easyplugin.utils.MessageUtils; 6 | import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem; 7 | import cc.carm.plugin.userprefix.Main; 8 | import cc.carm.plugin.userprefix.manager.ServiceManager; 9 | import org.bukkit.command.CommandSender; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.inventory.ItemStack; 12 | import org.jetbrains.annotations.Contract; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | 16 | import java.util.List; 17 | 18 | public class PrefixConfig { 19 | 20 | protected final @NotNull String identifier; 21 | 22 | protected final @NotNull String name; 23 | protected final @NotNull String content; 24 | 25 | protected final int weight; 26 | 27 | protected final @Nullable String permission; 28 | 29 | protected final @NotNull List actions; 30 | 31 | protected final @NotNull ItemStack itemHasPermission; 32 | protected final @Nullable ItemStack itemNoPermission; 33 | protected final @Nullable ItemStack itemWhenUsing; 34 | 35 | public PrefixConfig(@NotNull String identifier, @NotNull String name, 36 | @NotNull String content, int weight, @Nullable String permission, 37 | @NotNull List actions, 38 | @NotNull ItemStack itemHasPermission, 39 | @Nullable ItemStack itemWhenUsing, 40 | @Nullable ItemStack itemNoPermission) { 41 | this.identifier = identifier; 42 | this.name = name; 43 | this.content = content; 44 | this.weight = weight; 45 | this.permission = permission; 46 | this.actions = actions; 47 | this.itemHasPermission = itemHasPermission; 48 | this.itemNoPermission = itemNoPermission; 49 | this.itemWhenUsing = itemWhenUsing; 50 | } 51 | 52 | @NotNull 53 | public String getIdentifier() { 54 | return identifier; 55 | } 56 | 57 | @NotNull 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | @NotNull 63 | public String getContent(CommandSender viewer) { 64 | return MessageUtils.setPlaceholders(viewer, content); 65 | } 66 | 67 | public int getWeight() { 68 | return weight; 69 | } 70 | 71 | @Nullable 72 | public String getPermission() { 73 | return permission; 74 | } 75 | 76 | @NotNull 77 | public ItemStack getItemHasPermission(@Nullable Player player) { 78 | return getItem(player, this.itemHasPermission); 79 | } 80 | 81 | @Nullable 82 | public ItemStack getItemNoPermission(@Nullable Player player) { 83 | return getItem(player, this.itemNoPermission); 84 | } 85 | 86 | @Nullable 87 | public ItemStack getItemWhenUsing(@Nullable Player player) { 88 | return getItem(player, this.itemWhenUsing); 89 | } 90 | 91 | @Contract("_,!null->!null") 92 | protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) { 93 | return PreparedItem.of(item).get(player); 94 | } 95 | 96 | 97 | public boolean isPublic() { 98 | return getPermission() == null; 99 | } 100 | 101 | public void executeActions(@NotNull Player player) { 102 | this.actions.forEach(action -> { 103 | if (action.getActionType() == GUIActionType.CONSOLE) { // 控制台执行命令必须在全局调度器中执行 104 | Main.getInstance().getFoliaScheduler().runGlobal(false, () -> action.executeAction(player)); 105 | } else { 106 | action.executeAction(player); 107 | } 108 | }); 109 | } 110 | 111 | public boolean isVisible(Player player) { 112 | return this.itemNoPermission != null || checkPermission(player); 113 | } 114 | 115 | /** 116 | * 判断某玩家是否有权限使用该前缀 117 | * 118 | * @param player 玩家 119 | * @return 若前缀标识不存在,则返回false;若前缀为默认前缀,或该前缀无权限,或玩家有该前缀的权限,则返回true。 120 | */ 121 | public boolean checkPermission(Player player) { 122 | return permission == null || ServiceManager.hasPermission(player, permission); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/event/UserPrefixChangeEvent.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.event; 2 | 3 | import cc.carm.plugin.userprefix.Main; 4 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.Cancellable; 8 | import org.bukkit.event.HandlerList; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import java.util.Optional; 13 | import java.util.function.Consumer; 14 | 15 | public class UserPrefixChangeEvent extends UserPrefixEvent implements Cancellable { 16 | 17 | public static HandlerList handler = new HandlerList(); 18 | 19 | private boolean cancelled; 20 | 21 | private final @Nullable PrefixConfig before; 22 | private @NotNull PrefixConfig after; 23 | 24 | public UserPrefixChangeEvent(@NotNull Player who, 25 | @Nullable PrefixConfig before, 26 | @NotNull PrefixConfig after) { 27 | super(who); 28 | this.before = before; 29 | this.after = after; 30 | } 31 | 32 | public @Nullable PrefixConfig getBefore() { 33 | return before; 34 | } 35 | 36 | public @NotNull PrefixConfig getAfter() { 37 | return after; 38 | } 39 | 40 | public void setAfter(@NotNull PrefixConfig after) { 41 | this.after = after; 42 | } 43 | 44 | @Override 45 | public boolean isCancelled() { 46 | if (before == null) return false; //Could not be cancelled when prefix is null. 47 | else return this.cancelled; 48 | } 49 | 50 | @Override 51 | public void setCancelled(boolean cancel) { 52 | this.cancelled = cancel; 53 | } 54 | 55 | @NotNull 56 | @Override 57 | public HandlerList getHandlers() { 58 | return handler; 59 | } 60 | 61 | public static void call(@NotNull Player who, 62 | @Nullable PrefixConfig before, 63 | @NotNull PrefixConfig after, 64 | @Nullable Consumer<@Nullable PrefixConfig> finish) { 65 | UserPrefixChangeEvent event = new UserPrefixChangeEvent(who, before, after); 66 | Main.getInstance().getFoliaScheduler().runGlobal(true, () -> { 67 | Bukkit.getPluginManager().callEvent(event); 68 | Optional.ofNullable(finish).ifPresent(f -> f.accept(event.getAfter())); 69 | }); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/event/UserPrefixEvent.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.event; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.player.PlayerEvent; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public abstract class UserPrefixEvent extends PlayerEvent { 8 | 9 | public UserPrefixEvent(@NotNull Player who) { 10 | super(who); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/event/UserPrefixExpireEvent.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.event; 2 | 3 | import cc.carm.plugin.userprefix.Main; 4 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.HandlerList; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public class UserPrefixExpireEvent extends UserPrefixEvent { 11 | 12 | public static HandlerList handler = new HandlerList(); 13 | 14 | 15 | public final @NotNull PrefixConfig expiredPrefix; 16 | 17 | public UserPrefixExpireEvent(@NotNull Player who, 18 | @NotNull PrefixConfig expiredPrefix) { 19 | super(who); 20 | this.expiredPrefix = expiredPrefix; 21 | } 22 | 23 | public @NotNull PrefixConfig getExpiredPrefix() { 24 | return expiredPrefix; 25 | } 26 | 27 | @NotNull 28 | @Override 29 | public HandlerList getHandlers() { 30 | return handler; 31 | } 32 | 33 | public static void call(@NotNull Player player, @NotNull PrefixConfig currentPrefix) { 34 | Main.getInstance().getFoliaScheduler().runGlobal(true, () -> Bukkit.getPluginManager().callEvent(new UserPrefixExpireEvent(player, currentPrefix))); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/folia/FoliaScheduler.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.folia; 2 | 3 | import cc.carm.plugin.userprefix.Main; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.plugin.Plugin; 7 | 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.util.function.Consumer; 10 | 11 | public class FoliaScheduler { 12 | private final Main plugin; 13 | private final boolean folia; 14 | 15 | public FoliaScheduler(Main plugin, boolean folia) { 16 | this.plugin = plugin; 17 | this.folia = folia; 18 | } 19 | 20 | public void runAsync(Runnable task) { 21 | if (this.folia) { 22 | this.runAsyncFolia(task); 23 | } else { 24 | this.runAsyncBukkit(task); 25 | } 26 | } 27 | 28 | private void runAsyncBukkit(Runnable task) { 29 | Bukkit.getScheduler().runTaskAsynchronously(this.plugin, task); 30 | } 31 | 32 | private void runAsyncFolia(Runnable task) { 33 | // AsyncScheduler asyncScheduler = Bukkit.getAsyncScheduler(); 34 | // asyncScheduler.runNow(this.plugin, t -> task.run()); 35 | 36 | try { 37 | Object asyncScheduler = Bukkit.class.getMethod("getAsyncScheduler") 38 | .invoke(null); 39 | asyncScheduler.getClass().getMethod("runNow", Plugin.class, Consumer.class) 40 | .invoke(asyncScheduler, this.plugin, (Consumer) t -> task.run()); 41 | } catch (IllegalAccessException | NoSuchMethodException e) { 42 | Main.severe("unexpected exception during reflection (#runAsyncFolia), it should never happen!"); 43 | e.printStackTrace(); 44 | } catch (InvocationTargetException e) { 45 | throw (RuntimeException) e.getTargetException(); 46 | } 47 | } 48 | 49 | /** 50 | * Folia 上在实体所在的调度器上执行任务,或在 Bukkit 上同步执行任务 51 | * 52 | * @param entity 实体 53 | * @param forceSync 若为 true,Bukkit 下强制同步运行;若为 false,Bukkit 下直接执行 54 | * @param task 任务 55 | * @see FoliaScheduler#runBukkit(boolean, Runnable) 56 | * @see FoliaScheduler#runOnEntityFolia(Entity, Runnable) 57 | */ 58 | public void runOnEntity(Entity entity, boolean forceSync, Runnable task) { 59 | if (this.folia) { 60 | this.runOnEntityFolia(entity, task); 61 | } else { 62 | this.runBukkit(forceSync, task); 63 | } 64 | } 65 | 66 | private void runOnEntityFolia(Entity entity, Runnable task) { 67 | // EntityScheduler entityScheduler = entity.getScheduler(); 68 | // entityScheduler.run(this.plugin, t -> task.run(), null); 69 | try { 70 | Object entityScheduler = Entity.class.getMethod("getScheduler") 71 | .invoke(entity); 72 | entityScheduler.getClass().getMethod("run", Plugin.class, Consumer.class, Runnable.class) 73 | .invoke(entityScheduler, this.plugin, (Consumer) t -> task.run(), null); 74 | } catch (IllegalAccessException | NoSuchMethodException e) { 75 | Main.severe("unexpected exception during reflection (#runOnEntityFolia), it should never happen!"); 76 | e.printStackTrace(); 77 | } catch (InvocationTargetException e) { 78 | throw (RuntimeException) e.getTargetException(); 79 | } 80 | } 81 | 82 | /** 83 | * Folia 上在全局调度器上执行任务,或在 Bukkit 上同步执行任务 84 | * 85 | * @param forceSync 若为 true,Bukkit 下强制同步运行;若为 false,Bukkit 下直接执行 86 | * @param task 任务 87 | * @see FoliaScheduler#runBukkit(boolean, Runnable) 88 | * @see FoliaScheduler#runGlobalFolia(Runnable) 89 | */ 90 | public void runGlobal(boolean forceSync, Runnable task) { 91 | if (this.folia) { 92 | this.runGlobalFolia(task); 93 | } else { 94 | this.runBukkit(forceSync, task); 95 | } 96 | } 97 | 98 | private void runGlobalFolia(Runnable task) { 99 | // GlobalRegionScheduler globalRegionScheduler = Bukkit.getGlobalRegionScheduler(); 100 | // globalRegionScheduler.execute(this.plugin, task); 101 | try { 102 | Object globalRegionScheduler = Bukkit.class.getMethod("getGlobalRegionScheduler") 103 | .invoke(null); 104 | globalRegionScheduler.getClass().getMethod("execute", Plugin.class, Runnable.class) 105 | .invoke(globalRegionScheduler, this.plugin, task); 106 | } catch (IllegalAccessException | NoSuchMethodException e) { 107 | Main.severe("unexpected exception during reflection (#runGlobalFolia), it should never happen!"); 108 | e.printStackTrace(); 109 | } catch (InvocationTargetException e) { 110 | throw (RuntimeException) e.getTargetException(); 111 | } 112 | } 113 | 114 | private void runBukkit(boolean forceSync, Runnable task) { 115 | if (forceSync) { 116 | Bukkit.getScheduler().runTask(this.plugin, task); 117 | } else { 118 | task.run(); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/folia/MajorUtil.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.folia; 2 | 3 | import cc.carm.plugin.userprefix.Main; 4 | import org.bukkit.enchantments.Enchantment; 5 | 6 | public interface MajorUtil { 7 | static Enchantment getEnchantProtection() { 8 | Class enchantmentClass = Enchantment.class; 9 | try { 10 | return (Enchantment) enchantmentClass.getField("PROTECTION_ENVIRONMENTAL").get(null); 11 | } catch (NoSuchFieldException e1) { 12 | try { 13 | return (Enchantment) enchantmentClass.getField("PROTECTION").get(null); 14 | } catch (NoSuchFieldException | IllegalAccessException e2) { 15 | Main.severe("unexpected exception during reflection (#getEnchantProtection), it should never happen!"); 16 | throw new RuntimeException(e2); 17 | } 18 | } catch (IllegalAccessException e) { 19 | Main.severe("unexpected exception during reflection (#getEnchantProtection), it should never happen!"); 20 | throw new RuntimeException(e); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/hooker/UserNameTag.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.hooker; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.scoreboard.Scoreboard; 6 | import org.bukkit.scoreboard.Team; 7 | import org.jetbrains.annotations.Range; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | import java.util.Set; 12 | import java.util.UUID; 13 | 14 | /** 15 | * 用户头顶标签。 16 | * 17 | * @author LSeng, Tony, Carm 18 | */ 19 | public class UserNameTag { 20 | 21 | public static final int MAX_ORDER = 999; 22 | 23 | private final Player viewer; 24 | private Team team; 25 | private final Scoreboard sb; 26 | private int order = MAX_ORDER; 27 | private final Map targetOrders = new HashMap<>(); 28 | private final Map previousTeamNames = new HashMap<>(); 29 | 30 | public UserNameTag(Player viewer) { 31 | this.viewer = viewer; 32 | Scoreboard sb = viewer.getScoreboard(); 33 | if (sb == Bukkit.getServer().getScoreboardManager().getMainScoreboard()) { 34 | sb = Bukkit.getScoreboardManager().getNewScoreboard(); 35 | } 36 | team = sb.registerNewTeam(order + viewer.getUniqueId().toString().substring(0, 10)); 37 | team.setCanSeeFriendlyInvisibles(true); 38 | team.addEntry(viewer.getName()); 39 | this.sb = sb; 40 | viewer.setScoreboard(sb); 41 | } 42 | 43 | /** 44 | * 设置自己的前缀 45 | * 46 | * @param prefix 前缀内容 47 | */ 48 | public void setPrefix(String prefix) { 49 | team.setPrefix(prefix); 50 | update(viewer); 51 | } 52 | 53 | /** 54 | * 设置某个玩家的前缀 55 | * 56 | * @param target 目标 57 | * @param prefix 前缀内容 58 | */ 59 | public void setPrefix(Player target, String prefix) { 60 | if (target == viewer) { 61 | setPrefix(prefix); 62 | } else { 63 | Team targetTeam = checkTeam(target); 64 | targetTeam.setPrefix(prefix); 65 | } 66 | update(viewer); 67 | if (viewer != target) 68 | update(target); 69 | } 70 | 71 | /** 72 | * 设置名字在TabList中的顺序 73 | * 74 | * @param order 顺序 (0~999) 75 | */ 76 | public void setOrder(@Range(from = 0, to = 999) int order) { 77 | this.order = order; 78 | targetOrders.put(viewer.getUniqueId(), order); 79 | update(viewer); 80 | } 81 | 82 | /** 83 | * 设置名字在TabList中的顺序 84 | * 85 | * @param order 顺序 86 | */ 87 | public void setOrder(Player target, @Range(from = 0, to = 999) int order) { 88 | Team targetTeam = checkTeam(target); 89 | String teamName = order + UUID.randomUUID().toString().substring(0, 10); 90 | targetTeam.setDisplayName(teamName); 91 | targetOrders.put(target.getUniqueId(), order); 92 | update(viewer); 93 | if (viewer != target) update(target); 94 | } 95 | 96 | public void update(Player target) { 97 | if (target == viewer) { 98 | Set entries = team.getEntries(); 99 | String name = order + viewer.getUniqueId().toString().substring(0, 10); 100 | if (sb.getTeam(name) == null) { 101 | Team newTeam = sb.registerNewTeam(name); 102 | newTeam.setDisplayName(name); 103 | entries.forEach(newTeam::addEntry); 104 | team.getPrefix(); 105 | if (!team.getPrefix().isEmpty()) 106 | newTeam.setPrefix(team.getPrefix()); 107 | team.getSuffix(); 108 | if (!team.getSuffix().isEmpty()) 109 | newTeam.setSuffix(team.getSuffix()); 110 | newTeam.setNameTagVisibility(team.getNameTagVisibility()); 111 | newTeam.setCanSeeFriendlyInvisibles(true); 112 | team.unregister(); 113 | team = newTeam; 114 | } 115 | } else { 116 | int order = targetOrders.getOrDefault(target.getUniqueId(), 999); 117 | String previousTeamName = previousTeamNames.get(target.getUniqueId()); 118 | if (previousTeamName == null) { 119 | return; 120 | } 121 | String name = order + target.getUniqueId().toString().substring(0, 10); 122 | Team targetTeam = this.sb.getTeam(previousTeamName); 123 | if (targetTeam == null) { 124 | return; 125 | } 126 | if (sb.getTeam(name) == null) { 127 | Team newTeam = sb.registerNewTeam(name); 128 | newTeam.setDisplayName(name); 129 | newTeam.addEntry(target.getName()); 130 | newTeam.setNameTagVisibility(targetTeam.getNameTagVisibility()); 131 | newTeam.setCanSeeFriendlyInvisibles(true); 132 | targetTeam.getPrefix(); 133 | if (!targetTeam.getPrefix().isEmpty()) newTeam.setPrefix(targetTeam.getPrefix()); 134 | targetTeam.getSuffix(); 135 | if (!targetTeam.getSuffix().isEmpty()) newTeam.setSuffix(targetTeam.getSuffix()); 136 | targetTeam.unregister(); 137 | previousTeamNames.put(target.getUniqueId(), name); 138 | } 139 | } 140 | 141 | } 142 | 143 | private Team checkTeam(Player target) { 144 | int order = targetOrders.getOrDefault(target.getUniqueId(), 999); 145 | String name = order + target.getUniqueId().toString().substring(0, 10); 146 | Team targetTeam = this.sb.getTeam(name); 147 | if (targetTeam == null) { 148 | targetTeam = this.sb.registerNewTeam(name); 149 | targetTeam.addEntry(target.getName()); 150 | previousTeamNames.put(target.getUniqueId(), name); 151 | } 152 | return targetTeam; 153 | } 154 | 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/hooker/UserPrefixExpansion.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.hooker; 2 | 3 | import cc.carm.lib.easyplugin.papi.EasyPlaceholder; 4 | import cc.carm.lib.easyplugin.papi.expansion.SubExpansion; 5 | import cc.carm.lib.easyplugin.papi.handler.PlaceholderHandler; 6 | import cc.carm.plugin.userprefix.UserPrefixAPI; 7 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 8 | import org.bukkit.OfflinePlayer; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.Collections; 15 | import java.util.function.BiFunction; 16 | import java.util.function.Function; 17 | 18 | public class UserPrefixExpansion extends EasyPlaceholder { 19 | 20 | public UserPrefixExpansion(@NotNull JavaPlugin plugin, @NotNull String rootIdentifier) { 21 | super(plugin, rootIdentifier); 22 | 23 | handle("version", (player, args) -> getVersion()); 24 | 25 | handle("identifier", handlePrefix(PrefixConfig::getIdentifier), "id"); 26 | handle("prefix", handlePrefix(PrefixConfig::getContent)); 27 | handle("name", handlePrefix(PrefixConfig::getName)); 28 | handle("weight", handlePrefix(PrefixConfig::getWeight)); 29 | handle("amount", handlePlayer( 30 | (player) -> UserPrefixAPI.getUserManager().getUsablePrefixes(player).size() + 1) 31 | ); 32 | 33 | handle("has", handlePlayer((player, args) -> { 34 | if (args.length < 1) return "参数不足"; 35 | PrefixConfig prefix = UserPrefixAPI.getPrefixManager().getPrefix(args[0]); 36 | if (prefix == null) return "该前缀不存在"; 37 | return prefix.checkPermission(player); 38 | }), Collections.singletonList("<前缀ID>")); 39 | 40 | } 41 | 42 | public PlaceholderHandler handlePrefix(Function handler) { 43 | return handlePlayer((player, args) -> handler.apply(UserPrefixAPI.getUserManager().getPrefix(player))); 44 | } 45 | 46 | public PlaceholderHandler handlePrefix(BiFunction handler) { 47 | return handlePlayer((player, args) -> handler.apply(UserPrefixAPI.getUserManager().getPrefix(player), player)); 48 | } 49 | 50 | /** 51 | * This is required or else PlaceholderAPI will unregister the Expansion on reload 52 | */ 53 | @Override 54 | public boolean persist() { 55 | return true; 56 | } 57 | 58 | public PlaceholderHandler handlePlayer(BiFunction handler) { 59 | return (player, args) -> { 60 | if (player == null || !player.isOnline()) return "Loading..."; 61 | return handler.apply((Player) player, args); 62 | }; 63 | } 64 | 65 | public PlaceholderHandler handlePlayer(Function handler) { 66 | return handlePlayer((player, args) -> handler.apply(player)); 67 | } 68 | 69 | @Override 70 | public String onErrorParams(@Nullable OfflinePlayer player) { 71 | return "参数不足"; 72 | } 73 | 74 | @Override 75 | public String onException(@Nullable OfflinePlayer player, @NotNull SubExpansion expansion, 76 | @NotNull Exception exception) { 77 | exception.printStackTrace(); 78 | return "参数错误"; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.listener; 2 | 3 | import cc.carm.lib.easyplugin.utils.MessageUtils; 4 | import cc.carm.plugin.userprefix.Main; 5 | import cc.carm.plugin.userprefix.conf.PluginConfig; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.player.AsyncPlayerChatEvent; 9 | 10 | public class ChatListener implements Listener { 11 | 12 | @EventHandler 13 | public void onChat(AsyncPlayerChatEvent event) { 14 | if (!PluginConfig.FUNCTIONS.CHAT.ENABLE.getNotNull()) return; 15 | 16 | String format = PluginConfig.FUNCTIONS.CHAT.FORMAT.get(); 17 | if (format == null || format.length() < 1) return; 18 | 19 | try { 20 | event.setFormat(MessageUtils.setPlaceholders(event.getPlayer(), format)); 21 | } catch (Exception exception) { 22 | Main.severe("请检查配置文件中聊天相关是否配置正确。"); 23 | Main.severe("Please check the chat configuration."); 24 | exception.printStackTrace(); 25 | } 26 | 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/listener/UserListener.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.listener; 2 | 3 | import cc.carm.plugin.userprefix.UserPrefixAPI; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.player.PlayerJoinEvent; 7 | import org.bukkit.event.player.PlayerQuitEvent; 8 | 9 | public class UserListener implements Listener { 10 | 11 | @EventHandler 12 | public void onJoin(PlayerJoinEvent event) { 13 | UserPrefixAPI.getUserManager().initPlayer(event.getPlayer()); 14 | } 15 | 16 | @EventHandler 17 | public void onLeave(PlayerQuitEvent event) { 18 | UserPrefixAPI.getUserManager().unloadPlayer(event.getPlayer()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/listener/UserPermListener.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.listener; 2 | 3 | import cc.carm.plugin.userprefix.Main; 4 | import cc.carm.plugin.userprefix.UserPrefixAPI; 5 | import cc.carm.plugin.userprefix.ui.PrefixSelectGUI; 6 | import net.luckperms.api.event.user.UserDataRecalculateEvent; 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.entity.Player; 9 | 10 | public class UserPermListener { 11 | 12 | public static void process(UserDataRecalculateEvent event) { 13 | Player player = Bukkit.getPlayer(event.getUser().getUniqueId()); 14 | if (player == null) return; 15 | UserPrefixAPI.getUserManager().checkPrefix(player, true); 16 | if (PrefixSelectGUI.openingUsers.contains(player)) { 17 | Main.getInstance().getFoliaScheduler().runOnEntity(player, true, () -> { 18 | // 玩家权限更新,同步关闭其GUI,以令其重新打开刷新自己的前缀。 19 | player.closeInventory(); 20 | PrefixSelectGUI.removeOpening(player); 21 | }); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/manager/ConfigManager.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.manager; 2 | 3 | import cc.carm.lib.configuration.source.ConfigurationHolder; 4 | import cc.carm.lib.easyplugin.utils.JarResourceUtils; 5 | import cc.carm.lib.mineconfiguration.bukkit.MineConfiguration; 6 | import cc.carm.plugin.userprefix.conf.PluginConfig; 7 | import cc.carm.plugin.userprefix.conf.PluginMessages; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | 12 | public class ConfigManager { 13 | 14 | private final ConfigurationHolder configProvider; 15 | private final ConfigurationHolder messageProvider; 16 | 17 | public ConfigManager(File dataFolder) { 18 | firstInitialize(dataFolder); 19 | this.configProvider = MineConfiguration.from(new File(dataFolder, "config.yml"), null); 20 | this.messageProvider = MineConfiguration.from(new File(dataFolder, "messages.yml"), null); 21 | this.configProvider.initialize(PluginConfig.class); 22 | this.messageProvider.initialize(PluginMessages.class); 23 | } 24 | 25 | protected void firstInitialize(File dataFolder) { 26 | File configFile = new File(dataFolder, "config.yml"); 27 | if (!configFile.exists()) { 28 | try { 29 | JarResourceUtils.copyFolderFromJar("i18n", dataFolder, JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST); 30 | JarResourceUtils.copyFolderFromJar("prefixes", dataFolder, JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | } 37 | 38 | public ConfigurationHolder getConfigProvider() { 39 | return configProvider; 40 | } 41 | 42 | public ConfigurationHolder getMessageProvider() { 43 | return messageProvider; 44 | } 45 | 46 | public void reload() throws Exception { 47 | getConfigProvider().reload(); 48 | getMessageProvider().reload(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/manager/PrefixManager.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.manager; 2 | 3 | import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration; 4 | import cc.carm.lib.easyplugin.utils.ItemStackFactory; 5 | import cc.carm.plugin.userprefix.Main; 6 | import cc.carm.plugin.userprefix.conf.PluginConfig; 7 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 8 | import com.cryptomorin.xseries.XItemStack; 9 | import org.bukkit.Material; 10 | import org.bukkit.configuration.ConfigurationSection; 11 | import org.bukkit.configuration.file.FileConfiguration; 12 | import org.bukkit.configuration.file.YamlConfiguration; 13 | import org.bukkit.entity.Player; 14 | import org.bukkit.inventory.ItemStack; 15 | import org.jetbrains.annotations.Contract; 16 | import org.jetbrains.annotations.NotNull; 17 | import org.jetbrains.annotations.Nullable; 18 | 19 | import java.io.File; 20 | import java.util.*; 21 | import java.util.stream.Collectors; 22 | 23 | public class PrefixManager { 24 | 25 | protected static final String FOLDER_NAME = "prefixes"; 26 | 27 | protected @NotNull Map prefixes = new HashMap<>(); 28 | protected PrefixConfig defaultPrefix; 29 | 30 | public int loadPrefixes() { 31 | loadDefaultPrefix(); 32 | loadConfiguredPrefixes(); 33 | return prefixes.size(); 34 | } 35 | 36 | @SuppressWarnings("ResultOfMethodCallIgnored") 37 | public void loadConfiguredPrefixes() { 38 | 39 | File prefixDataFolder = getStorageFolder(); 40 | if (!prefixDataFolder.isDirectory() || !prefixDataFolder.exists()) { 41 | prefixDataFolder.mkdir(); 42 | } 43 | 44 | String[] filesList = prefixDataFolder.list(); 45 | if (filesList == null || filesList.length < 1) { 46 | Main.severe("配置文件夹中暂无任何前缀配置问,请检查。"); 47 | Main.severe("There's no configured prefix."); 48 | Main.severe("Path: " + prefixDataFolder.getAbsolutePath()); 49 | return; 50 | } 51 | 52 | List files = Arrays.stream(filesList) 53 | .map(s -> new File(prefixDataFolder, s)) 54 | .filter(File::isFile) 55 | .collect(Collectors.toList()); 56 | 57 | HashMap loaded = new HashMap<>(); 58 | 59 | if (files.size() > 0) { 60 | for (File file : files) { 61 | try { 62 | PrefixConfig prefix = addPrefix(file); 63 | Main.debugging("完成前缀加载 " + prefix.getIdentifier() + " : " + prefix.getName()); 64 | loaded.put(prefix.getIdentifier(), prefix); 65 | } catch (Exception ex) { 66 | Main.severe("在加载前缀 " + file.getAbsolutePath() + " 时出错,请检查配置!"); 67 | Main.severe("Error occurred when loading prefix #" + file.getAbsolutePath() + " !"); 68 | ex.printStackTrace(); 69 | } 70 | } 71 | } 72 | 73 | this.prefixes = loaded; 74 | } 75 | 76 | public void loadDefaultPrefix() { 77 | this.defaultPrefix = new PrefixConfig( 78 | "default", 79 | PluginConfig.DEFAULT_PREFIX.NAME.getNotNull(), 80 | PluginConfig.DEFAULT_PREFIX.CONTENT.getNotNull(), 81 | PluginConfig.DEFAULT_PREFIX.WEIGHT.getNotNull(), 82 | null, 83 | readActions(PluginConfig.DEFAULT_PREFIX.ACTIONS.get()), 84 | PluginConfig.DEFAULT_PREFIX.ITEM.NOT_USING.getNotNull(), 85 | PluginConfig.DEFAULT_PREFIX.ITEM.USING.get(), null 86 | ); 87 | Main.debugging(" 完成默认前缀加载 " + defaultPrefix.getName()); 88 | } 89 | 90 | public List getVisiblePrefix(Player player) { 91 | return getPrefixes().values().stream() 92 | .filter(c -> c.isVisible(player)) 93 | .sorted(Comparator.comparingInt(PrefixConfig::getWeight)) 94 | .collect(Collectors.toList()); 95 | } 96 | 97 | @NotNull 98 | public PrefixConfig getDefaultPrefix() { 99 | return defaultPrefix; 100 | } 101 | 102 | @NotNull 103 | public Map getPrefixes() { 104 | return prefixes; 105 | } 106 | 107 | @Nullable 108 | public PrefixConfig getPrefix(String identifier) { 109 | if (identifier == null) { 110 | return null; 111 | } else if (identifier.equalsIgnoreCase("default")) { 112 | return getDefaultPrefix(); 113 | } else { 114 | return getPrefixes().get(identifier); 115 | } 116 | } 117 | 118 | 119 | protected File getStorageFolder() { 120 | if (PluginConfig.CUSTOM_STORAGE.ENABLE.getNotNull()) { 121 | return new File(PluginConfig.CUSTOM_STORAGE.PATH.getNotNull()); 122 | } else { 123 | return new File(Main.getInstance().getDataFolder() + File.separator + FOLDER_NAME); 124 | } 125 | } 126 | 127 | public static @NotNull PrefixConfig addPrefix(@NotNull File file) throws Exception { 128 | FileConfiguration conf = YamlConfiguration.loadConfiguration(file); 129 | String identifier = conf.getString("identifier"); 130 | if (identifier == null) 131 | throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的唯一标识。"); 132 | 133 | String name = conf.getString("name"); 134 | if (name == null) throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的显示名称。"); 135 | 136 | return new PrefixConfig( 137 | identifier, name, 138 | conf.getString("content", "&r"), 139 | conf.getInt("weight", 1), 140 | conf.getString("permission"), 141 | readActions(conf.getStringList("actions")), 142 | readItem( 143 | conf.getConfigurationSection("item.has-perm"), 144 | new ItemStackFactory(Material.STONE) 145 | .setDisplayName(name) 146 | .addLore("§a➥ 点击切换到该前缀") 147 | .toItemStack() 148 | ), 149 | readItem(conf.getConfigurationSection("item.using"), null), 150 | readItem(conf.getConfigurationSection("item.no-perm"), null) 151 | ); 152 | } 153 | 154 | 155 | @Contract("_,!null->!null") 156 | protected static ItemStack readItem(@Nullable ConfigurationSection section, 157 | @Nullable ItemStack defaultValue) throws Exception { 158 | if (section == null) return defaultValue; 159 | else return XItemStack.deserialize(section); 160 | } 161 | 162 | protected static List readActions(@NotNull List strings) { 163 | return strings.stream().map(GUIActionConfiguration::deserialize).filter(Objects::nonNull).collect(Collectors.toList()); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/manager/ServiceManager.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.manager; 2 | 3 | import net.luckperms.api.LuckPerms; 4 | import net.luckperms.api.LuckPermsProvider; 5 | import net.luckperms.api.model.user.User; 6 | import net.luckperms.api.platform.PlayerAdapter; 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.plugin.RegisteredServiceProvider; 10 | 11 | /** 12 | * 服务管理器,旨在于LuckPerms互联,调用其原始接口。 13 | */ 14 | public class ServiceManager { 15 | 16 | public static User getUser(Player player) { 17 | return getAPI().getUser(player); 18 | } 19 | 20 | public static LuckPerms getService() { 21 | RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class); 22 | if (provider != null) { 23 | return provider.getProvider(); 24 | } else { 25 | return LuckPermsProvider.get(); 26 | } 27 | } 28 | 29 | public static PlayerAdapter getAPI() { 30 | return getService().getPlayerAdapter(Player.class); 31 | } 32 | 33 | 34 | /** 35 | * 通过LuckPermsAPI判断玩家是否有对应的权限 36 | * 37 | * @param user 用户 38 | * @param permission 权限 39 | * @return true / false 40 | */ 41 | public static boolean hasPermission(User user, String permission) { 42 | return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean(); 43 | } 44 | 45 | public static boolean hasPermission(Player player, String permission) { 46 | return hasPermission(getUser(player), permission); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/manager/UserManager.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.manager; 2 | 3 | import cc.carm.lib.easyplugin.gui.GUI; 4 | import cc.carm.plugin.userprefix.Main; 5 | import cc.carm.plugin.userprefix.UserPrefixAPI; 6 | import cc.carm.plugin.userprefix.conf.PluginConfig; 7 | import cc.carm.plugin.userprefix.conf.PluginMessages; 8 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 9 | import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent; 10 | import cc.carm.plugin.userprefix.event.UserPrefixExpireEvent; 11 | import cc.carm.plugin.userprefix.hooker.UserNameTag; 12 | import cc.carm.plugin.userprefix.ui.PrefixSelectGUI; 13 | import net.luckperms.api.model.user.User; 14 | import net.luckperms.api.node.NodeType; 15 | import net.luckperms.api.node.types.MetaNode; 16 | import org.bukkit.Bukkit; 17 | import org.bukkit.entity.Player; 18 | import org.jetbrains.annotations.NotNull; 19 | import org.jetbrains.annotations.Nullable; 20 | 21 | import java.util.*; 22 | import java.util.stream.Collectors; 23 | 24 | public class UserManager { 25 | 26 | // LuckPerms竟然会把所有的metaKey全部转换为小写... 那我这里就直接写成小写吧~ 27 | public static final @NotNull String META_KEY = "userprefix"; 28 | 29 | protected final HashMap nameTags = new HashMap<>(); 30 | 31 | protected final HashSet checkingPlayers = new HashSet<>(); 32 | 33 | @Nullable 34 | public UserNameTag getNameTag(Player player) { 35 | if (this.isNamePrefixEnabled()) { 36 | if (nameTags.containsKey(player.getUniqueId())) { 37 | return nameTags.get(player.getUniqueId()); 38 | } else { 39 | return createNameTag(player); 40 | } 41 | } else { 42 | return null; 43 | } 44 | } 45 | 46 | @NotNull 47 | public UserNameTag createNameTag(Player player) { 48 | if (nameTags.containsKey(player.getUniqueId())) return nameTags.get(player.getUniqueId()); 49 | UserNameTag nameTag = new UserNameTag(player); 50 | nameTags.put(player.getUniqueId(), nameTag); 51 | return nameTag; 52 | } 53 | 54 | public void initPlayer(Player player) { 55 | checkPrefix(player, false); 56 | if (this.isNamePrefixEnabled()) { 57 | createNameTag(player); 58 | updatePrefixView(player, true); 59 | } 60 | } 61 | 62 | public void unloadPlayer(Player player) { 63 | PrefixSelectGUI.removeOpening(player); 64 | unloadNameTag(player.getUniqueId()); 65 | checkingPlayers.remove(player.getUniqueId()); 66 | GUI.removeOpenedGUI(player); // 清空打开过的GUI缓存 (用于记录物品点击的 67 | } 68 | 69 | /** 70 | * 更新前缀显示效果 71 | * 72 | * @param player 玩家 73 | * @param loadOthers 是否为玩家更新其他人的前缀(一般用于加入游戏) 74 | */ 75 | public void updatePrefixView(Player player, boolean loadOthers) { 76 | if (!this.isNamePrefixEnabled()) return; //未启用的情况下,不需要进行任何操作。 77 | UserNameTag tag = getNameTag(player); 78 | if (tag == null) return; //未启用的情况下,不需要进行任何操作。 79 | 80 | PrefixConfig playerPrefix = getPrefix(player); 81 | boolean descOrder = PluginConfig.FUNCTIONS.NAME_PREFIX.ORDER_DESC.getNotNull(); 82 | 83 | tag.setPrefix(playerPrefix.getContent(player)); 84 | tag.setOrder(descOrder ? 999 - playerPrefix.getWeight() : playerPrefix.getWeight()); 85 | 86 | Main.debugging("为玩家 " + player.getName() + " 设置了 " + player.getName() + "的前缀为 #" + playerPrefix.getWeight() + " " + playerPrefix.getName()); 87 | 88 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 89 | if (onlinePlayer.equals(player)) continue; 90 | UserNameTag onlinePlayerTag = getNameTag(onlinePlayer); 91 | 92 | if (onlinePlayerTag != null) { 93 | onlinePlayerTag.setPrefix(player, playerPrefix.getContent(onlinePlayer)); 94 | onlinePlayerTag.setOrder(player, descOrder ? 999 - playerPrefix.getWeight() : playerPrefix.getWeight()); 95 | Main.debugging("为玩家 " + onlinePlayer.getName() + " 设置了 " + player.getName() + "的前缀为 #" + playerPrefix.getWeight() + " " + playerPrefix.getName()); 96 | 97 | } 98 | 99 | if (loadOthers) { 100 | PrefixConfig onlinePlayerPrefix = getPrefix(onlinePlayer); 101 | tag.setPrefix(onlinePlayer, onlinePlayerPrefix.getContent(player)); 102 | tag.setOrder(onlinePlayer, descOrder ? 999 - onlinePlayerPrefix.getWeight() : onlinePlayerPrefix.getWeight()); 103 | Main.debugging("为玩家 " + player.getName() + " 设置了 " + onlinePlayer.getName() + "的前缀为 #" + onlinePlayerPrefix.getWeight() + " " + onlinePlayerPrefix.getName()); 104 | } 105 | } 106 | } 107 | 108 | /** 109 | * 检查玩家的前缀的使用权 110 | * 111 | * @param player 玩家 112 | * @param updateView 是否更新头顶与TabList中的前缀 113 | */ 114 | public void checkPrefix(Player player, boolean updateView) { 115 | if (checkingPlayers.contains(player.getUniqueId())) { 116 | /* 117 | * 这里为了避免极短时间内的重复触发导致多次判断且结果相同误导玩家, 118 | * 故没有采用同步锁,而是采用添加到一个临时Set中,对Set中玩家跳过判断。 119 | */ 120 | return; 121 | } 122 | checkingPlayers.add(player.getUniqueId()); 123 | String currentPrefixData = getPrefixData(player); 124 | 125 | if (!isPrefixUsable(player, currentPrefixData)) { 126 | PrefixConfig currentPrefix = UserPrefixAPI.getPrefixManager().getPrefix(currentPrefixData); 127 | PrefixConfig newPrefix = getHighestPrefix(player); 128 | 129 | if (currentPrefix != null) { 130 | //当前前缀不为空,则代表属于前缀过期的情况 131 | UserPrefixExpireEvent.call(player, currentPrefix); 132 | 133 | // 发送消息 134 | PluginMessages.EXPIRED.sendTo(player, currentPrefix.getName(), newPrefix.getName()); 135 | 136 | // 播放声音 137 | PluginConfig.SOUNDS.PREFIX_EXPIRED.playTo(player); 138 | } else { 139 | // 当前前缀为空,则代表是旧的前缀不存在了, 140 | PluginMessages.REMOVED.sendTo(player, newPrefix.getName()); 141 | } 142 | 143 | UserPrefixChangeEvent.call(player, currentPrefix, newPrefix, (after) -> { 144 | if (after != null) setPrefix(player, after, updateView); 145 | checkingPlayers.remove(player.getUniqueId()); 146 | }); 147 | 148 | } else { 149 | checkingPlayers.remove(player.getUniqueId()); 150 | } 151 | } 152 | 153 | public void unloadNameTag(UUID uuid) { 154 | nameTags.remove(uuid); 155 | } 156 | 157 | /** 158 | * 得到玩家的前缀。 159 | * 该方法会自动判断玩家当前的前缀是否可用,并返回最终可用的前缀。 160 | * 161 | * @param player 玩家 162 | * @return 前缀配置 163 | */ 164 | @NotNull 165 | public PrefixConfig getPrefix(Player player) { 166 | String identifier = getPrefixData(player); 167 | if (identifier == null || !isPrefixUsable(player, identifier)) { 168 | return getHighestPrefix(player); 169 | } else { 170 | PrefixConfig prefix = UserPrefixAPI.getPrefixManager().getPrefix(identifier); 171 | return prefix == null ? UserPrefixAPI.getDefaultPrefix() : prefix; 172 | } 173 | } 174 | 175 | /** 176 | * 设定玩家前缀 177 | * 178 | * @param player 玩家 179 | * @param prefix 前缀配置 180 | * @param updateView 是否更新头顶上、TabList的前缀 181 | */ 182 | public void setPrefix(Player player, PrefixConfig prefix, boolean updateView) { 183 | setPrefixData(player, prefix.getIdentifier()); 184 | prefix.executeActions(player); 185 | if (updateView) updatePrefixView(player, false); 186 | } 187 | 188 | /** 189 | * 得到玩家所有可用的前缀 190 | * 191 | * @param player 玩家 192 | * @return 可用前缀列表 193 | */ 194 | @NotNull 195 | public List getUsablePrefixes(Player player) { 196 | return UserPrefixAPI.getPrefixManager().getPrefixes().values().stream() 197 | .filter(prefix -> prefix.checkPermission(player)) //过滤出玩家可用的前缀 198 | .sorted(Comparator.comparingInt(PrefixConfig::getWeight)) // 以前缀排序 199 | .collect(Collectors.toList()); // 返回集合 200 | } 201 | 202 | 203 | /** 204 | * 得到玩家可使用的最高权重的权限 205 | * 注意:若配置文件中关闭了 “autoUsePrefix” ,则会返回默认前缀。 206 | * 207 | * @param player 玩家 208 | * @return 权限内容 209 | */ 210 | @NotNull 211 | public PrefixConfig getHighestPrefix(Player player) { 212 | if (!PluginConfig.FUNCTIONS.AUTO_USE.getNotNull()) { 213 | // 关闭了自动选择,就直接给默认的前缀,让玩家自己去设置吧~ 214 | return UserPrefixAPI.getDefaultPrefix(); 215 | } 216 | return getUsablePrefixes(player).stream() 217 | .max(Comparator.comparingInt(PrefixConfig::getWeight)) // 取权重最大 218 | .orElseGet(UserPrefixAPI::getDefaultPrefix); // 啥都没有? 返回默认前缀。 219 | } 220 | 221 | /** 222 | * 判断一个前缀对某玩家是否可用 223 | * 224 | * @param player 玩家 225 | * @param prefixIdentifier 前缀标识 226 | * @return 若前缀标识不存在,则返回false;若前缀为默认前缀,或该前缀无权限,或玩家有该前缀的权限,则返回true。 227 | */ 228 | @SuppressWarnings("BooleanMethodIsAlwaysInverted") 229 | public boolean isPrefixUsable(Player player, String prefixIdentifier) { 230 | if (prefixIdentifier == null || prefixIdentifier.equalsIgnoreCase("default")) return true; 231 | PrefixConfig prefix = UserPrefixAPI.getPrefixManager().getPrefix(prefixIdentifier); 232 | return prefix != null && prefix.checkPermission(player); 233 | } 234 | 235 | 236 | /** 237 | * 得到用户当前正在使用的前缀Identifier。 238 | * 该方法通过LuckPerms的MetaData实现,因此可以通过指令去操作。 239 | * 240 | * @param player 玩家 241 | * @return 正在使用的前缀Identifier(若不存在则返回null, 代表未设置前缀) 242 | */ 243 | @Nullable 244 | public String getPrefixData(Player player) { 245 | return ServiceManager.getAPI().getMetaData(player) 246 | .getMetaValue(META_KEY, String::valueOf) 247 | .orElse(null); 248 | } 249 | 250 | /** 251 | * 设定用户所使用的的prefix。 252 | * 该方法通过LuckPerms的MetaData实现,因此可以通过指令去操作。 253 | * 254 | * @param player 玩家 255 | * @param prefixIdentifier 前缀的标识 256 | */ 257 | public void setPrefixData(Player player, String prefixIdentifier) { 258 | User user = ServiceManager.getUser(player); 259 | clearPrefixData(player); // 清除掉旧的数据,LuckPerms不会去覆盖一个Meta,需要手动清除。 260 | if (prefixIdentifier != null) { 261 | user.data().add(MetaNode.builder(META_KEY, prefixIdentifier).build()); 262 | ServiceManager.getService().getUserManager().saveUser(user); // 保存数据 263 | } 264 | } 265 | 266 | /** 267 | * 清除玩家所选择的前缀数据 268 | * 269 | * @param player 玩家 270 | */ 271 | public void clearPrefixData(Player player) { 272 | User user = ServiceManager.getUser(player); 273 | user.data().clear(NodeType.META.predicate(mn -> mn.getMetaKey().equals(META_KEY))); 274 | } 275 | 276 | private boolean isNamePrefixEnabled() { 277 | return PluginConfig.FUNCTIONS.NAME_PREFIX.ENABLE.getNotNull() && !Main.getInstance().isOnFolia(); 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /src/main/java/cc/carm/plugin/userprefix/ui/PrefixSelectGUI.java: -------------------------------------------------------------------------------- 1 | package cc.carm.plugin.userprefix.ui; 2 | 3 | import cc.carm.lib.easyplugin.gui.GUIItem; 4 | import cc.carm.lib.easyplugin.gui.GUIType; 5 | import cc.carm.lib.easyplugin.gui.paged.AutoPagedGUI; 6 | import cc.carm.plugin.userprefix.UserPrefixAPI; 7 | import cc.carm.plugin.userprefix.conf.PluginConfig; 8 | import cc.carm.plugin.userprefix.conf.PluginMessages; 9 | import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig; 10 | import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent; 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.inventory.ClickType; 13 | 14 | import java.util.ArrayList; 15 | import java.util.HashSet; 16 | import java.util.List; 17 | import java.util.Optional; 18 | 19 | public class PrefixSelectGUI extends AutoPagedGUI { 20 | 21 | public static HashSet openingUsers = new HashSet<>(); 22 | 23 | Player player; 24 | 25 | public PrefixSelectGUI(Player player) { 26 | super(GUIType.SIX_BY_NINE, PluginConfig.GUI.TITLE.get(), 10, 43); 27 | this.player = player; 28 | 29 | setPreviousPageSlot(18); 30 | setNextPageSlot(26); 31 | 32 | loadExtraIcons(); 33 | loadItems(); 34 | } 35 | 36 | public Player getPlayer() { 37 | return player; 38 | } 39 | 40 | public void loadExtraIcons() { 41 | PluginConfig.GUI.ITEMS.getNotNull().getItems().values().forEach(v -> v.setupItems(player, this)); 42 | } 43 | 44 | public void loadItems() { 45 | List prefixList = new ArrayList<>(); 46 | prefixList.add(UserPrefixAPI.getPrefixManager().getDefaultPrefix()); 47 | prefixList.addAll(UserPrefixAPI.getPrefixManager().getVisiblePrefix(player)); //只需要读取看得见的 48 | 49 | PrefixConfig usingPrefix = UserPrefixAPI.getUserManager().getPrefix(getPlayer()); 50 | 51 | for (PrefixConfig prefix : prefixList) { 52 | if (prefix.getIdentifier().equals(usingPrefix.getIdentifier())) { 53 | addItem(new GUIItem(Optional 54 | .ofNullable(prefix.getItemWhenUsing(player)) 55 | .orElse(prefix.getItemHasPermission(player)) 56 | )); 57 | } else if (prefix.checkPermission(player)) { 58 | addItem(new GUIItem(prefix.getItemHasPermission(player)) { 59 | 60 | @Override 61 | public void onClick(Player clicker, ClickType type) { 62 | player.closeInventory(); 63 | //再次检查,防止打开GUI后、选择前的时间段内权限消失 64 | if (prefix.checkPermission(player)) { 65 | 66 | // 发送消息与提示 67 | PluginConfig.SOUNDS.PREFIX_CHANGE.playTo(player); 68 | PluginMessages.SELECTED.sendTo(player, prefix.getName()); 69 | 70 | UserPrefixChangeEvent.call(player, usingPrefix, prefix, config -> { 71 | if (config == null) return; 72 | UserPrefixAPI.getUserManager().setPrefix(player, config, true); 73 | }); 74 | 75 | } else { 76 | PluginConfig.SOUNDS.GUI_CLICK.playTo(player); 77 | } 78 | } 79 | }); 80 | } else { 81 | addItem(new GUIItem(prefix.getItemNoPermission(player)) { 82 | @Override 83 | public void onClick(Player clicker, ClickType type) { 84 | PluginConfig.SOUNDS.GUI_CLICK.playTo(player); 85 | } 86 | }); 87 | } 88 | } 89 | 90 | 91 | } 92 | 93 | @Override 94 | public void onClose() { 95 | removeOpening(player); 96 | } 97 | 98 | public static void removeOpening(Player player) { 99 | openingUsers.remove(player); 100 | } 101 | 102 | public static void closeAll() { 103 | for (Player player : new HashSet<>(openingUsers)) { 104 | player.closeInventory(); 105 | } 106 | openingUsers.clear(); 107 | } 108 | 109 | public static void open(Player player) { 110 | // player.closeInventory(); // 防止冲突 111 | PluginConfig.SOUNDS.GUI_OPEN.playTo(player); 112 | new PrefixSelectGUI(player).openGUI(player); 113 | openingUsers.add(player); 114 | } 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/resources/PLUGIN_INFO: -------------------------------------------------------------------------------- 1 | &f __ __ &3___ ____ 2 | &f / / / /__ ___ ____&3/ _ \_______ / _(_)_ __ 3 | &f/ /_/ (_-