ItemStack to String

Discussion in 'Plugin Development' started by DSCxSander, Feb 5, 2017.

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

    DSCxSander

    Hey Guys!

    I´m making a small auction plugin for my server.
    But if I sell an itemstack then it wil say null (see picture)

    Picture:
    [​IMG]

    My code:
    Code:
    ItemStack hand = p.getInventory().getItemInHand();
    
    Bukkit.broadcastMessage(Main.prefix + "§f" + p.getName() + "§7 verkoopt: §a" + hand.getItemMeta().getDisplayName() + " §7voor een prijs van: §a" + args[0] + " goud §7 en het is er §a 1 stuk§7.");
     
  2. Online

    timtower Administrator Administrator Moderator

    @DSCxSander displayname is the custom name (anvil rename)
    getType().name()
     
  3. Offline

    DSCxSander

    @timtower Thanks! And when an player sells this product which method can I use for the /buy command?
     
  4. Online

    timtower Administrator Administrator Moderator

    @DSCxSander Don't know, don't know the rest of your code, don't know how you want the /buy command to work.
     
  5. Offline

    DSCxSander

    When player A set an cobblestone for 5 gold on the auction,
    and player B want to buy it, and do /buy. It will remove 5 gold of his inventory and add this in the inventory of player A @timtower
     
  6. Online

    timtower Administrator Administrator Moderator

    @DSCxSander How long will the offer be up? What if multiple people make an offer? Does /buy also have an item after the command?
     
  7. Offline

    PQE

    @DSCxSander you'd want to have a hashmap of all values in an auction (HashMap of String, Double). Then you'd want a GUI to show the shop prices, and the hashmap values of each items. I assume it's first come first serve, so buying them would just check if the player has gold:

    Code:
    int goldCount = 0;
    Player player = (Player) sender;
    PlayerInventory pi = player.getInventory();
    for (int i=0; i < 36; i++) {
        if (pi.getItem(i).getType() == Material.GOLD_INGOT) {
            goldCount = goldCount + pi.getItem(i).getType().getAmount();
            if (goldCount >= [HASHMAP FOR GOLD REQUIRED] {
                  break;
            }
        }
    if (goldCount >= [HASHMAP FOR ITEM SALE PRICE]) {
        code code code
    }
    
    That's really inaccurate but just to give you a general idea..

    EDIT: Make sure you clear the amount of gold from their inv too
     
Thread Status:
Not open for further replies.

Share This Page