var scriptName = "Packet counter";
var scriptAuthor = "Soulplexis";
var scriptVersion = 1.0;

script.import("lib/glFunctions.js");
script.import("lib/systemFunctions.js")

function Derp() {
	var Accuracy = value.createList("Interval", ["Low", "Medium", "High"], "High");
    this.getName = function() {
        return "Packets";
    }
    this.getCategory = function() {
        return "Render";   
    }
    this.getDescription = function() {
        return "Shows the amount of packets flowing in the arraylist (module tag).";
    }
	
	var time = 0;
	var aa = 0;
	var packets = 0;
	var started = false;
	this.onEnable = function() {
		started = false;
	}
	this.onPacket = function(event) {
		aa++;
		if(time >= timeamountz) {
			time = 0;
			packets = aa;
			aa = 0;
			started = true;
		}
	}
	var timeamountz = 0;
	this.onUpdate = function() {
		time++;	
		switch(Accuracy.get()) {
			case "High":
			timeamountz = 20;
			break;
			case "Medium":
			timeamountz = 10;
			break;
			case "Low":
			timeamountz = 1;
			break;
		}
	}
	this.onRender2D = function(){
		var mcHeight = getScaledHeight();
        var mcWidth = getScaledWidth();
		mc.fontRendererObj.drawStringWithShadow('Packets: ' + (packets.toString())+ '  ' , 5, mcHeight/2-8, 0xFFFFFF);
	}
	this.addValues = function(henti) {
//		henti.add(Accuracy);
	}
	/* this.getTag = function(){
		if(started == true) {
			if(packets < 250) {
			return packets.toString();
			} else {
				return "§c" + packets.toString();
			}
		} else {
			return "Measuring...";
		}
	} */
	this.addValues = function(ass) {
		ass.add(Accuracy);
	}
}

var derp = new Derp();
var derpClient;

function onEnable() {
    derpClient = moduleManager.registerModule(derp);
}

function onDisable() {
    moduleManager.unregisterModule(derpClient);
}