2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2011-11-29 05:41:47 +00:00
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2011-11-29 05:41:47 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Enchant items.", usage = "/<command> <list | addall | reset | add <name> | remove <name>>")
|
2015-11-22 18:26:47 +00:00
|
|
|
public class Command_enchant extends FreedomCommand
|
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2011-11-29 05:41:47 +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)
|
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
ItemStack itemInHand = playerSender.getItemInHand();
|
2011-11-29 05:41:47 +00:00
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
if (itemInHand == null)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("You are holding an invalid item.");
|
2011-11-29 05:41:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
if (args[0].equalsIgnoreCase("list"))
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
boolean has_enchantments = false;
|
|
|
|
|
|
|
|
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
|
2015-11-22 18:26:47 +00:00
|
|
|
for (Enchantment ench : Enchantment.values())
|
|
|
|
{
|
|
|
|
if (ench.canEnchantItem(itemInHand))
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
has_enchantments = true;
|
|
|
|
possible_ench.append(ench.getName()).append(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
if (has_enchantments)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(possible_ench.toString());
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("The held item has no enchantments.");
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("addall"))
|
|
|
|
{
|
|
|
|
for (Enchantment ench : Enchantment.values())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (ench.canEnchantItem(itemInHand))
|
|
|
|
{
|
2013-07-20 23:38:27 +00:00
|
|
|
itemInHand.addEnchantment(ench, ench.getMaxLevel());
|
|
|
|
}
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + playerSender.getName() + ".");
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Added all possible enchantments for this item.");
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("reset"))
|
|
|
|
{
|
|
|
|
for (Enchantment ench : itemInHand.getEnchantments().keySet())
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
itemInHand.removeEnchantment(ench);
|
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Removed all enchantments.");
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Enchantment ench = null;
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
try
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
ench = Enchantment.getByName(args[1]);
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
if (ench == null)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(args[1] + " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
|
2011-11-29 05:41:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
if (args[0].equalsIgnoreCase("add"))
|
|
|
|
{
|
|
|
|
if (ench.canEnchantItem(itemInHand))
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
itemInHand.addEnchantment(ench, ench.getMaxLevel());
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Added enchantment: " + ench.getName());
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Can't use this enchantment on held item.");
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
2015-11-22 18:26:47 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equals("remove"))
|
|
|
|
{
|
2011-11-29 05:41:47 +00:00
|
|
|
itemInHand.removeEnchantment(ench);
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Removed enchantment: " + ench.getName());
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|