Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Bugfix -> Analytics now are better
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Jul 9, 2023
1 parent e8518d4 commit 5d0a6d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import de.cubeattack.neoprotect.core.model.Gameshield;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;

public class NeoProtectExecutor {

Expand Down Expand Up @@ -108,8 +110,37 @@ private void command(ExecutorBuilder executorBuilder) {
}

private void analytics(){
JSONObject analytics = instance.getCore().getRestAPI().getAnalytics();
analytics.keySet().forEach(k -> instance.sendMessage(sender, k + ": " + analytics.get(k).toString().replace("onlinePlayers", "online players")));
instance.sendMessage(sender, "§7§l-------- §bAnalytics §7§l--------");
JSONObject analytics = instance.getCore().getRestAPI().getAnalytics();
instance.getCore().getRestAPI().getAnalytics().keySet().forEach(ak -> {
if(ak.equals("bandwidth")){
return;
}

if(ak.equals("traffic")){
instance.sendMessage(sender, ak.replace("traffic", "bandwidth") + ": " +
new DecimalFormat("#.####").format((float) analytics.getInt(ak) * 8 / (1000 * 1000)) + " mbit/s");
JSONObject traffic = instance.getCore().getRestAPI().getTraffic();

AtomicReference<String> trafficUsed = new AtomicReference<>();
AtomicReference<String> trafficAvailable = new AtomicReference<>();
traffic.keySet().forEach(bk -> {
if(bk.equals("used")) {
trafficUsed.set(traffic.getFloat(bk) / (1000 * 1000 * 1000) + " gb");
}
if(bk.equals("available")) {
trafficAvailable.set(String.valueOf(traffic.getLong(bk)).equals("999999999") ? "unlimited" : traffic.getLong(bk) + " gb");
}
});
instance.sendMessage(sender,"bandwidth used" + ": " + trafficUsed.get() + "/" + trafficAvailable.get());

return;
}

instance.sendMessage(sender, ak
.replace("onlinePlayers", "online players")
.replace("cps", "connections/s") + ": " + analytics.get(ak));
});
}

private void setup(Object sender){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public JSONObject getAnalytics() {
return rest.request(RequestType.GET_GAMESHIELD_LASTSTATS, null, Config.getGameShieldID()).getResponseBodyObject();
}

public JSONObject getTraffic() {
return rest.request(RequestType.GET_GAMESHIELD_BANDWIDTH, null, Config.getGameShieldID()).getResponseBodyObject();
}

public void testCredentials(){

if(isAPIInvalid(Config.getAPIKey())){
Expand Down

0 comments on commit 5d0a6d2

Please sign in to comment.