2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.banning.Ban;
|
2018-03-03 04:29:08 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
|
|
|
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
|
|
|
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
2018-07-28 07:11:48 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-07-31 16:19:23 +00:00
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2019-12-24 04:21:52 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
2020-04-23 11:18:03 +00:00
|
|
|
@CommandParameters(description = "Bans the specified player.", usage = "/<command> <username> [reason] [-nrb | -q]", aliases = "gtfo")
|
2020-04-22 08:29:27 +00:00
|
|
|
public class Command_ban extends FreedomCommand
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2013-07-29 18:44:18 +00:00
|
|
|
if (args.length == 0)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-23 11:18:03 +00:00
|
|
|
String reason = null;
|
|
|
|
Boolean silent = false;
|
|
|
|
Boolean cancelRollback = false;
|
|
|
|
if (args.length >= 2)
|
|
|
|
{
|
|
|
|
if (args[args.length - 1].equalsIgnoreCase("-nrb") || args[args.length - 1].equalsIgnoreCase("-q"))
|
|
|
|
{
|
|
|
|
if (args[args.length - 1].equalsIgnoreCase("-nrb"))
|
|
|
|
{
|
|
|
|
cancelRollback = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[args.length - 1].equalsIgnoreCase("-q"))
|
|
|
|
{
|
|
|
|
silent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length >= 3)
|
|
|
|
{
|
|
|
|
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:29:08 +00:00
|
|
|
final String username;
|
|
|
|
final List<String> ips = new ArrayList<>();
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2018-03-03 04:29:08 +00:00
|
|
|
final Player player = getPlayer(args[0]);
|
2014-04-26 11:55:24 +00:00
|
|
|
if (player == null)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2018-03-03 04:29:08 +00:00
|
|
|
final PlayerData 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;
|
|
|
|
}
|
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
username = entry.getName();
|
2018-03-03 04:29:08 +00:00
|
|
|
ips.addAll(entry.getIps());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
final PlayerData entry = plugin.pl.getData(player);
|
|
|
|
username = player.getName();
|
2020-04-23 11:18:03 +00:00
|
|
|
//ips.addAll(entry.getIps());/
|
2020-07-01 01:51:06 +00:00
|
|
|
ips.add(FUtil.getIp(player));
|
2018-03-03 04:29:08 +00:00
|
|
|
|
|
|
|
// Deop
|
|
|
|
player.setOp(false);
|
|
|
|
|
2018-07-26 21:08:48 +00:00
|
|
|
// Gamemode survival
|
2018-03-03 04:29:08 +00:00
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
|
|
|
|
|
|
|
// Clear inventory
|
|
|
|
player.getInventory().clear();
|
|
|
|
|
2020-04-23 11:18:03 +00:00
|
|
|
if (!silent)
|
2018-03-03 04:29:08 +00:00
|
|
|
{
|
2020-04-23 11:18:03 +00:00
|
|
|
// Strike with lightning
|
|
|
|
final Location targetPos = player.getLocation();
|
|
|
|
for (int x = -1; x <= 1; x++)
|
2018-03-03 04:29:08 +00:00
|
|
|
{
|
2020-04-23 11:18:03 +00:00
|
|
|
for (int z = -1; z <= 1; z++)
|
|
|
|
{
|
|
|
|
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
|
|
|
targetPos.getWorld().strikeLightning(strike_pos);
|
|
|
|
}
|
2018-03-03 04:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kill player
|
|
|
|
player.setHealth(0.0);
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
2012-09-16 17:41:41 +00:00
|
|
|
|
2018-07-26 21:08:48 +00:00
|
|
|
// Checks if CoreProtect is loaded and installed, and skips the rollback and uses CoreProtect directly
|
2019-01-04 21:39:38 +00:00
|
|
|
if (!cancelRollback)
|
2014-04-15 13:43:07 +00:00
|
|
|
{
|
2020-04-23 11:18:03 +00:00
|
|
|
plugin.cpb.rollback(username);
|
2020-01-12 14:51:29 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 11:18:03 +00:00
|
|
|
if (player != null && !silent)
|
2012-11-24 01:22:52 +00:00
|
|
|
{
|
2018-03-03 04:29:08 +00:00
|
|
|
FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2018-03-03 04:29:08 +00:00
|
|
|
// Ban player
|
2020-08-10 05:25:04 +00:00
|
|
|
Ban ban;
|
|
|
|
|
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
ban = Ban.forPlayer(player, sender, null, reason);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ban = Ban.forPlayerName(username, sender, null, reason);
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:29:08 +00:00
|
|
|
for (String ip : ips)
|
|
|
|
{
|
|
|
|
ban.addIp(ip);
|
2020-04-29 23:29:43 +00:00
|
|
|
ban.addIp(FUtil.getFuzzyIp(ip));
|
2018-03-03 04:29:08 +00:00
|
|
|
}
|
|
|
|
plugin.bm.addBan(ban);
|
2014-08-02 15:14:37 +00:00
|
|
|
|
2020-04-23 11:18:03 +00:00
|
|
|
|
|
|
|
if (!silent)
|
2014-08-02 15:14:37 +00:00
|
|
|
{
|
2020-04-23 11:18:03 +00:00
|
|
|
// Broadcast
|
|
|
|
final StringBuilder bcast = new StringBuilder()
|
|
|
|
.append("Banning: ")
|
|
|
|
.append(username);
|
|
|
|
if (reason != null)
|
|
|
|
{
|
|
|
|
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
|
|
|
|
}
|
|
|
|
msg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + StringUtils.join(ips, ", "));
|
|
|
|
FUtil.adminAction(sender.getName(), String.format(bcast.toString()), true);
|
2014-08-02 15:14:37 +00:00
|
|
|
}
|
2014-08-25 12:07:47 +00:00
|
|
|
|
2019-12-24 04:21:52 +00:00
|
|
|
// Kick player and handle others on IP
|
2018-03-03 04:29:08 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
2020-05-29 10:14:21 +00:00
|
|
|
player.kickPlayer(ban.bakeKickMessage());
|
2019-12-24 04:21:52 +00:00
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
2020-07-01 01:51:06 +00:00
|
|
|
if (FUtil.getIp(p).equals(FUtil.getIp(player)))
|
2019-12-24 04:21:52 +00:00
|
|
|
{
|
|
|
|
p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned.");
|
|
|
|
}
|
|
|
|
}
|
2018-03-03 04:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Log ban
|
|
|
|
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.BAN, reason));
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2012-11-24 01:22:52 +00:00
|
|
|
return true;
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
2018-03-03 04:29:08 +00:00
|
|
|
}
|