From 87c0f20e92f504dbdf1bbff8d74e9ff262a638c1 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 25 Jun 2014 19:19:04 +0100 Subject: Add some debugging to make it easier to diagnose kit errors. --- .../earth2me/essentials/commands/Commandkit.java | 53 +++++++++++++++------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 046745dcb..aa3f21d3b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.utils.StringUtil; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.logging.Level; import org.bukkit.Server; @@ -17,7 +18,7 @@ public class Commandkit extends EssentialsCommand { super("kit"); } - + @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { @@ -39,7 +40,7 @@ public class Commandkit extends EssentialsCommand giveKits(user, user, kitNames); } } - + @Override public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { @@ -53,18 +54,18 @@ public class Commandkit extends EssentialsCommand { final User userTo = getPlayer(server, args, 1, true, false); final String[] kits = args[0].toLowerCase(Locale.ENGLISH).split(","); - + for (final String kitName : kits) { final Kit kit = new Kit(kitName, ess); kit.expandItems(userTo); - + sender.sendMessage(tl("kitGiveTo", kitName, userTo.getDisplayName())); userTo.sendMessage(tl("kitReceive", kitName)); } } } - + private void giveKits(final User userTo, final User userFrom, final String kitNames) throws Exception { if (kitNames.isEmpty()) @@ -72,35 +73,53 @@ public class Commandkit extends EssentialsCommand throw new Exception(tl("kitNotFound")); } String[] kitList = kitNames.split(","); - + List kits = new ArrayList(); - + for (final String kitName : kitList) { if (kitName.isEmpty()) { throw new Exception(tl("kitNotFound")); } - + Kit kit = new Kit(kitName, ess); kit.checkPerms(userFrom); kit.checkDelay(userFrom); kit.checkAffordable(userFrom); kits.add(kit); } - + for (final Kit kit : kits) { - kit.setTime(userFrom); - kit.expandItems(userTo); - kit.chargeUser(userTo); - - if (!userFrom.equals(userTo)) + try { - userFrom.sendMessage(tl("kitGiveTo", kit.getName(), userTo.getDisplayName())); + + kit.checkDelay(userFrom); + kit.checkAffordable(userFrom); + kit.setTime(userFrom); + kit.expandItems(userTo); + kit.chargeUser(userTo); + + if (!userFrom.equals(userTo)) + { + userFrom.sendMessage(tl("kitGiveTo", kit.getName(), userTo.getDisplayName())); + } + + userTo.sendMessage(tl("kitReceive", kit.getName())); + + } + catch (NoChargeException ex) + { + if (ess.getSettings().isDebug()) + { + ess.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); + } + } + catch (Exception ex) + { + ess.showError(userFrom.getSource(), ex, "\\ kit: " + kit.getName()); } - - userTo.sendMessage(tl("kitReceive", kit.getName())); } } } -- cgit v1.2.3