Displaying Usages

Discussion in 'Plugin Development' started by SnapchatDev, Apr 29, 2017.

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

    SnapchatDev

  2. Offline

    Zombie_Striker

    @SnapchatDev
    To get the total amount of memory, use
    To get the amount of ram free, use
    And then, to get the amount used, put the two together like this:
    Side note: If you do create this plugin, I would recommend that you merge all three of those variables. Just give the percentage the used memory and then add a / and then the total amount. From that one line, you can know all three variables without the display seeming cluttered.
     
  3. Offline

    SnapchatDev

    Code:
            new BukkitRunnable()
            {
                public void run()
                {
                    for(Player player : Bukkit.getOnlinePlayers()) {
                        if(player.hasPermission("core.alert")) {
                            player.sendMessage(ChatColor.GREEN + "Saved all core data..");
                            player.sendMessage(ChatColor.RED + "RAM Free: " + ChatColor.GOLD + Runtime.getRuntime().totalMemory());
                            player.sendMessage(ChatColor.GREEN + "TPS Total Free Memory: " + ChatColor.GOLD + Runtime.getRuntime().freeMemory());
                            player.sendMessage(ChatColor.GREEN + "TPS Total Free Memory: " + ChatColor.GOLD + Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory());
                        }
                    }
                }
            } .runTaskTimerAsynchronously(getInstance(), 2400L, 2400L);
        }
    Operator '-' cannot be applied to 'java.lang.String', 'long

    https://gyazo.com/ac66f9d6cf611c1e2e35acf79549ca17

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 29, 2017
  4. Offline

    Zombie_Striker

    @SnapchatDev
    1. Encapsulation. When doing the math to calculate the total amount of memory used, you need to make sure the addition of the Math is in a different operation than the addition of the String. Fix this by adding ( and ) around the math.
    2. If you want readable numbers, such as Kb and Mb. See the chart below:
    If the number is greater than 1073741824 (Or 1024^3 ), then use Gb and divide by that number
    Else, if it is greater than 1048576 (or 1024^2), then use MB and divide
    Else, if it is greater than 1024, use KB and divide
    Else, if it is not equal to any of the above, it is it Bytes, which should never happen and likely means your server will crash at that moment. If this is the case, use B.
     
Thread Status:
Not open for further replies.

Share This Page