use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ActiveCookieStoreTest method createActiveCookieStore.
@BeforeEach
void createActiveCookieStore() {
DBSystem dbSystem = Mockito.mock(DBSystem.class);
Database db = Mockito.mock(Database.class);
when(dbSystem.getDatabase()).thenReturn(db);
underTest = new ActiveCookieStore(Mockito.mock(ActiveCookieExpiryCleanupTask.class), Mockito.mock(PlanConfig.class), dbSystem, Mockito.mock(Processing.class));
user = new User(TestConstants.PLAYER_ONE_NAME, "console", null, PassEncryptUtil.createHash("testPass"), 0, WebUser.getPermissionsForLevel(0));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ExtensionDisableOnGameServerTask method checkAndDisableProxyExtension.
private void checkAndDisableProxyExtension(ServerUUID proxyUUID, String pluginName) {
Database db = dbSystem.getDatabase();
ExtensionSettings extensionSettings = config.getExtensionSettings();
boolean isInstalledOnProxy = db.query(new HasExtensionDataForPluginQuery(pluginName, proxyUUID));
if (isInstalledOnProxy && extensionSettings.isEnabled(pluginName)) {
extensionSettings.setEnabled(pluginName, false);
logger.info("Set " + pluginName + " Extension as disabled in config since it is already enabled on the proxy server. This is to avoid duplicate data.");
}
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ExtensionDisableOnGameServerTask method checkAndDisableProxyExtensions.
private void checkAndDisableProxyExtensions(String pluginName) {
Database db = dbSystem.getDatabase();
db.query(ServerQueries.fetchProxyServerInformation()).map(Server::getUuid).ifPresent(proxyUUID -> checkAndDisableProxyExtension(proxyUUID, pluginName));
}
use of com.djrapitops.plan.storage.database.Database 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();
NukkitAFKListener.afkTracker.performedAction(playerUUID, time);
String world = player.getLevel().getName();
String gm = GMTimes.magicNumberToGMName(player.getGamemode());
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetAddress address = player.getSocketAddress().getAddress();
Supplier<String> getHostName = () -> null;
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));
}
long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate, playerName, serverUUID, getHostName));
dbSystem.getDatabase().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));
}
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnJoinEvent.
private void actOnJoinEvent(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
UUID playerUUID = player.getUniqueId();
ServerUUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis();
SpongeAFKListener.afkTracker.performedAction(playerUUID, time);
String world = player.getWorld().getName();
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
String gm = gameMode.map(mode -> mode.getName().toUpperCase()).orElse("ADVENTURE");
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetAddress address = player.getConnection().getAddress().getAddress();
Supplier<String> getHostName = () -> player.getConnection().getVirtualHost().getHostString();
String playerName = player.getName();
String displayName = player.getDisplayNameData().displayName().get().toPlain();
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID, getHostName));
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