summaryrefslogtreecommitdiffstats
path: root/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/Statistics.java
blob: 9c83e97d5c2772f40ea5814538975305a330c048 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.earth2me.essentials.anticheat.data;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;


public class Statistics
{
	public enum Id
	{
		BB_DIRECTION("blockbreak.direction"), BB_NOSWING("blockbreak.noswing"),
		BB_REACH("blockbreak.reach"), BP_DIRECTION("blockplace.direction"),
		BP_REACH("blockplace.reach"), CHAT_COLOR("chat.color"),
		CHAT_SPAM("chat.spam"), FI_DIRECTION("fight.direction"),
		FI_NOSWING("fight.noswing"), FI_REACH("fight.reach"),
		FI_SPEED("fight.speed"), INV_DROP("inventory.drop"),
		INV_BOW("inventory.instantbow"), INV_EAT("inventory.instanteat"),
		MOV_RUNNING("moving.running"), MOV_FLYING("moving.flying"),
		MOV_MOREPACKETS("moving.morepackets"), MOV_NOFALL("moving.nofall"),
		MOV_SNEAKING("moving.sneaking"), MOV_SWIMMING("moving.swimming"),
		FI_GODMODE("fight.godmode"), FI_INSTANTHEAL("fight.instantheal");
		private final String name;

		private Id(String name)
		{
			this.name = name;
		}

		public String toString()
		{
			return this.name;
		}
	}
	private final Map<Id, Double> statisticVLs = new HashMap<Id, Double>(Id.values().length);
	private final Map<Id, Integer> statisticFails = new HashMap<Id, Integer>(Id.values().length);

	public Statistics()
	{
		// Initialize statistic values
		for (Id id : Id.values())
		{
			statisticVLs.put(id, 0D);
			statisticFails.put(id, 0);
		}
	}

	public void increment(Id id, double vl)
	{
		Double stored = statisticVLs.get(id);
		if (stored == null)
		{
			stored = 0D;
		}
		statisticVLs.put(id, stored + vl);

		Integer failed = statisticFails.get(id);
		if (failed == null)
		{
			failed = 0;
		}
		statisticFails.put(id, failed + 1);
	}

	public Map<String, Object> get()
	{
		Map<String, Object> map = new TreeMap<String, Object>();

		for (Entry<Id, Double> entry : statisticVLs.entrySet())
		{
			map.put(entry.getKey().toString() + ".vl", entry.getValue().intValue());
		}

		for (Entry<Id, Integer> entry : statisticFails.entrySet())
		{
			map.put(entry.getKey().toString() + ".failed", entry.getValue());
		}

		return map;
	}
}