Skip to content

Commit

Permalink
Add some debugging to make it easier to diagnose kit errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
khobbits committed Jun 25, 2014
1 parent f6b2524 commit 87c0f20
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions Essentials/src/com/earth2me/essentials/commands/Commandkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import org.bukkit.Server;


Expand All @@ -17,7 +18,7 @@ public Commandkit()
{
super("kit");
}

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
Expand All @@ -39,7 +40,7 @@ else if (args.length > 1 && user.isAuthorized("essentials.kit.others"))
giveKits(user, user, kitNames);
}
}

@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
{
Expand All @@ -53,54 +54,72 @@ public void run(final Server server, final CommandSource sender, final String co
{
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())
{
throw new Exception(tl("kitNotFound"));
}
String[] kitList = kitNames.split(",");

List<Kit> kits = new ArrayList<Kit>();

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

0 comments on commit 87c0f20

Please sign in to comment.