Merge pull request 'Improve PunishmentCommand Permissions' (#180) from VelocityCore/ImprovePunishmentCommand into main

Reviewed-on: SteamWar/SteamWar#180
Reviewed-by: Chaoscaot <max@chaoscaot.de>
This commit is contained in:
2025-10-28 19:54:45 +01:00
2 changed files with 15 additions and 14 deletions
@@ -119,17 +119,17 @@ public class Punishment {
@RequiredArgsConstructor @RequiredArgsConstructor
@Getter @Getter
public enum PunishmentType { public enum PunishmentType {
Ban(false, "BAN_TEAM", "BAN_PERMA", "BAN_UNTIL", "UNBAN_ERROR", "UNBAN"), Ban(UserPerm.TEAM, "BAN_TEAM", "BAN_PERMA", "BAN_UNTIL", "UNBAN_ERROR", "UNBAN"),
Mute( false, "MUTE_TEAM", "MUTE_PERMA", "MUTE_UNTIL", "UNMUTE_ERROR", "UNMUTE"), Mute( UserPerm.TEAM, "MUTE_TEAM", "MUTE_PERMA", "MUTE_UNTIL", "UNMUTE_ERROR", "UNMUTE"),
NoSchemReceiving(true, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"), NoSchemReceiving(UserPerm.MODERATION, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"),
NoSchemSharing(true, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"), NoSchemSharing(UserPerm.MODERATION, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"),
NoSchemSubmitting(false, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"), NoSchemSubmitting(UserPerm.TEAM, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"),
NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER"), NoDevServer(UserPerm.PREFIX_DEVELOPER, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER"),
NoFightServer(true, "NOFIGHTSERVER_TEAM", "NOFIGHTSERVER_PERMA", "NOFIGHTSERVER_UNTIL", "UNNOFIGHTSERVER_ERROR", "UNNOFIGHTSERVER"), NoFightServer(UserPerm.MODERATION, "NOFIGHTSERVER_TEAM", "NOFIGHTSERVER_PERMA", "NOFIGHTSERVER_UNTIL", "UNNOFIGHTSERVER_ERROR", "UNNOFIGHTSERVER"),
NoTeamServer(true, "NOTEAMSERVER_TEAM", "NOTEAMSERVER_PERMA", "NOTEAMSERVER_UNTIL", "UNNOTEAMSERVER_ERROR", "UNNOTEAMSERVER"), NoTeamServer(UserPerm.MODERATION, "NOTEAMSERVER_TEAM", "NOTEAMSERVER_PERMA", "NOTEAMSERVER_UNTIL", "UNNOTEAMSERVER_ERROR", "UNNOTEAMSERVER"),
Note(false, "NOTE_TEAM", null, null, null, null, true); Note(UserPerm.TEAM, "NOTE_TEAM", null, null, null, null, true);
private final boolean needsAdmin; private final UserPerm userPerm;
private final String teamMessage; private final String teamMessage;
private final String playerMessagePerma; private final String playerMessagePerma;
private final String playerMessageUntil; private final String playerMessageUntil;
@@ -181,7 +181,7 @@ public class PunishmentCommand {
private final Punishment.PunishmentType punishmentType; private final Punishment.PunishmentType punishmentType;
private PunishCommand(String command, Punishment.PunishmentType punishmentType) { private PunishCommand(String command, Punishment.PunishmentType punishmentType) {
super(command, UserPerm.TEAM); super(command, punishmentType.getUserPerm());
this.command = command; this.command = command;
this.punishmentType = punishmentType; this.punishmentType = punishmentType;
} }
@@ -196,7 +196,7 @@ public class PunishmentCommand {
@Register @Register
public void genericCommand(Chatter sender, @Mapper("toPunish") String toPunish, String date, @ErrorMessage(allowEAs = false, value = "PUNISHMENT_USAGE_REASON") String... message) { public void genericCommand(Chatter sender, @Mapper("toPunish") String toPunish, String date, @ErrorMessage(allowEAs = false, value = "PUNISHMENT_USAGE_REASON") String... message) {
SteamwarUser punisher = sender.user(); SteamwarUser punisher = sender.user();
if (punishmentType.isNeedsAdmin() && !punisher.hasPerm(UserPerm.MODERATION)) if (!punisher.hasPerm(punishmentType.getUserPerm()))
return; return;
SteamwarUser target = unsafeUser(sender, toPunish); SteamwarUser target = unsafeUser(sender, toPunish);
@@ -246,14 +246,15 @@ public class PunishmentCommand {
private final Punishment.PunishmentType punishmentType; private final Punishment.PunishmentType punishmentType;
private UnpunishCommand(String command, Punishment.PunishmentType punishmentType) { private UnpunishCommand(String command, Punishment.PunishmentType punishmentType) {
super(command, UserPerm.TEAM); super(command, punishmentType.getUserPerm());
this.command = command; this.command = command;
this.punishmentType = punishmentType; this.punishmentType = punishmentType;
} }
@Register @Register
public void genericCommand(Chatter sender, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { public void genericCommand(Chatter sender, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) {
if (punishmentType.isNeedsAdmin() && !sender.user().hasPerm(UserPerm.MODERATION)) SteamwarUser punisher = sender.user();
if (!punisher.hasPerm(punishmentType.getUserPerm()))
return; return;
if (!target.isPunished(punishmentType)) { if (!target.isPunished(punishmentType)) {