Extension data updating to login listeners

This commit is contained in:
Rsl1122 2019-03-20 15:55:48 +02:00
parent f62140d6ca
commit da33ec0b9e
8 changed files with 63 additions and 27 deletions

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.transactions.events.*; import com.djrapitops.plan.db.access.transactions.events.*;
import com.djrapitops.plan.extension.ExtensionServiceImplementation;
import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.cache.NicknameCache; import com.djrapitops.plan.system.cache.NicknameCache;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
@ -57,6 +58,7 @@ public class PlayerOnlineListener implements Listener {
private final Processing processing; private final Processing processing;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final NicknameCache nicknameCache; private final NicknameCache nicknameCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
@ -70,6 +72,7 @@ public class PlayerOnlineListener implements Listener {
Processing processing, Processing processing,
ServerInfo serverInfo, ServerInfo serverInfo,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, GeolocationCache geolocationCache,
NicknameCache nicknameCache, NicknameCache nicknameCache,
SessionCache sessionCache, SessionCache sessionCache,
@ -81,6 +84,7 @@ public class PlayerOnlineListener implements Listener {
this.processing = processing; this.processing = processing;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.nicknameCache = nicknameCache; this.nicknameCache = nicknameCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
@ -139,11 +143,11 @@ public class PlayerOnlineListener implements Listener {
private void actOnJoinEvent(PlayerJoinEvent event) { private void actOnJoinEvent(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
UUID serverUUID = serverInfo.getServerUUID(); UUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
AFKListener.AFK_TRACKER.performedAction(uuid, time); AFKListener.AFK_TRACKER.performedAction(playerUUID, time);
String world = player.getWorld().getName(); String world = player.getWorld().getName();
String gm = player.getGameMode().name(); String gm = player.getGameMode().name();
@ -159,20 +163,21 @@ public class PlayerOnlineListener implements Listener {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) { if (gatheringGeolocations) {
database.executeTransaction( database.executeTransaction(
new GeoInfoStoreTransaction(uuid, address, time, geolocationCache::getCountry) new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
); );
} }
database.executeTransaction(new PlayerServerRegisterTransaction(uuid, player::getFirstPlayed, playerName, serverUUID)); database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID));
sessionCache.cacheSession(uuid, new Session(uuid, serverUUID, time, world, gm)) sessionCache.cacheSession(playerUUID, new Session(playerUUID, serverUUID, time, world, gm))
.ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession))); .ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
database.executeTransaction(new NicknameStoreTransaction( database.executeTransaction(new NicknameStoreTransaction(
uuid, new Nickname(displayName, time, serverUUID), playerUUID, new Nickname(displayName, time, serverUUID),
(playerUUID, name) -> name.equals(nicknameCache.getDisplayName(playerUUID)) (uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid))
)); ));
processing.submitNonCritical(processors.info().playerPageUpdateProcessor(uuid)); processing.submitNonCritical(processors.info().playerPageUpdateProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName));
} }

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction;
import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction; import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction;
import com.djrapitops.plan.extension.ExtensionServiceImplementation;
import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
@ -54,6 +55,7 @@ public class PlayerOnlineListener implements Listener {
private final Processors processors; private final Processors processors;
private final Processing processing; private final Processing processing;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -65,6 +67,7 @@ public class PlayerOnlineListener implements Listener {
Processors processors, Processors processors,
Processing processing, Processing processing,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, GeolocationCache geolocationCache,
SessionCache sessionCache, SessionCache sessionCache,
ServerInfo serverInfo, ServerInfo serverInfo,
@ -74,6 +77,7 @@ public class PlayerOnlineListener implements Listener {
this.processors = processors; this.processors = processors;
this.processing = processing; this.processing = processing;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -85,7 +89,7 @@ public class PlayerOnlineListener implements Listener {
try { try {
ProxiedPlayer player = event.getPlayer(); ProxiedPlayer player = event.getPlayer();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
String name = player.getName(); String playerName = player.getName();
InetAddress address = player.getAddress().getAddress(); InetAddress address = player.getAddress().getAddress();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
@ -99,8 +103,9 @@ public class PlayerOnlineListener implements Listener {
); );
} }
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, name)); database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
processing.submit(processors.info().playerPageUpdateProcessor(playerUUID)); processing.submit(processors.info().playerPageUpdateProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName));
ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID()));
} catch (Exception e) { } catch (Exception e) {
errorHandler.log(L.WARN, this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);

View File

@ -1,6 +1,6 @@
dependencies { dependencies {
compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion" compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion"
compile project(path: ":api") compile project(path: ":api", configuration: 'shadow')
compile project(path: ":extensions", configuration: 'shadow') compile project(path: ":extensions", configuration: 'shadow')
compile "com.djrapitops:PlanPluginBridge:$planPluginBridgeVersion" compile "com.djrapitops:PlanPluginBridge:$planPluginBridgeVersion"
compile "org.apache.httpcomponents:httpclient:$httpClientVersion" compile "org.apache.httpcomponents:httpclient:$httpClientVersion"

View File

@ -1,3 +1,19 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.extension.implementation; package com.djrapitops.plan.extension.implementation;
import com.djrapitops.extension.AdvancedAchievementsExtensionFactory; import com.djrapitops.extension.AdvancedAchievementsExtensionFactory;

View File

@ -35,7 +35,7 @@ public class SpongeListenerSystem extends ListenerSystem {
private final SpongeCommandListener commandListener; private final SpongeCommandListener commandListener;
private final SpongeDeathListener deathListener; private final SpongeDeathListener deathListener;
private final SpongeGMChangeListener gmChangeListener; private final SpongeGMChangeListener gmChangeListener;
private final SpongePlayerListener playerListener; private final PlayerOnlineListener playerListener;
private final SpongeWorldChangeListener worldChangeListener; private final SpongeWorldChangeListener worldChangeListener;
private final SpongeServerShutdownSave spongeServerShutdownSave; private final SpongeServerShutdownSave spongeServerShutdownSave;
@ -47,7 +47,7 @@ public class SpongeListenerSystem extends ListenerSystem {
SpongeCommandListener commandListener, SpongeCommandListener commandListener,
SpongeDeathListener deathListener, SpongeDeathListener deathListener,
SpongeGMChangeListener gmChangeListener, SpongeGMChangeListener gmChangeListener,
SpongePlayerListener playerListener, PlayerOnlineListener playerListener,
SpongeWorldChangeListener worldChangeListener, SpongeWorldChangeListener worldChangeListener,
SpongeServerShutdownSave spongeServerShutdownSave SpongeServerShutdownSave spongeServerShutdownSave
) { ) {

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.transactions.events.*; import com.djrapitops.plan.db.access.transactions.events.*;
import com.djrapitops.plan.extension.ExtensionServiceImplementation;
import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.cache.NicknameCache; import com.djrapitops.plan.system.cache.NicknameCache;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
@ -54,13 +55,14 @@ import java.util.UUID;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class SpongePlayerListener { public class PlayerOnlineListener {
private final PlanConfig config; private final PlanConfig config;
private final Processors processors; private final Processors processors;
private final Processing processing; private final Processing processing;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final NicknameCache nicknameCache; private final NicknameCache nicknameCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
@ -68,12 +70,13 @@ public class SpongePlayerListener {
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@Inject @Inject
public SpongePlayerListener( public PlayerOnlineListener(
PlanConfig config, PlanConfig config,
Processors processors, Processors processors,
Processing processing, Processing processing,
ServerInfo serverInfo, ServerInfo serverInfo,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, GeolocationCache geolocationCache,
NicknameCache nicknameCache, NicknameCache nicknameCache,
SessionCache sessionCache, SessionCache sessionCache,
@ -85,6 +88,7 @@ public class SpongePlayerListener {
this.processing = processing; this.processing = processing;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.nicknameCache = nicknameCache; this.nicknameCache = nicknameCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
@ -142,11 +146,11 @@ public class SpongePlayerListener {
private void actOnJoinEvent(ClientConnectionEvent.Join event) { private void actOnJoinEvent(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity(); Player player = event.getTargetEntity();
UUID uuid = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
UUID serverUUID = serverInfo.getServerUUID(); UUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
SpongeAFKListener.AFK_TRACKER.performedAction(uuid, time); SpongeAFKListener.AFK_TRACKER.performedAction(playerUUID, time);
String world = player.getWorld().getName(); String world = player.getWorld().getName();
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE); Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
@ -163,20 +167,21 @@ public class SpongePlayerListener {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) { if (gatheringGeolocations) {
database.executeTransaction( database.executeTransaction(
new GeoInfoStoreTransaction(uuid, address, time, geolocationCache::getCountry) new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
); );
} }
database.executeTransaction(new PlayerServerRegisterTransaction(uuid, () -> time, playerName, serverUUID)); database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID));
sessionCache.cacheSession(uuid, new Session(uuid, serverUUID, time, world, gm)) sessionCache.cacheSession(playerUUID, new Session(playerUUID, serverUUID, time, world, gm))
.ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession))); .ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
database.executeTransaction(new NicknameStoreTransaction( database.executeTransaction(new NicknameStoreTransaction(
uuid, new Nickname(displayName, time, serverUUID), playerUUID, new Nickname(displayName, time, serverUUID),
(playerUUID, name) -> name.equals(nicknameCache.getDisplayName(playerUUID)) (uuid, name) -> name.equals(nicknameCache.getDisplayName(uuid))
)); ));
processing.submitNonCritical(processors.info().playerPageUpdateProcessor(uuid)); processing.submitNonCritical(processors.info().playerPageUpdateProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName));
} }
@Listener(order = Order.POST) @Listener(order = Order.POST)

View File

@ -37,10 +37,10 @@ import java.util.UUID;
/** /**
* Listener that keeps track of actions that are not considered being AFK. * Listener that keeps track of actions that are not considered being AFK.
* <p> * <p>
* Additional Listener calls in SpongePlayerListener to avoid having HIGHEST priority listeners. * Additional Listener calls in PlayerOnlineListener to avoid having HIGHEST priority listeners.
* *
* @author Rsl1122 * @author Rsl1122
* @see SpongePlayerListener * @see PlayerOnlineListener
*/ */
public class SpongeAFKListener { public class SpongeAFKListener {

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.db.access.transactions.events.GeoInfoStoreTransaction;
import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction; import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction;
import com.djrapitops.plan.extension.ExtensionServiceImplementation;
import com.djrapitops.plan.system.cache.GeolocationCache; import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
@ -57,6 +58,7 @@ public class PlayerOnlineListener {
private final Processors processors; private final Processors processors;
private final Processing processing; private final Processing processing;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ExtensionServiceImplementation extensionService;
private final GeolocationCache geolocationCache; private final GeolocationCache geolocationCache;
private final SessionCache sessionCache; private final SessionCache sessionCache;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@ -68,6 +70,7 @@ public class PlayerOnlineListener {
Processing processing, Processing processing,
Processors processors, Processors processors,
DBSystem dbSystem, DBSystem dbSystem,
ExtensionServiceImplementation extensionService,
GeolocationCache geolocationCache, GeolocationCache geolocationCache,
SessionCache sessionCache, SessionCache sessionCache,
ServerInfo serverInfo, ServerInfo serverInfo,
@ -77,6 +80,7 @@ public class PlayerOnlineListener {
this.processing = processing; this.processing = processing;
this.processors = processors; this.processors = processors;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.extensionService = extensionService;
this.geolocationCache = geolocationCache; this.geolocationCache = geolocationCache;
this.sessionCache = sessionCache; this.sessionCache = sessionCache;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
@ -88,7 +92,7 @@ public class PlayerOnlineListener {
try { try {
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
String name = player.getUsername(); String playerName = player.getUsername();
InetAddress address = player.getRemoteAddress().getAddress(); InetAddress address = player.getRemoteAddress().getAddress();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
@ -103,8 +107,9 @@ public class PlayerOnlineListener {
); );
} }
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, name)); database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
processing.submit(processors.info().playerPageUpdateProcessor(playerUUID)); processing.submit(processors.info().playerPageUpdateProcessor(playerUUID));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName));
ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID()));
} catch (Exception e) { } catch (Exception e) {
errorHandler.log(L.WARN, this.getClass(), e); errorHandler.log(L.WARN, this.getClass(), e);