mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Multiple birds, one commit
Here's a list of things I've fixed/mitigated: - Range bans in ban-related commands (FS-209) - Bug in /tempban where the duration in the broadcast is always wrong - Over-complicated handling of /tempban durations (instead of trying to process them and silently fail, it'll flat out say that an invalid duration is well, invalid) - Inconsistent "player not found" messages in banning commands - (Mitigates) weird issue with case-sensitive usernames in banning commands when the server has restarted since a player last joined - (Mitigates) banned IPs being inaccurate when a player was banned offline whilst containing multiple IPs in their playerdata - Redoing how MovementValidator handled positive and negative infinity exploit items, completely removing the need for Mojangson in the first place and allowing the plugin to run without Essentials once more in the process (related to FS-406) Here is what I've done in addition: - Merged /tban and /noob into /tempban, which now bans for 5 minutes by default (FS-205)
This commit is contained in:
parent
54cb0cfac4
commit
032e54e2d4
6
pom.xml
6
pom.xml
@ -132,12 +132,6 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ca.momoperes</groupId>
|
||||
<artifactId>mojangson</artifactId>
|
||||
<version>1.0-20210821.193420-1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
|
@ -1,17 +1,16 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import ca.momothereal.mojangson.ex.MojangsonParseException;
|
||||
import ca.momothereal.mojangson.value.MojangsonCompound;
|
||||
import ca.momothereal.mojangson.value.MojangsonValue;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagList;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -20,6 +19,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class MovementValidator extends FreedomService
|
||||
{
|
||||
@ -133,55 +133,49 @@ public class MovementValidator extends FreedomService
|
||||
|
||||
private Boolean exploitItem(ItemStack item)
|
||||
{
|
||||
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
|
||||
NBTTagList modifiers = getAttributeList(nmsStack);
|
||||
MojangsonCompound compound = new MojangsonCompound();
|
||||
boolean foundNegative = false;
|
||||
boolean foundPositive = false;
|
||||
try
|
||||
if (item == null)
|
||||
{
|
||||
String mod = modifiers.toString();
|
||||
String fancy = ("{" + (mod.substring(1, mod.length() - 1).replace("{", "").replace("}", "")) + "}");
|
||||
compound.read(fancy);
|
||||
for (String key : compound.keySet())
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null)
|
||||
{
|
||||
Multimap<Attribute, AttributeModifier> attributes = meta.getAttributeModifiers();
|
||||
if (attributes != null)
|
||||
{
|
||||
if (Objects.equals(key, "Amount")) //null-safe .equals()
|
||||
Map<Attribute, Collection<AttributeModifier>> attrMap = attributes.asMap();
|
||||
|
||||
// For every attribute...
|
||||
for (Attribute attr : attributes.keySet())
|
||||
{
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<MojangsonValue> values = compound.get(key);
|
||||
for (MojangsonValue<?> val : values)
|
||||
// Default values
|
||||
boolean posInf = false;
|
||||
boolean negInf = false;
|
||||
|
||||
// For every AttributeModifier...
|
||||
for (AttributeModifier modifier : attrMap.get(attr))
|
||||
{
|
||||
if (val.getValue().toString().equals("Infinityd"))
|
||||
// Are they ∞ or -∞?
|
||||
if (modifier.getAmount() == Double.POSITIVE_INFINITY)
|
||||
{
|
||||
foundPositive = true;
|
||||
posInf = true;
|
||||
}
|
||||
if (val.getValue().toString().equals("-Infinityd"))
|
||||
else if (modifier.getAmount() == Double.NEGATIVE_INFINITY)
|
||||
{
|
||||
foundNegative = true;
|
||||
negInf = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Are both values set as true?
|
||||
if (posInf && negInf)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MojangsonParseException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return foundNegative && foundPositive;
|
||||
}
|
||||
|
||||
|
||||
private NBTTagList getAttributeList(net.minecraft.server.v1_16_R3.ItemStack stack)
|
||||
{
|
||||
if (stack.getTag() == null)
|
||||
{
|
||||
stack.setTag(new NBTTagCompound());
|
||||
}
|
||||
NBTTagList attr = stack.getTag().getList("AttributeModifiers", 10);
|
||||
if (attr == null)
|
||||
{
|
||||
stack.getTag().set("AttributeModifiers", new NBTTagList());
|
||||
}
|
||||
return stack.getTag().getList("AttributeModifiers", 10);
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
@ -60,28 +60,39 @@ public class Command_ban extends FreedomCommand
|
||||
}
|
||||
|
||||
final String username;
|
||||
final List<String> ips = new ArrayList<>();
|
||||
final String ip;
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
if (player == null)
|
||||
{
|
||||
final PlayerData entry = plugin.pl.getData(args[0]);
|
||||
|
||||
if (entry == null)
|
||||
// Gets the IP using Essentials data if available
|
||||
if (plugin.esb.isEnabled() && plugin.esb.getEssentialsUser(args[0]) != null)
|
||||
{
|
||||
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
|
||||
return true;
|
||||
User essUser = plugin.esb.getEssentialsUser(args[0]);
|
||||
//
|
||||
username = essUser.getName();
|
||||
ip = essUser.getLastLoginAddress();
|
||||
}
|
||||
// Last resort - Getting the first result from the username itself
|
||||
else
|
||||
{
|
||||
PlayerData entry = plugin.pl.getData(args[0]);
|
||||
if (entry == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
username = entry.getName();
|
||||
ip = entry.getIps().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
username = entry.getName();
|
||||
ips.addAll(entry.getIps());
|
||||
}
|
||||
else
|
||||
{
|
||||
final PlayerData entry = plugin.pl.getData(player);
|
||||
username = player.getName();
|
||||
//ips.addAll(entry.getIps());/
|
||||
ips.add(FUtil.getIp(player));
|
||||
ip = FUtil.getIp(player);
|
||||
|
||||
// Deop
|
||||
player.setOp(false);
|
||||
@ -126,7 +137,6 @@ public class Command_ban extends FreedomCommand
|
||||
|
||||
// Ban player
|
||||
Ban ban;
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
ban = Ban.forPlayer(player, sender, null, reason);
|
||||
@ -135,12 +145,8 @@ public class Command_ban extends FreedomCommand
|
||||
{
|
||||
ban = Ban.forPlayerName(username, sender, null, reason);
|
||||
}
|
||||
ban.addIp(ip);
|
||||
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
ban.addIp(FUtil.getFuzzyIp(ip));
|
||||
}
|
||||
plugin.bm.addBan(ban);
|
||||
|
||||
|
||||
@ -154,7 +160,7 @@ public class Command_ban extends FreedomCommand
|
||||
{
|
||||
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
|
||||
}
|
||||
msg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + StringUtils.join(ips, ", "));
|
||||
msg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + ip);
|
||||
FUtil.adminAction(sender.getName(), bcast.toString(), true);
|
||||
}
|
||||
|
||||
@ -172,7 +178,7 @@ public class Command_ban extends FreedomCommand
|
||||
}
|
||||
|
||||
// Log ban
|
||||
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.BAN, reason));
|
||||
plugin.pul.logPunishment(new Punishment(username, ip, sender.getName(), PunishmentType.BAN, reason));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Objects;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
@ -43,7 +42,7 @@ public class Command_doom extends FreedomCommand
|
||||
FUtil.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
|
||||
FUtil.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
|
||||
|
||||
final String ip = Objects.requireNonNull(player.getAddress()).getAddress().getHostAddress().trim();
|
||||
final String ip = FUtil.getIp(player);
|
||||
|
||||
// Remove from admin
|
||||
Admin admin = getAdmin(player);
|
||||
@ -76,10 +75,7 @@ public class Command_doom extends FreedomCommand
|
||||
// Ban player
|
||||
Ban ban = Ban.forPlayer(player, sender);
|
||||
ban.setReason((reason == null ? "FUCKOFF" : reason));
|
||||
for (String playerIp : plugin.pl.getData(player).getIps())
|
||||
{
|
||||
ban.addIp(playerIp);
|
||||
}
|
||||
ban.addIp(ip);
|
||||
plugin.bm.addBan(ban);
|
||||
|
||||
// Set gamemode to survival
|
||||
|
@ -1,143 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
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;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> [-q] <username> [reason]", aliases = "noob")
|
||||
public class Command_tban extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean quiet = args[0].equalsIgnoreCase("-q");
|
||||
if (quiet)
|
||||
{
|
||||
args = org.apache.commons.lang3.ArrayUtils.subarray(args, 1, args.length);
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final String username;
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
final PlayerData entry;
|
||||
if (player == null)
|
||||
{
|
||||
entry = plugin.pl.getData(args[0]);
|
||||
|
||||
if (entry == null)
|
||||
{
|
||||
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
|
||||
return true;
|
||||
}
|
||||
|
||||
username = entry.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = plugin.pl.getData(player);
|
||||
username = player.getName();
|
||||
}
|
||||
final List<String> ips = new ArrayList<>(entry.getIps());
|
||||
|
||||
String reason = null;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
}
|
||||
|
||||
StringBuilder kick = new StringBuilder()
|
||||
.append(ChatColor.RED)
|
||||
.append("You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
|
||||
|
||||
if (!quiet)
|
||||
{
|
||||
// Strike with lightning
|
||||
if (player != null)
|
||||
{
|
||||
final Location targetPos = player.getLocation();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
||||
Objects.requireNonNull(targetPos.getWorld()).strikeLightning(strike_pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Kill player
|
||||
player.setHealth(0.0);
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes - Reason: " + reason, true);
|
||||
kick.append("\n")
|
||||
.append(ChatColor.RED)
|
||||
.append("Reason: ")
|
||||
.append(ChatColor.GOLD)
|
||||
.append(reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
if (reason != null)
|
||||
{
|
||||
msg("Quietly temporarily banned " + player.getName() + " for 5 minutes.");
|
||||
kick.append("\n")
|
||||
.append(ChatColor.RED)
|
||||
.append("Reason: ")
|
||||
.append(ChatColor.GOLD)
|
||||
.append(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ban player
|
||||
Ban ban = Ban.forPlayerName(username, sender, FUtil.parseDateOffset("5m"), reason);
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
}
|
||||
plugin.bm.addBan(ban);
|
||||
|
||||
// Kick player
|
||||
if (player != null)
|
||||
{
|
||||
player.kickPlayer(kick.toString());
|
||||
}
|
||||
|
||||
// Log ban
|
||||
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
@ -21,7 +21,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [-q] <username> [duration] [reason]")
|
||||
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [-q] <username> [duration] [reason]", aliases = "tban,noob")
|
||||
public class Command_tempban extends FreedomCommand
|
||||
{
|
||||
|
||||
@ -47,49 +47,72 @@ public class Command_tempban extends FreedomCommand
|
||||
}
|
||||
|
||||
final String username;
|
||||
final List<String> ips = new ArrayList<>();
|
||||
final String ip;
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
final PlayerData entry;
|
||||
PlayerData entry;
|
||||
if (player == null)
|
||||
{
|
||||
entry = plugin.pl.getData(args[0]);
|
||||
|
||||
if (entry == null)
|
||||
// Gets the IP using Essentials data if available
|
||||
if (plugin.esb.isEnabled() && plugin.esb.getEssentialsUser(args[0]) != null)
|
||||
{
|
||||
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
|
||||
return true;
|
||||
User essUser = plugin.esb.getEssentialsUser(args[0]);
|
||||
//
|
||||
username = essUser.getName();
|
||||
ip = essUser.getLastLoginAddress();
|
||||
}
|
||||
// Last resort - Getting the first result from the username itself
|
||||
else
|
||||
{
|
||||
entry = plugin.pl.getData(args[0]);
|
||||
if (entry == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
username = entry.getName();
|
||||
ip = entry.getIps().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
username = entry.getName();
|
||||
ips.addAll(entry.getIps());
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = plugin.pl.getData(player);
|
||||
username = player.getName();
|
||||
ips.add(FUtil.getIp(player));
|
||||
ip = FUtil.getIp(player);
|
||||
}
|
||||
|
||||
final StringBuilder message = new StringBuilder("Temporarily banned " + username);
|
||||
|
||||
Date expires = FUtil.parseDateOffset("30m");
|
||||
// Default expiration date is 5 minutes
|
||||
Date expires = FUtil.parseDateOffset("5m");
|
||||
|
||||
// Parses what comes after as a duration
|
||||
if (args.length > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
expires = FUtil.parseDateOffset(args[1]);
|
||||
}
|
||||
catch (NumberFormatException error)
|
||||
{
|
||||
msg("Invalid duration: " + args[1], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
message.append(" until ").append(date_format.format(expires));
|
||||
|
||||
// If a reason appears to exist, set it.
|
||||
String reason = null;
|
||||
if (args.length >= 2)
|
||||
if (args.length > 2)
|
||||
{
|
||||
Date parsed_offset = FUtil.parseDateOffset(args[1]);
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, parsed_offset == null ? 1 : 2, args.length), " ") + " (" + sender.getName() + ")";
|
||||
if (parsed_offset != null)
|
||||
{
|
||||
expires = parsed_offset;
|
||||
}
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " (" + sender.getName() + ")";
|
||||
message.append(", Reason: \"").append(reason).append("\"");
|
||||
}
|
||||
|
||||
Ban ban;
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
ban = Ban.forPlayer(player, sender, expires, reason);
|
||||
@ -98,11 +121,8 @@ public class Command_tempban extends FreedomCommand
|
||||
{
|
||||
ban = Ban.forPlayerName(username, sender, expires, reason);
|
||||
}
|
||||
ban.addIp(ip);
|
||||
|
||||
for (String ip : ips)
|
||||
{
|
||||
ban.addIp(ip);
|
||||
}
|
||||
plugin.bm.addBan(ban);
|
||||
|
||||
if (!quiet)
|
||||
@ -119,6 +139,8 @@ public class Command_tempban extends FreedomCommand
|
||||
Objects.requireNonNull(targetPos.getWorld()).strikeLightningEffect(strike_pos);
|
||||
}
|
||||
}
|
||||
|
||||
player.kickPlayer(ban.bakeKickMessage());
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), message.toString(), true);
|
||||
@ -128,19 +150,15 @@ public class Command_tempban extends FreedomCommand
|
||||
msg("Quietly temporarily banned " + username + ".");
|
||||
}
|
||||
|
||||
if (player != null)
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
player.kickPlayer(ban.bakeKickMessage());
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
if (FUtil.getIp(p).equals(ip))
|
||||
{
|
||||
if (FUtil.getIp(p).equals(FUtil.getIp(player)))
|
||||
{
|
||||
p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned.");
|
||||
}
|
||||
p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned.");
|
||||
}
|
||||
}
|
||||
|
||||
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason));
|
||||
plugin.pul.logPunishment(new Punishment(username, ip, sender.getName(), PunishmentType.TEMPBAN, reason));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.banning.Ban;
|
||||
import com.earth2me.essentials.User;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,20 +19,33 @@ public class Command_unban extends FreedomCommand
|
||||
if (args.length > 0)
|
||||
{
|
||||
String username;
|
||||
final PlayerData entry = plugin.pl.getData(args[0]);
|
||||
String ip;
|
||||
|
||||
if (entry == null)
|
||||
// Gets the IP using Essentials data if available
|
||||
if (plugin.esb.isEnabled() && plugin.esb.getEssentialsUser(args[0]) != null)
|
||||
{
|
||||
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
|
||||
return true;
|
||||
User essUser = plugin.esb.getEssentialsUser(args[0]);
|
||||
//
|
||||
username = essUser.getName();
|
||||
ip = essUser.getLastLoginAddress();
|
||||
}
|
||||
// Secondary method - using Essentials if available
|
||||
else
|
||||
{
|
||||
final PlayerData entry = plugin.pl.getData(args[0]);
|
||||
if (entry == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
username = entry.getName();
|
||||
ip = entry.getIps().get(0);
|
||||
}
|
||||
|
||||
username = entry.getName();
|
||||
final List<String> ips = new ArrayList<>(entry.getIps());
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Unbanning " + username, true);
|
||||
msg(username + " has been unbanned along with the following IPs: " + StringUtils.join(ips, ", "));
|
||||
plugin.bm.removeBan(plugin.bm.getByUsername(username));
|
||||
plugin.bm.removeBan(plugin.bm.getByIp(ip));
|
||||
msg(username + " has been unbanned along with the IP: " + ip);
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
@ -45,20 +55,6 @@ public class Command_unban extends FreedomCommand
|
||||
msg("Restored edits for: " + username);
|
||||
}
|
||||
}
|
||||
|
||||
for (String ip : ips)
|
||||
{
|
||||
Ban ban = plugin.bm.getByIp(ip);
|
||||
if (ban != null)
|
||||
{
|
||||
plugin.bm.removeBan(ban);
|
||||
}
|
||||
ban = plugin.bm.getByIp(FUtil.getFuzzyIp(ip));
|
||||
if (ban != null)
|
||||
{
|
||||
plugin.bm.removeBan(ban);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user