TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java

198 lines
6.4 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
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;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
2019-12-24 04:21:52 +00:00
import net.pravian.aero.util.Ips;
import org.apache.commons.lang.ArrayUtils;
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;
2020-01-12 14:51:29 +00:00
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
2011-10-19 00:37:00 +00:00
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Bans the specified player.", usage = "/<command> <username> [reason] [-nrb]", aliases = "ban")
public class Command_gtfo extends FreedomCommand
2011-10-19 00:37:00 +00:00
{
2011-10-19 00:37:00 +00:00
@Override
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;
}
2018-03-03 04:29:08 +00:00
final String username;
final List<String> ips = new ArrayList<>();
2018-03-03 04:29:08 +00:00
final Player player = getPlayer(args[0]);
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;
}
username = entry.getUsername();
ips.addAll(entry.getIps());
}
else
{
final PlayerData entry = plugin.pl.getData(player);
username = player.getName();
2020-02-04 04:54:51 +00:00
//ips.addAll(entry.getIps());
ips.add(Ips.getIp(player));
2018-03-03 04:29:08 +00:00
// Deop
player.setOp(false);
// Gamemode survival
2018-03-03 04:29:08 +00:00
player.setGameMode(GameMode.SURVIVAL);
// Clear inventory
player.getInventory().clear();
// Strike with lightning
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);
targetPos.getWorld().strikeLightning(strike_pos);
}
}
// Kill player
player.setHealth(0.0);
}
String reason = null;
2019-01-04 21:39:38 +00:00
Boolean cancelRollback = false;
2020-01-12 14:51:29 +00:00
Boolean epicFail = false;
2013-07-29 18:44:18 +00:00
if (args.length >= 2)
{
2019-01-04 21:39:38 +00:00
if (args[args.length - 1].equalsIgnoreCase("-nrb"))
{
2019-01-04 21:39:38 +00:00
cancelRollback = true;
if (args.length >= 3)
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
}
}
2020-01-12 14:51:29 +00:00
if (args[args.length - 1].equalsIgnoreCase("-ef"))
{
epicFail = 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), " ");
}
2013-07-29 18:44:18 +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)
{
2018-03-03 04:29:08 +00:00
if (!plugin.cpb.isEnabled())
{
// Undo WorldEdits
try
{
plugin.web.undo(player, 15);
}
2018-03-03 04:29:08 +00:00
catch (NoClassDefFoundError | NullPointerException ex)
{
}
// Rollback
2018-03-03 04:29:08 +00:00
plugin.rb.rollback(username);
}
else
{
2018-03-03 04:29:08 +00:00
plugin.cpb.rollback(username);
}
}
2013-07-02 18:31:22 +00:00
2020-01-12 14:51:29 +00:00
if (epicFail)
{
for (int i = 0; i < 25; i++)
{
player.setVelocity(player.getVelocity().clone().add(new Vector(0, 50, 0)));
new BukkitRunnable()
{
public void run()
{
for (int i = 0; i < 8; i++)
{
player.getWorld().strikeLightning(player.getLocation());
//FUtil.
}
}
}.runTaskLater(plugin, 2L * 20L);
}
return true;
}
2018-03-03 04:29:08 +00:00
if (player != null)
{
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
}
2018-03-03 04:29:08 +00:00
// Ban player
Ban ban = Ban.forPlayerName(username, sender, null, reason);
for (String ip : ips)
{
ban.addIp(ip);
}
plugin.bm.addBan(ban);
// Broadcast
2014-08-25 12:07:47 +00:00
final StringBuilder bcast = new StringBuilder()
2018-03-03 04:29:08 +00:00
.append("Banning: ")
.append(username);
if (reason != null)
{
2018-03-03 04:29:08 +00:00
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-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)
{
player.kickPlayer(ban.bakeKickMessage(Ips.getIp(player)));
2019-12-24 04:21:52 +00:00
for (Player p : Bukkit.getOnlinePlayers())
{
if (Ips.getIp(p).equals(Ips.getIp(player)))
{
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
return true;
2011-10-19 00:37:00 +00:00
}
2018-03-03 04:29:08 +00:00
}