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)
|
2014-10-27 11:23:08 +00:00
|
|
|
@CommandParameters(description = "Warns a player.", usage = "/<command> <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
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = getPlayer(args[0]);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
if (player.equals(playerSender))
|
2014-10-27 11:23:08 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(ChatColor.RED + "Please, don't try to warn yourself.");
|
2014-10-27 11:23:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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), " ");
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
msg(player, ChatColor.RED + "[WARNING] You received a warning: " + warnReason);
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(ChatColor.GREEN + "You have successfully warned " + player.getName());
|
2018-07-24 06:54:19 +00:00
|
|
|
final StringBuilder adminNotice = new StringBuilder()
|
|
|
|
.append(ChatColor.RED)
|
|
|
|
.append(sender.getName())
|
|
|
|
.append(" - ")
|
|
|
|
.append("Warning: ")
|
|
|
|
.append(player.getName())
|
|
|
|
.append(" - Reason: ")
|
|
|
|
.append(ChatColor.YELLOW)
|
|
|
|
.append(warnReason);
|
|
|
|
plugin.al.messageAllAdmins(adminNotice.toString());
|
2014-10-27 11:23:08 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.pl.getPlayer(player).incrementWarnings();
|
2014-10-27 11:23:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-20 22:20:31 +00:00
|
|
|
}
|