Solved GUI Help

Discussion in 'Spigot Plugin Development' started by JustCedric, May 20, 2016.

  1. Hi guys,

    I'm making a GUI menu but I dont know how to do something.
    Code (Text):
            int money = instance.playerConfig.getInt(UUID + ".money");
            int diamond_blocks = money / 5000;
            int diamond_left = diamond_block * 5000;
            int redstone_block = (money - diamond_left) / 1000
    With this code I can show how much diamond blocks & redstone blocks a player has with his money but how do I show it in a GUI menu? If it's > 64 it will create a new stack and if it's 0 it wont show
     
    #1 JustCedric, May 20, 2016
    Last edited: May 20, 2016
  2. Change the name of the item to the amount of diamond blocks instead of using the stack size?
     
  3. Maybe if there're no other options, if there're I'd like to use them so I can just use it how I want :p
     
    • Funny Funny x 1
  4. While the amount of the item is greater than 64, add a stack of the item, and decrement 64 from the amount. Add the remainder at the end?
     
  5. You could write in the Lore too or you can send the player a message by clicking the item
     
  6. If you have for example more then 64 diamond blocks it will create a new stack and if you got everythink from diamond blocks you'll create the blocks for redstone if that's more then 64 it will also get 2 stacks.
     
  7. Working on it.
     
  8. Inventory#setMaxItemSize(int amount);

    ?? Why not use this
     
  9. I would suggest putting the amount in the lore instead, it is easier to read and to code.
     
  10. If it's over 127, that won't work.
     
  11. That's how you have to think to do that.


    I remind you he's asking for a COMPLETE GUI, not a GUI to click and get info.

    I tried but I don't feel like finishing, I am getting tired too... xD
    So what I will post is only the basics...

    Code (Text):

    private void openMoneyGui(Player player) {
        Inventory inv = Bukkit.createInventory(null, 9, "Your GUI Name, ChatColor supported!");
       
        // This is what you're going to be looking at!
        if(diamond_blocks != 0){
            double rawNumberOfStacks = diamond_blocks / 64;
            int numberOfStacks = (int) Math.ceil(rawNumberOfStacks);
            ItemStack diamondBlock[] = new ItemStack[numberOfStacks];
            for(int i = 0; i <= numberOfStacks - 1; i++){
                diamondBlock[i] = new ItemStack(Material.);
            }
            // Here you'll make a stack for leftovers;
        }
        // Here's the end of the diamond blocks!
         
        ItemStack redstoneBlock = new ItemStack (Material.REDSTONE_BLOCK, redstone_block);
        ItemStack redstoneBlockMeta = new redstoneBlock.getItemMeta();
     
        redstoneBlockMeta.setDisplayName(ChatColor.DARK_RED + "Exit");
        redstoneBlock.setItemMeta(redstoneBlockMeta);
         
        inv.setItem(9, redstoneBlock);

        player.openInventory(inv);
    }
     
     
  12. What do you mean with leftovers?
     
  13. Maybe add a line in the lore that says "Amount:{amount}"
     
  14. Leftovers : The last diamond block stack which is not exactly 64 of size, so there are, x number of stacks plus the rest, so for example, 64 (Complete stack) + 64 + 64 + 42 (Leftovers)
     
  15. Doesn't work.. It wont show the items and I get no errors.
     
  16. Its not finished, I told you I had some problems trying to find out the solution, can I see the code you made from mine please?
     
  17. Code (Text):
            int money = Main.getInstance().playerConfig.getInt(UUID + ".bank");
            int diamond_blocks = money / 2500;
            int diamond_left = diamond_blocks * 2500;
            int redstone_block = (money - diamond_left) / 1000;
           
            if(diamond_blocks != 0){
                double rawNumberOfStacks = diamond_blocks / 64;
                int numberOfStacks = (int) Math.ceil(rawNumberOfStacks);
                ItemStack diamondBlock[] = new ItemStack[numberOfStacks];
                for(int i = 0; i <= numberOfStacks - 1; i++){
                    diamondBlock[i] = new ItemStack(Material.DIAMOND_BLOCK);
                }
                int leftover = diamond_blocks - (2500 * numberOfStacks);
            }
    I didn't made leftover and I dont know how I've to add the stacks etc to a specific inv slot
     
  18. What I made was meant to be the gui, you didnt take anything of it :/
    Its a method you have to put apart, EVERYTHING in the method has to stay there.
    Once you have it, it your above code add this: openMoneyGui(player);
    Code (Text):
    private void openMoneyGui(Player player) {
        Inventory inv = Bukkit.createInventory(null, 9, "Your GUI Name, ChatColor supported!");
         
        ItemStack redstoneBlock = new ItemStack (Material.REDSTONE_BLOCK, redstone_block);
        ItemStack redstoneBlockMeta = new redstoneBlock.getItemMeta();

        redstoneBlockMeta.setDisplayName(ChatColor.DARK_RED + "Exit");
        redstoneBlock.setItemMeta(redstoneBlockMeta);
         
        inv.setItem(9, redstoneBlock);

        player.openInventory(inv);
    }
    Start by telling me if this generates a GUI and shows redstone blocks.
    But take the complete method and let it be independant in the class, you're not meant to implement some things in your old method.
     
  19. It's inside a GUI I'll give you the whole code.
     
  20. With @JustCedric we've got the problem and the thread has served its purpose!
    @JustCedric please tag your post as solved.