2012-09-19 02:21:25 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2012-11-13 01:42:30 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
2013-01-16 14:48:56 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
2013-01-07 15:33:54 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
2012-09-19 02:21:25 +00:00
|
|
|
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;
|
2012-09-20 01:43:12 +00:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
2012-09-19 02:21:25 +00:00
|
|
|
|
2013-03-19 22:05:20 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(
|
|
|
|
description = "Manipulate potion effects. Duration is measured in server ticks (~20 ticks per second).",
|
|
|
|
usage = "/<command> <list | clear [target_name] | add <type> <duration> <amplifier> [target_name]>")
|
2012-09-19 02:21:25 +00:00
|
|
|
public class Command_potion extends TFM_Command
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2012-09-20 01:43:12 +00:00
|
|
|
if (args.length == 1 || args.length == 2)
|
2012-09-19 02:21:25 +00:00
|
|
|
{
|
2012-09-20 01:43:12 +00:00
|
|
|
if (args[0].equalsIgnoreCase("list"))
|
|
|
|
{
|
|
|
|
List<String> potionEffectTypeNames = new ArrayList<String>();
|
|
|
|
for (PotionEffectType potion_effect_type : PotionEffectType.values())
|
|
|
|
{
|
|
|
|
if (potion_effect_type != null)
|
|
|
|
{
|
|
|
|
potionEffectTypeNames.add(potion_effect_type.getName());
|
|
|
|
}
|
|
|
|
}
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "), ChatColor.AQUA);
|
2012-09-20 01:43:12 +00:00
|
|
|
}
|
2013-01-07 15:33:54 +00:00
|
|
|
else if (args[0].equalsIgnoreCase("clearall"))
|
|
|
|
{
|
|
|
|
if (!(TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole))
|
|
|
|
{
|
|
|
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-16 14:48:56 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Cleared all potion effects from all players", true);
|
2013-01-07 15:33:54 +00:00
|
|
|
for (Player target : server.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
|
|
|
{
|
|
|
|
target.removePotionEffect(potion_effect.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 01:43:12 +00:00
|
|
|
else if (args[0].equalsIgnoreCase("clear"))
|
|
|
|
{
|
|
|
|
Player target = sender_p;
|
2012-09-19 02:21:25 +00:00
|
|
|
|
2012-09-20 01:43:12 +00:00
|
|
|
if (args.length == 2)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
target = getPlayer(args[1]);
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (PlayerNotFoundException ex)
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
playerMsg(ex.getMessage(), ChatColor.RED);
|
2012-09-20 01:43:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-23 23:00:45 +00:00
|
|
|
if (!target.equals(sender_p))
|
|
|
|
{
|
2012-11-13 01:42:30 +00:00
|
|
|
if (!TFM_SuperadminList.isUserSuperadmin(sender))
|
2012-09-23 23:00:45 +00:00
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Only superadmins can clear potion effects from other players.");
|
2012-09-23 23:00:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (senderIsConsole)
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("You must specify a target player when using this command from the console.");
|
2012-09-20 01:43:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-20 03:17:10 +00:00
|
|
|
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
|
|
|
target.removePotionEffect(potion_effect.getType());
|
|
|
|
}
|
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Cleared all active potion effects " + (!target.equals(sender_p) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
2012-09-20 01:43:12 +00:00
|
|
|
}
|
|
|
|
else
|
2012-09-19 02:21:25 +00:00
|
|
|
{
|
2012-09-20 01:43:12 +00:00
|
|
|
return false;
|
2012-09-19 02:21:25 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 01:43:12 +00:00
|
|
|
else if (args.length == 4 || args.length == 5)
|
|
|
|
{
|
|
|
|
if (args[0].equalsIgnoreCase("add"))
|
|
|
|
{
|
|
|
|
Player target = sender_p;
|
|
|
|
|
|
|
|
if (args.length == 5)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
target = getPlayer(args[4]);
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (PlayerNotFoundException ex)
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
playerMsg(ex.getMessage(), ChatColor.RED);
|
2012-09-20 01:43:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-09-19 02:21:25 +00:00
|
|
|
|
2012-09-23 23:00:45 +00:00
|
|
|
if (!target.equals(sender_p))
|
|
|
|
{
|
2012-11-13 01:42:30 +00:00
|
|
|
if (!TFM_SuperadminList.isUserSuperadmin(sender))
|
2012-09-23 23:00:45 +00:00
|
|
|
{
|
|
|
|
sender.sendMessage("Only superadmins can apply potion effects to other players.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (senderIsConsole)
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
2012-09-23 23:00:45 +00:00
|
|
|
sender.sendMessage("You must specify a target player when using this command from the console.");
|
2012-09-20 01:43:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
|
|
|
|
if (potion_effect_type == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.AQUA + "Invalid potion effect type.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int duration;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
duration = Integer.parseInt(args[2]);
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (NumberFormatException ex)
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Invalid potion duration.", ChatColor.RED);
|
2012-09-20 01:43:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amplifier;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
amplifier = Integer.parseInt(args[3]);
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (NumberFormatException ex)
|
2012-09-20 01:43:12 +00:00
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Invalid potion amplifier.", ChatColor.RED);
|
2012-09-20 01:43:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier);
|
|
|
|
target.addPotionEffect(new_effect, true);
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg(
|
|
|
|
"Added potion effect: " + new_effect.getType().getName()
|
2012-09-20 01:43:12 +00:00
|
|
|
+ ", Duration: " + new_effect.getDuration()
|
|
|
|
+ ", Amplifier: " + new_effect.getAmplifier()
|
2013-01-07 14:56:53 +00:00
|
|
|
+ (!target.equals(sender_p) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
2012-09-20 01:43:12 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-19 02:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|