Show ratios as items

Discussion in 'Plugin Development' started by plisov, Sep 1, 2017.

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

    plisov

    This is going to be a bit hard to explain so bare with me.

    I'm trying to make a plugin that takes two numbers and makes a ratio out of them. I have the ratio method working great with text however I'm wondering how to show it as items. Here is my ratio method.

    Code:
        public static String ratio(int yays, int nays, int symbolAmount, ChatColor leftColor, ChatColor rightColor,
                String symbol) {
    
            StringBuilder mratio = new StringBuilder("");
    
            double dYes = yays;
            double dNo = nays;
    
            double yesv = (dYes / (dYes + dNo) * symbolAmount);
    
            if (dYes == 0 && dNo == 0) {
                return ChatColor.RED + "Limited Data";
            }
    
            for (int i = 0; i < yesv; i++) {
                mratio.append(ChatColor.GREEN);
                mratio.append(symbol);
            }
    
            for (; yesv < symbolAmount; yesv++) {
                mratio.append(ChatColor.RED);
                mratio.append(symbol);
            }
    
            return mratio.toString();
        }
    What I'm trying to do is to make it show like this[​IMG]
    instead of this
    [​IMG]
    If you need more clarification, please feel free to ask.
    Any help is very much appreciated.

    Thanks,
    plisov
     
  2. Offline

    Horsey

    1. Create a List of ItemStacks.
    2. In the same way you're appending symbols to a String builder, just add an itemstack to the list.
    3. Set the inventory's contents to your list.
    4. Profit.
     
  3. Offline

    plisov

    This seems like it would work however it won't know when to go to the next row. I can add an itemstack until it gets to the top but how would I make it go back down to the bottom and start a new row?
     
  4. Offline

    Horsey

    Add ItemStacks of material air until the list's size is divisible by 6.
     
  5. Offline

    plisov

    Okay I definitely did this incorrectly. Whenever I try to do inv.setContents(list); it turn setContents to red.

    Code:
        public static ArrayList<ItemStack> list = new ArrayList<ItemStack>();
    
        public static void createInv(Player player) {
    
            FileConfiguration config = null;
            File file = new File("plugins" + File.separator + "Vote" + File.separator + "vote-results.yml");
    
            config = YamlConfiguration.loadConfiguration(file);
    
            if (!config.contains("Voted." + player.getName())) {
                config.set("Voted." + player.getName(), false);
            }
    
            Inventory inv = Bukkit.getServer().createInventory(player, 54,
                    config.getString("Config.Question").replaceAll("&", "ยง"));
    
            y = yes(DyeColor.LIME, ChatColor.GREEN + "Yes");
            n = no(DyeColor.PINK, ChatColor.RED + "No");
    
            // Admin Panel Starts
    
            inv.setItem(53, ap);
    
            // Admin Panel Ends
            double dyes = config.getInt("Results.Yes");
            double dno = config.getInt("Results.No");
    
            int yes = config.getInt("Results.Yes");
            int no = config.getInt("Results.No");
    
            double yesv = (dyes / (dyes + dno) * 10);
    
            for (int i = 0; i < yesv; i++) {
                // mratio.append(ChatColor.GREEN);
                // mratio.append("|");
    
                inv.setItem(0, new ItemStack(yes(DyeColor.GREEN, "")));
    
            }
    
            for (; yesv < 10; yesv++) {
                // mratio.append(ChatColor.RED);
                // mratio.append("|");
    
                inv.setItem(1, new ItemStack(no(DyeColor.RED, "")));
            }
    
            player.openInventory(inv);
    
        }
    I'm also unsure how to make the itemstack move to a new slot after appending it.
     
Thread Status:
Not open for further replies.

Share This Page