use of com.djrapitops.plan.gathering.domain.ActiveSession in project Plan by plan-player-analytics.
the class WorldAliasSettings method getLongestWorldPlayed.
public String getLongestWorldPlayed(ActiveSession session) {
Optional<WorldTimes> foundWorldTimes = session.getExtraData(WorldTimes.class);
if (!foundWorldTimes.isPresent()) {
return locale.get().getString(HtmlLang.UNIT_NO_DATA);
}
WorldTimes worldTimes = foundWorldTimes.orElseGet(WorldTimes::new);
return worldTimes.getCurrentWorld().map(currentWorld -> "Current: " + getAlias(currentWorld).orElse(currentWorld)).orElse("Current: " + locale.get().getString(GenericLang.UNAVAILABLE));
}
use of com.djrapitops.plan.gathering.domain.ActiveSession in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnServerSwitch.
public void actOnServerSwitch(ServerConnectedEvent event) {
Player player = event.getPlayer();
String playerName = player.getUsername();
UUID playerUUID = player.getUniqueId();
long time = System.currentTimeMillis();
// Replaces the current session in the cache.
ActiveSession session = new ActiveSession(playerUUID, serverInfo.getServerUUID(), time, null, null);
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
session.getExtraData().put(ServerName.class, new ServerName("Proxy Server"));
sessionCache.cacheSession(playerUUID, session);
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
use of com.djrapitops.plan.gathering.domain.ActiveSession in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnLogin.
public void actOnLogin(PostLoginEvent event) {
Player player = event.getPlayer();
UUID playerUUID = player.getUniqueId();
String playerName = player.getUsername();
InetAddress address = player.getRemoteAddress().getAddress();
long time = System.currentTimeMillis();
ActiveSession session = new ActiveSession(playerUUID, serverInfo.getServerUUID(), time, null, null);
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
session.getExtraData().put(ServerName.class, new ServerName("Proxy Server"));
sessionCache.cacheSession(playerUUID, session);
Database database = dbSystem.getDatabase();
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
}
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
use of com.djrapitops.plan.gathering.domain.ActiveSession in project Plan by plan-player-analytics.
the class DeathEventListener method onDeath.
@EventHandler(priority = EventPriority.MONITOR)
public void onDeath(EntityDeathEvent event) {
long time = System.currentTimeMillis();
LivingEntity dead = event.getEntity();
if (dead instanceof Player) {
// Process Death
SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(ActiveSession::addDeath);
}
try {
Optional<Player> foundKiller = findKiller(dead);
if (!foundKiller.isPresent()) {
return;
}
Player killer = foundKiller.get();
Runnable processor = dead instanceof Player ? new PlayerKillProcessor(getKiller(killer), getVictim((Player) dead), serverInfo.getServerIdentifier(), findWeapon(dead), time) : new MobKillProcessor(killer.getUniqueId());
processing.submitCritical(processor);
} catch (Exception e) {
errorLogger.error(e, ErrorContext.builder().related(event, dead).build());
}
}
use of com.djrapitops.plan.gathering.domain.ActiveSession in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnJoinEvent.
private void actOnJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID playerUUID = player.getUniqueId();
ServerUUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis();
BukkitAFKListener.afkTracker.performedAction(playerUUID, time);
String world = player.getWorld().getName();
String gm = Optional.ofNullable(player.getGameMode()).map(gameMode -> gameMode.name()).orElse("Unknown");
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetAddress address = player.getAddress().getAddress();
Supplier<String> getHostName = () -> getHostname(player);
String playerName = player.getName();
String displayName = player.getDisplayName();
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID, getHostName));
database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));
ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
database.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
Aggregations