Solved Help with printing out how many items are in a stack to the player.

Discussion in 'Plugin Development' started by Drew1895, Mar 5, 2014.

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


    Hi! I'm trying to create a economy plugin that has commands like /buy, /sell, etc. I've mostly got it down, but when I do /sell, It returns "You have sold ItemStack{STONE x 64} for 0. Your new balance is 25. What I want it to do print "You have sold 64 stone for x. Your new balance is x".

    Heres the code:

    1. else if(command.getName().equalsIgnoreCase("sell")){
    2. int globalsellint = this.getConfig().getInt(Player.getItemInHand().toString() + "Price") * this.getConfig().getInt("globalsellmultiplier") ;
    3. EconomyResponse sellitems = economy.depositPlayer(Player.getName(), globalsellint);
    4. if(sellitems.transactionSuccess()){
    5. sender.sendMessage(ChatColor.GOLD + "[GlobalShop]" + ChatColor.BLUE + "You have sold " + Player.getItemInHand() + Player.getItemInHand().getAmount() + "Price");
    6. sender.sendMessage(ChatColor.BLUE + "Your new balance is " + sellitems.balance);
    7. Player.getInventory().removeItem(Player.getItemInHand());
    8. }

    Being that this is my first plugin, all help is appreciated.
    NOTE: The reason for the word 'price' after toString is because in the config, I have the items setup like stonePrice: 1

  2. Offline


    use String methods like .replace(String old, String new) and other useful ones. And after all of this, print message.
  3. Offline


    Dont print Player.getItemInHand(), it returns an itemstack, which doesn't look pretty in chat.
    Instead try using
    1. sender.sendMessage(ChatColor.GOLD + "[GlobalShop]" + ChatColor.BLUE + "You have sold " + Player.getItemInHand().getAmount() + " " + Player.getItemInHand().getType());
  4. Offline


    String sold = "" + player.getItemInHand().getType();
    int amt = player.getItemInHand().getAmount();
    "You have sold " + (Character.toUpperCase(sold.charAt(0))+sold.substring(1) .replace("_", " ") + " x" + amt)

    "You have sold Mossy cobblestone x64" (an example)

    Also, your sig, "isStraight" suggests a boolean return, but the method's return type is void. And you're missing a }. Just saiyan.
  5. Offline


    Loop through everything in the list and send a message for every item
  6. Offline


    Best suggestion ever, great contribution
    Panjab and Bartoke like this.
  7. Offline


    I was trying to help as I can dude, I just had like 5 minutes on my phone and saw this thread. I was hoping for him to get something out of it rather than somebody being rude about it.
Thread Status:
Not open for further replies.

Share This Page