mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-29 06:34:17 +02:00
Compare commits
84 Commits
v1.0.0
..
2bccf45439
| Author | SHA1 | Date | |
|---|---|---|---|
|
2bccf45439
|
|||
|
24da79642a
|
|||
|
ea54f83909
|
|||
|
6c76066d8b
|
|||
|
823093be35
|
|||
|
fecd21bf19
|
|||
|
fc8c1c9f26
|
|||
|
f7f541c8a4
|
|||
|
a8f836d94c
|
|||
|
fcd2a513aa
|
|||
|
5c4feea042
|
|||
|
c4e1aedeca
|
|||
|
7907ee87f6
|
|||
|
041c541356
|
|||
|
dcb52e3e6d
|
|||
|
53df1a908a
|
|||
| 3317e2fffd | |||
| 4b52f74fc5 | |||
| 4ef2700d6b | |||
| 7826c4e75a | |||
| c4953d2acb | |||
| 7e3139126c | |||
| 2be16da939 | |||
| a17086b059 | |||
| 039b40bd53 | |||
| a69c7cb426 | |||
| 8a147eb7cf | |||
| ecdd688a79 | |||
| 26166b5a73 | |||
| 27a1fd8244 | |||
| 66c113bad2 | |||
| d863622168 | |||
| 361f66f645 | |||
| fbaaa6ec89 | |||
| 955ab8791a | |||
| 8128628b12 | |||
| 02570993a7 | |||
| 0d095c40f0 | |||
| 8df1029d42 | |||
| 2f66c6f12c | |||
| 1f9758f3d0 | |||
| c7502fd661 | |||
| 1a9cf76a93 | |||
| b3ec076cae | |||
| 3cb3314f4c | |||
| fb785fb53a | |||
| e44f6489af | |||
| faa2eb0a43 | |||
| 8c00347ef2 | |||
| 8de4382ec4 | |||
| a7c487decd | |||
| 22f42df1da | |||
| 7e90939b84 | |||
| 5c5eee0bca | |||
| d7560d5ef3 | |||
| ce8a8a44cd | |||
| 7902bb9a46 | |||
| b40e543f9e | |||
| ab037716c4 | |||
| 56aef4a2c9 | |||
| 755b758b2f | |||
| 4392456b15 | |||
| 0db57042af | |||
| 57b21c2e1f | |||
| 4266b7ebb6 | |||
| a46e00a68d | |||
| bad8a4bb90 | |||
| 05c41dc4c3 | |||
| bf476c7a4b | |||
| d93a9aa9e4 | |||
| 7d94c782b8 | |||
| d8ff58191f | |||
| e2a344d92c | |||
| 1f91b2aa4e | |||
| 2b5a089a86 | |||
| 8698d7991d | |||
| 121d736468 | |||
| 762629e263 | |||
| 95f1814588 | |||
| 9ca54567b2 | |||
| 7eeb6daa46 | |||
| e54f88fa5e | |||
| 1631f3bd32 | |||
| b9a7f23af2 |
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -3,55 +3,30 @@
|
|||||||
|
|
||||||
SModeration can be used to mute, ban, and kick players that break the rules while providing a nice interface to your moderators.
|
SModeration can be used to mute, ban, and kick players that break the rules while providing a nice interface to your moderators.
|
||||||
It keeps track of all punishments to ensure that you get a complete overview of every rule violation on your server.
|
It keeps track of all punishments to ensure that you get a complete overview of every rule violation on your server.
|
||||||
|
You can also modify player inventories and ender chests.
|
||||||
|
|
||||||
If you have any feature requests, please [open an issue](https://github.com/Shiewk/SModeration/issues).
|
If you have any feature requests, please [open an issue](https://github.com/Shiewk/SModeration/issues).
|
||||||
|
|
||||||
## The SMod menu
|
## The SMod menu
|
||||||

|

|
||||||
|
|
||||||
SModeration provides a nice user interface that can be used instead of chat commands.
|
SModeration provides a nice user interface that can be used instead of chat commands.
|
||||||

|
|
||||||
It has helpful functions like filtering and sorting options.
|

|
||||||
|
|
||||||
|
It has helpful functions like filtering, searching and sorting options.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
### /smod
|
This plugin has many commands, for a complete list of commands and their usage, please see [the commands list](https://github.com/Shiewk/SModeration/blob/main/docs/commands.md).
|
||||||
The /smod command just opens the SMod menu. It takes no arguments.
|
The most important ones are:
|
||||||
### /mute
|
- /mute
|
||||||
The /mute command is used to mute players.
|
- /ban
|
||||||
|
- /kick
|
||||||
|
- /smod
|
||||||
|
- /unmute & /unban
|
||||||
|
- /invsee & /enderchestsee
|
||||||
|
- /vanish
|
||||||
|
|
||||||
It requires 2 arguments:
|
|
||||||
- Player name
|
|
||||||
- Duration
|
|
||||||
|
|
||||||
If you want to, you can also add a **reason**.
|
|
||||||
|
|
||||||
For example, if you want to mute a player for breaking server rules, just use **/mute playername 1h 30min Breaking server rules.**
|
|
||||||
|
|
||||||
The player will be muted for 1 hour and 30 minutes with the reason "Breaking server rules.".
|
|
||||||
|
|
||||||
Muted players can still join the server, but can't use the chat.
|
|
||||||
### /ban
|
|
||||||
The /ban command works the same as the /mute command, with one important difference:
|
|
||||||
|
|
||||||
Banned players **can't even join** the server until the ban expires.
|
|
||||||
### /kick
|
|
||||||
The /kick command is a bit different. It does not require a duration because kicks are instant. Instead, you can use the command like this: **/kick playername reason**
|
|
||||||
### /modlogs
|
|
||||||
The /modlogs command can be used when the /smod menu is unavailable. It displays information about a player in chat instead of a menu.
|
|
||||||
|
|
||||||
Example: **/modlogs playername** shows you a message in chat that tells you whether the player is muted or banned.
|
|
||||||
### /unmute & /unban
|
|
||||||
The /unmute and /unban commands only take one argument, the player name.
|
|
||||||
|
|
||||||
The specified player will then be unmuted or unbanned.
|
|
||||||
## Permissions
|
## Permissions
|
||||||
This plugin uses Bukkit permissions for commands and other actions.
|
This plugin uses Bukkit permissions for commands and other actions.
|
||||||
- **smod.mute**: Allows the player to mute other players.
|
For a list of permissions, please see [the permissions file](https://github.com/Shiewk/SModeration/blob/main/docs/permissions.md).
|
||||||
- **smod.ban**: Allows the player to ban and kick other players.
|
|
||||||
- **smod.kick**: Allows the player to kick other players.
|
|
||||||
- **smod.menu**: Allows the player to use the SModeration menu.
|
|
||||||
- **smod.notifications**: Allows the player to be notified when a punishment is issued.
|
|
||||||
- **smod.unmute**: Allows the player to unmute other players.
|
|
||||||
- **smod.unban**: Allows the player to unban other players.
|
|
||||||
- **smod.logs**: Allows the player to view mod logs.
|
|
||||||
|
|
||||||
All of these permissions are granted by default if the player is a server operator.
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 42 KiB |
+34
-15
@@ -1,9 +1,10 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id("xyz.jpenilla.run-paper") version "${runPaperVersion}"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'de.shiewk'
|
group = 'de.shiewk'
|
||||||
version = '1.0'
|
version = pluginVersion
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -11,17 +12,44 @@ repositories {
|
|||||||
name = "papermc-repo"
|
name = "papermc-repo"
|
||||||
url = "https://repo.papermc.io/repository/maven-public/"
|
url = "https://repo.papermc.io/repository/maven-public/"
|
||||||
}
|
}
|
||||||
maven {
|
}
|
||||||
name = "sonatype"
|
|
||||||
url = "https://oss.sonatype.org/content/groups/public/"
|
processResources {
|
||||||
|
def props = [version: version]
|
||||||
|
inputs.properties props
|
||||||
|
filteringCharset 'UTF-8'
|
||||||
|
filesMatching('paper-plugin.yml') {
|
||||||
|
expand props
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runPaper {
|
||||||
|
folia {
|
||||||
|
registerTask()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runServer {
|
||||||
|
minecraftVersion("1.21.11")
|
||||||
|
downloadPlugins {
|
||||||
|
// for testing from other client versions
|
||||||
|
modrinth("ViaVersion", viaVersionVersion)
|
||||||
|
modrinth("ViaBackwards", viaVersionVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT"
|
//compileOnly "io.papermc.paper:paper-api:${apiVersion}"
|
||||||
|
compileOnly "dev.folia:folia-api:${apiVersion}"
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 17
|
jar {
|
||||||
|
archiveBaseName.set('SModeration-Paper')
|
||||||
|
archiveVersion.set(pluginVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def targetJavaVersion = 21
|
||||||
java {
|
java {
|
||||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
sourceCompatibility = javaVersion
|
sourceCompatibility = javaVersion
|
||||||
@@ -38,12 +66,3 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
options.release.set(targetJavaVersion)
|
options.release.set(targetJavaVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
|
||||||
def props = [version: version]
|
|
||||||
inputs.properties props
|
|
||||||
filteringCharset 'UTF-8'
|
|
||||||
filesMatching('plugin.yml') {
|
|
||||||
expand props
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# SModeration commands
|
||||||
|
|
||||||
|
| Command | Description | Permission |
|
||||||
|
|----------------------------------------|------------------------------------------------------------------------------|--------------------|
|
||||||
|
| /smod | Opens the SMod menu. | smod.menu |
|
||||||
|
| /mute \<player> \<duration> \<reason?> | Mutes a player so that they can't type in chat for the specified duration. | smod.mute |
|
||||||
|
| /ban \<player> \<duration> \<reason?> | Bans a player so that they can't join the server for the specified duration. | smod.ban |
|
||||||
|
| /kick \<player> \<reason?> | Kicks a player from the server. | smod.kick |
|
||||||
|
| /modlogs <player\|uuid> | Lists a player's active punishments in chat. | smod.logs |
|
||||||
|
| /unmute <player> | Clears a player's mute status. | smod.unmute |
|
||||||
|
| /unban <player> | Clears a player's ban status. | smod.unban |
|
||||||
|
| /invsee \<player> inventory | Views another player's inventory. | smod.invsee |
|
||||||
|
| /invsee \<player> equipment | Views another player's equipment (armor and offhand). | smod.invsee |
|
||||||
|
| /enderchestsee <player> | Views another player's ender chest. | smod.enderchestsee |
|
||||||
|
| /vanish | Toggles vanish mode so that other players can't see you're online. | smod.vanish |
|
||||||
|
| /vanish toggle \<players> | Toggles vanish mode for other players. | smod.vanish |
|
||||||
|
| /vanish list | Lists all vanished players. | smod.vanish.see |
|
||||||
|
| /socialspy | Enables SocialSpy mode where you can see other player's private messages. | smod.socialspy |
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# SModeration config
|
||||||
|
|
||||||
|
| Key | What it does |
|
||||||
|
|--------------------------|------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| socialspy-commands | The commands that `/socialspy` will listen to. |
|
||||||
|
| force-reason | Whether a reason is required for every punishment. |
|
||||||
|
| muted-forbidden-commands | Commands that players are not allowed to run while they are muted. |
|
||||||
|
| features | Controls which plugin features are enabled. |
|
||||||
|
| features.punishments | Whether the plugin provides punishing features (kick, ban, mute) |
|
||||||
|
| features.smodmenu | If punishments are enabled, controls whether the SMod Menu can be opened. Has no effect when punishments are disabled. |
|
||||||
|
| features.invsee | Whether the plugin provides invsee feature |
|
||||||
|
| features.enderchestsee | Whether the plugin provides enderchestsee feature |
|
||||||
|
| features.offlinetp | Whether the plugin provides the offlinetp feature |
|
||||||
|
| features.socialspy | Whether the plugin provides the SocialSpy feature |
|
||||||
|
| features.vanish | Whether the plugin provides the vanish feature |
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# SModeration permissions
|
||||||
|
| Permission | Description |
|
||||||
|
|---------------------------|------------------------------------------------------------------|
|
||||||
|
| smod.mute | Allows the player to mute other players. |
|
||||||
|
| smod.preventmute | Prevents the player from being muted (if they are online). |
|
||||||
|
| smod.ban | Allows the player to ban and kick other players. |
|
||||||
|
| smod.preventban | Prevents the player from being banned (if they are online). |
|
||||||
|
| smod.kick | Allows the player to kick other players. |
|
||||||
|
| smod.preventkick | Prevents the player from being kicked (if they are online). |
|
||||||
|
| smod.menu | Allows the player to use the SModeration menu. |
|
||||||
|
| smod.notifications | Allows the player to be notified when a punishment is issued. |
|
||||||
|
| smod.unmute | Allows the player to unmute other players. |
|
||||||
|
| smod.unban | Allows the player to unban other players. |
|
||||||
|
| smod.logs | Allows the player to view mod logs. |
|
||||||
|
| smod.invsee | Allows the player to view other players inventories. |
|
||||||
|
| smod.invsee.modify | Allows the player to view and modify other players inventories. |
|
||||||
|
| smod.invsee.preventmodify | Prevents the player's inventory from being modified. |
|
||||||
|
| smod.enderchestsee | Allows the player to view other players ender chests. |
|
||||||
|
| smod.enderchestsee.modify | Allows the player to view and modify other players ender chests. |
|
||||||
|
| smod.vanish | Allows the player to enter and leave vanish mode. |
|
||||||
|
| smod.vanish.see | Allows the player to see vanished players |
|
||||||
|
| smod.socialspy | Allows the player to enable SocialSpy |
|
||||||
|
|
||||||
|
All of these permissions are granted by default if the player is a server operator.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
pluginVersion = 1.8.2
|
||||||
|
apiVersion = 1.21.4-R0.1-SNAPSHOT
|
||||||
|
runPaperVersion = 3.0.2
|
||||||
|
viaVersionVersion = 5.8.0
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
package de.shiewk.smoderation;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.command.*;
|
|
||||||
import de.shiewk.smoderation.event.CustomInventoryEvents;
|
|
||||||
import de.shiewk.smoderation.listener.PunishmentListener;
|
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
|
||||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static org.bukkit.Bukkit.getPluginManager;
|
|
||||||
|
|
||||||
public final class SModeration extends JavaPlugin {
|
|
||||||
|
|
||||||
public static final PunishmentContainer container = new PunishmentContainer();
|
|
||||||
public static ComponentLogger LOGGER = null;
|
|
||||||
public static SModeration PLUGIN = null;
|
|
||||||
public static File SAVE_FILE = null;
|
|
||||||
|
|
||||||
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
|
||||||
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
|
||||||
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
|
||||||
public static final TextComponent CHAT_PREFIX = Component.text("SM \u00BB ").color(PRIMARY_COLOR);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad() {
|
|
||||||
LOGGER = getComponentLogger();
|
|
||||||
PLUGIN = this;
|
|
||||||
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
getPluginManager().registerEvents(new PunishmentListener(), this);
|
|
||||||
getPluginManager().registerEvents(new CustomInventoryEvents(), this);
|
|
||||||
|
|
||||||
final PluginCommand mute = getCommand("mute");
|
|
||||||
assert mute != null;
|
|
||||||
mute.setExecutor(new MuteCommand());
|
|
||||||
mute.setTabCompleter(new MuteCommand());
|
|
||||||
|
|
||||||
final PluginCommand ban = getCommand("ban");
|
|
||||||
assert ban != null;
|
|
||||||
ban.setExecutor(new BanCommand());
|
|
||||||
ban.setTabCompleter(new BanCommand());
|
|
||||||
|
|
||||||
final PluginCommand kick = getCommand("kick");
|
|
||||||
assert kick != null;
|
|
||||||
kick.setExecutor(new KickCommand());
|
|
||||||
kick.setTabCompleter(new KickCommand());
|
|
||||||
|
|
||||||
final PluginCommand smod = getCommand("smod");
|
|
||||||
assert smod != null;
|
|
||||||
smod.setExecutor(new SModCommand());
|
|
||||||
smod.setTabCompleter(new SModCommand());
|
|
||||||
|
|
||||||
final PluginCommand logs = getCommand("modlogs");
|
|
||||||
assert logs != null;
|
|
||||||
logs.setExecutor(new ModLogsCommand());
|
|
||||||
logs.setTabCompleter(new ModLogsCommand());
|
|
||||||
|
|
||||||
final PluginCommand unmute = getCommand("unmute");
|
|
||||||
assert unmute != null;
|
|
||||||
unmute.setExecutor(new UnmuteCommand());
|
|
||||||
unmute.setTabCompleter(new UnmuteCommand());
|
|
||||||
|
|
||||||
final PluginCommand unban = getCommand("unban");
|
|
||||||
assert unban != null;
|
|
||||||
unban.setExecutor(new UnbanCommand());
|
|
||||||
unban.setTabCompleter(new UnbanCommand());
|
|
||||||
|
|
||||||
container.load(SAVE_FILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
SModeration.container.save(SModeration.SAVE_FILE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.*;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BanCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 2){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
UUID senderUUID;
|
|
||||||
if (sender instanceof ConsoleCommandSender){
|
|
||||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
|
||||||
} else if (sender instanceof Player pl){
|
|
||||||
senderUUID = pl.getUniqueId();
|
|
||||||
} else if (sender instanceof BlockCommandSender){
|
|
||||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
String playerName = args[0];
|
|
||||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
|
||||||
if (senderUUID.equals(uuid)) {
|
|
||||||
sender.sendMessage(Component.text("You can't ban yourself.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
long duration = 0;
|
|
||||||
int p = 1;
|
|
||||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
|
||||||
String arg = args[i];
|
|
||||||
long parsedDuration = TimeUtil.parseDurationMillisSafely(arg);
|
|
||||||
if (parsedDuration == -1){
|
|
||||||
p = i;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
duration += parsedDuration;
|
|
||||||
}
|
|
||||||
if (i == args.length - 1){ p = args.length; }
|
|
||||||
}
|
|
||||||
if (duration == 0){
|
|
||||||
sender.sendMessage(Component.text("Please provide a valid duration.").color(NamedTextColor.RED));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (duration < 0){
|
|
||||||
sender.sendMessage(Component.text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
StringBuilder reason = new StringBuilder();
|
|
||||||
for (int i = p; i < args.length; i++) {
|
|
||||||
if (!reason.isEmpty()){
|
|
||||||
reason.append(" ");
|
|
||||||
}
|
|
||||||
reason.append(args[i]);
|
|
||||||
}
|
|
||||||
final Punishment punishment = Punishment.ban(System.currentTimeMillis(), System.currentTimeMillis() + duration, senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
|
||||||
Punishment.issue(punishment, SModeration.container);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 2){
|
|
||||||
String toComplete = args.length > 0 ? args[0] : "";
|
|
||||||
ArrayList<String> names = new ArrayList<>();
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
|
||||||
names.add(onlinePlayer.getName());
|
|
||||||
}
|
|
||||||
ArrayList<String> completions = new ArrayList<>();
|
|
||||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
|
||||||
return completions;
|
|
||||||
} else {
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
|
||||||
if (TimeUtil.parseDurationMillisSafely(args[i]) == -1){
|
|
||||||
try {
|
|
||||||
Long.parseLong(args[i]);
|
|
||||||
} catch (NumberFormatException ignored){
|
|
||||||
if (i != 1){
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return List.of(
|
|
||||||
"100ms",
|
|
||||||
"15s", // some sample completions for duration
|
|
||||||
"30min", // you can input your own ones as well
|
|
||||||
"6h",
|
|
||||||
"1d",
|
|
||||||
"2w",
|
|
||||||
"3mo",
|
|
||||||
"1y"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.*;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class KickCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 1){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
UUID senderUUID;
|
|
||||||
if (sender instanceof ConsoleCommandSender){
|
|
||||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
|
||||||
} else if (sender instanceof Player pl){
|
|
||||||
senderUUID = pl.getUniqueId();
|
|
||||||
} else if (sender instanceof BlockCommandSender){
|
|
||||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
String playerName = args[0];
|
|
||||||
Player player = Bukkit.getPlayer(playerName);
|
|
||||||
if (player == null) {
|
|
||||||
sender.sendMessage(Component.text("This player is not online.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
if (senderUUID.equals(uuid)) {
|
|
||||||
sender.sendMessage(Component.text("You can't kick yourself.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
StringBuilder reason = new StringBuilder();
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
|
||||||
if (!reason.isEmpty()){
|
|
||||||
reason.append(" ");
|
|
||||||
}
|
|
||||||
reason.append(args[i]);
|
|
||||||
}
|
|
||||||
final Punishment punishment = Punishment.kick(System.currentTimeMillis(), senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
|
||||||
Punishment.issue(punishment, SModeration.container);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 2){
|
|
||||||
String toComplete = args.length > 0 ? args[0] : "";
|
|
||||||
ArrayList<String> names = new ArrayList<>();
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
|
||||||
names.add(onlinePlayer.getName());
|
|
||||||
}
|
|
||||||
ArrayList<String> completions = new ArrayList<>();
|
|
||||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
|
||||||
return completions;
|
|
||||||
}
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
|
||||||
|
|
||||||
public class ModLogsCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 1){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
String playername = args[0];
|
|
||||||
String name;
|
|
||||||
UUID uuid;
|
|
||||||
try {
|
|
||||||
uuid = UUID.fromString(playername);
|
|
||||||
} catch (IllegalArgumentException ignored){
|
|
||||||
uuid = PlayerUtil.offlinePlayerUUIDByName(playername);
|
|
||||||
}
|
|
||||||
if (uuid == null){
|
|
||||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
name = PlayerUtil.offlinePlayerName(uuid);
|
|
||||||
sender.sendMessage(CHAT_PREFIX.append(Component.text("Player ").color(PRIMARY_COLOR)
|
|
||||||
.append(Component.text(name).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(" (%s)".formatted(uuid)).color(INACTIVE_COLOR))));
|
|
||||||
UUID finalUuid = uuid;
|
|
||||||
final List<Punishment> punishments = SModeration.container.findAll(p -> p.to.equals(finalUuid) && p.isActive());
|
|
||||||
for (Punishment punishment : punishments) {
|
|
||||||
sender.sendMessage(Component.text("- is currently ").color(PRIMARY_COLOR)
|
|
||||||
.append(Component.text(punishment.type == PunishmentType.BAN ? "banned" : "muted").color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(" until ").color(PRIMARY_COLOR))
|
|
||||||
.append(Component.text(TimeUtil.calendarTimestamp(punishment.until)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(" (in %s)".formatted(TimeUtil.formatTimeLong(punishment.until - System.currentTimeMillis()))).color(INACTIVE_COLOR))
|
|
||||||
.append(Component.text(". Reason: ").color(PRIMARY_COLOR))
|
|
||||||
.append(Component.text(punishment.reason).color(SECONDARY_COLOR)));
|
|
||||||
}
|
|
||||||
if (punishments.isEmpty()){
|
|
||||||
sender.sendMessage(Component.text("- has no punishments.").color(PRIMARY_COLOR));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length > 1){
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
String search = args.length > 0 ? args[0] : "";
|
|
||||||
List<String> playernames = new ArrayList<>();
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
|
||||||
playernames.add(onlinePlayer.getName());
|
|
||||||
}
|
|
||||||
List<String> completions = new ArrayList<>();
|
|
||||||
StringUtil.copyPartialMatches(search, playernames, completions);
|
|
||||||
return completions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.*;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MuteCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 2){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
UUID senderUUID;
|
|
||||||
if (sender instanceof ConsoleCommandSender){
|
|
||||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
|
||||||
} else if (sender instanceof Player pl){
|
|
||||||
senderUUID = pl.getUniqueId();
|
|
||||||
} else if (sender instanceof BlockCommandSender){
|
|
||||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
String playerName = args[0];
|
|
||||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
|
||||||
if (senderUUID.equals(uuid)) {
|
|
||||||
sender.sendMessage(Component.text("You can't mute yourself.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (uuid == null) {
|
|
||||||
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
long duration = 0;
|
|
||||||
int p = 1;
|
|
||||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
|
||||||
String arg = args[i];
|
|
||||||
long parsedDuration = TimeUtil.parseDurationMillisSafely(arg);
|
|
||||||
if (parsedDuration == -1){
|
|
||||||
p = i;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
duration += parsedDuration;
|
|
||||||
}
|
|
||||||
if (i == args.length - 1){ p = args.length; }
|
|
||||||
}
|
|
||||||
if (duration == 0){
|
|
||||||
sender.sendMessage(Component.text("Please provide a valid duration.").color(NamedTextColor.RED));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (duration < 0){
|
|
||||||
sender.sendMessage(Component.text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
StringBuilder reason = new StringBuilder();
|
|
||||||
for (int i = p; i < args.length; i++) {
|
|
||||||
if (!reason.isEmpty()){
|
|
||||||
reason.append(" ");
|
|
||||||
}
|
|
||||||
reason.append(args[i]);
|
|
||||||
}
|
|
||||||
final Punishment punishment = Punishment.mute(System.currentTimeMillis(), System.currentTimeMillis() + duration, senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
|
||||||
Punishment.issue(punishment, SModeration.container);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 2){
|
|
||||||
String toComplete = args.length > 0 ? args[0] : "";
|
|
||||||
ArrayList<String> names = new ArrayList<>();
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
|
||||||
names.add(onlinePlayer.getName());
|
|
||||||
}
|
|
||||||
ArrayList<String> completions = new ArrayList<>();
|
|
||||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
|
||||||
return completions;
|
|
||||||
} else {
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
|
||||||
if (TimeUtil.parseDurationMillisSafely(args[i]) == -1){
|
|
||||||
try {
|
|
||||||
Long.parseLong(args[i]);
|
|
||||||
} catch (NumberFormatException ignored){
|
|
||||||
if (i != 1){
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return List.of(
|
|
||||||
"100ms",
|
|
||||||
"15s", // some sample completions for duration
|
|
||||||
"30min", // you can input your own ones as well
|
|
||||||
"6h",
|
|
||||||
"1d",
|
|
||||||
"2w",
|
|
||||||
"3mo",
|
|
||||||
"1y"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.inventory.SModMenu;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SModCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
|
||||||
if (commandSender instanceof Player player){
|
|
||||||
new SModMenu(player, SModeration.container).open();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.command.*;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class UnbanCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 1){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
UUID senderUUID;
|
|
||||||
if (sender instanceof ConsoleCommandSender){
|
|
||||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
|
||||||
} else if (sender instanceof Player pl){
|
|
||||||
senderUUID = pl.getUniqueId();
|
|
||||||
} else if (sender instanceof BlockCommandSender){
|
|
||||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String nameArg = args[0];
|
|
||||||
UUID uuid;
|
|
||||||
try {
|
|
||||||
uuid = UUID.fromString(nameArg);
|
|
||||||
} catch (IllegalArgumentException ignored){
|
|
||||||
uuid = PlayerUtil.offlinePlayerUUIDByName(nameArg);
|
|
||||||
}
|
|
||||||
if (uuid == null){
|
|
||||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
UUID finalUuid = uuid;
|
|
||||||
final Punishment punishment = SModeration.container.find(p -> p.to.equals(finalUuid) && p.isActive() && p.type == PunishmentType.BAN);
|
|
||||||
if (punishment != null) {
|
|
||||||
punishment.undo(senderUUID);
|
|
||||||
punishment.broadcastUndo(SModeration.container);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("This player is not banned.").color(NamedTextColor.RED));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package de.shiewk.smoderation.command;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.command.*;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class UnmuteCommand implements CommandExecutor, TabCompleter {
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (args.length < 1){
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
UUID senderUUID;
|
|
||||||
if (sender instanceof ConsoleCommandSender){
|
|
||||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
|
||||||
} else if (sender instanceof Player pl){
|
|
||||||
senderUUID = pl.getUniqueId();
|
|
||||||
} else if (sender instanceof BlockCommandSender){
|
|
||||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String nameArg = args[0];
|
|
||||||
UUID uuid;
|
|
||||||
try {
|
|
||||||
uuid = UUID.fromString(nameArg);
|
|
||||||
} catch (IllegalArgumentException ignored){
|
|
||||||
uuid = PlayerUtil.offlinePlayerUUIDByName(nameArg);
|
|
||||||
}
|
|
||||||
if (uuid == null){
|
|
||||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
UUID finalUuid = uuid;
|
|
||||||
final Punishment punishment = SModeration.container.find(p -> p.to.equals(finalUuid) && p.isActive() && p.type == PunishmentType.MUTE);
|
|
||||||
if (punishment != null) {
|
|
||||||
punishment.undo(senderUUID);
|
|
||||||
punishment.broadcastUndo(SModeration.container);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("This player is not muted.").color(NamedTextColor.RED));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package de.shiewk.smoderation.event;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.inventory.CustomInventory;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
|
|
||||||
public class CustomInventoryEvents implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
||||||
public void onInventoryClick(InventoryClickEvent event){
|
|
||||||
if (event.getInventory().getHolder() instanceof CustomInventory customInventory){
|
|
||||||
customInventory.click(event.getCurrentItem(), event);
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package de.shiewk.smoderation.inventory;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public interface CustomInventory extends InventoryHolder {
|
|
||||||
|
|
||||||
void refresh();
|
|
||||||
void open();
|
|
||||||
void click(ItemStack stack, InventoryClickEvent event);
|
|
||||||
|
|
||||||
default ItemStack createEmptyStack(){
|
|
||||||
ItemStack stack = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
|
||||||
stack.editMeta(meta -> meta.displayName(Component.empty()));
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
default Component applyFormatting(Component component){
|
|
||||||
return component.decoration(TextDecoration.ITALIC, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,286 +0,0 @@
|
|||||||
package de.shiewk.smoderation.inventory;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
|
||||||
|
|
||||||
public class SModMenu extends PageableCustomInventory {
|
|
||||||
|
|
||||||
public enum Filter {
|
|
||||||
ACTIVE("Active punishments", Punishment::isActive),
|
|
||||||
OLD("Old punishments", p -> !p.isActive()),
|
|
||||||
ALL("All punishments", p -> true);
|
|
||||||
|
|
||||||
public static final Material ICON = Material.HOPPER;
|
|
||||||
|
|
||||||
public final String name;
|
|
||||||
public final Predicate<Punishment> filter;
|
|
||||||
Filter(String name, Predicate<Punishment> filter) {
|
|
||||||
this.name = name;
|
|
||||||
this.filter = filter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Sort {
|
|
||||||
EXPIRY("Expiry", Comparator.comparingLong(p -> p.until)),
|
|
||||||
TIME("Date", Comparator.comparingLong(p -> p.time)),
|
|
||||||
PLAYER_NAME("Player name", (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.to), PlayerUtil.offlinePlayerName(p2.to))),
|
|
||||||
MODERATOR_NAME("Moderator name", (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.by), PlayerUtil.offlinePlayerName(p2.by)));
|
|
||||||
|
|
||||||
public static final Material ICON = Material.COMPARATOR;
|
|
||||||
|
|
||||||
public final String name;
|
|
||||||
public final Comparator<Punishment> comparator;
|
|
||||||
|
|
||||||
Sort(String name, Comparator<Punishment> comparator) {
|
|
||||||
this.name = name;
|
|
||||||
this.comparator = comparator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static final NamespacedKey PUNISHMENT_STORE_KEY = new NamespacedKey("smod", "punishmentid");
|
|
||||||
|
|
||||||
private final Inventory inventory;
|
|
||||||
private final Player player;
|
|
||||||
private final PunishmentContainer container;
|
|
||||||
private List<Punishment> punishments;
|
|
||||||
private ItemStack sortStack = null;
|
|
||||||
private ItemStack filterStack = null;
|
|
||||||
private int sort = 0;
|
|
||||||
private int filter = 0;
|
|
||||||
|
|
||||||
public SModMenu(Player player, PunishmentContainer container) {
|
|
||||||
this.player = player;
|
|
||||||
this.container = container;
|
|
||||||
this.inventory = Bukkit.createInventory(this, 54, Component.text("SMod Menu"));
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sort getSort(){
|
|
||||||
return Sort.values()[sort];
|
|
||||||
}
|
|
||||||
|
|
||||||
public Filter getFilter(){
|
|
||||||
return Filter.values()[filter];
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reload(){
|
|
||||||
this.punishments = container.copy().stream().filter(getFilter().filter).sorted(getSort().comparator).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int lastPage() {
|
|
||||||
return Math.max((punishments.size() - 1) / 45, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cycleFilter(boolean backwards){
|
|
||||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
|
||||||
if (backwards){
|
|
||||||
if (filter <= 0){
|
|
||||||
filter = Filter.values().length-1;
|
|
||||||
} else {
|
|
||||||
filter--;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (filter >= Filter.values().length-1){
|
|
||||||
filter = 0;
|
|
||||||
} else {
|
|
||||||
filter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reload();
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cycleSort(boolean backwards){
|
|
||||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
|
||||||
if (backwards){
|
|
||||||
if (sort <= 0){
|
|
||||||
sort = Sort.values().length-1;
|
|
||||||
} else {
|
|
||||||
sort--;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (sort >= Sort.values().length-1){
|
|
||||||
sort = 0;
|
|
||||||
} else {
|
|
||||||
sort++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reload();
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void switchPage() {
|
|
||||||
player.playSound(player, Sound.BLOCK_STONE_HIT, 0.75f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack createFilterItem(){
|
|
||||||
final Filter filter = getFilter();
|
|
||||||
final ItemStack stack = new ItemStack(Filter.ICON);
|
|
||||||
stack.editMeta(meta -> {
|
|
||||||
meta.displayName(applyFormatting(Component.text("Filter: " + filter.name).color(SECONDARY_COLOR)));
|
|
||||||
ArrayList<Component> lore = new ArrayList<>();
|
|
||||||
lore.add(Component.empty());
|
|
||||||
for (Filter value : Filter.values()) {
|
|
||||||
final boolean selected = filter == value;
|
|
||||||
Component filterText = applyFormatting(Component.text((selected ? "\u00BB " : "") + value.name).color(selected ? PRIMARY_COLOR : INACTIVE_COLOR));
|
|
||||||
lore.add(filterText);
|
|
||||||
}
|
|
||||||
lore.add(Component.empty());
|
|
||||||
lore.add(applyFormatting(Component.text("\u00BB Click to switch filter").color(NamedTextColor.GOLD)));
|
|
||||||
meta.lore(lore);
|
|
||||||
});
|
|
||||||
filterStack = stack;
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack createSortItem(){
|
|
||||||
final Sort sort = getSort();
|
|
||||||
final ItemStack stack = new ItemStack(Sort.ICON);
|
|
||||||
stack.editMeta(meta -> {
|
|
||||||
meta.displayName(applyFormatting(Component.text("Sort by: " + sort.name).color(PRIMARY_COLOR)));
|
|
||||||
ArrayList<Component> lore = new ArrayList<>();
|
|
||||||
lore.add(Component.empty());
|
|
||||||
for (Sort value : Sort.values()) {
|
|
||||||
final boolean selected = sort == value;
|
|
||||||
Component sortText = applyFormatting(Component.text((selected ? "\u00BB " : "") + value.name).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
|
||||||
lore.add(sortText);
|
|
||||||
}
|
|
||||||
lore.add(Component.empty());
|
|
||||||
lore.add(applyFormatting(Component.text("\u00BB Click to switch sorting option").color(NamedTextColor.GOLD)));
|
|
||||||
meta.lore(lore);
|
|
||||||
});
|
|
||||||
sortStack = stack;
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack createPunishmentItem(Punishment punishment){
|
|
||||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
|
||||||
stack.editMeta(meta -> {
|
|
||||||
if (meta instanceof SkullMeta skullMeta){
|
|
||||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to));
|
|
||||||
}
|
|
||||||
meta.displayName(applyFormatting(Component.text(punishment.type.name).color(NamedTextColor.RED).decorate(TextDecoration.BOLD)));
|
|
||||||
ArrayList<Component> lore = new ArrayList<>();
|
|
||||||
lore.add(applyFormatting(Component.text("Player: ").color(SECONDARY_COLOR).append(Component.text(PlayerUtil.offlinePlayerName(punishment.to)).color(PRIMARY_COLOR))));
|
|
||||||
lore.add(applyFormatting(Component.text("Punished by: ").color(SECONDARY_COLOR).append(Component.text(PlayerUtil.offlinePlayerName(punishment.by)).color(PRIMARY_COLOR))));
|
|
||||||
lore.add(applyFormatting(Component.text("Timestamp: ").color(SECONDARY_COLOR).append(Component.text(TimeUtil.calendarTimestamp(punishment.time)).color(PRIMARY_COLOR))));
|
|
||||||
if (punishment.type != PunishmentType.KICK){
|
|
||||||
lore.add(applyFormatting(Component.text("Duration: ").color(SECONDARY_COLOR).append(Component.text(TimeUtil.formatTimeLong(punishment.until - punishment.time)).color(PRIMARY_COLOR))));
|
|
||||||
long remainingTime = punishment.until - System.currentTimeMillis();
|
|
||||||
final String expires;
|
|
||||||
if (remainingTime > 0){
|
|
||||||
expires = "in " + TimeUtil.formatTimeLong(remainingTime);
|
|
||||||
} else {
|
|
||||||
remainingTime *= -1;
|
|
||||||
expires = TimeUtil.formatTimeLong(remainingTime) + " ago";
|
|
||||||
}
|
|
||||||
lore.add(applyFormatting(Component.text("Expires: ").color(SECONDARY_COLOR).append(Component.text(expires).color(PRIMARY_COLOR))));
|
|
||||||
}
|
|
||||||
lore.add(applyFormatting(Component.text("Reason: ").color(SECONDARY_COLOR).append(Component.text(punishment.reason).color(PRIMARY_COLOR))));
|
|
||||||
if (punishment.wasUndone()){
|
|
||||||
lore.add(applyFormatting(Component.text("Undone by: ").color(NamedTextColor.RED).append(Component.text(PlayerUtil.offlinePlayerName(punishment.undoneBy())).color(NamedTextColor.GOLD))));
|
|
||||||
} else if (punishment.isActive()) {
|
|
||||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))){
|
|
||||||
lore.add(Component.empty());
|
|
||||||
lore.add(applyFormatting(Component.text("\u00BB Click to undo punishment").color(NamedTextColor.GOLD)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
meta.lore(lore);
|
|
||||||
});
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refresh() {
|
|
||||||
for (int i = 45; i < 54; i++) {
|
|
||||||
inventory.setItem(i, createEmptyStack());
|
|
||||||
}
|
|
||||||
inventory.setItem(45, createPreviousPageStack());
|
|
||||||
inventory.setItem(53, createNextPageStack());
|
|
||||||
inventory.setItem(50, createFilterItem());
|
|
||||||
inventory.setItem(48, createSortItem());
|
|
||||||
|
|
||||||
for (int i = 0; i < 45; i++) {
|
|
||||||
int ci = i + (getPage() * 45);
|
|
||||||
if (punishments.size() > ci){
|
|
||||||
final Punishment punishment = punishments.get(ci);
|
|
||||||
final ItemStack item = createPunishmentItem(punishment);
|
|
||||||
if (punishment.isActive()){
|
|
||||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))) {
|
|
||||||
item.editMeta(meta -> meta.getPersistentDataContainer().set(PUNISHMENT_STORE_KEY, PersistentDataType.LONG, punishment.time));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inventory.setItem(i, item);
|
|
||||||
} else {
|
|
||||||
inventory.setItem(i, new ItemStack(Material.AIR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
|
||||||
super.click(stack, event);
|
|
||||||
if (stack != null) {
|
|
||||||
if (stack.equals(filterStack)){
|
|
||||||
cycleFilter(event.isRightClick());
|
|
||||||
} else if (stack.equals(sortStack)){
|
|
||||||
cycleSort(event.isRightClick());
|
|
||||||
}
|
|
||||||
final ItemMeta itemMeta = stack.getItemMeta();
|
|
||||||
if (itemMeta != null) {
|
|
||||||
final PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();
|
|
||||||
final Long timestamp = persistentDataContainer.get(PUNISHMENT_STORE_KEY, PersistentDataType.LONG);
|
|
||||||
if (timestamp != null) {
|
|
||||||
final Punishment punishment = container.findByTimestamp(timestamp);
|
|
||||||
if (punishment != null) {
|
|
||||||
new ConfirmationInventory(player, "Do you want to undo this punishment?", () -> {
|
|
||||||
punishment.undo(player.getUniqueId());
|
|
||||||
punishment.broadcastUndo(container);
|
|
||||||
player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f);
|
|
||||||
this.open();
|
|
||||||
}, this::open, false).open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void open() {
|
|
||||||
reload();
|
|
||||||
refresh();
|
|
||||||
player.openInventory(this.inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Inventory getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package de.shiewk.smoderation.listener;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.event.PunishmentIssueEvent;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
import org.bukkit.event.world.WorldSaveEvent;
|
|
||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.CHAT_PREFIX;
|
|
||||||
|
|
||||||
public class PunishmentListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
|
||||||
public void onPlayerLogin(PlayerLoginEvent event){
|
|
||||||
Punishment punishment = SModeration.container.find(p ->
|
|
||||||
p.type == PunishmentType.BAN
|
|
||||||
&& p.to.equals(event.getPlayer().getUniqueId())
|
|
||||||
&& p.isActive());
|
|
||||||
if (punishment != null){
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CHAT_PREFIX.append(punishment.playerMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
||||||
public void onPlayerChat(AsyncChatEvent event){
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
final Punishment punishment = SModeration.container.find(p ->
|
|
||||||
p.type == PunishmentType.MUTE
|
|
||||||
&& p.to.equals(player.getUniqueId())
|
|
||||||
&& p.isActive());
|
|
||||||
if (punishment != null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
player.sendMessage(CHAT_PREFIX.append(punishment.playerMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onPunishmentIssue(PunishmentIssueEvent event){
|
|
||||||
final Punishment punishment = event.getPunishment();
|
|
||||||
final PunishmentContainer container = event.getContainer();
|
|
||||||
final Punishment duplicate = container.find(p -> p.to.equals(punishment.to) && p.type == punishment.type && p.isActive());
|
|
||||||
if (duplicate != null){
|
|
||||||
container.remove(duplicate);
|
|
||||||
container.add(new Punishment(duplicate.type, duplicate.time, System.currentTimeMillis(), duplicate.by, duplicate.to, duplicate.reason));
|
|
||||||
}
|
|
||||||
switch (punishment.type){
|
|
||||||
case KICK, BAN -> {
|
|
||||||
final Player player = Bukkit.getPlayer(punishment.to);
|
|
||||||
if (player != null) {
|
|
||||||
player.kick(CHAT_PREFIX.append(punishment.playerMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onWorldSave(WorldSaveEvent event){
|
|
||||||
if (event.getWorld().equals(Bukkit.getServer().getWorlds().get(0))){
|
|
||||||
SModeration.container.save(SModeration.SAVE_FILE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,223 @@
|
|||||||
|
package de.shiewk.smoderation.paper;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import de.shiewk.smoderation.paper.command.*;
|
||||||
|
import de.shiewk.smoderation.paper.input.ChatInput;
|
||||||
|
import de.shiewk.smoderation.paper.input.ChatInputListener;
|
||||||
|
import de.shiewk.smoderation.paper.listener.*;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Kick;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.translation.TranslatorManager;
|
||||||
|
import de.shiewk.smoderation.paper.util.SModLegacy;
|
||||||
|
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.command.VanishCommand.isVanished;
|
||||||
|
import static de.shiewk.smoderation.paper.command.VanishCommand.toggleVanish;
|
||||||
|
import static org.bukkit.Bukkit.getPluginManager;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class SModerationPaper extends JavaPlugin {
|
||||||
|
|
||||||
|
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
||||||
|
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
||||||
|
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
||||||
|
|
||||||
|
public static final Gson gson = new Gson();
|
||||||
|
public static ComponentLogger LOGGER = null;
|
||||||
|
public static SModerationPaper PLUGIN = null;
|
||||||
|
private static SkinTextureProvider textureProvider = null;
|
||||||
|
|
||||||
|
private final TranslatorManager translatorManager = new TranslatorManager(
|
||||||
|
Key.key("smoderation", "translations"),
|
||||||
|
createMiniMessage(),
|
||||||
|
"smoderation/translations/",
|
||||||
|
new Locale[] {
|
||||||
|
Locale.forLanguageTag("en-US"),
|
||||||
|
Locale.forLanguageTag("de-DE")
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
private PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public static FileConfiguration config() {
|
||||||
|
return PLUGIN.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
LOGGER = getComponentLogger();
|
||||||
|
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
|
||||||
|
PLUGIN = this;
|
||||||
|
LOGGER.info("Loading translations");
|
||||||
|
translatorManager.load();
|
||||||
|
updateConfig();
|
||||||
|
|
||||||
|
this.punishmentManager = new PunishmentManager(getDataPath().resolve("punishments.v2"));
|
||||||
|
this.punishmentManager.registerType("mute", new Mute.Factory());
|
||||||
|
this.punishmentManager.registerType("ban", new Ban.Factory());
|
||||||
|
this.punishmentManager.registerType("kick", new Kick.Factory());
|
||||||
|
|
||||||
|
SModLegacy.migrateV1PunishmentsFile(
|
||||||
|
this.punishmentManager,
|
||||||
|
getDataPath().resolve("container.gz"),
|
||||||
|
getDataPath().resolve("v1-backup.gz")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFeatureEnabled(String feature){
|
||||||
|
return getConfig().getBoolean("features."+feature, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
if (isFeatureEnabled("punishments")) listen(new PunishmentListener(punishmentManager));
|
||||||
|
if (isFeatureEnabled("punishments")) listen(new CacheListener(punishmentManager));
|
||||||
|
if (isFeatureEnabled("invsee")) listen(new InvSeeListener());
|
||||||
|
if (isFeatureEnabled("enderchestsee")) listen(new EnderchestSeeListener());
|
||||||
|
if (isFeatureEnabled("socialspy")) listen(new SocialSpyListener());
|
||||||
|
if (isFeatureEnabled("vanish")) listen(new VanishListener());
|
||||||
|
|
||||||
|
listen(new CustomInventoryListener());
|
||||||
|
listen(new ChatInputListener());
|
||||||
|
|
||||||
|
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
|
||||||
|
Commands commands = event.registrar();
|
||||||
|
|
||||||
|
if (isFeatureEnabled("punishments")){
|
||||||
|
registerCommand(commands, new KickCommand(punishmentManager));
|
||||||
|
registerCommand(commands, new ModLogsCommand(punishmentManager));
|
||||||
|
registerCommand(commands, new UnmuteCommand(punishmentManager));
|
||||||
|
registerCommand(commands, new UnbanCommand(punishmentManager));
|
||||||
|
registerCommand(commands, new MuteCommand(punishmentManager));
|
||||||
|
registerCommand(commands, new BanCommand(punishmentManager));
|
||||||
|
|
||||||
|
if (isFeatureEnabled("smodmenu")){
|
||||||
|
registerCommand(commands, new SModCommand(punishmentManager));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFeatureEnabled("invsee")) registerCommand(commands, new InvseeCommand());
|
||||||
|
if (isFeatureEnabled("enderchestsee")) registerCommand(commands, new EnderchestSeeCommand());
|
||||||
|
if (isFeatureEnabled("socialspy")) registerCommand(commands, new SocialSpyCommand());
|
||||||
|
if (isFeatureEnabled("vanish")) registerCommand(commands, new VanishCommand());
|
||||||
|
if (isFeatureEnabled("offlinetp")) registerCommand(commands, new OfflineTPCommand());
|
||||||
|
});
|
||||||
|
|
||||||
|
if (SchedulerUtil.isFolia){
|
||||||
|
// Normal ticking logic can cause issues on Folia
|
||||||
|
listen(new FoliaInventoryUpdatingListener());
|
||||||
|
} else {
|
||||||
|
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, CustomInventoryListener::tickAllPaper, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listen(Listener listener) {
|
||||||
|
getPluginManager().registerEvents(listener, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerCommand(Commands commands, CommandProvider provider){
|
||||||
|
commands.register(
|
||||||
|
provider.getCommandNode(),
|
||||||
|
provider.getCommandDescription(),
|
||||||
|
provider.getAliases()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
// in case players are still vanished when the server shuts down
|
||||||
|
if (isVanished(player)){
|
||||||
|
toggleVanish(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinTextureProvider getTextureProvider() {
|
||||||
|
return textureProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setTextureProvider(SkinTextureProvider textureProvider) {
|
||||||
|
SModerationPaper.textureProvider = textureProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MiniMessage createMiniMessage() {
|
||||||
|
return MiniMessage.builder()
|
||||||
|
.tags(TagResolver.builder()
|
||||||
|
.resolver(TagResolver.resolver("primary", Tag.styling(style -> style.color(PRIMARY_COLOR))))
|
||||||
|
.resolver(TagResolver.resolver("secondary", Tag.styling(style -> style.color(SECONDARY_COLOR))))
|
||||||
|
.resolver(TagResolver.standard())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateConfig() {
|
||||||
|
LOGGER.info("Updating config");
|
||||||
|
try {
|
||||||
|
FileConfiguration config = getConfig();
|
||||||
|
|
||||||
|
InputStream defaultConfigStream = getResource("default-config.yml");
|
||||||
|
if (defaultConfigStream == null) {
|
||||||
|
throw new IllegalStateException("Default config not found in JAR; could not load");
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultConfigStream));
|
||||||
|
|
||||||
|
boolean changedSomething = false;
|
||||||
|
for (String key : defaultConfig.getKeys(true)) {
|
||||||
|
if (!config.contains(key)) {
|
||||||
|
// There's a new key in the default config
|
||||||
|
config.set(key, defaultConfig.get(key));
|
||||||
|
changedSomething = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> defaultComments = new ArrayList<>(defaultConfig.getComments(key));
|
||||||
|
List<String> comments = new ArrayList<>(config.getComments(key));
|
||||||
|
defaultComments.removeIf(Objects::isNull);
|
||||||
|
comments.removeIf(Objects::isNull);
|
||||||
|
|
||||||
|
if (!defaultComments.equals(comments)) {
|
||||||
|
// Comments changed
|
||||||
|
config.setComments(key, defaultConfig.getComments(key));
|
||||||
|
changedSomething = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the updated configuration file
|
||||||
|
if (changedSomething){
|
||||||
|
LOGGER.info("Changing config file to add new options/documentation");
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Could not update config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package de.shiewk.smoderation.paper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public interface SkinTextureProvider {
|
||||||
|
|
||||||
|
CompletableFuture<String> textureProperty(UUID player);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.DurationArgument;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class BanCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public BanCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("ban")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.ban"))
|
||||||
|
.then(argument("player", new PlayerUUIDArgument())
|
||||||
|
.then(argument("duration", new DurationArgument())
|
||||||
|
.executes(this::banWithoutReason)
|
||||||
|
.then(argument("reason", StringArgumentType.greedyString())
|
||||||
|
.executes(this::banWithReason)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int banWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
if (SModerationPaper.config().getBoolean("force-reason", false)){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.ban.fail.forceReason");
|
||||||
|
}
|
||||||
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
|
long duration = context.getArgument("duration", Long.class);
|
||||||
|
executeBan(punishmentManager, sender, target, duration, SModerationPaper.config().getString("default-reason", "No reason provided."));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int banWithReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
|
long duration = context.getArgument("duration", Long.class);
|
||||||
|
String reason = StringArgumentType.getString(context, "reason");
|
||||||
|
executeBan(punishmentManager, sender, target, duration, reason);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeBan(PunishmentManager manager, UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||||
|
Player targetPlayer = Bukkit.getPlayer(target);
|
||||||
|
if (duration == 0){
|
||||||
|
if (targetPlayer == null){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.ban.fail.tooShort");
|
||||||
|
} else {
|
||||||
|
KickCommand.executeKick(manager, sender, targetPlayer, reason);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sender.equals(target)) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.ban.fail.self");
|
||||||
|
} else {
|
||||||
|
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventban")){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.ban.fail.protect");
|
||||||
|
} else {
|
||||||
|
if (!manager.byTargetUUID(target, p -> p instanceof Ban ban && ban.isActive()).isEmpty()) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.ban.fail.alreadyBanned");
|
||||||
|
}
|
||||||
|
Punishment punishment = new Ban(
|
||||||
|
Punishment.generateUUID(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
sender,
|
||||||
|
target,
|
||||||
|
reason,
|
||||||
|
duration
|
||||||
|
);
|
||||||
|
manager.tryIssue(punishment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Bans a player for a customizable duration.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodban");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public interface CommandProvider {
|
||||||
|
|
||||||
|
LiteralCommandNode<CommandSourceStack> getCommandNode();
|
||||||
|
|
||||||
|
String getCommandDescription();
|
||||||
|
|
||||||
|
default Collection<String> getAliases(){
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class EnderchestSeeCommand implements CommandProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("enderchestsee")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.enderchestsee"))
|
||||||
|
.then(argument("player", ArgumentTypes.player())
|
||||||
|
.executes(this::openEnderChest)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int openEnderChest(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||||
|
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||||
|
sender.sendMessage(translatable("smod.command.ecsee.opening", target.teamDisplayName()));
|
||||||
|
sender.openInventory(target.getEnderChest());
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Views the ender chest of a player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("ecsee");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.inventory.InvSeeEquipmentInventory;
|
||||||
|
import de.shiewk.smoderation.paper.inventory.InvSeeInventory;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class InvseeCommand implements CommandProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("invsee")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.invsee"))
|
||||||
|
.then(argument("player", ArgumentTypes.player())
|
||||||
|
.executes(this::invseeInventory)
|
||||||
|
.then(literal("inventory")
|
||||||
|
.executes(this::invseeInventory)
|
||||||
|
)
|
||||||
|
.then(literal("armor")
|
||||||
|
.executes(this::invseeEquipment)
|
||||||
|
)
|
||||||
|
.then(literal("equipment")
|
||||||
|
.executes(this::invseeEquipment)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int invseeInventory(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||||
|
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||||
|
if (sender.equals(target)){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.invsee.fail.self");
|
||||||
|
}
|
||||||
|
sender.sendMessage(translatable("smod.command.invsee.opening", target.teamDisplayName()));
|
||||||
|
new InvSeeInventory(sender, target).open();
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int invseeEquipment(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||||
|
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||||
|
if (sender.equals(target)){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.invsee.fail.self");
|
||||||
|
}
|
||||||
|
sender.sendMessage(translatable("smod.command.invsee.opening", target.teamDisplayName()));
|
||||||
|
new InvSeeEquipmentInventory(sender, target).open();
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Views the inventory of another player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("sinvsee", "smodinvsee", "invs");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Kick;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class KickCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public KickCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("kick")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.kick"))
|
||||||
|
.then(argument("player", ArgumentTypes.player())
|
||||||
|
.executes(this::kickWithoutReason)
|
||||||
|
.then(argument("reason", StringArgumentType.greedyString())
|
||||||
|
.executes(this::kickWithReason)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int kickWithReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||||
|
String reason = StringArgumentType.getString(context, "reason");
|
||||||
|
executeKick(punishmentManager, sender, target, reason);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int kickWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
if (SModerationPaper.config().getBoolean("force-reason", false)){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.kick.fail.forceReason");
|
||||||
|
}
|
||||||
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||||
|
executeKick(punishmentManager, sender, target, SModerationPaper.config().getString("default-reason", "No reason provided."));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeKick(PunishmentManager manager, UUID sender, Player target, String reason) throws CommandSyntaxException {
|
||||||
|
UUID targetId = target.getUniqueId();
|
||||||
|
if (sender.equals(targetId)) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.kick.fail.self");
|
||||||
|
} else if (target.hasPermission("smod.preventkick")){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.kick.fail.protect");
|
||||||
|
}
|
||||||
|
Punishment punishment = new Kick(
|
||||||
|
Punishment.generateUUID(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
sender,
|
||||||
|
targetId,
|
||||||
|
reason
|
||||||
|
);
|
||||||
|
manager.tryIssue(punishment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Kicks a player";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodkick");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class ModLogsCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public ModLogsCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("modlogs")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.logs"))
|
||||||
|
.then(argument("player", new PlayerUUIDArgument())
|
||||||
|
.executes(this::showModLogs)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int showModLogs(CommandContext<CommandSourceStack> context) {
|
||||||
|
CommandSender sender = context.getSource().getSender();
|
||||||
|
UUID uuid = context.getArgument("player", UUID.class);
|
||||||
|
String name = PlayerUtil.offlinePlayerName(uuid);
|
||||||
|
sender.sendMessage(translatable("smod.command.modlogs.heading", text(name), text(uuid.toString())));
|
||||||
|
List<Punishment> punishments = punishmentManager.byTargetUUID(uuid);
|
||||||
|
for (Punishment punishment : punishments) {
|
||||||
|
if (punishment instanceof TimedPunishment timed && timed.isActive()){
|
||||||
|
if (timed.isPermanent()){
|
||||||
|
sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType() + ".permanent", text(punishment.getReason())));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType(),
|
||||||
|
TimeUtil.calendarTimestamp(timed.getExpiry()),
|
||||||
|
TimeUtil.formatTimeLong(timed.getExpiry() - System.currentTimeMillis()),
|
||||||
|
text(punishment.getReason())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (punishments.isEmpty()){
|
||||||
|
sender.sendMessage(translatable("smod.command.modlogs.none"));
|
||||||
|
}
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Views all current punishments of a player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("logs", "seen", "smodlogs");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.DurationArgument;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class MuteCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public MuteCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("mute")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.mute"))
|
||||||
|
.then(argument("player", new PlayerUUIDArgument())
|
||||||
|
.then(argument("duration", new DurationArgument())
|
||||||
|
.executes(this::muteWithoutReason)
|
||||||
|
.then(argument("reason", StringArgumentType.greedyString())
|
||||||
|
.executes(this::muteWithReason)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int muteWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
if (SModerationPaper.config().getBoolean("force-reason", false)){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.mute.fail.forceReason");
|
||||||
|
}
|
||||||
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
|
long duration = context.getArgument("duration", Long.class);
|
||||||
|
executeMute(punishmentManager, sender, target, duration, SModerationPaper.config().getString("default-reason", "No reason provided."));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int muteWithReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
|
long duration = context.getArgument("duration", Long.class);
|
||||||
|
String reason = StringArgumentType.getString(context, "reason");
|
||||||
|
executeMute(punishmentManager, sender, target, duration, reason);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeMute(PunishmentManager manager, UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||||
|
if (duration == 0){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.mute.fail.tooShort");
|
||||||
|
}
|
||||||
|
if (sender.equals(target)) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.mute.fail.self");
|
||||||
|
} else {
|
||||||
|
Player targetPlayer = Bukkit.getPlayer(target);
|
||||||
|
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventmute")){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.mute.fail.protect");
|
||||||
|
} else {
|
||||||
|
if (!manager.byTargetUUID(target, p -> p instanceof Mute mute && mute.isActive()).isEmpty()) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.mute.fail.alreadyMuted");
|
||||||
|
}
|
||||||
|
Punishment punishment = new Mute(
|
||||||
|
Punishment.generateUUID(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
sender,
|
||||||
|
target,
|
||||||
|
reason,
|
||||||
|
duration
|
||||||
|
);
|
||||||
|
manager.tryIssue(punishment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Mutes a player for a customizable duration.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodmute");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.OfflinePlayerArgument;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class OfflineTPCommand implements CommandProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("offlinetp")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.offlinetp"))
|
||||||
|
.then(argument("player", new OfflinePlayerArgument())
|
||||||
|
.executes(this::offlineTeleport)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int offlineTeleport(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||||
|
OfflinePlayer player = context.getArgument("player", OfflinePlayer.class);
|
||||||
|
|
||||||
|
Location location = player.getLocation();
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.offlinetp.fail.unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.teleportAsync(location, PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||||
|
sender.sendMessage(translatable("smod.command.offlinetp.teleporting", text(PlayerUtil.offlinePlayerName(player.getUniqueId()))));
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Teleports you to an offline player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodofflinetp");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.inventory.SModMenu;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class SModCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public SModCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("smod")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.menu"))
|
||||||
|
.executes(this::openMenu)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int openMenu(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
Player player = CommandUtil.getExecutingPlayer(context.getSource());
|
||||||
|
new SModMenu(player, punishmentManager).open();
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Shows the SModeration menu.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodmenu", "smoderation");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.listener.SocialSpyListener;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class SocialSpyCommand implements CommandProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("socialspy")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.socialspy"))
|
||||||
|
.executes(this::toggleSocialSpy)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int toggleSocialSpy(CommandContext<CommandSourceStack> context) {
|
||||||
|
CommandSender sender = context.getSource().getSender();
|
||||||
|
final boolean enabled = SocialSpyListener.toggle(sender);
|
||||||
|
if (enabled){
|
||||||
|
sender.sendMessage(translatable("smod.command.socialspy.enabled"));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(translatable("smod.command.socialspy.disabled"));
|
||||||
|
}
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Enables SocialSpy mode (allows you to see private messages of other players)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodsocialspy");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class UnbanCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public UnbanCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("unban")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.unban"))
|
||||||
|
.then(argument("player", new PlayerUUIDArgument())
|
||||||
|
.executes(this::unbanPlayer)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int unbanPlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
|
final List<Punishment> punishments = punishmentManager.byTargetUUID(
|
||||||
|
target,
|
||||||
|
p -> p instanceof Ban ban && ban.isActive()
|
||||||
|
);
|
||||||
|
for (Punishment punishment : punishments) {
|
||||||
|
punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
|
||||||
|
}
|
||||||
|
if (punishments.isEmpty()) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.unban.fail.notBanned");
|
||||||
|
}
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Unbans a banned player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodunban");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class UnmuteCommand implements CommandProvider {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public UnmuteCommand(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("unmute")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.unmute"))
|
||||||
|
.then(argument("player", new PlayerUUIDArgument())
|
||||||
|
.executes(this::unmutePlayer)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int unmutePlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
|
||||||
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
|
final List<Punishment> punishments = punishmentManager.byTargetUUID(
|
||||||
|
target,
|
||||||
|
p -> p instanceof Mute mute && mute.isActive()
|
||||||
|
);
|
||||||
|
for (Punishment punishment : punishments) {
|
||||||
|
punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
|
||||||
|
}
|
||||||
|
if (punishments.isEmpty()) {
|
||||||
|
CommandUtil.errorTranslatable("smod.command.unmute.fail.notBanned");
|
||||||
|
}
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Unmutes a muted player.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smodunmute");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import de.shiewk.smoderation.paper.event.VanishToggleEvent;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.*;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class VanishCommand implements CommandProvider {
|
||||||
|
|
||||||
|
public static final NamespacedKey KEY_VANISHED = new NamespacedKey("smoderation", "vanished");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||||
|
return literal("vanish")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.vanish"))
|
||||||
|
.executes(this::toggleVanishSelf)
|
||||||
|
.then(literal("toggle")
|
||||||
|
.executes(this::toggleVanishSelf)
|
||||||
|
.then(argument("targets", ArgumentTypes.players())
|
||||||
|
.executes(this::toggleVanishForTargets)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.then(literal("list")
|
||||||
|
.requires(CommandUtil.requirePermission("smod.vanish.see"))
|
||||||
|
.executes(this::listVanishedPlayers)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int toggleVanishForTargets(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
List<Player> targets = context.getArgument("targets", PlayerSelectorArgumentResolver.class).resolve(context.getSource());
|
||||||
|
if (targets.isEmpty()){
|
||||||
|
CommandUtil.errorTranslatable("smod.command.vanish.fail.noPlayersFound");
|
||||||
|
} else {
|
||||||
|
for (Player target : targets) {
|
||||||
|
toggleVanish(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int toggleVanishSelf(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
toggleVanish(CommandUtil.getExecutingPlayer(context.getSource()));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int listVanishedPlayers(CommandContext<CommandSourceStack> context) {
|
||||||
|
listVanishedPlayersTo(context.getSource().getSender());
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommandDescription() {
|
||||||
|
return "Toggles vanish mode which prevents other players from seeing you're online.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getAliases() {
|
||||||
|
return List.of("smvanish", "smodvanish", "v", "smv");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>(0);
|
||||||
|
|
||||||
|
public static void toggleVanish(Player player){
|
||||||
|
final boolean newStatus = !isVanished(player);
|
||||||
|
VanishToggleEvent event = new VanishToggleEvent(player, newStatus);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newStatus){
|
||||||
|
vanishedPlayers.add(player);
|
||||||
|
for (CommandSender sender : Punishment.getBroadcastTargets()) {
|
||||||
|
sender.sendMessage(translatable("smod.command.vanish.broadcast.on", player.teamDisplayName()));
|
||||||
|
}
|
||||||
|
player.sendMessage(translatable("smod.command.vanish.toggle.on"));
|
||||||
|
player.setVisibleByDefault(false);
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||||
|
onlinePlayer.showEntity(PLUGIN, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vanishedPlayers.remove(player);
|
||||||
|
for (CommandSender sender : Punishment.getBroadcastTargets()) {
|
||||||
|
sender.sendMessage(translatable("smod.command.vanish.broadcast.off", player.teamDisplayName()));
|
||||||
|
}
|
||||||
|
player.sendMessage(translatable("smod.command.vanish.toggle.off"));
|
||||||
|
player.setVisibleByDefault(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean toggleVanishSilent(Player player, boolean force){
|
||||||
|
final boolean newStatus = !isVanished(player);
|
||||||
|
VanishToggleEvent event = new VanishToggleEvent(player, newStatus);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled() && !force){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (newStatus){
|
||||||
|
vanishedPlayers.add(player);
|
||||||
|
player.setVisibleByDefault(false);
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||||
|
onlinePlayer.showEntity(PLUGIN, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vanishedPlayers.remove(player);
|
||||||
|
player.setVisibleByDefault(true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isVanished(Player player){
|
||||||
|
return vanishedPlayers.contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ObjectArrayList<Player> getVanishedPlayers() {
|
||||||
|
return vanishedPlayers.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void listVanishedPlayersTo(CommandSender receiver){
|
||||||
|
if (vanishedPlayers.isEmpty()){
|
||||||
|
receiver.sendMessage(translatable("smod.command.vanish.list.none"));
|
||||||
|
} else {
|
||||||
|
Component vanishList = empty();
|
||||||
|
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||||
|
Player vanishedPlayer = iterator.next();
|
||||||
|
vanishList = vanishList.append(
|
||||||
|
vanishedPlayer.teamDisplayName().colorIfAbsent(SECONDARY_COLOR)
|
||||||
|
);
|
||||||
|
if (iterator.hasNext()){
|
||||||
|
vanishList = vanishList.append(
|
||||||
|
text().content(", ").color(PRIMARY_COLOR)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
receiver.sendMessage(translatable("smod.command.vanish.list", vanishList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command.argument;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.regex.MatchResult;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class DurationArgument implements CustomArgumentType.Converted<Long, String> {
|
||||||
|
|
||||||
|
public static final Pattern DURATION_PATTERN = Pattern.compile("([0-9]{1,9})(ms|s|min|h|d|w|mo|y)");
|
||||||
|
public static final Pattern VALIDATION_PATTERN = Pattern.compile("(([0-9]{1,9})(ms|s|min|h|d|w|mo|y))+");
|
||||||
|
public static final long INFINITE_DURATION = -1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Long convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||||
|
if (nativeType.startsWith("perm") || nativeType.startsWith("inf")) {
|
||||||
|
return INFINITE_DURATION;
|
||||||
|
}
|
||||||
|
if (!VALIDATION_PATTERN.matcher(nativeType).matches()){
|
||||||
|
CommandUtil.errorTranslatable("smod.argument.duration.fail.pattern");
|
||||||
|
}
|
||||||
|
AtomicLong totalDuration = new AtomicLong();
|
||||||
|
for (MatchResult result : DURATION_PATTERN.matcher(nativeType).results().toList()) {
|
||||||
|
long amount = Long.parseLong(result.group(1));
|
||||||
|
long timeSpan = switch (result.group(2)) {
|
||||||
|
case "ms" -> 1;
|
||||||
|
case "s" -> 1000;
|
||||||
|
case "min" -> 60_000;
|
||||||
|
case "h" -> 3600_000;
|
||||||
|
case "d" -> 86400_000;
|
||||||
|
case "w" -> 604800_000;
|
||||||
|
case "mo" -> 2_592_000_000L;
|
||||||
|
case "y" -> 31_536_000_000L;
|
||||||
|
default -> {
|
||||||
|
CommandUtil.errorTranslatable("smod.argument.duration.fail.invalid", result.group(2));
|
||||||
|
throw new UnknownError(); // can't happen
|
||||||
|
}
|
||||||
|
};
|
||||||
|
totalDuration.addAndGet(amount*timeSpan);
|
||||||
|
}
|
||||||
|
return totalDuration.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ArgumentType<String> getNativeType() {
|
||||||
|
return StringArgumentType.word();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||||
|
if (builder.getRemaining().isBlank()){
|
||||||
|
List.of(
|
||||||
|
"infinite", "inf",
|
||||||
|
"permanent", "perm",
|
||||||
|
"100ms",
|
||||||
|
"15s",
|
||||||
|
"2min",
|
||||||
|
"3h",
|
||||||
|
"7d",
|
||||||
|
"1w",
|
||||||
|
"3mo",
|
||||||
|
"1y",
|
||||||
|
"1mo15d",
|
||||||
|
"2h30min"
|
||||||
|
).forEach(builder::suggest);
|
||||||
|
}
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command.argument;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class OfflinePlayerArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull OfflinePlayer convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayerIfCached(nativeType);
|
||||||
|
if (player != null){
|
||||||
|
return player;
|
||||||
|
} else {
|
||||||
|
CommandUtil.errorTranslatable("smod.argument.offlinePlayer.fail.notCached");
|
||||||
|
throw new AssertionError(); // can't happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ArgumentType<String> getNativeType() {
|
||||||
|
return StringArgumentType.word();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package de.shiewk.smoderation.paper.command.argument;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class PlayerUUIDArgument implements CustomArgumentType.Converted<UUID, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull UUID convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||||
|
try {
|
||||||
|
return UUID.fromString(nativeType);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayerIfCached(nativeType);
|
||||||
|
if (player != null){
|
||||||
|
return player.getUniqueId();
|
||||||
|
} else {
|
||||||
|
CommandUtil.errorTranslatable("smod.argument.uuid.fail.notCached");
|
||||||
|
throw new UnknownError(); // can't happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ArgumentType<String> getNativeType() {
|
||||||
|
return StringArgumentType.word();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||||
|
Bukkit.getOnlinePlayers()
|
||||||
|
.stream()
|
||||||
|
.map(Player::getName)
|
||||||
|
.filter(name -> name.toLowerCase().startsWith(builder.getRemainingLowerCase()))
|
||||||
|
.forEach(builder::suggest);
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+8
-8
@@ -1,7 +1,7 @@
|
|||||||
package de.shiewk.smoderation.event;
|
package de.shiewk.smoderation.paper.event;
|
||||||
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -11,20 +11,20 @@ public class PunishmentIssueEvent extends Event implements Cancellable {
|
|||||||
private static final HandlerList handlerList = new HandlerList();
|
private static final HandlerList handlerList = new HandlerList();
|
||||||
|
|
||||||
private final Punishment punishment;
|
private final Punishment punishment;
|
||||||
private final PunishmentContainer container;
|
private final PunishmentManager manager;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public PunishmentIssueEvent(Punishment punishment, PunishmentContainer container) {
|
public PunishmentIssueEvent(Punishment punishment, PunishmentManager manager) {
|
||||||
this.punishment = punishment;
|
this.punishment = punishment;
|
||||||
this.container = container;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Punishment getPunishment() {
|
public Punishment getPunishment() {
|
||||||
return punishment;
|
return punishment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PunishmentContainer getContainer() {
|
public PunishmentManager getPunishmentManager() {
|
||||||
return container;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package de.shiewk.smoderation.paper.event;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class VanishToggleEvent extends PlayerEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlerList = new HandlerList();
|
||||||
|
|
||||||
|
private final boolean state;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public VanishToggleEvent(Player player, boolean state) {
|
||||||
|
super(player);
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return handlerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package de.shiewk.smoderation.paper.input;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.title.Title;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.PRIMARY_COLOR;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public class ChatInput {
|
||||||
|
private final Player player;
|
||||||
|
private final Component prompt;
|
||||||
|
private final Consumer<Component> action;
|
||||||
|
private int remainingTicks;
|
||||||
|
|
||||||
|
private ChatInput(@NotNull Player player, @NotNull Component prompt, @NotNull Consumer<Component> action, int remainingSeconds){
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
Objects.requireNonNull(prompt);
|
||||||
|
Objects.requireNonNull(player);
|
||||||
|
this.player = player;
|
||||||
|
this.prompt = prompt;
|
||||||
|
this.action = action;
|
||||||
|
this.remainingTicks = remainingSeconds * 20 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tickAll() {
|
||||||
|
runningInputs.values().forEach(ChatInput::tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick(){
|
||||||
|
remainingTicks--;
|
||||||
|
if (remainingTicks <= 0){
|
||||||
|
runningInputs.remove(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (remainingTicks % 20 == 0){
|
||||||
|
player.showTitle(Title.title(
|
||||||
|
translatable("smod.chatInput.remainingTime", text(getRemainingTicks() / 20)),
|
||||||
|
getPrompt(),
|
||||||
|
Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ZERO)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final static ConcurrentHashMap<Player, ChatInput> runningInputs = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static void prompt(Player player, Consumer<Component> consumer, Component prompt, int timeSeconds){
|
||||||
|
runningInputs.put(player, new ChatInput(player, prompt, consumer, timeSeconds));
|
||||||
|
player.sendMessage(prompt.colorIfAbsent(PRIMARY_COLOR));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getPrompt() {
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Consumer<Component> getAction() {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRemainingTicks() {
|
||||||
|
return remainingTicks;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package de.shiewk.smoderation.paper.input;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.input.ChatInput.runningInputs;
|
||||||
|
|
||||||
|
public class ChatInputListener implements Listener {
|
||||||
|
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAsyncChat(AsyncChatEvent event){
|
||||||
|
final ChatInput input = runningInputs.remove(event.getPlayer());
|
||||||
|
if (input != null){
|
||||||
|
event.setCancelled(true);
|
||||||
|
input.getAction().accept(event.message());
|
||||||
|
event.getPlayer().clearTitle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
runningInputs.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
|
public interface AutoUpdatingCustomInventory extends CustomInventory { }
|
||||||
+20
-18
@@ -1,5 +1,6 @@
|
|||||||
package de.shiewk.smoderation.inventory;
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -11,37 +12,38 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.inventory.CustomInventory.renderComponent;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
public class ConfirmationInventory implements CustomInventory {
|
public class ConfirmationInventory implements CustomInventory {
|
||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final String prompt;
|
private final Component prompt;
|
||||||
private final ItemStack yesStack;
|
|
||||||
private final ItemStack noStack;
|
|
||||||
private final Runnable onAccept;
|
private final Runnable onAccept;
|
||||||
private final Runnable onReject;
|
private final Runnable onReject;
|
||||||
private final boolean reversed;
|
|
||||||
|
|
||||||
public ConfirmationInventory(Player player, String prompt, Runnable onAccept, Runnable onReject, boolean reversed) {
|
public ConfirmationInventory(Player player, Component prompt, Runnable onAccept, Runnable onReject) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.prompt = prompt;
|
this.prompt = prompt;
|
||||||
this.onAccept = onAccept;
|
this.onAccept = onAccept;
|
||||||
this.onReject = onReject;
|
this.onReject = onReject;
|
||||||
this.reversed = reversed;
|
inventory = Bukkit.createInventory(this, InventoryType.HOPPER, this.prompt);
|
||||||
inventory = Bukkit.createInventory(this, InventoryType.HOPPER, Component.text(this.prompt));
|
|
||||||
yesStack = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
|
|
||||||
noStack = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
yesStack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Yes").color(NamedTextColor.GREEN))));
|
ItemStack accept = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
|
||||||
noStack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("No").color(NamedTextColor.RED))));
|
|
||||||
ItemStack confirmation = new ItemStack(Material.PAPER);
|
ItemStack confirmation = new ItemStack(Material.PAPER);
|
||||||
confirmation.editMeta(meta -> meta.displayName(applyFormatting(Component.text(prompt).color(NamedTextColor.GOLD))));
|
ItemStack reject = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||||
|
|
||||||
inventory.setItem(reversed ? 4 : 0, noStack);
|
accept.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, applyFormatting(translatable("smod.confirm.yes"))));
|
||||||
|
confirmation.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, prompt.colorIfAbsent(NamedTextColor.GOLD)));
|
||||||
|
reject.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, applyFormatting(translatable("smod.confirm.no"))));
|
||||||
|
|
||||||
|
inventory.setItem(0, accept);
|
||||||
inventory.setItem(2, confirmation);
|
inventory.setItem(2, confirmation);
|
||||||
inventory.setItem(reversed ? 0 : 4, yesStack);
|
inventory.setItem(4, reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,11 +53,11 @@ public class ConfirmationInventory implements CustomInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
public void click(InventoryClickEvent event) {
|
||||||
if (yesStack.equals(stack)){
|
if (event.getSlot() == 0){
|
||||||
inventory.close();
|
inventory.close();
|
||||||
onAccept.run();
|
onAccept.run();
|
||||||
} else if (noStack.equals(stack)) {
|
} else if (event.getSlot() == 4) {
|
||||||
inventory.close();
|
inventory.close();
|
||||||
onReject.run();
|
onReject.run();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import net.kyori.adventure.translation.GlobalTranslator;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CustomInventory extends InventoryHolder {
|
||||||
|
|
||||||
|
void refresh();
|
||||||
|
void open();
|
||||||
|
void click(InventoryClickEvent event);
|
||||||
|
|
||||||
|
default ItemStack createEmptyStack(){
|
||||||
|
ItemStack stack = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
||||||
|
stack.editMeta(meta -> meta.displayName(Component.empty()));
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
default Component applyFormatting(Component component){
|
||||||
|
return component.decoration(TextDecoration.ITALIC, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Component renderComponent(Player viewer, Component component){
|
||||||
|
Component render = GlobalTranslator.render(component, viewer.locale());
|
||||||
|
List<Component> oldChildren = render.children();
|
||||||
|
List<Component> newChildren = new ObjectArrayList<>(oldChildren.size());
|
||||||
|
for (Component oldChild : oldChildren) {
|
||||||
|
Component e = renderComponent(viewer, oldChild);
|
||||||
|
newChildren.add(e);
|
||||||
|
}
|
||||||
|
return render.children(newChildren);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class InvSeeEquipmentInventory implements AutoUpdatingCustomInventory {
|
||||||
|
private final HumanEntity viewer;
|
||||||
|
private final HumanEntity subject;
|
||||||
|
private final Inventory inventory = Bukkit.createInventory(this, InventoryType.HOPPER, text("Player equipment"));
|
||||||
|
private boolean changing = false;
|
||||||
|
|
||||||
|
public InvSeeEquipmentInventory(HumanEntity viewer, HumanEntity subject) {
|
||||||
|
this.viewer = viewer;
|
||||||
|
this.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
if (!changing){
|
||||||
|
final EntityEquipment equipment = subject.getEquipment();
|
||||||
|
inventory.setItem(0, equipment.getHelmet());
|
||||||
|
inventory.setItem(1, equipment.getChestplate());
|
||||||
|
inventory.setItem(2, equipment.getLeggings());
|
||||||
|
inventory.setItem(3, equipment.getBoots());
|
||||||
|
inventory.setItem(4, equipment.getItemInOffHand());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() {
|
||||||
|
refresh();
|
||||||
|
viewer.openInventory(getInventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(InventoryClickEvent event) {
|
||||||
|
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||||
|
event.setCancelled(false);
|
||||||
|
changing = true;
|
||||||
|
SchedulerUtil.scheduleGlobal(SModerationPaper.PLUGIN, () -> {
|
||||||
|
changing = false;
|
||||||
|
final EntityEquipment equipment = subject.getEquipment();
|
||||||
|
equipment.setHelmet(inventory.getItem(0));
|
||||||
|
equipment.setChestplate(inventory.getItem(1));
|
||||||
|
equipment.setLeggings(inventory.getItem(2));
|
||||||
|
equipment.setBoots(inventory.getItem(3));
|
||||||
|
equipment.setItemInOffHand(inventory.getItem(4));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class InvSeeInventory implements AutoUpdatingCustomInventory {
|
||||||
|
private final HumanEntity viewer;
|
||||||
|
private final HumanEntity subject;
|
||||||
|
private final Inventory subjectInventory;
|
||||||
|
private final Inventory inventory;
|
||||||
|
private boolean changing = false;
|
||||||
|
|
||||||
|
public InvSeeInventory(HumanEntity viewer, HumanEntity subject) {
|
||||||
|
this.viewer = viewer;
|
||||||
|
this.subject = subject;
|
||||||
|
this.subjectInventory = subject.getInventory();
|
||||||
|
this.inventory = Bukkit.createInventory(this, 36, text("Player inventory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
if (!changing){
|
||||||
|
loadContents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadContents() {
|
||||||
|
for (int i = 0; i < inventory.getSize(); i++) {
|
||||||
|
inventory.setItem(i, subjectInventory.getItem(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() {
|
||||||
|
refresh();
|
||||||
|
viewer.openInventory(getInventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(InventoryClickEvent event) {
|
||||||
|
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||||
|
event.setCancelled(false);
|
||||||
|
changing = true;
|
||||||
|
SchedulerUtil.scheduleGlobal(SModerationPaper.PLUGIN, () -> {
|
||||||
|
changing = false;
|
||||||
|
applyChanges();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyChanges() {
|
||||||
|
for (int i = 0; i < inventory.getSize(); i++) {
|
||||||
|
subjectInventory.setItem(i, inventory.getItem(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-19
@@ -1,31 +1,40 @@
|
|||||||
package de.shiewk.smoderation.inventory;
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Data Component API
|
||||||
public abstract class PageableCustomInventory implements CustomInventory {
|
public abstract class PageableCustomInventory implements CustomInventory {
|
||||||
public abstract int lastPage();
|
|
||||||
public abstract void switchPage();
|
protected final int prevSlot, nextSlot;
|
||||||
private ItemStack previousStack = null;
|
|
||||||
private ItemStack nextStack = null;
|
|
||||||
private int page = 0;
|
private int page = 0;
|
||||||
|
|
||||||
|
public PageableCustomInventory(int prevSlot, int nextSlot) {
|
||||||
|
this.prevSlot = prevSlot;
|
||||||
|
this.nextSlot = nextSlot;
|
||||||
|
}
|
||||||
|
|
||||||
public int getPage(){
|
public int getPage(){
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract int lastPage();
|
||||||
|
public abstract void switchPage();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
public void click(InventoryClickEvent event) {
|
||||||
if (stack != null){
|
if (event.getSlot() == prevSlot) {
|
||||||
if (stack.equals(previousStack)){
|
previousPage();
|
||||||
previousPage();
|
} else if (event.getSlot() == nextSlot) {
|
||||||
} else if (stack.equals(nextStack)) {
|
nextPage();
|
||||||
nextPage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,23 +54,21 @@ public abstract class PageableCustomInventory implements CustomInventory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createPreviousPageStack(){
|
public ItemStack createPreviousPageStack(Player viewer){
|
||||||
boolean allowed = page > 0;
|
boolean allowed = page > 0;
|
||||||
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
||||||
int skip = allowed ? page : page+1;
|
int skip = allowed ? page : page+1;
|
||||||
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
||||||
stack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Previous page (%s/%s)".formatted(skip, lastPage()+1)).color(color))));
|
stack.setData(DataComponentTypes.ITEM_NAME, CustomInventory.renderComponent(viewer, applyFormatting(translatable("smod.inventory.previous", text(skip), text(lastPage()+1)).color(color))));
|
||||||
previousStack = stack;
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createNextPageStack(){
|
public ItemStack createNextPageStack(Player viewer){
|
||||||
boolean allowed = page < lastPage();
|
boolean allowed = page < lastPage();
|
||||||
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
||||||
int skip = allowed ? page+2 : page+1;
|
int skip = allowed ? page+2 : page+1;
|
||||||
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
||||||
stack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Next page (%s/%s)".formatted(skip, lastPage()+1)).color(color))));
|
stack.setData(DataComponentTypes.ITEM_NAME, CustomInventory.renderComponent(viewer, applyFormatting(translatable("smod.inventory.next", text(skip), text(lastPage()+1)).color(color))));
|
||||||
nextStack = stack;
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,444 @@
|
|||||||
|
package de.shiewk.smoderation.paper.inventory;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||||
|
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||||
|
import de.shiewk.smoderation.paper.SkinTextureProvider;
|
||||||
|
import de.shiewk.smoderation.paper.input.ChatInput;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||||
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
|
import io.papermc.paper.datacomponent.item.ItemLore;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||||
|
import static de.shiewk.smoderation.paper.inventory.CustomInventory.renderComponent;
|
||||||
|
import static net.kyori.adventure.text.Component.*;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API, Paper Data Component API
|
||||||
|
public class SModMenu extends PageableCustomInventory {
|
||||||
|
|
||||||
|
public enum Filter {
|
||||||
|
ACTIVE(translatable("smod.menu.filter.active"), p -> p instanceof TimedPunishment timed && timed.isActive()),
|
||||||
|
OLD(translatable("smod.menu.filter.expired"), p -> !(p instanceof TimedPunishment timed && timed.isActive())),
|
||||||
|
ALL(translatable("smod.menu.filter.all"), p -> true);
|
||||||
|
|
||||||
|
public static final Material ICON = Material.HOPPER;
|
||||||
|
|
||||||
|
public final Component name;
|
||||||
|
public final Predicate<Punishment> filter;
|
||||||
|
Filter(Component name, Predicate<Punishment> filter) {
|
||||||
|
this.name = name;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Sort {
|
||||||
|
EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p instanceof TimedPunishment timed ? timed.getExpiry() : p.getTimestamp())),
|
||||||
|
TIME(translatable("smod.menu.sort.time"), Comparator.comparingLong(Punishment::getTimestamp)),
|
||||||
|
PLAYER_NAME(translatable("smod.menu.sort.playerName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getTargetID()), PlayerUtil.offlinePlayerName(p2.getTargetID()))),
|
||||||
|
MODERATOR_NAME(translatable("smod.menu.sort.moderatorName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getIssuerID()), PlayerUtil.offlinePlayerName(p2.getIssuerID())));
|
||||||
|
|
||||||
|
public static final Material ICON = Material.COMPARATOR;
|
||||||
|
|
||||||
|
public final Component name;
|
||||||
|
public final Comparator<Punishment> comparator;
|
||||||
|
|
||||||
|
Sort(Component name, Comparator<Punishment> comparator) {
|
||||||
|
this.name = name;
|
||||||
|
this.comparator = comparator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Inventory inventory;
|
||||||
|
private final Player player;
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
private final Int2ObjectArrayMap<Punishment> slotMap = new Int2ObjectArrayMap<>(45);
|
||||||
|
private List<Punishment> punishments;
|
||||||
|
private int sort = 0;
|
||||||
|
private int filter = 0;
|
||||||
|
private int type = -1;
|
||||||
|
private int rfId = 0;
|
||||||
|
private String searchQuery = null;
|
||||||
|
|
||||||
|
public SModMenu(Player player, PunishmentManager punishmentManager) {
|
||||||
|
super(45, 53);
|
||||||
|
this.player = player;
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
this.inventory = Bukkit.createInventory(this, 54, translatable("smod.menu"));
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sort getSort(){
|
||||||
|
return Sort.values()[sort];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Filter getFilter(){
|
||||||
|
return Filter.values()[filter];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType(){
|
||||||
|
return type == -1 ? null : punishmentManager.getRegisteredTypes().get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reload() {
|
||||||
|
try {
|
||||||
|
this.punishments = this.punishmentManager.getAll()
|
||||||
|
.stream()
|
||||||
|
.filter(getFilter().filter)
|
||||||
|
.filter(p -> getType() == null || Objects.equals(p.getType(), getType()))
|
||||||
|
.filter(p -> p.matchesSearchQuery(searchQuery))
|
||||||
|
.sorted(getSort().comparator).toList();
|
||||||
|
} catch (IOException e) {
|
||||||
|
this.punishments = List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void promptSearchQuery(){
|
||||||
|
SchedulerUtil.scheduleForEntity(PLUGIN, player, player::closeInventory);
|
||||||
|
ChatInput.prompt(player, component -> {
|
||||||
|
if (component instanceof TextComponent text){
|
||||||
|
this.searchQuery = text.content();
|
||||||
|
// chat event is async
|
||||||
|
SchedulerUtil.scheduleForEntity(PLUGIN, player, this::open);
|
||||||
|
}
|
||||||
|
}, translatable("smod.menu.search.query").color(SECONDARY_COLOR), 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int lastPage() {
|
||||||
|
return Math.max((punishments.size() - 1) / 45, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cycleFilter(boolean backwards){
|
||||||
|
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||||
|
if (backwards){
|
||||||
|
if (filter <= 0){
|
||||||
|
filter = Filter.values().length-1;
|
||||||
|
} else {
|
||||||
|
filter--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (filter >= Filter.values().length-1){
|
||||||
|
filter = 0;
|
||||||
|
} else {
|
||||||
|
filter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reload();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cycleSort(boolean backwards){
|
||||||
|
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||||
|
if (backwards){
|
||||||
|
if (sort <= 0){
|
||||||
|
sort = Sort.values().length-1;
|
||||||
|
} else {
|
||||||
|
sort--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sort >= Sort.values().length-1){
|
||||||
|
sort = 0;
|
||||||
|
} else {
|
||||||
|
sort++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reload();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cycleType(boolean backwards){
|
||||||
|
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||||
|
if (backwards){
|
||||||
|
if (type <= -1){
|
||||||
|
type = punishmentManager.getRegisteredTypes().size()-1;
|
||||||
|
} else {
|
||||||
|
type--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (type >= punishmentManager.getRegisteredTypes().size()-1){
|
||||||
|
type = -1;
|
||||||
|
} else {
|
||||||
|
type++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reload();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void switchPage() {
|
||||||
|
player.playSound(player, Sound.BLOCK_STONE_HIT, 0.75f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createFilterItem(){
|
||||||
|
final Filter filter = getFilter();
|
||||||
|
final ItemStack stack = new ItemStack(Filter.ICON);
|
||||||
|
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.filter", filter.name).color(PRIMARY_COLOR)));
|
||||||
|
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||||
|
|
||||||
|
loreBuilder.addLine(empty());
|
||||||
|
for (Filter value : Filter.values()) {
|
||||||
|
final boolean selected = filter == value;
|
||||||
|
Component filterText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value.name)));
|
||||||
|
loreBuilder.addLine(filterText);
|
||||||
|
}
|
||||||
|
loreBuilder.addLine(empty());
|
||||||
|
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.filter.switch", NamedTextColor.GOLD))));
|
||||||
|
|
||||||
|
stack.setData(DataComponentTypes.LORE, loreBuilder.build());
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createTypeItem(){
|
||||||
|
final String type = getType();
|
||||||
|
final ItemStack stack = new ItemStack(Material.CHEST);
|
||||||
|
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + type)))).color(PRIMARY_COLOR));
|
||||||
|
|
||||||
|
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||||
|
loreBuilder.addLine(empty());
|
||||||
|
final Consumer<String> addToLore = value -> {
|
||||||
|
final boolean selected = Objects.equals(type, value);
|
||||||
|
Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + value))));
|
||||||
|
loreBuilder.addLine(typeText);
|
||||||
|
};
|
||||||
|
addToLore.accept(null);
|
||||||
|
for (String value : punishmentManager.getRegisteredTypes()) {
|
||||||
|
addToLore.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
loreBuilder.addLine(empty());
|
||||||
|
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.type.switch", NamedTextColor.GOLD))));
|
||||||
|
|
||||||
|
stack.setData(DataComponentTypes.LORE, loreBuilder);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createSortItem(){
|
||||||
|
final Sort sort = getSort();
|
||||||
|
final ItemStack stack = new ItemStack(Sort.ICON);
|
||||||
|
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.sort", sort.name).color(PRIMARY_COLOR)));
|
||||||
|
|
||||||
|
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||||
|
loreBuilder.addLine(empty());
|
||||||
|
|
||||||
|
for (Sort value : Sort.values()) {
|
||||||
|
final boolean selected = sort == value;
|
||||||
|
Component sortText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value.name)));
|
||||||
|
loreBuilder.addLine(sortText);
|
||||||
|
}
|
||||||
|
|
||||||
|
loreBuilder.addLine(empty());
|
||||||
|
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.sort.switch", NamedTextColor.GOLD))));
|
||||||
|
|
||||||
|
stack.setData(DataComponentTypes.LORE, loreBuilder);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createSearchItem(){
|
||||||
|
final ItemStack stack = new ItemStack(Material.FLOWER_BANNER_PATTERN);
|
||||||
|
|
||||||
|
try {
|
||||||
|
stack.setData(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP);
|
||||||
|
} catch (NoSuchFieldError e) {
|
||||||
|
// that component is no longer present under that name,
|
||||||
|
// we just create the stack without it instead of throwing
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.search", PRIMARY_COLOR)));
|
||||||
|
|
||||||
|
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||||
|
loreBuilder.addLines(List.of(
|
||||||
|
empty(),
|
||||||
|
renderComponent(player, applyFormatting(translatable("smod.menu.search.current", searchQuery == null ? translatable("smod.menu.search.none") : text('"' + searchQuery + '"'))).color(SECONDARY_COLOR)),
|
||||||
|
empty(),
|
||||||
|
renderComponent(player, applyFormatting(translatable("smod.menu.search.new", NamedTextColor.GOLD)))
|
||||||
|
));
|
||||||
|
if (searchQuery != null){
|
||||||
|
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.search.remove", NamedTextColor.GOLD))));
|
||||||
|
}
|
||||||
|
stack.setData(DataComponentTypes.LORE, loreBuilder);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<ItemStack> createPunishmentItem(Punishment punishment){
|
||||||
|
SkinTextureProvider provider = getTextureProvider();
|
||||||
|
if (provider != null) {
|
||||||
|
return provider.textureProperty(punishment.getTargetID())
|
||||||
|
.thenApply(texture -> {
|
||||||
|
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
stack.editMeta(meta -> {
|
||||||
|
if (meta instanceof SkullMeta skullMeta){
|
||||||
|
PlayerProfile profile = Bukkit.createProfile(punishment.getTargetID());
|
||||||
|
profile.setProperty(new ProfileProperty(
|
||||||
|
"textures",
|
||||||
|
texture
|
||||||
|
));
|
||||||
|
skullMeta.setPlayerProfile(profile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addPunishmentInfo(punishment, stack);
|
||||||
|
return stack;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
stack.editMeta(meta -> {
|
||||||
|
if (meta instanceof SkullMeta skullMeta){
|
||||||
|
try {
|
||||||
|
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.getTargetID()));
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.getTargetID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addPunishmentInfo(punishment, stack);
|
||||||
|
return CompletableFuture.completedFuture(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPunishmentInfo(Punishment punishment, ItemStack stack) {
|
||||||
|
stack.setData(DataComponentTypes.CUSTOM_NAME, renderComponent(player, applyFormatting(translatable("smod.punishment.name." + punishment.getType(), NamedTextColor.RED).decorate(TextDecoration.BOLD))));
|
||||||
|
ItemLore.Builder lore = ItemLore.lore();
|
||||||
|
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.player", text(PlayerUtil.offlinePlayerName(punishment.getTargetID()))))));
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.punishedBy", text(PlayerUtil.offlinePlayerName(punishment.getIssuerID()))))));
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.getTimestamp())))));
|
||||||
|
|
||||||
|
if (punishment instanceof TimedPunishment timed){
|
||||||
|
if (timed.isPermanent()){
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", translatable("smod.time.permanent")))));
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.never"))));
|
||||||
|
} else {
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(timed.getExpiry() - punishment.getTimestamp())))));
|
||||||
|
long remainingTime = timed.getExpiry() - System.currentTimeMillis();
|
||||||
|
if (remainingTime > 0){
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime)))));
|
||||||
|
} else {
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.past", TimeUtil.formatTimeLong(-remainingTime)))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.reason", text(punishment.getReason())))));
|
||||||
|
|
||||||
|
if (punishment instanceof TimedPunishment timed){
|
||||||
|
if (timed.wasCancelled()){
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.cancelled", text(PlayerUtil.offlinePlayerName(timed.getCancelledBy()))))));
|
||||||
|
} else if (timed.isActive()) {
|
||||||
|
if (player.hasPermission("smod.un" + punishment.getType())){
|
||||||
|
lore.addLine(empty());
|
||||||
|
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.click", NamedTextColor.GOLD))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stack.setData(DataComponentTypes.LORE, lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
int rfId = ++this.rfId;
|
||||||
|
while (getPage() > lastPage()){
|
||||||
|
previousPage();
|
||||||
|
}
|
||||||
|
inventory.clear();
|
||||||
|
slotMap.clear();
|
||||||
|
for (int i = 45; i < 54; i++) {
|
||||||
|
inventory.setItem(i, createEmptyStack());
|
||||||
|
}
|
||||||
|
inventory.setItem(prevSlot, createPreviousPageStack(player));
|
||||||
|
inventory.setItem(nextSlot, createNextPageStack(player));
|
||||||
|
inventory.setItem(47, createSearchItem());
|
||||||
|
inventory.setItem(48, createTypeItem());
|
||||||
|
inventory.setItem(50, createFilterItem());
|
||||||
|
inventory.setItem(51, createSortItem());
|
||||||
|
|
||||||
|
for (int i = 0; i < 45; i++) {
|
||||||
|
int ci = i + (getPage() * 45);
|
||||||
|
if (punishments.size() > ci){
|
||||||
|
final Punishment punishment = punishments.get(ci);
|
||||||
|
int slot = i;
|
||||||
|
slotMap.put(slot, punishment);
|
||||||
|
createPunishmentItem(punishment).thenAccept(item -> {
|
||||||
|
if (rfId != this.rfId) return;
|
||||||
|
inventory.setItem(slot, item);
|
||||||
|
}).exceptionally(x -> {
|
||||||
|
LOGGER.warn("Error creating punishment item", x);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
inventory.setItem(i, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(InventoryClickEvent event) {
|
||||||
|
super.click(event);
|
||||||
|
int slot = event.getSlot();
|
||||||
|
if (slot == 47) {
|
||||||
|
if (event.isRightClick() && searchQuery != null){
|
||||||
|
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.8f);
|
||||||
|
searchQuery = null;
|
||||||
|
reload();
|
||||||
|
refresh();
|
||||||
|
} else {
|
||||||
|
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 2f);
|
||||||
|
promptSearchQuery();
|
||||||
|
}
|
||||||
|
} else if (slot == 48) {
|
||||||
|
cycleType(event.isRightClick());
|
||||||
|
} else if (slot == 50) {
|
||||||
|
cycleFilter(event.isRightClick());
|
||||||
|
} else if (slot == 51) {
|
||||||
|
cycleSort(event.isRightClick());
|
||||||
|
} else {
|
||||||
|
Punishment punishment = slotMap.get(slot);
|
||||||
|
if (punishment instanceof TimedPunishment timed && timed.isActive()){
|
||||||
|
if (player.hasPermission("smod.un" + punishment.getType())) {
|
||||||
|
new ConfirmationInventory(player, translatable("smod.menu.cancelConfirmation"), () -> {
|
||||||
|
punishmentManager.cancel(timed, player.getUniqueId());
|
||||||
|
player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f);
|
||||||
|
this.open();
|
||||||
|
}, this::open).open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() {
|
||||||
|
reload();
|
||||||
|
refresh();
|
||||||
|
player.openInventory(this.inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public class CacheListener implements Listener {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public CacheListener(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
try {
|
||||||
|
punishmentManager.loadToCache(event.getPlayer().getUniqueId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Failed to load punishments", e);
|
||||||
|
event.getPlayer().kick(translatable("mco.errorMessage.connectionFailure"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
punishmentManager.removeFromCache(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.inventory.AutoUpdatingCustomInventory;
|
||||||
|
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
|
|
||||||
|
public class CustomInventoryListener implements Listener {
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onInventoryClick(InventoryClickEvent event){
|
||||||
|
if (event.getInventory().getHolder() instanceof CustomInventory customInventory){
|
||||||
|
event.setCancelled(true);
|
||||||
|
customInventory.click(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onInventoryDrag(InventoryDragEvent event){
|
||||||
|
if (event.getInventory().getHolder() instanceof CustomInventory){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tickAllPaper(){
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
tickForPlayer(onlinePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tickForPlayer(Player onlinePlayer) {
|
||||||
|
if (onlinePlayer.getOpenInventory().getTopInventory().getHolder() instanceof AutoUpdatingCustomInventory ci) {
|
||||||
|
ci.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
public class EnderchestSeeListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event){
|
||||||
|
final Inventory clicked = event.getView().getTopInventory();
|
||||||
|
if (!(clicked instanceof PlayerInventory)){
|
||||||
|
final InventoryHolder holder = clicked.getHolder();
|
||||||
|
if (holder instanceof HumanEntity humanHolder && humanHolder.getEnderChest().equals(clicked) && !humanHolder.equals(event.getWhoClicked())){
|
||||||
|
if (!event.getWhoClicked().hasPermission("smod.enderchestsee.modify")){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
|
public class FoliaInventoryUpdatingListener implements Listener {
|
||||||
|
|
||||||
|
public static final String METADATA_KEY = "smod_invtick";
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ScheduledTask task = player.getScheduler().runAtFixedRate(
|
||||||
|
SModerationPaper.PLUGIN,
|
||||||
|
t -> CustomInventoryListener.tickForPlayer(player),
|
||||||
|
null,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
player.setMetadata(METADATA_KEY, new FixedMetadataValue(
|
||||||
|
SModerationPaper.PLUGIN,
|
||||||
|
task
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
for (MetadataValue meta : event.getPlayer().getMetadata("smod_invtick")) {
|
||||||
|
if (meta.getOwningPlugin() == SModerationPaper.PLUGIN) {
|
||||||
|
if (meta.value() instanceof ScheduledTask task) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class InvSeeListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event){
|
||||||
|
final Inventory clicked = event.getView().getTopInventory();
|
||||||
|
if (clicked instanceof PlayerInventory inventory){
|
||||||
|
final HumanEntity holder = inventory.getHolder();
|
||||||
|
if (Objects.equals(holder, event.getWhoClicked())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!event.getWhoClicked().hasPermission("smod.invsee.modify")){
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (holder != null) {
|
||||||
|
if (holder.hasPermission("smod.invsee.preventmodify")){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||||
|
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.PRIMARY_COLOR;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public class PunishmentListener implements Listener {
|
||||||
|
|
||||||
|
private final PunishmentManager punishmentManager;
|
||||||
|
|
||||||
|
public PunishmentListener(PunishmentManager punishmentManager) {
|
||||||
|
this.punishmentManager = punishmentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onPlayerLogin(AsyncPlayerPreLoginEvent event){
|
||||||
|
List<Punishment> list = punishmentManager.byTargetUUID(event.getUniqueId(), p -> p instanceof Ban ban && ban.isActive());
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, list.getFirst().infoMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onPlayerChat(AsyncChatEvent event){
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(list.getFirst().infoMessage().colorIfAbsent(PRIMARY_COLOR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
|
||||||
|
if (!list.isEmpty()) { // Player is muted
|
||||||
|
List<String> forbiddenCommands = SModerationPaper.config().getStringList("muted-forbidden-commands");
|
||||||
|
final String message = event.getMessage();
|
||||||
|
if (forbiddenCommands.stream().anyMatch(str ->
|
||||||
|
message.toLowerCase().startsWith("/"+str.toLowerCase()+" ")
|
||||||
|
|| message.toLowerCase().startsWith(str.toLowerCase()+" ")
|
||||||
|
)){
|
||||||
|
Bukkit.getConsoleSender().sendMessage(player.getName() + " tried to run forbidden command while muted");
|
||||||
|
player.sendMessage(translatable("smod.punishment.playerMessage.mute.chat", PRIMARY_COLOR));
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public class SocialSpyListener implements Listener {
|
||||||
|
|
||||||
|
private static final NamespacedKey SAVE_KEY = new NamespacedKey("smoderation", "socialspy");
|
||||||
|
private static final ObjectArrayList<CommandSender> targets = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
public static boolean toggle(CommandSender sender) {
|
||||||
|
boolean enabledNow = isEnabled(sender);
|
||||||
|
if (enabledNow){
|
||||||
|
targets.remove(sender);
|
||||||
|
if (sender instanceof Player player){
|
||||||
|
player.getPersistentDataContainer().set(SAVE_KEY, PersistentDataType.BOOLEAN, false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
targets.add(sender);
|
||||||
|
if (sender instanceof Player player){
|
||||||
|
player.getPersistentDataContainer().set(SAVE_KEY, PersistentDataType.BOOLEAN, true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
final PersistentDataContainer pdc = event.getPlayer().getPersistentDataContainer();
|
||||||
|
if (Boolean.TRUE.equals(pdc.get(SAVE_KEY, PersistentDataType.BOOLEAN))){
|
||||||
|
targets.add(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
targets.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled(CommandSender sender){
|
||||||
|
return targets.contains(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerSendCommand(PlayerCommandPreprocessEvent event){
|
||||||
|
List<String> socialSpyCommands = SModerationPaper.config().getStringList("socialspy-commands");
|
||||||
|
final String message = event.getMessage();
|
||||||
|
if (socialSpyCommands.stream().anyMatch(str ->
|
||||||
|
message.toLowerCase().startsWith("/"+str.toLowerCase()+" ")
|
||||||
|
|| message.toLowerCase().startsWith(str.toLowerCase()+" ")
|
||||||
|
)){
|
||||||
|
SocialSpyListener.command(event.getPlayer(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void command(Player player, String command){
|
||||||
|
for (CommandSender target : targets) {
|
||||||
|
target.sendMessage(translatable("smod.socialspy.command", player.teamDisplayName(), text(command)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package de.shiewk.smoderation.paper.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.command.VanishCommand;
|
||||||
|
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||||
|
import io.papermc.paper.event.entity.WardenAngerChangeEvent;
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.SECONDARY_COLOR;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public class VanishListener implements Listener {
|
||||||
|
|
||||||
|
public static final Component PREFIX = text("[VANISH] ").color(SECONDARY_COLOR);
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
if (VanishCommand.isVanished(player)){
|
||||||
|
player.getPersistentDataContainer().set(VanishCommand.KEY_VANISHED, PersistentDataType.BOOLEAN, true);
|
||||||
|
VanishCommand.toggleVanishSilent(player, true);
|
||||||
|
Component message = event.quitMessage();
|
||||||
|
event.quitMessage(null);
|
||||||
|
if (message != null){
|
||||||
|
broadcast(message.color(null));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.getPersistentDataContainer().remove(VanishCommand.KEY_VANISHED);
|
||||||
|
}
|
||||||
|
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||||
|
// to clean up visibility status
|
||||||
|
player.hideEntity(SModerationPaper.PLUGIN, vanishedPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
if (player.getPersistentDataContainer().has(VanishCommand.KEY_VANISHED)){
|
||||||
|
boolean state = VanishCommand.toggleVanishSilent(player, false);
|
||||||
|
if (state){
|
||||||
|
Component message = event.joinMessage();
|
||||||
|
event.joinMessage(null);
|
||||||
|
if (message != null){
|
||||||
|
broadcast(message.color(null));
|
||||||
|
}
|
||||||
|
SchedulerUtil.scheduleForEntity(SModerationPaper.PLUGIN, player, () -> {
|
||||||
|
player.sendMessage(translatable("smod.command.vanish.stillEnabled"));
|
||||||
|
player.playSound(Sound.sound(
|
||||||
|
Key.key("minecraft", "block.beacon.power_select"),
|
||||||
|
Sound.Source.MASTER,
|
||||||
|
1f,
|
||||||
|
1f
|
||||||
|
), player);
|
||||||
|
}, 20);
|
||||||
|
} else {
|
||||||
|
player.getPersistentDataContainer().remove(VanishCommand.KEY_VANISHED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SchedulerUtil.scheduleForEntity(SModerationPaper.PLUGIN, player, () -> {
|
||||||
|
if (player.hasPermission("smod.vanish.see")){
|
||||||
|
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||||
|
// to show visible vanished players
|
||||||
|
player.showEntity(SModerationPaper.PLUGIN, vanishedPlayer);
|
||||||
|
}
|
||||||
|
VanishCommand.listVanishedPlayersTo(player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerDeath(PlayerDeathEvent event){
|
||||||
|
final Component message = event.deathMessage();
|
||||||
|
if (VanishCommand.isVanished(event.getPlayer()) && message != null){
|
||||||
|
event.deathMessage(null);
|
||||||
|
broadcast(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onEntityTarget(EntityTargetEvent event){
|
||||||
|
if (event.getTarget() instanceof Player pl && VanishCommand.isVanished(pl)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onEntityTarget(WardenAngerChangeEvent event){
|
||||||
|
if (event.getTarget() instanceof Player pl && VanishCommand.isVanished(pl)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onAdvancementDone(PlayerAdvancementDoneEvent event){
|
||||||
|
Player pl = event.getPlayer();
|
||||||
|
Component message = event.message();
|
||||||
|
if (VanishCommand.isVanished(pl) && message != null) {
|
||||||
|
broadcast(message);
|
||||||
|
event.message(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void broadcast(Component message) {
|
||||||
|
Component result = PREFIX.append(message);
|
||||||
|
Bukkit.getConsoleSender().sendMessage(result);
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||||
|
onlinePlayer.sendMessage(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Ban extends TimedPunishment {
|
||||||
|
|
||||||
|
public Ban(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
|
||||||
|
super(id, "ban", timestamp, issuer, target, reason, duration, cancelledBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ban(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration) {
|
||||||
|
this(id, timestamp, issuer, target, reason, duration, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements PunishmentFactory<Ban> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Ban deserialize(SerializationHelper helper) {
|
||||||
|
return new Ban(
|
||||||
|
helper.getUUID("id"),
|
||||||
|
helper.getLong("timestamp"),
|
||||||
|
helper.getUUID("issuer"),
|
||||||
|
helper.getUUID("target"),
|
||||||
|
helper.getString("reason"),
|
||||||
|
helper.getLong("duration"),
|
||||||
|
helper.getUUID("cancelledBy", null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processIssue() {
|
||||||
|
super.processIssue();
|
||||||
|
final Player player = Bukkit.getPlayer(getTargetID());
|
||||||
|
if (player != null) {
|
||||||
|
player.kick(CustomInventory.renderComponent(player, infoMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Kick extends Punishment {
|
||||||
|
|
||||||
|
public Kick(UUID id, long timestamp, UUID issuer, UUID target, String reason) {
|
||||||
|
super(id, "kick", timestamp, issuer, target, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements PunishmentFactory<Kick> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Kick deserialize(SerializationHelper helper) {
|
||||||
|
return new Kick(
|
||||||
|
helper.getUUID("id"),
|
||||||
|
helper.getLong("timestamp"),
|
||||||
|
helper.getUUID("issuer"),
|
||||||
|
helper.getUUID("target"),
|
||||||
|
helper.getString("reason")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processIssue() {
|
||||||
|
super.processIssue();
|
||||||
|
final Player player = Bukkit.getPlayer(getTargetID());
|
||||||
|
if (player != null) {
|
||||||
|
player.kick(CustomInventory.renderComponent(player, infoMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Mute extends TimedPunishment {
|
||||||
|
|
||||||
|
public Mute(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
|
||||||
|
super(id, "mute", timestamp, issuer, target, reason, duration, cancelledBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mute(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration) {
|
||||||
|
this(id, timestamp, issuer, target, reason, duration, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements PunishmentFactory<Mute> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Mute deserialize(SerializationHelper helper) {
|
||||||
|
return new Mute(
|
||||||
|
helper.getUUID("id"),
|
||||||
|
helper.getLong("timestamp"),
|
||||||
|
helper.getUUID("issuer"),
|
||||||
|
helper.getUUID("target"),
|
||||||
|
helper.getString("reason"),
|
||||||
|
helper.getLong("duration"),
|
||||||
|
helper.getUUID("cancelledBy", null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public abstract class Punishment {
|
||||||
|
|
||||||
|
protected final UUID id;
|
||||||
|
protected final String type;
|
||||||
|
protected final long timestamp;
|
||||||
|
protected final UUID issuer;
|
||||||
|
protected final UUID target;
|
||||||
|
protected final String reason;
|
||||||
|
|
||||||
|
protected Punishment(UUID id, String type, long timestamp, UUID issuer, UUID target, String reason) {
|
||||||
|
this.id = id;
|
||||||
|
this.type = type;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.issuer = issuer;
|
||||||
|
this.target = target;
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getIssuerID() {
|
||||||
|
return issuer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getTargetID() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSerializableProperties(SerializationHelper helper){
|
||||||
|
helper.putUUID("id", id);
|
||||||
|
helper.putString("type", type);
|
||||||
|
helper.putLong("timestamp", timestamp);
|
||||||
|
helper.putUUID("issuer", issuer);
|
||||||
|
helper.putUUID("target", target);
|
||||||
|
helper.putString("reason", reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesSearchQuery(String query){
|
||||||
|
if (query == null) return true;
|
||||||
|
query = query.toLowerCase();
|
||||||
|
return reason.toLowerCase().contains(query)
|
||||||
|
|| issuer.toString().equalsIgnoreCase(query)
|
||||||
|
|| target.toString().equalsIgnoreCase(query)
|
||||||
|
|| PlayerUtil.offlinePlayerName(issuer).toLowerCase().contains(query)
|
||||||
|
|| PlayerUtil.offlinePlayerName(target).toLowerCase().contains(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component infoMessage(){
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.playerMessage." + type,
|
||||||
|
text(PlayerUtil.offlinePlayerName(this.issuer)),
|
||||||
|
text(reason)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component adminMessage(){
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.broadcast." + type,
|
||||||
|
text(PlayerUtil.offlinePlayerName(target)),
|
||||||
|
text(PlayerUtil.offlinePlayerName(issuer)),
|
||||||
|
text(reason)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processIssue() {
|
||||||
|
CommandSender sender = PlayerUtil.senderByUUID(target);
|
||||||
|
if (sender != null) {
|
||||||
|
sender.sendMessage(infoMessage());
|
||||||
|
}
|
||||||
|
for (CommandSender target : getBroadcastTargets()) {
|
||||||
|
target.sendMessage(adminMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CommandSender> getBroadcastTargets() {
|
||||||
|
ObjectArrayList<CommandSender> senders = new ObjectArrayList<>();
|
||||||
|
senders.add(Bukkit.getConsoleSender());
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.hasPermission("smod.notifications")){
|
||||||
|
senders.add(onlinePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return List.copyOf(senders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID generateUUID() {
|
||||||
|
Random random = new Random();
|
||||||
|
return new UUID(System.currentTimeMillis(), random.nextLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public interface PunishmentFactory<T extends Punishment> {
|
||||||
|
|
||||||
|
@NotNull T deserialize(SerializationHelper helper);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.Strictness;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
|
||||||
|
|
||||||
|
public final class PunishmentManager {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PunishmentManager.class);
|
||||||
|
private final Object2ObjectArrayMap<String, PunishmentFactory<?>> typeRegistry = new Object2ObjectArrayMap<>(1);
|
||||||
|
private final ConcurrentHashMap<UUID, List<Punishment>> cache = new ConcurrentHashMap<>(1);
|
||||||
|
private final Object ioLock = new Object();
|
||||||
|
private final Path dataDir;
|
||||||
|
|
||||||
|
public PunishmentManager(Path dataDir) {
|
||||||
|
this.dataDir = dataDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path getTargetFile(UUID targetUUID){
|
||||||
|
return dataDir.resolve(targetUUID.toString().replace("-", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryIssue(Punishment punishment) {
|
||||||
|
try {
|
||||||
|
PunishmentIssueEvent event = new PunishmentIssueEvent(punishment, this);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()){
|
||||||
|
this.appendToSave(punishment);
|
||||||
|
punishment.processIssue();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Punishment> byTargetUUID(UUID target) {
|
||||||
|
List<Punishment> cached = cache.get(target);
|
||||||
|
if (cached != null) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
synchronized (ioLock) {
|
||||||
|
Path file = getTargetFile(target);
|
||||||
|
|
||||||
|
if (!Files.exists(file)) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
try (
|
||||||
|
BufferedReader reader = Files.newBufferedReader(file);
|
||||||
|
JsonReader json = new JsonReader(reader)
|
||||||
|
) {
|
||||||
|
json.setStrictness(Strictness.LENIENT);
|
||||||
|
Object2ObjectArrayMap<UUID, Punishment> punishments = new Object2ObjectArrayMap<>(0);
|
||||||
|
while (json.hasNext()){
|
||||||
|
JsonObject obj = SModerationPaper.gson.fromJson(json, JsonObject.class);
|
||||||
|
try {
|
||||||
|
SerializationHelper helper = new SerializationHelper(obj);
|
||||||
|
String type = helper.getString("type");
|
||||||
|
PunishmentFactory<?> factory = typeRegistry.get(type);
|
||||||
|
if (factory != null){
|
||||||
|
Punishment punishment = factory.deserialize(helper);
|
||||||
|
if (!punishment.getTargetID().equals(target)){
|
||||||
|
LOGGER.warn("Punishment saved in file for {} has incorrect target UUID {}", target, punishment.getTargetID());
|
||||||
|
} else {
|
||||||
|
punishments.put(punishment.getID(), punishment);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Unknown punishment type '{}'! Can not load.", type);
|
||||||
|
LOGGER.warn("Please check your configuration, or see file {} to remove corrupted data.", file);
|
||||||
|
LOGGER.warn(obj.toString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.warn("Could not deserialize punishment!", e);
|
||||||
|
LOGGER.warn("Please check file {} for corrupted data, or remove the corresponding line.", file);
|
||||||
|
LOGGER.warn(obj.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return List.copyOf(punishments.values());
|
||||||
|
} catch (IOException e){
|
||||||
|
throw new RuntimeException("Error while reading punishment file " + file, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Punishment> byTargetUUID(UUID target, Predicate<Punishment> filter) {
|
||||||
|
return byTargetUUID(target).stream().filter(filter).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Punishment> void registerType(String type, PunishmentFactory<T> factory){
|
||||||
|
if (typeRegistry.containsKey(type)) {
|
||||||
|
throw new IllegalStateException("Punishment type already registered: " + type);
|
||||||
|
}
|
||||||
|
typeRegistry.put(type, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRegisteredTypes(){
|
||||||
|
return List.copyOf(typeRegistry.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendToSave(Punishment punishment) throws IOException {
|
||||||
|
synchronized (ioLock) {
|
||||||
|
Path file = getTargetFile(punishment.getTargetID());
|
||||||
|
if (!Files.exists(file)) {
|
||||||
|
Files.createDirectories(dataDir);
|
||||||
|
Files.createFile(file);
|
||||||
|
}
|
||||||
|
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardOpenOption.APPEND)) {
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
punishment.addSerializableProperties(new SerializationHelper(json));
|
||||||
|
SModerationPaper.gson.toJson(json, writer);
|
||||||
|
writer.append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addToCachedList(punishment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<Punishment> getAll() throws IOException {
|
||||||
|
ObjectArrayList<Punishment> punishments = new ObjectArrayList<>();
|
||||||
|
synchronized (ioLock) {
|
||||||
|
try (Stream<Path> stream = Files.list(dataDir)) {
|
||||||
|
stream.forEach(file -> {
|
||||||
|
try {
|
||||||
|
String name = file.getFileName().toString();
|
||||||
|
UUID targetUUID = PlayerUtil.uuidFromString(name);
|
||||||
|
punishments.addAll(byTargetUUID(targetUUID));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Could not read punishment file {}", file, e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return List.copyOf(punishments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Punishment> getAll(Predicate<Punishment> filter) throws IOException {
|
||||||
|
return getAll().stream().filter(filter).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel(TimedPunishment punishment, UUID canceller) {
|
||||||
|
if (!punishment.isActive()){
|
||||||
|
throw new IllegalStateException("This punishment is not active");
|
||||||
|
}
|
||||||
|
punishment.cancel(canceller);
|
||||||
|
try {
|
||||||
|
appendToSave(punishment);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadToCache(UUID uuid) {
|
||||||
|
removeFromCache(uuid);
|
||||||
|
cache.put(uuid, byTargetUUID(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeFromCache(UUID uuid) {
|
||||||
|
cache.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToCachedList(Punishment punishment) {
|
||||||
|
cache.computeIfPresent(punishment.getTargetID(), (k, v) -> {
|
||||||
|
ObjectArrayList<Punishment> newList = new ObjectArrayList<>(v);
|
||||||
|
newList.add(punishment);
|
||||||
|
return List.copyOf(newList);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package de.shiewk.smoderation.paper.punishments;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.command.argument.DurationArgument;
|
||||||
|
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||||
|
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||||
|
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
public abstract class TimedPunishment extends Punishment {
|
||||||
|
|
||||||
|
protected final long duration;
|
||||||
|
protected UUID cancelledBy;
|
||||||
|
|
||||||
|
protected TimedPunishment(UUID id, String type, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
|
||||||
|
super(id, type, timestamp, issuer, target, reason);
|
||||||
|
this.duration = duration;
|
||||||
|
this.cancelledBy = cancelledBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getCancelledBy() {
|
||||||
|
return cancelledBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean wasCancelled(){
|
||||||
|
return cancelledBy != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive(){
|
||||||
|
return !wasCancelled() && (isPermanent() || System.currentTimeMillis() < getExpiry());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addSerializableProperties(SerializationHelper helper) {
|
||||||
|
super.addSerializableProperties(helper);
|
||||||
|
helper.putLong("duration", duration);
|
||||||
|
helper.putUUID("cancelledBy", cancelledBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matchesSearchQuery(String query) {
|
||||||
|
if (super.matchesSearchQuery(query)) return true;
|
||||||
|
query = query.toLowerCase();
|
||||||
|
return cancelledBy.toString().equalsIgnoreCase(query)
|
||||||
|
|| PlayerUtil.offlinePlayerName(cancelledBy).toLowerCase().contains(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component infoMessage(){
|
||||||
|
if (isPermanent()){
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.playerMessage." + type + ".permanent",
|
||||||
|
text(PlayerUtil.offlinePlayerName(this.issuer)),
|
||||||
|
text(reason)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.playerMessage." + type,
|
||||||
|
text(PlayerUtil.offlinePlayerName(this.issuer)),
|
||||||
|
text(reason),
|
||||||
|
TimeUtil.formatTimeLong(this.timestamp + this.duration - System.currentTimeMillis())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component adminMessage(){
|
||||||
|
if (isPermanent()){
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.broadcast." + type + ".permanent",
|
||||||
|
text(PlayerUtil.offlinePlayerName(target)),
|
||||||
|
text(PlayerUtil.offlinePlayerName(issuer)),
|
||||||
|
text(reason)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.broadcast." + type,
|
||||||
|
text(PlayerUtil.offlinePlayerName(target)),
|
||||||
|
text(PlayerUtil.offlinePlayerName(issuer)),
|
||||||
|
text(reason),
|
||||||
|
TimeUtil.formatTimeLong(this.duration)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component cancelMessage(){
|
||||||
|
return translatable(
|
||||||
|
"smod.punishment.cancel." + type,
|
||||||
|
text(PlayerUtil.offlinePlayerName(target)),
|
||||||
|
text(PlayerUtil.offlinePlayerName(cancelledBy))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getExpiry() {
|
||||||
|
return isPermanent() ? Long.MAX_VALUE : getTimestamp() + getDuration();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermanent() {
|
||||||
|
return getDuration() == DurationArgument.INFINITE_DURATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cancel(UUID canceller) {
|
||||||
|
if (this.cancelledBy != null){
|
||||||
|
throw new IllegalArgumentException("This punishment was already cancelled.");
|
||||||
|
}
|
||||||
|
this.cancelledBy = canceller;
|
||||||
|
for (CommandSender sender : getBroadcastTargets()) {
|
||||||
|
sender.sendMessage(cancelMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package de.shiewk.smoderation.paper.translation;
|
||||||
|
|
||||||
|
import com.google.gson.JsonIOException;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.translation.MiniMessageTranslationStore;
|
||||||
|
import net.kyori.adventure.translation.GlobalTranslator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TranslatorManager {
|
||||||
|
|
||||||
|
public final String resourcePath;
|
||||||
|
public final Locale[] availableLocales;
|
||||||
|
private final MiniMessageTranslationStore translationStore;
|
||||||
|
|
||||||
|
public TranslatorManager(Key key, MiniMessage miniMessage, String resourcePath, Locale[] availableLocales) {
|
||||||
|
this.resourcePath = resourcePath;
|
||||||
|
this.availableLocales = availableLocales;
|
||||||
|
this.translationStore = MiniMessageTranslationStore.create(key, miniMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(){
|
||||||
|
for (Locale locale : availableLocales) {
|
||||||
|
String s = locale.getLanguage() + "_" + locale.getCountry().toLowerCase();
|
||||||
|
try (InputStream stream = SModerationPaper.class.getClassLoader().getResourceAsStream(resourcePath + s + ".json")) {
|
||||||
|
if (stream == null) {
|
||||||
|
SModerationPaper.LOGGER.warn("Translations for {} not found or not accessible", locale);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> translationMap = SModerationPaper.gson.fromJson(new InputStreamReader(stream), new TypeToken<>(){});
|
||||||
|
translationStore.registerAll(locale, translationMap);
|
||||||
|
|
||||||
|
} catch (IOException | JsonSyntaxException | JsonIOException e) {
|
||||||
|
SModerationPaper.LOGGER.warn("Failed to load translations for {}", locale, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GlobalTranslator.translator().addSource(translationStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package de.shiewk.smoderation.paper.util;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.util.PlayerUtil.UUID_CONSOLE;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||||
|
public final class CommandUtil {
|
||||||
|
private CommandUtil(){}
|
||||||
|
|
||||||
|
public static Predicate<CommandSourceStack> requirePermission(String permission) {
|
||||||
|
return stack -> stack.getSender().hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Player getExecutingPlayer(CommandSourceStack stack) throws CommandSyntaxException {
|
||||||
|
CommandSender sender = stack.getSender();
|
||||||
|
if (sender instanceof Player player) {
|
||||||
|
return player;
|
||||||
|
} else {
|
||||||
|
errorTranslatable("smod.command.fail.players");
|
||||||
|
throw new UnknownError(); // can't happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID getSenderUUID(CommandSourceStack stack) throws CommandSyntaxException {
|
||||||
|
CommandSender sender = stack.getSender();
|
||||||
|
if (sender instanceof Player player) {
|
||||||
|
return player.getUniqueId();
|
||||||
|
} else if (sender instanceof ConsoleCommandSender){
|
||||||
|
return UUID_CONSOLE;
|
||||||
|
} else {
|
||||||
|
errorTranslatable("smod.command.fail.playersConsole");
|
||||||
|
throw new UnknownError(); // can't happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Player getPlayerSingle(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
|
||||||
|
@NotNull List<Player> players = context.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(context.getSource());
|
||||||
|
if (players.isEmpty()){
|
||||||
|
errorTranslatable("smod.command.fail.invalidPlayer");
|
||||||
|
}
|
||||||
|
return players.getFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(Component message) throws CommandSyntaxException {
|
||||||
|
throw new CommandSyntaxException(
|
||||||
|
new SimpleCommandExceptionType(null),
|
||||||
|
MessageComponentSerializer.message().serialize(message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void errorTranslatable(String key) throws CommandSyntaxException {
|
||||||
|
error(translatable(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void errorTranslatable(String key, Component...args) throws CommandSyntaxException {
|
||||||
|
error(translatable(key, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void errorTranslatable(String key, String...args) throws CommandSyntaxException {
|
||||||
|
errorTranslatable(key, Arrays.stream(args).map(Component::text).toArray(Component[]::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-18
@@ -1,7 +1,5 @@
|
|||||||
package de.shiewk.smoderation.util;
|
package de.shiewk.smoderation.paper.util;
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -10,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class PlayerUtil {
|
public final class PlayerUtil {
|
||||||
private PlayerUtil(){}
|
private PlayerUtil(){}
|
||||||
|
|
||||||
public static final UUID UUID_CONSOLE = new UUID(0, 0);
|
public static final UUID UUID_CONSOLE = new UUID(0, 0);
|
||||||
@@ -23,20 +21,6 @@ public abstract class PlayerUtil {
|
|||||||
return player.getName() == null ? uuid.toString() : player.getName();
|
return player.getName() == null ? uuid.toString() : player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable UUID offlinePlayerUUIDByName(String name){
|
|
||||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(name); // getOfflinePlayerIfCached(String) is safer (I have experience with getOfflinePlayer(String) returning wrong UUIDs)
|
|
||||||
if (offlinePlayer != null) {
|
|
||||||
return offlinePlayer.getUniqueId();
|
|
||||||
} else {
|
|
||||||
// try to find uuid by searching through punishments
|
|
||||||
final Punishment punishment = SModeration.container.find(p -> offlinePlayerName(p.to).equalsIgnoreCase(name));
|
|
||||||
if (punishment != null) {
|
|
||||||
return punishment.to;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @Nullable CommandSender senderByUUID(@NotNull UUID uid){
|
public static @Nullable CommandSender senderByUUID(@NotNull UUID uid){
|
||||||
if (uid.equals(UUID_CONSOLE)){
|
if (uid.equals(UUID_CONSOLE)){
|
||||||
return Bukkit.getConsoleSender();
|
return Bukkit.getConsoleSender();
|
||||||
@@ -45,4 +29,11 @@ public abstract class PlayerUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UUID uuidFromString(String string) {
|
||||||
|
if (string.length() == 36) {
|
||||||
|
return UUID.fromString(string);
|
||||||
|
} else {
|
||||||
|
return UUID.fromString(string.replaceFirst("(.{8})(.{4})(.{4})(.{4})(.{12})", "$1-$2-$3-$4-$5"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package de.shiewk.smoderation.paper.util;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.paper.punishments.*;
|
||||||
|
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
|
||||||
|
|
||||||
|
public final class SModLegacy {
|
||||||
|
private SModLegacy() {}
|
||||||
|
|
||||||
|
private static byte[] longToBytes(long v){
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||||
|
buffer.putLong(v);
|
||||||
|
return buffer.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long bytesToLong(byte[] i){
|
||||||
|
if (i.length != 8){
|
||||||
|
throw new IllegalArgumentException("length must be 8");
|
||||||
|
}
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||||
|
buffer.put(0, i);
|
||||||
|
return buffer.getLong(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] uuidToBytes(UUID uuid){
|
||||||
|
byte[] l = longToBytes(uuid.getLeastSignificantBits());
|
||||||
|
byte[] m = longToBytes(uuid.getMostSignificantBits());
|
||||||
|
return new byte[]{
|
||||||
|
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7],
|
||||||
|
l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UUID bytesToUuid(byte[] i){
|
||||||
|
if (i.length != 16){
|
||||||
|
throw new IllegalArgumentException("length must be 16, was " + i.length);
|
||||||
|
}
|
||||||
|
long l = bytesToLong(new byte[]{ i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15] });
|
||||||
|
long m = bytesToLong(new byte[]{ i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7] });
|
||||||
|
return new UUID(m, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int bytesToInt(byte[] bytes) {
|
||||||
|
if (bytes.length != 4){
|
||||||
|
throw new IllegalArgumentException("length must be 4");
|
||||||
|
}
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||||
|
buffer.put(0, bytes);
|
||||||
|
return buffer.getInt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] intToBytes(int value) {
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||||
|
buffer.putInt(value);
|
||||||
|
return buffer.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] readStreamInternal(InputStream stream, int len) throws IOException {
|
||||||
|
final byte[] bytes = stream.readNBytes(len);
|
||||||
|
if (bytes.length != len){
|
||||||
|
throw new EOFException("Stream has ended before enough bytes were read");
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void migrateV1PunishmentsFile(PunishmentManager manager, Path path, Path copy) {
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
if (Files.isRegularFile(path)) {
|
||||||
|
LOGGER.info("Migrating V1 punishment file: {}", path);
|
||||||
|
try (InputStream in = new FileInputStream(path.toFile());
|
||||||
|
GZIPInputStream gzin = new GZIPInputStream(in)){
|
||||||
|
while (gzin.available() > 0){
|
||||||
|
int type = bytesToInt(readStreamInternal(gzin, 4));
|
||||||
|
long time = bytesToLong(readStreamInternal(gzin, 8));
|
||||||
|
long until = bytesToLong(readStreamInternal(gzin, 8));
|
||||||
|
UUID by = bytesToUuid(readStreamInternal(gzin, 16));
|
||||||
|
UUID to = bytesToUuid(readStreamInternal(gzin, 16));
|
||||||
|
int reasonLen = bytesToInt(readStreamInternal(gzin, 4));
|
||||||
|
String reason = new String(readStreamInternal(gzin, reasonLen));
|
||||||
|
UUID canceller = null;
|
||||||
|
boolean cancelled = gzin.read() == 1;
|
||||||
|
if (cancelled){
|
||||||
|
canceller = bytesToUuid(readStreamInternal(gzin, 16));
|
||||||
|
}
|
||||||
|
// Type 0: mute; 1: kick; 2: ban
|
||||||
|
Punishment p = switch (type){
|
||||||
|
case 0 -> new Mute(
|
||||||
|
Punishment.generateUUID(),
|
||||||
|
time,
|
||||||
|
by,
|
||||||
|
to,
|
||||||
|
reason,
|
||||||
|
until - time,
|
||||||
|
canceller
|
||||||
|
);
|
||||||
|
case 1 -> new Kick(
|
||||||
|
Punishment.generateUUID(),
|
||||||
|
time,
|
||||||
|
by,
|
||||||
|
to,
|
||||||
|
reason
|
||||||
|
);
|
||||||
|
case 2 -> new Ban(
|
||||||
|
Punishment.generateUUID(),
|
||||||
|
time,
|
||||||
|
by,
|
||||||
|
to,
|
||||||
|
reason,
|
||||||
|
until - time,
|
||||||
|
canceller
|
||||||
|
);
|
||||||
|
default -> throw new IllegalArgumentException("Invalid legacy type for punishment: " + type);
|
||||||
|
};
|
||||||
|
count++;
|
||||||
|
manager.appendToSave(p);
|
||||||
|
LOGGER.info("Migrated: {}", p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOGGER.info("Successfully loaded {} items.", count);
|
||||||
|
Files.move(path, copy);
|
||||||
|
}
|
||||||
|
} catch (EOFException e) {
|
||||||
|
LOGGER.error("The file was not correctly saved, {} items could be recovered!", count);
|
||||||
|
} catch (IOException e){
|
||||||
|
LOGGER.error("An error occurred while loading", e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package de.shiewk.smoderation.paper.util;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides some convenience methods that make Folia support easier
|
||||||
|
*/
|
||||||
|
public final class SchedulerUtil {
|
||||||
|
private SchedulerUtil(){}
|
||||||
|
|
||||||
|
public static final boolean isFolia;
|
||||||
|
|
||||||
|
static {
|
||||||
|
boolean folia;
|
||||||
|
try {
|
||||||
|
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||||
|
folia = true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
folia = false;
|
||||||
|
}
|
||||||
|
isFolia = folia;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleForEntity(Plugin plugin, Entity entity, Runnable task, int delayTicks){
|
||||||
|
if (isFolia){
|
||||||
|
entity.getScheduler().execute(plugin, task, null, delayTicks);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task, delayTicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleForEntity(Plugin plugin, Entity entity, Runnable task){
|
||||||
|
if (isFolia){
|
||||||
|
entity.getScheduler().run(plugin, t -> task.run(), null);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleGlobalRepeating(Plugin plugin, Runnable task, int delay, int interval){
|
||||||
|
if (isFolia){
|
||||||
|
Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, t -> task.run(), delay, interval);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scheduleGlobal(Plugin plugin, Runnable task){
|
||||||
|
if (isFolia){
|
||||||
|
Bukkit.getGlobalRegionScheduler().run(plugin, t -> task.run());
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.shiewk.smoderation.paper.util;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class SerializationHelper {
|
||||||
|
|
||||||
|
private final JsonObject json;
|
||||||
|
|
||||||
|
public SerializationHelper(JsonObject json) {
|
||||||
|
this.json = json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key) {
|
||||||
|
try {
|
||||||
|
return json.get(key).getAsString();
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
throw new IllegalStateException("Key " + key + " does not exist on this object");
|
||||||
|
} catch (UnsupportedOperationException | IllegalStateException e) {
|
||||||
|
throw new IllegalStateException("Tried to get string " + key + ", but is " + json.get(key).getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putString(String key, String value) {
|
||||||
|
json.addProperty(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLong(String key) {
|
||||||
|
try {
|
||||||
|
return json.get(key).getAsLong();
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
throw new IllegalStateException("Key " + key + " does not exist on this object");
|
||||||
|
} catch (UnsupportedOperationException | IllegalStateException e) {
|
||||||
|
throw new IllegalStateException("Tried to get long " + key + ", but is " + json.get(key).getClass().getSimpleName());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new IllegalStateException("Tried to get long " + key + ", but is malformed: " + json.get(key).getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putLong(String key, long value) {
|
||||||
|
json.addProperty(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID(String key) {
|
||||||
|
try {
|
||||||
|
return PlayerUtil.uuidFromString(getString(key));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new IllegalStateException("UUID " + key + " malformed: " + getString(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID(String key, UUID defaultValue) {
|
||||||
|
try {
|
||||||
|
return getUUID(key);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putUUID(String key, UUID value) {
|
||||||
|
if (value == null) return;
|
||||||
|
json.addProperty(key, value.toString().replace("-", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package de.shiewk.smoderation.paper.util;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.*;
|
||||||
|
|
||||||
|
public final class TimeUtil {
|
||||||
|
private TimeUtil(){}
|
||||||
|
|
||||||
|
public static Component formatTimeLong(long millis){
|
||||||
|
long seconds = millis / 1000;
|
||||||
|
millis -= seconds * 1000;
|
||||||
|
|
||||||
|
long minutes = seconds / 60;
|
||||||
|
seconds -= minutes * 60;
|
||||||
|
|
||||||
|
long hours = minutes / 60;
|
||||||
|
minutes -= hours * 60;
|
||||||
|
|
||||||
|
long days = hours / 24;
|
||||||
|
hours -= days * 24;
|
||||||
|
|
||||||
|
long years = days / 365;
|
||||||
|
days -= years * 365;
|
||||||
|
|
||||||
|
long months = days / 30;
|
||||||
|
days -= months * 30;
|
||||||
|
|
||||||
|
long weeks = days / 7;
|
||||||
|
days -= weeks * 7;
|
||||||
|
|
||||||
|
TextComponent.Builder builder = empty().toBuilder();
|
||||||
|
|
||||||
|
if (years > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.years", text(years)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (months > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.months", text(months)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (weeks > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.weeks", text(weeks)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (days > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.days", text(days)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.hours", text(hours)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minutes > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.minutes", text(minutes)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seconds > 0){
|
||||||
|
if (!builder.children().isEmpty()){
|
||||||
|
builder.appendSpace();
|
||||||
|
}
|
||||||
|
builder.append(translatable("smod.time.seconds", text(seconds)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (builder.children().isEmpty()){
|
||||||
|
builder.append(translatable("smod.time.milliseconds", text(millis)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component calendarTimestamp(long time){
|
||||||
|
Date date = new Date(time);
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
TimeZone zone = calendar.getTimeZone();
|
||||||
|
int second = calendar.get(Calendar.SECOND);
|
||||||
|
int minute = calendar.get(Calendar.MINUTE);
|
||||||
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
|
|
||||||
|
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||||
|
Component month = monthName(calendar.get(Calendar.MONTH));
|
||||||
|
return translatable(
|
||||||
|
"smod.time.timestamp",
|
||||||
|
text(year),
|
||||||
|
month,
|
||||||
|
text(day),
|
||||||
|
text((hour < 10 ? "0" : "") + hour),
|
||||||
|
text((minute < 10 ? "0" : "") + minute),
|
||||||
|
text((second < 10 ? "0" : "") + second),
|
||||||
|
text(zone.getDisplayName(zone.inDaylightTime(calendar.getTime()), TimeZone.SHORT))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component monthName(@Range(from = 0, to = 11) int m){
|
||||||
|
return translatable("smod.time.month." + m);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,242 +0,0 @@
|
|||||||
package de.shiewk.smoderation.punishments;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.event.PunishmentIssueEvent;
|
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
|
||||||
import de.shiewk.smoderation.util.ByteUtil;
|
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
|
||||||
|
|
||||||
public class Punishment {
|
|
||||||
public static final String DEFAULT_REASON = "No reason provided.";
|
|
||||||
public final PunishmentType type;
|
|
||||||
public final long time;
|
|
||||||
public final long until;
|
|
||||||
public final UUID by;
|
|
||||||
public final UUID to;
|
|
||||||
public final String reason;
|
|
||||||
private UUID undoneBy;
|
|
||||||
|
|
||||||
public Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason) {
|
|
||||||
this(type, time, until, by, to, reason, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason, UUID undoneBy) {
|
|
||||||
this.type = type;
|
|
||||||
this.time = time;
|
|
||||||
this.until = until;
|
|
||||||
this.by = by;
|
|
||||||
this.to = to;
|
|
||||||
this.reason = reason;
|
|
||||||
this.undoneBy = undoneBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static byte[] readStreamInternal(InputStream stream, int len) throws IOException {
|
|
||||||
final byte[] bytes = stream.readNBytes(len);
|
|
||||||
if (bytes.length != len){
|
|
||||||
throw new EOFException("Stream has ended before enough bytes were read");
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Punishment load(InputStream in) throws IOException {
|
|
||||||
PunishmentType type = PunishmentType.values()[ByteUtil.bytesToInt(readStreamInternal(in, 4))];
|
|
||||||
long time = ByteUtil.bytesToLong(readStreamInternal(in, 8));
|
|
||||||
long until = ByteUtil.bytesToLong(readStreamInternal(in, 8));
|
|
||||||
UUID by = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
|
||||||
UUID to = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
|
||||||
int reasonLen = ByteUtil.bytesToInt(readStreamInternal(in, 4));
|
|
||||||
String reason = new String(readStreamInternal(in, reasonLen));
|
|
||||||
UUID undoneBy = null;
|
|
||||||
boolean undone = in.read() == 1;
|
|
||||||
if (undone){
|
|
||||||
undoneBy = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
|
||||||
}
|
|
||||||
return new Punishment(type, time, until, by, to, reason, undoneBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean wasUndone(){
|
|
||||||
return undoneBy != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID undoneBy() {
|
|
||||||
return undoneBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void undo(UUID undoneBy){
|
|
||||||
if (this.undoneBy != null){
|
|
||||||
throw new IllegalArgumentException("This punishment was already undone.");
|
|
||||||
}
|
|
||||||
this.undoneBy = undoneBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive(){
|
|
||||||
return until > System.currentTimeMillis() && !wasUndone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Punishment mute(long time, long until, UUID by, UUID to, String reason){
|
|
||||||
return new Punishment(PunishmentType.MUTE, time, until, by, to, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Punishment ban(long time, long until, UUID by, UUID to, String reason){
|
|
||||||
return new Punishment(PunishmentType.BAN, time, until, by, to, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Punishment kick(long time, UUID by, UUID to, String reason){
|
|
||||||
return new Punishment(PunishmentType.KICK, time, time, by, to, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int BUFFER_LENGTH = 56;
|
|
||||||
|
|
||||||
public void writeBytes(OutputStream stream) throws IOException {
|
|
||||||
stream.write(ByteUtil.intToBytes(type.ordinal()));
|
|
||||||
stream.write(ByteUtil.longToBytes(time));
|
|
||||||
stream.write(ByteUtil.longToBytes(until));
|
|
||||||
stream.write(ByteUtil.uuidToBytes(by));
|
|
||||||
stream.write(ByteUtil.uuidToBytes(to));
|
|
||||||
final byte[] reasonBytes = reason.getBytes();
|
|
||||||
stream.write(ByteUtil.intToBytes(reasonBytes.length));
|
|
||||||
stream.write(reasonBytes);
|
|
||||||
stream.write(wasUndone() ? 1 : 0);
|
|
||||||
if (wasUndone()){
|
|
||||||
stream.write(ByteUtil.uuidToBytes(undoneBy));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Component undoMessage(){
|
|
||||||
String msg = "";
|
|
||||||
switch (type){
|
|
||||||
case MUTE -> msg = "unmuted";
|
|
||||||
case KICK -> msg = "unkicked??";
|
|
||||||
case BAN -> msg = "unbanned";
|
|
||||||
}
|
|
||||||
return Component.text(PlayerUtil.offlinePlayerName(to)).color(SECONDARY_COLOR)
|
|
||||||
.append(Component.text(" was ").color(PRIMARY_COLOR))
|
|
||||||
.append(Component.text(msg))
|
|
||||||
.append(Component.text(" by ").color(PRIMARY_COLOR))
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(undoneBy)))
|
|
||||||
.append(Component.text(".").color(PRIMARY_COLOR));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void broadcastUndo(PunishmentContainer container){
|
|
||||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
|
||||||
sender.sendMessage(CHAT_PREFIX.append(undoMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Punishment{" +
|
|
||||||
"type=" + type +
|
|
||||||
", time=" + time +
|
|
||||||
", until=" + until +
|
|
||||||
", by=" + by +
|
|
||||||
", to=" + to +
|
|
||||||
", reason=" + reason +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void issue(Punishment punishment, PunishmentContainer container){
|
|
||||||
final PunishmentIssueEvent event = new PunishmentIssueEvent(punishment, container);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if (!event.isCancelled()){
|
|
||||||
container.add(punishment);
|
|
||||||
punishment.firstIssue(container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Component broadcastMessage(){
|
|
||||||
final String toName = PlayerUtil.offlinePlayerName(to);
|
|
||||||
switch (type) {
|
|
||||||
case MUTE -> {
|
|
||||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
|
||||||
Component.text(" has been muted by ").color(PRIMARY_COLOR)
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(" for "))
|
|
||||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - this.time)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(".\nReason: "))
|
|
||||||
.append(Component.text(reason).color(SECONDARY_COLOR)));
|
|
||||||
}
|
|
||||||
case KICK -> {
|
|
||||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
|
||||||
Component.text(" has been kicked by ").color(PRIMARY_COLOR)
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(".\nReason: "))
|
|
||||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
|
||||||
.color(PRIMARY_COLOR));
|
|
||||||
}
|
|
||||||
case BAN -> {
|
|
||||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
|
||||||
Component.text(" has been banned by ").color(PRIMARY_COLOR)
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(" for "))
|
|
||||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - this.time)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(".\nReason: "))
|
|
||||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
|
||||||
.color(PRIMARY_COLOR));
|
|
||||||
}
|
|
||||||
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void broadcastIssue(PunishmentContainer container){
|
|
||||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
|
||||||
sender.sendMessage(CHAT_PREFIX.append(broadcastMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void firstIssue(PunishmentContainer container){
|
|
||||||
switch (type) {
|
|
||||||
case MUTE, BAN -> {
|
|
||||||
final CommandSender sender = PlayerUtil.senderByUUID(to);
|
|
||||||
if (sender != null) {
|
|
||||||
sender.sendMessage(CHAT_PREFIX.append(playerMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
broadcastIssue(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component playerMessage(){
|
|
||||||
switch (type) {
|
|
||||||
case MUTE -> {
|
|
||||||
return Component.text("You have been muted by ")
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(".\nReason: "))
|
|
||||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text("\nYour mute expires in "))
|
|
||||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - System.currentTimeMillis())).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text("."))
|
|
||||||
.color(PRIMARY_COLOR);
|
|
||||||
}
|
|
||||||
case KICK -> {
|
|
||||||
return Component.text("You have been kicked by ")
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(".\nReason: "))
|
|
||||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
|
||||||
.color(PRIMARY_COLOR);
|
|
||||||
}
|
|
||||||
case BAN -> {
|
|
||||||
return Component.text("You have been banned from this server by ")
|
|
||||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text(".\nReason: "))
|
|
||||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text("\nYour ban expires in "))
|
|
||||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - System.currentTimeMillis())).color(SECONDARY_COLOR))
|
|
||||||
.append(Component.text("."))
|
|
||||||
.color(PRIMARY_COLOR);
|
|
||||||
}
|
|
||||||
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package de.shiewk.smoderation.punishments;
|
|
||||||
|
|
||||||
public enum PunishmentType {
|
|
||||||
MUTE("Mute"),
|
|
||||||
KICK("Kick"),
|
|
||||||
BAN("Ban");
|
|
||||||
|
|
||||||
public final String name;
|
|
||||||
|
|
||||||
PunishmentType(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
package de.shiewk.smoderation.storage;
|
|
||||||
|
|
||||||
import de.shiewk.smoderation.SModeration;
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
|
||||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
public class PunishmentContainer {
|
|
||||||
|
|
||||||
private final CopyOnWriteArrayList<Punishment> punishments = new CopyOnWriteArrayList<>();
|
|
||||||
|
|
||||||
public PunishmentContainer(){}
|
|
||||||
|
|
||||||
public void add(Punishment punishment){
|
|
||||||
punishments.add(punishment);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable Punishment remove(int index){
|
|
||||||
return punishments.remove(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(Punishment punishment){
|
|
||||||
punishments.remove(punishment);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
|
||||||
for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) {
|
|
||||||
if (predicate.test(punishment)){
|
|
||||||
return punishment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull List<Punishment> findAll(Predicate<Punishment> predicate){
|
|
||||||
List<Punishment> found = new ArrayList<>();
|
|
||||||
for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) {
|
|
||||||
if (predicate.test(punishment)){
|
|
||||||
found.add(punishment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommandSender> collectBroadcastTargets(){
|
|
||||||
ArrayList<CommandSender> senders = new ArrayList<>();
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (onlinePlayer.hasPermission("smod.notifications")){
|
|
||||||
senders.add(onlinePlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
senders.add(Bukkit.getConsoleSender());
|
|
||||||
return Collections.unmodifiableList(senders);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable Punishment findByTimestamp(long timestamp){
|
|
||||||
return find(punishment -> punishment.time == timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Punishment> copy() {
|
|
||||||
return new ArrayList<>(punishments);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load(File file){
|
|
||||||
final ComponentLogger logger = SModeration.LOGGER;
|
|
||||||
try {
|
|
||||||
logger.info("Loading from {}", file.getPath());
|
|
||||||
if (!file.isFile()){
|
|
||||||
logger.warn("The file does not exist.");
|
|
||||||
} else {
|
|
||||||
try (FileInputStream fin = new FileInputStream(file)){
|
|
||||||
GZIPInputStream gzin = new GZIPInputStream(fin);
|
|
||||||
while (gzin.available() > 0){
|
|
||||||
add(Punishment.load(gzin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.info("Successfully loaded {} items.", punishments.size());
|
|
||||||
}
|
|
||||||
} catch (EOFException e) {
|
|
||||||
logger.error("The file was not correctly saved, {} items could be recovered!", this.punishments.size());
|
|
||||||
} catch (IOException e){
|
|
||||||
logger.error("An error occurred while loading: {}", e.toString());
|
|
||||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
|
||||||
logger.error(stackTraceElement.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(File file) {
|
|
||||||
final ComponentLogger logger = SModeration.LOGGER;
|
|
||||||
try {
|
|
||||||
logger.info("Saving to {}", file.getPath());
|
|
||||||
if (!file.isFile()){
|
|
||||||
file.mkdirs();
|
|
||||||
file.delete();
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
|
||||||
GZIPOutputStream gzout = new GZIPOutputStream(outputStream);
|
|
||||||
for (Punishment punishment : copy()) {
|
|
||||||
punishment.writeBytes(gzout);
|
|
||||||
}
|
|
||||||
gzout.close();
|
|
||||||
}
|
|
||||||
logger.info("Successfully saved.");
|
|
||||||
} catch (IOException e){
|
|
||||||
logger.error("An error occurred while saving: {}", e.toString());
|
|
||||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
|
||||||
logger.error(stackTraceElement.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package de.shiewk.smoderation.util;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for byte-based saving of integers, longs and UUIDs
|
|
||||||
*/
|
|
||||||
public abstract class ByteUtil {
|
|
||||||
private ByteUtil(){}
|
|
||||||
|
|
||||||
public static byte[] longToBytes(long v){
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
|
||||||
buffer.putLong(v);
|
|
||||||
return buffer.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long bytesToLong(byte[] i){
|
|
||||||
if (i.length != 8){
|
|
||||||
throw new IllegalArgumentException("length must be 8");
|
|
||||||
}
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
|
||||||
buffer.put(0, i);
|
|
||||||
return buffer.getLong(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] uuidToBytes(UUID uuid){
|
|
||||||
byte[] l = longToBytes(uuid.getLeastSignificantBits());
|
|
||||||
byte[] m = longToBytes(uuid.getMostSignificantBits());
|
|
||||||
return new byte[]{
|
|
||||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7],
|
|
||||||
l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UUID bytesToUuid(byte[] i){
|
|
||||||
if (i.length != 16){
|
|
||||||
throw new IllegalArgumentException("length must be 16, was " + i.length);
|
|
||||||
}
|
|
||||||
long l = bytesToLong(new byte[]{ i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15] });
|
|
||||||
long m = bytesToLong(new byte[]{ i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7] });
|
|
||||||
return new UUID(m, l);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int bytesToInt(byte[] bytes) {
|
|
||||||
if (bytes.length != 4){
|
|
||||||
throw new IllegalArgumentException("length must be 4");
|
|
||||||
}
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
|
||||||
buffer.put(0, bytes);
|
|
||||||
return buffer.getInt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] intToBytes(int value) {
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
|
||||||
buffer.putInt(value);
|
|
||||||
return buffer.array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
package de.shiewk.smoderation.util;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
public abstract class TimeUtil {
|
|
||||||
private TimeUtil(){}
|
|
||||||
|
|
||||||
public static String formatTimeLong(long millis){
|
|
||||||
long seconds = millis / 1000;
|
|
||||||
millis -= seconds * 1000;
|
|
||||||
|
|
||||||
long minutes = seconds / 60;
|
|
||||||
seconds -= minutes * 60;
|
|
||||||
|
|
||||||
long hours = minutes / 60;
|
|
||||||
minutes -= hours * 60;
|
|
||||||
|
|
||||||
long days = hours / 24;
|
|
||||||
hours -= days * 24;
|
|
||||||
|
|
||||||
long years = days / 365;
|
|
||||||
days -= years * 365;
|
|
||||||
|
|
||||||
long months = days / 30;
|
|
||||||
days -= months * 30;
|
|
||||||
|
|
||||||
long weeks = days / 7;
|
|
||||||
days -= weeks * 7;
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
if (years > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s years".formatted(years));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (months > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s months".formatted(months));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (weeks > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s weeks".formatted(weeks));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (days > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s days".formatted(days));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hours > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s hours".formatted(hours));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minutes > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s minutes".formatted(minutes));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seconds > 0){
|
|
||||||
if (!builder.isEmpty()){
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
builder.append("%s seconds".formatted(seconds));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (builder.isEmpty()){
|
|
||||||
builder.append("%s ms".formatted(millis));
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long parseDurationMillisSafely(String in){
|
|
||||||
try {
|
|
||||||
return parseDurationMillis(in);
|
|
||||||
} catch (Throwable e){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long parseDurationMillis(String in){
|
|
||||||
if (in.endsWith("ms")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-2));
|
|
||||||
} else if (in.endsWith("s")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-1)) * 1000L;
|
|
||||||
} else if (in.endsWith("min")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-3)) * 60000L;
|
|
||||||
} else if (in.endsWith("h")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-1)) * 3600000L;
|
|
||||||
} else if (in.endsWith("d")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-1)) * 86400000L;
|
|
||||||
} else if (in.endsWith("w")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-1)) * 604800000L;
|
|
||||||
} else if (in.endsWith("mo")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-2)) * 2592000000L;
|
|
||||||
} else if (in.endsWith("y")){
|
|
||||||
return Long.parseLong(in.substring(0, in.length()-1)) * 31536000000L;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String calendarTimestamp(long time){
|
|
||||||
Date date = new Date(time);
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
TimeZone zone = calendar.getTimeZone();
|
|
||||||
int second = calendar.get(Calendar.SECOND);
|
|
||||||
int minute = calendar.get(Calendar.MINUTE);
|
|
||||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
|
||||||
int year = calendar.get(Calendar.YEAR);
|
|
||||||
|
|
||||||
String day = numberWithSuffix(calendar.get(Calendar.DAY_OF_MONTH));
|
|
||||||
String month = monthName(calendar.get(Calendar.MONTH));
|
|
||||||
return "%s %s %s, %s:%s:%s %s".formatted(
|
|
||||||
month,
|
|
||||||
day,
|
|
||||||
year,
|
|
||||||
hour < 10 ? "0" + hour : hour,
|
|
||||||
minute < 10 ? "0" + minute : minute,
|
|
||||||
second < 10 ? "0" + second : second,
|
|
||||||
zone.getDisplayName(false, TimeZone.SHORT)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String numberWithSuffix(int i){
|
|
||||||
return i + numberSuffix(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String numberSuffix(int i){
|
|
||||||
if ((i % 10) == 1 && i != 11){
|
|
||||||
return "st";
|
|
||||||
} else if ((i % 10) == 2 && i != 12){
|
|
||||||
return "nd";
|
|
||||||
} else if ((i % 10) == 3 && i != 13){
|
|
||||||
return "rd";
|
|
||||||
}
|
|
||||||
return "th";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String monthName(@Range(from = 0, to = 11) int m){
|
|
||||||
switch (m){
|
|
||||||
case 0 -> {
|
|
||||||
return "January";
|
|
||||||
}
|
|
||||||
case 1 -> {
|
|
||||||
return "February";
|
|
||||||
}
|
|
||||||
case 2 -> {
|
|
||||||
return "March";
|
|
||||||
}
|
|
||||||
case 3 -> {
|
|
||||||
return "April";
|
|
||||||
}
|
|
||||||
case 4 -> {
|
|
||||||
return "May";
|
|
||||||
}
|
|
||||||
case 5 -> {
|
|
||||||
return "June";
|
|
||||||
}
|
|
||||||
case 6 -> {
|
|
||||||
return "July";
|
|
||||||
}
|
|
||||||
case 7 -> {
|
|
||||||
return "August";
|
|
||||||
}
|
|
||||||
case 8 -> {
|
|
||||||
return "September";
|
|
||||||
}
|
|
||||||
case 9 -> {
|
|
||||||
return "October";
|
|
||||||
}
|
|
||||||
case 10 -> {
|
|
||||||
return "November";
|
|
||||||
}
|
|
||||||
case 11 -> {
|
|
||||||
return "December";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "Unknown Month";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# If enabled, punishments can no longer be issued without providing a reason.
|
||||||
|
force-reason: false
|
||||||
|
|
||||||
|
# The string that should be used when no reason is provided.
|
||||||
|
# This has no effect if 'force-reason' is set to true.
|
||||||
|
default-reason: No reason provided.
|
||||||
|
|
||||||
|
# Allows you to toggle specific plugin features.
|
||||||
|
features:
|
||||||
|
# Should punishments be tracked and executed?
|
||||||
|
# Note that disabling this will also disable the SMod menu and
|
||||||
|
# /modlogs command since their only use is viewing punishments
|
||||||
|
punishments: true
|
||||||
|
# Should commands for opening the SMod menu be registered?
|
||||||
|
smodmenu: true
|
||||||
|
# Should commands for viewing player inventories be registered?
|
||||||
|
invsee: true
|
||||||
|
# Should commands for viewing player ender chests be registered?
|
||||||
|
enderchestsee: true
|
||||||
|
# Should commands for teleporting to offline players be registered?
|
||||||
|
offlinetp: true
|
||||||
|
# Should commands for viewing other players' messaging commands be registered?
|
||||||
|
socialspy: true
|
||||||
|
# Should players be able to enable vanish mode?
|
||||||
|
vanish: true
|
||||||
|
|
||||||
|
# A list of commands which will be captured and broadcast
|
||||||
|
# to players which have SocialSpy enabled (/socialspy).
|
||||||
|
socialspy-commands:
|
||||||
|
- w
|
||||||
|
- tell
|
||||||
|
- msg
|
||||||
|
- teammsg
|
||||||
|
- tm
|
||||||
|
- minecraft:w
|
||||||
|
- minecraft:tell
|
||||||
|
- minecraft:msg
|
||||||
|
- minecraft:teammsg
|
||||||
|
- minecraft:tm
|
||||||
|
|
||||||
|
# A list of commands which muted players will not be able to run.
|
||||||
|
muted-forbidden-commands:
|
||||||
|
- w
|
||||||
|
- tell
|
||||||
|
- msg
|
||||||
|
- teammsg
|
||||||
|
- tm
|
||||||
|
- me
|
||||||
|
- minecraft:w
|
||||||
|
- minecraft:tell
|
||||||
|
- minecraft:msg
|
||||||
|
- minecraft:teammsg
|
||||||
|
- minecraft:tm
|
||||||
|
- minecraft:me
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
name: SModeration
|
||||||
|
version: '${version}'
|
||||||
|
main: de.shiewk.smoderation.paper.SModerationPaper
|
||||||
|
website: https://github.com/Shiewk/SModeration
|
||||||
|
api-version: '1.21.4'
|
||||||
|
load: STARTUP
|
||||||
|
authors:
|
||||||
|
- Shiewk
|
||||||
|
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
||||||
|
folia-supported: true
|
||||||
|
permissions:
|
||||||
|
smod.mute:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to mute other players.
|
||||||
|
smod.ban:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to ban and kick other players.
|
||||||
|
children:
|
||||||
|
- smod.kick
|
||||||
|
smod.kick:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to kick other players.
|
||||||
|
smod.menu:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to use the SModeration menu.
|
||||||
|
smod.notifications:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to be notified when a punishment is issued.
|
||||||
|
smod.unmute:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to unmute other players.
|
||||||
|
smod.unban:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to unban other players.
|
||||||
|
smod.logs:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view mod logs.
|
||||||
|
smod.invsee:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view other players inventories.
|
||||||
|
smod.invsee.modify:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view and modify other players inventories.
|
||||||
|
children:
|
||||||
|
- smod.invsee
|
||||||
|
smod.invsee.preventmodify:
|
||||||
|
default: op
|
||||||
|
description: When giving this permission to a player, prevents their inventory from being modified.
|
||||||
|
smod.enderchestsee:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view other players ender chests.
|
||||||
|
smod.enderchestsee.modify:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view and modify other players ender chests.
|
||||||
|
children:
|
||||||
|
- smod.enderchestsee
|
||||||
|
smod.preventmute:
|
||||||
|
default: op
|
||||||
|
description: Prevents the player from being muted (if online)
|
||||||
|
smod.preventkick:
|
||||||
|
default: op
|
||||||
|
description: Prevents the player from being kicked (if online)
|
||||||
|
smod.preventban:
|
||||||
|
default: op
|
||||||
|
description: Prevents the player from being banned (if online)
|
||||||
|
smod.vanish:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to use /vanish
|
||||||
|
smod.vanish.see:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to see vanished players
|
||||||
|
smod.socialspy:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to enable SocialSpy
|
||||||
|
smod.offlinetp:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to teleport themself to offline players
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
name: SModeration
|
|
||||||
version: '${version}'
|
|
||||||
main: de.shiewk.smoderation.SModeration
|
|
||||||
api-version: '1.20'
|
|
||||||
load: STARTUP
|
|
||||||
authors:
|
|
||||||
- Shiewk
|
|
||||||
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
|
||||||
commands:
|
|
||||||
modlogs:
|
|
||||||
usage: "§cUsage: /modlogs <player|uuid>"
|
|
||||||
aliases:
|
|
||||||
- logs
|
|
||||||
- seen
|
|
||||||
- smodlogs
|
|
||||||
permission: smod.logs
|
|
||||||
mute:
|
|
||||||
usage: "§cUsage: /mute <player> <duration> <reason>"
|
|
||||||
aliases:
|
|
||||||
- smodmute
|
|
||||||
permission: smod.mute
|
|
||||||
description: Mutes a player, either temporarily or permanently.
|
|
||||||
ban:
|
|
||||||
usage: "§cUsage: /ban <player> <duration> <reason>"
|
|
||||||
aliases:
|
|
||||||
- smodban
|
|
||||||
- tempban
|
|
||||||
permission: smod.ban
|
|
||||||
description: Bans a player, either temporarily or permanently.
|
|
||||||
kick:
|
|
||||||
usage: "§cUsage: /kick <player> <reason>"
|
|
||||||
aliases:
|
|
||||||
- smodkick
|
|
||||||
permission: smod.kick
|
|
||||||
description: Kicks a player
|
|
||||||
smod:
|
|
||||||
usage: "§cUsage: /smod"
|
|
||||||
aliases:
|
|
||||||
- smodmenu
|
|
||||||
- smoderation
|
|
||||||
permission: smod.menu
|
|
||||||
description: Shows the SModeration menu.
|
|
||||||
unmute:
|
|
||||||
usage: "§cUsage: /unmute <player|uuid>"
|
|
||||||
aliases:
|
|
||||||
- sunmute
|
|
||||||
permission: smod.unmute
|
|
||||||
description: Unmutes a muted player.
|
|
||||||
unban:
|
|
||||||
usage: "§cUsage: /unban <player|uuid>"
|
|
||||||
aliases:
|
|
||||||
- sunban
|
|
||||||
- pardon
|
|
||||||
- spardon
|
|
||||||
permission: smod.unban
|
|
||||||
description: Unbans a banned player.
|
|
||||||
permissions:
|
|
||||||
smod.mute:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to mute other players.
|
|
||||||
smod.ban:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to ban and kick other players.
|
|
||||||
children:
|
|
||||||
- smod.kick
|
|
||||||
smod.kick:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to kick other players.
|
|
||||||
smod.menu:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to use the SModeration menu.
|
|
||||||
smod.notifications:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to be notified when a punishment is issued.
|
|
||||||
smod.unmute:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to unmute other players.
|
|
||||||
smod.unban:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to unban other players.
|
|
||||||
smod.logs:
|
|
||||||
default: op
|
|
||||||
description: Allows the player to view mod logs.
|
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
{
|
||||||
|
"smod.argument.duration.fail.invalid": "Ungültige Zeit '<arg:0>'",
|
||||||
|
"smod.argument.duration.fail.pattern": "Bitte gib eine gültige Zeit an, z.B. '1d6h30min'",
|
||||||
|
"smod.argument.offlinePlayer.fail.notCached": "Die Daten des Spielers sind nicht gespeichert.",
|
||||||
|
"smod.argument.uuid.fail.notCached": "Die Daten des Spielers sind nicht gespeichert. Versuche, stattdessen seine UUID anzugeben.",
|
||||||
|
"smod.chatInput.remainingTime": "<gray><arg:0> Sekunden",
|
||||||
|
"smod.command.ban.fail.alreadyBanned": "Dieser Spieler ist schon gebannt.",
|
||||||
|
"smod.command.ban.fail.forceReason": "Bitte gib einen Grund an.",
|
||||||
|
"smod.command.ban.fail.protect": "Dieser Spieler kann nicht gebannt werden.",
|
||||||
|
"smod.command.ban.fail.self": "Du kannst dich nicht selbst bannen.",
|
||||||
|
"smod.command.ban.fail.tooShort": "Du kannst Spieler, die nicht online sind, nicht so kurz bannen.",
|
||||||
|
"smod.command.ecsee.opening": "<primary>Enderkiste von <secondary><arg:0></secondary> wird geöffnet.",
|
||||||
|
"smod.command.fail.invalidPlayer": "Bitte gib einen gültigen Spieler an.",
|
||||||
|
"smod.command.fail.players": "Nur Spieler können diesen Befehl ausführen.",
|
||||||
|
"smod.command.fail.playersConsole": "Nur Spieler und die Konsole können diesen Befehl ausführen.",
|
||||||
|
"smod.command.invsee.fail.self": "Du kannst dein eigenes Inventar nicht öffnen.",
|
||||||
|
"smod.command.invsee.opening": "<primary>Inventar von <secondary><arg:0></secondary> wird geöffnet.",
|
||||||
|
"smod.command.kick.fail.forceReason": "Bitte gib einen Grund an.",
|
||||||
|
"smod.command.kick.fail.protect": "Dieser Spieler kann nicht gekickt werden.",
|
||||||
|
"smod.command.kick.fail.self": "Du kannst dich nicht selbst kicken.",
|
||||||
|
"smod.command.modlogs.ban": "<primary>- ist bis <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray> gebannt. Grund: <secondary><arg:2>",
|
||||||
|
"smod.command.modlogs.ban.permanent": "<primary>- ist <secondary>permanent</secondary> gebannt. Grund: <secondary><arg:0>",
|
||||||
|
"smod.command.modlogs.heading": "<primary>Spieler <secondary><arg:0> <gray>(<arg:1>)",
|
||||||
|
"smod.command.modlogs.mute": "<primary>- ist bis <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray> stummgeschaltet. Grund: <secondary><arg:2>",
|
||||||
|
"smod.command.modlogs.mute.permanent": "<primary>- ist <secondary>permanent</secondary> stummgeschaltet. Grund: <secondary><arg:0>",
|
||||||
|
"smod.command.modlogs.none": "<primary>- ist momentan nicht gebannt oder stummgeschaltet.",
|
||||||
|
"smod.command.mute.fail.alreadyMuted": "Dieser Spieler ist schon stummgeschaltet.",
|
||||||
|
"smod.command.mute.fail.forceReason": "Bitte gib einen Grund an.",
|
||||||
|
"smod.command.mute.fail.protect": "Dieser Spieler kann nicht stummgeschaltet werden.",
|
||||||
|
"smod.command.mute.fail.self": "Du kannst dich nicht selbst stummschalten.",
|
||||||
|
"smod.command.mute.fail.tooShort": "Du kannst Spieler nicht so kurz stummschalten.",
|
||||||
|
"smod.command.offlinetp.fail.unknown": "Die Position des Spielers ist nicht bekannt.",
|
||||||
|
"smod.command.offlinetp.teleporting": "<primary>Du wirst zu <secondary><arg:0></secondary> teleportiert.",
|
||||||
|
"smod.command.socialspy.disabled": "<primary>SocialSpy <red>deaktiviert</red>.",
|
||||||
|
"smod.command.socialspy.enabled": "<primary>SocialSpy <green>aktiviert</green>.",
|
||||||
|
"smod.command.unban.fail.notBanned": "Dieser Spieler ist nicht gebannt.",
|
||||||
|
"smod.command.unmute.fail.notMuted": "Dieser Spieler ist nicht stummgeschaltet.",
|
||||||
|
"smod.command.vanish.broadcast.off": "<primary><secondary><arg:0></secondary> ist wieder erschienen.",
|
||||||
|
"smod.command.vanish.broadcast.on": "<primary><secondary><arg:0></secondary> ist verschwunden.",
|
||||||
|
"smod.command.vanish.fail.noPlayersFound": "Kein Spieler wurde gefunden.",
|
||||||
|
"smod.command.vanish.list": "<primary>Diese Spieler sind momentan versteckt: <arg:0>",
|
||||||
|
"smod.command.vanish.list.none": "<primary>Keine Spieler sind gerade versteckt.",
|
||||||
|
"smod.command.vanish.stillEnabled": "<bold><primary>Du bist noch unsichtbar!",
|
||||||
|
"smod.command.vanish.toggle.off": "<primary>Du bist nicht mehr versteckt.",
|
||||||
|
"smod.command.vanish.toggle.on": "<primary>Du bist jetzt unsichtbar.",
|
||||||
|
"smod.confirm.no": "<red>Nein",
|
||||||
|
"smod.confirm.yes": "<green>Ja",
|
||||||
|
"smod.inventory.next": "Nächste Seite (<arg:0>/<arg:1>)",
|
||||||
|
"smod.inventory.previous": "Vorherige Seite (<arg:0>/<arg:1>)",
|
||||||
|
"smod.menu": "SMod Menü",
|
||||||
|
"smod.menu.cancelConfirmation": "Bist du sicher, dass du die Strafe aufheben willst?",
|
||||||
|
"smod.menu.filter": "Filter: <arg:0>",
|
||||||
|
"smod.menu.filter.active": "Aktive Strafen",
|
||||||
|
"smod.menu.filter.all": "Alle Strafen",
|
||||||
|
"smod.menu.filter.expired": "Abgelaufene Strafen",
|
||||||
|
"smod.menu.filter.switch": "\u00BB Klicke, um den Filter zu ändern",
|
||||||
|
"smod.menu.info.cancelled": "<red>Aufgehoben von: <gold><arg:0>",
|
||||||
|
"smod.menu.info.click": "\u00BB Klicke, um die Strafe aufzuheben",
|
||||||
|
"smod.menu.info.duration": "<secondary>Dauer: <primary><arg:0>",
|
||||||
|
"smod.menu.info.expiry.future": "<secondary>Läuft ab: <primary>In <arg:0>",
|
||||||
|
"smod.menu.info.expiry.never": "<secondary>Läuft ab: <primary>Nie",
|
||||||
|
"smod.menu.info.expiry.past": "<secondary>Ist abgelaufen: <primary><arg:0> ago",
|
||||||
|
"smod.menu.info.player": "<secondary>Spieler: <primary><arg:0>",
|
||||||
|
"smod.menu.info.punishedBy": "<secondary>Bestraft von: <primary><arg:0>",
|
||||||
|
"smod.menu.info.reason": "<secondary>Grund: <primary><arg:0>",
|
||||||
|
"smod.menu.info.timestamp": "<secondary>Zeitpunkt: <primary><arg:0>",
|
||||||
|
"smod.menu.search": "Suchen",
|
||||||
|
"smod.menu.search.current": "Aktueller Suchbegriff: <arg:0>",
|
||||||
|
"smod.menu.search.new": "\u00BB Klicke, um einen neuen Suchbegriff einzugeben",
|
||||||
|
"smod.menu.search.none": "Keiner",
|
||||||
|
"smod.menu.search.query": "Gib deinen Suchbegriff in den Chat ein",
|
||||||
|
"smod.menu.search.remove": "\u00BB Rechtsklick, um die Suche aufzuheben",
|
||||||
|
"smod.menu.sort": "Sortieren nach: <arg:0>",
|
||||||
|
"smod.menu.sort.expiry": "Ablaufzeitpunkt",
|
||||||
|
"smod.menu.sort.moderatorName": "Moderatorname",
|
||||||
|
"smod.menu.sort.playerName": "Spielername",
|
||||||
|
"smod.menu.sort.switch": "\u00BB Klicke, um die Sortierung zu ändern",
|
||||||
|
"smod.menu.sort.time": "Ausstellungszeitpunkt",
|
||||||
|
"smod.menu.type": "Typ: <arg:0>",
|
||||||
|
"smod.menu.type.all": "Alle",
|
||||||
|
"smod.menu.type.switch": "\u00BB Klicke, um den Typ zu ändern",
|
||||||
|
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:3></secondary> gebannt.<newline>Grund: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.ban.permanent": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> <secondary>permanent</secondary> gebannt.<newline>Grund: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> gekickt.<newline>Grund: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:3></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.mute.permanent": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> <secondary>permanent</secondary> stummgeschaltet.<newline>Grund: <secondary><arg:2>",
|
||||||
|
"smod.punishment.cancel.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> entbannt.",
|
||||||
|
"smod.punishment.cancel.mute": "<primary><secondary><arg:0></secondary>s Stummschaltung wurde von <secondary><arg:1></secondary> aufgehoben.",
|
||||||
|
"smod.punishment.name.ban": "Bann",
|
||||||
|
"smod.punishment.name.kick": "Kick",
|
||||||
|
"smod.punishment.name.mute": "Stummschaltung",
|
||||||
|
"smod.punishment.playerMessage.ban": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gebannt.<newline>Grund: <secondary><arg:1></secondary><newline>Dein Bann läuft in <secondary><arg:2></secondary> ab.",
|
||||||
|
"smod.punishment.playerMessage.ban.permanent": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gebannt.<newline>Grund: <secondary><arg:1></secondary><newline>Dein Bann läuft <secondary>nicht</secondary> ab.",
|
||||||
|
"smod.punishment.playerMessage.kick": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gekickt.<newline>Grund: <secondary><arg:1>",
|
||||||
|
"smod.punishment.playerMessage.mute": "<primary>Du wurdest von <secondary><arg:0></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:1></secondary><newline>Du kannst in <secondary><arg:2></secondary> wieder schreiben.",
|
||||||
|
"smod.punishment.playerMessage.mute.permanent": "<primary>Du wurdest von <secondary><arg:0></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:1></secondary><newline>Du kannst <secondary>nie</secondary> wieder schreiben.",
|
||||||
|
"smod.punishment.playerMessage.mute.chat": "<primary>Du kannst diesen Befehl nicht ausführen, während du stummgeschaltet bist.",
|
||||||
|
"smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>",
|
||||||
|
"smod.time.days": "<arg:0> Tage",
|
||||||
|
"smod.time.hours": "<arg:0> Stunden",
|
||||||
|
"smod.time.milliseconds": "<arg:0> Millisekunden",
|
||||||
|
"smod.time.minutes": "<arg:0> Minuten",
|
||||||
|
"smod.time.month.0": "Januar",
|
||||||
|
"smod.time.month.1": "Februar",
|
||||||
|
"smod.time.month.10": "November",
|
||||||
|
"smod.time.month.11": "Dezember",
|
||||||
|
"smod.time.month.2": "März",
|
||||||
|
"smod.time.month.3": "April",
|
||||||
|
"smod.time.month.4": "Mai",
|
||||||
|
"smod.time.month.5": "Juni",
|
||||||
|
"smod.time.month.6": "Juli",
|
||||||
|
"smod.time.month.7": "August",
|
||||||
|
"smod.time.month.8": "September",
|
||||||
|
"smod.time.month.9": "Oktober",
|
||||||
|
"smod.time.months": "<arg:0> Monate",
|
||||||
|
"smod.time.never": "Nie",
|
||||||
|
"smod.time.permanent": "Permanent",
|
||||||
|
"smod.time.seconds": "<arg:0> Sekunden",
|
||||||
|
"smod.time.timestamp": "<arg:2>. <arg:1> <arg:0> <arg:3>:<arg:4>:<arg:5> <arg:6>",
|
||||||
|
"smod.time.weeks": "<arg:0> Wochen",
|
||||||
|
"smod.time.years": "<arg:0> Jahre"
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
{
|
||||||
|
"smod.argument.duration.fail.invalid": "Invalid duration '<arg:0>'",
|
||||||
|
"smod.argument.duration.fail.pattern": "Please provide a valid duration, e.g. '1d6h30min'",
|
||||||
|
"smod.argument.offlinePlayer.fail.notCached": "That player's data is not saved.",
|
||||||
|
"smod.argument.uuid.fail.notCached": "That player's data is not saved. Try providing an UUID instead.",
|
||||||
|
"smod.chatInput.remainingTime": "<gray><arg:0> seconds",
|
||||||
|
"smod.command.ban.fail.alreadyBanned": "This player is already banned.",
|
||||||
|
"smod.command.ban.fail.forceReason": "Please provide a reason.",
|
||||||
|
"smod.command.ban.fail.protect": "This player can't be banned.",
|
||||||
|
"smod.command.ban.fail.self": "You can't ban yourself.",
|
||||||
|
"smod.command.ban.fail.tooShort": "You can't ban an offline player for less than 1ms.",
|
||||||
|
"smod.command.ecsee.opening": "<primary>Opening ender chest of <secondary><arg:0></secondary>.",
|
||||||
|
"smod.command.fail.invalidPlayer": "Please provide a valid player.",
|
||||||
|
"smod.command.fail.players": "Only players can execute this command.",
|
||||||
|
"smod.command.fail.playersConsole": "Only players and the console can execute this command.",
|
||||||
|
"smod.command.invsee.fail.self": "You can't open your own inventory.",
|
||||||
|
"smod.command.invsee.opening": "<primary>Opening inventory of <secondary><arg:0></secondary>.",
|
||||||
|
"smod.command.kick.fail.forceReason": "Please provide a reason.",
|
||||||
|
"smod.command.kick.fail.protect": "This player can't be kicked.",
|
||||||
|
"smod.command.kick.fail.self": "You can't kick yourself.",
|
||||||
|
"smod.command.modlogs.ban": "<primary>- is banned until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
|
||||||
|
"smod.command.modlogs.ban.permanent": "<primary>- is banned <secondary>permanently</secondary>. Reason: <secondary><arg:0>",
|
||||||
|
"smod.command.modlogs.heading": "<primary>Player <secondary><arg:0> <gray>(<arg:1>)",
|
||||||
|
"smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
|
||||||
|
"smod.command.modlogs.mute.permanent": "<primary>- is muted <secondary>permanently</secondary>. Reason: <secondary><arg:0>",
|
||||||
|
"smod.command.modlogs.none": "<primary>- is not currently muted or banned.",
|
||||||
|
"smod.command.mute.fail.alreadyMuted": "This player is already muted.",
|
||||||
|
"smod.command.mute.fail.forceReason": "Please provide a reason.",
|
||||||
|
"smod.command.mute.fail.protect": "This player can't be muted.",
|
||||||
|
"smod.command.mute.fail.self": "You can't mute yourself.",
|
||||||
|
"smod.command.mute.fail.tooShort": "You can't mute a player for less than 1ms.",
|
||||||
|
"smod.command.offlinetp.fail.unknown": "This player's location is unknown.",
|
||||||
|
"smod.command.offlinetp.teleporting": "<primary>Teleporting you to <secondary><arg:0></secondary>.",
|
||||||
|
"smod.command.socialspy.disabled": "<primary>SocialSpy <red>disabled</red>.",
|
||||||
|
"smod.command.socialspy.enabled": "<primary>SocialSpy <green>enabled</green>.",
|
||||||
|
"smod.command.unban.fail.notBanned": "That player is not banned.",
|
||||||
|
"smod.command.unmute.fail.notMuted": "That player is not muted.",
|
||||||
|
"smod.command.vanish.broadcast.off": "<primary><secondary><arg:0></secondary> re-appeared.",
|
||||||
|
"smod.command.vanish.broadcast.on": "<primary><secondary><arg:0></secondary> vanished.",
|
||||||
|
"smod.command.vanish.fail.noPlayersFound": "No player was found.",
|
||||||
|
"smod.command.vanish.list": "<primary>The following players are currently vanished: <arg:0>",
|
||||||
|
"smod.command.vanish.list.none": "<primary>No players are currently vanished.",
|
||||||
|
"smod.command.vanish.stillEnabled": "<bold><primary>You are still vanished!",
|
||||||
|
"smod.command.vanish.toggle.off": "<primary>You are no longer vanished.",
|
||||||
|
"smod.command.vanish.toggle.on": "<primary>You are now vanished.",
|
||||||
|
"smod.confirm.no": "<red>No",
|
||||||
|
"smod.confirm.yes": "<green>Yes",
|
||||||
|
"smod.inventory.next": "Next page (<arg:0>/<arg:1>)",
|
||||||
|
"smod.inventory.previous": "Previous page (<arg:0>/<arg:1>)",
|
||||||
|
"smod.menu": "SMod Menu",
|
||||||
|
"smod.menu.cancelConfirmation": "Are you sure that you want to cancel this punishment?",
|
||||||
|
"smod.menu.filter": "Filter: <arg:0>",
|
||||||
|
"smod.menu.filter.active": "Active punishments",
|
||||||
|
"smod.menu.filter.all": "All punishments",
|
||||||
|
"smod.menu.filter.expired": "Expired punishments",
|
||||||
|
"smod.menu.filter.switch": "\u00BB Click to switch filter",
|
||||||
|
"smod.menu.info.cancelled": "<red>Cancelled by: <gold><arg:0>",
|
||||||
|
"smod.menu.info.click": "\u00BB Click to cancel punishment",
|
||||||
|
"smod.menu.info.duration": "<secondary>Duration: <primary><arg:0>",
|
||||||
|
"smod.menu.info.expiry.future": "<secondary>Expires: <primary>In <arg:0>",
|
||||||
|
"smod.menu.info.expiry.never": "<secondary>Expires: <primary>Never",
|
||||||
|
"smod.menu.info.expiry.past": "<secondary>Expired: <primary><arg:0> ago",
|
||||||
|
"smod.menu.info.player": "<secondary>Player: <primary><arg:0>",
|
||||||
|
"smod.menu.info.punishedBy": "<secondary>Punished by: <primary><arg:0>",
|
||||||
|
"smod.menu.info.reason": "<secondary>Reason: <primary><arg:0>",
|
||||||
|
"smod.menu.info.timestamp": "<secondary>Timestamp: <primary><arg:0>",
|
||||||
|
"smod.menu.search": "Search",
|
||||||
|
"smod.menu.search.current": "Current search query: <arg:0>",
|
||||||
|
"smod.menu.search.new": "\u00BB Click to enter new search query",
|
||||||
|
"smod.menu.search.none": "None",
|
||||||
|
"smod.menu.search.query": "Enter your search query in the chat",
|
||||||
|
"smod.menu.search.remove": "\u00BB Right click to remove search query",
|
||||||
|
"smod.menu.sort": "Sort by: <arg:0>",
|
||||||
|
"smod.menu.sort.expiry": "Expiry time",
|
||||||
|
"smod.menu.sort.moderatorName": "Moderator name",
|
||||||
|
"smod.menu.sort.playerName": "Player name",
|
||||||
|
"smod.menu.sort.switch": "\u00BB Click to switch sorting option",
|
||||||
|
"smod.menu.sort.time": "Time issued",
|
||||||
|
"smod.menu.type": "Type: <arg:0>",
|
||||||
|
"smod.menu.type.all": "All",
|
||||||
|
"smod.menu.type.switch": "» Click to switch type",
|
||||||
|
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> was banned by <secondary><arg:1></secondary> for <secondary><arg:3></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.ban.permanent": "<primary><secondary><arg:0></secondary> was banned <secondary>permanently</secondary> by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> was kicked by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> was muted by <secondary><arg:1></secondary> for <secondary><arg:3></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||||
|
"smod.punishment.broadcast.mute.permanent": "<primary><secondary><arg:0></secondary> was muted <secondary>permanently</secondary> by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||||
|
"smod.punishment.cancel.ban": "<primary><secondary><arg:0></secondary> was unbanned by <secondary><arg:1></secondary>.",
|
||||||
|
"smod.punishment.cancel.mute": "<primary><secondary><arg:0></secondary> was unmuted by <secondary><arg:1></secondary>.",
|
||||||
|
"smod.punishment.name.ban": "Ban",
|
||||||
|
"smod.punishment.name.kick": "Kick",
|
||||||
|
"smod.punishment.name.mute": "Mute",
|
||||||
|
"smod.punishment.playerMessage.ban": "<primary>You have been banned from this server by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your ban expires in <secondary><arg:2></secondary>.",
|
||||||
|
"smod.punishment.playerMessage.ban.permanent": "<primary>You have been banned from this server by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your ban <secondary>does not</secondary> expire.",
|
||||||
|
"smod.punishment.playerMessage.kick": "<primary>You have been kicked by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1>",
|
||||||
|
"smod.punishment.playerMessage.mute": "<primary>You have been muted by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your mute expires in <secondary><arg:2></secondary>.",
|
||||||
|
"smod.punishment.playerMessage.mute.permanent": "<primary>You have been muted by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your mute <secondary>does not</secondary> expire.",
|
||||||
|
"smod.punishment.playerMessage.mute.chat": "<primary>You can't run this command while you are muted.",
|
||||||
|
"smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>",
|
||||||
|
"smod.time.days": "<arg:0> days",
|
||||||
|
"smod.time.hours": "<arg:0> hours",
|
||||||
|
"smod.time.milliseconds": "<arg:0> milliseconds",
|
||||||
|
"smod.time.minutes": "<arg:0> minutes",
|
||||||
|
"smod.time.month.0": "January",
|
||||||
|
"smod.time.month.1": "February",
|
||||||
|
"smod.time.month.10": "November",
|
||||||
|
"smod.time.month.11": "December",
|
||||||
|
"smod.time.month.2": "March",
|
||||||
|
"smod.time.month.3": "April",
|
||||||
|
"smod.time.month.4": "May",
|
||||||
|
"smod.time.month.5": "June",
|
||||||
|
"smod.time.month.6": "July",
|
||||||
|
"smod.time.month.7": "August",
|
||||||
|
"smod.time.month.8": "September",
|
||||||
|
"smod.time.month.9": "October",
|
||||||
|
"smod.time.months": "<arg:0> months",
|
||||||
|
"smod.time.never": "Never",
|
||||||
|
"smod.time.permanent": "Permanent",
|
||||||
|
"smod.time.seconds": "<arg:0> seconds",
|
||||||
|
"smod.time.timestamp": "<arg:2> <arg:1> <arg:0> <arg:3>:<arg:4>:<arg:5> <arg:6>",
|
||||||
|
"smod.time.weeks": "<arg:0> weeks",
|
||||||
|
"smod.time.years": "<arg:0> years"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user