Added command repair [hand|all]

fixed if statements in commandsell
This commit is contained in:
okamosy 2011-08-20 20:49:17 +01:00
parent 4bc3d5efad
commit 3e9b27e3ef
9 changed files with 154 additions and 2 deletions

View File

@ -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();
}
}

View File

@ -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())
{

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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>