2011-06-08 01:18:33 +00:00
|
|
|
package com.earth2me.essentials.signs;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.ChargeException;
|
2012-09-25 21:37:58 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2013-07-13 15:14:39 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2011-11-18 17:42:26 +00:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-06-08 01:18:33 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-12-07 01:12:36 +00:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2011-06-08 01:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class SignWarp extends EssentialsSign
|
|
|
|
{
|
|
|
|
public SignWarp()
|
|
|
|
{
|
|
|
|
super("Warp");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
validateTrade(sign, 3, ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
final String warpName = sign.getLine(1);
|
|
|
|
|
|
|
|
if (warpName.isEmpty())
|
|
|
|
{
|
2012-09-23 23:19:39 +00:00
|
|
|
sign.setLine(1, "§c<Warp name>");
|
2012-09-25 21:37:58 +00:00
|
|
|
throw new SignException(_("invalidSignLine", 1));
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ess.getWarps().getWarp(warpName);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
final String group = sign.getLine(2);
|
2011-11-04 00:44:41 +00:00
|
|
|
if ("Everyone".equalsIgnoreCase(group) || "Everybody".equalsIgnoreCase(group))
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
|
|
|
sign.setLine(2, "§2Everyone");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
|
|
|
{
|
|
|
|
final String warpName = sign.getLine(1);
|
|
|
|
final String group = sign.getLine(2);
|
|
|
|
if ((!group.isEmpty()
|
|
|
|
&& ("§2Everyone".equals(group)
|
|
|
|
|| player.inGroup(group)))
|
2012-09-29 12:55:47 +00:00
|
|
|
|| (group.isEmpty() && (!ess.getSettings().getPerWarpPermission() || player.isAuthorized("essentials.warps." + warpName))))
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
final Trade charge = getTrade(sign, 3, ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
try
|
|
|
|
{
|
2013-06-08 18:34:14 +00:00
|
|
|
player.getTeleport().warp(player, warpName, charge, TeleportCause.PLUGIN);
|
2013-02-28 03:15:21 +00:00
|
|
|
Trade.log("Sign", "Warp", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|