mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-29 06:34:17 +02:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a9cf76a93 | |||
| b3ec076cae | |||
| 3cb3314f4c | |||
| fb785fb53a | |||
| faa2eb0a43 | |||
| 8c00347ef2 | |||
| 8de4382ec4 | |||
| a7c487decd | |||
| 22f42df1da | |||
| 5c5eee0bca | |||
| d7560d5ef3 | |||
| ce8a8a44cd | |||
| 7902bb9a46 | |||
| b40e543f9e | |||
| ab037716c4 | |||
| 56aef4a2c9 | |||
| 755b758b2f | |||
| 4392456b15 | |||
| 0db57042af | |||
| 57b21c2e1f | |||
| a46e00a68d | |||
| bad8a4bb90 | |||
| 05c41dc4c3 | |||
| bf476c7a4b | |||
| d93a9aa9e4 | |||
| 7d94c782b8 | |||
| d8ff58191f | |||
| e2a344d92c | |||
| 1f91b2aa4e | |||
| 2b5a089a86 | |||
| 8698d7991d | |||
| 121d736468 | |||
| 762629e263 |
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Report bugs to help us make the plugin better and more reliable.
|
||||||
|
title: "[BUG]"
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Server**
|
||||||
|
Please provide information about the plugin version and the server.
|
||||||
|
This section should include:
|
||||||
|
1. Server Software
|
||||||
|
2. Server version
|
||||||
|
3. Plugin Version you are using
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this plugin
|
||||||
|
title: "[REQUEST]"
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
@@ -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.
|
||||||
@@ -14,65 +14,19 @@ SModeration provides a nice user interface that can be used instead of chat comm
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
It has helpful functions like filtering and sorting options.
|
It has helpful functions like filtering, searching and sorting options.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
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).
|
||||||
### /smod
|
The most important ones are:
|
||||||
The /smod command just opens the SMod menu. It takes no arguments.
|
- /mute
|
||||||
### /mute
|
- /ban
|
||||||
The /mute command is used to mute players.
|
- /kick
|
||||||
|
- /smod
|
||||||
It requires 2 arguments:
|
- /unmute & /unban
|
||||||
- Player name
|
- /invsee & /enderchestsee
|
||||||
- Duration
|
- /vanish
|
||||||
|
|
||||||
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.
|
|
||||||
### /invsee
|
|
||||||
The /invsee command can be used to view the inventory of another player.
|
|
||||||
|
|
||||||
It takes one argument: the player name.
|
|
||||||
The player has to be online.
|
|
||||||
### /enderchestsee
|
|
||||||
The /enderchestsee command can, similarly to /invsee, be used to view the ender chest of another player.
|
|
||||||
|
|
||||||
It takes one argument: the player name.
|
|
||||||
The player has to be online.
|
|
||||||
|
|
||||||
## 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.
|
|
||||||
- **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**: When giving this permission to a player, prevents their 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.
|
|
||||||
|
|
||||||
All of these permissions are granted by default if the player is a server operator.
|
|
||||||
+1
-1
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'de.shiewk'
|
group = 'de.shiewk'
|
||||||
version = '1.1'
|
version = pluginVersion
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -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 \<player> | Toggles vanish mode for another player. | 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,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 @@
|
|||||||
|
pluginVersion = 1.4.1
|
||||||
@@ -1,21 +1,25 @@
|
|||||||
package de.shiewk.smoderation;
|
package de.shiewk.smoderation;
|
||||||
|
|
||||||
import de.shiewk.smoderation.command.*;
|
import de.shiewk.smoderation.command.*;
|
||||||
import de.shiewk.smoderation.event.CustomInventoryEvents;
|
import de.shiewk.smoderation.config.SModerationConfig;
|
||||||
import de.shiewk.smoderation.event.EnderchestSeeEvents;
|
import de.shiewk.smoderation.input.ChatInputListener;
|
||||||
import de.shiewk.smoderation.event.InvSeeEvents;
|
import de.shiewk.smoderation.listener.*;
|
||||||
import de.shiewk.smoderation.listener.PunishmentListener;
|
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
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 net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.command.VanishCommand.isVanished;
|
||||||
|
import static de.shiewk.smoderation.command.VanishCommand.toggleVanish;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
import static org.bukkit.Bukkit.getPluginManager;
|
import static org.bukkit.Bukkit.getPluginManager;
|
||||||
|
|
||||||
public final class SModeration extends JavaPlugin {
|
public final class SModeration extends JavaPlugin {
|
||||||
@@ -23,78 +27,66 @@ public final class SModeration extends JavaPlugin {
|
|||||||
public static final PunishmentContainer container = new PunishmentContainer();
|
public static final PunishmentContainer container = new PunishmentContainer();
|
||||||
public static ComponentLogger LOGGER = null;
|
public static ComponentLogger LOGGER = null;
|
||||||
public static SModeration PLUGIN = null;
|
public static SModeration PLUGIN = null;
|
||||||
|
public static SModerationConfig CONFIG = null;
|
||||||
public static File SAVE_FILE = null;
|
public static File SAVE_FILE = null;
|
||||||
|
|
||||||
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
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 SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
||||||
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
||||||
public static final TextColor FAIL_COLOR = NamedTextColor.RED;
|
public static final TextColor FAIL_COLOR = NamedTextColor.RED;
|
||||||
public static final TextComponent CHAT_PREFIX = Component.text("SM \u00BB ").color(PRIMARY_COLOR);
|
public static final TextComponent CHAT_PREFIX = text("SM \u00BB ").color(PRIMARY_COLOR);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
LOGGER = getComponentLogger();
|
LOGGER = getComponentLogger();
|
||||||
PLUGIN = this;
|
PLUGIN = this;
|
||||||
|
CONFIG = new SModerationConfig(this.getConfig(), this);
|
||||||
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
|
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getPluginManager().registerEvents(new PunishmentListener(), this);
|
getPluginManager().registerEvents(new PunishmentListener(), this);
|
||||||
getPluginManager().registerEvents(new CustomInventoryEvents(), this);
|
getPluginManager().registerEvents(new CustomInventoryListener(), this);
|
||||||
getPluginManager().registerEvents(new InvSeeEvents(), this);
|
getPluginManager().registerEvents(new InvSeeListener(), this);
|
||||||
getPluginManager().registerEvents(new EnderchestSeeEvents(), this);
|
getPluginManager().registerEvents(new EnderchestSeeListener(), this);
|
||||||
|
getPluginManager().registerEvents(new VanishListener(), this);
|
||||||
|
getPluginManager().registerEvents(new ChatInputListener(), this);
|
||||||
|
getPluginManager().registerEvents(new SocialSpyListener(), this);
|
||||||
|
|
||||||
final PluginCommand mute = getCommand("mute");
|
registerCommand("mute", new MuteCommand());
|
||||||
assert mute != null;
|
registerCommand("ban", new BanCommand());
|
||||||
mute.setExecutor(new MuteCommand());
|
registerCommand("kick", new KickCommand());
|
||||||
mute.setTabCompleter(new MuteCommand());
|
registerCommand("smod", new SModCommand());
|
||||||
|
registerCommand("modlogs", new ModLogsCommand());
|
||||||
final PluginCommand ban = getCommand("ban");
|
registerCommand("unmute", new UnmuteCommand());
|
||||||
assert ban != null;
|
registerCommand("unban", new UnbanCommand());
|
||||||
ban.setExecutor(new BanCommand());
|
registerCommand("invsee", new InvseeCommand());
|
||||||
ban.setTabCompleter(new BanCommand());
|
registerCommand("enderchestsee", new EnderchestSeeCommand());
|
||||||
|
registerCommand("vanish", new VanishCommand());
|
||||||
final PluginCommand kick = getCommand("kick");
|
registerCommand("socialspy", new SocialSpyCommand());
|
||||||
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());
|
|
||||||
|
|
||||||
final PluginCommand invsee = getCommand("invsee");
|
|
||||||
assert invsee != null;
|
|
||||||
invsee.setExecutor(new InvseeCommand());
|
|
||||||
invsee.setTabCompleter(new InvseeCommand());
|
|
||||||
|
|
||||||
final PluginCommand ecsee = getCommand("enderchestsee");
|
|
||||||
assert ecsee != null;
|
|
||||||
ecsee.setExecutor(new EnderchestSeeCommand());
|
|
||||||
ecsee.setTabCompleter(new EnderchestSeeCommand());
|
|
||||||
|
|
||||||
container.load(SAVE_FILE);
|
container.load(SAVE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerCommand(String label, TabExecutor executor){
|
||||||
|
final PluginCommand command = getCommand(label);
|
||||||
|
if (command != null) {
|
||||||
|
command.setExecutor(executor);
|
||||||
|
command.setTabCompleter(executor);
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Command %s failed to register: This command does not exist".formatted(label));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
SModeration.container.save(SModeration.SAVE_FILE);
|
SModeration.container.save(SModeration.SAVE_FILE);
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
// in case players are still vanished when the server shuts down
|
||||||
|
if (isVanished(player)){
|
||||||
|
toggleVanish(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BanCommand implements CommandExecutor, TabCompleter {
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class BanCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 2){
|
if (args.length < 2){
|
||||||
@@ -45,6 +47,11 @@ public class BanCommand implements CommandExecutor, TabCompleter {
|
|||||||
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
final Player toPlayer = Bukkit.getPlayer(uuid);
|
||||||
|
if (toPlayer != null && toPlayer.hasPermission("smod.preventban")){
|
||||||
|
sender.sendMessage(text().content("This player can't be banned.").color(NamedTextColor.RED));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
long duration = 0;
|
long duration = 0;
|
||||||
int p = 1;
|
int p = 1;
|
||||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ import de.shiewk.smoderation.util.PlayerUtil;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
@@ -18,7 +17,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
import static de.shiewk.smoderation.SModeration.*;
|
||||||
|
|
||||||
public class EnderchestSeeCommand implements CommandExecutor, TabCompleter {
|
public class EnderchestSeeCommand implements TabExecutor {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -29,16 +28,12 @@ public class EnderchestSeeCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (sender instanceof HumanEntity human){
|
if (sender instanceof HumanEntity human){
|
||||||
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (human.getUniqueId().equals(player.getUniqueId())){
|
human.sendMessage(CHAT_PREFIX.append(
|
||||||
human.sendMessage(Component.text("You can't open your own ender chest.").color(FAIL_COLOR));
|
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
|
||||||
} else {
|
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||||
human.sendMessage(CHAT_PREFIX.append(
|
.append(Component.text("."))
|
||||||
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
|
));
|
||||||
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
human.openInventory(player.getEnderChest());
|
||||||
.append(Component.text("."))
|
|
||||||
));
|
|
||||||
human.openInventory(player.getEnderChest());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package de.shiewk.smoderation.command;
|
package de.shiewk.smoderation.command;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.inventory.InvSeeEquipmentInventory;
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
import de.shiewk.smoderation.util.PlayerUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
@@ -18,7 +18,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
import static de.shiewk.smoderation.SModeration.*;
|
||||||
|
|
||||||
public class InvseeCommand implements CommandExecutor, TabCompleter {
|
public class InvseeCommand implements TabExecutor {
|
||||||
|
|
||||||
|
private enum InvseeType {
|
||||||
|
INVENTORY,
|
||||||
|
EQUIPMENT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,10 +31,19 @@ public class InvseeCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final InvseeType type;
|
||||||
|
if (args.length > 1){
|
||||||
|
switch (args[1].toLowerCase()){
|
||||||
|
case "armor", "equipment" -> type = InvseeType.EQUIPMENT;
|
||||||
|
default -> type = InvseeType.INVENTORY;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
type = InvseeType.INVENTORY;
|
||||||
|
}
|
||||||
if (sender instanceof HumanEntity human){
|
if (sender instanceof HumanEntity human){
|
||||||
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (human.getUniqueId().equals(player.getUniqueId())){
|
if (human.getUniqueId().equals(player.getUniqueId()) && type != InvseeType.EQUIPMENT){
|
||||||
human.sendMessage(Component.text("You can't open your own inventory.").color(FAIL_COLOR));
|
human.sendMessage(Component.text("You can't open your own inventory.").color(FAIL_COLOR));
|
||||||
} else {
|
} else {
|
||||||
human.sendMessage(CHAT_PREFIX.append(
|
human.sendMessage(CHAT_PREFIX.append(
|
||||||
@@ -37,7 +51,10 @@ public class InvseeCommand implements CommandExecutor, TabCompleter {
|
|||||||
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||||
.append(Component.text("."))
|
.append(Component.text("."))
|
||||||
));
|
));
|
||||||
human.openInventory(player.getInventory());
|
switch (type){
|
||||||
|
case INVENTORY -> human.openInventory(player.getInventory());
|
||||||
|
case EQUIPMENT -> new InvSeeEquipmentInventory(human, player).open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
||||||
@@ -50,8 +67,10 @@ public class InvseeCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length > 1){
|
if (args.length > 2){
|
||||||
return List.of();
|
return List.of();
|
||||||
|
} else if (args.length > 1){
|
||||||
|
return List.of("armor", "equipment", "inventory");
|
||||||
}
|
}
|
||||||
List<String> available = new ArrayList<>();
|
List<String> available = new ArrayList<>();
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class KickCommand implements CommandExecutor, TabCompleter {
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class KickCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 1){
|
if (args.length < 1){
|
||||||
@@ -45,6 +47,10 @@ public class KickCommand implements CommandExecutor, TabCompleter {
|
|||||||
sender.sendMessage(Component.text("You can't kick yourself.").color(NamedTextColor.RED));
|
sender.sendMessage(Component.text("You can't kick yourself.").color(NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (player.hasPermission("smod.preventkick")){
|
||||||
|
sender.sendMessage(text().content("This player can't be kicked.").color(NamedTextColor.RED));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
StringBuilder reason = new StringBuilder();
|
StringBuilder reason = new StringBuilder();
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
if (!reason.isEmpty()){
|
if (!reason.isEmpty()){
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ 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;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -23,7 +22,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
import static de.shiewk.smoderation.SModeration.*;
|
||||||
|
|
||||||
public class ModLogsCommand implements CommandExecutor, TabCompleter {
|
public class ModLogsCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 1){
|
if (args.length < 1){
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import de.shiewk.smoderation.SModeration;
|
|||||||
import de.shiewk.smoderation.punishments.Punishment;
|
import de.shiewk.smoderation.punishments.Punishment;
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
import de.shiewk.smoderation.util.PlayerUtil;
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
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.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
@@ -17,7 +16,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MuteCommand implements CommandExecutor, TabCompleter {
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class MuteCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 2){
|
if (args.length < 2){
|
||||||
@@ -29,20 +30,25 @@ public class MuteCommand implements CommandExecutor, TabCompleter {
|
|||||||
} else if (sender instanceof Player pl){
|
} else if (sender instanceof Player pl){
|
||||||
senderUUID = pl.getUniqueId();
|
senderUUID = pl.getUniqueId();
|
||||||
} else if (sender instanceof BlockCommandSender){
|
} else if (sender instanceof BlockCommandSender){
|
||||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
sender.sendMessage(text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
sender.sendMessage(text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String playerName = args[0];
|
String playerName = args[0];
|
||||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
||||||
if (senderUUID.equals(uuid)) {
|
if (senderUUID.equals(uuid)) {
|
||||||
sender.sendMessage(Component.text("You can't mute yourself.").color(NamedTextColor.RED));
|
sender.sendMessage(text("You can't mute yourself.").color(NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
sender.sendMessage(text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final Player toPlayer = Bukkit.getPlayer(uuid);
|
||||||
|
if (toPlayer != null && toPlayer.hasPermission("smod.preventmute")){
|
||||||
|
sender.sendMessage(text().content("This player can't be muted.").color(NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
long duration = 0;
|
long duration = 0;
|
||||||
@@ -59,11 +65,11 @@ public class MuteCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (i == args.length - 1){ p = args.length; }
|
if (i == args.length - 1){ p = args.length; }
|
||||||
}
|
}
|
||||||
if (duration == 0){
|
if (duration == 0){
|
||||||
sender.sendMessage(Component.text("Please provide a valid duration.").color(NamedTextColor.RED));
|
sender.sendMessage(text("Please provide a valid duration.").color(NamedTextColor.RED));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (duration < 0){
|
if (duration < 0){
|
||||||
sender.sendMessage(Component.text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
sender.sendMessage(text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
StringBuilder reason = new StringBuilder();
|
StringBuilder reason = new StringBuilder();
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ package de.shiewk.smoderation.command;
|
|||||||
import de.shiewk.smoderation.SModeration;
|
import de.shiewk.smoderation.SModeration;
|
||||||
import de.shiewk.smoderation.inventory.SModMenu;
|
import de.shiewk.smoderation.inventory.SModMenu;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SModCommand implements CommandExecutor, TabCompleter {
|
public class SModCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||||
if (commandSender instanceof Player player){
|
if (commandSender instanceof Player player){
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.shiewk.smoderation.command;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.listener.SocialSpyListener;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.SModeration.CHAT_PREFIX;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class SocialSpyCommand implements TabExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
final boolean enabled = SocialSpyListener.toggle(sender);
|
||||||
|
sender.sendMessage(CHAT_PREFIX.append(text("SocialSpy ").append(
|
||||||
|
enabled ?
|
||||||
|
text("enabled").color(NamedTextColor.GREEN) :
|
||||||
|
text("disabled").color(NamedTextColor.RED)
|
||||||
|
).append(text("."))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UnbanCommand implements CommandExecutor, TabCompleter {
|
public class UnbanCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 1){
|
if (args.length < 1){
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UnmuteCommand implements CommandExecutor, TabCompleter {
|
public class UnmuteCommand implements TabExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 1){
|
if (args.length < 1){
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package de.shiewk.smoderation.command;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.SModeration;
|
||||||
|
import de.shiewk.smoderation.util.PlayerUtil;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||||
|
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.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.SModeration.*;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class VanishCommand implements TabExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
if (args.length == 0 || args[0].equalsIgnoreCase("toggle")){
|
||||||
|
Player player = null;
|
||||||
|
if (args.length > 1){
|
||||||
|
player = PlayerUtil.findOnlinePlayer(args[1]);
|
||||||
|
} else if (sender instanceof Player){
|
||||||
|
player = (Player) sender;
|
||||||
|
}
|
||||||
|
if (player != null){
|
||||||
|
toggleVanish(player);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (args[0].equalsIgnoreCase("list")) {
|
||||||
|
if (sender.hasPermission("smod.vanish.see")){
|
||||||
|
listVanishedPlayersTo(sender);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(text().color(NamedTextColor.RED).content("You do not have permission to list all vanished players."));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
if (args.length < 2){
|
||||||
|
return List.of("list", "toggle");
|
||||||
|
}
|
||||||
|
if (args.length < 3 && args[0].equalsIgnoreCase("toggle")){
|
||||||
|
return PlayerUtil.listPlayerNames(args[1]);
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
public static void toggleVanish(Player player){
|
||||||
|
final boolean newStatus = !isVanished(player);
|
||||||
|
if (newStatus){
|
||||||
|
vanishedPlayers.add(player);
|
||||||
|
for (CommandSender sender : SModeration.container.collectBroadcastTargets()) {
|
||||||
|
sender.sendMessage(CHAT_PREFIX.append(
|
||||||
|
player.displayName()
|
||||||
|
.colorIfAbsent(SECONDARY_COLOR)
|
||||||
|
).append(
|
||||||
|
text()
|
||||||
|
.content(" vanished.")
|
||||||
|
.color(PRIMARY_COLOR)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
player.sendMessage(CHAT_PREFIX.append(text("You are now vanished.").color(PRIMARY_COLOR)));
|
||||||
|
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 : container.collectBroadcastTargets()) {
|
||||||
|
sender.sendMessage(CHAT_PREFIX.append(
|
||||||
|
player.displayName()
|
||||||
|
.colorIfAbsent(SECONDARY_COLOR)
|
||||||
|
).append(
|
||||||
|
text()
|
||||||
|
.content(" re-appeared.")
|
||||||
|
.color(PRIMARY_COLOR)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
player.sendMessage(CHAT_PREFIX.append(text("You are no longer vanished.").color(PRIMARY_COLOR)));
|
||||||
|
player.setVisibleByDefault(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(CHAT_PREFIX.append(
|
||||||
|
text().content("No players are currently vanished.").color(PRIMARY_COLOR)
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
Component vanishList = CHAT_PREFIX.append(
|
||||||
|
text().content("The following players are currently vanished: ").color(PRIMARY_COLOR)
|
||||||
|
);
|
||||||
|
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||||
|
Player vanishedPlayer = iterator.next();
|
||||||
|
vanishList = vanishList.append(
|
||||||
|
vanishedPlayer.displayName().colorIfAbsent(SECONDARY_COLOR)
|
||||||
|
);
|
||||||
|
if (iterator.hasNext()){
|
||||||
|
vanishList = vanishList.append(
|
||||||
|
text().content(", ").color(PRIMARY_COLOR)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
receiver.sendMessage(vanishList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package de.shiewk.smoderation.config;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.SModeration;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SModerationConfig {
|
||||||
|
|
||||||
|
private final FileConfiguration config;
|
||||||
|
private final SModeration plugin;
|
||||||
|
|
||||||
|
public SModerationConfig(FileConfiguration config, SModeration plugin) {
|
||||||
|
this.config = config;
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getSocialSpyCommands(List<String> default_){
|
||||||
|
final String path = "socialspy-commands";
|
||||||
|
if (!config.contains(path)){
|
||||||
|
config.set(path, default_);
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
return config.getStringList(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package de.shiewk.smoderation.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.SModeration.CHAT_PREFIX;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
text().content(getRemainingTicks() / 20 + " seconds").color(GRAY).build(),
|
||||||
|
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(CHAT_PREFIX.append(prompt));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getPrompt() {
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Consumer<Component> getAction() {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRemainingTicks() {
|
||||||
|
return remainingTicks;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.shiewk.smoderation.input;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
runningInputs.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR) public void onServerTickStart(ServerTickStartEvent event){
|
||||||
|
ChatInput.tickAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package de.shiewk.smoderation.inventory;
|
||||||
|
|
||||||
|
public interface AutoUpdatingCustomInventory extends CustomInventory { }
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package de.shiewk.smoderation.inventory;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.SModeration;
|
||||||
|
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.bukkit.inventory.ItemStack;
|
||||||
|
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(ItemStack stack, InventoryClickEvent event) {
|
||||||
|
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||||
|
event.setCancelled(false);
|
||||||
|
changing = true;
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(SModeration.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package de.shiewk.smoderation.inventory;
|
package de.shiewk.smoderation.inventory;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.input.ChatInput;
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
import de.shiewk.smoderation.punishments.Punishment;
|
||||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
import de.shiewk.smoderation.punishments.PunishmentType;
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
import de.shiewk.smoderation.util.PlayerUtil;
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
import de.shiewk.smoderation.util.TimeUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
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.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -15,6 +17,7 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
@@ -25,9 +28,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static de.shiewk.smoderation.SModeration.*;
|
import static de.shiewk.smoderation.SModeration.*;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
public class SModMenu extends PageableCustomInventory {
|
public class SModMenu extends PageableCustomInventory {
|
||||||
|
|
||||||
@@ -70,13 +75,17 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
private List<Punishment> punishments;
|
private List<Punishment> punishments;
|
||||||
private ItemStack sortStack = null;
|
private ItemStack sortStack = null;
|
||||||
private ItemStack filterStack = null;
|
private ItemStack filterStack = null;
|
||||||
|
private ItemStack searchStack = null;
|
||||||
|
private ItemStack typeStack = null;
|
||||||
private int sort = 0;
|
private int sort = 0;
|
||||||
private int filter = 0;
|
private int filter = 0;
|
||||||
|
private int type = -1;
|
||||||
|
private String searchQuery = null;
|
||||||
|
|
||||||
public SModMenu(Player player, PunishmentContainer container) {
|
public SModMenu(Player player, PunishmentContainer container) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.inventory = Bukkit.createInventory(this, 54, Component.text("SMod Menu"));
|
this.inventory = Bukkit.createInventory(this, 54, text("SMod Menu"));
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +97,27 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
return Filter.values()[filter];
|
return Filter.values()[filter];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PunishmentType getType(){
|
||||||
|
return type == -1 ? null : PunishmentType.values()[type];
|
||||||
|
}
|
||||||
|
|
||||||
private void reload(){
|
private void reload(){
|
||||||
this.punishments = container.copy().stream().filter(getFilter().filter).sorted(getSort().comparator).toList();
|
this.punishments = container.copy().stream()
|
||||||
|
.filter(getFilter().filter)
|
||||||
|
.filter(p -> getType() == null || p.type == getType())
|
||||||
|
.filter(p -> p.matchesSearchQuery(searchQuery))
|
||||||
|
.sorted(getSort().comparator).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void promptSearchQuery(){
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN, player::closeInventory);
|
||||||
|
ChatInput.prompt(player, component -> {
|
||||||
|
if (component instanceof TextComponent text){
|
||||||
|
this.searchQuery = text.content();
|
||||||
|
// chat event is async
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN, this::open);
|
||||||
|
}
|
||||||
|
}, text("Enter your search query in chat").color(SECONDARY_COLOR), 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -135,6 +163,25 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cycleType(boolean backwards){
|
||||||
|
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||||
|
if (backwards){
|
||||||
|
if (type <= -1){
|
||||||
|
type = PunishmentType.values().length-1;
|
||||||
|
} else {
|
||||||
|
type--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (type >= PunishmentType.values().length-1){
|
||||||
|
type = -1;
|
||||||
|
} else {
|
||||||
|
type++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reload();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void switchPage() {
|
public void switchPage() {
|
||||||
player.playSound(player, Sound.BLOCK_STONE_HIT, 0.75f, 1f);
|
player.playSound(player, Sound.BLOCK_STONE_HIT, 0.75f, 1f);
|
||||||
@@ -144,55 +191,101 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
final Filter filter = getFilter();
|
final Filter filter = getFilter();
|
||||||
final ItemStack stack = new ItemStack(Filter.ICON);
|
final ItemStack stack = new ItemStack(Filter.ICON);
|
||||||
stack.editMeta(meta -> {
|
stack.editMeta(meta -> {
|
||||||
meta.displayName(applyFormatting(Component.text("Filter: " + filter.name).color(SECONDARY_COLOR)));
|
meta.displayName(applyFormatting(text("Filter: " + filter.name).color(PRIMARY_COLOR)));
|
||||||
ArrayList<Component> lore = new ArrayList<>();
|
ArrayList<Component> lore = new ArrayList<>();
|
||||||
lore.add(Component.empty());
|
lore.add(Component.empty());
|
||||||
for (Filter value : Filter.values()) {
|
for (Filter value : Filter.values()) {
|
||||||
final boolean selected = filter == value;
|
final boolean selected = filter == value;
|
||||||
Component filterText = applyFormatting(Component.text((selected ? "\u00BB " : "") + value.name).color(selected ? PRIMARY_COLOR : INACTIVE_COLOR));
|
Component filterText = applyFormatting(text((selected ? "\u00BB " : "") + value.name).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
||||||
lore.add(filterText);
|
lore.add(filterText);
|
||||||
}
|
}
|
||||||
lore.add(Component.empty());
|
lore.add(Component.empty());
|
||||||
lore.add(applyFormatting(Component.text("\u00BB Click to switch filter").color(NamedTextColor.GOLD)));
|
lore.add(applyFormatting(text("\u00BB Click to switch filter").color(NamedTextColor.GOLD)));
|
||||||
meta.lore(lore);
|
meta.lore(lore);
|
||||||
});
|
});
|
||||||
filterStack = stack;
|
filterStack = stack;
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ItemStack createTypeItem(){
|
||||||
|
final PunishmentType type = getType();
|
||||||
|
final ItemStack stack = new ItemStack(Material.CHEST);
|
||||||
|
stack.editMeta(meta -> {
|
||||||
|
meta.displayName(applyFormatting(text("Type: " + (type == null ? "All" : type.name)).color(PRIMARY_COLOR)));
|
||||||
|
ArrayList<Component> lore = new ArrayList<>();
|
||||||
|
lore.add(Component.empty());
|
||||||
|
final Consumer<PunishmentType> addToLore = value -> {
|
||||||
|
final boolean selected = type == value;
|
||||||
|
Component typeText = applyFormatting(text((selected ? "\u00BB " : "") + (value == null ? "All" : value.name)).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
||||||
|
lore.add(typeText);
|
||||||
|
};
|
||||||
|
addToLore.accept(null);
|
||||||
|
for (PunishmentType value : PunishmentType.values()) {
|
||||||
|
addToLore.accept(value);
|
||||||
|
}
|
||||||
|
lore.add(Component.empty());
|
||||||
|
lore.add(applyFormatting(text("\u00BB Click to switch type").color(NamedTextColor.GOLD)));
|
||||||
|
meta.lore(lore);
|
||||||
|
});
|
||||||
|
return typeStack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
private ItemStack createSortItem(){
|
private ItemStack createSortItem(){
|
||||||
final Sort sort = getSort();
|
final Sort sort = getSort();
|
||||||
final ItemStack stack = new ItemStack(Sort.ICON);
|
final ItemStack stack = new ItemStack(Sort.ICON);
|
||||||
stack.editMeta(meta -> {
|
stack.editMeta(meta -> {
|
||||||
meta.displayName(applyFormatting(Component.text("Sort by: " + sort.name).color(PRIMARY_COLOR)));
|
meta.displayName(applyFormatting(text("Sort by: " + sort.name).color(PRIMARY_COLOR)));
|
||||||
ArrayList<Component> lore = new ArrayList<>();
|
ArrayList<Component> lore = new ArrayList<>();
|
||||||
lore.add(Component.empty());
|
lore.add(Component.empty());
|
||||||
for (Sort value : Sort.values()) {
|
for (Sort value : Sort.values()) {
|
||||||
final boolean selected = sort == value;
|
final boolean selected = sort == value;
|
||||||
Component sortText = applyFormatting(Component.text((selected ? "\u00BB " : "") + value.name).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
Component sortText = applyFormatting(text((selected ? "\u00BB " : "") + value.name).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
||||||
lore.add(sortText);
|
lore.add(sortText);
|
||||||
}
|
}
|
||||||
lore.add(Component.empty());
|
lore.add(Component.empty());
|
||||||
lore.add(applyFormatting(Component.text("\u00BB Click to switch sorting option").color(NamedTextColor.GOLD)));
|
lore.add(applyFormatting(text("\u00BB Click to switch sorting option").color(NamedTextColor.GOLD)));
|
||||||
meta.lore(lore);
|
meta.lore(lore);
|
||||||
});
|
});
|
||||||
sortStack = stack;
|
sortStack = stack;
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ItemStack createSearchItem(){
|
||||||
|
final ItemStack stack = new ItemStack(Material.FLOWER_BANNER_PATTERN);
|
||||||
|
stack.editMeta(meta -> {
|
||||||
|
meta.addItemFlags(ItemFlag.HIDE_ITEM_SPECIFICS);
|
||||||
|
meta.displayName(applyFormatting(text("Search").color(PRIMARY_COLOR)));
|
||||||
|
final ArrayList<Component> lore = new ArrayList<>(List.of(
|
||||||
|
Component.empty(),
|
||||||
|
applyFormatting(text("Current search query: %s".formatted(searchQuery == null ? "None" : "\"" + searchQuery + "\"")).color(SECONDARY_COLOR)),
|
||||||
|
Component.empty(),
|
||||||
|
applyFormatting(text("\u00BB Click to enter new search query").color(NamedTextColor.GOLD))
|
||||||
|
));
|
||||||
|
if (searchQuery != null){
|
||||||
|
lore.add(applyFormatting(text("\u00BB Right click to remove search query").color(NamedTextColor.GOLD)));
|
||||||
|
}
|
||||||
|
meta.lore(lore);
|
||||||
|
});
|
||||||
|
return searchStack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
private ItemStack createPunishmentItem(Punishment punishment){
|
private ItemStack createPunishmentItem(Punishment punishment){
|
||||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||||
stack.editMeta(meta -> {
|
stack.editMeta(meta -> {
|
||||||
if (meta instanceof SkullMeta skullMeta){
|
if (meta instanceof SkullMeta skullMeta){
|
||||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to));
|
try {
|
||||||
|
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to));
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.to);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
meta.displayName(applyFormatting(Component.text(punishment.type.name).color(NamedTextColor.RED).decorate(TextDecoration.BOLD)));
|
meta.displayName(applyFormatting(text(punishment.type.name).color(NamedTextColor.RED).decorate(TextDecoration.BOLD)));
|
||||||
ArrayList<Component> lore = new ArrayList<>();
|
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(text("Player: ").color(SECONDARY_COLOR).append(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(text("Punished by: ").color(SECONDARY_COLOR).append(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))));
|
lore.add(applyFormatting(text("Timestamp: ").color(SECONDARY_COLOR).append(text(TimeUtil.calendarTimestamp(punishment.time)).color(PRIMARY_COLOR))));
|
||||||
if (punishment.type != PunishmentType.KICK){
|
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))));
|
lore.add(applyFormatting(text("Duration: ").color(SECONDARY_COLOR).append(text(TimeUtil.formatTimeLong(punishment.until - punishment.time)).color(PRIMARY_COLOR))));
|
||||||
long remainingTime = punishment.until - System.currentTimeMillis();
|
long remainingTime = punishment.until - System.currentTimeMillis();
|
||||||
final String expires;
|
final String expires;
|
||||||
if (remainingTime > 0){
|
if (remainingTime > 0){
|
||||||
@@ -201,15 +294,15 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
remainingTime *= -1;
|
remainingTime *= -1;
|
||||||
expires = TimeUtil.formatTimeLong(remainingTime) + " ago";
|
expires = TimeUtil.formatTimeLong(remainingTime) + " ago";
|
||||||
}
|
}
|
||||||
lore.add(applyFormatting(Component.text("Expires: ").color(SECONDARY_COLOR).append(Component.text(expires).color(PRIMARY_COLOR))));
|
lore.add(applyFormatting(text("Expires: ").color(SECONDARY_COLOR).append(text(expires).color(PRIMARY_COLOR))));
|
||||||
}
|
}
|
||||||
lore.add(applyFormatting(Component.text("Reason: ").color(SECONDARY_COLOR).append(Component.text(punishment.reason).color(PRIMARY_COLOR))));
|
lore.add(applyFormatting(text("Reason: ").color(SECONDARY_COLOR).append(text(punishment.reason).color(PRIMARY_COLOR))));
|
||||||
if (punishment.wasUndone()){
|
if (punishment.wasUndone()){
|
||||||
lore.add(applyFormatting(Component.text("Undone by: ").color(NamedTextColor.RED).append(Component.text(PlayerUtil.offlinePlayerName(punishment.undoneBy())).color(NamedTextColor.GOLD))));
|
lore.add(applyFormatting(text("Undone by: ").color(NamedTextColor.RED).append(text(PlayerUtil.offlinePlayerName(punishment.undoneBy())).color(NamedTextColor.GOLD))));
|
||||||
} else if (punishment.isActive()) {
|
} else if (punishment.isActive()) {
|
||||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))){
|
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))){
|
||||||
lore.add(Component.empty());
|
lore.add(Component.empty());
|
||||||
lore.add(applyFormatting(Component.text("\u00BB Click to undo punishment").color(NamedTextColor.GOLD)));
|
lore.add(applyFormatting(text("\u00BB Click to undo punishment").color(NamedTextColor.GOLD)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
meta.lore(lore);
|
meta.lore(lore);
|
||||||
@@ -224,8 +317,10 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
}
|
}
|
||||||
inventory.setItem(45, createPreviousPageStack());
|
inventory.setItem(45, createPreviousPageStack());
|
||||||
inventory.setItem(53, createNextPageStack());
|
inventory.setItem(53, createNextPageStack());
|
||||||
|
inventory.setItem(47, createSearchItem());
|
||||||
|
inventory.setItem(48, createTypeItem());
|
||||||
inventory.setItem(50, createFilterItem());
|
inventory.setItem(50, createFilterItem());
|
||||||
inventory.setItem(48, createSortItem());
|
inventory.setItem(51, createSortItem());
|
||||||
|
|
||||||
for (int i = 0; i < 45; i++) {
|
for (int i = 0; i < 45; i++) {
|
||||||
int ci = i + (getPage() * 45);
|
int ci = i + (getPage() * 45);
|
||||||
@@ -252,6 +347,18 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
cycleFilter(event.isRightClick());
|
cycleFilter(event.isRightClick());
|
||||||
} else if (stack.equals(sortStack)){
|
} else if (stack.equals(sortStack)){
|
||||||
cycleSort(event.isRightClick());
|
cycleSort(event.isRightClick());
|
||||||
|
} else if (stack.equals(searchStack)){
|
||||||
|
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 (stack.equals(typeStack)) {
|
||||||
|
cycleType(event.isRightClick());
|
||||||
}
|
}
|
||||||
final ItemMeta itemMeta = stack.getItemMeta();
|
final ItemMeta itemMeta = stack.getItemMeta();
|
||||||
if (itemMeta != null) {
|
if (itemMeta != null) {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package de.shiewk.smoderation.listener;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
||||||
|
import de.shiewk.smoderation.inventory.AutoUpdatingCustomInventory;
|
||||||
|
import de.shiewk.smoderation.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.getCurrentItem(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void onInventoryDrag(InventoryDragEvent event){
|
||||||
|
if (event.getInventory().getHolder() instanceof CustomInventory){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onServerTickEnd(ServerTickEndEvent event){
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.getOpenInventory().getTopInventory().getHolder() instanceof AutoUpdatingCustomInventory ci) {
|
||||||
|
ci.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package de.shiewk.smoderation.event;
|
package de.shiewk.smoderation.listener;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -8,14 +8,14 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
public class EnderchestSeeEvents implements Listener {
|
public class EnderchestSeeListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent event){
|
public void onInventoryClick(InventoryClickEvent event){
|
||||||
final Inventory clicked = event.getView().getTopInventory();
|
final Inventory clicked = event.getView().getTopInventory();
|
||||||
if (!(clicked instanceof PlayerInventory)){
|
if (!(clicked instanceof PlayerInventory)){
|
||||||
final InventoryHolder holder = clicked.getHolder();
|
final InventoryHolder holder = clicked.getHolder();
|
||||||
if (holder instanceof HumanEntity humanHolder){
|
if (holder instanceof HumanEntity humanHolder && humanHolder.getEnderChest().equals(clicked) && !humanHolder.equals(event.getWhoClicked())){
|
||||||
if (!event.getWhoClicked().hasPermission("smod.enderchestsee.modify")){
|
if (!event.getWhoClicked().hasPermission("smod.enderchestsee.modify")){
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
+7
-2
@@ -1,4 +1,4 @@
|
|||||||
package de.shiewk.smoderation.event;
|
package de.shiewk.smoderation.listener;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -7,13 +7,18 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
public class InvSeeEvents implements Listener {
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class InvSeeListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent event){
|
public void onInventoryClick(InventoryClickEvent event){
|
||||||
final Inventory clicked = event.getView().getTopInventory();
|
final Inventory clicked = event.getView().getTopInventory();
|
||||||
if (clicked instanceof PlayerInventory inventory){
|
if (clicked instanceof PlayerInventory inventory){
|
||||||
final HumanEntity holder = inventory.getHolder();
|
final HumanEntity holder = inventory.getHolder();
|
||||||
|
if (Objects.equals(holder, event.getWhoClicked())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!event.getWhoClicked().hasPermission("smod.invsee.modify")){
|
if (!event.getWhoClicked().hasPermission("smod.invsee.modify")){
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package de.shiewk.smoderation.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.SModeration;
|
||||||
|
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 de.shiewk.smoderation.SModeration.PRIMARY_COLOR;
|
||||||
|
import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class SocialSpyListener implements Listener {
|
||||||
|
|
||||||
|
private static final List<String> defaultCommands = List.of(
|
||||||
|
"w",
|
||||||
|
"tell",
|
||||||
|
"msg",
|
||||||
|
"teammsg",
|
||||||
|
"tm",
|
||||||
|
"minecraft:w",
|
||||||
|
"minecraft:tell",
|
||||||
|
"minecraft:msg",
|
||||||
|
"minecraft:teammsg",
|
||||||
|
"minecraft:tm"
|
||||||
|
);
|
||||||
|
|
||||||
|
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> ssCommands = SModeration.CONFIG.getSocialSpyCommands(defaultCommands);
|
||||||
|
final String message = event.getMessage();
|
||||||
|
if (ssCommands.stream().anyMatch(str ->
|
||||||
|
message.startsWith("/"+str+" ")
|
||||||
|
|| message.startsWith(str+" ")
|
||||||
|
)){
|
||||||
|
SocialSpyListener.command(event.getPlayer(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void command(Player player, String command){
|
||||||
|
for (CommandSender target : targets) {
|
||||||
|
target.sendMessage(text("[", PRIMARY_COLOR)
|
||||||
|
.append(text("SocialSpy", SECONDARY_COLOR))
|
||||||
|
.append(text("] "))
|
||||||
|
.append(player.displayName().colorIfAbsent(PRIMARY_COLOR))
|
||||||
|
.append(text(": ", PRIMARY_COLOR))
|
||||||
|
.append(text(command, SECONDARY_COLOR))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package de.shiewk.smoderation.listener;
|
||||||
|
|
||||||
|
import de.shiewk.smoderation.SModeration;
|
||||||
|
import de.shiewk.smoderation.command.VanishCommand;
|
||||||
|
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.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class VanishListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
if (VanishCommand.isVanished(player)){
|
||||||
|
VanishCommand.toggleVanish(player);
|
||||||
|
}
|
||||||
|
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||||
|
// to clean up visibility status
|
||||||
|
player.hideEntity(SModeration.PLUGIN, vanishedPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(SModeration.PLUGIN, () -> {
|
||||||
|
final Player player = event.getPlayer().getPlayer();
|
||||||
|
assert player != null;
|
||||||
|
if (player.hasPermission("smod.vanish.see")){
|
||||||
|
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||||
|
// to show visible vanished players
|
||||||
|
player.showEntity(SModeration.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);
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||||
|
onlinePlayer.sendMessage(text("[VANISH] ").color(SECONDARY_COLOR).append(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -239,4 +239,23 @@ public class Punishment {
|
|||||||
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean matchesSearchQuery(String searchQuery) {
|
||||||
|
if (searchQuery == null) return true;
|
||||||
|
searchQuery = searchQuery.toLowerCase();
|
||||||
|
return reason.toLowerCase().contains(searchQuery)
|
||||||
|
|| by.toString().equalsIgnoreCase(searchQuery)
|
||||||
|
|| to.toString().equalsIgnoreCase(searchQuery)
|
||||||
|
|| getPlayerName().toLowerCase().contains(searchQuery)
|
||||||
|
|| getModeratorName().toLowerCase().contains(searchQuery);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPlayerName() {
|
||||||
|
return PlayerUtil.offlinePlayerName(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getModeratorName() {
|
||||||
|
return PlayerUtil.offlinePlayerName(by);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public abstract class PlayerUtil {
|
public abstract class PlayerUtil {
|
||||||
private PlayerUtil(){}
|
private PlayerUtil(){}
|
||||||
@@ -21,7 +25,7 @@ public abstract class PlayerUtil {
|
|||||||
return "CONSOLE";
|
return "CONSOLE";
|
||||||
}
|
}
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
return player.getName() == null ? uuid.toString() : player.getName();
|
return player.getName() == null ? "Unknown Player" + uuid : player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable UUID offlinePlayerUUIDByName(String name){
|
public static @Nullable UUID offlinePlayerUUIDByName(String name){
|
||||||
@@ -55,4 +59,21 @@ public abstract class PlayerUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> listPlayerNames(){
|
||||||
|
return listPlayerNames(pl -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> listPlayerNames(final Predicate<Player> predicate) {
|
||||||
|
final ArrayList<String> names = new ArrayList<>();
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (predicate.test(onlinePlayer)){
|
||||||
|
names.add(onlinePlayer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return List.copyOf(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> listPlayerNames(String search) {
|
||||||
|
return StringUtil.copyPartialMatches(search, listPlayerNames(), new ArrayList<>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,24 @@ commands:
|
|||||||
- ecs
|
- ecs
|
||||||
permission: smod.enderchestsee
|
permission: smod.enderchestsee
|
||||||
description: Views the ender chest of another player.
|
description: Views the ender chest of another player.
|
||||||
|
vanish:
|
||||||
|
usage: "§cUsage: /vanish list or /vanish toggle <player>"
|
||||||
|
aliases:
|
||||||
|
- smvanish
|
||||||
|
- smodvanish
|
||||||
|
- v
|
||||||
|
- smv
|
||||||
|
permission: smod.vanish
|
||||||
|
description: Toggles vanish mode which prevents other players from seeing you're online
|
||||||
|
socialspy:
|
||||||
|
usage: "§cUsage: /socialspy"
|
||||||
|
description: Enables socialspy mode (you can see private messages of other players)
|
||||||
|
permission: smod.socialspy
|
||||||
|
aliases:
|
||||||
|
- smodsocialspy
|
||||||
|
- smsocialspy
|
||||||
|
- smss
|
||||||
|
- ss
|
||||||
permissions:
|
permissions:
|
||||||
smod.mute:
|
smod.mute:
|
||||||
default: op
|
default: op
|
||||||
@@ -117,3 +135,21 @@ permissions:
|
|||||||
description: Allows the player to view and modify other players ender chests.
|
description: Allows the player to view and modify other players ender chests.
|
||||||
children:
|
children:
|
||||||
- smod.enderchestsee
|
- 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 muted (if online)
|
||||||
|
smod.preventban:
|
||||||
|
default: op
|
||||||
|
description: Prevents the player from being muted (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
|
||||||
Reference in New Issue
Block a user