Help - Anything like Material.getMaterial(String, Byte)?

Discussion in 'Plugin Development' started by BitBoxGaming, Dec 16, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    BitBoxGaming

    I am making a plugin for my Prison Server for a Sell All sign, however I am trouble getting a material with a data value.

    This is how I would like to have the sign to be layed out:

    [Sell All]
    LOG(Any material name)
    1(Data value of log)
    10(sell price per item)

    I have got everything worked out however I am not sure how to implement the Data Value, so they can only sell an item that has that value.


    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;
            if (event.getClickedBlock().getState() instanceof Sign) {
                Sign sign = (Sign) event.getClickedBlock().getState();
                if (sign.getLine(0).equalsIgnoreCase(ChatColor.GREEN + "[Sell All]")) {
                    Material line1 = Material.getMaterial(sign.getLine(1));
                    if (player.getInventory().contains(line1)) {
                        int amount = 0;
                        ListIterator<ItemStack> itemStackListIterator = player.getInventory().iterator();
                        while (itemStackListIterator.hasNext()) {
                            ItemStack current = itemStackListIterator.next();
                            if (current != null && current.getType() == line1) {
                                amount += current.getAmount();
                            }
                        }
                        int money = Integer.parseInt(sign.getLine(3));
                        player.getInventory().remove(line1);
                        AddCoins.addCoins(player, money * amount);
                        player.sendMessage(ChatColor.GREEN + "You sold " + ChatColor.DARK_GREEN + amount + " " + line1.name().toString().toLowerCase() + ChatColor.GREEN + " for the price of " + ChatColor.GOLD + money * amount + " Coin");
                    }
                }
            }
        }

    For example the sign for selling 1 spruce log for $10 would be:

    [Sell All]
    LOG
    1
    10
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    BitBoxGaming

    @timtower

    I hate being spoonfed, but do you think you could show me how?
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    BitBoxGaming

    @timtower

    How would I cast the int as MaterialData?
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    BitBoxGaming

    @timtower

    I am really sorry, but I still can't figure out how to get this to work

    @timtower

    I have got it working.

    Thanks very much for all the help <3 <3 <3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
Thread Status:
Not open for further replies.

Share This Page