summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLogan Fick <logaldeveloper@protonmail.com>2017-10-29 20:24:14 -0400
committerLogan Fick <logaldeveloper@protonmail.com>2017-10-29 20:24:14 -0400
commitd70df0deef56907f4cd6f8c329be2bfdf8cfd608 (patch)
treece52d0132c7fb150da6ca86fe468dd1f02608d0c
parent5b3b0fe3ef30d5500c75418fd02b5d14fd04206d (diff)
parent3c7bfa93380074ce4d866196b340cdbe0f294db2 (diff)
Merge pull request #46.
-rw-r--r--app/controllers/statics_controller.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/app/controllers/statics_controller.rb b/app/controllers/statics_controller.rb
index c624c32..aaaf5b4 100644
--- a/app/controllers/statics_controller.rb
+++ b/app/controllers/statics_controller.rb
@@ -17,15 +17,26 @@ class StaticsController < ApplicationController
end
def online
+ @players = []
+ @count = 0
begin
json = JSON.parse(File.read("/etc/minecraft/redstoner/plugins/ModuleLoader/players.json"))
rescue
flash.now[:alert] = "The server is currently offline."
- @players = {}
- @count = 0
else
- @players = json["players"].collect!{ |p| User.find_by(uuid: p["UUID"].tr("-", "")) or User.new(name: p["name"], ign: p["name"], uuid: p["UUID"].tr("-", ""), role: Role.get("normal"), badge: Badge.get("none"), confirmed: true) }.sort_by!(&:role).reverse!
- @count = json["amount"]
+ case json["dataFormat"]
+ when "v1"
+ @players = json["players"].collect!{ |p| User.find_by(uuid: p["UUID"].tr("-", "")) or User.new(name: p["name"], ign: p["name"], uuid: p["UUID"].tr("-", ""), role: Role.get("normal"), badge: Badge.get("none"), confirmed: true) }
+ @count = json["amount"]
+ when "v2"
+ json["players"].reject{|p| !mod? && p["vanished"] == "true"}.each do |p|
+ @players.push(User.find_by(uuid: p["UUID"].tr("-", "")) || User.new(name: p["name"], ign: p["name"], uuid: p["UUID"].tr("-", ""), role: Role.get("normal"), badge: Badge.get("none"), confirmed: true))
+ end
+ @count = @players.count
+ else
+ flash.now[:alert] = "The server is using an incompatible data format. We are aware of this issue and are most likely already working on it."
+ end
+ @players.sort_by!(&:role).reverse!
end
end
end