2011-12-08 04:44:18 +00:00
|
|
|
package com.earth2me.essentials.signs;
|
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import com.earth2me.essentials.ChargeException;
|
|
|
|
import com.earth2me.essentials.Kit;
|
|
|
|
import com.earth2me.essentials.Trade;
|
|
|
|
import com.earth2me.essentials.User;
|
2012-08-07 23:14:07 +00:00
|
|
|
import com.earth2me.essentials.commands.NoChargeException;
|
2013-10-11 02:44:41 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2011-12-08 04:44:18 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2011-12-08 04:44:18 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public class SignKit extends EssentialsSign {
|
|
|
|
public SignKit() {
|
|
|
|
super("Kit");
|
|
|
|
}
|
2011-12-08 04:44:18 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException {
|
|
|
|
validateTrade(sign, 3, ess);
|
2012-03-01 22:36:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH).trim();
|
2011-12-08 04:44:18 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
if (kitName.isEmpty()) {
|
|
|
|
sign.setLine(1, "§dKit name!");
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
ess.getSettings().getKit(kitName);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
final String group = sign.getLine(2);
|
|
|
|
if ("Everyone".equalsIgnoreCase(group) || "Everybody".equalsIgnoreCase(group)) {
|
|
|
|
sign.setLine(2, "§2Everyone");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-12-08 04:44:18 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
|
|
|
|
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH).trim();
|
|
|
|
final String group = sign.getLine(2).trim();
|
|
|
|
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group))) || (group.isEmpty() && (player.isAuthorized("essentials.kits." + kitName)))) {
|
|
|
|
final Trade charge = getTrade(sign, 3, ess);
|
|
|
|
charge.isAffordableFor(player);
|
|
|
|
try {
|
|
|
|
final Kit kit = new Kit(kitName, ess);
|
|
|
|
kit.checkDelay(player);
|
|
|
|
kit.setTime(player);
|
|
|
|
kit.expandItems(player);
|
2014-06-25 18:03:31 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
charge.charge(player);
|
|
|
|
Trade.log("Sign", "Kit", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
|
|
|
} catch (NoChargeException ex) {
|
|
|
|
return false;
|
|
|
|
} catch (Exception ex) {
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (group.isEmpty()) {
|
|
|
|
throw new SignException(tl("noKitPermission", "essentials.kits." + kitName));
|
|
|
|
} else {
|
|
|
|
throw new SignException(tl("noKitGroup", group));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-08 04:44:18 +00:00
|
|
|
}
|