2011-06-08 01:18:33 +00:00
|
|
|
package com.earth2me.essentials.signs;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-11-18 17:42:26 +00:00
|
|
|
import com.earth2me.essentials.*;
|
2011-06-26 13:31:13 +00:00
|
|
|
import java.util.HashSet;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-06-26 13:31:13 +00:00
|
|
|
import java.util.Set;
|
|
|
|
import org.bukkit.Material;
|
2011-06-08 01:18:33 +00:00
|
|
|
import org.bukkit.block.Block;
|
2011-06-26 13:31:13 +00:00
|
|
|
import org.bukkit.block.BlockFace;
|
2011-06-08 01:18:33 +00:00
|
|
|
import org.bukkit.block.Sign;
|
2011-06-26 13:31:13 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-06-08 01:18:33 +00:00
|
|
|
import org.bukkit.event.block.SignChangeEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
|
|
public class EssentialsSign
|
|
|
|
{
|
2011-06-26 13:31:13 +00:00
|
|
|
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
|
2012-12-30 04:32:20 +00:00
|
|
|
|
2011-06-08 01:18:33 +00:00
|
|
|
protected transient final String signName;
|
|
|
|
|
|
|
|
public EssentialsSign(final String signName)
|
|
|
|
{
|
|
|
|
this.signName = signName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
|
|
|
|
{
|
|
|
|
final ISign sign = new EventSign(event);
|
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2011-11-21 01:55:26 +00:00
|
|
|
if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".create")
|
|
|
|
|| user.isAuthorized("essentials.signs.create." + signName.toLowerCase(Locale.ENGLISH))))
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-08-08 20:40:54 +00:00
|
|
|
// Return true, so other plugins can use the same sign title, just hope
|
|
|
|
// they won't change it to §1[Signname]
|
|
|
|
return true;
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
2011-11-21 01:55:26 +00:00
|
|
|
sign.setLine(0, _("signFormatFail", this.signName));
|
2011-06-08 01:18:33 +00:00
|
|
|
try
|
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
|
|
|
|
if (ret)
|
|
|
|
{
|
2011-06-26 13:31:13 +00:00
|
|
|
sign.setLine(0, getSuccessName());
|
2011-06-13 13:05:31 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
catch (ChargeException ex)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
catch (SignException ex)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
ess.showError(user, ex, signName);
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
2011-08-08 20:40:54 +00:00
|
|
|
// Return true, so the player sees the wrong sign.
|
|
|
|
return true;
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 13:31:13 +00:00
|
|
|
public String getSuccessName()
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
return _("signFormatSuccess", this.signName);
|
2011-06-26 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getTemplateName()
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
return _("signFormatTemplate", this.signName);
|
2011-06-26 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 01:18:33 +00:00
|
|
|
private String getUsername(final User user)
|
|
|
|
{
|
2011-08-08 13:13:27 +00:00
|
|
|
return user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 13:31:13 +00:00
|
|
|
public final boolean onSignInteract(final Block block, final Player player, final IEssentials ess)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-26 13:31:13 +00:00
|
|
|
final ISign sign = new BlockSign(block);
|
|
|
|
final User user = ess.getUser(player);
|
2012-06-17 18:28:59 +00:00
|
|
|
if (user.checkSignThrottle())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-08 01:18:33 +00:00
|
|
|
try
|
|
|
|
{
|
2013-04-01 04:23:04 +00:00
|
|
|
return (!user.isDead() && (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use")
|
|
|
|
|| user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH))))
|
2011-06-08 01:18:33 +00:00
|
|
|
&& onSignInteract(sign, user, getUsername(user), ess);
|
|
|
|
}
|
|
|
|
catch (ChargeException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (SignException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:31:13 +00:00
|
|
|
public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-26 13:31:13 +00:00
|
|
|
final ISign sign = new BlockSign(block);
|
|
|
|
final User user = ess.getUser(player);
|
2011-06-08 01:18:33 +00:00
|
|
|
try
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break")
|
|
|
|
|| user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH)))
|
2011-06-08 01:18:33 +00:00
|
|
|
&& onSignBreak(sign, user, getUsername(user), ess);
|
|
|
|
}
|
|
|
|
catch (SignException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:31:13 +00:00
|
|
|
public final boolean onBlockPlace(final Block block, final Player player, final IEssentials ess)
|
|
|
|
{
|
|
|
|
User user = ess.getUser(player);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return onBlockPlace(block, user, getUsername(user), ess);
|
|
|
|
}
|
|
|
|
catch (ChargeException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
}
|
|
|
|
catch (SignException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean onBlockInteract(final Block block, final Player player, final IEssentials ess)
|
|
|
|
{
|
|
|
|
User user = ess.getUser(player);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return onBlockInteract(block, user, getUsername(user), ess);
|
|
|
|
}
|
|
|
|
catch (ChargeException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
}
|
|
|
|
catch (SignException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess)
|
|
|
|
{
|
|
|
|
User user = ess.getUser(player);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return onBlockBreak(block, user, getUsername(user), ess);
|
|
|
|
}
|
|
|
|
catch (SignException ex)
|
|
|
|
{
|
|
|
|
ess.showError(user, ex, signName);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-21 01:55:26 +00:00
|
|
|
|
2011-09-21 00:29:51 +00:00
|
|
|
public boolean onBlockBreak(final Block block, final IEssentials ess)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-26 13:31:13 +00:00
|
|
|
|
|
|
|
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-21 01:55:26 +00:00
|
|
|
|
2011-08-25 15:37:41 +00:00
|
|
|
public boolean onBlockIgnite(final Block block, final IEssentials ess)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-26 13:31:13 +00:00
|
|
|
|
2011-08-25 15:37:41 +00:00
|
|
|
public boolean onBlockPush(final Block block, final IEssentials ess)
|
2011-07-17 22:50:03 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:31:13 +00:00
|
|
|
public static boolean checkIfBlockBreaksSigns(final Block block)
|
|
|
|
{
|
2011-08-08 13:07:26 +00:00
|
|
|
final Block sign = block.getRelative(BlockFace.UP);
|
|
|
|
if (sign.getType() == Material.SIGN_POST && isValidSign(new BlockSign(sign)))
|
2011-06-26 13:31:13 +00:00
|
|
|
{
|
2011-06-30 20:50:22 +00:00
|
|
|
return true;
|
2011-06-26 13:31:13 +00:00
|
|
|
}
|
|
|
|
final BlockFace[] directions = new BlockFace[]
|
|
|
|
{
|
|
|
|
BlockFace.NORTH,
|
|
|
|
BlockFace.EAST,
|
|
|
|
BlockFace.SOUTH,
|
|
|
|
BlockFace.WEST
|
|
|
|
};
|
|
|
|
for (BlockFace blockFace : directions)
|
|
|
|
{
|
2011-07-17 23:17:24 +00:00
|
|
|
final Block signblock = block.getRelative(blockFace);
|
2011-06-26 13:31:13 +00:00
|
|
|
if (signblock.getType() == Material.WALL_SIGN)
|
|
|
|
{
|
2011-08-08 13:07:26 +00:00
|
|
|
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData();
|
2011-10-11 00:03:38 +00:00
|
|
|
if (signMat != null && signMat.getFacing() == blockFace && isValidSign(new BlockSign(signblock)))
|
2011-06-26 13:31:13 +00:00
|
|
|
{
|
2011-06-30 20:50:22 +00:00
|
|
|
return true;
|
2011-06-26 13:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 20:50:22 +00:00
|
|
|
return false;
|
2011-06-26 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 13:07:26 +00:00
|
|
|
public static boolean isValidSign(final ISign sign)
|
|
|
|
{
|
|
|
|
return sign.getLine(0).matches("§1\\[.*\\]");
|
|
|
|
}
|
|
|
|
|
2011-06-26 13:31:13 +00:00
|
|
|
protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean onBlockInteract(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean onBlockBreak(final Block block, final User player, final String username, final IEssentials ess) throws SignException
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<Material> getBlocks()
|
|
|
|
{
|
|
|
|
return EMPTY_SET;
|
|
|
|
}
|
2012-12-30 04:32:20 +00:00
|
|
|
|
|
|
|
public boolean areHeavyEventRequired()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-26 13:31:13 +00:00
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-12 20:33:47 +00:00
|
|
|
final String line = sign.getLine(index).trim();
|
2011-06-08 01:18:33 +00:00
|
|
|
if (line.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
final Trade trade = getTrade(sign, index, 0, ess);
|
|
|
|
final Double money = trade.getMoney();
|
|
|
|
if (money != null)
|
|
|
|
{
|
2012-03-04 10:11:58 +00:00
|
|
|
sign.setLine(index, Util.shortCurrency(money, ess));
|
2011-06-13 13:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
|
|
|
final User player, final IEssentials ess) throws SignException
|
|
|
|
{
|
2011-12-13 07:38:15 +00:00
|
|
|
if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
|
|
|
|
{
|
|
|
|
int amount = getIntegerPositive(sign.getLine(amountIndex));
|
|
|
|
sign.setLine(amountIndex, Integer.toString(amount));
|
|
|
|
sign.setLine(itemIndex, "exp");
|
2011-12-13 07:41:28 +00:00
|
|
|
return;
|
2011-12-13 07:38:15 +00:00
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
|
|
|
|
final ItemStack item = trade.getItemStack();
|
|
|
|
sign.setLine(amountIndex, Integer.toString(item.getAmount()));
|
|
|
|
sign.setLine(itemIndex, sign.getLine(itemIndex).trim());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
|
|
|
final User player, final IEssentials ess) throws SignException
|
|
|
|
{
|
2011-12-13 07:38:15 +00:00
|
|
|
if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
|
|
|
|
{
|
|
|
|
final int amount = getIntegerPositive(sign.getLine(amountIndex));
|
|
|
|
return new Trade(amount, ess);
|
|
|
|
}
|
2011-07-15 23:33:22 +00:00
|
|
|
final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess);
|
2011-06-26 16:14:59 +00:00
|
|
|
final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
|
2011-06-13 13:05:31 +00:00
|
|
|
if (item.getTypeId() == 0 || amount < 1)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new SignException(_("moreThanZero"));
|
2011-06-13 13:05:31 +00:00
|
|
|
}
|
|
|
|
item.setAmount(amount);
|
|
|
|
return new Trade(item, ess);
|
|
|
|
}
|
2011-06-08 01:18:33 +00:00
|
|
|
|
2011-06-12 20:33:47 +00:00
|
|
|
protected final void validateInteger(final ISign sign, final int index) throws SignException
|
|
|
|
{
|
|
|
|
final String line = sign.getLine(index).trim();
|
|
|
|
if (line.isEmpty())
|
|
|
|
{
|
|
|
|
throw new SignException("Empty line " + index);
|
|
|
|
}
|
2011-06-26 16:14:59 +00:00
|
|
|
final int quantity = getIntegerPositive(line);
|
2011-06-12 20:33:47 +00:00
|
|
|
sign.setLine(index, Integer.toString(quantity));
|
|
|
|
}
|
|
|
|
|
2011-06-26 16:14:59 +00:00
|
|
|
protected final int getIntegerPositive(final String line) throws SignException
|
|
|
|
{
|
|
|
|
final int quantity = getInteger(line);
|
2011-06-30 23:33:09 +00:00
|
|
|
if (quantity < 1)
|
2011-06-26 16:14:59 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new SignException(_("moreThanZero"));
|
2011-06-26 16:14:59 +00:00
|
|
|
}
|
|
|
|
return quantity;
|
|
|
|
}
|
|
|
|
|
2011-06-12 20:33:47 +00:00
|
|
|
protected final int getInteger(final String line) throws SignException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final int quantity = Integer.parseInt(line);
|
2011-06-26 16:14:59 +00:00
|
|
|
|
2011-06-12 20:33:47 +00:00
|
|
|
return quantity;
|
|
|
|
}
|
|
|
|
catch (NumberFormatException ex)
|
|
|
|
{
|
|
|
|
throw new SignException("Invalid sign", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 23:33:22 +00:00
|
|
|
protected final ItemStack getItemStack(final String itemName, final int quantity, final IEssentials ess) throws SignException
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-07-15 23:33:22 +00:00
|
|
|
final ItemStack item = ess.getItemDb().get(itemName);
|
2011-06-13 13:05:31 +00:00
|
|
|
item.setAmount(quantity);
|
|
|
|
return item;
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:15:19 +00:00
|
|
|
protected final Double getMoney(final String line) throws SignException
|
2011-06-12 20:33:47 +00:00
|
|
|
{
|
2011-06-30 21:27:00 +00:00
|
|
|
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
2011-06-30 23:33:09 +00:00
|
|
|
return isMoney ? getDoublePositive(line.substring(1)) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final Double getDoublePositive(final String line) throws SignException
|
|
|
|
{
|
|
|
|
final double quantity = getDouble(line);
|
2011-07-17 22:50:03 +00:00
|
|
|
if (Math.round(quantity * 100.0) < 1.0)
|
2011-06-30 23:33:09 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new SignException(_("moreThanZero"));
|
2011-06-30 23:33:09 +00:00
|
|
|
}
|
|
|
|
return quantity;
|
2011-06-12 20:33:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 13:15:19 +00:00
|
|
|
protected final Double getDouble(final String line) throws SignException
|
2011-06-12 20:33:47 +00:00
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
try
|
2011-06-12 20:33:47 +00:00
|
|
|
{
|
2011-06-30 23:33:09 +00:00
|
|
|
return Double.parseDouble(line);
|
2011-06-12 20:33:47 +00:00
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
catch (NumberFormatException ex)
|
2011-06-12 20:33:47 +00:00
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
throw new SignException(ex.getMessage(), ex);
|
2011-06-12 20:33:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
protected final Trade getTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
|
|
|
{
|
|
|
|
return getTrade(sign, index, 1, ess);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected final Trade getTrade(final ISign sign, final int index, final int decrement, final IEssentials ess) throws SignException
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-12 20:33:47 +00:00
|
|
|
final String line = sign.getLine(index).trim();
|
2011-06-08 01:18:33 +00:00
|
|
|
if (line.isEmpty())
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 13:05:31 +00:00
|
|
|
final Double money = getMoney(line);
|
|
|
|
if (money == null)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
final String[] split = line.split("[ :]+", 2);
|
2011-06-08 01:18:33 +00:00
|
|
|
if (split.length != 2)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new SignException(_("invalidCharge"));
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
2011-06-26 16:14:59 +00:00
|
|
|
final int quantity = getIntegerPositive(split[0]);
|
2011-06-13 13:05:31 +00:00
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
final String item = split[1].toLowerCase(Locale.ENGLISH);
|
2011-06-13 13:05:31 +00:00
|
|
|
if (item.equalsIgnoreCase("times"))
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-13 13:05:31 +00:00
|
|
|
sign.setLine(index, (quantity - decrement) + " times");
|
2012-07-31 10:13:18 +00:00
|
|
|
sign.updateSign();
|
2011-11-21 01:55:26 +00:00
|
|
|
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
2011-12-07 09:31:18 +00:00
|
|
|
else if (item.equalsIgnoreCase("exp") || item.equalsIgnoreCase("xp"))
|
|
|
|
{
|
|
|
|
sign.setLine(index, quantity + " exp");
|
|
|
|
return new Trade(quantity, ess);
|
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
else
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-07-15 23:33:22 +00:00
|
|
|
final ItemStack stack = getItemStack(item, quantity, ess);
|
2011-06-13 13:05:31 +00:00
|
|
|
sign.setLine(index, quantity + " " + item);
|
2011-06-30 21:27:00 +00:00
|
|
|
return new Trade(stack, ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-13 13:05:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return new Trade(money, ess);
|
|
|
|
}
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static class EventSign implements ISign
|
|
|
|
{
|
|
|
|
private final transient SignChangeEvent event;
|
2011-06-26 13:31:13 +00:00
|
|
|
private final transient Block block;
|
2012-09-23 23:19:39 +00:00
|
|
|
private final transient Sign sign;
|
2011-06-08 01:18:33 +00:00
|
|
|
|
2012-09-24 02:10:54 +00:00
|
|
|
EventSign(final SignChangeEvent event)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
|
|
|
this.event = event;
|
2011-06-26 13:31:13 +00:00
|
|
|
this.block = event.getBlock();
|
2012-09-23 23:19:39 +00:00
|
|
|
this.sign = (Sign)block.getState();
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-08 01:18:33 +00:00
|
|
|
public final String getLine(final int index)
|
|
|
|
{
|
|
|
|
return event.getLine(index);
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-08 01:18:33 +00:00
|
|
|
public final void setLine(final int index, final String text)
|
|
|
|
{
|
|
|
|
event.setLine(index, text);
|
2012-09-23 23:19:39 +00:00
|
|
|
sign.setLine(index, text);
|
|
|
|
updateSign();
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
2011-06-26 13:31:13 +00:00
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-26 13:31:13 +00:00
|
|
|
public Block getBlock()
|
|
|
|
{
|
|
|
|
return block;
|
|
|
|
}
|
2011-07-08 11:00:18 +00:00
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-07-08 11:00:18 +00:00
|
|
|
public void updateSign()
|
|
|
|
{
|
2012-09-23 23:19:39 +00:00
|
|
|
sign.update();
|
2011-07-08 11:00:18 +00:00
|
|
|
}
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static class BlockSign implements ISign
|
|
|
|
{
|
|
|
|
private final transient Sign sign;
|
2011-06-26 13:31:13 +00:00
|
|
|
private final transient Block block;
|
2011-06-08 01:18:33 +00:00
|
|
|
|
2012-09-24 02:10:54 +00:00
|
|
|
BlockSign(final Block block)
|
2011-06-08 01:18:33 +00:00
|
|
|
{
|
2011-06-26 13:31:13 +00:00
|
|
|
this.block = block;
|
2011-08-27 18:39:54 +00:00
|
|
|
this.sign = (Sign)block.getState();
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-08 01:18:33 +00:00
|
|
|
public final String getLine(final int index)
|
|
|
|
{
|
|
|
|
return sign.getLine(index);
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-08 01:18:33 +00:00
|
|
|
public final void setLine(final int index, final String text)
|
|
|
|
{
|
|
|
|
sign.setLine(index, text);
|
|
|
|
}
|
2011-06-26 13:31:13 +00:00
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-06-26 13:31:13 +00:00
|
|
|
public final Block getBlock()
|
|
|
|
{
|
|
|
|
return block;
|
|
|
|
}
|
2011-07-17 22:50:03 +00:00
|
|
|
|
2011-11-18 18:07:28 +00:00
|
|
|
@Override
|
2011-07-08 11:00:18 +00:00
|
|
|
public final void updateSign()
|
|
|
|
{
|
|
|
|
sign.update();
|
|
|
|
}
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface ISign
|
|
|
|
{
|
|
|
|
String getLine(final int index);
|
|
|
|
|
|
|
|
void setLine(final int index, final String text);
|
2011-06-26 13:31:13 +00:00
|
|
|
|
|
|
|
public Block getBlock();
|
2011-07-17 22:50:03 +00:00
|
|
|
|
2011-07-08 11:00:18 +00:00
|
|
|
void updateSign();
|
2011-06-08 01:18:33 +00:00
|
|
|
}
|
|
|
|
}
|