├── .github
└── workflows
│ └── maven.yml
├── .gitignore
├── LICENSE
├── README.md
├── lib
└── achievements_v1.0-SNAPSHOT.jar
├── pom.xml
└── src
└── main
├── java
└── tip
│ ├── Main.java
│ ├── bossbar
│ └── BossBarApi.java
│ ├── commands
│ ├── TipsCommand.java
│ ├── base
│ │ ├── BaseCommand.java
│ │ └── BaseSubCommand.java
│ └── sub
│ │ ├── AchAllSubCommand.java
│ │ ├── DefaultSubCommand.java
│ │ ├── ReloadSubCommand.java
│ │ ├── SendSubCommand.java
│ │ └── ThemeSubCommand.java
│ ├── lib
│ └── viewcompass
│ │ └── ViewCompassVariable.java
│ ├── messages
│ ├── BaseMessage.java
│ ├── BossBarMessage.java
│ ├── BroadcastMessage.java
│ ├── ChatMessage.java
│ ├── NameTagMessage.java
│ ├── ScoreBoardMessage.java
│ ├── TipMessage.java
│ └── defaults
│ │ ├── BossBarMessage.java
│ │ ├── BroadcastMessage.java
│ │ ├── ChatMessage.java
│ │ ├── MessageManager.java
│ │ ├── NameTagMessage.java
│ │ ├── ScoreBoardMessage.java
│ │ └── TipMessage.java
│ ├── tasks
│ ├── AbstractPlayerAsyncTask.java
│ ├── AddPlayerTask.java
│ ├── BaseTipsRunnable.java
│ ├── BossBarAllPlayerTask.java
│ ├── BossBarTask.java
│ ├── BroadCastPlayerTask.java
│ ├── BroadCastTask.java
│ ├── MotdTask.java
│ ├── NameTagTask.java
│ ├── ScoreBoardTask.java
│ └── TipTask.java
│ ├── utils
│ ├── Api.java
│ ├── BossMessageBuilder.java
│ ├── GameCoreDownload.java
│ ├── OnListener.java
│ ├── PlayerConfig.java
│ ├── SendPlayerClass.java
│ ├── ThemeManager.java
│ └── variables
│ │ ├── ASMTemplateCompiler.java
│ │ ├── BaseVariable.java
│ │ ├── VariableManager.java
│ │ └── defaults
│ │ └── DefaultVariables.java
│ └── windows
│ ├── CreateWindow.java
│ └── ListenerWindow.java
└── resources
├── Tips变量.txt
├── config.yml
├── levelMessage.yml
├── plugin.yml
└── theme
├── default.yml
└── easy.yml
/.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://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3 |
4 | # This workflow uses actions that are not certified by GitHub.
5 | # They are provided by a third-party and are governed by
6 | # separate terms of service, privacy policy, and support
7 | # documentation.
8 |
9 | name: Java CI with Maven
10 |
11 | on:
12 | push:
13 | branches: [ "master" ]
14 | pull_request:
15 | branches: [ "master" ]
16 |
17 | jobs:
18 | build:
19 |
20 | runs-on: ubuntu-latest
21 |
22 | steps:
23 | - uses: actions/checkout@v4
24 | - name: Set up JDK 8
25 | uses: actions/setup-java@v4
26 | with:
27 | java-version: 8
28 | distribution: 'temurin'
29 | - name: Cache Maven packages
30 | uses: actions/cache@v4
31 | with:
32 | path: ~/.m2
33 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
34 | restore-keys: ${{ runner.os }}-m2
35 | - name: Build projects
36 | run: mvn -B package --file pom.xml
37 | - run: mkdir staging && cp target/*.jar staging
38 | - uses: actions/upload-artifact@v4
39 | with:
40 | name: Tips
41 | path: staging
42 | # 生成信息
43 | - name: Get Short SHA
44 | id: vars
45 | run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
46 | - name: Format ChangeLog
47 | id: get-changelog
48 | if: success() && github.event_name == 'push' && github.repository == 'MemoriesOfTime/Tips' && contains(github.ref_name, 'master')
49 | run: echo "changelog=${{ github.event.commits[0].message }}" >> $GITHUB_OUTPUT
50 | - name: Get Time
51 | id: time
52 | uses: nanzm/get-time-action@v1.1
53 | if: github.repository == 'MemoriesOfTime/Tips' && contains(github.ref_name, 'master')
54 | with:
55 | timeZone: 8
56 | format: 'YYYY/MM/DD-HH:mm:ss'
57 | # 推送到minebbs
58 | - name: Update MineBBS infomation
59 | uses: fjogeleit/http-request-action@v1
60 | if: success() && github.event_name == 'push' && github.repository == 'MemoriesOfTime/Tips' && contains(github.ref_name, 'master')
61 | with:
62 | url: 'https://api.minebbs.com/api/openapi/v1/resources/796/update'
63 | method: 'POST'
64 | customHeaders: '{"Authorization": "Bearer ${{ secrets.MINEBBS_API_KEY }}"}'
65 | contentType: 'application/json'
66 | data: '{"title": "${{ github.ref_name }}-${{ steps.vars.outputs.sha_short }}", "description": "${{ steps.get-changelog.outputs.changelog }}", "new_version": "${{ steps.time.outputs.time }}", "file_url": "https://motci.cn/job/Tips/"}'
67 | escapeData: 'true'
68 | preventFailureOnNoResponse: 'true'
69 | ignoreStatusCodes: '400,404,401,403,500,502,503,504'
70 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.idea/
3 | .DS_Store
4 | */.DS_Store
5 | *.py
6 | *.iml
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright © 2007 Free Software Foundation, Inc.
5 |
6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 | The GNU General Public License is a free, copyleft license for software and other kinds of works.
10 |
11 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
12 |
13 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
14 |
15 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
16 |
17 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
18 |
19 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
20 |
21 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
22 |
23 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
24 |
25 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
26 |
27 | The precise terms and conditions for copying, distribution and modification follow.
28 |
29 | TERMS AND CONDITIONS
30 | 0. Definitions.
31 | “This License” refers to version 3 of the GNU General Public License.
32 |
33 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
34 |
35 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
36 |
37 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
38 |
39 | A “covered work” means either the unmodified Program or a work based on the Program.
40 |
41 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
42 |
43 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
44 |
45 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
46 |
47 | 1. Source Code.
48 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
49 |
50 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
51 |
52 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
53 |
54 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
55 |
56 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
57 |
58 | The Corresponding Source for a work in source code form is that same work.
59 |
60 | 2. Basic Permissions.
61 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
62 |
63 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
64 |
65 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
66 |
67 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
68 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
69 |
70 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
71 |
72 | 4. Conveying Verbatim Copies.
73 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
74 |
75 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
76 |
77 | 5. Conveying Modified Source Versions.
78 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
79 |
80 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
81 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
82 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
83 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
84 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
85 |
86 | 6. Conveying Non-Source Forms.
87 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
88 |
89 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
90 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
91 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
92 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
93 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
94 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
95 |
96 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
97 |
98 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
99 |
100 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
101 |
102 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
103 |
104 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
105 |
106 | 7. Additional Terms.
107 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
108 |
109 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
110 |
111 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
112 |
113 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
114 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
115 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
116 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
117 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
118 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
119 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
120 |
121 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
122 |
123 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
124 |
125 | 8. Termination.
126 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
127 |
128 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
129 |
130 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
131 |
132 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
133 |
134 | 9. Acceptance Not Required for Having Copies.
135 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
136 |
137 | 10. Automatic Licensing of Downstream Recipients.
138 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
139 |
140 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
141 |
142 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
143 |
144 | 11. Patents.
145 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
146 |
147 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
148 |
149 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
150 |
151 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
152 |
153 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
154 |
155 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
156 |
157 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
158 |
159 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
160 |
161 | 12. No Surrender of Others' Freedom.
162 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
163 |
164 | 13. Use with the GNU Affero General Public License.
165 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
166 |
167 | 14. Revised Versions of this License.
168 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
169 |
170 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
171 |
172 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
173 |
174 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
175 |
176 | 15. Disclaimer of Warranty.
177 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
178 |
179 | 16. Limitation of Liability.
180 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
181 |
182 | 17. Interpretation of Sections 15 and 16.
183 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
184 |
185 | END OF TERMS AND CONDITIONS
186 |
187 | How to Apply These Terms to Your New Programs
188 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
189 |
190 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
191 |
192 |
193 | Copyright (C)
194 |
195 | This program is free software: you can redistribute it and/or modify
196 | it under the terms of the GNU General Public License as published by
197 | the Free Software Foundation, either version 3 of the License, or
198 | (at your option) any later version.
199 |
200 | This program is distributed in the hope that it will be useful,
201 | but WITHOUT ANY WARRANTY; without even the implied warranty of
202 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203 | GNU General Public License for more details.
204 |
205 | You should have received a copy of the GNU General Public License
206 | along with this program. If not, see .
207 | Also add information on how to contact you by electronic and paper mail.
208 |
209 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
210 |
211 | Copyright (C)
212 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
213 | This is free software, and you are welcome to redistribute it
214 | under certain conditions; type `show c' for details.
215 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
216 |
217 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see .
218 |
219 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # **Tips**
6 | 一款多功能显示插件
7 |
8 | #### 使用说明
9 | - 用户:
10 | 1. 将本插件安装到` plugins`文件夹
11 | 2. 安装前置插件 参考 **`Tips变量.txt`** 文件
12 | 3. 修改` config.yml` 配置
13 |
14 | > (小贴士) config内的 default 为全地图通用显示
15 | 若想实现每个 地图 不同的内容 只需要复制粘贴
16 | delfault 内容即可 然后将 default 替换成
17 | 那个地图的名称
18 |
19 | 开发者
20 | > 注册变量
21 | >> 创建一个类继承 `BaseVariable `
22 | 调用`BaseVariable `类里的` addStrReplaceString`方法
23 | 传入 key(变量名称) value(显示内容)
24 | 然后在 插件的 onEnable 里增加
25 | ```java
26 | Api.registerVariables("插件名", extends BaseVariable>class);
27 | ```
28 | >添加单一变量
29 | ```java
30 | Api.addVariable("变量字符","值");
31 | ```
32 |
33 | 修改内容
34 | > 调用Api类内的方法 修改
35 |
36 |
37 |
--------------------------------------------------------------------------------
/lib/achievements_v1.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MemoriesOfTime/Tips/d17f2b42262ac025ac9c2cdfb4d4bb4fbaa3a169/lib/achievements_v1.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.smallaswater.tips
8 | Tips
9 | 2.2.2
10 |
11 |
12 |
13 | UTF-8
14 | UTF-8
15 | 1.8
16 | 1.8
17 | UTF-8
18 | 1.6.9
19 |
20 |
21 |
22 |
23 | repo-lanink-cn
24 | https://repo.lanink.cn/repository/maven-snapshots/
25 |
26 |
27 | repo-lanink-cn
28 | https://repo.lanink.cn/repository/maven-releases/
29 |
30 |
31 |
32 |
33 |
34 | repo-lanink-cn
35 | https://repo.lanink.cn/repository/maven-public/
36 |
37 |
38 | opencollab-repo-release
39 | https://repo.opencollab.dev/maven-releases/
40 |
41 | true
42 |
43 |
44 | false
45 |
46 |
47 |
48 | opencollab-repo-snapshot
49 | https://repo.opencollab.dev/maven-snapshots/
50 |
51 | false
52 |
53 |
54 | true
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.jetbrains
62 | annotations
63 | 24.1.0
64 | provided
65 |
66 |
67 |
68 | cn.nukkit
69 | nukkit
70 | 1.0-SNAPSHOT
71 | provided
72 |
73 |
74 |
75 | org.ow2.asm
76 | asm
77 | 9.7
78 | compile
79 |
80 |
81 |
82 | cn.lanink
83 | MemoriesOfTime-GameCore
84 | ${lib.GameCore.version}
85 | provided
86 |
87 |
88 |
89 | com.smallaswater.ServerInfo
90 | ServerInfo
91 | 1.0.10
92 | provided
93 |
94 |
95 |
96 | me.onebone
97 | economyapi
98 | 2.0.2
99 | provided
100 |
101 |
102 |
103 | com.smallaswater.autoupdata
104 | AutoUpData
105 | 1.3.0
106 | provided
107 |
108 |
109 |
110 | smallaswater.achievement
111 | achievements
112 | 1.0-SNAPSHOT
113 | system
114 | ${project.basedir}/lib/achievements_v1.0-SNAPSHOT.jar
115 |
116 |
117 |
118 |
119 |
120 |
121 | org.apache.maven.plugins
122 | maven-compiler-plugin
123 | 3.8.1
124 |
125 | ${maven.compiler.source}
126 | ${maven.compiler.target}
127 | ${maven.compiler.encoding}
128 |
129 |
130 |
131 | com.google.code.maven-replacer-plugin
132 | replacer
133 | 1.5.3
134 |
135 |
136 | add-version
137 | process-sources
138 |
139 | replace
140 |
141 |
142 |
143 | ${project.basedir}/src/main/resources/plugin.yml
144 | ${project.basedir}/src/main/java/tip/utils/GameCoreDownload.java
145 |
146 |
147 |
148 | version: ".*"
149 | version: "${project.version}"
150 |
151 |
152 | MINIMUM_GAME_CORE_VERSION = ".*"
153 | MINIMUM_GAME_CORE_VERSION = "${lib.GameCore.version}"
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 | org.apache.maven.plugins
162 | maven-shade-plugin
163 | 3.2.4
164 |
165 |
166 | package
167 |
168 | shade
169 |
170 |
171 | false
172 |
173 |
174 | org.ow2.asm:asm
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/src/main/java/tip/Main.java:
--------------------------------------------------------------------------------
1 | package tip;
2 |
3 |
4 | import cn.nukkit.Player;
5 | import cn.nukkit.Server;
6 | import cn.nukkit.plugin.PluginBase;
7 | import cn.nukkit.utils.BossBarColor;
8 | import cn.nukkit.utils.Config;
9 | import com.google.common.cache.Cache;
10 | import com.google.common.cache.CacheBuilder;
11 | import com.google.common.util.concurrent.ThreadFactoryBuilder;
12 | import tip.bossbar.BossBarApi;
13 | import tip.commands.TipsCommand;
14 | import tip.lib.viewcompass.ViewCompassVariable;
15 | import tip.messages.BaseMessage;
16 | import tip.messages.defaults.*;
17 | import tip.tasks.AddPlayerTask;
18 | import tip.tasks.BossBarTask;
19 | import tip.tasks.MotdTask;
20 | import tip.tasks.TipTask;
21 | import tip.utils.*;
22 | import tip.utils.variables.VariableManager;
23 | import tip.utils.variables.defaults.DefaultVariables;
24 | import tip.windows.ListenerWindow;
25 | import updata.AutoData;
26 |
27 | import java.io.File;
28 | import java.util.*;
29 | import java.util.concurrent.ExecutorService;
30 | import java.util.concurrent.Executors;
31 | import java.util.concurrent.TimeUnit;
32 |
33 | /**
34 | * @author 若水
35 |
36 | */
37 | public class Main extends PluginBase {
38 |
39 |
40 | private static Main instance;
41 |
42 | private String theme;
43 |
44 | private boolean scoreboard = false;
45 |
46 | private String motd;
47 |
48 |
49 | private VariableManager varManager;
50 | public Set scoreboards = new HashSet<>();
51 |
52 | public Cache tasks = CacheBuilder.newBuilder()
53 | .expireAfterAccess(60, TimeUnit.MINUTES)
54 | .build();
55 |
56 | public final LinkedHashMap apis = new LinkedHashMap<>();
57 |
58 | private MessageManager showMessages = new MessageManager();
59 |
60 | private final ThemeManager themeManager = new ThemeManager();
61 |
62 | private LinkedList playerConfigs = new LinkedList<>();
63 |
64 | public static ExecutorService executor = null;
65 |
66 |
67 | @Override
68 | public void onLoad() {
69 | instance = this;
70 | Api.registerVariables("default", DefaultVariables.class);
71 | Api.registerVariables("ViewCompass", ViewCompassVariable.class);
72 | }
73 |
74 | @Override
75 | public void onEnable() {
76 | if (executor != null) {
77 | executor.shutdown();
78 | }
79 | executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Tips-Thread-%d").build());
80 |
81 | try {
82 | if (Server.getInstance().getPluginManager().getPlugin("AutoUpData") != null) {
83 | if (AutoData.defaultUpDataByMaven(this, this.getFile(), "com.smallaswater.tips", "Tips", null)) {
84 | return;
85 | }
86 | }
87 | } catch (Throwable e) {
88 | this.getLogger().warning("插件自动更新失败!请检查AutoUpData前置插件!");
89 | }
90 | init();
91 |
92 | motd = getConfig().getString("自定义MOTD.内容","&l{color}在线 -{online}/{maxplayer}\n {version}");
93 | if(getConfig().getBoolean("自定义MOTD.是否启用",false)){
94 | executor.execute(new MotdTask(this));
95 | }
96 | this.getServer().getCommandMap().register("tips", new TipsCommand(getConfig().getString("自定义指令.name","tips")));
97 | this.getServer().getPluginManager().registerEvents(new OnListener(),this);
98 | this.getServer().getPluginManager().registerEvents(new ListenerWindow(),this);
99 |
100 | if (GameCoreDownload.checkAndDownload() == 1) {
101 | this.getLogger().error("MemoriesOfTime-GameCore依赖 下载失败,无法使用计分板功能!");
102 | } else {
103 | Main.getInstance().getLogger().info("检测到 MemoriesOfTime-GameCore 成功开启计分板功能");
104 | scoreboard = true;
105 | }
106 | AddPlayerTask.add(new TipTask(Main.getInstance(),Main.getInstance().getConfig().getInt("自定义刷新刻度.底部",20)));
107 |
108 | this.getLogger().info("插件加载完成~");
109 | }
110 |
111 | public String getMotd() {
112 | return motd;
113 | }
114 |
115 | public boolean isScoreboard() {
116 | return scoreboard;
117 | }
118 |
119 | public String getTheme() {
120 | return theme;
121 | }
122 |
123 | public ThemeManager getThemeManager() {
124 | return themeManager;
125 | }
126 |
127 | private Config getLevelMessage() {
128 | return themeManager.getConfig(theme);
129 | }
130 |
131 | public void init(){
132 | this.saveDefaultConfig();
133 | this.reloadConfig();
134 | showMessages = new MessageManager();
135 |
136 | this.saveResource("Tips变量.txt","/Tips变量.txt",true); //每次加载时写入,保证是最新的
137 |
138 | if(!new File(this.getDataFolder()+"/theme").exists()){
139 | if(!new File(this.getDataFolder()+"/theme").mkdirs()){
140 | getLogger().error("创建 theme 文件夹失败");
141 | }
142 | if(!new File(this.getDataFolder()+"/theme/easy.yml").exists()){
143 | this.saveResource("theme/easy.yml","/theme/easy.yml",false);
144 | }
145 | }
146 |
147 | if(!new File(this.getDataFolder()+"/theme/default.yml").exists()){
148 | this.saveResource("theme/default.yml","/theme/default.yml",false);
149 | }
150 |
151 | if(!new File(this.getDataFolder()+"/Players").exists()){
152 | if(!new File(this.getDataFolder()+"/Players").mkdirs()){
153 | this.getLogger().error("玩家文件夹创建失败");
154 | }
155 | }
156 | //加载风格
157 | loadTheme();
158 | theme = getConfig().getString("默认样式","default");
159 | getLogger().info("当前样式已设置为: "+theme);
160 |
161 | showMessages.addAll(getManagerByConfig(getLevelMessage()));
162 | //开始加载Message
163 | playerConfigs = new LinkedList<>();
164 | }
165 |
166 | public void loadPlayerConfig(Player player){
167 | if(new File(Main.getInstance().getDataFolder()+"/Players/"+player.getName()+".yml").exists()){
168 | Config config = new Config(Main.getInstance().getDataFolder()+"/Players/"+player.getName()+".yml",2);
169 | PlayerConfig playerConfig = new PlayerConfig(player.getName(),Main.getInstance().getManagerByConfig(config),config.getString("样式",null));
170 | Main.getInstance().getPlayerConfigs().add(playerConfig);
171 |
172 | }
173 | }
174 |
175 | private MessageManager getManagerByConfig(Config config){
176 | MessageManager messages = new MessageManager();
177 | if(config == null){
178 | return messages;
179 | }
180 | for(BaseMessage.BaseTypes types: BaseMessage.BaseTypes.values()){
181 | if(config.exists(types.getConfigName())) {
182 | LinkedList messages1 = addShowMessageByMap((Map, ?>) config.get(types.getConfigName()), types.getType());
183 | if (messages1.size() > 0) {
184 | messages.addAll(messages1);
185 | }
186 | }
187 | }
188 | return messages;
189 | }
190 |
191 | private void loadTheme(){
192 | String[] strings = getFileNames("theme");
193 | if(strings.length > 0){
194 | for(String file:strings){
195 | Config config = new Config(this.getDataFolder()+"/theme/"+file+".yml",2);
196 | themeManager.put(file,getManagerByConfig(config),config);
197 | getLogger().info("加载样式: "+file);
198 | }
199 | }else{
200 | getLogger().info("未加载任何样式");
201 | }
202 | }
203 |
204 |
205 | public LinkedList getPlayerConfigs() {
206 | return playerConfigs;
207 | }
208 |
209 | public VariableManager getVarManager() {
210 | return varManager;
211 | }
212 |
213 | public void setVarManager(VariableManager varManager) {
214 | this.varManager = varManager;
215 | }
216 |
217 | public PlayerConfig getPlayerConfig(String playerName) {
218 | for(PlayerConfig config:playerConfigs) {
219 | if(config.getPlayerName().equalsIgnoreCase(playerName)) {
220 | return config;
221 | }
222 | }
223 | return null;
224 | }
225 |
226 | public PlayerConfig getPlayerConfigInit(String playerName){
227 | PlayerConfig config = new PlayerConfig(playerName,new MessageManager(),null);
228 | if(!playerConfigs.contains(config)){
229 | playerConfigs.add(config);
230 | }
231 | return playerConfigs.get(playerConfigs.indexOf(config));
232 | }
233 |
234 | public MessageManager getShowMessages() {
235 | return showMessages;
236 | }
237 |
238 | public MessageManager addShowMessageByMap(Map map1, int type){
239 | MessageManager messages = new MessageManager();
240 | if(map1 != null && map1.size() > 0) {
241 | switch (type) {
242 | case BaseMessage.BOSS_BAR_TYPE:
243 | for (Object o : map1.keySet()) {
244 | Map map = (Map) map1.get(o);
245 | BossBarMessage message = new BossBarMessage(o.toString(),
246 | (boolean) map.get("是否开启"),
247 | (int) map.get("间隔时间"),
248 | (boolean) map.get("是否根据玩家血量变化"),
249 | getList((List) map.get("消息轮播")));
250 | if (map.containsKey("显示颜色")) {
251 | try {
252 | message.setBossBarColor(BossBarColor.valueOf((String) map.get("显示颜色")));
253 | } catch (Exception e) {
254 | getLogger().error("错误: 无法识别的BossBar颜色: " + map.get("显示颜色"), e);
255 | }
256 | }
257 | messages.add(message);
258 | }
259 | break;
260 | case BaseMessage.CHAT_MESSAGE_TYPE:
261 | for (Object o : map1.keySet()) {
262 | Map map = (Map) map1.get(o);
263 | messages.add(new ChatMessage(o.toString(), (boolean) map.get("是否开启"), (String) map.get("显示"), (boolean) map.get("是否仅在世界内有效")));
264 | }
265 | break;
266 | case BaseMessage.NAME_TAG_TYPE:
267 | for (Object o : map1.keySet()) {
268 | Map map = (Map) map1.get(o);
269 | messages.add(new NameTagMessage(o.toString(), (boolean) map.get("是否开启"), (String) map.get("显示")));
270 | }
271 | break;
272 | case BaseMessage.SCOREBOARD_TYPE:
273 | for (Object o : map1.keySet()) {
274 | Map map = (Map) map1.get(o);
275 | messages.add(new ScoreBoardMessage(o.toString(),
276 | (boolean) map.get("是否开启"),
277 | (String) map.get("Title"),
278 | getList((List) map.get("Line"))));
279 | }
280 | break;
281 | case BaseMessage.TIP_MESSAGE_TYPE:
282 | for (Object o : map1.keySet()) {
283 | Map map = (Map) map1.get(o);
284 | messages.add(new TipMessage(o.toString(),
285 | (boolean) map.get("是否开启"), (int) map.get("显示类型"),
286 | (String) map.get("显示")));
287 | }
288 | break;
289 | case BaseMessage.BROAD_CAST_TYPE:
290 | for (Object o : map1.keySet()) {
291 | Map map = (Map) map1.get(o);
292 | messages.add(new BroadcastMessage(o.toString(),
293 | (boolean) map.get("是否开启"),
294 | (int) map.get("间隔时间"), getList((List) map.get("消息轮播"))));
295 | }
296 | break;
297 | default:
298 | break;
299 | }
300 | }
301 | return messages;
302 | }
303 |
304 | private LinkedList getList(List list){
305 | LinkedList strings = new LinkedList<>();
306 | for(Object o:list){
307 | strings.add(o.toString());
308 | }
309 | return strings;
310 | }
311 |
312 | public void setShowMessages(MessageManager showMessages) {
313 | this.showMessages = showMessages;
314 | }
315 |
316 |
317 |
318 | public static Main getInstance() {
319 | return instance;
320 | }
321 |
322 | private String[] getFileNames(String fileName) {
323 | List names = new ArrayList<>();
324 | File files = new File(getDataFolder()+ "/"+fileName);
325 | if(files.isDirectory()){
326 | File[] filesArray = files.listFiles();
327 | if(filesArray != null){
328 | if(filesArray.length>0){
329 | for(File file : filesArray){
330 | names.add( file.getName().substring(0, file.getName().lastIndexOf(".")));
331 | }
332 | }
333 | }
334 | }
335 | return names.toArray(new String[0]);
336 | }
337 |
338 | private String[] getPlayerFiles() {
339 | return getFileNames("Players");
340 | }
341 |
342 | @Override
343 | public void onDisable() {
344 | //保存配置文件
345 | for(PlayerConfig config:playerConfigs){
346 | config.save();
347 | }
348 | LinkedHashMap> configs = new LinkedHashMap<>();
349 | for(BaseMessage message: getShowMessages()){
350 | BaseMessage.BaseTypes type = BaseMessage.getBaseTypeByInteger(message.getType());
351 | if(type != null){
352 | if(configs.containsKey(type.getConfigName())){
353 | LinkedHashMap map = configs.get(type.getConfigName());
354 | map.putAll(message.getConfig());
355 | }else {
356 | configs.put(type.getConfigName(), message.getConfig());
357 | }
358 | }
359 | }
360 | Config config = getLevelMessage();
361 | if(config != null) {
362 | for (String name : configs.keySet()) {
363 | config.set(name, configs.get(name));
364 | }
365 | config.save();
366 | }
367 | //关闭不再使用的消息
368 | if (executor != null) {
369 | executor.shutdown();
370 | executor = null;
371 | }
372 |
373 | tasks.invalidateAll();
374 | for (Player player : new HashSet<>(this.apis.keySet())) {
375 | BossBarApi.removeBossBar(player);
376 | }
377 | }
378 |
379 |
380 | }
381 |
--------------------------------------------------------------------------------
/src/main/java/tip/bossbar/BossBarApi.java:
--------------------------------------------------------------------------------
1 | package tip.bossbar;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.utils.DummyBossBar;
5 | import tip.Main;
6 | import tip.utils.BossMessageBuilder;
7 |
8 |
9 | /**
10 | * @author SmallasWater
11 | */
12 | public class BossBarApi extends DummyBossBar.Builder{
13 |
14 | public long bossId;
15 |
16 | private BossBarApi(Player player){
17 | super(player);
18 | }
19 |
20 |
21 | public static void createBossBar(Player player){
22 | if(!Main.getInstance().apis.containsKey(player)) {
23 | BossBarApi bossBar = new BossBarApi(player);
24 | bossBar.length(0);
25 | bossBar.text("加载中");
26 | Main.getInstance().apis.put(player, bossBar);
27 | bossBar.bossId = player.createBossBar(Main.getInstance().apis.get(player).build());
28 | }
29 | }
30 |
31 |
32 | public static void removeBossBar(Player player){
33 | if(Main.getInstance().apis.containsKey(player)){
34 | if(player.getDummyBossBar(Main.getInstance().apis.get(player).bossId) != null) {
35 | player.removeBossBar(Main.getInstance().apis.get(player).bossId);
36 | }
37 | }
38 | }
39 |
40 |
41 | public static void showBoss(Player player, String text, BossMessageBuilder builder, int time){
42 | if(Main.getInstance().apis.get(player) != null){
43 | if(player.getDummyBossBar(Main.getInstance().apis.get(player).bossId) == null){
44 | Main.getInstance().apis.remove(player);
45 | return;
46 | }
47 | DummyBossBar bossBar = player.getDummyBossBar(Main.getInstance().apis.get(player).bossId);
48 | bossBar.setText(text);
49 | if(builder.isHealth()){
50 | bossBar.setLength((float)Math.round(player.getHealth() / (float)player.getMaxHealth() * 100.0F));
51 | }else{
52 | float m;
53 | if(time < 0){
54 | m = 0;
55 | }else{
56 | m = (float)Math.round(time / (float)builder.getTime() * 100.0F);
57 | }
58 | bossBar.setLength(m);
59 | }
60 | try {
61 | Class.forName("cn.nukkit.utils.BossBarColor");
62 | bossBar.setColor(builder.getBossBarColor());
63 | }catch (Exception ignore){}
64 | player.createBossBar(bossBar);
65 |
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/TipsCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.command.CommandSender;
5 | import tip.Main;
6 | import tip.commands.base.BaseCommand;
7 | import tip.commands.sub.*;
8 | import tip.windows.CreateWindow;
9 | import tip.windows.ListenerWindow;
10 |
11 | /**
12 | * @author SmallasWater
13 | */
14 | public class TipsCommand extends BaseCommand {
15 |
16 | public TipsCommand(String name) {
17 | super(name, "");
18 | this.setPermission("tips.ts");
19 | this.setAliases(Main.getInstance().getConfig().getStringList("自定义指令.aliases").toArray(new String[0]));
20 | this.description = Main.getInstance().getConfig().getString("自定义指令.description", "自定义玩家提示");
21 |
22 | this.addSubCommand(new DefaultSubCommand("default"));
23 | this.addSubCommand(new SendSubCommand("send"));
24 | this.addSubCommand(new ReloadSubCommand("reload"));
25 |
26 | this.addSubCommand(new AchAllSubCommand("achAll"));
27 | this.addSubCommand(new ThemeSubCommand("theme"));
28 |
29 | this.loadCommandBase();
30 | }
31 |
32 | @Override
33 | public boolean hasPermission(CommandSender sender) {
34 | return true;
35 | }
36 |
37 | @Override
38 | public boolean execute(CommandSender sender, String s, String[] args) {
39 | if (hasPermission(sender)) {
40 | if (sender.isOp()) {
41 | if (args.length == 0) {
42 | if (sender instanceof Player) {
43 | ListenerWindow.CHOSE_TYPE.put(sender.getName(), 0);
44 | CreateWindow.sendSetting((Player) sender);
45 | return true;
46 | } else {
47 | sender.sendMessage("请不要用控制台执行..");
48 | return false;
49 | }
50 | }
51 | } else {
52 | if (args.length == 0) {
53 | this.sendHelp(sender);
54 | return false;
55 | }
56 | }
57 | } else {
58 | if (args.length == 0) {
59 | this.sendHelp(sender);
60 | return false;
61 | }
62 | }
63 | return super.execute(sender, s, args);
64 | }
65 |
66 | @Override
67 | public void sendHelp(CommandSender sender) {
68 | sender.sendMessage("§a====================");
69 | if (sender.isOp()) {
70 | sender.sendMessage("§e/" + getName() + " §e打开设置玩家显示GUI");
71 | sender.sendMessage("§e/" + getName() + " §7default §e打开设置默认显示GUI");
72 | sender.sendMessage("§e/" + getName() + " §7send <玩家> <类型> <信息>§e给玩家发送消息\n§r类型: tip,popup,action,title,msg");
73 | sender.sendMessage("§e/" + getName() + " §7reload §e重新读取配置");
74 | }
75 | sender.sendMessage("§e/" + getName() + " §7achAll §e打开成就GUI");
76 | sender.sendMessage("§e/" + getName() + " §7theme §e打开设置样式GUI");
77 | sender.sendMessage("§a====================");
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/base/BaseCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.base;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.command.Command;
5 | import cn.nukkit.command.CommandSender;
6 | import cn.nukkit.command.data.CommandParameter;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Arrays;
10 | import java.util.LinkedList;
11 | import java.util.concurrent.ConcurrentHashMap;
12 |
13 | /**
14 | * @author SmallasWater
15 | */
16 | public abstract class BaseCommand extends Command {
17 |
18 | private final ArrayList subCommand = new ArrayList<>();
19 |
20 | private final ConcurrentHashMap subCommands = new ConcurrentHashMap<>();
21 |
22 | public BaseCommand(String name, String description) {
23 | super(name,description);
24 | }
25 |
26 | /**
27 | * 获取权限
28 | * @param sender 玩家
29 | * @return 是否拥有权限
30 | */
31 | abstract public boolean hasPermission(CommandSender sender);
32 |
33 |
34 | @Override
35 | public boolean execute(CommandSender sender, String s, String[] args) {
36 | if(hasPermission(sender)) {
37 | String subCommand = args[0].toLowerCase();
38 | if (subCommands.containsKey(subCommand)) {
39 | BaseSubCommand command = this.subCommand.get(subCommands.get(subCommand));
40 | boolean canUse = command.hasPermission(sender);
41 | if (canUse) {
42 | return command.execute(sender,s, args);
43 | } else if (sender instanceof Player) {
44 | sender.sendMessage("你没有权限使用这个指令");
45 | return true;
46 | } else {
47 | sender.sendMessage("请不要在控制台执行此指令");
48 | }
49 | } else {
50 | sendHelp(sender);
51 | return true;
52 | }
53 | }
54 | return true;
55 | }
56 |
57 | /**
58 | * 发送帮助
59 | * @param sender 玩家
60 | * */
61 | abstract public void sendHelp(CommandSender sender);
62 |
63 | protected void addSubCommand(BaseSubCommand cmd) {
64 | subCommand.add(cmd);
65 | int commandId = (subCommand.size()) - 1;
66 | subCommands.put(cmd.getName().toLowerCase(), commandId);
67 | for (String alias : cmd.getAliases()) {
68 | subCommands.put(alias.toLowerCase(), commandId);
69 | }
70 | }
71 |
72 | protected void loadCommandBase(){
73 | this.commandParameters.clear();
74 | for(BaseSubCommand subCommand:subCommand){
75 | LinkedList parameters = new LinkedList<>();
76 | parameters.add(new CommandParameter(subCommand.getName(), new String[]{subCommand.getName()}));
77 | parameters.addAll(Arrays.asList(subCommand.getParameters()));
78 | this.commandParameters.put(subCommand.getName(),parameters.toArray(new CommandParameter[0]));
79 | }
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/base/BaseSubCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.base;
2 |
3 | import cn.nukkit.command.CommandSender;
4 | import cn.nukkit.command.data.CommandParameter;
5 |
6 | /**
7 | * @author SmallasWater
8 | */
9 | public abstract class BaseSubCommand {
10 |
11 | private final String name;
12 |
13 | protected BaseSubCommand(String name) {
14 | this.name = name.toLowerCase();
15 | }
16 |
17 | /**
18 | * 获取名称
19 | * @return string
20 | */
21 | public String getName(){
22 | return name;
23 | }
24 | /**
25 | * 获取别名
26 | * @return string[]
27 | */
28 | public abstract String[] getAliases();
29 |
30 | /**
31 | * 命令响应
32 | * @param sender the sender - CommandSender
33 | * @param args The arrugements - String[]
34 | * @param label label..
35 | * @return true if true
36 | */
37 | public abstract boolean execute(CommandSender sender,String label, String[] args);
38 |
39 |
40 | public boolean hasPermission(CommandSender sender){
41 | return true;
42 | }
43 | /**
44 | * 指令参数.
45 | * @return 提示参数
46 | * */
47 | abstract public CommandParameter[] getParameters();
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/sub/AchAllSubCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.sub;
2 |
3 | import cn.nukkit.Achievement;
4 | import cn.nukkit.Player;
5 | import cn.nukkit.Server;
6 | import cn.nukkit.command.CommandSender;
7 | import cn.nukkit.command.data.CommandParameter;
8 | import cn.nukkit.form.window.FormWindowSimple;
9 | import com.smallaswater.achievement.Achievements;
10 | import tip.commands.base.BaseSubCommand;
11 |
12 | /**
13 | * @author SmallasWater
14 | */
15 | public class AchAllSubCommand extends BaseSubCommand {
16 |
17 | public AchAllSubCommand(String name) {
18 | super(name);
19 | }
20 |
21 | @Override
22 | public String[] getAliases() {
23 | return new String[0];
24 | }
25 |
26 | @Override
27 | public boolean execute(CommandSender sender, String label, String[] args) {
28 | if(sender instanceof Player) {
29 | FormWindowSimple simple = new FormWindowSimple("§e§l成就系统", "");
30 | StringBuilder builder = new StringBuilder();
31 | builder.append("§7成就进度: §2").append(((Player) sender).achievements.size()).append("§r/§7").append(Achievement.achievements.size()).append("§r\n");
32 | for (String s1 : Achievement.achievements.keySet()) {
33 | String msg = Achievement.achievements.get(s1).message;
34 | if (Server.getInstance().getPluginManager().getPlugin("Achievements") != null) {
35 | String a1 = Achievements.getString(msg);
36 | if (!"".equals(a1)) {
37 | msg = a1;
38 | } else {
39 | a1 = Achievements.getString(s1);
40 | if (!"".equals(a1)) {
41 | msg = a1;
42 | }
43 | }
44 | }
45 | builder.append(msg).append("§e: —— ");
46 | if (!((Player) sender).hasAchievement(s1)) {
47 | builder.append("§c§l✘§r\n\n");
48 | } else {
49 | builder.append("§a§l√§r\n\n");
50 | }
51 | }
52 |
53 | simple.setContent(builder.toString());
54 | ((Player) sender).showFormWindow(simple);
55 | }
56 | return true;
57 | }
58 |
59 | @Override
60 | public boolean hasPermission(CommandSender sender) {
61 | return sender.hasPermission("tips.achall");
62 | }
63 |
64 | @Override
65 | public CommandParameter[] getParameters() {
66 | return new CommandParameter[0];
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/sub/DefaultSubCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.sub;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.command.CommandSender;
5 | import cn.nukkit.command.data.CommandParameter;
6 | import tip.commands.base.BaseSubCommand;
7 | import tip.windows.CreateWindow;
8 | import tip.windows.ListenerWindow;
9 |
10 | /**
11 | * @author SmallasWater
12 | */
13 | public class DefaultSubCommand extends BaseSubCommand {
14 | public DefaultSubCommand(String name) {
15 | super(name);
16 | }
17 |
18 | @Override
19 | public String[] getAliases() {
20 | return new String[0];
21 | }
22 |
23 | @Override
24 | public boolean execute(CommandSender sender, String label, String[] args) {
25 | if (sender instanceof Player) {
26 | ListenerWindow.CHOSE_TYPE.put(sender.getName(),1);
27 | CreateWindow.sendSettingType((Player) sender);
28 | return true;
29 | } else {
30 | sender.sendMessage("请不要用控制台执行..");
31 | return false;
32 | }
33 | }
34 |
35 | @Override
36 | public boolean hasPermission(CommandSender sender) {
37 | return sender.hasPermission("tips.default");
38 | }
39 |
40 | @Override
41 | public CommandParameter[] getParameters() {
42 | return new CommandParameter[0];
43 | }
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/sub/ReloadSubCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.sub;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.Server;
5 | import cn.nukkit.command.CommandSender;
6 | import cn.nukkit.command.data.CommandParameter;
7 | import cn.nukkit.utils.TextFormat;
8 | import tip.Main;
9 | import tip.commands.base.BaseSubCommand;
10 |
11 | /**
12 | * @author SmallasWater
13 | */
14 | public class ReloadSubCommand extends BaseSubCommand {
15 | public ReloadSubCommand(String name) {
16 | super(name);
17 | }
18 |
19 | @Override
20 | public String[] getAliases() {
21 | return new String[0];
22 | }
23 |
24 | @Override
25 | public boolean execute(CommandSender sender, String label, String[] args) {
26 | Main.getInstance().init();
27 | for(Player player: Server.getInstance().getOnlinePlayers().values()){
28 | Main.getInstance().loadPlayerConfig(player);
29 | }
30 | sender.sendMessage(TextFormat.YELLOW+"配置文件重新读取完成");
31 | return true;
32 | }
33 |
34 | @Override
35 | public CommandParameter[] getParameters() {
36 | return new CommandParameter[0];
37 | }
38 |
39 | @Override
40 | public boolean hasPermission(CommandSender sender) {
41 | return sender.hasPermission("tips.reload");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/sub/SendSubCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.sub;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.Server;
5 | import cn.nukkit.command.CommandSender;
6 | import cn.nukkit.command.data.CommandParamType;
7 | import cn.nukkit.command.data.CommandParameter;
8 | import tip.commands.base.BaseSubCommand;
9 |
10 | import java.util.Arrays;
11 |
12 | /**
13 | * @author SmallasWater
14 | */
15 | public class SendSubCommand extends BaseSubCommand {
16 | public SendSubCommand(String name) {
17 | super(name);
18 | }
19 |
20 | @Override
21 | public String[] getAliases() {
22 | return new String[0];
23 | }
24 |
25 | private final static String[] TYPES = new String[]{"tip","popup","action","title","msg"};
26 | @Override
27 | public boolean execute(CommandSender sender, String label, String[] args) {
28 | if(args.length > 2){
29 | String playerName = args[1];
30 | Player player = Server.getInstance().getPlayer(playerName);
31 | if(player != null){
32 | String type = args[2].toLowerCase();
33 | if(Arrays.asList(TYPES).contains(type)){
34 | String msg = args[3];
35 | switch (type){
36 | case "tip":
37 | player.sendTip(msg);
38 | break;
39 | case "action":
40 | player.sendActionBar(msg);
41 | break;
42 | case "popup":
43 | player.sendPopup(msg);
44 | break;
45 | case "title":
46 | String[] strings = msg.split("&");
47 | String title = strings[0];
48 | StringBuilder s = new StringBuilder();
49 | if(strings.length > 1){
50 | for(int i = 1;i < strings.length;i++){
51 | s.append(strings[i]).append("\n");
52 | }
53 | }
54 | player.sendTitle(title, s.toString());
55 | break;
56 | case "msg":
57 | player.sendMessage(msg);
58 | break;
59 | default:break;
60 | }
61 | sender.sendMessage("发送成功");
62 | return true;
63 | }else{
64 | sender.sendMessage("请使用支持的类型: "+Arrays.asList(TYPES));
65 | }
66 |
67 | }else{
68 | sender.sendMessage("玩家 "+playerName+"不在线");
69 | return true;
70 | }
71 | }
72 | return false;
73 | }
74 |
75 | @Override
76 | public CommandParameter[] getParameters() {
77 | return new CommandParameter[]{
78 | new CommandParameter("player", CommandParamType.TARGET,true),
79 | new CommandParameter("type", TYPES),
80 | new CommandParameter("message",CommandParamType.TEXT,true)
81 | };
82 | }
83 |
84 | @Override
85 | public boolean hasPermission(CommandSender sender) {
86 | return sender.hasPermission("tips.send");
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/tip/commands/sub/ThemeSubCommand.java:
--------------------------------------------------------------------------------
1 | package tip.commands.sub;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.command.CommandSender;
5 | import cn.nukkit.command.data.CommandParameter;
6 | import tip.commands.base.BaseSubCommand;
7 | import tip.windows.CreateWindow;
8 |
9 |
10 | /**
11 | * @author SmallasWater
12 | *
13 | */
14 | public class ThemeSubCommand extends BaseSubCommand {
15 |
16 | public ThemeSubCommand(String name) {
17 | super(name);
18 |
19 | }
20 |
21 | @Override
22 | public String[] getAliases() {
23 | return new String[0];
24 | }
25 |
26 | @Override
27 | public boolean execute(CommandSender sender, String label, String[] args) {
28 | if(sender.isPlayer()){
29 | CreateWindow.sendChoseTheme((Player) sender);
30 | return true;
31 | }
32 | return false;
33 | }
34 |
35 | @Override
36 | public boolean hasPermission(CommandSender sender) {
37 | return sender.hasPermission("tips.theme");
38 | }
39 |
40 | @Override
41 | public CommandParameter[] getParameters() {
42 | return new CommandParameter[0];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/tip/lib/viewcompass/ViewCompassVariable.java:
--------------------------------------------------------------------------------
1 | package tip.lib.viewcompass;
2 |
3 | import cn.nukkit.Player;
4 | import tip.utils.variables.BaseVariable;
5 |
6 | /**
7 | * 本类引用 @PetteriM1 作者 的ViewCompass 方法
8 | *
9 | * @author from PetteriM1
10 | */
11 | public class ViewCompassVariable extends BaseVariable {
12 |
13 | private static final String[] COMPASS = new String[36];
14 |
15 | public ViewCompassVariable(Player player) {
16 | super(player);
17 | init();
18 | }
19 |
20 | private void init() {
21 | COMPASS[0] = "\u00A77| | | | | \u00A7l\u00A71南\u00A7r\u00A77 | | | | |";
22 | COMPASS[1] = "\u00A77| | | | \u00A7l\u00A71南\u00A7r\u00A77 | | | | | |";
23 | COMPASS[2] = "\u00A77| | | \u00A7l\u00A71南\u00A7r\u00A77 | | | | \u00A7l\u00A7f西南\u00A7r\u00A77 | |";
24 | COMPASS[3] = "\u00A77| | | | | | \u00A7l\u00A7f西南\u00A7r\u00A77 | | | |";
25 | COMPASS[4] = "\u00A77| | | | | \u00A7l\u00A7f西南\u00A7r\u00A77 | | | | |";
26 | COMPASS[5] = "\u00A77| | | | \u00A7l\u00A7f西南\u00A7r\u00A77 | | | | | |";
27 | COMPASS[6] = "\u00A77| | \u00A7l\u00A7f西南\u00A7r\u00A77 | | | | \u00A7l\u00A7a西\u00A7r\u00A77 | | |";
28 | COMPASS[7] = "\u00A77| | | | | | \u00A7l\u00A7a西\u00A7r\u00A77 | | | |";
29 | COMPASS[8] = "\u00A77| | | | | \u00A7l\u00A7a西\u00A7r\u00A77 | | | | |";
30 | COMPASS[9] = "\u00A77| | | | | \u00A7l\u00A7a西\u00A7r\u00A77 | | | | |";
31 | COMPASS[10] = "\u00A77| | | | \u00A7l\u00A7a西\u00A7r\u00A77 | | | | | |";
32 | COMPASS[11] = "\u00A77| | | \u00A7l\u00A7a西\u00A7r\u00A77 | | | | \u00A7l\u00A7f西北\u00A7r\u00A77 | |";
33 | COMPASS[12] = "\u00A77| | | | | | \u00A7l\u00A7f西北\u00A7r\u00A77 | | | |";
34 | COMPASS[13] = "\u00A77| | | | | \u00A7l\u00A7f西北\u00A7r\u00A77 | | | | |";
35 | COMPASS[14] = "\u00A77| | | | \u00A7l\u00A7f西北\u00A7r\u00A77 | | | | | |";
36 | COMPASS[15] = "\u00A77| | \u00A7l\u00A7f西北\u00A7r\u00A77 | | | | \u00A7l\u00A7c北\u00A7r\u00A77 | | |";
37 | COMPASS[16] = "\u00A77| | | | | | \u00A7l\u00A7c北\u00A7r\u00A77 | | | |";
38 | COMPASS[17] = "\u00A77| | | | | \u00A7l\u00A7c北\u00A7r\u00A77 | | | | |";
39 | COMPASS[18] = "\u00A77| | | | | \u00A7l\u00A7c北\u00A7r\u00A77 | | | | |";
40 | COMPASS[19] = "\u00A77| | | | \u00A7l\u00A7c北\u00A7r\u00A77 | | | | | |";
41 | COMPASS[20] = "\u00A77| | | \u00A7l\u00A7c北\u00A7r\u00A77 | | | | \u00A7l\u00A7f东北\u00A7r\u00A77 | |";
42 | COMPASS[21] = "\u00A77| | | | | | \u00A7l\u00A7f东北\u00A7r\u00A77 | | | |";
43 | COMPASS[22] = "\u00A77| | | | | \u00A7l\u00A7f东北\u00A7r\u00A77 | | | | |";
44 | COMPASS[23] = "\u00A77| | | | \u00A7l\u00A7f东北\u00A7r\u00A77 | | | | | |";
45 | COMPASS[24] = "\u00A77| | \u00A7l\u00A7f东北\u00A7r\u00A77 | | | | \u00A7l\u00A7e东\u00A7r\u00A77 | | |";
46 | COMPASS[25] = "\u00A77| | | | | | | \u00A7l\u00A7e东\u00A7r\u00A77 | | |";
47 | COMPASS[26] = "\u00A77| | | | | | \u00A7l\u00A7e东\u00A7r\u00A77 | | | |";
48 | COMPASS[27] = "\u00A77| | | | | \u00A7l\u00A7e东\u00A7r\u00A77 | | | | |";
49 | COMPASS[28] = "\u00A77| | | | \u00A7l\u00A7e东\u00A7r\u00A77 | | | | | |";
50 | COMPASS[29] = "\u00A77| | | \u00A7l\u00A7e东\u00A7r\u00A77 | | | | \u00A7l\u00A7f东南\u00A7r\u00A77 | |";
51 | COMPASS[30] = "\u00A77| | | | | | \u00A7l\u00A7f东南\u00A7r\u00A77 | | | |";
52 | COMPASS[31] = "\u00A77| | | | | \u00A7l\u00A7f东南\u00A7r\u00A77 | | | | |";
53 | COMPASS[32] = "\u00A77| | | | \u00A7l\u00A7f东南\u00A7r\u00A77 | | | | | |";
54 | COMPASS[33] = "\u00A77| | \u00A7l\u00A7f东南\u00A7r\u00A77 | | | | \u00A7l\u00A71南\u00A7r\u00A77 | | |";
55 | COMPASS[34] = "\u00A77| | | | | | | \u00A7l\u00A71南\u00A7r\u00A77 | | |";
56 | COMPASS[35] = "\u00A77| | | | | | \u00A7l\u00A71南\u00A7r\u00A77 | | | |";
57 | }
58 |
59 | private String getCompass(double direction) {
60 | direction = direction + Math.ceil(-direction / 360) * 360;
61 | direction = direction * 2 / 10 / 2;
62 | return COMPASS[Math.round((long) direction)];
63 | }
64 |
65 | @Override
66 | public void strReplace() {
67 | if (player == null || !player.isOnline()) {
68 | return;
69 | }
70 | addStrReplaceString("{view}", getCompass(player.getYaw()));
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/BaseMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 |
4 | import tip.utils.variables.BaseVariable;
5 |
6 | import java.util.LinkedHashMap;
7 |
8 | /**
9 | * @author SmallasWater
10 | */
11 | public abstract class BaseMessage implements Cloneable{
12 |
13 | public static final int BOSS_BAR_TYPE = 0;
14 |
15 | public static final int CHAT_MESSAGE_TYPE = 1;
16 |
17 | public static final int NAME_TAG_TYPE = 2;
18 |
19 | public static final int SCOREBOARD_TYPE = 3;
20 |
21 | public static final int TIP_MESSAGE_TYPE = 4;
22 |
23 | public static final int BROAD_CAST_TYPE = 5;
24 |
25 | private String worldName;
26 |
27 |
28 | private boolean open;
29 |
30 | public BaseMessage(String worldName, boolean open){
31 | this.worldName = worldName;
32 | this.open = open;
33 | }
34 |
35 | public int getType(){
36 | return -1;
37 | }
38 |
39 |
40 | @Override
41 | public int hashCode() {
42 | return worldName.hashCode() + getType();
43 | }
44 |
45 | public void setWorldName(String worldName) {
46 | this.worldName = worldName;
47 | }
48 |
49 | public String getWorldName() {
50 | return worldName;
51 | }
52 |
53 | public boolean isOpen() {
54 | return open;
55 | }
56 |
57 |
58 | public void setOpen(boolean open) {
59 | this.open = open;
60 | }
61 |
62 |
63 |
64 | /**
65 | * 保存在配置的..
66 | * @return 配置内容
67 | * */
68 | abstract public LinkedHashMap getConfig();
69 |
70 | @Override
71 | public boolean equals(Object obj) {
72 | if(obj instanceof BaseMessage){
73 | return ((BaseMessage) obj).getWorldName().equalsIgnoreCase(getWorldName())
74 | && ((BaseMessage) obj).getType() == getType();
75 | }
76 | return false;
77 | }
78 |
79 | public static BaseTypes getBaseTypeByInteger(int type){
80 | for(BaseTypes types:BaseTypes.values()){
81 | if(types.getType() == type){
82 | return types;
83 | }
84 | }
85 | return null;
86 | }
87 |
88 | public static BaseTypes getTypeByName(String name){
89 | for(BaseTypes types:BaseTypes.values()){
90 | if(types.getConfigName().equalsIgnoreCase(name)){
91 | return types;
92 | }
93 | }
94 | return null;
95 | }
96 |
97 |
98 |
99 |
100 | public enum BaseTypes{
101 | /**显示类型*/
102 | BOSS_BAR(0,"Boss血条"),
103 | CHAT_MESSAGE(1,"聊天"),
104 | NAME_TAG(2,"头部"),
105 | SCORE_BOARD(3,"计分板"),
106 | TIP(4,"底部"),
107 | BROADCAST(5,"聊天栏公告");
108 | protected int type;
109 | protected String configName;
110 | BaseTypes(int type,String configName){
111 | this.type = type;
112 | this.configName = configName;
113 | }
114 |
115 | public String getConfigName() {
116 | return configName;
117 | }
118 |
119 | public int getType() {
120 | return type;
121 | }
122 | }
123 |
124 | @Override
125 | public BaseMessage clone() {
126 | try {
127 | return (BaseMessage) super.clone();
128 | } catch (CloneNotSupportedException e) {
129 | e.printStackTrace();
130 | }
131 | return null;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/BossBarMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 | import tip.utils.BossMessageBuilder;
4 |
5 | import java.util.LinkedHashMap;
6 | import java.util.LinkedList;
7 |
8 | /**
9 | * @author SmallasWater
10 | */
11 | @Deprecated
12 | public class BossBarMessage extends tip.messages.defaults.BossBarMessage {
13 |
14 |
15 | public BossBarMessage(String worldName, boolean open, int time, boolean size, LinkedList message) {
16 | super(worldName, open, time, size, message);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/BroadcastMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.LinkedList;
5 |
6 | /**
7 | * @author SmallasWater
8 | */
9 | @Deprecated
10 | public class BroadcastMessage extends tip.messages.defaults.BroadcastMessage {
11 |
12 |
13 | public BroadcastMessage(String worldName, boolean open, int time, LinkedList message) {
14 | super(worldName, open, time, message);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/ChatMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 | import java.util.LinkedHashMap;
4 |
5 | /**
6 | * @author SmallasWater
7 | */
8 | @Deprecated
9 | public class ChatMessage extends tip.messages.defaults.ChatMessage {
10 |
11 |
12 | public ChatMessage(String worldName, boolean open, String message, boolean inWorld) {
13 | super(worldName, open, message, inWorld);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/NameTagMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 |
4 | /**
5 | * @author SmallasWater
6 | */
7 | @Deprecated
8 | public class NameTagMessage extends tip.messages.defaults.NameTagMessage {
9 |
10 | public NameTagMessage(String worldName, boolean open, String message) {
11 | super(worldName, open, message);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/ScoreBoardMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 |
4 | import java.util.LinkedList;
5 |
6 | /**
7 | * @author SmallasWater
8 | */
9 | @Deprecated
10 | public class ScoreBoardMessage extends tip.messages.defaults.ScoreBoardMessage {
11 |
12 | public ScoreBoardMessage(String worldName, boolean open, String title, LinkedList message) {
13 | super(worldName, open, title, message);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/TipMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages;
2 |
3 |
4 | /**
5 | * 适配旧版本的
6 | * @author SmallasWater
7 | */
8 | @Deprecated
9 | public class TipMessage extends tip.messages.defaults.TipMessage {
10 |
11 | public TipMessage(String worldName, boolean open, int type, String message) {
12 | super(worldName, open, type, message);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/BossBarMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 | import cn.nukkit.utils.BossBarColor;
4 | import tip.messages.BaseMessage;
5 | import tip.utils.BossMessageBuilder;
6 |
7 |
8 | import java.util.LinkedHashMap;
9 | import java.util.LinkedList;
10 |
11 | /**
12 | * @author SmallasWater
13 | */
14 | public class BossBarMessage extends BaseMessage {
15 |
16 |
17 | private int time;
18 |
19 | private LinkedList messages;
20 |
21 | private BossBarColor bossBarColor;
22 |
23 | private boolean size;
24 |
25 | public BossBarMessage(String worldName, boolean open,int time,boolean size,LinkedList message) {
26 | this(worldName, open, time, BossBarColor.RED, size, message);
27 | }
28 |
29 | public BossBarMessage(String worldName, boolean open, int time, BossBarColor bossBarColor, boolean size, LinkedList message) {
30 | super(worldName, open);
31 | this.time = time;
32 | this.messages = message;
33 | this.bossBarColor = bossBarColor;
34 | this.size = size;
35 | }
36 |
37 | public BossMessageBuilder getBuilder(){
38 | return new BossMessageBuilder(messages,time,size,bossBarColor);
39 | }
40 |
41 | @Override
42 | public int getType() {
43 | return BOSS_BAR_TYPE;
44 | }
45 |
46 | public int getTime() {
47 | return time;
48 | }
49 |
50 | public void setTime(int time) {
51 | this.time = time;
52 | }
53 |
54 | public boolean isSize() {
55 | return size;
56 | }
57 |
58 | public void setSize(boolean size) {
59 | this.size = size;
60 | }
61 |
62 | public BossBarColor getBossBarColor() {
63 | return bossBarColor;
64 | }
65 |
66 | public void setBossBarColor(BossBarColor bossBarColor) {
67 | this.bossBarColor = bossBarColor;
68 | }
69 |
70 | public LinkedList getMessages() {
71 | return messages;
72 | }
73 |
74 | public void setMessages(LinkedList messages) {
75 | this.messages = messages;
76 | }
77 |
78 | @Override
79 | public LinkedHashMap getConfig(){
80 | LinkedHashMap objectLinkedHashMap = new LinkedHashMap<>();
81 | LinkedHashMap sub = new LinkedHashMap<>();
82 | sub.put("是否开启",isOpen());
83 | sub.put("间隔时间",getTime());
84 | sub.put("显示颜色",getBossBarColor().name());
85 | sub.put("是否根据玩家血量变化",isSize());
86 | sub.put("消息轮播",getMessages());
87 | objectLinkedHashMap.put(getWorldName(),sub);
88 | return objectLinkedHashMap;
89 | }
90 |
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/BroadcastMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 | import tip.messages.BaseMessage;
4 |
5 | import java.util.LinkedHashMap;
6 | import java.util.LinkedList;
7 |
8 | /**
9 | * @author SmallasWater
10 | */
11 | public class BroadcastMessage extends BaseMessage {
12 |
13 | private int time;
14 |
15 | private LinkedList messages;
16 | public BroadcastMessage(String worldName, boolean open, int time, LinkedList message) {
17 | super(worldName, open);
18 | this.time = time;
19 | this.messages = message;
20 | }
21 |
22 | @Override
23 | public int getType() {
24 | return BROAD_CAST_TYPE;
25 | }
26 |
27 | public LinkedList getMessages() {
28 | return messages;
29 | }
30 |
31 | public void setMessages(LinkedList message) {
32 | this.messages = message;
33 | }
34 |
35 | public int getTime() {
36 | return time;
37 | }
38 |
39 | public void setTime(int time) {
40 | this.time = time;
41 | }
42 |
43 | @Override
44 | public LinkedHashMap getConfig() {
45 | LinkedHashMap objectLinkedHashMap = new LinkedHashMap<>();
46 | LinkedHashMap sub = new LinkedHashMap<>();
47 | sub.put("是否开启",isOpen());
48 | sub.put("间隔时间",getTime());
49 | sub.put("消息轮播",getMessages());
50 | objectLinkedHashMap.put(getWorldName(),sub);
51 | return objectLinkedHashMap;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/ChatMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 | import tip.messages.BaseMessage;
4 |
5 | import java.util.LinkedHashMap;
6 |
7 | /**
8 | * @author SmallasWater
9 | */
10 | public class ChatMessage extends BaseMessage {
11 |
12 | private String message;
13 |
14 | private boolean inWorld;
15 |
16 | public ChatMessage(String worldName, boolean open, String message, boolean inWorld) {
17 | super(worldName, open);
18 | this.message = message;
19 | this.inWorld = inWorld;
20 | }
21 |
22 | public String getMessage() {
23 | return message;
24 | }
25 |
26 | @Override
27 | public int getType() {
28 | return CHAT_MESSAGE_TYPE;
29 | }
30 |
31 | public boolean isInWorld() {
32 | return inWorld;
33 | }
34 |
35 | public void setInWorld(boolean inWorld) {
36 | this.inWorld = inWorld;
37 | }
38 |
39 | public void setMessage(String message) {
40 | this.message = message;
41 | }
42 |
43 | @Override
44 | public LinkedHashMap getConfig(){
45 | LinkedHashMap objectLinkedHashMap = new LinkedHashMap<>();
46 | LinkedHashMap sub = new LinkedHashMap<>();
47 | sub.put("是否开启",isOpen());
48 | sub.put("显示",getMessage());
49 | sub.put("是否仅在世界内有效",isInWorld());
50 | objectLinkedHashMap.put(getWorldName(),sub);
51 | return objectLinkedHashMap;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/MessageManager.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 |
4 | import tip.messages.BaseMessage;
5 |
6 | import java.util.Arrays;
7 | import java.util.LinkedHashMap;
8 | import java.util.LinkedList;
9 |
10 | /**
11 | * @author SmallasWater
12 | */
13 | public class MessageManager extends LinkedList {
14 |
15 | public boolean hasExistsType(BaseMessage.BaseTypes types){
16 | for(BaseMessage message:this){
17 | if(message.getType() == types.getType()){
18 | return true;
19 | }
20 | }
21 | return false;
22 | }
23 |
24 | public void setMessage(BaseMessage message){
25 | BaseMessage message1 = getMessageByTypeAndWorld(message.getWorldName(),message.getType());
26 | if(message1 == null){
27 | this.add(message);
28 | }else{
29 | int i = this.indexOf(message1);
30 | if(i != -1) {
31 | this.set(i, message);
32 | }
33 | }
34 | }
35 |
36 | public BaseMessage getMessageByTypeAndWorld(String worldName,int type){
37 | BaseMessage baseMessage = null;
38 | for(BaseMessage message: this){
39 | if(message.getWorldName().split("&").length > 1){
40 | if(Arrays.asList(message.getWorldName().split("&"))
41 | .contains(worldName) && type == message.getType()){
42 | baseMessage = message;
43 | }
44 | }
45 | if("default".equalsIgnoreCase(message.getWorldName()) && message.getType() == type){
46 | baseMessage = message;
47 | }
48 | if(worldName.equalsIgnoreCase(message.getWorldName()) && type == message.getType()){
49 | baseMessage = message;
50 | }
51 | }
52 | return baseMessage;
53 | }
54 |
55 | public LinkedHashMap saveConfig(){
56 | LinkedHashMap config = new LinkedHashMap<>();
57 | for(BaseMessage message:this){
58 | BaseMessage.BaseTypes types = BaseMessage.getBaseTypeByInteger(message.getType());
59 | if(types != null){
60 | config.put(types.getConfigName(),message.getConfig());
61 | }
62 | }
63 | return config;
64 |
65 | }
66 |
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/NameTagMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 | import tip.messages.BaseMessage;
4 |
5 | import java.util.LinkedHashMap;
6 |
7 | /**
8 | * @author SmallasWater
9 | */
10 | public class NameTagMessage extends BaseMessage {
11 |
12 | private String message;
13 |
14 | public NameTagMessage(String worldName, boolean open,String message) {
15 | super(worldName, open);
16 | this.message = message;
17 | }
18 |
19 | @Override
20 | public int getType() {
21 | return NAME_TAG_TYPE;
22 | }
23 |
24 | public String getMessage() {
25 | return message;
26 | }
27 |
28 | public void setMessage(String message) {
29 | this.message = message;
30 | }
31 |
32 | @Override
33 | public LinkedHashMap getConfig(){
34 | LinkedHashMap objectLinkedHashMap = new LinkedHashMap<>();
35 | LinkedHashMap sub = new LinkedHashMap<>();
36 | sub.put("是否开启",isOpen());
37 | sub.put("显示",getMessage());
38 | objectLinkedHashMap.put(getWorldName(),sub);
39 | return objectLinkedHashMap;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/ScoreBoardMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 |
4 | import tip.messages.BaseMessage;
5 |
6 | import java.util.LinkedHashMap;
7 | import java.util.LinkedList;
8 |
9 | /**
10 | * @author SmallasWater
11 | */
12 | public class ScoreBoardMessage extends BaseMessage {
13 |
14 | private String title;
15 |
16 | private LinkedList messages;
17 |
18 | public ScoreBoardMessage(String worldName, boolean open,String title,LinkedList message) {
19 | super(worldName, open);
20 | this.title = title;
21 | this.messages = message;
22 | }
23 |
24 | @Override
25 | public int getType() {
26 | return SCOREBOARD_TYPE;
27 | }
28 |
29 | public String getTitle() {
30 | return title;
31 | }
32 |
33 | public LinkedList getMessages() {
34 | return messages;
35 | }
36 |
37 | public void setMessages(LinkedList messages) {
38 | this.messages = messages;
39 | }
40 |
41 | @Override
42 | public LinkedHashMap getConfig(){
43 | LinkedHashMap objectLinkedHashMap = new LinkedHashMap<>();
44 | LinkedHashMap sub = new LinkedHashMap<>();
45 | sub.put("是否开启",isOpen());
46 | sub.put("Title",getTitle());
47 | sub.put("Line",getMessages());
48 | objectLinkedHashMap.put(getWorldName(),sub);
49 | return objectLinkedHashMap;
50 | }
51 |
52 | public void setTitle(String title) {
53 | this.title = title;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/tip/messages/defaults/TipMessage.java:
--------------------------------------------------------------------------------
1 | package tip.messages.defaults;
2 |
3 | import tip.messages.BaseMessage;
4 |
5 | import java.util.LinkedHashMap;
6 |
7 | /**
8 | * @author SmallasWater
9 | */
10 | public class TipMessage extends BaseMessage {
11 |
12 | public static final int TIP = 0;
13 |
14 | public static final int POPUP = 1;
15 |
16 | public static final int ACTION = 2;
17 |
18 |
19 | private int type;
20 |
21 | private String message;
22 |
23 | public TipMessage(String worldName, boolean open,int type,String message) {
24 | super(worldName, open);
25 | this.message = message;
26 | this.type = type;
27 | }
28 |
29 | public void setType(int type) {
30 | this.type = type;
31 | }
32 |
33 | public String getMessage() {
34 | return message;
35 | }
36 |
37 | @Override
38 | public int getType() {
39 | return TIP_MESSAGE_TYPE;
40 | }
41 |
42 | public int getShowType() {
43 | return type;
44 | }
45 |
46 | public void setMessage(String message) {
47 | this.message = message;
48 | }
49 |
50 | @Override
51 | public LinkedHashMap getConfig(){
52 | LinkedHashMap objectLinkedHashMap = new LinkedHashMap<>();
53 | LinkedHashMap sub = new LinkedHashMap<>();
54 | sub.put("是否开启",isOpen());
55 | sub.put("显示类型",getShowType());
56 | sub.put("显示",getMessage());
57 | objectLinkedHashMap.put(getWorldName(),sub);
58 | return objectLinkedHashMap;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/AbstractPlayerAsyncTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.scheduler.AsyncTask;
5 |
6 | /**
7 | * @author SmallasWater
8 | */
9 | public abstract class AbstractPlayerAsyncTask extends AsyncTask {
10 |
11 | private Player player;
12 | AbstractPlayerAsyncTask(Player player){
13 | this.player = player;
14 | }
15 |
16 | public Player getPlayer() {
17 | return player;
18 | }
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/AddPlayerTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 |
4 | import tip.Main;
5 |
6 |
7 | /**
8 | * @author SmallasWater
9 | */
10 | public class AddPlayerTask {
11 |
12 | public static void add(BaseTipsRunnable task){
13 | Main.executor.execute(task);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/BaseTipsRunnable.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import tip.Main;
4 |
5 | /**
6 | * @author SmallasWater
7 | * Create on 2021/2/26 14:47
8 | * Package tip.tasks
9 | */
10 | public abstract class BaseTipsRunnable implements Runnable {
11 |
12 | public Main owner;
13 |
14 | public BaseTipsRunnable(Main owner){
15 | this.owner = owner;
16 | }
17 |
18 | public Main getOwner() {
19 | return owner;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/BossBarAllPlayerTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import tip.Main;
5 | import tip.bossbar.BossBarApi;
6 |
7 |
8 | /**
9 | * @author SmallasWater
10 | */
11 | public class BossBarAllPlayerTask {
12 |
13 |
14 | private Player player;
15 |
16 | public BossBarAllPlayerTask(Player player) {
17 | this.player = player;
18 | }
19 |
20 | public void onRun() {
21 | if (player == null || !player.isOnline()) {
22 | return;
23 | }
24 | BossBarApi.createBossBar(player);
25 | BossBarTask task = Main.getInstance().tasks.getIfPresent(player);
26 | if (task == null) {
27 | task = new BossBarTask();
28 | Main.getInstance().tasks.put(player, task);
29 | }
30 | task.onRun(player);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/BossBarTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import tip.Main;
5 | import tip.bossbar.BossBarApi;
6 | import tip.messages.BaseMessage;
7 | import tip.messages.defaults.BossBarMessage;
8 | import tip.utils.Api;
9 | import tip.utils.BossMessageBuilder;
10 |
11 | import java.util.LinkedHashMap;
12 |
13 | /**
14 | * @author 若水
15 | */
16 | public class BossBarTask {
17 |
18 | private final LinkedHashMap type = new LinkedHashMap<>();
19 |
20 | void onRun(Player player) {
21 | if (player == null) {
22 | return;
23 | }
24 | if (player.isOnline()) {
25 | if (!Main.getInstance().apis.containsKey(player)) {
26 | return;
27 | }
28 | BossBarMessage message = (BossBarMessage) Api.getSendPlayerMessage(player.getName(), player.getLevel().getFolderName(), BaseMessage.BaseTypes.BOSS_BAR);
29 | if (message != null) {
30 | if (message.isOpen()) {
31 | if (!type.containsKey(player.getLevel().getFolderName())) {
32 | type.put(player.getLevel().getFolderName(), new MessageType());
33 | }
34 | MessageType m = type.get(player.getLevel().getFolderName());
35 | BossMessageBuilder bossMessageBuilder = message.getBuilder();
36 | if (m.time == -2) {
37 | m.time = bossMessageBuilder.getTime();
38 | }
39 | if (m.time <= 0) {
40 | m.time = bossMessageBuilder.getTime();
41 | ++m.i;
42 | }
43 | if (m.i >= bossMessageBuilder.getStrings().size()) {
44 | m.i = 0;
45 | }
46 | String text = bossMessageBuilder.getStrings().get(m.i);
47 | text = Api.strReplace(text, player);
48 | BossBarApi.showBoss(player, text, bossMessageBuilder, m.time);
49 | m.time--;
50 | } else {
51 | BossBarApi.removeBossBar(player);
52 | }
53 | } else {
54 | BossBarApi.removeBossBar(player);
55 | }
56 | }
57 | }
58 |
59 | private static class MessageType {
60 | public int i = 0;
61 | public int time = -2;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/BroadCastPlayerTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import tip.messages.BaseMessage;
5 | import tip.messages.defaults.BroadcastMessage;
6 | import tip.utils.Api;
7 |
8 | import java.util.LinkedHashMap;
9 |
10 | /**
11 | * @author SmallasWater
12 | */
13 | public class BroadCastPlayerTask {
14 |
15 | private final Player player;
16 | private final LinkedHashMap type = new LinkedHashMap<>();
17 |
18 |
19 | public BroadCastPlayerTask(Player owner) {
20 | this.player = owner;
21 | }
22 |
23 | public void onRun() {
24 | if (player == null || !player.isOnline()) {
25 | return;
26 | }
27 | BroadcastMessage message = (BroadcastMessage) Api.getSendPlayerMessage(player.getName(), player.level.getFolderName(), BaseMessage.BaseTypes.BROADCAST);
28 | if (message != null && message.isOpen() && !message.getMessages().isEmpty()) {
29 | if (!type.containsKey(message)) {
30 | type.put(message, new MessageType());
31 | }
32 | MessageType m = type.get(message);
33 | if (m.time == -1) {
34 | m.time = message.getTime();
35 | m.key = true;
36 | } else if (m.time <= 0) {
37 | m.i++;
38 | m.time = message.getTime();
39 | m.key = true;
40 | }
41 | if (m.i >= message.getMessages().size()) {
42 | m.i = 0;
43 | }
44 | if (m.key) {
45 | m.key = false;
46 | String text = message.getMessages().get(m.i);
47 | player.sendMessage(Api.strReplace(text, player));
48 | }
49 | if (m.time > 0) {
50 | m.time--;
51 | }
52 | type.put(message, m);
53 | }
54 | }
55 |
56 | private static class MessageType {
57 | public int i = 0;
58 |
59 | public int time = -1;
60 |
61 | boolean key = false;
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/BroadCastTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.Server;
5 | import cn.nukkit.scheduler.PluginTask;
6 | import tip.Main;
7 |
8 | import java.util.LinkedHashMap;
9 |
10 |
11 | /**
12 | * @author SmallasWater
13 | */
14 | public class BroadCastTask {
15 |
16 |
17 | private Player player;
18 | private LinkedHashMap taskLinkedHashMap = new LinkedHashMap<>();
19 |
20 | public BroadCastTask(Player player) {
21 | this.player = player;
22 | }
23 |
24 | public void onRun() {
25 | if(!taskLinkedHashMap.containsKey(player.getName())){
26 | taskLinkedHashMap.put(player.getName(),new BroadCastPlayerTask(player));
27 | }
28 | BroadCastPlayerTask task = taskLinkedHashMap.get(player.getName());
29 | task.onRun();
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/MotdTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Server;
4 | import cn.nukkit.utils.TextFormat;
5 | import com.smallaswater.serverinfo.ServerInfoMainClass;
6 | import com.smallaswater.serverinfo.servers.ServerInfo;
7 | import tip.Main;
8 |
9 | import java.util.concurrent.ThreadLocalRandom;
10 |
11 |
12 | /**
13 | * @author SmallasWater
14 | * Create on 2020/12/2 19:06
15 | * Package tip.tasks
16 | */
17 | public class MotdTask extends BaseTipsRunnable {
18 |
19 | private boolean hasServerInfoPlugin = false;
20 |
21 | public MotdTask(Main owner) {
22 | super(owner);
23 |
24 | try {
25 | Class.forName("com.smallaswater.serverinfo.ServerInfoMainClass");
26 | this.hasServerInfoPlugin = true;
27 | }catch (Exception ignored){
28 |
29 | }
30 | }
31 |
32 | @Override
33 | public void run() {
34 | while (this.owner.isEnabled()) {
35 | String motd = this.owner.getMotd();
36 | String[] strings = new String[]{"§c", "§6", "§e", "§a", "§b", "§9", "§d", "§7", "§5"};
37 | motd = motd.replace("{online}", Server.getInstance().getOnlinePlayers().size() + "");
38 | motd = motd.replace("{maxplayer}", Server.getInstance().getMaxPlayers() + "");
39 | motd = motd.replace("{换行}", "\n");
40 | motd = motd.replace("{color}", strings[ThreadLocalRandom.current().nextInt(strings.length)]);
41 | int maxOnline = 0;
42 | if (this.hasServerInfoPlugin) {
43 | for (ServerInfo info : ServerInfoMainClass.getInstance().getServerInfos()) {
44 | if (info.onLine()) {
45 | maxOnline += info.getPlayer();
46 | motd = motd.replace("{ServerInfoPlayer@" + info.getCallback() + "}", String.valueOf(info.getPlayer()));
47 | motd = motd.replace("{ServerInfoMaxPlayer@" + info.getCallback() + "}", String.valueOf(info.getMaxPlayer()));
48 | } else {
49 | motd = motd.replace("{ServerInfoPlayer@" + info.getCallback() + "}", "服务器离线");
50 | motd = motd.replace("{ServerInfoMaxPlayer@" + info.getCallback() + "}", "服务器离线");
51 | }
52 |
53 | }
54 | motd = motd.replace("{ServerInfoPlayer}", maxOnline + "");
55 | }
56 |
57 | owner.getServer().getNetwork().setName(TextFormat.colorize('&', motd));
58 | try {
59 | Thread.sleep(getOwner().getConfig().getInt("自定义刷新刻度.motd", 20) * 50L);
60 | } catch (InterruptedException e) {
61 | e.printStackTrace();
62 | return;
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/NameTagTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import tip.messages.BaseMessage;
5 | import tip.messages.defaults.NameTagMessage;
6 | import tip.utils.Api;
7 |
8 | /**
9 | * @author SmallasWater
10 | */
11 | public class NameTagTask {
12 |
13 | private Player player;
14 |
15 | public NameTagTask(Player player) {
16 |
17 | this.player = player;
18 | }
19 |
20 | public void onRun() {
21 | if (player == null || !player.isOnline()) {
22 | return;
23 | }
24 | NameTagMessage nameTagMessage = (NameTagMessage) Api.getSendPlayerMessage(player.getName(), player.level.getFolderName(), BaseMessage.BaseTypes.NAME_TAG);
25 | if (nameTagMessage != null) {
26 | if (nameTagMessage.isOpen()) {
27 | player.setNameTag(Api.strReplace(nameTagMessage.getMessage(), player));
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/ScoreBoardTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.lanink.gamecore.GameCore;
4 | import cn.lanink.gamecore.scoreboard.ScoreboardUtil;
5 | import cn.lanink.gamecore.scoreboard.base.IScoreboard;
6 | import cn.lanink.gamecore.scoreboard.ltname.SimpleScoreboard;
7 | import cn.nukkit.Player;
8 | import cn.nukkit.utils.TextFormat;
9 | import tip.Main;
10 | import tip.messages.BaseMessage;
11 | import tip.messages.defaults.ScoreBoardMessage;
12 | import tip.utils.Api;
13 |
14 |
15 | import java.util.ArrayList;
16 | import java.util.LinkedList;
17 |
18 |
19 | /**
20 | * @author 若水
21 | */
22 | public class ScoreBoardTask {
23 |
24 | private final Player player;
25 | private final Main main;
26 | private IScoreboard scoreboard = null;
27 |
28 | public ScoreBoardTask(Player player,Main main) {
29 | this.player = player;
30 | this.main = main;
31 |
32 | try {
33 | Class.forName("cn.lanink.gamecore.scoreboard.ScoreboardUtil");
34 | scoreboard = ScoreboardUtil.getScoreboard();
35 | } catch (Exception ignored) {
36 |
37 | }
38 | }
39 |
40 | private Main getOwner() {
41 | return main;
42 | }
43 |
44 | public void onRun() {
45 | if (this.scoreboard == null) {
46 | return;
47 | }
48 | // for (Player player : Server.getInstance().getOnlinePlayers().values()) {
49 | if (player == null || !player.isOnline()) {
50 | return;
51 | }
52 | ScoreBoardMessage message = (ScoreBoardMessage) Api.getSendPlayerMessage(player.getName(), player.level.getFolderName(), BaseMessage.BaseTypes.SCORE_BOARD);
53 | if (message == null || !message.isOpen()) {
54 | if (getOwner().scoreboards.contains(player)) {
55 | this.scoreboard.closeScoreboard(player);
56 | getOwner().scoreboards.remove(player);
57 | }
58 | return;
59 | }
60 |
61 | if (player.isOnline()) {
62 | try {
63 | String title = Api.strReplace(message.getTitle(), player);
64 | ArrayList list = new ArrayList<>();
65 | for (String ms : message.getMessages()) {
66 | list.add(Api.strReplace(ms, player));
67 | }
68 | this.scoreboard.showScoreboard(player, title, list);
69 | Main.getInstance().scoreboards.add(player);
70 | } catch (Exception ignored) {
71 | }
72 | }
73 | // }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/tip/tasks/TipTask.java:
--------------------------------------------------------------------------------
1 | package tip.tasks;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.Server;
5 | import com.google.common.cache.Cache;
6 | import com.google.common.cache.CacheBuilder;
7 | import tip.Main;
8 | import tip.utils.SendPlayerClass;
9 |
10 | import java.util.concurrent.TimeUnit;
11 |
12 | /**
13 | * @author 若水
14 | */
15 | public class TipTask extends BaseTipsRunnable {
16 |
17 | private static final Cache sendPlayerClassCache = CacheBuilder.newBuilder()
18 | .expireAfterAccess(1, TimeUnit.MINUTES)
19 | .build();
20 |
21 | private final int sleep;
22 |
23 | public TipTask(Main owner, int sleep) {
24 | super(owner);
25 | this.sleep = sleep * 50;
26 | }
27 |
28 | @Override
29 | public void run() {
30 | while (this.owner.isEnabled()) {
31 | for (Player player : Server.getInstance().getOnlinePlayers().values()) {
32 | try {
33 | SendPlayerClass sendPlayerClass;
34 | if ((sendPlayerClass = sendPlayerClassCache.getIfPresent(player)) == null) {
35 | sendPlayerClass = new SendPlayerClass(player, getOwner());
36 | sendPlayerClassCache.put(player, sendPlayerClass);
37 | }
38 | sendPlayerClass.init();
39 | } catch (Exception e) {
40 | e.printStackTrace();
41 | }
42 | }
43 | try {
44 | Thread.sleep(sleep);
45 | } catch (InterruptedException e) {
46 | e.printStackTrace();
47 | return;
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/Api.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 | import cn.nukkit.IPlayer;
4 | import cn.nukkit.Player;
5 | import cn.nukkit.Server;
6 | import cn.nukkit.level.Level;
7 | import cn.nukkit.utils.TextFormat;
8 | import org.jetbrains.annotations.NotNull;
9 | import tip.Main;
10 | import tip.messages.BaseMessage;
11 | import tip.messages.defaults.MessageManager;
12 | import tip.utils.variables.BaseVariable;
13 | import tip.utils.variables.VariableManager;
14 |
15 | import java.lang.reflect.Constructor;
16 | import java.util.*;
17 |
18 | /**
19 | * @author 若水
20 | * Tips变量
21 | */
22 | public final class Api {
23 |
24 | @Deprecated
25 | private final String string;
26 | @Deprecated
27 | private final IPlayer player;
28 |
29 | private static final LinkedHashMap> VARIABLE = new LinkedHashMap<>();
30 |
31 | @Deprecated
32 | public Api(String string, IPlayer player) {
33 | this.string = string;
34 | this.player = player;
35 | }
36 |
37 | @Deprecated
38 | public String strReplace() {
39 | String m = string;
40 | m = Main.getInstance().getVarManager().toMessage((Player) player, m);
41 |
42 | return TextFormat.colorize('&', m);
43 | }
44 |
45 | public static void registerVariables(String name, Class extends BaseVariable> variable) {
46 | if (VARIABLE.containsKey(name)) {
47 | return;
48 | }
49 | VARIABLE.put(name, variable);
50 | Main.getInstance().setVarManager(flush(variable));
51 | }
52 |
53 | private static VariableManager flush(Class extends BaseVariable> var) {
54 | VariableManager varManager = Main.getInstance().getVarManager();
55 | if (Main.getInstance().getVarManager() == null) {
56 | varManager = new VariableManager();
57 | }
58 | BaseVariable variable = Api.initVariable(var);
59 | if (variable != null) {
60 | varManager.addVariableClass(variable);
61 | }
62 | return varManager;
63 | }
64 |
65 | private static BaseVariable initVariable(Class extends BaseVariable> var) {
66 | BaseVariable variable = null;
67 | for (Constructor> constructor : var.getConstructors()) {
68 | try {
69 | if (constructor.getParameterCount() == 1) {
70 | variable = (BaseVariable) constructor.newInstance((Object) null);
71 | } else {
72 | variable = (BaseVariable) constructor.newInstance((Object) null, null);
73 | }
74 | } catch (Exception e) {
75 | e.printStackTrace();
76 | return null;
77 | }
78 | }
79 | return variable;
80 | }
81 |
82 | public static String strReplace(@NotNull String string, Player player) {
83 | return TextFormat.colorize('&', Main.getInstance().getVarManager().toMessage(player, string));
84 | }
85 |
86 | /**
87 | * 增加单个变量
88 | */
89 | public static void addVariable(@NotNull String var, @NotNull String message) {
90 | Main.getInstance().getVarManager().addVariable(var, message);
91 | }
92 |
93 | public static BaseMessage getSendPlayerMessage(String playerName, String levelName, BaseMessage.BaseTypes baseTypes) {
94 | PlayerConfig config = Main.getInstance().getPlayerConfig(playerName);
95 | BaseMessage message = null;
96 | if (config != null) {
97 | message = config.getMessage(levelName, baseTypes.getType());
98 | }
99 | if (message == null) {
100 | message = getLevelDefaultMessage(levelName, baseTypes);
101 | }
102 |
103 | return message;
104 | }
105 |
106 | public static BaseMessage getLevelDefaultMessage(String levelName, BaseMessage.BaseTypes baseTypes) {
107 | return Main.getInstance().getShowMessages().getMessageByTypeAndWorld(levelName, baseTypes.getType());
108 | }
109 |
110 | public static void setLevelMessage(BaseMessage message) {
111 | Main.getInstance().getShowMessages().setMessage(message);
112 | }
113 |
114 | public static LinkedList getSettingLevels() {
115 | LinkedList linkedList = new LinkedList<>();
116 | linkedList.add("default");
117 | for (Level level : Server.getInstance().getLevels().values()) {
118 | if (!"default".equalsIgnoreCase(level.getFolderName())) {
119 | linkedList.add(level.getFolderName());
120 | }
121 | }
122 | return linkedList;
123 | }
124 |
125 | public static void setPlayerShowMessage(String playerName, BaseMessage message) {
126 | PlayerConfig config = Main.getInstance().getPlayerConfigInit(playerName);
127 | config.setMessage(message);
128 | }
129 |
130 | public static void removePlayerShowMessage(String playerName, BaseMessage message) {
131 | PlayerConfig config = Main.getInstance().getPlayerConfig(playerName);
132 | if (config == null) {
133 | config = new PlayerConfig(playerName, new MessageManager(), Main.getInstance().getTheme());
134 | }
135 | if (config.messages.contains(message)) {
136 | config.removeMessage(message);
137 | }
138 | if (config.messages.isEmpty()) {
139 | Main.getInstance().getPlayerConfigs().remove(config);
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/BossMessageBuilder.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 |
4 | import cn.nukkit.utils.BossBarColor;
5 |
6 | import java.util.LinkedList;
7 |
8 | /**
9 | * @author 若水
10 | */
11 | public class BossMessageBuilder {
12 |
13 | private int time;
14 |
15 | private LinkedList strings;
16 |
17 | private boolean health;
18 |
19 | private BossBarColor bossBarColor;
20 |
21 | public BossMessageBuilder(LinkedList strings,int time,boolean health){
22 | this(strings, time, health, BossBarColor.GREEN);
23 | }
24 |
25 | public BossMessageBuilder(LinkedList strings, int time, boolean health, BossBarColor bossBarColor){
26 | this.time = time;
27 | this.strings = strings;
28 | this.health = health;
29 | this.bossBarColor = bossBarColor;
30 | }
31 |
32 | public int getTime() {
33 | return time;
34 | }
35 |
36 | public LinkedList getStrings() {
37 | return strings;
38 | }
39 |
40 | public boolean isHealth() {
41 | return health;
42 | }
43 |
44 | public BossBarColor getBossBarColor() {
45 | return bossBarColor;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/GameCoreDownload.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 | import cn.lanink.gamecore.utils.VersionUtils;
4 | import cn.nukkit.Server;
5 | import cn.nukkit.math.NukkitMath;
6 | import cn.nukkit.plugin.Plugin;
7 | import com.google.common.util.concurrent.AtomicDouble;
8 | import tip.Main;
9 |
10 | import java.io.*;
11 | import java.net.HttpURLConnection;
12 | import java.net.URL;
13 | import java.net.URLClassLoader;
14 | import java.net.URLDecoder;
15 | import java.util.Arrays;
16 | import java.util.Collections;
17 | import java.util.List;
18 | import java.util.concurrent.ForkJoinPool;
19 | import java.util.concurrent.RecursiveAction;
20 | import java.util.concurrent.TimeUnit;
21 | import java.util.concurrent.atomic.AtomicLong;
22 | import java.util.function.BiConsumer;
23 | import java.util.function.Consumer;
24 |
25 | /**
26 | * 自动下载GameCore依赖工具类
27 | */
28 | public class GameCoreDownload {
29 |
30 | private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36";
31 |
32 | // 每个任务下载 128 kb数据
33 | private static final int THRESHOLD = 128 * 1024;
34 |
35 | public static final String MINIMUM_GAME_CORE_VERSION = "1.6.9";
36 | private static String ACTUAL_MINIMUM_GAME_CORE_VERSION;
37 |
38 | private static final String MAVEN_URL_CENTRAL = "https://repo1.maven.org/maven2/";
39 | private static final String MAVEN_URL_HUAWEI = "https://repo.huaweicloud.com/repository/maven/";
40 | private static final String MAVEN_URL_LANINK = "https://repo.lanink.cn/repository/maven-public/";
41 |
42 | private static final List GAME_CORE_URL_LIST;
43 |
44 | static {
45 | //为了防止编译依赖和实际环境区别,这里重新检查GameCore完整版本号
46 | ACTUAL_MINIMUM_GAME_CORE_VERSION = MINIMUM_GAME_CORE_VERSION.split("-")[0];
47 | String codename = Server.getInstance().getCodename();
48 | if ("PowerNukkitX".equalsIgnoreCase(codename)/* || "PowerNukkit".equalsIgnoreCase(codename)*/) {
49 | ACTUAL_MINIMUM_GAME_CORE_VERSION += "-PNX";
50 | } else if ("PM1E".equalsIgnoreCase(codename)) {
51 | ACTUAL_MINIMUM_GAME_CORE_VERSION += "-PM1E";
52 | }
53 |
54 | GAME_CORE_URL_LIST = Collections.unmodifiableList(Arrays.asList(
55 | getGameCoreUrl(MAVEN_URL_CENTRAL),
56 | getGameCoreUrl(MAVEN_URL_HUAWEI),
57 | getGameCoreUrl(MAVEN_URL_LANINK)
58 | ));
59 | }
60 |
61 | private static String getGameCoreUrl(String mavenUrl) {
62 | //插件完整下载地址
63 | return mavenUrl + "cn/lanink/MemoriesOfTime-GameCore/" + ACTUAL_MINIMUM_GAME_CORE_VERSION + "/MemoriesOfTime-GameCore-" + ACTUAL_MINIMUM_GAME_CORE_VERSION + ".jar";
64 | }
65 |
66 | private GameCoreDownload() {
67 | throw new RuntimeException("error");
68 | }
69 |
70 | /**
71 | * 检查并下载GameCore依赖
72 | *
73 | * @return 0 - GameCore已加载且是最新版本 1 - 无法下载GameCore 2 下载成功
74 | */
75 | public static int checkAndDownload() {
76 | return checkAndDownload(0);
77 | }
78 |
79 | /**
80 | * 检查并下载GameCore依赖
81 | *
82 | * @param retry 重试次数(下载链接序号)
83 | * @return 0 - GameCore已加载且是最新版本 1 - 无法下载GameCore 2 下载成功
84 | */
85 | private static int checkAndDownload(int retry) {
86 | if (retry >= GAME_CORE_URL_LIST.size()) {
87 | return 1;
88 | }
89 | String url = GAME_CORE_URL_LIST.get(retry);
90 |
91 | Plugin plugin = Server.getInstance().getPluginManager().getPlugin("MemoriesOfTime-GameCore");
92 |
93 | if (plugin != null) {
94 | if (!VersionUtils.checkMinimumVersion(plugin, ACTUAL_MINIMUM_GAME_CORE_VERSION)) {
95 | Main.getInstance().getLogger().warning("MemoriesOfTime-GameCore依赖版本太低!正在尝试更新版本...");
96 | File file = getPluginFile(plugin);
97 | if (file != null) {
98 | Server.getInstance().getPluginManager().disablePlugin(plugin);
99 | ClassLoader classLoader = plugin.getClass().getClassLoader();
100 | try {
101 | if (classLoader instanceof URLClassLoader) {
102 | ((URLClassLoader) classLoader).close();
103 | }
104 | } catch (IOException ignored) {
105 |
106 | }
107 | file.delete();
108 | }else {
109 | Main.getInstance().getLogger().error("删除旧版本失败!请手动删除!");
110 | }
111 | }
112 | }
113 |
114 | if (plugin == null || plugin.isDisabled()) {
115 | Main.getInstance().getLogger().info("尝试从 " + url + " 下载 MemoriesOfTime-GameCore 中...");
116 |
117 | File file = new File(Server.getInstance().getFilePath() + "/plugins/MemoriesOfTime-GameCore-" + ACTUAL_MINIMUM_GAME_CORE_VERSION + ".jar");
118 |
119 | try {
120 | AtomicDouble last = new AtomicDouble(-16);
121 | download(url, file, (len, fullLength) -> {
122 | double d = NukkitMath.round(len * 1.0 / fullLength * 100, 2);
123 | if (d - last.get() > 15) { // 每15%提示一次
124 | Main.getInstance().getLogger().info("已下载:" + d + "%");
125 | last.set(d);
126 | }
127 | });
128 | } catch (Exception e) {
129 | Main.getInstance().getLogger().error("MemoriesOfTime-GameCore依赖下载失败!");
130 | return checkAndDownload(++retry);
131 | }
132 |
133 | Main.getInstance().getLogger().info("MemoriesOfTime-GameCore依赖下载成功!");
134 | Server.getInstance().getPluginManager().loadPlugin(file);
135 | return 2;
136 | }
137 | return 0;
138 | }
139 |
140 | public static File getPluginFile(Plugin plugin) {
141 | File file = null;
142 | ClassLoader PluginClass = plugin.getClass().getClassLoader();
143 | try {
144 | if (PluginClass instanceof URLClassLoader) {
145 | URLClassLoader pluginClass = (URLClassLoader) PluginClass;
146 | URL url = pluginClass.getURLs()[0];
147 | file = new File(URLDecoder.decode(url.getFile(), "UTF-8"));
148 | }
149 | } catch (UnsupportedEncodingException ignored) {
150 |
151 | }
152 | return file;
153 | }
154 |
155 | /**
156 | * 下载
157 | *
158 | * @param strUrl 目标url
159 | * @param saveFile 保存到文件
160 | * @param callback 下载完的回调
161 | */
162 | private static void download(String strUrl, File saveFile, BiConsumer callback) throws Exception {
163 | URL url = new URL(strUrl);
164 | HttpURLConnection connection = ((HttpURLConnection) url.openConnection());
165 | connection.setRequestMethod("GET");
166 | connection.setRequestProperty("Connection", "keep-alive");
167 | connection.setRequestProperty("Accept", "*/*");
168 | connection.setRequestProperty("User-Agent", USER_AGENT);
169 | connection.setReadTimeout(5000);
170 |
171 |
172 | long fullLength = connection.getContentLength();
173 | if ("chunked".equals(connection.getHeaderField("Transfer-Encoding"))) { // chunked transfer 采用单线程下载
174 | RandomAccessFile out = new RandomAccessFile(saveFile, "rw");
175 | out.seek(0);
176 | byte[] b = new byte[1024];
177 | InputStream in = connection.getInputStream();
178 | int read;
179 | long count = 0;
180 | while ((read = in.read(b)) >= 0) {
181 | out.write(b, 0, read);
182 | count += read;
183 | if (callback != null) {
184 | callback.accept(count, fullLength);
185 | }
186 | }
187 | in.close();
188 | out.close();
189 | return;
190 | }
191 | ForkJoinPool pool = new ForkJoinPool();
192 | AtomicLong atomicLong = new AtomicLong();
193 | pool.submit(new DownloadTask(strUrl,0, fullLength, saveFile, (l) -> {
194 | atomicLong.addAndGet(l);
195 | callback.accept(atomicLong.get(), fullLength);
196 | }));
197 | pool.shutdown();
198 | // 同步 等待所有线程完成操作
199 | while (!pool.awaitTermination(1, TimeUnit.SECONDS)) {
200 | }
201 | if (fullLength < 1 || saveFile.length() < 1) {
202 | throw new Exception("下载失败");
203 | }
204 | }
205 |
206 | private static class DownloadTask extends RecursiveAction {
207 |
208 | private final String strUrl;
209 | private final File file;
210 | private final long start;
211 | private final long end;
212 |
213 | private final Consumer callback;
214 |
215 | public DownloadTask(String strUrl, long start, long end, File file, Consumer callback) {
216 | this.strUrl = strUrl;
217 | this.start = start;
218 | this.end = end;
219 | this.file = file;
220 | this.callback = callback;
221 | }
222 |
223 | @Override
224 | protected void compute() {
225 | RandomAccessFile out = null;
226 | InputStream in = null;
227 | try {
228 | long l = end - start;
229 | if (l < THRESHOLD) {
230 | HttpURLConnection connection = getConnection();
231 | connection.setRequestProperty("Range", "bytes=" + start + "-" + end);
232 |
233 | out = new RandomAccessFile(file, "rw");
234 | out.seek(start);
235 | in = connection.getInputStream();
236 | byte[] b = new byte[1024];
237 | int len;
238 | while ((len = in.read(b)) >= 0) {
239 | out.write(b, 0, len);
240 | callback.accept(len);
241 | }
242 | in.close();
243 | out.close();
244 | } else {
245 | long mid = (start + end) / 2;
246 | new SubDownloadTask(strUrl, start, mid, file, callback).fork();
247 | new SubDownloadTask(strUrl, mid, end, file, callback).fork();
248 | }
249 | } catch (Exception e) {
250 | throw new RuntimeException(e);
251 | } finally {
252 | if (out != null) {
253 | try {
254 | out.close();
255 | } catch (IOException e) {
256 | e.printStackTrace();
257 | }
258 | }
259 | if (in != null) {
260 | try {
261 | in.close();
262 | } catch (IOException e) {
263 | e.printStackTrace();
264 | }
265 | }
266 | }
267 | }
268 |
269 | public HttpURLConnection getConnection() throws IOException {
270 | HttpURLConnection connection = (HttpURLConnection) new URL(strUrl).openConnection();
271 | connection.setReadTimeout(5000);
272 | connection.setRequestMethod("GET");
273 | connection.setRequestProperty("Connection", "keep-alive");
274 | connection.setRequestProperty("Accept", "*/*");
275 | connection.setRequestProperty("User-Agent", USER_AGENT);
276 |
277 | return connection;
278 | }
279 | }
280 |
281 | private static class SubDownloadTask extends DownloadTask {
282 |
283 | public SubDownloadTask(String strUrl, long start, long end, File file, Consumer callback) {
284 | super(strUrl, start, end, file, callback);
285 | }
286 |
287 | }
288 |
289 | }
290 |
291 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/OnListener.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 | import cn.nukkit.Player;
4 | import cn.nukkit.Server;
5 | import cn.nukkit.event.EventHandler;
6 | import cn.nukkit.event.EventPriority;
7 | import cn.nukkit.event.Listener;
8 | import cn.nukkit.event.player.PlayerChatEvent;
9 | import cn.nukkit.event.player.PlayerJoinEvent;
10 | import cn.nukkit.event.player.PlayerQuitEvent;
11 | import cn.nukkit.event.player.PlayerRespawnEvent;
12 | import tip.Main;
13 | import tip.bossbar.BossBarApi;
14 | import tip.messages.BaseMessage;
15 | import tip.messages.defaults.ChatMessage;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * @author 若水
21 | */
22 | public class OnListener implements Listener {
23 |
24 | @EventHandler
25 | public void onJoin(PlayerJoinEvent event) {
26 | Main.getInstance().loadPlayerConfig(event.getPlayer());
27 |
28 | }
29 |
30 | @EventHandler
31 | public void onQuit(PlayerQuitEvent event) {
32 | Player player = event.getPlayer();
33 | PlayerConfig config = Main.getInstance().getPlayerConfig(player.getName());
34 | if (config != null) {
35 | config.save();
36 | Main.getInstance().getPlayerConfigs().remove(config);
37 | }
38 |
39 | BossBarApi.removeBossBar(player);
40 | Main.getInstance().apis.remove(player);
41 | }
42 |
43 | @EventHandler
44 | public void onPlayerRespawn(PlayerRespawnEvent event) {
45 | BossBarApi.removeBossBar(event.getPlayer());
46 | }
47 |
48 | private String getBadWorld(String msg, List badWords) {
49 | for (Object badWord : badWords) {
50 | if (msg.contains((String) badWord)) {
51 | msg = msg.replace((String) badWord, "*");
52 | }
53 | }
54 | return msg;
55 | }
56 |
57 |
58 | @EventHandler(priority = EventPriority.HIGH)
59 | public void onChat(PlayerChatEvent event) {
60 | if (event.isCancelled()) {
61 | return;
62 | }
63 | Player player = event.getPlayer();
64 | String msg = event.getMessage();
65 |
66 | ChatMessage message = (ChatMessage) Main.getInstance().getShowMessages().getMessageByTypeAndWorld(player.level.getFolderName()
67 | , BaseMessage.CHAT_MESSAGE_TYPE);
68 | PlayerConfig config = Main.getInstance().getPlayerConfig(player.getName());
69 | if (config != null) {
70 | if (config.getMessage(player.getLevel().getFolderName(), BaseMessage.CHAT_MESSAGE_TYPE) != null) {
71 | message = (ChatMessage) config.getMessage(player.getLevel().getFolderName(), BaseMessage.CHAT_MESSAGE_TYPE);
72 | }
73 | }
74 | if (message != null) {
75 | String s = message.getMessage();
76 | if (!message.isOpen()) {
77 | return;
78 | }
79 | if (!"".equals(s)) {
80 | String send = Api.strReplace(s, player).replace("{msg}", msg);
81 | if (message.isInWorld()) {
82 | for (Player player1 : player.getLevel().getPlayers().values()) {
83 | player1.sendMessage(send);
84 | }
85 | } else {
86 | Server.getInstance().broadcastMessage(send);
87 | }
88 | }
89 | event.setCancelled();
90 | }
91 |
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/PlayerConfig.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 | import cn.nukkit.utils.Config;
4 | import tip.Main;
5 | import tip.messages.BaseMessage;
6 | import tip.messages.defaults.MessageManager;
7 |
8 | import java.util.LinkedHashMap;
9 |
10 | /**
11 | * @author SmallasWater
12 | */
13 | public class PlayerConfig {
14 |
15 | public MessageManager messages;
16 |
17 | private String playerName;
18 |
19 | public PlayerConfig(String playerName,MessageManager baseMessages,String theme){
20 | this.playerName = playerName;
21 | this.messages = baseMessages;
22 | this.theme = theme;
23 | }
24 |
25 |
26 | private String theme;
27 |
28 |
29 |
30 | public String getPlayerName() {
31 | return playerName;
32 | }
33 |
34 | public void addMessage(BaseMessage message){
35 | messages.add(message);
36 | }
37 |
38 |
39 | public void setTheme(String theme) {
40 | this.theme = theme;
41 | }
42 |
43 | public void removeMessage(BaseMessage message){
44 | messages.remove(message);
45 | }
46 |
47 | public void setMessage(BaseMessage message){
48 | messages.setMessage(message);
49 |
50 | }
51 |
52 | public BaseMessage getMessageNewInstance(String levelName,int type,boolean create){
53 | BaseMessage message = messages.getMessageByTypeAndWorld(levelName, type);
54 | if(message == null){
55 | if(theme != null){
56 | MessageManager message1 = Main.getInstance().getThemeManager().get(theme);
57 | if(message1 != null){
58 | message = message1.getMessageByTypeAndWorld(levelName, type);
59 | }
60 | }
61 | }
62 | if(message == null && create){
63 | message = Main.getInstance().getThemeManager()
64 | .getDefaultManager().getMessageByTypeAndWorld(levelName,type);
65 | if(message != null){
66 | message = message.clone();
67 | }
68 | }
69 | return message;
70 | }
71 |
72 | public BaseMessage getMessage(String levelName,int type){
73 | return getMessageNewInstance(levelName,type,false);
74 | }
75 |
76 |
77 | public MessageManager getMessages() {
78 | return messages;
79 | }
80 |
81 | public void save(){
82 | Config config = new Config(Main.getInstance().getDataFolder()+"/Players/"+playerName+".yml",2);
83 | LinkedHashMap map = new LinkedHashMap<>();
84 | map.put("样式",theme);
85 | map.putAll(messages.saveConfig());
86 | config.setAll(map);
87 | config.save();
88 | }
89 |
90 | @Override
91 | public boolean equals(Object obj) {
92 | if(obj instanceof PlayerConfig){
93 | return ((PlayerConfig) obj).playerName.equals(playerName);
94 | }
95 | return false;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/SendPlayerClass.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 | import cn.nukkit.Player;
4 | import tip.Main;
5 | import tip.messages.BaseMessage;
6 | import tip.messages.defaults.TipMessage;
7 | import tip.tasks.BossBarAllPlayerTask;
8 | import tip.tasks.BroadCastTask;
9 | import tip.tasks.NameTagTask;
10 | import tip.tasks.ScoreBoardTask;
11 |
12 | /**
13 | * @author SmallasWater
14 | * Create on 2021/1/29 21:49
15 | * Package tip.utils
16 | */
17 | public class SendPlayerClass {
18 |
19 | private BossBarAllPlayerTask bossTask;
20 |
21 | private BroadCastTask broadtask;
22 |
23 | private NameTagTask nametask;
24 |
25 | private ScoreBoardTask scoreTask;
26 |
27 | private Player player;
28 | private Main main;
29 | public SendPlayerClass(Player player,Main main){
30 | this.player = player;
31 | this.main = main;
32 |
33 | }
34 |
35 | private Main getOwner() {
36 | return main;
37 | }
38 |
39 | public void init(){
40 | if(player == null || !player.isOnline()){
41 | return;
42 | }
43 | TipMessage tipMessage;
44 | tipMessage = (TipMessage) Api.getSendPlayerMessage(player.getName(),player.level.getFolderName(),
45 | BaseMessage.BaseTypes.TIP);
46 | if (tipMessage != null) {
47 | if (tipMessage.isOpen()) {
48 | sendTip(player, Api.strReplace(tipMessage.getMessage(), player), tipMessage.getShowType());
49 | }
50 | }
51 | if(bossTask == null){
52 | bossTask = new BossBarAllPlayerTask(player);
53 | }
54 | bossTask.onRun();
55 | if(broadtask == null){
56 | broadtask = new BroadCastTask(player);
57 | }
58 | broadtask.onRun();
59 | if(nametask == null){
60 | nametask = new NameTagTask(player);
61 | }
62 | nametask.onRun();
63 | if(scoreTask == null){
64 | scoreTask = new ScoreBoardTask(player,getOwner());
65 | }
66 | scoreTask.onRun();
67 |
68 | }
69 |
70 | private void sendTip(Player player,String tip,int type){
71 | switch (type){
72 | case TipMessage.POPUP:
73 | player.sendPopup(tip);
74 | break;
75 | case TipMessage.ACTION:
76 | player.sendActionBar(tip);
77 | break;
78 | default:
79 | player.sendTip(tip);
80 | break;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/ThemeManager.java:
--------------------------------------------------------------------------------
1 | package tip.utils;
2 |
3 | import cn.nukkit.utils.Config;
4 | import tip.messages.defaults.MessageManager;
5 |
6 | import java.util.LinkedHashMap;
7 | import java.util.LinkedList;
8 |
9 | /**
10 | * @author SmallasWater
11 | */
12 | public class ThemeManager extends LinkedHashMap {
13 |
14 |
15 | private LinkedHashMap configs = new LinkedHashMap<>();
16 |
17 | public MessageManager put(String key, MessageManager value,Config config) {
18 | configs.put(key,config);
19 | return super.put(key, value);
20 | }
21 |
22 | public LinkedList getNames() {
23 | return new LinkedList<>(configs.keySet());
24 | }
25 |
26 |
27 | public LinkedList getConfigs() {
28 | return new LinkedList<>(configs.values());
29 | }
30 |
31 | public Config getConfig(String theme) {
32 | return configs.getOrDefault(theme,null);
33 | }
34 |
35 | public MessageManager getDefaultManager(){
36 | return getOrDefault("default",null);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/tip/utils/variables/ASMTemplateCompiler.java:
--------------------------------------------------------------------------------
1 | package tip.utils.variables;
2 |
3 | import org.objectweb.asm.*;
4 |
5 | import java.util.Map;
6 | import java.util.concurrent.ConcurrentHashMap;
7 | import java.util.function.Function;
8 | import java.util.regex.Pattern;
9 |
10 | import static org.objectweb.asm.Opcodes.*;
11 |
12 | public final class ASMTemplateCompiler {
13 |
14 | private static final Pattern variablePattern = Pattern.compile("\\{([^}]+)}");
15 |
16 | private static final Map, String>> templateCache = new ConcurrentHashMap<>();
17 |
18 | private ASMTemplateCompiler() {
19 |
20 | }
21 |
22 | public static String strReplace(String template, Map variables) {
23 | // 调用模板函数,进行替换
24 | Function