2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2011-11-29 05:41:47 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
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;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.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-15 23:32:04 +00:00
|
|
|
public class Command_enchant extends FreedomCommand {
|
|
|
|
|
2011-11-29 05:41:47 +00:00
|
|
|
@Override
|
2015-11-15 23:32:04 +00:00
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
|
|
|
if (args.length < 1) {
|
2011-11-29 05:41:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack itemInHand = sender_p.getItemInHand();
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
if (itemInHand == null) {
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("You are holding an invalid item.");
|
2011-11-29 05:41:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +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-15 23:32:04 +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-15 23:32:04 +00:00
|
|
|
if (has_enchantments) {
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg(possible_ench.toString());
|
2015-11-15 23:32:04 +00:00
|
|
|
} else {
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("The held item has no enchantments.");
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
2015-11-15 23:32:04 +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-15 23:32:04 +00:00
|
|
|
} catch (Exception ex) {
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + ".");
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Added all possible enchantments for this item.");
|
2015-11-15 23:32:04 +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
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Removed all enchantments.");
|
2015-11-15 23:32:04 +00:00
|
|
|
} else {
|
|
|
|
if (args.length < 2) {
|
2011-11-29 05:41:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Enchantment ench = null;
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
try {
|
2011-11-29 05:41:47 +00:00
|
|
|
ench = Enchantment.getByName(args[1]);
|
2015-11-15 23:32:04 +00:00
|
|
|
} catch (Exception ex) {
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
if (ench == null) {
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg(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-15 23:32:04 +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
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Added enchantment: " + ench.getName());
|
2015-11-15 23:32:04 +00:00
|
|
|
} else {
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Can't use this enchantment on held item.");
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
2015-11-15 23:32:04 +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
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Removed enchantment: " + ench.getName());
|
2011-11-29 05:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|