diff --git a/docs/config.md b/docs/config.md new file mode 100644 index 0000000..8010e2c --- /dev/null +++ b/docs/config.md @@ -0,0 +1,7 @@ +# SModeration config + +| Key | What it does | +|--------------------------|--------------------------------------------------------------------| +| socialspy-commands | The commands that `/socialspy` will listen to. | +| force-reason | Whether a reason is required for every punishment. | +| muted-forbidden-commands | Commands that players are not allowed to run while they are muted. | \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index a4674cb..12991d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -pluginVersion = 1.6.0 \ No newline at end of file +pluginVersion = 1.7.0 \ No newline at end of file diff --git a/src/main/java/de/shiewk/smoderation/paper/listener/PunishmentListener.java b/src/main/java/de/shiewk/smoderation/paper/listener/PunishmentListener.java index 9357920..90c73fc 100644 --- a/src/main/java/de/shiewk/smoderation/paper/listener/PunishmentListener.java +++ b/src/main/java/de/shiewk/smoderation/paper/listener/PunishmentListener.java @@ -12,9 +12,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.world.WorldSaveEvent; +import java.util.List; + import static de.shiewk.smoderation.paper.SModerationPaper.CHAT_PREFIX; +import static net.kyori.adventure.text.Component.translatable; public class PunishmentListener implements Listener { @@ -45,6 +49,29 @@ public class PunishmentListener implements Listener { } } + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){ + Player player = event.getPlayer(); + final Punishment mute = SModerationPaper.container.find(p -> + p.type == PunishmentType.MUTE + && p.to.equals(player.getUniqueId()) + && p.isActive()); + + if (mute != null) { // Player is muted + List forbiddenCommands = SModerationPaper.config().getStringList("muted-forbidden-commands"); + final String message = event.getMessage(); + if (forbiddenCommands.stream().anyMatch(str -> + message.toLowerCase().startsWith("/"+str.toLowerCase()+" ") + || message.toLowerCase().startsWith(str.toLowerCase()+" ") + )){ + Bukkit.getConsoleSender().sendMessage(player.getName() + " tried to run forbidden command while muted"); + player.sendMessage(CHAT_PREFIX.append(translatable("smod.punishment.playerMessage.mute.chat"))); + event.setCancelled(true); + } + } + + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPunishmentIssue(PunishmentIssueEvent event){ final Punishment punishment = event.getPunishment(); diff --git a/src/main/java/de/shiewk/smoderation/paper/listener/SocialSpyListener.java b/src/main/java/de/shiewk/smoderation/paper/listener/SocialSpyListener.java index 322538f..784eb3c 100644 --- a/src/main/java/de/shiewk/smoderation/paper/listener/SocialSpyListener.java +++ b/src/main/java/de/shiewk/smoderation/paper/listener/SocialSpyListener.java @@ -61,8 +61,8 @@ public class SocialSpyListener implements Listener { List socialSpyCommands = SModerationPaper.config().getStringList("socialspy-commands"); final String message = event.getMessage(); if (socialSpyCommands.stream().anyMatch(str -> - message.startsWith("/"+str+" ") - || message.startsWith(str+" ") + message.toLowerCase().startsWith("/"+str.toLowerCase()+" ") + || message.toLowerCase().startsWith(str.toLowerCase()+" ") )){ SocialSpyListener.command(event.getPlayer(), message); } diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index dc309f0..947cbce 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -9,4 +9,17 @@ socialspy-commands: - minecraft:msg - minecraft:teammsg - minecraft:tm -force-reason: false \ No newline at end of file +force-reason: false +muted-forbidden-commands: + - w + - tell + - msg + - teammsg + - tm + - me + - minecraft:w + - minecraft:tell + - minecraft:msg + - minecraft:teammsg + - minecraft:tm + - minecraft:me \ No newline at end of file diff --git a/src/main/resources/smoderation/translations/en_us.json b/src/main/resources/smoderation/translations/en_us.json index dabc9f8..950efab 100644 --- a/src/main/resources/smoderation/translations/en_us.json +++ b/src/main/resources/smoderation/translations/en_us.json @@ -1,59 +1,96 @@ { - "smod.command.ban.fail.tooShort": "You can't ban an offline player for less than 1ms.", - "smod.command.ban.fail.self": "You can't ban yourself.", - "smod.command.ban.fail.protect": "This player can't be banned.", - "smod.command.ban.fail.forceReason": "Please provide a reason.", "smod.argument.duration.fail.invalid": "Invalid duration ''", "smod.argument.duration.fail.pattern": "Please provide a valid duration, e.g. '1d6h30min'", "smod.argument.offlinePlayer.fail.notCached": "That player is not cached.", "smod.argument.uuid.fail.notCached": "That player is not cached. Try providing an UUID instead.", + "smod.chatInput.remainingTime": " seconds", + "smod.command.ban.fail.forceReason": "Please provide a reason.", + "smod.command.ban.fail.protect": "This player can't be banned.", + "smod.command.ban.fail.self": "You can't ban yourself.", + "smod.command.ban.fail.tooShort": "You can't ban an offline player for less than 1ms.", "smod.command.ecsee.opening": "Opening ender chest of .", + "smod.command.fail.invalidPlayer": "Please provide a valid player.", + "smod.command.fail.players": "Only players can execute this command.", + "smod.command.fail.playersConsole": "Only players and the console can execute this command.", "smod.command.invsee.fail.self": "You can't open your own inventory.", "smod.command.invsee.opening": "Opening inventory of .", "smod.command.kick.fail.forceReason": "Please provide a reason.", - "smod.command.kick.fail.self": "You can't kick yourself.", "smod.command.kick.fail.protect": "This player can't be kicked.", - "smod.command.modlogs.heading": "Player ()", - "smod.command.modlogs.none": "- is not currently muted or banned.", - "smod.command.modlogs.mute": "- is muted until (in ). Reason: ", + "smod.command.kick.fail.self": "You can't kick yourself.", "smod.command.modlogs.ban": "- is banned until (in ). Reason: ", + "smod.command.modlogs.heading": "Player ()", + "smod.command.modlogs.mute": "- is muted until (in ). Reason: ", + "smod.command.modlogs.none": "- is not currently muted or banned.", "smod.command.mute.fail.forceReason": "Please provide a reason.", - "smod.command.mute.fail.self": "You can't mute yourself.", "smod.command.mute.fail.protect": "This player can't be muted.", + "smod.command.mute.fail.self": "You can't mute yourself.", "smod.command.offlinetp.fail.unknown": "This player's location is unknown.", "smod.command.offlinetp.teleporting": "Teleporting you to .", - "smod.command.socialspy.enabled": "SocialSpy enabled.", "smod.command.socialspy.disabled": "SocialSpy disabled.", + "smod.command.socialspy.enabled": "SocialSpy enabled.", "smod.command.unban.fail.notBanned": "That player is not banned.", "smod.command.unmute.fail.notMuted": "That player is not muted.", - "smod.command.vanish.fail.noPlayersFound": "No player was found.", - "smod.command.vanish.broadcast.on": " vanished.", "smod.command.vanish.broadcast.off": " re-appeared.", - "smod.command.vanish.toggle.on": "You are now vanished.", - "smod.command.vanish.toggle.off": "You are no longer vanished.", - "smod.command.vanish.list.none": "No players are currently vanished.", + "smod.command.vanish.broadcast.on": " vanished.", + "smod.command.vanish.fail.noPlayersFound": "No player was found.", "smod.command.vanish.list": "The following players are currently vanished: ", - "smod.chatInput.remainingTime": " seconds", - "smod.confirm.yes": "Yes", + "smod.command.vanish.list.none": "No players are currently vanished.", + "smod.command.vanish.toggle.off": "You are no longer vanished.", + "smod.command.vanish.toggle.on": "You are now vanished.", "smod.confirm.no": "No", - "smod.socialspy.command": "[SocialSpy] : ", - "smod.vanish.stillEnabled": "You are still vanished!", - "smod.punishment.undo.mute": " was unmuted by .", - "smod.punishment.undo.ban": " was unbanned by .", - "smod.punishment.broadcast.mute": " was muted by for .Reason: ", + "smod.confirm.yes": "Yes", + "smod.menu": "SMod Menu", + "smod.menu.filter": "Filter: ", + "smod.menu.filter.active": "Active punishments", + "smod.menu.filter.all": "All punishments", + "smod.menu.filter.expired": "Expired punishments", + "smod.menu.filter.switch": "\u00BB Click to switch filter", + "smod.menu.info.click": "\u00BB Click to undo punishment", + "smod.menu.info.duration": "Duration: ", + "smod.menu.info.expiry.future": "Expires: In ", + "smod.menu.info.expiry.past": "Expired: ago", + "smod.menu.info.player": "Player: ", + "smod.menu.info.punishedBy": "Punished by: ", + "smod.menu.info.reason": "Reason: ", + "smod.menu.info.timestamp": "Timestamp: ", + "smod.menu.info.undone": "Undone by: ", + "smod.menu.search": "Search", + "smod.menu.search.current": "Current search query: ", + "smod.menu.search.new": "\u00BB Click to enter new search query", + "smod.menu.search.none": "None", + "smod.menu.search.query": "Enter your search query in the chat", + "smod.menu.search.remove": "\u00BB Right click to remove search query", + "smod.menu.sort": "Sort by: ", + "smod.menu.sort.expiry": "Expiry time", + "smod.menu.sort.moderatorName": "Moderator name", + "smod.menu.sort.playerName": "Player name", + "smod.menu.sort.switch": "\u00BB Click to switch sorting option", + "smod.menu.sort.time": "Time issued", + "smod.menu.type": "Type: ", + "smod.menu.type.all": "All", + "smod.menu.type.switch": "» Click to switch type", + "smod.menu.undoConfirmation": "Are you sure that you want to undo this punishment?", "smod.punishment.broadcast.ban": " was banned by for .Reason: ", "smod.punishment.broadcast.kick": " was kicked by .Reason: ", - "smod.punishment.playerMessage.mute": "You have been muted by .Reason: Your mute expires in .", + "smod.punishment.broadcast.mute": " was muted by for .Reason: ", + "smod.punishment.name.ban": "Ban", + "smod.punishment.name.kick": "Kick", + "smod.punishment.name.mute": "Mute", "smod.punishment.playerMessage.ban": "You have been banned from this server by .Reason: Your ban expires in .", "smod.punishment.playerMessage.kick": "You have been kicked by .Reason: ", - "smod.punishment.name.mute": "Mute", - "smod.punishment.name.kick": "Kick", - "smod.punishment.name.ban": "Ban", - "smod.command.fail.players": "Only players can execute this command.", - "smod.command.fail.playersConsole": "Only players and the console can execute this command.", - "smod.command.fail.invalidPlayer": "Please provide a valid player.", + "smod.punishment.playerMessage.mute": "You have been muted by .Reason: Your mute expires in .", + "smod.punishment.playerMessage.mute.chat": "You can't run this command while you are muted.", + "smod.punishment.undo.ban": " was unbanned by .", + "smod.punishment.undo.mute": " was unmuted by .", + "smod.socialspy.command": "[SocialSpy] : ", + "smod.time.days": " days", + "smod.time.hours": " hours", + "smod.time.milliseconds": " milliseconds", + "smod.time.minutes": " minutes", "smod.time.month.0": "January", "smod.time.month.1": "February", + "smod.time.month.10": "November", + "smod.time.month.11": "December", "smod.time.month.2": "March", "smod.time.month.3": "April", "smod.time.month.4": "May", @@ -62,46 +99,10 @@ "smod.time.month.7": "August", "smod.time.month.8": "September", "smod.time.month.9": "October", - "smod.time.month.10": "November", - "smod.time.month.11": "December", - "smod.time.timestamp": " :: ", - "smod.time.years": " years", "smod.time.months": " months", - "smod.time.weeks": " weeks", - "smod.time.days": " days", - "smod.time.hours": " hours", - "smod.time.minutes": " minutes", "smod.time.seconds": " seconds", - "smod.time.milliseconds": " milliseconds", - "smod.menu.undoConfirmation": "Are you sure that you want to undo this punishment?", - "smod.menu.filter.active": "Active punishments", - "smod.menu.filter.expired": "Expired punishments", - "smod.menu.filter.all": "All punishments", - "smod.menu.sort.expiry": "Expiry time", - "smod.menu.sort.time": "Time issued", - "smod.menu.sort.playerName": "Player name", - "smod.menu.sort.moderatorName": "Moderator name", - "smod.menu": "SMod Menu", - "smod.menu.search.query": "Enter your search query in the chat", - "smod.menu.filter": "Filter: ", - "smod.menu.filter.switch": "\u00BB Click to switch filter", - "smod.menu.type": "Type: ", - "smod.menu.type.all": "All", - "smod.menu.type.switch": "» Click to switch type", - "smod.menu.sort": "Sort by: ", - "smod.menu.sort.switch": "\u00BB Click to switch sorting option", - "smod.menu.search": "Search", - "smod.menu.search.current": "Current search query: ", - "smod.menu.search.none": "None", - "smod.menu.search.new": "\u00BB Click to enter new search query", - "smod.menu.search.remove": "\u00BB Right click to remove search query", - "smod.menu.info.player": "Player: ", - "smod.menu.info.punishedBy": "Punished by: ", - "smod.menu.info.timestamp": "Timestamp: ", - "smod.menu.info.duration": "Duration: ", - "smod.menu.info.expiry.future": "Expires: In ", - "smod.menu.info.expiry.past": "Expired: ago", - "smod.menu.info.reason": "Reason: ", - "smod.menu.info.undone": "Undone by: ", - "smod.menu.info.click": "\u00BB Click to undo punishment" + "smod.time.timestamp": " :: ", + "smod.time.weeks": " weeks", + "smod.time.years": " years", + "smod.vanish.stillEnabled": "You are still vanished!" } \ No newline at end of file