mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
Add a config option to require a reason
This commit is contained in:
@@ -46,6 +46,8 @@ public final class SModerationPaper extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
CONFIG.reload();
|
||||||
|
|
||||||
getPluginManager().registerEvents(new PunishmentListener(), this);
|
getPluginManager().registerEvents(new PunishmentListener(), this);
|
||||||
getPluginManager().registerEvents(new CustomInventoryListener(), this);
|
getPluginManager().registerEvents(new CustomInventoryListener(), this);
|
||||||
getPluginManager().registerEvents(new InvSeeListener(), this);
|
getPluginManager().registerEvents(new InvSeeListener(), this);
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public final class BanCommand implements CommandProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int banWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
private int banWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
if (SModerationPaper.CONFIG.shouldForceReason()){
|
||||||
|
CommandUtil.error("Please provide a reason.");
|
||||||
|
}
|
||||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
UUID target = context.getArgument("player", UUID.class);
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
long duration = context.getArgument("duration", Long.class);
|
long duration = context.getArgument("duration", Long.class);
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public final class KickCommand implements CommandProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int kickWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
private int kickWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
if (SModerationPaper.CONFIG.shouldForceReason()){
|
||||||
|
CommandUtil.error("Please provide a reason.");
|
||||||
|
}
|
||||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||||
executeKick(sender, target, Punishment.DEFAULT_REASON);
|
executeKick(sender, target, Punishment.DEFAULT_REASON);
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public final class MuteCommand implements CommandProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int muteWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
private int muteWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||||
|
if (SModerationPaper.CONFIG.shouldForceReason()){
|
||||||
|
CommandUtil.error("Please provide a reason.");
|
||||||
|
}
|
||||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||||
UUID target = context.getArgument("player", UUID.class);
|
UUID target = context.getArgument("player", UUID.class);
|
||||||
long duration = context.getArgument("duration", Long.class);
|
long duration = context.getArgument("duration", Long.class);
|
||||||
|
|||||||
@@ -15,16 +15,46 @@ public class SModerationConfig {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getSocialSpyCommands(List<String> default_){
|
private List<String> socialSpyCommands = List.of(
|
||||||
final String path = "socialspy-commands";
|
"w",
|
||||||
|
"tell",
|
||||||
|
"msg",
|
||||||
|
"teammsg",
|
||||||
|
"tm",
|
||||||
|
"minecraft:w",
|
||||||
|
"minecraft:tell",
|
||||||
|
"minecraft:msg",
|
||||||
|
"minecraft:teammsg",
|
||||||
|
"minecraft:tm"
|
||||||
|
);
|
||||||
|
private boolean forceReason = false;
|
||||||
|
|
||||||
|
public void reload(){
|
||||||
|
socialSpyCommands = loadOrSetStringList("socialspy-commands", socialSpyCommands);
|
||||||
|
forceReason = loadOrSetBoolean("force-reason", forceReason);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> loadOrSetStringList(String path, List<String> defaultValue) {
|
||||||
if (!config.contains(path)){
|
if (!config.contains(path)){
|
||||||
config.set(path, default_);
|
config.set(path, defaultValue);
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
}
|
}
|
||||||
return config.getStringList(path);
|
return config.getStringList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
private boolean loadOrSetBoolean(String path, boolean defaultValue) {
|
||||||
return config;
|
if (!config.contains(path)){
|
||||||
|
config.set(path, defaultValue);
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
return config.getBoolean(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getSocialSpyCommands(){
|
||||||
|
return socialSpyCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldForceReason(){
|
||||||
|
return forceReason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,6 @@ import static net.kyori.adventure.text.Component.text;
|
|||||||
|
|
||||||
public class SocialSpyListener implements Listener {
|
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 NamespacedKey SAVE_KEY = new NamespacedKey("smoderation", "socialspy");
|
||||||
private static final ObjectArrayList<CommandSender> targets = new ObjectArrayList<>();
|
private static final ObjectArrayList<CommandSender> targets = new ObjectArrayList<>();
|
||||||
|
|
||||||
@@ -72,9 +59,9 @@ public class SocialSpyListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||||
public void onPlayerSendCommand(PlayerCommandPreprocessEvent event){
|
public void onPlayerSendCommand(PlayerCommandPreprocessEvent event){
|
||||||
List<String> ssCommands = SModerationPaper.CONFIG.getSocialSpyCommands(defaultCommands);
|
List<String> socialSpyCommands = SModerationPaper.CONFIG.getSocialSpyCommands();
|
||||||
final String message = event.getMessage();
|
final String message = event.getMessage();
|
||||||
if (ssCommands.stream().anyMatch(str ->
|
if (socialSpyCommands.stream().anyMatch(str ->
|
||||||
message.startsWith("/"+str+" ")
|
message.startsWith("/"+str+" ")
|
||||||
|| message.startsWith(str+" ")
|
|| message.startsWith(str+" ")
|
||||||
)){
|
)){
|
||||||
|
|||||||
Reference in New Issue
Block a user