mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-04-18 18:30:31 +08:00
Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics into 4.0.0-BungeeCord-Support
This commit is contained in:
commit
dd3523fbb5
@ -67,7 +67,7 @@ public class UserData {
|
||||
accessing = 0;
|
||||
|
||||
this.gmTimes = new GMTimes(gm);
|
||||
this.worldTimes = new WorldTimes();
|
||||
// TODO REMOVE this.worldTimes = new WorldTimes();
|
||||
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data.analysis;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.WorldPieCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -31,8 +29,8 @@ public class WorldPart extends RawData {
|
||||
|
||||
@Override
|
||||
protected void analyse() {
|
||||
WorldTimes t = new WorldTimes(worldTimes);
|
||||
addValue("worldTotal", FormatUtils.formatTimeAmount(t.getTotal()));
|
||||
// TODO WorldTimes t = new WorldTimes(worldTimes);
|
||||
// addValue("worldTotal", FormatUtils.formatTimeAmount(t.getTotal()));
|
||||
addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes));
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,6 @@ public class PlaytimeHandling {
|
||||
gmTimes.changeState(gamemode != null ? gamemode : gmTimes.getState(), playTime);
|
||||
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
worldTimes.changeState(worldName, playTime);
|
||||
// TODO worldTimes.changeState(worldName, playTime);
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,10 @@ import java.util.Map;
|
||||
*/
|
||||
public class GMTimes extends TimeKeeper {
|
||||
|
||||
// TODO Make private once GMTimesTable is removed
|
||||
public static final String SURVIVAL = "SURVIVAL";
|
||||
public static final String CREATIVE = "CREATIVE";
|
||||
public static final String ADVENTURE = "ADVENTURE";
|
||||
public static final String SPECTATOR = "SPECTATOR";
|
||||
private static final String SURVIVAL = "SURVIVAL";
|
||||
private static final String CREATIVE = "CREATIVE";
|
||||
private static final String ADVENTURE = "ADVENTURE";
|
||||
private static final String SPECTATOR = "SPECTATOR";
|
||||
|
||||
public GMTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
||||
super(times, lastState, lastStateChange);
|
||||
@ -67,8 +66,8 @@ public class GMTimes extends TimeKeeper {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetTimes(long playtime) {
|
||||
resetState(SURVIVAL, playtime);
|
||||
public void resetTimes(long time) {
|
||||
resetState(SURVIVAL, time);
|
||||
resetState(CREATIVE);
|
||||
resetState(ADVENTURE);
|
||||
resetState(SPECTATOR);
|
||||
|
@ -1,44 +1,130 @@
|
||||
package main.java.com.djrapitops.plan.data.time;
|
||||
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TimeKeeper class that tracks the time spent in each World based on Playtime.
|
||||
* Class that tracks the time spent in each World based on GMTimes.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.6.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
// TODO Change WorldTimes to use GMTimes per world.
|
||||
public class WorldTimes extends TimeKeeper {
|
||||
public class WorldTimes {
|
||||
|
||||
public WorldTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
||||
super(times, lastState, lastStateChange);
|
||||
private final Map<String, GMTimes> worldTimes;
|
||||
private String currentWorld;
|
||||
private String currentGamemode;
|
||||
|
||||
/**
|
||||
* Creates a new Empty WorldTimes object.
|
||||
*
|
||||
* @param startingWorld World to start the calculations at.
|
||||
* @param startingGM GameMode to start the calculations at.
|
||||
*/
|
||||
public WorldTimes(String startingWorld, String startingGM) {
|
||||
worldTimes = new HashMap<>();
|
||||
currentWorld = startingWorld;
|
||||
currentGamemode = startingGM;
|
||||
addWorld(startingWorld, startingGM, MiscUtils.getTime());
|
||||
}
|
||||
|
||||
public WorldTimes(String lastState, long lastStateChange) {
|
||||
super(lastState, lastStateChange);
|
||||
/**
|
||||
* Re-Creates an existing WorldTimes object for viewing.
|
||||
*
|
||||
* @param times Map of each World's GMTimes object.
|
||||
*/
|
||||
public WorldTimes(Map<String, GMTimes> times) {
|
||||
worldTimes = times;
|
||||
}
|
||||
|
||||
public WorldTimes(String lastState) {
|
||||
super(lastState);
|
||||
private void addWorld(String worldName, String gameMode, long changeTime) {
|
||||
worldTimes.put(worldName, new GMTimes(gameMode, changeTime));
|
||||
}
|
||||
|
||||
public WorldTimes(Map<String, Long> times, long lastStateChange) {
|
||||
super(times, null, lastStateChange);
|
||||
/**
|
||||
* Updates the time status to match the new state.
|
||||
*
|
||||
* @param worldName World name of the world swapped to.
|
||||
* @param gameMode GameMode name of the gm swapped to.
|
||||
* @param changeTime Epoch ms the change occurred.
|
||||
*/
|
||||
public void updateState(String worldName, String gameMode, long changeTime) {
|
||||
GMTimes currentGMTimes = worldTimes.get(currentWorld);
|
||||
if (worldName.equals(currentWorld)) {
|
||||
currentGMTimes.changeState(gameMode, changeTime);
|
||||
} else {
|
||||
GMTimes newGMTimes = worldTimes.get(worldName);
|
||||
if (newGMTimes == null) {
|
||||
addWorld(worldName, gameMode, currentGMTimes.getLastStateChange());
|
||||
}
|
||||
currentGMTimes.changeState(currentGamemode, changeTime);
|
||||
}
|
||||
for (GMTimes gmTimes : worldTimes.values()) {
|
||||
gmTimes.setLastStateChange(changeTime);
|
||||
}
|
||||
currentWorld = worldName;
|
||||
currentGamemode = gameMode;
|
||||
}
|
||||
|
||||
public WorldTimes(Map<String, Long> times) {
|
||||
super(times);
|
||||
/**
|
||||
* Used to get a total playtime of a world.
|
||||
*
|
||||
* @param world World name being checked.
|
||||
* @return total milliseconds spent in a world.
|
||||
*/
|
||||
public long getWorldPlaytime(String world) {
|
||||
GMTimes gmTimes = worldTimes.get(world);
|
||||
if (gmTimes != null) {
|
||||
return gmTimes.getTotal();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public WorldTimes() {
|
||||
super();
|
||||
public long getTotal() {
|
||||
return worldTimes.values().stream()
|
||||
.mapToLong(GMTimes::getTotal)
|
||||
.sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for Quick access to time of each GameMode.
|
||||
* <p>
|
||||
* Should not be used for changing state,
|
||||
* because if player has not played in the world,
|
||||
* an empty GMTimes is given, with 0 as playtime
|
||||
*
|
||||
* @param world World name being checked.
|
||||
* @return GMTimes object with play times of each GameMode.
|
||||
*/
|
||||
public GMTimes getGMTimes(String world) {
|
||||
GMTimes gmTimes = worldTimes.get(world);
|
||||
if (gmTimes != null) {
|
||||
return gmTimes;
|
||||
}
|
||||
return new GMTimes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
String state = super.getState();
|
||||
return state != null ? state : "Unknown";
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder("WorldTimes (Current: " + currentWorld + "){\n");
|
||||
for (Map.Entry<String, GMTimes> entry : worldTimes.entrySet()) {
|
||||
b.append("World '").append(entry.getKey()).append("':\n");
|
||||
GMTimes value = entry.getValue();
|
||||
b.append(" Total: ").append(value.getTotal()).append("\n");
|
||||
b.append(" ").append(value.toString()).append("\n");
|
||||
}
|
||||
b.append("}");
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the Map for saving.
|
||||
*
|
||||
* @return Current time map.
|
||||
*/
|
||||
public Map<String, GMTimes> getWorldTimes() {
|
||||
return worldTimes;
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,6 @@ public abstract class Database {
|
||||
*/
|
||||
protected UsersTable usersTable;
|
||||
|
||||
/**
|
||||
* Table representing plan_gamemodetimes in the database.
|
||||
*/
|
||||
protected GMTimesTable gmTimesTable;
|
||||
|
||||
/**
|
||||
* Table representing plan_kills in the database.
|
||||
*/
|
||||
@ -294,15 +289,6 @@ public abstract class Database {
|
||||
return sessionsTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the gm times table.
|
||||
*
|
||||
* @return Table representing plan_gamemodetimes
|
||||
*/
|
||||
public GMTimesTable getGmTimesTable() {
|
||||
return gmTimesTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the kills table.
|
||||
*
|
||||
|
@ -45,7 +45,6 @@ public abstract class SQLDB extends Database {
|
||||
usingMySQL = getName().equals("MySQL");
|
||||
|
||||
usersTable = new UsersTable(this, usingMySQL);
|
||||
gmTimesTable = new GMTimesTable(this, usingMySQL);
|
||||
sessionsTable = new SessionsTable(this, usingMySQL);
|
||||
killsTable = new KillsTable(this, usingMySQL);
|
||||
ipsTable = new IPsTable(this, usingMySQL);
|
||||
@ -226,7 +225,7 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
public Table[] getAllTables() {
|
||||
return new Table[]{
|
||||
usersTable, gmTimesTable, ipsTable,
|
||||
usersTable, ipsTable,
|
||||
nicknamesTable, sessionsTable, killsTable,
|
||||
commandUseTable, tpsTable, worldTable,
|
||||
worldTimesTable, securityTable};
|
||||
@ -237,7 +236,7 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
public Table[] getAllTablesInRemoveOrder() {
|
||||
return new Table[]{
|
||||
gmTimesTable, ipsTable,
|
||||
ipsTable,
|
||||
nicknamesTable, sessionsTable, killsTable,
|
||||
worldTimesTable, worldTable, usersTable,
|
||||
commandUseTable, tpsTable};
|
||||
@ -320,7 +319,6 @@ public abstract class SQLDB extends Database {
|
||||
boolean success = userId != -1
|
||||
&& ipsTable.removeUserIPs(userId)
|
||||
&& nicknamesTable.removeUserNicknames(userId)
|
||||
&& gmTimesTable.removeUserGMTimes(userId)
|
||||
&& sessionsTable.removeUserSessions(userId)
|
||||
&& killsTable.removeUserKillsAndVictims(userId)
|
||||
&& worldTimesTable.removeUserWorldTimes(userId)
|
||||
@ -369,15 +367,12 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
List<InetAddress> ips = ipsTable.getIPAddresses(userId);
|
||||
data.addIpAddresses(ips);
|
||||
|
||||
Map<String, Long> gmTimes = gmTimesTable.getGMTimes(userId);
|
||||
data.getGmTimes().setTimes(gmTimes);
|
||||
Map<String, Long> worldTimes = worldTimesTable.getWorldTimes(userId);
|
||||
WorldTimes worldT = data.getWorldTimes();
|
||||
worldT.setTimes(worldTimes);
|
||||
if (worldT.getLastStateChange() == 0) {
|
||||
worldT.setLastStateChange(data.getPlayTime());
|
||||
}
|
||||
// worldT.setTimes(worldTimes); //TODO
|
||||
// if (worldT.getLastStateChange() == 0) {
|
||||
// worldT.setLastStateChange(data.getPlayTime());
|
||||
// }
|
||||
|
||||
List<SessionData> sessions = sessionsTable.getSessionData(userId);
|
||||
data.addSessions(sessions);
|
||||
@ -419,7 +414,6 @@ public abstract class SQLDB extends Database {
|
||||
Map<Integer, Set<InetAddress>> ipList = ipsTable.getIPList(ids);
|
||||
Map<Integer, List<KillData>> playerKills = killsTable.getPlayerKills(ids, idUuidRel);
|
||||
Map<Integer, List<SessionData>> sessionData = sessionsTable.getSessionData(ids);
|
||||
Map<Integer, Map<String, Long>> gmTimes = gmTimesTable.getGMTimes(ids);
|
||||
Map<Integer, Map<String, Long>> worldTimes = worldTimesTable.getWorldTimes(ids);
|
||||
|
||||
Log.debug("Database",
|
||||
@ -431,7 +425,6 @@ public abstract class SQLDB extends Database {
|
||||
" IPs: " + ipList.size(),
|
||||
" Kills: " + playerKills.size(),
|
||||
" Sessions: " + sessionData.size(),
|
||||
" GM Times: " + gmTimes.size(),
|
||||
" World Times: " + worldTimes.size()
|
||||
);
|
||||
|
||||
@ -446,12 +439,11 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
uData.addSessions(sessionData.get(id));
|
||||
uData.setPlayerKills(playerKills.get(id));
|
||||
uData.getGmTimes().setTimes(gmTimes.get(id));
|
||||
WorldTimes worldT = uData.getWorldTimes();
|
||||
worldT.setTimes(worldTimes.get(id));
|
||||
if (worldT.getLastStateChange() == 0) {
|
||||
worldT.setLastStateChange(uData.getPlayTime());
|
||||
}
|
||||
// worldT.setTimes(worldTimes.get(id)); //TODO
|
||||
// if (worldT.getLastStateChange() == 0) {
|
||||
// worldT.setLastStateChange(uData.getPlayTime());
|
||||
// }
|
||||
}
|
||||
|
||||
Benchmark.stop("Database", "Get UserData for " + uuidsCol.size());
|
||||
@ -493,13 +485,13 @@ public abstract class SQLDB extends Database {
|
||||
Map<Integer, Map<String, Long>> worldTimes = new HashMap<>();
|
||||
|
||||
// Put in data set
|
||||
List<String> worldNames = data.stream()
|
||||
.map(UserData::getWorldTimes)
|
||||
.map(WorldTimes::getTimes)
|
||||
.map(Map::keySet)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
// List<String> worldNames = data.stream() //TODO
|
||||
// .map(UserData::getWorldTimes)
|
||||
// .map(WorldTimes::getTimes)
|
||||
// .map(Map::keySet)
|
||||
// .flatMap(Collection::stream)
|
||||
// .distinct()
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
for (Map.Entry<UUID, UserData> entrySet : userDatas.entrySet()) {
|
||||
UUID uuid = entrySet.getKey();
|
||||
@ -518,7 +510,7 @@ public abstract class SQLDB extends Database {
|
||||
kills.put(id, new ArrayList<>(uData.getPlayerKills()));
|
||||
sessions.put(id, new ArrayList<>(uData.getSessions()));
|
||||
gmTimes.put(id, new HashMap<>(uData.getGmTimes().getTimes()));
|
||||
worldTimes.put(id, new HashMap<>(uData.getWorldTimes().getTimes()));
|
||||
// TODO worldTimes.put(id, new HashMap<>(uData.getWorldTimes().getTimes()));
|
||||
}
|
||||
|
||||
// Save
|
||||
@ -526,8 +518,7 @@ public abstract class SQLDB extends Database {
|
||||
ipsTable.saveIPList(ips);
|
||||
killsTable.savePlayerKills(kills, uuids);
|
||||
sessionsTable.saveSessionData(sessions);
|
||||
gmTimesTable.saveGMTimes(gmTimes);
|
||||
worldTable.saveWorlds(worldNames);
|
||||
// TODO worldTable.saveWorlds(worldNames);
|
||||
worldTimesTable.saveWorldTimes(worldTimes);
|
||||
commit();
|
||||
userDatas.values().stream()
|
||||
@ -561,9 +552,8 @@ public abstract class SQLDB extends Database {
|
||||
nicknamesTable.saveNickList(userId, new HashSet<>(data.getNicknames()), data.getLastNick());
|
||||
ipsTable.saveIPList(userId, new HashSet<>(data.getIps()));
|
||||
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
||||
gmTimesTable.saveGMTimes(userId, data.getGmTimes().getTimes());
|
||||
worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
||||
worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
||||
// TODO worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
||||
// worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
||||
data.stopAccessing();
|
||||
commit();
|
||||
Benchmark.stop("Database", "Save Single UserData");
|
||||
|
@ -1,354 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.database.tables;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
* @deprecated GM Times moved to WorldTable
|
||||
*/
|
||||
@Deprecated
|
||||
public class GMTimesTable extends UserIDTable {
|
||||
|
||||
private final String columnSurvivalTime;
|
||||
private final String columnCreativeTime;
|
||||
private final String columnAdventureTime;
|
||||
private final String columnSpectatorTime;
|
||||
|
||||
|
||||
/**
|
||||
* @param db
|
||||
* @param usingMySQL
|
||||
*/
|
||||
public GMTimesTable(SQLDB db, boolean usingMySQL) {
|
||||
super("plan_gamemodetimes", db, usingMySQL);
|
||||
columnUserID = "user_id";
|
||||
columnSurvivalTime = "SURVIVAL";
|
||||
columnCreativeTime = "CREATIVE";
|
||||
columnAdventureTime = "ADVENTURE";
|
||||
columnSpectatorTime = "SPECTATOR";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
try {
|
||||
execute(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnSurvivalTime, Sql.LONG).notNull()
|
||||
.column(columnCreativeTime, Sql.LONG).notNull()
|
||||
.column(columnAdventureTime, Sql.LONG).notNull()
|
||||
.column(columnSpectatorTime, Sql.LONG).notNull()
|
||||
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
.toString()
|
||||
);
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public boolean removeUserGMTimes(int userId) {
|
||||
return super.removeDataOf(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Map<String, Long> getGMTimes(int userId) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUserID + "=?)");
|
||||
statement.setInt(1, userId);
|
||||
set = statement.executeQuery();
|
||||
HashMap<String, Long> times = new HashMap<>();
|
||||
|
||||
while (set.next()) {
|
||||
times.put(GMTimes.SURVIVAL, set.getLong(columnSurvivalTime));
|
||||
times.put(GMTimes.CREATIVE, set.getLong(columnCreativeTime));
|
||||
times.put(GMTimes.ADVENTURE, set.getLong(columnAdventureTime));
|
||||
times.put(GMTimes.SPECTATOR, set.getLong(columnSpectatorTime));
|
||||
}
|
||||
|
||||
return times;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, Map<String, Long>> getGMTimes(Collection<Integer> userIds) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
Map<Integer, Map<String, Long>> times = new HashMap<>();
|
||||
try {
|
||||
statement = prepareStatement("SELECT * FROM " + tableName);
|
||||
set = statement.executeQuery();
|
||||
|
||||
while (set.next()) {
|
||||
Map<String, Long> gmTimes = new HashMap<>();
|
||||
int id = set.getInt(columnUserID);
|
||||
if (!userIds.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
gmTimes.put(GMTimes.SURVIVAL, set.getLong(columnSurvivalTime));
|
||||
gmTimes.put(GMTimes.CREATIVE, set.getLong(columnCreativeTime));
|
||||
gmTimes.put(GMTimes.ADVENTURE, set.getLong(columnAdventureTime));
|
||||
gmTimes.put(GMTimes.SPECTATOR, set.getLong(columnSpectatorTime));
|
||||
times.put(id, gmTimes);
|
||||
}
|
||||
|
||||
return times;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @param gamemodeTimes
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void saveGMTimes(int userId, Map<String, Long> gamemodeTimes) throws SQLException {
|
||||
if (Verify.isEmpty(gamemodeTimes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement statement = null;
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
int update;
|
||||
try {
|
||||
statement = prepareStatement(
|
||||
"UPDATE " + tableName + " SET "
|
||||
+ columnSurvivalTime + "=?, "
|
||||
+ columnCreativeTime + "=?, "
|
||||
+ columnAdventureTime + "=?, "
|
||||
+ columnSpectatorTime + "=? "
|
||||
+ " WHERE (" + columnUserID + "=?)");
|
||||
statement.setInt(5, userId);
|
||||
|
||||
for (int i = 0; i < gms.length; i++) {
|
||||
Long time = gamemodeTimes.get(gms[i]);
|
||||
statement.setLong(i + 1, time != null ? time : 0);
|
||||
}
|
||||
|
||||
update = statement.executeUpdate();
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
|
||||
if (update == 0) {
|
||||
addNewGMTimesRow(userId, gamemodeTimes);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Integer> getSavedIDs() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement("SELECT " + columnUserID + " FROM " + tableName);
|
||||
set = statement.executeQuery();
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
while (set.next()) {
|
||||
ids.add(set.getInt(columnUserID));
|
||||
}
|
||||
return ids;
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveGMTimes(Map<Integer, Map<String, Long>> gamemodeTimes) throws SQLException {
|
||||
if (Verify.isEmpty(gamemodeTimes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Integer> savedIDs = getSavedIDs();
|
||||
|
||||
Map<Integer, GMTimes> gmTimes = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Integer, Map<String, Long>> entrySet : gamemodeTimes.entrySet()) {
|
||||
int userID = entrySet.getKey();
|
||||
|
||||
if (!savedIDs.contains(userID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, Long> gmTimesMap = entrySet.getValue();
|
||||
gmTimes.put(userID, new GMTimes(gmTimesMap));
|
||||
}
|
||||
|
||||
List<List<Container<GMTimes>>> batches = DBUtils.splitIntoBatchesWithID(gmTimes);
|
||||
|
||||
batches.forEach(batch -> {
|
||||
try {
|
||||
saveGMTimesBatch(batch);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog("GMTimesTable.saveGMTimes", e);
|
||||
}
|
||||
});
|
||||
|
||||
gamemodeTimes.keySet().removeAll(savedIDs);
|
||||
|
||||
addNewGMTimesRows(gamemodeTimes);
|
||||
}
|
||||
|
||||
private void saveGMTimesBatch(List<Container<GMTimes>> batch) throws SQLException {
|
||||
if (batch.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
Set<Integer> savedIDs = getSavedIDs();
|
||||
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(
|
||||
"UPDATE " + tableName + " SET "
|
||||
+ columnSurvivalTime + "=?, "
|
||||
+ columnCreativeTime + "=?, "
|
||||
+ columnAdventureTime + "=?, "
|
||||
+ columnSpectatorTime + "=? "
|
||||
+ " WHERE (" + columnUserID + "=?)");
|
||||
|
||||
for (Container<GMTimes> data : batch) {
|
||||
int id = data.getId();
|
||||
|
||||
if (!savedIDs.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
statement.setInt(5, id);
|
||||
|
||||
for (int i = 0; i < gms.length; i++) {
|
||||
Map<String, Long> times = data.getObject().getTimes();
|
||||
Long time = times.get(gms[i]);
|
||||
|
||||
statement.setLong(i + 1, time != null ? time : 0);
|
||||
}
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewGMTimesRows(Map<Integer, Map<String, Long>> gamemodeTimes) {
|
||||
if (Verify.isEmpty(gamemodeTimes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Integer, GMTimes> gmTimes = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Integer, Map<String, Long>> entrySet : gamemodeTimes.entrySet()) {
|
||||
int userID = entrySet.getKey();
|
||||
Map<String, Long> gmTimesMap = entrySet.getValue();
|
||||
gmTimes.put(userID, new GMTimes(gmTimesMap));
|
||||
}
|
||||
|
||||
List<List<Container<GMTimes>>> batches = DBUtils.splitIntoBatchesWithID(gmTimes);
|
||||
|
||||
batches.forEach(batch -> {
|
||||
try {
|
||||
addNewGMTimesBatch(batch);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog("GMTimesTable.addNewGMTimesRows", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addNewGMTimesBatch(List<Container<GMTimes>> batch) throws SQLException {
|
||||
if (batch.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement(
|
||||
"INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnSurvivalTime + ", "
|
||||
+ columnCreativeTime + ", "
|
||||
+ columnAdventureTime + ", "
|
||||
+ columnSpectatorTime
|
||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
||||
|
||||
for (Container<GMTimes> data : batch) {
|
||||
statement.setInt(1, data.getId());
|
||||
|
||||
for (int i = 0; i < gms.length; i++) {
|
||||
Map<String, Long> times = data.getObject().getTimes();
|
||||
Long time = times.get(gms[i]);
|
||||
|
||||
statement.setLong(i + 2, time != null ? time : 0);
|
||||
}
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewGMTimesRow(int userId, Map<String, Long> gamemodeTimes) throws SQLException {
|
||||
if (Verify.isEmpty(gamemodeTimes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement statement = null;
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnUserID + ", "
|
||||
+ columnSurvivalTime + ", "
|
||||
+ columnCreativeTime + ", "
|
||||
+ columnAdventureTime + ", "
|
||||
+ columnSpectatorTime
|
||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
||||
|
||||
statement.setInt(1, userId);
|
||||
|
||||
for (int i = 0; i < gms.length; i++) {
|
||||
Long time = gamemodeTimes.get(gms[i]);
|
||||
statement.setLong(i + 2, time != null ? time : 0);
|
||||
}
|
||||
|
||||
statement.execute();
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -370,13 +370,13 @@ public class UsersTable extends Table {
|
||||
data.setDeaths(set.getInt(columnDeaths));
|
||||
data.setMobKills(set.getInt(columnMobKills));
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
String lastWorld = set.getString(columnLastWorld);
|
||||
if (!"Unknown".equals(lastWorld)) {
|
||||
worldTimes.setState(lastWorld);
|
||||
} else {
|
||||
worldTimes.setLastStateChange(playTime);
|
||||
}
|
||||
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
// String lastWorld = set.getString(columnLastWorld);
|
||||
// if (!"Unknown".equals(lastWorld)) {
|
||||
// worldTimes.setState(lastWorld);
|
||||
// } else {
|
||||
// worldTimes.setLastStateChange(playTime);
|
||||
// }
|
||||
return data;
|
||||
}
|
||||
} finally {
|
||||
@ -415,13 +415,13 @@ public class UsersTable extends Table {
|
||||
data.setDeaths(set.getInt(columnDeaths));
|
||||
data.setMobKills(set.getInt(columnMobKills));
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
String lastWorld = set.getString(columnLastWorld);
|
||||
if (!"Unknown".equals(lastWorld)) {
|
||||
worldTimes.setState(lastWorld);
|
||||
} else {
|
||||
worldTimes.setLastStateChange(playTime);
|
||||
}
|
||||
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
// String lastWorld = set.getString(columnLastWorld);
|
||||
// if (!"Unknown".equals(lastWorld)) {
|
||||
// worldTimes.setState(lastWorld);
|
||||
// } else {
|
||||
// worldTimes.setLastStateChange(playTime);
|
||||
// }
|
||||
datas.add(data);
|
||||
}
|
||||
} finally {
|
||||
@ -454,13 +454,13 @@ public class UsersTable extends Table {
|
||||
data.setDeaths(set.getInt(columnDeaths));
|
||||
data.setMobKills(set.getInt(columnMobKills));
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
String lastWorld = set.getString(columnLastWorld);
|
||||
if (!"Unknown".equals(lastWorld)) {
|
||||
worldTimes.setState(lastWorld);
|
||||
} else {
|
||||
worldTimes.setLastStateChange(playTime);
|
||||
}
|
||||
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
// String lastWorld = set.getString(columnLastWorld);
|
||||
// if (!"Unknown".equals(lastWorld)) {
|
||||
// worldTimes.setState(lastWorld);
|
||||
// } else {
|
||||
// worldTimes.setLastStateChange(playTime);
|
||||
// }
|
||||
}
|
||||
} finally {
|
||||
close(set);
|
||||
@ -497,13 +497,13 @@ public class UsersTable extends Table {
|
||||
gmTimes.setState(set.getString(columnLastGM));
|
||||
gmTimes.setLastStateChange(set.getLong(columnLastGMSwapTime));
|
||||
WorldTimes worldTimes = uData.getWorldTimes();
|
||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
String lastWorld = set.getString(columnLastWorld);
|
||||
if (!"Unknown".equals(lastWorld)) {
|
||||
worldTimes.setState(lastWorld);
|
||||
} else {
|
||||
worldTimes.setLastStateChange(playTime);
|
||||
}
|
||||
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||
// String lastWorld = set.getString(columnLastWorld);
|
||||
// if (!"Unknown".equals(lastWorld)) {
|
||||
// worldTimes.setState(lastWorld);
|
||||
// } else {
|
||||
// worldTimes.setLastStateChange(playTime);
|
||||
// }
|
||||
}
|
||||
} finally {
|
||||
close(set);
|
||||
@ -540,8 +540,8 @@ public class UsersTable extends Table {
|
||||
statement.setString(12, data.getName());
|
||||
statement.setLong(13, data.getRegistered());
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
statement.setString(14, worldTimes.getState());
|
||||
statement.setLong(15, worldTimes.getLastStateChange());
|
||||
// TODO statement.setString(14, worldTimes.getState());
|
||||
// statement.setLong(15, worldTimes.getLastStateChange());
|
||||
statement.setString(16, uuid.toString());
|
||||
update = statement.executeUpdate();
|
||||
}
|
||||
@ -565,8 +565,8 @@ public class UsersTable extends Table {
|
||||
statement.setString(13, data.getName());
|
||||
statement.setLong(14, data.getRegistered());
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
statement.setString(15, worldTimes.getState());
|
||||
statement.setLong(16, worldTimes.getLastStateChange());
|
||||
// TODO statement.setString(15, worldTimes.getState());
|
||||
// statement.setLong(16, worldTimes.getLastStateChange());
|
||||
statement.execute();
|
||||
}
|
||||
} finally {
|
||||
@ -701,8 +701,8 @@ public class UsersTable extends Table {
|
||||
statement.setLong(14, uData.getRegistered());
|
||||
|
||||
WorldTimes worldTimes = uData.getWorldTimes();
|
||||
statement.setString(15, worldTimes.getState());
|
||||
statement.setLong(16, worldTimes.getLastStateChange());
|
||||
// TODO statement.setString(15, worldTimes.getState());
|
||||
// statement.setLong(16, worldTimes.getLastStateChange());
|
||||
|
||||
statement.addBatch();
|
||||
}
|
||||
@ -759,8 +759,8 @@ public class UsersTable extends Table {
|
||||
statement.setString(12, uData.getName());
|
||||
statement.setLong(13, uData.getRegistered());
|
||||
WorldTimes worldTimes = uData.getWorldTimes();
|
||||
statement.setString(14, worldTimes.getState());
|
||||
statement.setLong(15, worldTimes.getLastStateChange());
|
||||
// TODO statement.setString(14, worldTimes.getState());
|
||||
// statement.setLong(15, worldTimes.getLastStateChange());
|
||||
statement.setString(16, uuid.toString());
|
||||
statement.addBatch();
|
||||
uData.stopAccessing();
|
||||
|
@ -7,7 +7,6 @@ import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.PunchCardGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.WorldPieCreator;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
@ -79,8 +78,8 @@ public class PlaceholderUtils {
|
||||
Set<SessionData> sessions = new HashSet<>(data.getSessions());
|
||||
replaceMap.put("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessions));
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
replaceMap.put("worldSeries", WorldPieCreator.createSeriesData(worldTimes.getTimes()));
|
||||
replaceMap.put("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
|
||||
// TODO replaceMap.put("worldSeries", WorldPieCreator.createSeriesData(worldTimes.getTimes()));
|
||||
// replaceMap.put("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
|
||||
|
||||
//TODO Plugin Tab content Web API
|
||||
//TODO Player Plugin tab code.
|
||||
|
@ -277,10 +277,10 @@ public class Analysis {
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Long> worldTimes = uData.getWorldTimes().getTimes();
|
||||
for (Map.Entry<String, Long> world : worldTimes.entrySet()) {
|
||||
worldPart.addToWorld(world.getKey(), world.getValue());
|
||||
}
|
||||
// TODO Map<String, Long> worldTimes = uData.getWorldTimes().getTimes();
|
||||
// for (Map.Entry<String, Long> world : worldTimes.entrySet()) {
|
||||
// worldPart.addToWorld(world.getKey(), world.getValue());
|
||||
// }
|
||||
|
||||
final long playTime = uData.getPlayTime();
|
||||
playtime.addToPlaytime(playTime);
|
||||
|
@ -63,6 +63,6 @@ public class LoginInfoTest {
|
||||
String geo = data.getGeolocation();
|
||||
assertTrue("Wrong location " + geo, geo.equals("United States"));
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
assertEquals("World", data.getWorldTimes().getState());
|
||||
// TODO assertEquals("World", data.getWorldTimes().getState());
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class LogoutInfoTest {
|
||||
assertTrue("Playtime wrong", data.getPlayTime() == 10L);
|
||||
assertTrue("Banned wrong", data.isBanned());
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
assertEquals("World", data.getWorldTimes().getState());
|
||||
// TODO assertEquals("World", data.getWorldTimes().getState());
|
||||
assertEquals(1, data.getSessions().size());
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,6 @@ public class ReloadInfoTest {
|
||||
assertEquals(nick, data.getLastNick());
|
||||
assertEquals("United States", data.getGeolocation());
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
assertEquals("World", data.getWorldTimes().getState());
|
||||
// TODO assertEquals("World", data.getWorldTimes().getState());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,175 @@
|
||||
package test.java.main.java.com.djrapitops.plan.data.time;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import test.java.utils.RandomData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class WorldTimesTest {
|
||||
|
||||
private long time;
|
||||
private WorldTimes test;
|
||||
private final String worldOne = "ONE";
|
||||
private final String worldTwo = "TWO";
|
||||
|
||||
private final String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
test = new WorldTimes(worldOne, gms[0]);
|
||||
time = test.getGMTimes(worldOne).getLastStateChange();
|
||||
System.out.println(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldChange() {
|
||||
long changeTime = time + 1000L;
|
||||
test.updateState(worldTwo, gms[0], changeTime);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGMChange() {
|
||||
long changeTime = time + 1000L;
|
||||
test.updateState(worldOne, gms[0], changeTime);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBothTwiceChange() {
|
||||
long changeTime = time + 1000L;
|
||||
long changeTime2 = changeTime + 1000L;
|
||||
test.updateState(worldTwo, gms[2], changeTime);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
test.updateState(worldOne, gms[1], changeTime2);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, (long) test.getWorldPlaytime(worldOne));
|
||||
assertEquals(1000L, test.getGMTimes(worldOne).getTime(gms[0]));
|
||||
assertEquals(1000L, test.getGMTimes(worldTwo).getTime(gms[2]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLotOfChangesWorldTime() {
|
||||
long amount = 1000L;
|
||||
String[] worlds = new String[]{worldOne, worldTwo};
|
||||
|
||||
Map<String, List<String>> testedW = new HashMap<>();
|
||||
testedW.put(worldOne, new ArrayList<>());
|
||||
testedW.put(worldTwo, new ArrayList<>());
|
||||
|
||||
String lastWorld = worldOne;
|
||||
String lastGM = gms[0];
|
||||
for (int i = 1; i <= 50; i++) {
|
||||
int wRndm = RandomData.randomInt(0, worlds.length);
|
||||
int gmRndm = RandomData.randomInt(0, gms.length);
|
||||
|
||||
String world = worlds[wRndm];
|
||||
String gm = gms[gmRndm];
|
||||
testedW.get(lastWorld).add(lastGM);
|
||||
lastGM = gm;
|
||||
lastWorld = world;
|
||||
|
||||
long time = i * amount + this.time;
|
||||
|
||||
test.updateState(world, gm, time);
|
||||
}
|
||||
|
||||
long worldOneCount = testedW.get(worldOne).size();
|
||||
long worldTwoCount = testedW.get(worldTwo).size();
|
||||
long worldTimeOne = worldOneCount * amount;
|
||||
long worldTimeTwo = worldTwoCount * amount;
|
||||
|
||||
long time1 = test.getWorldPlaytime(worldOne);
|
||||
long time2 = test.getWorldPlaytime(worldTwo);
|
||||
System.out.println(test);
|
||||
|
||||
// Tests World time calculation.
|
||||
assertEquals(amount * 50, time1 + time2);
|
||||
assertEquals(worldTimeOne, time1);
|
||||
assertEquals(worldTimeTwo, time2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGMTrackingSingleWorld() {
|
||||
long changeTime = time + 1000L;
|
||||
long changeTime2 = changeTime + 1000L;
|
||||
GMTimes gmTimes = test.getGMTimes(worldOne);
|
||||
test.updateState(worldOne, "CREATIVE", changeTime);
|
||||
assertEquals(1000L, gmTimes.getTime("SURVIVAL"));
|
||||
assertEquals(0L, gmTimes.getTime("CREATIVE"));
|
||||
test.updateState(worldOne, "ADVENTURE", changeTime2);
|
||||
assertEquals(1000L, gmTimes.getTime("SURVIVAL"));
|
||||
assertEquals(1000L, gmTimes.getTime("CREATIVE"));
|
||||
assertEquals(0L, gmTimes.getTime("ADVENTURE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGMTrackingTwoWorlds() {
|
||||
long changeTime = time + 1000L;
|
||||
long changeTime2 = time + 2000L;
|
||||
GMTimes worldOneGMTimes = test.getGMTimes(worldOne);
|
||||
test.updateState(worldOne, "CREATIVE", changeTime);
|
||||
test.updateState(worldOne, "ADVENTURE", changeTime2);
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
|
||||
assertEquals(0L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
|
||||
test.updateState(worldTwo, "SURVIVAL", time + 3000L);
|
||||
GMTimes worldTwoGMTimes = test.getGMTimes(worldTwo);
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
|
||||
assertEquals(0L, worldTwoGMTimes.getTime("SURVIVAL"));
|
||||
assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
assertEquals(0L, worldTwoGMTimes.getTime("ADVENTURE"));
|
||||
|
||||
test.updateState(worldTwo, "CREATIVE", time + 4000L);
|
||||
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL"));
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE"));
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
|
||||
assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL"));
|
||||
assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
|
||||
test.updateState(worldTwo, "CREATIVE", time + 5000L);
|
||||
assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL"));
|
||||
assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
|
||||
// No change should occur.
|
||||
test.updateState(worldOne, "ADVENTURE", time + 5000L);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
test.updateState(worldTwo, "CREATIVE", time + 5000L);
|
||||
System.out.println(test);
|
||||
test.updateState(worldOne, "ADVENTURE", time + 6000L);
|
||||
System.out.println(test);
|
||||
assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
|
||||
test.updateState(worldTwo, "ADVENTURE", time + 7000L);
|
||||
assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE"));
|
||||
assertEquals(2000L, worldOneGMTimes.getTime("ADVENTURE"));
|
||||
}
|
||||
|
||||
// TODO Test where SessionData is ended, check if worldTimes & session length add up.
|
||||
}
|
@ -224,9 +224,9 @@ public class DatabaseTest {
|
||||
gmTimes.setState("SURVIVAL");
|
||||
gmTimes.setLastStateChange(10L);
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
worldTimes.setTime("World", 20L);
|
||||
worldTimes.setState("World");
|
||||
worldTimes.setLastStateChange(10L);
|
||||
// TODO worldTimes.setTime("World", 20L);
|
||||
// worldTimes.setState("World");
|
||||
// worldTimes.setLastStateChange(10L);
|
||||
db.saveUserData(data);
|
||||
data.addNickname("TestUpdateForSave");
|
||||
db.saveUserData(data);
|
||||
@ -261,7 +261,7 @@ public class DatabaseTest {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
data.getGmTimes().setAllGMTimes(5L, 10L, 15L, 20L);
|
||||
data.getWorldTimes().setTime("World", 20L);
|
||||
// TODO data.getWorldTimes().setTime("World", 20L);
|
||||
data.addIpAddress(InetAddress.getByName("185.64.113.61"));
|
||||
data.addSession(new SessionData(1286349L, 2342978L));
|
||||
data.addNickname("TestNick");
|
||||
|
Loading…
x
Reference in New Issue
Block a user