From af777f1a76e91549a6285c88647a9c39228ec2c1 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Wed, 25 Jul 2018 18:34:40 -0700 Subject: [PATCH] Attempt to resolve banning issues (#96) --- .../totalfreedommod/command/Command_tban.java | 22 +++++++++++++++--- .../command/Command_tempban.java | 23 +++++++++++++++---- .../command/Command_unban.java | 3 +-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java index d12ecccd..77471d3b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -13,6 +14,9 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; + @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/ [reason]", aliases = "noob") public class Command_tban extends FreedomCommand @@ -26,14 +30,22 @@ public class Command_tban extends FreedomCommand return false; } + final String username; + final List ips = new ArrayList<>(); + final Player player = getPlayer(args[0]); + final PlayerData entry = plugin.pl.getData(args[0]); + if (player == null) { - msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED); + msg(FreedomCommand.PLAYER_NOT_FOUND); return true; } + username = entry.getUsername(); + ips.addAll(entry.getIps()); + String reason; if (args.length > 1) { @@ -56,8 +68,12 @@ public class Command_tban extends FreedomCommand } FUtil.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true); - plugin.bm.addBan(Ban.forPlayer(player, sender, FUtil.parseDateOffset("5m"), reason)); - + Ban ban = Ban.forPlayerName(username, sender, FUtil.parseDateOffset("5m"), reason); + for (String ip : ips) + { + ban.addIp(ip); + } + plugin.bm.addBan(ban); player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info."); plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason)); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java index 547fa1d0..9490f076 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java @@ -1,8 +1,7 @@ package me.totalfreedom.totalfreedommod.command; -import java.text.SimpleDateFormat; -import java.util.Date; import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -15,6 +14,11 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Temporarily ban someone.", usage = "/ [playername] [duration] [reason]") public class Command_tempban extends FreedomCommand @@ -30,7 +34,12 @@ public class Command_tempban extends FreedomCommand return false; } + final String username; + final List ips = new ArrayList<>(); + final Player player = getPlayer(args[0]); + final PlayerData entry = plugin.pl.getData(args[0]); + if (player == null) { @@ -38,6 +47,8 @@ public class Command_tempban extends FreedomCommand return true; } + username = entry.getUsername(); + ips.addAll(entry.getIps()); final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName()); Date expires = FUtil.parseDateOffset("30m"); @@ -71,8 +82,12 @@ public class Command_tempban extends FreedomCommand FUtil.adminAction(sender.getName(), message.toString(), true); - plugin.bm.addBan(Ban.forPlayer(player, sender, expires, reason)); - + Ban ban = Ban.forPlayerName(username, sender, expires, reason); + for (String ip : ips) + { + ban.addIp(ip); + } + plugin.bm.addBan(ban); player.kickPlayer(sender.getName() + " - " + message.toString()); plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason)); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java index 558312b0..15bb13d7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java @@ -27,7 +27,7 @@ public class Command_unban extends FreedomCommand if (entry == null) { - msg("Can't find that user."); + msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); return true; } @@ -52,7 +52,6 @@ public class Command_unban extends FreedomCommand } return true; } - return false; } }