Question on items with data values

Discussion in 'Plugin Development' started by DragonSlayer1920, Jun 26, 2014.

Thread Status:
Not open for further replies.
  1. Hello,
    I am making my own shop plugin for my server, and all is going well but when I try to remove an item that is stored along with that shop it will not be removed if it has a data-value. So lets say I have a coal shop, as you may know charcoal has the same ID as coal with a data value, when I sell my charcoal at a coal shop I still receive the money but the item is not removed because it has a data value, if this doesn't make since please tell me, this may have been a stupid question but I can't figure it out. Anyways thanks in advance for helping!
     
  2. Offline

    unrealdesign

    DragonSlayer1920 If you show us your code, we can better help you. Your verbal logic is sound, but you probably have some error in your code logic.
     
  3. unrealdesign

    Well honestly all I need to know is how to remove all of a type of item, like when I remove sandstone also remove the creeper face sandstone.

    Code:
    public void charge_buy_64(final Player p, int i, String s) {
           
            ItemStack item = new ItemStack(Material.matchMaterial(s), 64);
           
            try {
                r = econ.depositPlayer(p.getName(), i * 64);
                if(r.transactionSuccess()) {
                    p.sendMessage(ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "Shop" + ChatColor.DARK_GREEN + "]" + ChatColor.DARK_AQUA + " You sold 64 " + s.toLowerCase() + " for $" + i * 64+ ".");
                   
                    p.getInventory().removeItem(item);
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            p.updateInventory();
                        }
                    }.runTaskLater(this, 10);
                   
                } else {
                    p.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.DARK_RED + "Shop" + ChatColor.DARK_RED + "]" + ChatColor.RED + " Something went wrong!");
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
     
  4. Offline

    unrealdesign

    I believe your problem is:
    Code:java
    1. new BukkitRunnable() {
    2. @Override
    3. public void run() {
    4. p.updateInventory();
    5. }
    6. }.runTaskLater(this, 10);



    You want to do:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncDelayedTask(JavaPlugin, Runnable, long)



    Also, I recommend
    Code:java
    1. public void chargeBuy(final Player p, int i, String s, int amount)

    because it is more versatile.
     
  5. unrealdesign the scheduler is fine, all I need is removing items with data values, everything works except that
     
  6. Offline

    unrealdesign

    DragonSlayer1920 Then just pass the ItemStack instead of the string. I'm assuming you're doing it PlayerInteractEvent for Action.RIGHT_CLICK or something of the sort. So just pass the ItemStack along.

    If this is some how impossible, then you would have to pass along the data value for the ItemStack in the method. Then you would do item.setData(MaterialData);
     
Thread Status:
Not open for further replies.

Share This Page