2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2013-05-15 12:56:23 +00:00
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2020-12-25 19:46:43 +00:00
|
|
|
import java.util.Objects;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.banning.Ban;
|
2018-07-26 01:34:40 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
2018-03-03 04:29:08 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
|
|
|
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2020-08-08 00:51:47 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2013-05-15 12:56:23 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2013-12-22 22:20:31 +00:00
|
|
|
import org.bukkit.Location;
|
2013-05-15 12:56:23 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2020-09-28 03:17:01 +00:00
|
|
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
2020-08-08 00:51:47 +00:00
|
|
|
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> [-q] <username> [reason]", aliases = "noob")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_tban extends FreedomCommand
|
2013-07-02 18:31:22 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-05-15 12:56:23 +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)
|
2013-05-15 12:56:23 +00:00
|
|
|
{
|
2019-11-20 01:04:44 +00:00
|
|
|
if (args.length == 0)
|
2013-05-15 12:56:23 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 01:34:40 +00:00
|
|
|
final String username;
|
|
|
|
|
2014-04-26 11:55:24 +00:00
|
|
|
final Player player = getPlayer(args[0]);
|
2020-12-25 19:46:43 +00:00
|
|
|
final PlayerData entry;
|
2014-04-26 11:55:24 +00:00
|
|
|
if (player == null)
|
2013-05-15 12:56:23 +00:00
|
|
|
{
|
2020-12-25 19:46:43 +00:00
|
|
|
entry = plugin.pl.getData(args[0]);
|
2014-01-14 19:37:08 +00:00
|
|
|
|
2019-11-20 01:04:44 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-07-26 01:34:40 +00:00
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
username = entry.getName();
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-25 19:46:43 +00:00
|
|
|
entry = plugin.pl.getData(player);
|
2019-11-20 01:04:44 +00:00
|
|
|
username = player.getName();
|
2020-08-08 00:51:47 +00:00
|
|
|
}
|
2020-12-25 19:46:43 +00:00
|
|
|
final List<String> ips = new ArrayList<>(entry.getIps());
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-11-20 01:04:44 +00:00
|
|
|
// Strike with lightning
|
2020-08-08 00:51:47 +00:00
|
|
|
if (player != null)
|
2013-12-22 22:20:31 +00:00
|
|
|
{
|
2020-08-08 00:51:47 +00:00
|
|
|
final Location targetPos = player.getLocation();
|
|
|
|
for (int x = -1; x <= 1; x++)
|
2019-11-20 01:04:44 +00:00
|
|
|
{
|
2020-08-08 00:51:47 +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);
|
2020-12-25 19:46:43 +00:00
|
|
|
Objects.requireNonNull(targetPos.getWorld()).strikeLightning(strike_pos);
|
2020-08-08 00:51:47 +00:00
|
|
|
}
|
2019-11-20 01:04:44 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
// Kill player
|
|
|
|
player.setHealth(0.0);
|
2019-11-20 01:04:44 +00:00
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
if (reason != null)
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes - Reason: " + reason, true);
|
2020-08-08 00:51:47 +00:00
|
|
|
kick.append("\n")
|
|
|
|
.append(ChatColor.RED)
|
|
|
|
.append("Reason: ")
|
|
|
|
.append(ChatColor.GOLD)
|
|
|
|
.append(reason);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes", true);
|
2020-08-08 00:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-11-20 01:04:44 +00:00
|
|
|
{
|
2020-08-08 00:51:47 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-12-22 22:20:31 +00:00
|
|
|
}
|
2013-05-15 12:56:23 +00:00
|
|
|
|
2019-11-20 01:04:44 +00:00
|
|
|
// Ban player
|
2018-07-26 01:34:40 +00:00
|
|
|
Ban ban = Ban.forPlayerName(username, sender, FUtil.parseDateOffset("5m"), reason);
|
|
|
|
for (String ip : ips)
|
|
|
|
{
|
|
|
|
ban.addIp(ip);
|
|
|
|
}
|
|
|
|
plugin.bm.addBan(ban);
|
2013-05-15 12:56:23 +00:00
|
|
|
|
2019-11-20 01:04:44 +00:00
|
|
|
// Kick player
|
|
|
|
if (player != null)
|
|
|
|
{
|
2020-08-08 00:51:47 +00:00
|
|
|
player.kickPlayer(kick.toString());
|
2019-11-20 01:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Log ban
|
|
|
|
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason));
|
2013-05-15 12:56:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-11-20 01:04:44 +00:00
|
|
|
}
|