From abdaafe8211f387321a7f4a3ebdb743fd1e55584 Mon Sep 17 00:00:00 2001 From: Vladimir-Urik Date: Tue, 2 Jul 2024 12:02:15 +0200 Subject: [PATCH] Fix few things --- build.gradle | 2 +- .../punishments/commands/impl/BanCommand.java | 13 +++++++----- .../commands/impl/KickCommand.java | 8 ++++++++ .../commands/impl/MuteCommand.java | 13 ++++++++---- .../commands/impl/WarnCommand.java | 12 ++++++----- .../configurations/impl/DatabaseConfig.java | 2 +- .../configurations/impl/MessagesConfig.java | 20 +++++++++++++++++++ .../punishments/utils/PunishmentsUtils.java | 5 ----- 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index f05edf1..23c16f0 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'lol.gggedr.punishments' -version = '1.0' +version = '1.0.5' repositories { mavenCentral() diff --git a/src/main/java/lol/gggedr/punishments/commands/impl/BanCommand.java b/src/main/java/lol/gggedr/punishments/commands/impl/BanCommand.java index 09baf21..64d660a 100644 --- a/src/main/java/lol/gggedr/punishments/commands/impl/BanCommand.java +++ b/src/main/java/lol/gggedr/punishments/commands/impl/BanCommand.java @@ -29,7 +29,6 @@ public void execute(CommandSender sender, String[] args) { var requiredPermission = extractedDetails.isPermanent() ? permissionsConfig.getPermanentBanCommandPermission() : permissionsConfig.getTempBanCommandPermission(); if(!PunishmentsUtils.hasPermissions(sender, requiredPermission)) return; - var target = Bukkit.getPlayer(extractedDetails.nickname()); var punishment = new Punishment(new ObjectId(), extractedDetails.nickname(), extractedDetails.reason(), sender.getName(), System.currentTimeMillis(), (extractedDetails.isPermanent() ? -1L : System.currentTimeMillis() + extractedDetails.duration()), PunishmentType.BAN, true, "-", "-"); var dataStore = Managers.getManager(DatabaseManager.class).getDataStore(); @@ -39,16 +38,20 @@ public void execute(CommandSender sender, String[] args) { var messageConfig = getMessagesConfig(); if(extractedDetails.silent()) { - BukkitUtils.broadcast(messageConfig.getKickCommandAlertSilent(target.getName(), extractedDetails.reason(), extractedDetails.issuer()), permissionsConfig.getSilentByPassPermission()); + BukkitUtils.broadcast(messageConfig.getBanCommandAlertSilent(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer()), permissionsConfig.getSilentByPassPermission()); } else { - BukkitUtils.broadcast(messageConfig.getKickCommandAlertPublic(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); + BukkitUtils.broadcast(messageConfig.getBanCommandAlertPublic(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer())); } - sender.sendMessage(messageConfig.getKickCommandSuccess(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); + sender.sendMessage(messageConfig.getKickCommandSuccess(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer())); var layoutsConfig = getLayoutsConfig(); var layout = extractedDetails.isPermanent() ? layoutsConfig.getBanPermanent(extractedDetails.reason(), extractedDetails.issuer()) : layoutsConfig.getBanTemp(extractedDetails.reason(), extractedDetails.issuer(), (System.currentTimeMillis() + extractedDetails.duration())); - target.kickPlayer(layout); + + var target = Bukkit.getPlayer(extractedDetails.nickname()); + if(target != null) { + target.kickPlayer(layout); + } } } diff --git a/src/main/java/lol/gggedr/punishments/commands/impl/KickCommand.java b/src/main/java/lol/gggedr/punishments/commands/impl/KickCommand.java index e6aa09c..151a7a1 100644 --- a/src/main/java/lol/gggedr/punishments/commands/impl/KickCommand.java +++ b/src/main/java/lol/gggedr/punishments/commands/impl/KickCommand.java @@ -2,9 +2,11 @@ import lol.gggedr.punishments.commands.Command; import lol.gggedr.punishments.commands.annotations.CommandInfo; +import lol.gggedr.punishments.configurations.impl.MessagesConfig; import lol.gggedr.punishments.cons.Punishment; import lol.gggedr.punishments.enums.PunishmentType; import lol.gggedr.punishments.managers.Managers; +import lol.gggedr.punishments.managers.impl.ConfigurationsManager; import lol.gggedr.punishments.managers.impl.DatabaseManager; import lol.gggedr.punishments.managers.impl.PunishmentsManager; import lol.gggedr.punishments.utils.BukkitUtils; @@ -19,6 +21,7 @@ public class KickCommand implements Command { @Override public void execute(CommandSender sender, String[] args) { var permissionsConfig = getPermissionsConfig(); + var messagesConfig = getMessagesConfig(); if(!PunishmentsUtils.hasPermissions(sender, permissionsConfig.getKickCommandPermission())) return; @@ -26,6 +29,11 @@ public void execute(CommandSender sender, String[] args) { if(extractedDetails == null) return; var target = Bukkit.getPlayer(extractedDetails.nickname()); + if(target == null) { + var playerNotFound = messagesConfig.getPlayerNotFoundMessage(); + sender.sendMessage(playerNotFound); + return; + } var punishment = new Punishment(new ObjectId(), extractedDetails.nickname(), extractedDetails.reason(), sender.getName(), System.currentTimeMillis(), -1L, PunishmentType.KICK, true, "-", "-"); var dataStore = Managers.getManager(DatabaseManager.class).getDataStore(); diff --git a/src/main/java/lol/gggedr/punishments/commands/impl/MuteCommand.java b/src/main/java/lol/gggedr/punishments/commands/impl/MuteCommand.java index 84f0dfd..07e91a3 100644 --- a/src/main/java/lol/gggedr/punishments/commands/impl/MuteCommand.java +++ b/src/main/java/lol/gggedr/punishments/commands/impl/MuteCommand.java @@ -28,7 +28,6 @@ public void execute(CommandSender sender, String[] args) { var requiredPermission = extractedDetails.isPermanent() ? permissionsConfig.getPermanentMuteCommandPermission() : permissionsConfig.getTempMuteCommandPermission(); if(!PunishmentsUtils.hasPermissions(sender, requiredPermission)) return; - var target = Bukkit.getPlayer(extractedDetails.nickname()); var punishment = new Punishment(new ObjectId(), extractedDetails.nickname(), extractedDetails.reason(), sender.getName(), System.currentTimeMillis(), (extractedDetails.isPermanent() ? -1L : System.currentTimeMillis() + extractedDetails.duration()), PunishmentType.MUTE, true, "-", "-"); var dataStore = Managers.getManager(DatabaseManager.class).getDataStore(); @@ -38,12 +37,18 @@ public void execute(CommandSender sender, String[] args) { var messageConfig = getMessagesConfig(); if(extractedDetails.silent()) { - BukkitUtils.broadcast(messageConfig.getMuteCommandAlertSilent(target.getName(), extractedDetails.reason(), extractedDetails.issuer()), permissionsConfig.getSilentByPassPermission()); + BukkitUtils.broadcast(messageConfig.getMuteCommandAlertSilent(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer()), permissionsConfig.getSilentByPassPermission()); } else { - BukkitUtils.broadcast(messageConfig.getMuteCommandAlertPublic(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); + BukkitUtils.broadcast(messageConfig.getMuteCommandAlertPublic(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer())); + } + + sender.sendMessage(messageConfig.getMuteCommandSuccess(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer())); + + var target = Bukkit.getPlayer(extractedDetails.nickname()); + if (target == null) { + return; } - sender.sendMessage(messageConfig.getMuteCommandSuccess(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); target.sendMessage(messageConfig.getMuteCommandAlertTarget(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); } diff --git a/src/main/java/lol/gggedr/punishments/commands/impl/WarnCommand.java b/src/main/java/lol/gggedr/punishments/commands/impl/WarnCommand.java index 877b9f8..c788a85 100644 --- a/src/main/java/lol/gggedr/punishments/commands/impl/WarnCommand.java +++ b/src/main/java/lol/gggedr/punishments/commands/impl/WarnCommand.java @@ -25,8 +25,6 @@ public void execute(CommandSender sender, String[] args) { var extractedDetails = PunishmentsUtils.extractBasePunishmentDetails(sender, args, "warn"); if(extractedDetails == null) return; - var target = Bukkit.getPlayer(extractedDetails.nickname()); - var punishment = new Punishment(new ObjectId(), extractedDetails.nickname(), extractedDetails.reason(), sender.getName(), System.currentTimeMillis(), -1L, PunishmentType.WARN, true, "-", "-"); var dataStore = Managers.getManager(DatabaseManager.class).getDataStore(); dataStore.updatePunishment(punishment); @@ -35,12 +33,16 @@ public void execute(CommandSender sender, String[] args) { var messageConfig = getMessagesConfig(); if(extractedDetails.silent()) { - BukkitUtils.broadcast(messageConfig.getWarnCommandAlertSilent(target.getName(), extractedDetails.reason(), extractedDetails.issuer()), permissionsConfig.getSilentByPassPermission()); + BukkitUtils.broadcast(messageConfig.getWarnCommandAlertSilent(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer()), permissionsConfig.getSilentByPassPermission()); } else { - BukkitUtils.broadcast(messageConfig.getWarnCommandAlertPublic(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); + BukkitUtils.broadcast(messageConfig.getWarnCommandAlertPublic(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer())); } - sender.sendMessage(messageConfig.getWarnCommandSuccess(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); + sender.sendMessage(messageConfig.getWarnCommandSuccess(extractedDetails.nickname(), extractedDetails.reason(), extractedDetails.issuer())); + + var target = Bukkit.getPlayer(extractedDetails.nickname()); + if(target == null) return; + target.sendMessage(messageConfig.getWarnCommandAlertTarget(target.getName(), extractedDetails.reason(), extractedDetails.issuer())); } diff --git a/src/main/java/lol/gggedr/punishments/configurations/impl/DatabaseConfig.java b/src/main/java/lol/gggedr/punishments/configurations/impl/DatabaseConfig.java index 646387d..a6cb6a6 100644 --- a/src/main/java/lol/gggedr/punishments/configurations/impl/DatabaseConfig.java +++ b/src/main/java/lol/gggedr/punishments/configurations/impl/DatabaseConfig.java @@ -8,7 +8,7 @@ public class DatabaseConfig implements Config { @ConfigField(path = "type") - private String type = "mysql"; + private String type = "mongo"; @ConfigField(path = "host") private String host = "localhost"; diff --git a/src/main/java/lol/gggedr/punishments/configurations/impl/MessagesConfig.java b/src/main/java/lol/gggedr/punishments/configurations/impl/MessagesConfig.java index fb71f67..d635e2d 100644 --- a/src/main/java/lol/gggedr/punishments/configurations/impl/MessagesConfig.java +++ b/src/main/java/lol/gggedr/punishments/configurations/impl/MessagesConfig.java @@ -37,6 +37,12 @@ public class MessagesConfig implements Config { @ConfigField(path = "commands.kick.alert.silent") private String kickCommandAlertSilent = "&e%player% &ahas been kicked for &e%reason% &aby &e%issuer% &c(silent)"; + @ConfigField(path = "commands.ban.alert.public") + private String banCommandAlertPublic = "&e%player% &ahas been banned for &e%reason% &aby &e%issuer%"; + + @ConfigField(path = "commands.ban.alert.silent") + private String banCommandAlertSilent = "&e%player% &ahas been banned for &e%reason% &aby &e%issuer% &c(silent)"; + @ConfigField(path = "commands.mute.usage") private String muteCommandUsage = "&cUsage: /mute [duration] [reason] [-s]"; @@ -219,4 +225,18 @@ public String getUnmuteCommandSuccess(String player, String reason) { public String getPlayerNotMuted(String player) { return StringUtils.colorize(playerNotMuted).replace("%player%", player); } + + public String getBanCommandAlertPublic(String player, String reason, String issuer) { + return StringUtils.colorize(banCommandAlertPublic) + .replace("%player%", player) + .replace("%reason%", reason) + .replace("%issuer%", issuer); + } + + public String getBanCommandAlertSilent(String player, String reason, String issuer) { + return StringUtils.colorize(banCommandAlertSilent) + .replace("%player%", player) + .replace("%reason%", reason) + .replace("%issuer%", issuer); + } } diff --git a/src/main/java/lol/gggedr/punishments/utils/PunishmentsUtils.java b/src/main/java/lol/gggedr/punishments/utils/PunishmentsUtils.java index 38aec3a..6f8ca1c 100644 --- a/src/main/java/lol/gggedr/punishments/utils/PunishmentsUtils.java +++ b/src/main/java/lol/gggedr/punishments/utils/PunishmentsUtils.java @@ -27,11 +27,6 @@ public static BasePunishmentDetails extractBasePunishmentDetails(CommandSender s } var nickname = args[0]; - if(Bukkit.getPlayer(nickname) == null) { - var playerNotFound = messagesConfig.getPlayerNotFoundMessage(); - sender.sendMessage(playerNotFound); - return null; - } var duration = -1L; StringBuilder reason = new StringBuilder();