mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 13:13:24 +00:00
Add support for adding item meta to [free] signs.
Fix NPE on [sign] creation.
This commit is contained in:
parent
427b97433e
commit
946051de71
3 changed files with 38 additions and 6 deletions
|
@ -117,7 +117,7 @@ public class MetaItemStack
|
|||
}
|
||||
}
|
||||
|
||||
private void addStringMeta(final CommandSource sender, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
|
||||
public void addStringMeta(final CommandSource sender, final boolean allowUnsafe, final String string, final IEssentials ess) throws Exception
|
||||
{
|
||||
final String[] split = splitPattern.split(string, 2);
|
||||
if (split.length < 1)
|
||||
|
|
|
@ -100,7 +100,7 @@ public class EssentialsSign
|
|||
showError(ess, user.getSource(), ex, signName);
|
||||
return false;
|
||||
}
|
||||
catch (SignException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
showError(ess, user.getSource(), ex, signName);
|
||||
return false;
|
||||
|
@ -385,6 +385,26 @@ public class EssentialsSign
|
|||
}
|
||||
}
|
||||
|
||||
protected final ItemStack getItemMeta(final ItemStack item, final String meta, final IEssentials ess) throws SignException
|
||||
{
|
||||
ItemStack stack = item;
|
||||
try
|
||||
{
|
||||
if (!meta.isEmpty())
|
||||
{
|
||||
MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
metaStack.addStringMeta(null, allowUnsafe, meta, ess);
|
||||
stack = metaStack.getItemStack();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new SignException(ex.getMessage(), ex);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected final BigDecimal getMoney(final String line) throws SignException
|
||||
{
|
||||
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
|
||||
|
|
|
@ -4,9 +4,11 @@ import static com.earth2me.essentials.I18n._;
|
|||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
|
||||
public class SignFree extends EssentialsSign
|
||||
|
@ -20,7 +22,9 @@ public class SignFree extends EssentialsSign
|
|||
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
try {
|
||||
getItemStack(sign.getLine(1), 1, ess);
|
||||
ItemStack item = getItemStack(sign.getLine(1), 1, ess);
|
||||
item = getItemMeta(item, sign.getLine(2), ess);
|
||||
item = getItemMeta(item, sign.getLine(3), ess);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
|
@ -32,15 +36,23 @@ public class SignFree extends EssentialsSign
|
|||
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
||||
{
|
||||
final ItemStack item = getItemStack(sign.getLine(1), 1, ess);
|
||||
{
|
||||
ItemStack itemStack = getItemStack(sign.getLine(1), 1, ess);
|
||||
itemStack = getItemMeta(itemStack, sign.getLine(2), ess);
|
||||
final ItemStack item = getItemMeta(itemStack, sign.getLine(3), ess);
|
||||
|
||||
if (item.getType() == Material.AIR)
|
||||
{
|
||||
throw new SignException(_("cantSpawnItem", "Air"));
|
||||
}
|
||||
|
||||
item.setAmount(item.getType().getMaxStackSize());
|
||||
Inventory invent = ess.getServer().createInventory(player.getBase(), 36, item.getItemMeta().getDisplayName());
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
final String displayName = meta.hasDisplayName() ? meta.getDisplayName() : item.getType().toString();
|
||||
|
||||
Inventory invent = ess.getServer().createInventory(player.getBase(), 36, displayName);
|
||||
for (int i = 0; i < 36; i++) {
|
||||
invent.addItem(item);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue