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._;
|
|
|
|
import com.earth2me.essentials.Trade;
|
|
|
|
import com.earth2me.essentials.User;
|
2013-10-11 02:44:41 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2013-12-07 20:25:23 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2011-11-14 10:11:23 +00:00
|
|
|
import org.bukkit.Material;
|
2012-03-01 15:15:37 +00:00
|
|
|
import org.bukkit.inventory.Inventory;
|
2011-06-08 01:18:33 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-12-07 20:25:23 +00:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2011-06-08 01:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class SignFree extends EssentialsSign
|
|
|
|
{
|
|
|
|
public SignFree()
|
|
|
|
{
|
|
|
|
super("Free");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
|
|
|
{
|
2012-09-23 23:19:39 +00:00
|
|
|
try {
|
2013-12-07 20:25:23 +00:00
|
|
|
ItemStack item = getItemStack(sign.getLine(1), 1, ess);
|
|
|
|
item = getItemMeta(item, sign.getLine(2), ess);
|
|
|
|
item = getItemMeta(item, sign.getLine(3), ess);
|
2012-09-23 23:19:39 +00:00
|
|
|
}
|
|
|
|
catch (SignException ex)
|
|
|
|
{
|
|
|
|
sign.setLine(1, "§c<item>");
|
|
|
|
throw new SignException(ex.getMessage(), ex);
|
|
|
|
}
|
2011-06-08 01:18:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
2013-12-07 20:25:23 +00:00
|
|
|
{
|
|
|
|
ItemStack itemStack = getItemStack(sign.getLine(1), 1, ess);
|
|
|
|
itemStack = getItemMeta(itemStack, sign.getLine(2), ess);
|
|
|
|
final ItemStack item = getItemMeta(itemStack, sign.getLine(3), ess);
|
|
|
|
|
2011-11-14 10:11:23 +00:00
|
|
|
if (item.getType() == Material.AIR)
|
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
throw new SignException(_("cantSpawnItem", "Air"));
|
2011-11-14 10:11:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-23 20:15:03 +00:00
|
|
|
item.setAmount(item.getType().getMaxStackSize());
|
2013-12-07 20:25:23 +00:00
|
|
|
|
|
|
|
ItemMeta meta = item.getItemMeta();
|
|
|
|
|
|
|
|
final String displayName = meta.hasDisplayName() ? meta.getDisplayName() : item.getType().toString();
|
|
|
|
|
|
|
|
Inventory invent = ess.getServer().createInventory(player.getBase(), 36, displayName);
|
2012-03-23 20:15:03 +00:00
|
|
|
for (int i = 0; i < 36; i++) {
|
|
|
|
invent.addItem(item);
|
|
|
|
}
|
|
|
|
player.openInventory(invent);
|
2011-07-18 02:49:38 +00:00
|
|
|
Trade.log("Sign", "Free", "Interact", username, null, username, new Trade(item, ess), sign.getBlock().getLocation(), ess);
|
2011-06-08 01:18:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|