mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-17 04:46:11 +00:00
6edb6be7d9
Improved admin system Improved Rank system Implemented config converter Improved command handling Updated Aero
78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import me.totalfreedom.totalfreedommod.banning.Ban;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
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;
|
|
|
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
|
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [playername] [duration] [reason]")
|
|
public class Command_tempban extends FreedomCommand
|
|
{
|
|
|
|
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
|
|
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
{
|
|
if (args.length < 1)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
final Player player = getPlayer(args[0]);
|
|
|
|
if (player == null)
|
|
{
|
|
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
|
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);
|
|
targetPos.getWorld().strikeLightning(strike_pos);
|
|
}
|
|
}
|
|
|
|
FUtil.adminAction(sender.getName(), message.toString(), true);
|
|
|
|
plugin.bm.addBan(Ban.forPlayer(player, sender, expires, reason));
|
|
|
|
player.kickPlayer(sender.getName() + " - " + message.toString());
|
|
|
|
return true;
|
|
}
|
|
}
|