diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-08-20 20:55:21 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-08-20 20:55:21 +0100 |
commit | 69b76b810c1f327ee8726ee4b94079d974cfb665 (patch) | |
tree | 0f2ac6db863c6ad217c119a5f02fcd6bb147e10c | |
parent | 2c787e07ec934df12e0e61c464cb45d095da06e3 (diff) | |
parent | 3e9b27e3ef2f7d8fdd4da6699fe903974173ddb3 (diff) | |
download | Essentials-69b76b810c1f327ee8726ee4b94079d974cfb665.tar Essentials-69b76b810c1f327ee8726ee4b94079d974cfb665.tar.gz Essentials-69b76b810c1f327ee8726ee4b94079d974cfb665.tar.lz Essentials-69b76b810c1f327ee8726ee4b94079d974cfb665.tar.xz Essentials-69b76b810c1f327ee8726ee4b94079d974cfb665.zip |
Merge branch 'master' of github.com:khobbits/Essentials
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandrepair.java | 124 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandsell.java | 4 | ||||
-rw-r--r-- | Essentials/src/messages.properties | 4 | ||||
-rw-r--r-- | Essentials/src/messages_da.properties | 4 | ||||
-rw-r--r-- | Essentials/src/messages_de.properties | 4 | ||||
-rw-r--r-- | Essentials/src/messages_en.properties | 4 | ||||
-rw-r--r-- | Essentials/src/messages_fr.properties | 4 | ||||
-rw-r--r-- | Essentials/src/messages_nl.properties | 4 | ||||
-rw-r--r-- | Essentials/src/plugin.yml | 4 |
9 files changed, 154 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java new file mode 100644 index 000000000..a388f92d2 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -0,0 +1,124 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; + + +/** + * + * @author Seiji + */ +public class Commandrepair extends EssentialsCommand +{ + public Commandrepair() + { + super("repair"); + } + + @Override + public void run(Server server, User user, String commandLabel, String[] args) throws Exception + { + if (args.length < 1) + { + throw new NotEnoughArgumentsException(); + } + + if (args[0].equalsIgnoreCase("hand")) + { + ItemStack item = user.getItemInHand(); + try + { + repairItem(item); + } + catch (Exception e) + { + user.sendMessage(e.getMessage()); + return; + } + + String itemName = item.getType().toString().toLowerCase().replace('_', ' '); + user.sendMessage(Util.format("repair", itemName)); + } + else if (args[0].equalsIgnoreCase("all")) + { + StringBuilder itemList = new StringBuilder(); + itemList.append(repairItems(user.getInventory().getContents())); + + String armor = repairItems(user.getInventory().getArmorContents()); + + if(armor.length() > 0) + { + if(itemList.length() > 0) + { + itemList.append(", "); + } + + itemList.append(armor); + } + + if (itemList.length() == 0) + { + user.sendMessage(Util.format("repairNone")); + } + else + { + user.sendMessage(Util.format("repair", itemList.toString())); + } + + } + else + { + throw new NotEnoughArgumentsException(); + } + } + + private void repairItem(ItemStack item) throws Exception + { + Material material = Material.getMaterial(item.getTypeId()); + String error = null; + if (material.isBlock() || material.getMaxDurability() < 0) + { + throw new Exception(Util.i18n("repairInvalidType")); + } + + if (item.getDurability() == 0) + { + throw new Exception(Util.i18n("repairAlreadyFixed")); + } + + item.setDurability((short)0); + } + + private String repairItems(ItemStack[] items) + { + StringBuilder itemList = new StringBuilder(); + for (ItemStack item : items) + { + try + { + repairItem(item); + if (itemList.length() > 0) + { + itemList.append(", "); + } + + String itemName = item.getType().toString().toLowerCase().replace('_', ' '); + itemList.append(itemName); + } + catch (Exception e) + { + } + + } + + return itemList.toString(); + } +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index 56f6cb2fc..f471364d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -29,7 +29,7 @@ public class Commandsell extends EssentialsCommand { is = user.getItemInHand(); } - if (args[0].equalsIgnoreCase("inventory")) + else if (args[0].equalsIgnoreCase("inventory")) { for (ItemStack stack : user.getInventory().getContents()) { @@ -47,7 +47,7 @@ public class Commandsell extends EssentialsCommand } return; } - if (args[0].equalsIgnoreCase("blocks")) + else if (args[0].equalsIgnoreCase("blocks")) { for (ItemStack stack : user.getInventory().getContents()) { diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index b84d05994..089d05670 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -238,6 +238,10 @@ pTimeSet = Player time is set to \u00a73{0}\u00a7f for: \u00a7e{1} pTimeSetFixed = Player time is fixed to \u00a73{0}\u00a7f for: \u00a7e{1} questionFormat = \u00a77[Question]\u00a7f {0} reloadAllPlugins = \u00a77Reloaded all plugins. +repair = You have successfully repaired your: \u00a7e{0}. +repairAlreadyFixed = \u00a77This item does not need repairing. +repairInvalidType = \u00a7cThis item cannot be repaired. +repairNone = There were no items that needing repairing. requestAccepted = \u00a77Teleport request accepted. requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleport request denied. diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index fe45b375f..41b34ab0e 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -238,6 +238,10 @@ pTimeSet = Player time is set to \u00a73{0}\u00a7f for: \u00a7e{1} pTimeSetFixed = Player time is fixed to \u00a73{0}\u00a7f for: \u00a7e{1} questionFormat = \u00a77[Sp\u00f8rgsm\u00e5l]\u00a7f {0} reloadAllPlugins = \u00a77Genindl\u00e6ste alle tilf\u00f8jelser. +repair = You have successfully repaired your: \u00a7e{0}. +repairAlreadyFixed = \u00a77This item does not need repairing. +repairInvalidType = \u00a7cThis item cannot be repaired. +repairNone = There were no items that needing repairing. requestAccepted = \u00a77Teleporterings anmodning n\u00e6gtet. requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleporterings anmodning n\u00e6gtet. diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index a429d1aa6..d85cd4350 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -238,6 +238,10 @@ pTimeSet = Player time is set to \u00a73{0}\u00a7f for: \u00a7e{1} pTimeSetFixed = Player time is fixed to \u00a73{0}\u00a7f for: \u00a7e{1} questionFormat = \u00a77[Frage]\u00a7f {0} reloadAllPlugins = \u00a77Alle plugins neu geladen. +repair = You have successfully repaired your: \u00a7e{0}. +repairAlreadyFixed = \u00a77This item does not need repairing. +repairInvalidType = \u00a7cThis item cannot be repaired. +repairNone = There were no items that needing repairing. requestAccepted = \u00a77Teleportierungsanfrage akzeptiert. requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleportierungsanfrage verweigert. diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index e2aa6793c..4c1ad26d4 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -238,6 +238,10 @@ pTimeSet = Player time is set to \u00a73{0}\u00a7f for: \u00a7e{1} pTimeSetFixed = Player time is fixed to \u00a73{0}\u00a7f for: \u00a7e{1} questionFormat = \u00a77[Question]\u00a7f {0} reloadAllPlugins = \u00a77Reloaded all plugins. +repair = You have successfully repaired your: \u00a7e{0}. +repairAlreadyFixed = \u00a77This item does not need repairing. +repairInvalidType = \u00a7cThis item cannot be repaired. +repairNone = There were no items that needing repairing. requestAccepted = \u00a77Teleport request accepted. requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleport request denied. diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 9d9dd23fc..0849c78d6 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -238,6 +238,10 @@ pTimeSet = Player time is set to \u00a73{0}\u00a7f for: \u00a7e{1} pTimeSetFixed = Player time is fixed to \u00a73{0}\u00a7f for: \u00a7e{1} questionFormat = \u00a77[Question]\u00a7f {0} reloadAllPlugins = \u00a77Tous les plugins ont \u00e9t\u00e9 recharg\u00e9s. +repair = You have successfully repaired your: \u00a7e{0}. +repairAlreadyFixed = \u00a77This item does not need repairing. +repairInvalidType = \u00a7cThis item cannot be repaired. +repairNone = There were no items that needing repairing. requestAccepted = \u00a77Demande de t\u00e9l\u00e9portation accept\u00e9e. requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Demande de t\u00e9l\u00e9portation refus\u00e9e. diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index 1d086ee34..a76084a55 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -238,6 +238,10 @@ pTimeSet = Player time is set to \u00a73{0}\u00a7f for: \u00a7e{1} pTimeSetFixed = Player time is fixed to \u00a73{0}\u00a7f for: \u00a7e{1} questionFormat = \u00a77[Vraag]\u00a7f {0} reloadAllPlugins = \u00a77Alle plugins zijn herladen. +repair = You have successfully repaired your: \u00a7e{0}. +repairAlreadyFixed = \u00a77This item does not need repairing. +repairInvalidType = \u00a7cThis item cannot be repaired. +repairNone = There were no items that needing repairing. requestAccepted = \u00a77Teleporteer aanvraag geaccepteerd. requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleporteer aanvraag geweigerd. diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 42960031b..1acef22e8 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -222,6 +222,10 @@ commands: description: Reloads all plugins. usage: /<command> aliases: [rel,ereloadall,ereload,erel] + repair: + description: Repairs the item in hand, or all items in the current inventory. + usage: /<command> [hand|all] + aliases: [fix] rules: description: Views the server rules. usage: /<command> |