From 0344b69dd931751c64101e064a91aa7bfbaa01ce Mon Sep 17 00:00:00 2001 From: mcmonkey4eva Date: Thu, 15 Jan 2015 17:51:33 -0800 Subject: [PATCH] Add runtime tags (server.ram_*, server.available_processors) Yay for server details! --- .../denizen/tags/core/UtilTags.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java b/src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java index 74b42f292f..946897ebb8 100644 --- a/src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java +++ b/src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java @@ -238,6 +238,51 @@ public void serverTag(ReplaceableTagEvent event) { .getAttribute(attribute.fulfill(1))); } + // <--[tag] + // @attribute + // @returns Element(Number) + // @description + // How much RAM is allocated to the server, in bytes (total memory). + // --> + if (attribute.startsWith("ram_allocated")) { + event.setReplaced(new Element(Runtime.getRuntime().totalMemory()) + .getAttribute(attribute.fulfill(1))); + } + + // <--[tag] + // @attribute + // @returns Element(Number) + // @description + // How much RAM is available to the server, in bytes (max memory). + // --> + if (attribute.startsWith("ram_max")) { + event.setReplaced(new Element(Runtime.getRuntime().maxMemory()) + .getAttribute(attribute.fulfill(1))); + } + + // <--[tag] + // @attribute + // @returns Element(Number) + // @description + // How much RAM is unused but available on the server, in bytes (free memory). + // --> + if (attribute.startsWith("ram_free")) { + event.setReplaced(new Element(Runtime.getRuntime().freeMemory()) + .getAttribute(attribute.fulfill(1))); + } + + // <--[tag] + // @attribute + // @returns Element(Number) + // @description + // How many virtual processors are available to the server. + // (In general, Minecraft only uses one, unfortunately.) + // --> + if (attribute.startsWith("available_processors")) { + event.setReplaced(new Element(Runtime.getRuntime().availableProcessors()) + .getAttribute(attribute.fulfill(1))); + } + // <--[tag] // @attribute // @returns Element(Number)