1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00

Add permissions for mute/kick/ban immunity

This commit is contained in:
Shy
2024-07-23 16:23:40 +02:00
parent d8ff58191f
commit 7d94c782b8
4 changed files with 36 additions and 8 deletions
@@ -17,6 +17,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
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) {
@@ -45,6 +47,11 @@ public class BanCommand implements TabExecutor {
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++) {
@@ -16,6 +16,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
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) {
@@ -45,6 +47,10 @@ public class KickCommand implements TabExecutor {
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()){
@@ -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,6 +16,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
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) {
@@ -29,20 +30,25 @@ public class MuteCommand implements TabExecutor {
} 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 TabExecutor {
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();
+9
View File
@@ -117,3 +117,12 @@ 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)