96 lines
3.8 KiB
Java
96 lines
3.8 KiB
Java
package me.konsolas.aac.analysis;
|
|
|
|
import java.time.Instant;
|
|
import java.time.ZoneId;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.FormatStyle;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map.Entry;
|
|
import java.util.UUID;
|
|
import me.konsolas.aac.AAC;
|
|
import net.md_5.bungee.api.ChatColor;
|
|
import net.md_5.bungee.api.chat.BaseComponent;
|
|
import net.md_5.bungee.api.chat.HoverEvent;
|
|
import net.md_5.bungee.api.chat.HoverEvent.Action;
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
public class PlayerAnalysisReport {
|
|
|
|
public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withZone(ZoneId.systemDefault()).withLocale(Locale.UK);
|
|
|
|
private static final String PLUGIN_VERSION = "AAC " + AAC.class.getPackage().getImplementationVersion();
|
|
|
|
private final String playerName;
|
|
|
|
private final UUID playerId;
|
|
|
|
private final RiskLevel riskLevel;
|
|
|
|
private final Instant generatedAt;
|
|
|
|
private final double score;
|
|
|
|
private final List<FeatureResult> features;
|
|
|
|
public PlayerAnalysisReport(OfflinePlayer offlinePlayer, RiskLevel riskLevel, Instant generatedAt, double score, List features) {
|
|
this.playerName = offlinePlayer.getName();
|
|
this.playerId = offlinePlayer.getUniqueId();
|
|
this.riskLevel = riskLevel;
|
|
this.generatedAt = generatedAt;
|
|
this.score = score;
|
|
this.features = features;
|
|
}
|
|
|
|
public RiskLevel getRiskLevel() {
|
|
return this.riskLevel;
|
|
}
|
|
|
|
public Instant getGeneratedAt() {
|
|
return this.generatedAt;
|
|
}
|
|
|
|
public double getScore() {
|
|
return this.score;
|
|
}
|
|
|
|
public List<FeatureResult> getFeatures() {
|
|
return this.features;
|
|
}
|
|
|
|
public List<BaseComponent> toChatComponents() {
|
|
ArrayList values = new ArrayList();
|
|
TextComponent textComponent = new TextComponent(" AAC Player Analysis of " + this.playerName + " at ");
|
|
TextComponent textComponent2 = new TextComponent(DATE_FORMAT.format(this.generatedAt));
|
|
textComponent2.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new TextComponent[] { new TextComponent(DATE_FORMAT.getZone().getId()) }));
|
|
textComponent.addExtra(textComponent2);
|
|
TextComponent textComponent3 = new TextComponent(" Scoring (" + Math.round(this.score) + ") [" + this.features.size() + " features]");
|
|
textComponent3.setColor(ChatColor.DARK_AQUA);
|
|
values.add(textComponent);
|
|
values.add(textComponent3);
|
|
for (FeatureResult result : this.features) {
|
|
TextComponent textComponent4 = new TextComponent(" - ");
|
|
TextComponent textComponent5 = new TextComponent(result.getDescription());
|
|
result.getRiskLevel().updateBaseComponent(textComponent5);
|
|
TextComponent[] textComponents = new TextComponent[result.getDetails().size()];
|
|
int value = 0;
|
|
for (Entry entry : (Iterable<Entry>) (Iterable<?>) (result.getDetails().entrySet())) {
|
|
TextComponent textComponent6 = new TextComponent((String) entry.getKey() + ": ");
|
|
TextComponent textComponent7 = new TextComponent((String) entry.getValue() + "\n");
|
|
textComponent7.setColor(ChatColor.GRAY);
|
|
textComponent6.addExtra(textComponent7);
|
|
textComponents[value++] = textComponent6;
|
|
}
|
|
textComponent5.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, textComponents));
|
|
textComponent4.addExtra(textComponent5);
|
|
values.add(textComponent4);
|
|
}
|
|
TextComponent textComponent8 = new TextComponent("Generated by " + PLUGIN_VERSION);
|
|
textComponent8.setColor(ChatColor.DARK_GRAY);
|
|
values.add(textComponent8);
|
|
return values;
|
|
}
|
|
}
|