summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhyperia <khyperia@live.com>2011-12-04 14:58:00 -0500
committerKhyperia <khyperia@live.com>2011-12-04 14:58:00 -0500
commit2c2f956068fae54f20ccd750ddd48173fcc80c64 (patch)
treee8bcd28fb634081b3807f1768d6ce9305b4fdb68
parentba3ccf7a2c3cddb8f0f3f44d907eb112320153a3 (diff)
downloadEssentials-2c2f956068fae54f20ccd750ddd48173fcc80c64.tar
Essentials-2c2f956068fae54f20ccd750ddd48173fcc80c64.tar.gz
Essentials-2c2f956068fae54f20ccd750ddd48173fcc80c64.tar.lz
Essentials-2c2f956068fae54f20ccd750ddd48173fcc80c64.tar.xz
Essentials-2c2f956068fae54f20ccd750ddd48173fcc80c64.zip
Added [enchant] sign
Test #1177
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignEnchant.java138
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/Signs.java1
2 files changed, 139 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java
new file mode 100644
index 000000000..6561c0628
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java
@@ -0,0 +1,138 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.ChargeException;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import static com.earth2me.essentials.I18n._;
+import com.earth2me.essentials.Trade;
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemStack;
+
+
+public class SignEnchant extends EssentialsSign
+{
+ public SignEnchant()
+ {
+ super("Enchant");
+ }
+
+ @Override
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
+ {
+ getItemStack(sign.getLine(1), 1, ess);
+ String[] enchantLevel = sign.getLine(2).split(":");
+ if (enchantLevel.length != 2)
+ {
+ throw new SignException(_("invalidSignLine", 2));
+ }
+ if (!ENCHANTMENTS.containsKey(enchantLevel[0]))
+ {
+ throw new SignException(_("enchantmentNotFound"));
+ }
+ int level;
+ try
+ {
+ level = Integer.parseInt(enchantLevel[1]);
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new SignException(ex.getMessage());
+ }
+ if (level < 1 || level > ENCHANTMENTS.get(enchantLevel[0]).getMaxLevel())
+ {
+ sign.setLine(2, enchantLevel[0] + ":" + ENCHANTMENTS.get(enchantLevel[0]).getMaxLevel());
+ }
+ getTrade(sign, 3, ess);
+ return true;
+ }
+
+ @Override
+ protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException
+ {
+ Material search = getItemStack(sign.getLine(1), 1, ess).getType();
+ int slot;
+ Trade charge = getTrade(sign, 3, ess);
+ charge.isAffordableFor(player);
+ if (player.getInventory().contains(search))
+ {
+ slot = player.getInventory().first(search);
+ }
+ else
+ {
+ player.sendMessage(_("missingItems", 1, search.toString()));
+ return true;
+ }
+ ItemStack toEnchant = player.getInventory().getItem(slot);
+ String[] enchantLevel = sign.getLine(2).split(":");
+ if (enchantLevel.length != 2)
+ {
+ player.sendMessage(_("invalidSignLine", 2));
+ return true;
+ }
+ if (ENCHANTMENTS.containsKey(enchantLevel[0]))
+ {
+ try
+ {
+ toEnchant.addEnchantment(ENCHANTMENTS.get(enchantLevel[0]), Integer.parseInt(enchantLevel[1]));
+ }
+ catch (NumberFormatException ex)
+ {
+ toEnchant.addEnchantment(ENCHANTMENTS.get(enchantLevel[0]), 1);
+ }
+ }
+ else
+ {
+ player.sendMessage(_("enchantmentNotFound"));
+ return true;
+ }
+ charge.charge(player);
+ Trade.log("Sign", "Enchant", "Interact", username, charge, username, charge, sign.getBlock().getLocation(), ess);
+ return true;
+ }
+ private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<String, Enchantment>();
+
+ static
+ {
+ ENCHANTMENTS.put("alldamage", Enchantment.DAMAGE_ALL);
+ ENCHANTMENTS.put("alldmg", Enchantment.DAMAGE_ALL);
+ ENCHANTMENTS.put("sharpness", Enchantment.DAMAGE_ALL);
+ ENCHANTMENTS.put("arthropodsdamage", Enchantment.DAMAGE_ARTHROPODS);
+ ENCHANTMENTS.put("ardmg", Enchantment.DAMAGE_ARTHROPODS);
+ ENCHANTMENTS.put("baneofarthropods", Enchantment.DAMAGE_ARTHROPODS);
+ ENCHANTMENTS.put("undeaddamage", Enchantment.DAMAGE_UNDEAD);
+ ENCHANTMENTS.put("smite", Enchantment.DAMAGE_UNDEAD);
+ ENCHANTMENTS.put("digspeed", Enchantment.DIG_SPEED);
+ ENCHANTMENTS.put("efficiency", Enchantment.DIG_SPEED);
+ ENCHANTMENTS.put("durability", Enchantment.DURABILITY);
+ ENCHANTMENTS.put("dura", Enchantment.DURABILITY);
+ ENCHANTMENTS.put("unbreaking", Enchantment.DURABILITY);
+ ENCHANTMENTS.put("fireaspect", Enchantment.FIRE_ASPECT);
+ ENCHANTMENTS.put("fire", Enchantment.FIRE_ASPECT);
+ ENCHANTMENTS.put("knockback", Enchantment.KNOCKBACK);
+ ENCHANTMENTS.put("blockslootbonus", Enchantment.LOOT_BONUS_BLOCKS);
+ ENCHANTMENTS.put("fortune", Enchantment.LOOT_BONUS_BLOCKS);
+ ENCHANTMENTS.put("mobslootbonus", Enchantment.LOOT_BONUS_MOBS);
+ ENCHANTMENTS.put("mobloot", Enchantment.LOOT_BONUS_MOBS);
+ ENCHANTMENTS.put("looting", Enchantment.LOOT_BONUS_MOBS);
+ ENCHANTMENTS.put("oxygen", Enchantment.OXYGEN);
+ ENCHANTMENTS.put("respiration", Enchantment.OXYGEN);
+ ENCHANTMENTS.put("protection", Enchantment.PROTECTION_ENVIRONMENTAL);
+ ENCHANTMENTS.put("prot", Enchantment.PROTECTION_ENVIRONMENTAL);
+ ENCHANTMENTS.put("explosionsprotection", Enchantment.PROTECTION_EXPLOSIONS);
+ ENCHANTMENTS.put("expprot", Enchantment.PROTECTION_EXPLOSIONS);
+ ENCHANTMENTS.put("blastprotection", Enchantment.PROTECTION_EXPLOSIONS);
+ ENCHANTMENTS.put("fallprotection", Enchantment.PROTECTION_FALL);
+ ENCHANTMENTS.put("fallprot", Enchantment.PROTECTION_FALL);
+ ENCHANTMENTS.put("featherfalling", Enchantment.PROTECTION_FALL);
+ ENCHANTMENTS.put("fireprotection", Enchantment.PROTECTION_FIRE);
+ ENCHANTMENTS.put("fireprot", Enchantment.PROTECTION_FIRE);
+ ENCHANTMENTS.put("projectileprotection", Enchantment.PROTECTION_PROJECTILE);
+ ENCHANTMENTS.put("projprot", Enchantment.PROTECTION_PROJECTILE);
+ ENCHANTMENTS.put("silktouch", Enchantment.SILK_TOUCH);
+ ENCHANTMENTS.put("waterworker", Enchantment.WATER_WORKER);
+ ENCHANTMENTS.put("aquaaffinity", Enchantment.WATER_WORKER);
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/Signs.java b/Essentials/src/com/earth2me/essentials/signs/Signs.java
index d7c0d2086..83a0ee828 100644
--- a/Essentials/src/com/earth2me/essentials/signs/Signs.java
+++ b/Essentials/src/com/earth2me/essentials/signs/Signs.java
@@ -6,6 +6,7 @@ public enum Signs
BALANCE(new SignBalance()),
BUY(new SignBuy()),
DISPOSAL(new SignDisposal()),
+ ENCHANT(new SignEnchant()),
FREE(new SignFree()),
GAMEMODE(new SignGameMode()),
HEAL(new SignHeal()),