Skip to content

Commit

Permalink
Fix few things
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir-Urik committed Jul 2, 2024
1 parent 838ae7a commit abdaafe
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'lol.gggedr.punishments'
version = '1.0'
version = '1.0.5'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,13 +21,19 @@ 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;

var extractedDetails = PunishmentsUtils.extractBasePunishmentDetails(sender, args, "kick");
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <player> [duration] [reason] [-s]";

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit abdaafe

Please sign in to comment.