mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-19 06:58:17 +00:00
Exempt [repair] signs from 'essentials.repair.all' permissions check.
This commit is contained in:
parent
84874c9855
commit
1a4c2e8484
3 changed files with 66 additions and 45 deletions
|
@ -90,7 +90,7 @@ public class Commandfeed extends EssentialsCommand
|
||||||
|
|
||||||
private void feedPlayer(CommandSender sender, Player player) throws QuietAbortException
|
private void feedPlayer(CommandSender sender, Player player) throws QuietAbortException
|
||||||
{
|
{
|
||||||
final int amount = 100;
|
final int amount = 30;
|
||||||
|
|
||||||
final FoodLevelChangeEvent flce = new FoodLevelChangeEvent(player, amount);
|
final FoodLevelChangeEvent flce = new FoodLevelChangeEvent(player, amount);
|
||||||
ess.getServer().getPluginManager().callEvent(flce);
|
ess.getServer().getPluginManager().callEvent(flce);
|
||||||
|
|
|
@ -22,50 +22,13 @@ public class Commandrepair extends EssentialsCommand
|
||||||
{
|
{
|
||||||
if (args.length < 1 || args[0].equalsIgnoreCase("hand") || !user.isAuthorized("essentials.repair.all"))
|
if (args.length < 1 || args[0].equalsIgnoreCase("hand") || !user.isAuthorized("essentials.repair.all"))
|
||||||
{
|
{
|
||||||
final ItemStack item = user.getItemInHand();
|
repairHand(user);
|
||||||
if (item == null || item.getType().isBlock() || item.getDurability() == 0)
|
|
||||||
{
|
|
||||||
throw new Exception(_("repairInvalidType"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!item.getEnchantments().isEmpty()
|
|
||||||
&& !ess.getSettings().getRepairEnchanted()
|
|
||||||
&& !user.isAuthorized("essentials.repair.enchanted"))
|
|
||||||
{
|
|
||||||
throw new Exception(_("repairEnchanted"));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
|
|
||||||
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
|
|
||||||
|
|
||||||
charge.isAffordableFor(user);
|
|
||||||
|
|
||||||
repairItem(item);
|
|
||||||
|
|
||||||
charge.charge(user);
|
|
||||||
|
|
||||||
user.sendMessage(_("repair", itemName.replace('_', ' ')));
|
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("all"))
|
else if (args[0].equalsIgnoreCase("all"))
|
||||||
{
|
{
|
||||||
final Trade charge = new Trade("repair-all", ess);
|
final Trade charge = new Trade("repair-all", ess);
|
||||||
charge.isAffordableFor(user);
|
charge.isAffordableFor(user);
|
||||||
final List<String> repaired = new ArrayList<String>();
|
repairAll(user);
|
||||||
repairItems(user.getInventory().getContents(), user, repaired);
|
|
||||||
|
|
||||||
if (user.isAuthorized("essentials.repair.armor"))
|
|
||||||
{
|
|
||||||
repairItems(user.getInventory().getArmorContents(), user, repaired);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repaired.isEmpty())
|
|
||||||
{
|
|
||||||
throw new Exception(_("repairNone"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user.sendMessage(_("repair", Util.joinList(repaired)));
|
|
||||||
}
|
|
||||||
charge.charge(user);
|
charge.charge(user);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -74,6 +37,53 @@ public class Commandrepair extends EssentialsCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void repairHand(User user) throws Exception
|
||||||
|
{
|
||||||
|
final ItemStack item = user.getItemInHand();
|
||||||
|
if (item == null || item.getType().isBlock() || item.getDurability() == 0)
|
||||||
|
{
|
||||||
|
throw new Exception(_("repairInvalidType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item.getEnchantments().isEmpty()
|
||||||
|
&& !ess.getSettings().getRepairEnchanted()
|
||||||
|
&& !user.isAuthorized("essentials.repair.enchanted"))
|
||||||
|
{
|
||||||
|
throw new Exception(_("repairEnchanted"));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
|
||||||
|
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
|
||||||
|
|
||||||
|
charge.isAffordableFor(user);
|
||||||
|
|
||||||
|
repairItem(item);
|
||||||
|
|
||||||
|
charge.charge(user);
|
||||||
|
|
||||||
|
user.sendMessage(_("repair", itemName.replace('_', ' ')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void repairAll(User user) throws Exception
|
||||||
|
{
|
||||||
|
final List<String> repaired = new ArrayList<String>();
|
||||||
|
repairItems(user.getInventory().getContents(), user, repaired);
|
||||||
|
|
||||||
|
if (user.isAuthorized("essentials.repair.armor"))
|
||||||
|
{
|
||||||
|
repairItems(user.getInventory().getArmorContents(), user, repaired);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repaired.isEmpty())
|
||||||
|
{
|
||||||
|
throw new Exception(_("repairNone"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.sendMessage(_("repair", Util.joinList(repaired)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void repairItem(final ItemStack item) throws Exception
|
private void repairItem(final ItemStack item) throws Exception
|
||||||
{
|
{
|
||||||
final Material material = Material.getMaterial(item.getTypeId());
|
final Material material = Material.getMaterial(item.getTypeId());
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.commands.Commandrepair;
|
import com.earth2me.essentials.commands.Commandrepair;
|
||||||
|
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||||
|
|
||||||
|
|
||||||
public class SignRepair extends EssentialsSign
|
public class SignRepair extends EssentialsSign
|
||||||
|
@ -40,18 +41,28 @@ public class SignRepair extends EssentialsSign
|
||||||
|
|
||||||
Commandrepair command = new Commandrepair();
|
Commandrepair command = new Commandrepair();
|
||||||
command.setEssentials(ess);
|
command.setEssentials(ess);
|
||||||
String[] args = new String[]
|
|
||||||
{
|
|
||||||
sign.getLine(1)
|
|
||||||
};
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.run(ess.getServer(), player, "repair", args);
|
if (sign.getLine(1).equalsIgnoreCase("hand"))
|
||||||
|
{
|
||||||
|
command.repairHand(player);
|
||||||
|
}
|
||||||
|
else if (sign.getLine(1).equalsIgnoreCase("all"))
|
||||||
|
{
|
||||||
|
command.repairAll(player);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotEnoughArgumentsException();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new SignException(ex.getMessage(), ex);
|
throw new SignException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
charge.charge(player);
|
charge.charge(player);
|
||||||
Trade.log("Sign", "Repair", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
Trade.log("Sign", "Repair", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue