use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class TestData method storeServers.
public static Transaction storeServers() {
return new Transaction() {
@Override
protected void performOperations() {
executeOther(new StoreServerInformationTransaction(new Server(serverUUID, "Server 1", "", TestConstants.VERSION)));
executeOther(new StoreServerInformationTransaction(new Server(server2UUID, "Server 2", "", TestConstants.VERSION)));
for (String worldName : serverWorldNames) {
executeOther(new WorldNameStoreTransaction(serverUUID, worldName));
}
for (String worldName : server2WorldNames) {
executeOther(new WorldNameStoreTransaction(server2UUID, worldName));
}
}
};
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class ServerQueries method fetchServerMatchingIdentifier.
public static Query<Optional<Server>> fetchServerMatchingIdentifier(String identifier) {
String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + "(LOWER(" + ServerTable.SERVER_UUID + ") LIKE LOWER(?)" + OR + "LOWER(" + ServerTable.NAME + ") LIKE LOWER(?)" + OR + ServerTable.ID + "=?" + OR + ServerTable.ID + "=?)" + AND + ServerTable.INSTALLED + "=?" + LIMIT + '1';
return new QueryStatement<Optional<Server>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, identifier);
statement.setString(2, identifier);
statement.setInt(3, NumberUtils.isParsable(identifier) ? Integer.parseInt(identifier) : -1);
String id = identifier.startsWith("Server ") ? identifier.substring(7) : identifier;
statement.setInt(4, NumberUtils.isParsable(id) ? Integer.parseInt(id) : -1);
statement.setBoolean(5, true);
}
@Override
public Optional<Server> processResults(ResultSet set) throws SQLException {
if (set.next()) {
return Optional.of(new Server(set.getInt(ServerTable.ID), ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)), set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY), set.getString(ServerTable.PLAN_VERSION)));
}
return Optional.empty();
}
};
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class SessionQueries method extractDataFromSessionSelectStatement.
private static List<FinishedSession> extractDataFromSessionSelectStatement(ResultSet set) throws SQLException {
// Server UUID - Player UUID - Session Start - Session
Map<ServerUUID, Map<UUID, SortedMap<Long, FinishedSession>>> byServer = new HashMap<>();
// Utilities
String[] gms = GMTimes.getGMKeyArray();
Comparator<DateHolder> mostRecentFirst = new DateHolderRecentComparator();
// Descending order, most recent first.
Comparator<Long> longRecentComparator = (one, two) -> Long.compare(two, one);
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString("server_uuid"));
Map<UUID, SortedMap<Long, FinishedSession>> serverSessions = byServer.computeIfAbsent(serverUUID, Maps::create);
UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
SortedMap<Long, FinishedSession> playerSessions = serverSessions.computeIfAbsent(playerUUID, key -> new TreeMap<>(longRecentComparator));
long sessionStart = set.getLong(SessionsTable.SESSION_START);
// id, uuid, serverUUID, sessionStart, sessionEnd, mobKills, deaths, afkTime
FinishedSession session = playerSessions.getOrDefault(sessionStart, new FinishedSession(playerUUID, serverUUID, sessionStart, set.getLong(SessionsTable.SESSION_END), set.getLong(SessionsTable.AFK_TIME), new DataMap()));
DataMap extraData = session.getExtraData();
extraData.put(FinishedSession.Id.class, new FinishedSession.Id(set.getInt(SessionsTable.ID)));
extraData.put(MobKillCounter.class, new MobKillCounter(set.getInt(SessionsTable.MOB_KILLS)));
extraData.put(DeathCounter.class, new DeathCounter(set.getInt(SessionsTable.DEATHS)));
extraData.put(JoinAddress.class, new JoinAddress(set.getString("join_address")));
Optional<WorldTimes> existingWorldTimes = extraData.get(WorldTimes.class);
Optional<PlayerKills> existingPlayerKills = extraData.get(PlayerKills.class);
WorldTimes worldTimes = existingWorldTimes.orElseGet(WorldTimes::new);
String worldName = set.getString(WorldTable.NAME);
if (!worldTimes.contains(worldName)) {
Map<String, Long> gmMap = new HashMap<>();
gmMap.put(gms[0], set.getLong(WorldTimesTable.SURVIVAL));
gmMap.put(gms[1], set.getLong(WorldTimesTable.CREATIVE));
gmMap.put(gms[2], set.getLong(WorldTimesTable.ADVENTURE));
gmMap.put(gms[3], set.getLong(WorldTimesTable.SPECTATOR));
GMTimes gmTimes = new GMTimes(gmMap);
worldTimes.setGMTimesForWorld(worldName, gmTimes);
}
if (!existingWorldTimes.isPresent())
extraData.put(WorldTimes.class, worldTimes);
ServerName serverName = new ServerName(Server.getIdentifiableName(set.getString("server_name"), set.getInt("server_id")));
extraData.put(ServerName.class, serverName);
PlayerKills playerKills = existingPlayerKills.orElseGet(PlayerKills::new);
String victimName = set.getString("victim_name");
if (victimName != null) {
PlayerKill.Killer killer = new PlayerKill.Killer(UUID.fromString(set.getString(KillsTable.KILLER_UUID)), set.getString("killer_name"));
PlayerKill.Victim victim = new PlayerKill.Victim(UUID.fromString(set.getString(KillsTable.VICTIM_UUID)), victimName);
ServerIdentifier serverIdentifier = new ServerIdentifier(serverUUID, serverName);
String weapon = set.getString(KillsTable.WEAPON);
long date = set.getLong(KillsTable.DATE);
PlayerKill newKill = new PlayerKill(killer, victim, serverIdentifier, weapon, date);
if (!playerKills.contains(newKill)) {
playerKills.add(newKill);
}
}
if (!existingPlayerKills.isPresent())
extraData.put(PlayerKills.class, playerKills);
extraData.put(PlayerName.class, new PlayerName(set.getString("name")));
session.setAsFirstSessionIfMatches(set.getLong("registered"));
playerSessions.put(sessionStart, session);
}
return byServer.values().stream().map(Map::values).flatMap(Collection::stream).map(SortedMap::values).flatMap(Collection::stream).sorted(// Disorder arises
mostRecentFirst).collect(Collectors.toList());
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class ExportScheduler method scheduleServerPageExport.
private void scheduleServerPageExport() {
if (config.isFalse(ExportSettings.SERVER_PAGE))
return;
Collection<Server> servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection());
int serverCount = servers.size();
if (serverCount == 0)
return;
long period = TimeAmount.toTicks(config.get(ExportSettings.EXPORT_PERIOD), TimeUnit.MILLISECONDS);
long offset = period / serverCount;
Optional<Server> proxy = servers.stream().filter(Server::isProxy).findFirst();
proxy.ifPresent(mainServer -> runnableFactory.create(new ExportTask(exporter, same -> same.exportServerPage(mainServer), errorLogger)).runTaskTimerAsynchronously(TimeAmount.toTicks(1, TimeUnit.MINUTES), period));
// Delay first server export if on a network.
int offsetMultiplier = proxy.isPresent() ? 1 : 0;
for (Server server : servers) {
runnableFactory.create(new ExportTask(exporter, same -> {
same.exportServerPage(server);
same.exportServerJSON(server);
}, errorLogger)).runTaskTimerAsynchronously(offset * offsetMultiplier, period);
offsetMultiplier++;
}
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class DatabaseCommands method onUninstalled.
public void onUninstalled(CMDSender sender, Arguments arguments) {
ensureDatabaseIsOpen();
String identifier = arguments.concatenate(" ");
Server server = dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(identifier)).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_SERVER_NOT_FOUND, identifier)));
if (server.getUuid().equals(serverInfo.getServerUUID())) {
throw new IllegalArgumentException(locale.getString(CommandLang.UNINSTALLING_SAME_SERVER));
}
dbSystem.getDatabase().executeTransaction(new SetServerAsUninstalledTransaction(server.getUuid()));
sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
sender.send(locale.getString(CommandLang.DB_UNINSTALLED));
}
Aggregations