2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2014-10-27 11:23:08 +00:00
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2014-10-27 11:23:08 +00:00
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2018-07-24 06:54:19 +00:00
|
|
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
2020-08-08 00:51:47 +00:00
|
|
|
@CommandParameters(description = "Warns the specified player.", usage = "/<command> [-q] <player> <reason>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_warn extends FreedomCommand
|
2014-10-27 11:23:08 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2014-10-27 11:23:08 +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)
|
2014-10-27 11:23:08 +00:00
|
|
|
{
|
2020-08-08 00:51:47 +00:00
|
|
|
if (args.length == 0)
|
2014-10-27 11:23:08 +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);
|
2014-10-27 11:23:08 +00:00
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = getPlayer(args[0]);
|
2014-10-27 11:23:08 +00:00
|
|
|
if (player == null)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(PLAYER_NOT_FOUND);
|
2014-10-27 11:23:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
if (playerSender == player)
|
2014-10-27 11:23:08 +00:00
|
|
|
{
|
2020-08-08 00:51:47 +00:00
|
|
|
msg(ChatColor.RED + "Please, don't try to warn yourself.");
|
|
|
|
return true;
|
2014-10-27 11:23:08 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
if (plugin.al.isAdmin(player))
|
2014-10-27 11:23:08 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(ChatColor.RED + "You can not warn admins");
|
2014-10-27 11:23:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String warnReason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
2019-11-30 17:43:16 +00:00
|
|
|
player.sendTitle(ChatColor.RED + "You've been warned.", ChatColor.YELLOW + "Reason: " + warnReason, 20, 100, 60);
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(ChatColor.GREEN + "You have successfully warned " + player.getName());
|
2014-10-27 11:23:08 +00:00
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
if (quiet)
|
|
|
|
{
|
|
|
|
msg("Warned " + player.getName() + " quietly");
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-27 11:23:08 +00:00
|
|
|
|
2020-08-08 00:51:47 +00:00
|
|
|
msg(player, ChatColor.RED + "[WARNING] You received a warning from " + sender.getName() + ": " + warnReason);
|
|
|
|
String adminNotice = ChatColor.RED +
|
|
|
|
sender.getName() +
|
|
|
|
" - " +
|
|
|
|
"Warning: " +
|
|
|
|
player.getName() +
|
|
|
|
" - Reason: " +
|
|
|
|
ChatColor.YELLOW +
|
|
|
|
warnReason;
|
|
|
|
plugin.al.messageAllAdmins(adminNotice);
|
|
|
|
plugin.pl.getPlayer(player).incrementWarnings();
|
2014-10-27 11:23:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-08-08 00:51:47 +00:00
|
|
|
}
|