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

View File

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