mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-17 15:55:02 +02: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;
|
accessing = 0;
|
||||||
|
|
||||||
this.gmTimes = new GMTimes(gm);
|
this.gmTimes = new GMTimes(gm);
|
||||||
this.worldTimes = new WorldTimes();
|
// TODO REMOVE this.worldTimes = new WorldTimes();
|
||||||
|
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package main.java.com.djrapitops.plan.data.analysis;
|
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.ui.html.graphs.WorldPieCreator;
|
||||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,8 +29,8 @@ public class WorldPart extends RawData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void analyse() {
|
protected void analyse() {
|
||||||
WorldTimes t = new WorldTimes(worldTimes);
|
// TODO WorldTimes t = new WorldTimes(worldTimes);
|
||||||
addValue("worldTotal", FormatUtils.formatTimeAmount(t.getTotal()));
|
// addValue("worldTotal", FormatUtils.formatTimeAmount(t.getTotal()));
|
||||||
addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes));
|
addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,6 @@ public class PlaytimeHandling {
|
|||||||
gmTimes.changeState(gamemode != null ? gamemode : gmTimes.getState(), playTime);
|
gmTimes.changeState(gamemode != null ? gamemode : gmTimes.getState(), playTime);
|
||||||
|
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
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 {
|
public class GMTimes extends TimeKeeper {
|
||||||
|
|
||||||
// TODO Make private once GMTimesTable is removed
|
private static final String SURVIVAL = "SURVIVAL";
|
||||||
public static final String SURVIVAL = "SURVIVAL";
|
private static final String CREATIVE = "CREATIVE";
|
||||||
public static final String CREATIVE = "CREATIVE";
|
private static final String ADVENTURE = "ADVENTURE";
|
||||||
public static final String ADVENTURE = "ADVENTURE";
|
private static final String SPECTATOR = "SPECTATOR";
|
||||||
public static final String SPECTATOR = "SPECTATOR";
|
|
||||||
|
|
||||||
public GMTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
public GMTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
||||||
super(times, lastState, lastStateChange);
|
super(times, lastState, lastStateChange);
|
||||||
@ -67,8 +66,8 @@ public class GMTimes extends TimeKeeper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTimes(long playtime) {
|
public void resetTimes(long time) {
|
||||||
resetState(SURVIVAL, playtime);
|
resetState(SURVIVAL, time);
|
||||||
resetState(CREATIVE);
|
resetState(CREATIVE);
|
||||||
resetState(ADVENTURE);
|
resetState(ADVENTURE);
|
||||||
resetState(SPECTATOR);
|
resetState(SPECTATOR);
|
||||||
|
@ -1,44 +1,130 @@
|
|||||||
package main.java.com.djrapitops.plan.data.time;
|
package main.java.com.djrapitops.plan.data.time;
|
||||||
|
|
||||||
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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
|
* @author Rsl1122
|
||||||
* @since 3.6.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
// TODO Change WorldTimes to use GMTimes per world.
|
public class WorldTimes {
|
||||||
public class WorldTimes extends TimeKeeper {
|
|
||||||
|
|
||||||
public WorldTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
private final Map<String, GMTimes> worldTimes;
|
||||||
super(times, lastState, lastStateChange);
|
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) {
|
private void addWorld(String worldName, String gameMode, long changeTime) {
|
||||||
super(lastState);
|
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() {
|
public long getTotal() {
|
||||||
super();
|
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
|
@Override
|
||||||
public String getState() {
|
public String toString() {
|
||||||
String state = super.getState();
|
StringBuilder b = new StringBuilder("WorldTimes (Current: " + currentWorld + "){\n");
|
||||||
return state != null ? state : "Unknown";
|
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;
|
protected UsersTable usersTable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Table representing plan_gamemodetimes in the database.
|
|
||||||
*/
|
|
||||||
protected GMTimesTable gmTimesTable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table representing plan_kills in the database.
|
* Table representing plan_kills in the database.
|
||||||
*/
|
*/
|
||||||
@ -294,15 +289,6 @@ public abstract class Database {
|
|||||||
return sessionsTable;
|
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.
|
* Used to get the kills table.
|
||||||
*
|
*
|
||||||
|
@ -45,7 +45,6 @@ public abstract class SQLDB extends Database {
|
|||||||
usingMySQL = getName().equals("MySQL");
|
usingMySQL = getName().equals("MySQL");
|
||||||
|
|
||||||
usersTable = new UsersTable(this, usingMySQL);
|
usersTable = new UsersTable(this, usingMySQL);
|
||||||
gmTimesTable = new GMTimesTable(this, usingMySQL);
|
|
||||||
sessionsTable = new SessionsTable(this, usingMySQL);
|
sessionsTable = new SessionsTable(this, usingMySQL);
|
||||||
killsTable = new KillsTable(this, usingMySQL);
|
killsTable = new KillsTable(this, usingMySQL);
|
||||||
ipsTable = new IPsTable(this, usingMySQL);
|
ipsTable = new IPsTable(this, usingMySQL);
|
||||||
@ -226,7 +225,7 @@ public abstract class SQLDB extends Database {
|
|||||||
*/
|
*/
|
||||||
public Table[] getAllTables() {
|
public Table[] getAllTables() {
|
||||||
return new Table[]{
|
return new Table[]{
|
||||||
usersTable, gmTimesTable, ipsTable,
|
usersTable, ipsTable,
|
||||||
nicknamesTable, sessionsTable, killsTable,
|
nicknamesTable, sessionsTable, killsTable,
|
||||||
commandUseTable, tpsTable, worldTable,
|
commandUseTable, tpsTable, worldTable,
|
||||||
worldTimesTable, securityTable};
|
worldTimesTable, securityTable};
|
||||||
@ -237,7 +236,7 @@ public abstract class SQLDB extends Database {
|
|||||||
*/
|
*/
|
||||||
public Table[] getAllTablesInRemoveOrder() {
|
public Table[] getAllTablesInRemoveOrder() {
|
||||||
return new Table[]{
|
return new Table[]{
|
||||||
gmTimesTable, ipsTable,
|
ipsTable,
|
||||||
nicknamesTable, sessionsTable, killsTable,
|
nicknamesTable, sessionsTable, killsTable,
|
||||||
worldTimesTable, worldTable, usersTable,
|
worldTimesTable, worldTable, usersTable,
|
||||||
commandUseTable, tpsTable};
|
commandUseTable, tpsTable};
|
||||||
@ -320,7 +319,6 @@ public abstract class SQLDB extends Database {
|
|||||||
boolean success = userId != -1
|
boolean success = userId != -1
|
||||||
&& ipsTable.removeUserIPs(userId)
|
&& ipsTable.removeUserIPs(userId)
|
||||||
&& nicknamesTable.removeUserNicknames(userId)
|
&& nicknamesTable.removeUserNicknames(userId)
|
||||||
&& gmTimesTable.removeUserGMTimes(userId)
|
|
||||||
&& sessionsTable.removeUserSessions(userId)
|
&& sessionsTable.removeUserSessions(userId)
|
||||||
&& killsTable.removeUserKillsAndVictims(userId)
|
&& killsTable.removeUserKillsAndVictims(userId)
|
||||||
&& worldTimesTable.removeUserWorldTimes(userId)
|
&& worldTimesTable.removeUserWorldTimes(userId)
|
||||||
@ -369,15 +367,12 @@ public abstract class SQLDB extends Database {
|
|||||||
|
|
||||||
List<InetAddress> ips = ipsTable.getIPAddresses(userId);
|
List<InetAddress> ips = ipsTable.getIPAddresses(userId);
|
||||||
data.addIpAddresses(ips);
|
data.addIpAddresses(ips);
|
||||||
|
|
||||||
Map<String, Long> gmTimes = gmTimesTable.getGMTimes(userId);
|
|
||||||
data.getGmTimes().setTimes(gmTimes);
|
|
||||||
Map<String, Long> worldTimes = worldTimesTable.getWorldTimes(userId);
|
Map<String, Long> worldTimes = worldTimesTable.getWorldTimes(userId);
|
||||||
WorldTimes worldT = data.getWorldTimes();
|
WorldTimes worldT = data.getWorldTimes();
|
||||||
worldT.setTimes(worldTimes);
|
// worldT.setTimes(worldTimes); //TODO
|
||||||
if (worldT.getLastStateChange() == 0) {
|
// if (worldT.getLastStateChange() == 0) {
|
||||||
worldT.setLastStateChange(data.getPlayTime());
|
// worldT.setLastStateChange(data.getPlayTime());
|
||||||
}
|
// }
|
||||||
|
|
||||||
List<SessionData> sessions = sessionsTable.getSessionData(userId);
|
List<SessionData> sessions = sessionsTable.getSessionData(userId);
|
||||||
data.addSessions(sessions);
|
data.addSessions(sessions);
|
||||||
@ -419,7 +414,6 @@ public abstract class SQLDB extends Database {
|
|||||||
Map<Integer, Set<InetAddress>> ipList = ipsTable.getIPList(ids);
|
Map<Integer, Set<InetAddress>> ipList = ipsTable.getIPList(ids);
|
||||||
Map<Integer, List<KillData>> playerKills = killsTable.getPlayerKills(ids, idUuidRel);
|
Map<Integer, List<KillData>> playerKills = killsTable.getPlayerKills(ids, idUuidRel);
|
||||||
Map<Integer, List<SessionData>> sessionData = sessionsTable.getSessionData(ids);
|
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);
|
Map<Integer, Map<String, Long>> worldTimes = worldTimesTable.getWorldTimes(ids);
|
||||||
|
|
||||||
Log.debug("Database",
|
Log.debug("Database",
|
||||||
@ -431,7 +425,6 @@ public abstract class SQLDB extends Database {
|
|||||||
" IPs: " + ipList.size(),
|
" IPs: " + ipList.size(),
|
||||||
" Kills: " + playerKills.size(),
|
" Kills: " + playerKills.size(),
|
||||||
" Sessions: " + sessionData.size(),
|
" Sessions: " + sessionData.size(),
|
||||||
" GM Times: " + gmTimes.size(),
|
|
||||||
" World Times: " + worldTimes.size()
|
" World Times: " + worldTimes.size()
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -446,12 +439,11 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
uData.addSessions(sessionData.get(id));
|
uData.addSessions(sessionData.get(id));
|
||||||
uData.setPlayerKills(playerKills.get(id));
|
uData.setPlayerKills(playerKills.get(id));
|
||||||
uData.getGmTimes().setTimes(gmTimes.get(id));
|
|
||||||
WorldTimes worldT = uData.getWorldTimes();
|
WorldTimes worldT = uData.getWorldTimes();
|
||||||
worldT.setTimes(worldTimes.get(id));
|
// worldT.setTimes(worldTimes.get(id)); //TODO
|
||||||
if (worldT.getLastStateChange() == 0) {
|
// if (worldT.getLastStateChange() == 0) {
|
||||||
worldT.setLastStateChange(uData.getPlayTime());
|
// worldT.setLastStateChange(uData.getPlayTime());
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark.stop("Database", "Get UserData for " + uuidsCol.size());
|
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<>();
|
Map<Integer, Map<String, Long>> worldTimes = new HashMap<>();
|
||||||
|
|
||||||
// Put in data set
|
// Put in data set
|
||||||
List<String> worldNames = data.stream()
|
// List<String> worldNames = data.stream() //TODO
|
||||||
.map(UserData::getWorldTimes)
|
// .map(UserData::getWorldTimes)
|
||||||
.map(WorldTimes::getTimes)
|
// .map(WorldTimes::getTimes)
|
||||||
.map(Map::keySet)
|
// .map(Map::keySet)
|
||||||
.flatMap(Collection::stream)
|
// .flatMap(Collection::stream)
|
||||||
.distinct()
|
// .distinct()
|
||||||
.collect(Collectors.toList());
|
// .collect(Collectors.toList());
|
||||||
|
|
||||||
for (Map.Entry<UUID, UserData> entrySet : userDatas.entrySet()) {
|
for (Map.Entry<UUID, UserData> entrySet : userDatas.entrySet()) {
|
||||||
UUID uuid = entrySet.getKey();
|
UUID uuid = entrySet.getKey();
|
||||||
@ -518,7 +510,7 @@ public abstract class SQLDB extends Database {
|
|||||||
kills.put(id, new ArrayList<>(uData.getPlayerKills()));
|
kills.put(id, new ArrayList<>(uData.getPlayerKills()));
|
||||||
sessions.put(id, new ArrayList<>(uData.getSessions()));
|
sessions.put(id, new ArrayList<>(uData.getSessions()));
|
||||||
gmTimes.put(id, new HashMap<>(uData.getGmTimes().getTimes()));
|
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
|
// Save
|
||||||
@ -526,8 +518,7 @@ public abstract class SQLDB extends Database {
|
|||||||
ipsTable.saveIPList(ips);
|
ipsTable.saveIPList(ips);
|
||||||
killsTable.savePlayerKills(kills, uuids);
|
killsTable.savePlayerKills(kills, uuids);
|
||||||
sessionsTable.saveSessionData(sessions);
|
sessionsTable.saveSessionData(sessions);
|
||||||
gmTimesTable.saveGMTimes(gmTimes);
|
// TODO worldTable.saveWorlds(worldNames);
|
||||||
worldTable.saveWorlds(worldNames);
|
|
||||||
worldTimesTable.saveWorldTimes(worldTimes);
|
worldTimesTable.saveWorldTimes(worldTimes);
|
||||||
commit();
|
commit();
|
||||||
userDatas.values().stream()
|
userDatas.values().stream()
|
||||||
@ -561,9 +552,8 @@ public abstract class SQLDB extends Database {
|
|||||||
nicknamesTable.saveNickList(userId, new HashSet<>(data.getNicknames()), data.getLastNick());
|
nicknamesTable.saveNickList(userId, new HashSet<>(data.getNicknames()), data.getLastNick());
|
||||||
ipsTable.saveIPList(userId, new HashSet<>(data.getIps()));
|
ipsTable.saveIPList(userId, new HashSet<>(data.getIps()));
|
||||||
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
||||||
gmTimesTable.saveGMTimes(userId, data.getGmTimes().getTimes());
|
// TODO worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
||||||
worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
// worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
||||||
worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
|
||||||
data.stopAccessing();
|
data.stopAccessing();
|
||||||
commit();
|
commit();
|
||||||
Benchmark.stop("Database", "Save Single UserData");
|
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.setDeaths(set.getInt(columnDeaths));
|
||||||
data.setMobKills(set.getInt(columnMobKills));
|
data.setMobKills(set.getInt(columnMobKills));
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||||
String lastWorld = set.getString(columnLastWorld);
|
// String lastWorld = set.getString(columnLastWorld);
|
||||||
if (!"Unknown".equals(lastWorld)) {
|
// if (!"Unknown".equals(lastWorld)) {
|
||||||
worldTimes.setState(lastWorld);
|
// worldTimes.setState(lastWorld);
|
||||||
} else {
|
// } else {
|
||||||
worldTimes.setLastStateChange(playTime);
|
// worldTimes.setLastStateChange(playTime);
|
||||||
}
|
// }
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -415,13 +415,13 @@ public class UsersTable extends Table {
|
|||||||
data.setDeaths(set.getInt(columnDeaths));
|
data.setDeaths(set.getInt(columnDeaths));
|
||||||
data.setMobKills(set.getInt(columnMobKills));
|
data.setMobKills(set.getInt(columnMobKills));
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||||
String lastWorld = set.getString(columnLastWorld);
|
// String lastWorld = set.getString(columnLastWorld);
|
||||||
if (!"Unknown".equals(lastWorld)) {
|
// if (!"Unknown".equals(lastWorld)) {
|
||||||
worldTimes.setState(lastWorld);
|
// worldTimes.setState(lastWorld);
|
||||||
} else {
|
// } else {
|
||||||
worldTimes.setLastStateChange(playTime);
|
// worldTimes.setLastStateChange(playTime);
|
||||||
}
|
// }
|
||||||
datas.add(data);
|
datas.add(data);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -454,13 +454,13 @@ public class UsersTable extends Table {
|
|||||||
data.setDeaths(set.getInt(columnDeaths));
|
data.setDeaths(set.getInt(columnDeaths));
|
||||||
data.setMobKills(set.getInt(columnMobKills));
|
data.setMobKills(set.getInt(columnMobKills));
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||||
String lastWorld = set.getString(columnLastWorld);
|
// String lastWorld = set.getString(columnLastWorld);
|
||||||
if (!"Unknown".equals(lastWorld)) {
|
// if (!"Unknown".equals(lastWorld)) {
|
||||||
worldTimes.setState(lastWorld);
|
// worldTimes.setState(lastWorld);
|
||||||
} else {
|
// } else {
|
||||||
worldTimes.setLastStateChange(playTime);
|
// worldTimes.setLastStateChange(playTime);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
close(set);
|
close(set);
|
||||||
@ -497,13 +497,13 @@ public class UsersTable extends Table {
|
|||||||
gmTimes.setState(set.getString(columnLastGM));
|
gmTimes.setState(set.getString(columnLastGM));
|
||||||
gmTimes.setLastStateChange(set.getLong(columnLastGMSwapTime));
|
gmTimes.setLastStateChange(set.getLong(columnLastGMSwapTime));
|
||||||
WorldTimes worldTimes = uData.getWorldTimes();
|
WorldTimes worldTimes = uData.getWorldTimes();
|
||||||
worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
// TODO worldTimes.setLastStateChange(set.getLong(columnLastWorldSwapTime));
|
||||||
String lastWorld = set.getString(columnLastWorld);
|
// String lastWorld = set.getString(columnLastWorld);
|
||||||
if (!"Unknown".equals(lastWorld)) {
|
// if (!"Unknown".equals(lastWorld)) {
|
||||||
worldTimes.setState(lastWorld);
|
// worldTimes.setState(lastWorld);
|
||||||
} else {
|
// } else {
|
||||||
worldTimes.setLastStateChange(playTime);
|
// worldTimes.setLastStateChange(playTime);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
close(set);
|
close(set);
|
||||||
@ -540,8 +540,8 @@ public class UsersTable extends Table {
|
|||||||
statement.setString(12, data.getName());
|
statement.setString(12, data.getName());
|
||||||
statement.setLong(13, data.getRegistered());
|
statement.setLong(13, data.getRegistered());
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
statement.setString(14, worldTimes.getState());
|
// TODO statement.setString(14, worldTimes.getState());
|
||||||
statement.setLong(15, worldTimes.getLastStateChange());
|
// statement.setLong(15, worldTimes.getLastStateChange());
|
||||||
statement.setString(16, uuid.toString());
|
statement.setString(16, uuid.toString());
|
||||||
update = statement.executeUpdate();
|
update = statement.executeUpdate();
|
||||||
}
|
}
|
||||||
@ -565,8 +565,8 @@ public class UsersTable extends Table {
|
|||||||
statement.setString(13, data.getName());
|
statement.setString(13, data.getName());
|
||||||
statement.setLong(14, data.getRegistered());
|
statement.setLong(14, data.getRegistered());
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
statement.setString(15, worldTimes.getState());
|
// TODO statement.setString(15, worldTimes.getState());
|
||||||
statement.setLong(16, worldTimes.getLastStateChange());
|
// statement.setLong(16, worldTimes.getLastStateChange());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -701,8 +701,8 @@ public class UsersTable extends Table {
|
|||||||
statement.setLong(14, uData.getRegistered());
|
statement.setLong(14, uData.getRegistered());
|
||||||
|
|
||||||
WorldTimes worldTimes = uData.getWorldTimes();
|
WorldTimes worldTimes = uData.getWorldTimes();
|
||||||
statement.setString(15, worldTimes.getState());
|
// TODO statement.setString(15, worldTimes.getState());
|
||||||
statement.setLong(16, worldTimes.getLastStateChange());
|
// statement.setLong(16, worldTimes.getLastStateChange());
|
||||||
|
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
}
|
}
|
||||||
@ -759,8 +759,8 @@ public class UsersTable extends Table {
|
|||||||
statement.setString(12, uData.getName());
|
statement.setString(12, uData.getName());
|
||||||
statement.setLong(13, uData.getRegistered());
|
statement.setLong(13, uData.getRegistered());
|
||||||
WorldTimes worldTimes = uData.getWorldTimes();
|
WorldTimes worldTimes = uData.getWorldTimes();
|
||||||
statement.setString(14, worldTimes.getState());
|
// TODO statement.setString(14, worldTimes.getState());
|
||||||
statement.setLong(15, worldTimes.getLastStateChange());
|
// statement.setLong(15, worldTimes.getLastStateChange());
|
||||||
statement.setString(16, uuid.toString());
|
statement.setString(16, uuid.toString());
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
uData.stopAccessing();
|
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.UserData;
|
||||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
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.PunchCardGraphCreator;
|
||||||
import main.java.com.djrapitops.plan.ui.html.graphs.WorldPieCreator;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -79,8 +78,8 @@ public class PlaceholderUtils {
|
|||||||
Set<SessionData> sessions = new HashSet<>(data.getSessions());
|
Set<SessionData> sessions = new HashSet<>(data.getSessions());
|
||||||
replaceMap.put("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessions));
|
replaceMap.put("punchCardSeries", PunchCardGraphCreator.createDataSeries(sessions));
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
replaceMap.put("worldSeries", WorldPieCreator.createSeriesData(worldTimes.getTimes()));
|
// TODO replaceMap.put("worldSeries", WorldPieCreator.createSeriesData(worldTimes.getTimes()));
|
||||||
replaceMap.put("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
|
// replaceMap.put("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
|
||||||
|
|
||||||
//TODO Plugin Tab content Web API
|
//TODO Plugin Tab content Web API
|
||||||
//TODO Player Plugin tab code.
|
//TODO Player Plugin tab code.
|
||||||
|
@ -277,10 +277,10 @@ public class Analysis {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, Long> worldTimes = uData.getWorldTimes().getTimes();
|
// TODO Map<String, Long> worldTimes = uData.getWorldTimes().getTimes();
|
||||||
for (Map.Entry<String, Long> world : worldTimes.entrySet()) {
|
// for (Map.Entry<String, Long> world : worldTimes.entrySet()) {
|
||||||
worldPart.addToWorld(world.getKey(), world.getValue());
|
// worldPart.addToWorld(world.getKey(), world.getValue());
|
||||||
}
|
// }
|
||||||
|
|
||||||
final long playTime = uData.getPlayTime();
|
final long playTime = uData.getPlayTime();
|
||||||
playtime.addToPlaytime(playTime);
|
playtime.addToPlaytime(playTime);
|
||||||
|
@ -63,6 +63,6 @@ public class LoginInfoTest {
|
|||||||
String geo = data.getGeolocation();
|
String geo = data.getGeolocation();
|
||||||
assertTrue("Wrong location " + geo, geo.equals("United States"));
|
assertTrue("Wrong location " + geo, geo.equals("United States"));
|
||||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
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("Playtime wrong", data.getPlayTime() == 10L);
|
||||||
assertTrue("Banned wrong", data.isBanned());
|
assertTrue("Banned wrong", data.isBanned());
|
||||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||||
assertEquals("World", data.getWorldTimes().getState());
|
// TODO assertEquals("World", data.getWorldTimes().getState());
|
||||||
assertEquals(1, data.getSessions().size());
|
assertEquals(1, data.getSessions().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,6 @@ public class ReloadInfoTest {
|
|||||||
assertEquals(nick, data.getLastNick());
|
assertEquals(nick, data.getLastNick());
|
||||||
assertEquals("United States", data.getGeolocation());
|
assertEquals("United States", data.getGeolocation());
|
||||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
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.setState("SURVIVAL");
|
||||||
gmTimes.setLastStateChange(10L);
|
gmTimes.setLastStateChange(10L);
|
||||||
WorldTimes worldTimes = data.getWorldTimes();
|
WorldTimes worldTimes = data.getWorldTimes();
|
||||||
worldTimes.setTime("World", 20L);
|
// TODO worldTimes.setTime("World", 20L);
|
||||||
worldTimes.setState("World");
|
// worldTimes.setState("World");
|
||||||
worldTimes.setLastStateChange(10L);
|
// worldTimes.setLastStateChange(10L);
|
||||||
db.saveUserData(data);
|
db.saveUserData(data);
|
||||||
data.addNickname("TestUpdateForSave");
|
data.addNickname("TestUpdateForSave");
|
||||||
db.saveUserData(data);
|
db.saveUserData(data);
|
||||||
@ -261,7 +261,7 @@ public class DatabaseTest {
|
|||||||
db.init();
|
db.init();
|
||||||
UserData data = MockUtils.mockUser();
|
UserData data = MockUtils.mockUser();
|
||||||
data.getGmTimes().setAllGMTimes(5L, 10L, 15L, 20L);
|
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.addIpAddress(InetAddress.getByName("185.64.113.61"));
|
||||||
data.addSession(new SessionData(1286349L, 2342978L));
|
data.addSession(new SessionData(1286349L, 2342978L));
|
||||||
data.addNickname("TestNick");
|
data.addNickname("TestNick");
|
||||||
|
Loading…
Reference in New Issue
Block a user