@Override
public void setup(@Nonnull TerminableConsumer consumer) {
Events.subscribe(PlayerLoginEvent.class, EventPriority.MONITOR)
.filter(e -> e.getResult() == PlayerLoginEvent.Result.ALLOWED)
.handler(e -> {
plugin.getDataManager().logPlayer(e.getPlayer().getUniqueId(), e.getPlayer().getName());
Metadata.provideForPlayer(e.getPlayer()).put(NetworkAnalytics.CONNECTION_TIME_SECONDS, (System.currentTimeMillis() / 1000L));
})
.bindWith(consumer);
Events.subscribe(PlayerJoinEvent.class, EventPriority.MONITOR)
.handler(e -> {
ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(e.getPlayer());
if (protocolVersion != null) {
Metadata.provideForPlayer(e.getPlayer()).put(NetworkAnalytics.PROTOCOL_VERSION, protocolVersion);
}
})
.bindWith(consumer);
Events.subscribe(PlayerQuitEvent.class)
.handler(e -> {
Long loginTime = Metadata.provideForPlayer(e.getPlayer()).getOrNull(NetworkAnalytics.CONNECTION_TIME_SECONDS);
long now = System.currentTimeMillis() / 1000L;
if (loginTime != null) {
long diff = now - loginTime;
int mins = (int) TimeUnit.SECONDS.toMinutes(diff);
if (mins > 0) {
plugin.getDataManager().incrementPlayerMinutesPlayed(e.getPlayer().getUniqueId(), mins);
}
}
})
.bindWith(consumer);
}
AnalyticsListener.java 文件源码
java
阅读 41
收藏 0
点赞 0
评论 0
项目:NetworkAnalytics
作者:
评论列表
文章目录