mirror of
https://github.com/TotalFreedomMC/TotalFreedomMod.git
synced 2024-05-16 01:21:23 +00:00
5c0f77c7c5
Lombok implementation removal. I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!! Thank you!!
143 lines
4.7 KiB
Java
143 lines
4.7 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import me.totalfreedom.totalfreedommod.banning.Ban;
|
|
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 org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
|
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> [-q] <username> [reason]", aliases = "noob")
|
|
public class Command_tban extends FreedomCommand
|
|
{
|
|
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
{
|
|
if (args.length == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
final String username;
|
|
|
|
final Player player = getPlayer(args[0]);
|
|
final PlayerData entry;
|
|
if (player == null)
|
|
{
|
|
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.getName();
|
|
}
|
|
else
|
|
{
|
|
entry = plugin.pl.getData(player);
|
|
username = player.getName();
|
|
}
|
|
final List<String> ips = new ArrayList<>(entry.getIps());
|
|
|
|
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)
|
|
{
|
|
// Strike with lightning
|
|
if (player != null)
|
|
{
|
|
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);
|
|
Objects.requireNonNull(targetPos.getWorld()).strikeLightning(strike_pos);
|
|
}
|
|
}
|
|
|
|
// Kill player
|
|
player.setHealth(0.0);
|
|
|
|
if (reason != null)
|
|
{
|
|
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes - Reason: " + reason, true);
|
|
kick.append("\n")
|
|
.append(ChatColor.RED)
|
|
.append("Reason: ")
|
|
.append(ChatColor.GOLD)
|
|
.append(reason);
|
|
}
|
|
else
|
|
{
|
|
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes", true);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Ban player
|
|
Ban ban = Ban.forPlayerName(username, sender, FUtil.parseDateOffset("5m"), reason);
|
|
for (String ip : ips)
|
|
{
|
|
ban.addIp(ip);
|
|
}
|
|
plugin.bm.addBan(ban);
|
|
|
|
// Kick player
|
|
if (player != null)
|
|
{
|
|
player.kickPlayer(kick.toString());
|
|
}
|
|
|
|
// Log ban
|
|
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason));
|
|
return true;
|
|
}
|
|
} |