use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class DataValueGatherer method storeNumber.
private void storeNumber(Parameters parameters, Conditions conditions, NumberDataValue data) {
ProviderInformation information = data.getInformation();
Long value = getValue(conditions, data, information);
if (value == null)
return;
Database db = dbSystem.getDatabase();
db.executeTransaction(new StoreIconTransaction(information.getIcon()));
db.executeTransaction(new StoreProviderTransaction(information, parameters));
db.executeTransaction(new StoreServerNumberResultTransaction(information, parameters, value));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class DataValueGatherer method storePlayerTable.
private void storePlayerTable(Parameters parameters, Conditions conditions, TableDataValue data) {
ProviderInformation information = data.getInformation();
Table value = getValue(conditions, data, information);
if (value == null)
return;
Database db = dbSystem.getDatabase();
for (Icon icon : value.getIcons()) {
if (icon != null)
db.executeTransaction(new StoreIconTransaction(icon));
}
db.executeTransaction(new StoreTableProviderTransaction(information, parameters, value));
db.executeTransaction(new StorePlayerTableResultTransaction(information, parameters, value));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class BukkitImporter method processUserData.
private void processUserData() {
List<UserImportData> userImportData = getUserImportData();
if (userImportData == null || userImportData.isEmpty()) {
return;
}
BukkitUserImportRefiner userImportRefiner = new BukkitUserImportRefiner(userImportData);
userImportData = userImportRefiner.refineData();
Database db = dbSystem.getDatabase();
Set<UUID> existingUUIDs = db.query(UserIdentifierQueries.fetchAllPlayerUUIDs());
Set<UUID> existingUserInfoTableUUIDs = db.query(UserIdentifierQueries.fetchPlayerUUIDsOfServer(serverUUID.get()));
Map<UUID, BaseUser> users = new HashMap<>();
List<UserInfo> userInfo = new ArrayList<>();
Map<UUID, List<Nickname>> nickNames = new HashMap<>();
List<FinishedSession> sessions = new ArrayList<>();
Map<UUID, List<GeoInfo>> geoInfo = new HashMap<>();
userImportData.parallelStream().forEach(data -> {
UUID uuid = data.getUuid();
if (!existingUUIDs.contains(uuid)) {
users.put(uuid, toBaseUser(data));
}
if (!existingUserInfoTableUUIDs.contains(uuid)) {
userInfo.add(toUserInfo(data));
}
nickNames.put(uuid, data.getNicknames());
geoInfo.put(uuid, convertGeoInfo(data));
sessions.add(toSession(data));
});
db.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(LargeStoreQueries.storeAllCommonUserInformation(users.values()));
execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
Map<ServerUUID, List<UserInfo>> userInformation = Collections.singletonMap(serverUUID.get(), userInfo);
execute(LargeStoreQueries.storePerServerUserInformation(userInformation));
execute(LargeStoreQueries.storeAllNicknameData(Collections.singletonMap(serverUUID.get(), nickNames)));
execute(LargeStoreQueries.storeAllGeoInformation(geoInfo));
}
});
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnLogin.
private void actOnLogin(PostLoginEvent event) {
ProxiedPlayer player = event.getPlayer();
UUID playerUUID = player.getUniqueId();
String playerName = player.getName();
InetAddress address = player.getAddress().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.storage.database.Database in project Plan by plan-player-analytics.
the class JSONFactory method networkSessionsAsJSONMap.
public List<Map<String, Object>> networkSessionsAsJSONMap() {
Database db = dbSystem.getDatabase();
Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessions(perPageLimit));
// Add online sessions
if (serverInfo.getServer().isProxy()) {
addActiveSessions(sessions);
sessions.sort(new SessionStartComparator());
while (true) {
int size = sessions.size();
if (size <= perPageLimit)
break;
// Remove last until it fits.
sessions.remove(size - 1);
}
}
List<Map<String, Object>> sessionMaps = new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
// Add network_server property so that sessions have a server page link
sessionMaps.forEach(map -> map.put("network_server", map.get("server_name")));
return sessionMaps;
}
Aggregations