1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-29 06:34:17 +02:00

14 Commits

Author SHA1 Message Date
Shiewk 4266b7ebb6 Update main branch to version 1.2.0
- Improved command registration
- Add permissions for mute/kick/ban immunity
- Add vanish command and permissions
- Update to version 1.2.0
2024-07-23 18:36:40 +02:00
Shiewk a46e00a68d Remove duplicate methods 2024-07-23 17:48:42 +02:00
Shiewk bad8a4bb90 Merge remote-tracking branch 'origin/dev' into dev 2024-07-23 17:35:15 +02:00
Shiewk 05c41dc4c3 Update to version 1.2.0 2024-07-23 17:34:54 +02:00
Shiewk bf476c7a4b Add vanish command and permissions 2024-07-23 17:34:14 +02:00
Shiewk d93a9aa9e4 Add vanish command and permissions 2024-07-23 17:23:05 +02:00
Shiewk 7d94c782b8 Add permissions for mute/kick/ban immunity 2024-07-23 16:23:40 +02:00
Shiewk d8ff58191f Improved command registration 2024-07-23 15:04:36 +02:00
Shiewk e2a344d92c Create commands.md 2024-07-22 10:00:37 +02:00
Shiewk 1f91b2aa4e Create permissions.md 2024-07-22 09:58:05 +02:00
Shiewk 2b5a089a86 Update issue templates 2024-07-19 19:01:39 +02:00
Shiewk 8698d7991d Add LICENSE 2024-07-19 10:42:50 +02:00
Shiewk 121d736468 Update version to 1.1.1 2024-07-10 11:16:38 +02:00
Shiewk 762629e263 Fix InvSee bug 2024-07-10 11:16:21 +02:00
23 changed files with 576 additions and 128 deletions
+34
View File
@@ -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.
+20
View File
@@ -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.
+201
View File
@@ -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.
+9 -56
View File
@@ -17,62 +17,15 @@ SModeration provides a nice user interface that can be used instead of chat comm
It has helpful functions like filtering and sorting options.
## Commands
### /smod
The /smod command just opens the SMod menu. It takes no arguments.
### /mute
The /mute command is used to mute players.
It requires 2 arguments:
- Player name
- Duration
If you want to, you can also add a **reason**.
For example, if you want to mute a player for breaking server rules, just use **/mute playername 1h 30min Breaking server rules.**
The player will be muted for 1 hour and 30 minutes with the reason "Breaking server rules.".
Muted players can still join the server, but can't use the chat.
### /ban
The /ban command works the same as the /mute command, with one important difference:
Banned players **can't even join** the server until the ban expires.
### /kick
The /kick command is a bit different. It does not require a duration because kicks are instant. Instead, you can use the command like this: **/kick playername reason**
### /modlogs
The /modlogs command can be used when the /smod menu is unavailable. It displays information about a player in chat instead of a menu.
Example: **/modlogs playername** shows you a message in chat that tells you whether the player is muted or banned.
### /unmute & /unban
The /unmute and /unban commands only take one argument, the player name.
The specified player will then be unmuted or unbanned.
### /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.
This plugin has many commands, for a complete list of commands and their usage, please see [the commands list](https://github.com/Shiewk/SModeration/blob/main/docs/commands.md).
The most important ones are:
- /mute
- /ban
- /kick
- /smod
- /unmute & /unban
- /invsee & /enderchestsee
## Permissions
This plugin uses Bukkit permissions for commands and other actions.
- **smod.mute**: Allows the player to mute other players.
- **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.
For a list of permissions, please see [the permissions file](https://github.com/Shiewk/SModeration/blob/main/docs/permissions.md).
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
}
group = 'de.shiewk'
version = '1.1'
version = pluginVersion
repositories {
mavenCentral()
+53
View File
@@ -0,0 +1,53 @@
# SModeration commands
### /smod
The /smod command just opens the SMod menu. It takes no arguments.
### /mute
The /mute command is used to mute players.
It requires 2 arguments:
- Player name
- Duration
If you want to, you can also add a **reason**.
For example, if you want to mute a player for breaking server rules, just use **/mute playername 1h 30min Breaking server rules.**
The player will be muted for 1 hour and 30 minutes with the reason "Breaking server rules.".
Muted players can still join the server, but can't use the chat.
### /ban
The /ban command works the same as the /mute command, with one important difference:
Banned players **can't even join** the server until the ban expires.
### /kick
The /kick command is a bit different. It does not require a duration because kicks are instant. Instead, you can use the command like this: **/kick playername reason**
### /modlogs
The /modlogs command can be used when the /smod menu is unavailable. It displays information about a player in chat instead of a menu.
Example: **/modlogs playername** shows you a message in chat that tells you whether the player is muted or banned.
### /unmute & /unban
The /unmute and /unban commands only take one argument, the player name.
The specified player will then be unmuted or unbanned.
### /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.
### /vanish
The /vanish command is used to toggle vanish mode.
In vanish mode, other players (who don't have the necessary permissions) can't see that you're online.
To toggle vanish mode for yourself, use **/vanish**.
To toggle vanish mode for someone else, use **/vanish <playername>**.
Vanish status is not saved, so you re-appear when you leave the server.
+19
View File
@@ -0,0 +1,19 @@
# SModeration permissions
- **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**: 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
View File
@@ -0,0 +1 @@
pluginVersion = 1.2.0
@@ -5,17 +5,23 @@ import de.shiewk.smoderation.event.CustomInventoryEvents;
import de.shiewk.smoderation.event.EnderchestSeeEvents;
import de.shiewk.smoderation.event.InvSeeEvents;
import de.shiewk.smoderation.listener.PunishmentListener;
import de.shiewk.smoderation.listener.VanishListener;
import de.shiewk.smoderation.storage.PunishmentContainer;
import net.kyori.adventure.text.Component;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import static net.kyori.adventure.text.Component.text;
import static org.bukkit.Bukkit.getPluginManager;
public final class SModeration extends JavaPlugin {
@@ -29,7 +35,7 @@ public final class SModeration extends JavaPlugin {
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
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
public void onLoad() {
@@ -44,57 +50,88 @@ public final class SModeration extends JavaPlugin {
getPluginManager().registerEvents(new CustomInventoryEvents(), this);
getPluginManager().registerEvents(new InvSeeEvents(), this);
getPluginManager().registerEvents(new EnderchestSeeEvents(), this);
getPluginManager().registerEvents(new VanishListener(), this);
final PluginCommand mute = getCommand("mute");
assert mute != null;
mute.setExecutor(new MuteCommand());
mute.setTabCompleter(new MuteCommand());
final PluginCommand ban = getCommand("ban");
assert ban != null;
ban.setExecutor(new BanCommand());
ban.setTabCompleter(new BanCommand());
final PluginCommand kick = getCommand("kick");
assert kick != null;
kick.setExecutor(new KickCommand());
kick.setTabCompleter(new KickCommand());
final PluginCommand smod = getCommand("smod");
assert smod != null;
smod.setExecutor(new SModCommand());
smod.setTabCompleter(new SModCommand());
final PluginCommand logs = getCommand("modlogs");
assert logs != null;
logs.setExecutor(new ModLogsCommand());
logs.setTabCompleter(new ModLogsCommand());
final PluginCommand unmute = getCommand("unmute");
assert unmute != null;
unmute.setExecutor(new UnmuteCommand());
unmute.setTabCompleter(new UnmuteCommand());
final PluginCommand unban = getCommand("unban");
assert unban != null;
unban.setExecutor(new UnbanCommand());
unban.setTabCompleter(new UnbanCommand());
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());
registerCommand("mute", new MuteCommand());
registerCommand("ban", new BanCommand());
registerCommand("kick", new KickCommand());
registerCommand("smod", new SModCommand());
registerCommand("modlogs", new ModLogsCommand());
registerCommand("unmute", new UnmuteCommand());
registerCommand("unban", new UnbanCommand());
registerCommand("invsee", new InvseeCommand());
registerCommand("enderchestsee", new EnderchestSeeCommand());
registerCommand("vanish", new VanishCommand());
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
public void onDisable() {
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);
}
}
}
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 : 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();
}
}
@@ -17,7 +17,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class BanCommand implements CommandExecutor, TabCompleter {
import static net.kyori.adventure.text.Component.text;
public class BanCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
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));
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;
int p = 1;
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 org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
@@ -18,7 +17,7 @@ import java.util.List;
import static de.shiewk.smoderation.SModeration.*;
public class EnderchestSeeCommand implements CommandExecutor, TabCompleter {
public class EnderchestSeeCommand implements TabExecutor {
@Override
@@ -4,9 +4,8 @@ import de.shiewk.smoderation.util.PlayerUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
@@ -18,7 +17,7 @@ import java.util.List;
import static de.shiewk.smoderation.SModeration.*;
public class InvseeCommand implements CommandExecutor, TabCompleter {
public class InvseeCommand implements TabExecutor {
@Override
@@ -16,7 +16,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class KickCommand implements CommandExecutor, TabCompleter {
import static net.kyori.adventure.text.Component.text;
public class KickCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
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));
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();
for (int i = 1; i < args.length; i++) {
if (!reason.isEmpty()){
@@ -9,9 +9,8 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@@ -23,7 +22,7 @@ import java.util.UUID;
import static de.shiewk.smoderation.SModeration.*;
public class ModLogsCommand implements CommandExecutor, TabCompleter {
public class ModLogsCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1){
@@ -4,7 +4,6 @@ import de.shiewk.smoderation.SModeration;
import de.shiewk.smoderation.punishments.Punishment;
import de.shiewk.smoderation.util.PlayerUtil;
import de.shiewk.smoderation.util.TimeUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.*;
@@ -17,7 +16,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MuteCommand implements CommandExecutor, TabCompleter {
import static net.kyori.adventure.text.Component.text;
public class MuteCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 2){
@@ -29,20 +30,25 @@ public class MuteCommand implements CommandExecutor, TabCompleter {
} else if (sender instanceof Player pl){
senderUUID = pl.getUniqueId();
} else if (sender instanceof BlockCommandSender){
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
sender.sendMessage(text("Blocks can't execute this command.").color(NamedTextColor.RED));
return true;
} else {
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
sender.sendMessage(text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
return true;
}
String playerName = args[0];
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
if (senderUUID.equals(uuid)) {
sender.sendMessage(Component.text("You can't mute yourself.").color(NamedTextColor.RED));
sender.sendMessage(text("You can't mute yourself.").color(NamedTextColor.RED));
return true;
}
if (uuid == null) {
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
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;
}
long duration = 0;
@@ -59,11 +65,11 @@ public class MuteCommand implements CommandExecutor, TabCompleter {
if (i == args.length - 1){ p = args.length; }
}
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;
}
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;
}
StringBuilder reason = new StringBuilder();
@@ -3,16 +3,15 @@ package de.shiewk.smoderation.command;
import de.shiewk.smoderation.SModeration;
import de.shiewk.smoderation.inventory.SModMenu;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class SModCommand implements CommandExecutor, TabCompleter {
public class SModCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (commandSender instanceof Player player){
@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.UUID;
public class UnbanCommand implements CommandExecutor, TabCompleter {
public class UnbanCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1){
@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.UUID;
public class UnmuteCommand implements CommandExecutor, TabCompleter {
public class UnmuteCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1){
@@ -0,0 +1,39 @@
package de.shiewk.smoderation.command;
import de.shiewk.smoderation.SModeration;
import de.shiewk.smoderation.util.PlayerUtil;
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;
public class VanishCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Player player = null;
if (args.length > 0){
player = PlayerUtil.findOnlinePlayer(args[0]);
} else if (sender instanceof Player){
player = (Player) sender;
}
if (player != null){
SModeration.toggleVanish(player);
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 PlayerUtil.listPlayerNames();
}
return List.of();
}
}
@@ -7,6 +7,8 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import java.util.Objects;
public class InvSeeEvents implements Listener {
@EventHandler
@@ -14,6 +16,9 @@ public class InvSeeEvents implements Listener {
final Inventory clicked = event.getView().getTopInventory();
if (clicked instanceof PlayerInventory inventory){
final HumanEntity holder = inventory.getHolder();
if (Objects.equals(holder, event.getWhoClicked())){
return;
}
if (!event.getWhoClicked().hasPermission("smod.invsee.modify")){
event.setCancelled(true);
return;
@@ -0,0 +1,34 @@
package de.shiewk.smoderation.listener;
import de.shiewk.smoderation.SModeration;
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.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class VanishListener implements Listener {
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
final Player player = event.getPlayer();
if (SModeration.isVanished(player)){
SModeration.toggleVanish(player);
}
for (Player vanishedPlayer : SModeration.getVanishedPlayers()) {
// to clean up visibility status
player.hideEntity(SModeration.PLUGIN, vanishedPlayer);
}
}
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent event){
final Player player = event.getPlayer();
if (player.hasPermission("smod.vanish.see")){
for (Player vanishedPlayer : SModeration.getVanishedPlayers()) {
// to show visible vanished players
player.showEntity(SModeration.PLUGIN, vanishedPlayer);
}
}
}
}
@@ -9,7 +9,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
public abstract class PlayerUtil {
private PlayerUtil(){}
@@ -55,4 +58,17 @@ public abstract class PlayerUtil {
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);
}
}
+21
View File
@@ -71,6 +71,12 @@ commands:
- ecs
permission: smod.enderchestsee
description: Views the ender chest of another player.
vanish:
usage: "§cUsage: /vanish <player>"
aliases:
- smvanish
permission: smod.vanish
description: Toggles vanish mode which prevents other players from seeing you're online
permissions:
smod.mute:
default: op
@@ -117,3 +123,18 @@ permissions:
description: Allows the player to view and modify other players ender chests.
children:
- smod.enderchestsee
smod.preventmute:
default: op
description: Prevents the player from being muted (if online)
smod.preventkick:
default: op
description: Prevents the player from being 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