mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 12:46:04 +01:00
Implement basic stat tracking for traits
This commit is contained in:
parent
c1ae7aa0d3
commit
e2e4b2a0c1
@ -7,7 +7,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -50,12 +49,14 @@ import net.citizensnpcs.api.event.CitizensPreReloadEvent;
|
||||
import net.citizensnpcs.api.event.CitizensReloadEvent;
|
||||
import net.citizensnpcs.api.event.DespawnReason;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCDataStore;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
import net.citizensnpcs.api.npc.SimpleNPCDataStore;
|
||||
import net.citizensnpcs.api.scripting.EventRegistrar;
|
||||
import net.citizensnpcs.api.scripting.ObjectProvider;
|
||||
import net.citizensnpcs.api.scripting.ScriptCompiler;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitFactory;
|
||||
import net.citizensnpcs.api.trait.TraitInfo;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
@ -547,13 +548,21 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
private void startMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this, 2463);
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("total_npcs", new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() {
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("total_npcs", () -> {
|
||||
if (npcRegistry == null)
|
||||
return 0;
|
||||
return Iterables.size(npcRegistry);
|
||||
}));
|
||||
metrics.addCustomChart(new Metrics.AdvancedPie("traits", () -> {
|
||||
Map<String, Integer> res = Maps.newHashMap();
|
||||
for (NPC npc : npcRegistry) {
|
||||
for (Trait trait : npc.getTraits()) {
|
||||
if (traitFactory.trackStats(trait)) {
|
||||
res.put(trait.getName(), res.getOrDefault(trait.getName(), 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}));
|
||||
} catch (Exception e) {
|
||||
Messaging.logTr(Messages.METRICS_ERROR_NOTIFICATION, e.getMessage());
|
||||
|
@ -692,7 +692,6 @@ public class NPCCommands {
|
||||
if (args.hasFlag('t') || temporaryTicks != null) {
|
||||
registry = temporaryRegistry;
|
||||
}
|
||||
|
||||
if (item != null) {
|
||||
ItemStack stack = new ItemStack(Material.STONE, 1);
|
||||
try {
|
||||
|
@ -76,30 +76,31 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
registerTrait(TraitInfo.create(Anchors.class));
|
||||
registerTrait(TraitInfo.create(BoundingBoxTrait.class));
|
||||
registerTrait(TraitInfo.create(ClickRedirectTrait.class));
|
||||
registerTrait(TraitInfo.create(CommandTrait.class));
|
||||
registerTrait(TraitInfo.create(Controllable.class));
|
||||
registerTrait(TraitInfo.create(CommandTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(Controllable.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(CurrentLocation.class));
|
||||
registerTrait(TraitInfo.create(DropsTrait.class));
|
||||
registerTrait(TraitInfo.create(DropsTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(EnderCrystalTrait.class));
|
||||
registerTrait(TraitInfo.create(EndermanTrait.class));
|
||||
registerTrait(TraitInfo.create(Equipment.class));
|
||||
registerTrait(TraitInfo.create(FollowTrait.class));
|
||||
registerTrait(TraitInfo.create(FollowTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(GameModeTrait.class));
|
||||
registerTrait(TraitInfo.create(Gravity.class));
|
||||
registerTrait(TraitInfo.create(HomeTrait.class));
|
||||
registerTrait(TraitInfo.create(HomeTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(HorseModifiers.class));
|
||||
registerTrait(TraitInfo.create(HologramTrait.class));
|
||||
registerTrait(TraitInfo.create(Inventory.class));
|
||||
registerTrait(TraitInfo.create(LookClose.class));
|
||||
registerTrait(TraitInfo.create(PaintingTrait.class));
|
||||
registerTrait(TraitInfo.create(MirrorTrait.class));
|
||||
registerTrait(TraitInfo.create(MirrorTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(MountTrait.class));
|
||||
registerTrait(TraitInfo.create(MobType.class).asDefaultTrait());
|
||||
registerTrait(TraitInfo.create(OcelotModifiers.class));
|
||||
registerTrait(TraitInfo.create(Owner.class));
|
||||
registerTrait(TraitInfo.create(PacketNPC.class));
|
||||
registerTrait(TraitInfo.create(PausePathfindingTrait.class));
|
||||
registerTrait(TraitInfo.create(PlayerFilter.class).withSupplier(() -> new PlayerFilter((p, e) -> {
|
||||
registerTrait(TraitInfo.create(PacketNPC.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(PausePathfindingTrait.class).optInToStats());
|
||||
registerTrait(
|
||||
TraitInfo.create(PlayerFilter.class).optInToStats().withSupplier(() -> new PlayerFilter((p, e) -> {
|
||||
EntityPacketTracker ept = NMS.getPacketTracker(e);
|
||||
if (ept != null) {
|
||||
ept.unlink(p);
|
||||
@ -110,14 +111,14 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
ept.link(p);
|
||||
}
|
||||
})));
|
||||
registerTrait(TraitInfo.create(Poses.class));
|
||||
registerTrait(TraitInfo.create(Poses.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(Powered.class));
|
||||
registerTrait(TraitInfo.create(RabbitType.class));
|
||||
registerTrait(TraitInfo.create(RotationTrait.class));
|
||||
registerTrait(TraitInfo.create(Saddle.class));
|
||||
registerTrait(TraitInfo.create(ScoreboardTrait.class));
|
||||
registerTrait(TraitInfo.create(ScriptTrait.class));
|
||||
registerTrait(TraitInfo.create(SitTrait.class));
|
||||
registerTrait(TraitInfo.create(ScriptTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(SitTrait.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(SleepTrait.class));
|
||||
registerTrait(TraitInfo.create(SheepTrait.class));
|
||||
registerTrait(TraitInfo.create(SkinLayers.class));
|
||||
@ -126,7 +127,7 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
registerTrait(TraitInfo.create(SlimeSize.class));
|
||||
registerTrait(TraitInfo.create(Spawned.class));
|
||||
registerTrait(TraitInfo.create(Text.class));
|
||||
registerTrait(TraitInfo.create(Waypoints.class));
|
||||
registerTrait(TraitInfo.create(Waypoints.class).optInToStats());
|
||||
registerTrait(TraitInfo.create(WitherTrait.class));
|
||||
registerTrait(TraitInfo.create(WoolColor.class));
|
||||
registerTrait(TraitInfo.create(WolfModifiers.class));
|
||||
@ -192,4 +193,8 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
defaultTraits.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean trackStats(Trait trait) {
|
||||
return registered.get(trait.getName()).trackStats();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user