Adjust violation history info to include n, av., max.

This commit is contained in:
asofold 2012-09-15 17:23:47 +02:00
parent dcf7bacfa5
commit 2e9ae3aa83
2 changed files with 24 additions and 9 deletions

View File

@ -55,8 +55,15 @@ public class ViolationHistory {
/** The check. */
public final String check;
/** The VL. */
public double VL;
/** The sum of violation levels added. */
public double sumVL;
/** Number of violations. */
public int nVL;
/** Maximal violation level added. */
public double maxVL;
/** The last VL time. */
public long time;
@ -71,7 +78,9 @@ public class ViolationHistory {
*/
public ViolationLevel(final String check, final double VL) {
this.check = check;
this.VL = VL;
this.sumVL = VL;
this.nVL = 1;
this.maxVL = VL;
time = System.currentTimeMillis();
}
@ -82,7 +91,9 @@ public class ViolationHistory {
* the vL
*/
public void add(final double VL) {
this.VL += VL;
this.sumVL += VL;
this.nVL ++;
this.maxVL = Math.max(maxVL, VL);
time = System.currentTimeMillis();
}

View File

@ -5,6 +5,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -53,14 +54,17 @@ public class InfoCommand extends NCPCommand {
final ViolationLevel[] violations = history.getViolationLevels();
if (violations.length > 0) {
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations...");
final String c = (sender instanceof Player) ? ChatColor.GRAY.toString() : "";
for (final ViolationLevel violationLevel : violations) {
final long time = violationLevel.time;
final String[] parts = violationLevel.check.split("\\.");
final String check = parts[parts.length - 1];
final String parent = parts[parts.length - 2];
final double VL = Math.round(violationLevel.VL);
sender.sendMessage(TAG + "[" + dateFormat.format(new Date(time)) + "] (" + parent + ".)" + check
+ " VL " + VL);
final String check = parts[parts.length - 1].toLowerCase();
final String parent = parts[parts.length - 2].toLowerCase();
final long sumVL = Math.round(violationLevel.sumVL);
final long maxVL = Math.round(violationLevel.maxVL);
final long avVl = Math.round(violationLevel.sumVL / (double) violationLevel.nVL);
sender.sendMessage(TAG + "[" + dateFormat.format(new Date(time)) + "] " + parent + "." + check
+ " VL " + sumVL + c + " (n" + violationLevel.nVL + "a" + avVl +"m" + maxVL +")");
}
} else
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations... nothing to display.");