Skip to content

Commit

Permalink
Add runtime tags (server.ram_*, server.available_processors)
Browse files Browse the repository at this point in the history
Yay for server details!
  • Loading branch information
mcmonkey4eva committed Jan 16, 2015
1 parent d43c384 commit 0344b69
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java
Expand Up @@ -238,6 +238,51 @@ public void serverTag(ReplaceableTagEvent event) {
.getAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.ram_allocated>
// @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 <server.ram_max>
// @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 <server.ram_free>
// @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 <server.available_processors>
// @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 <server.current_time_millis>
// @returns Element(Number)
Expand Down

0 comments on commit 0344b69

Please sign in to comment.