2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.banning.Ban;
|
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;
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
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)
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [playername] [duration] [reason]")
|
|
|
|
public class Command_tempban extends FreedomCommand
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
|
|
|
|
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Player player = getPlayer(args[0]);
|
|
|
|
|
|
|
|
if (player == null)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
2015-10-19 17:43:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName());
|
|
|
|
|
|
|
|
Date expires = FUtil.parseDateOffset("30m");
|
|
|
|
if (args.length >= 2)
|
|
|
|
{
|
|
|
|
Date parsed_offset = FUtil.parseDateOffset(args[1]);
|
|
|
|
if (parsed_offset != null)
|
|
|
|
{
|
|
|
|
expires = parsed_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message.append(" until ").append(date_format.format(expires));
|
|
|
|
|
|
|
|
String reason = "Banned by " + sender.getName();
|
|
|
|
if (args.length >= 3)
|
|
|
|
{
|
|
|
|
reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " (" + sender.getName() + ")";
|
|
|
|
message.append(", Reason: \"").append(reason).append("\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
// strike with lightning effect:
|
|
|
|
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);
|
2017-11-16 22:32:09 +00:00
|
|
|
targetPos.getWorld().strikeLightningEffect(strike_pos);
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), message.toString(), true);
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
plugin.bm.addBan(Ban.forPlayer(player, sender, expires, reason));
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
player.kickPlayer(sender.getName() + " - " + message.toString());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|