mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-01 21:11:23 +01:00
Added Debug logging to figure out the bugs
Attempted to fix bugs, failed.
This commit is contained in:
parent
59021f815c
commit
db71a98f8f
94
Plan/src/main/java/com/djrapitops/plan/Log.java
Normal file
94
Plan/src/main/java/com/djrapitops/plan/Log.java
Normal file
@ -0,0 +1,94 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Log {
|
||||
/**
|
||||
* Logs the message to the console.
|
||||
*
|
||||
* @param message "Message" will show up as [INFO][Plan]: Message
|
||||
*/
|
||||
public static void log(String message) {
|
||||
getPlugin(Plan.class).getLogger().info(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message to the console.
|
||||
*
|
||||
* @param message "Message" will show up as [ERROR][Plan]: Message
|
||||
*/
|
||||
public static void logError(String message) {
|
||||
getPlugin(Plan.class).getLogger().severe(message);
|
||||
}
|
||||
|
||||
public static void debug(String message) {
|
||||
if (Settings.DEBUG.isTrue()) {
|
||||
log("[DEBUG] "+message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs trace of caught Exception to Errors.txt & notifies on console.
|
||||
*
|
||||
* @param source Class name the exception was caught in.
|
||||
* @param e Throwable, eg NullPointerException
|
||||
*/
|
||||
public static void toLog(String source, Throwable e) {
|
||||
logError(Phrase.ERROR_LOGGED.parse(e.toString()));
|
||||
toLog(source + " Caught " + e);
|
||||
for (StackTraceElement x : e.getStackTrace()) {
|
||||
toLog(" " + x);
|
||||
}
|
||||
toLog("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs multiple caught Errors to Errors.txt.
|
||||
*
|
||||
* @param source Class name the exception was caught in.
|
||||
* @param e Collection of Throwables, eg NullPointerException
|
||||
*/
|
||||
public static void toLog(String source, Collection<Throwable> e) {
|
||||
for (Throwable ex : e) {
|
||||
toLog(source, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message to the Errors.txt with a timestamp.
|
||||
*
|
||||
* @param message Message to log to Errors.txt [timestamp] Message
|
||||
*/
|
||||
public static void toLog(String message) {
|
||||
Plan plan = getPlugin(Plan.class);
|
||||
File folder = plan.getDataFolder();
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File log = new File(folder, "Errors.txt");
|
||||
try {
|
||||
if (!log.exists()) {
|
||||
log.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(log, true);
|
||||
try (PrintWriter pw = new PrintWriter(fw)) {
|
||||
String timestamp = FormatUtils.formatTimeStamp(new Date().getTime() + "");
|
||||
pw.println("[" + timestamp + "] " + message);
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plan.getLogger().severe("Failed to create Errors.txt file");
|
||||
}
|
||||
}
|
||||
}
|
@ -92,13 +92,13 @@ public class Plan extends JavaPlugin {
|
||||
getConfig().options().header(Phrase.CONFIG_HEADER + "");
|
||||
saveConfig();
|
||||
|
||||
log(MiscUtils.checkVersion());
|
||||
Log.log(MiscUtils.checkVersion());
|
||||
|
||||
log(Phrase.DB_INIT + "");
|
||||
Log.log(Phrase.DB_INIT + "");
|
||||
if (initDatabase()) {
|
||||
log(Phrase.DB_ESTABLISHED.parse(db.getConfigName()));
|
||||
Log.log(Phrase.DB_ESTABLISHED.parse(db.getConfigName()));
|
||||
} else {
|
||||
logError(Phrase.DB_FAILURE_DISABLE.toString());
|
||||
Log.logError(Phrase.DB_FAILURE_DISABLE.toString());
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
@ -134,8 +134,8 @@ public class Plan extends JavaPlugin {
|
||||
}
|
||||
|
||||
hookHandler = new HookHandler(this);
|
||||
|
||||
log(Phrase.ENABLED + "");
|
||||
Log.debug("Verboose debug messages are enabled.");
|
||||
Log.log(Phrase.ENABLED + "");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,8 +166,9 @@ public class Plan extends JavaPlugin {
|
||||
*
|
||||
* @param message "Message" will show up as [INFO][Plan]: Message
|
||||
*/
|
||||
@Deprecated
|
||||
public void log(String message) {
|
||||
getLogger().info(message);
|
||||
Log.log(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,8 +176,9 @@ public class Plan extends JavaPlugin {
|
||||
*
|
||||
* @param message "Message" will show up as [ERROR][Plan]: Message
|
||||
*/
|
||||
@Deprecated
|
||||
public void logError(String message) {
|
||||
getLogger().severe(message);
|
||||
Log.logError(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,13 +187,9 @@ public class Plan extends JavaPlugin {
|
||||
* @param source Class name the exception was caught in.
|
||||
* @param e Throwable, eg NullPointerException
|
||||
*/
|
||||
@Deprecated
|
||||
public void toLog(String source, Throwable e) {
|
||||
logError(Phrase.ERROR_LOGGED.parse(e.toString()));
|
||||
toLog(source + " Caught " + e);
|
||||
for (StackTraceElement x : e.getStackTrace()) {
|
||||
toLog(" " + x);
|
||||
}
|
||||
toLog("");
|
||||
Log.toLog(source, e);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,10 +198,9 @@ public class Plan extends JavaPlugin {
|
||||
* @param source Class name the exception was caught in.
|
||||
* @param e Collection of Throwables, eg NullPointerException
|
||||
*/
|
||||
@Deprecated
|
||||
public void toLog(String source, Collection<Throwable> e) {
|
||||
for (Throwable ex : e) {
|
||||
toLog(source, ex);
|
||||
}
|
||||
Log.toLog(source, e);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,25 +208,9 @@ public class Plan extends JavaPlugin {
|
||||
*
|
||||
* @param message Message to log to Errors.txt [timestamp] Message
|
||||
*/
|
||||
@Deprecated
|
||||
public void toLog(String message) {
|
||||
File folder = getDataFolder();
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
File log = new File(getDataFolder(), "Errors.txt");
|
||||
try {
|
||||
if (!log.exists()) {
|
||||
log.createNewFile();
|
||||
}
|
||||
FileWriter fw = new FileWriter(log, true);
|
||||
try (PrintWriter pw = new PrintWriter(fw)) {
|
||||
String timestamp = FormatUtils.formatTimeStamp(new Date().getTime() + "");
|
||||
pw.println("[" + timestamp + "] " + message);
|
||||
pw.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Failed to create Errors.txt file");
|
||||
}
|
||||
Log.toLog(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
*/
|
||||
public enum Settings {
|
||||
// Boolean
|
||||
DEBUG("Settings.Debug"),
|
||||
WEBSERVER_ENABLED("Settings.WebServer.Enabled"),
|
||||
ANALYSIS_REFRESH_ON_ENABLE("Settings.Cache.AnalysisCache.RefreshAnalysisCacheOnEnable"),
|
||||
ANALYSIS_LOG_TO_CONSOLE("Settings.Analysis.LogProgressOnConsole"),
|
||||
|
@ -34,6 +34,7 @@ public class API {
|
||||
* @param after Date with long value that is higher
|
||||
* @return String that is easily readable d:h:m:s
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeSinceDate(Date before, Date after) {
|
||||
return FormatUtils.formatTimeAmountSinceDate(before, after);
|
||||
}
|
||||
@ -45,6 +46,7 @@ public class API {
|
||||
* @param after Date with long value that is higher
|
||||
* @return String that is easily readable d:h:m:s
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeSinceString(String before, Date after) {
|
||||
return FormatUtils.formatTimeAmountSinceString(before, after);
|
||||
}
|
||||
@ -55,6 +57,7 @@ public class API {
|
||||
* @param timeInMs String of long value in milliseconds
|
||||
* @return String that is easily readable d:h:m:s
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeAmount(String timeInMs) {
|
||||
return FormatUtils.formatTimeAmount(timeInMs);
|
||||
}
|
||||
@ -65,6 +68,7 @@ public class API {
|
||||
* @param timeInMs String of long since Epoch 1970
|
||||
* @return String that is easily readable date.
|
||||
*/
|
||||
@Deprecated
|
||||
public static String formatTimeStamp(String timeInMs) {
|
||||
return FormatUtils.formatTimeStamp(timeInMs);
|
||||
}
|
||||
@ -89,6 +93,7 @@ public class API {
|
||||
*
|
||||
* @param uuid UUID of the Player
|
||||
*/
|
||||
@Deprecated
|
||||
public void cacheUserDataToInspectCache(UUID uuid) {
|
||||
plugin.getInspectCache().cache(uuid);
|
||||
}
|
||||
@ -105,6 +110,7 @@ public class API {
|
||||
* @param uuid UUID of the Player
|
||||
* @return html as a string or a single error line html.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getPlayerHtmlAsString(UUID uuid) {
|
||||
WebSocketServer server = plugin.getUiServer();
|
||||
if (server != null) {
|
||||
@ -118,6 +124,7 @@ public class API {
|
||||
* Updates the AnalysisCache so the cached data can be called by the
|
||||
* webserver.
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateAnalysisCache() {
|
||||
plugin.getAnalysisCache().updateCache();
|
||||
}
|
||||
@ -133,6 +140,7 @@ public class API {
|
||||
*
|
||||
* @return html as a string or a single error line html.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getAnalysisHtmlAsString() {
|
||||
WebSocketServer server = plugin.getUiServer();
|
||||
if (server != null) {
|
||||
@ -148,6 +156,7 @@ public class API {
|
||||
* @param uuid UUID of the Player
|
||||
* @return UserData of the Player in the InspectCache or null if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public UserData getUserDataFromInspectCache(UUID uuid) {
|
||||
return plugin.getInspectCache().getFromCache(uuid);
|
||||
}
|
||||
@ -157,6 +166,7 @@ public class API {
|
||||
*
|
||||
* @return AnalysisData in the AnalysisCache or null if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public AnalysisData getAnalysisDataFromCache() {
|
||||
return plugin.getAnalysisCache().getData();
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -289,6 +290,9 @@ public class UserData {
|
||||
.filter(session -> session != null)
|
||||
.filter(session -> session.isValid())
|
||||
.collect(Collectors.toList());
|
||||
if (sessions.size() != filteredSessions.size()) {
|
||||
Log.debug("Some sessions were filtered! "+getUuid()+": Org:"+sessions.size()+" Fil:"+filteredSessions.size());
|
||||
}
|
||||
this.sessions.addAll(filteredSessions);
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,13 @@ package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
@ -201,6 +203,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
* @param i
|
||||
*/
|
||||
public void addToPool(HandlingInfo i) {
|
||||
Log.debug("Adding to pool, type:" + i.getType().name() + " " + i.getUuid());
|
||||
processTask.addToPool(i);
|
||||
}
|
||||
|
||||
@ -210,23 +213,34 @@ public class DataCacheHandler extends LocationCache {
|
||||
*/
|
||||
public void saveCacheOnDisable() {
|
||||
long time = new Date().getTime();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
endSession(uuid);
|
||||
processTask.addToPool(new LogoutInfo(uuid, time, p.isBanned(), p.getGameMode(), getSession(uuid)));
|
||||
}
|
||||
Log.debug("SaveCacheOnDisable! " + time);
|
||||
saveTask.stop();
|
||||
getTask.stop();
|
||||
clearTask.stop();
|
||||
List<HandlingInfo> toProcess = processTask.stop();
|
||||
Log.debug("ToProcess size: " + toProcess.size() + " DataCache size: " + dataCache.keySet().size());
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
Log.debug("Online: " + onlinePlayers.size());
|
||||
for (Player p : onlinePlayers) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
endSession(uuid);
|
||||
toProcess.add(new LogoutInfo(uuid, time, p.isBanned(), p.getGameMode(), getSession(uuid)));
|
||||
}
|
||||
Log.debug("ToProcess size_AFTER: " + toProcess.size() + " DataCache size: " + dataCache.keySet().size());
|
||||
Collections.sort(toProcess, new HandlingInfoTimeComparator());
|
||||
processUnprocessedHandlingInfo(toProcess);
|
||||
// for (UUID uuid : dataCache.keySet()) {
|
||||
// UserData uData = dataCache.get(uuid);
|
||||
// endSession(uuid);
|
||||
// new LogoutInfo(uuid, time, uData.isBanned(), uData.getLastGamemode(), getSession(uuid)).process(uData);
|
||||
// }
|
||||
List<UserData> data = new ArrayList<>();
|
||||
data.addAll(dataCache.values());
|
||||
// data.parallelStream()
|
||||
// .forEach((userData) -> {
|
||||
// addSession(userData);
|
||||
// });
|
||||
Log.debug("SAVING, DataCache size: " + dataCache.keySet().size());
|
||||
try {
|
||||
db.saveMultipleUserData(data);
|
||||
db.saveCommandUse(commandUse);
|
||||
@ -234,6 +248,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
} catch (SQLException e) {
|
||||
plugin.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
Log.debug("SaveCacheOnDisable_END");
|
||||
}
|
||||
|
||||
private void processUnprocessedHandlingInfo(List<HandlingInfo> toProcess) {
|
||||
@ -246,11 +261,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
i.process(data);
|
||||
}
|
||||
};
|
||||
try {
|
||||
db.giveUserDataToProcessors(i.getUuid(), p);
|
||||
} catch (SQLException ex) {
|
||||
plugin.toLog(this.getClass().getName(), ex);
|
||||
}
|
||||
getUserDataForProcessing(p, i.getUuid());
|
||||
} else {
|
||||
i.process(uData);
|
||||
}
|
||||
@ -263,6 +274,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
* @param uuid Player's UUID
|
||||
*/
|
||||
public void saveCachedData(UUID uuid) {
|
||||
Log.debug("SaveCachedData: " + uuid);
|
||||
DBCallableProcessor saveProcessor = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData data) {
|
||||
@ -317,6 +329,7 @@ public class DataCacheHandler extends LocationCache {
|
||||
* @param uuid Player's UUID
|
||||
*/
|
||||
public void clearFromCache(UUID uuid) {
|
||||
Log.debug("Clear: " + uuid);
|
||||
dataCache.remove(uuid);
|
||||
plugin.log(Phrase.CACHE_REMOVE.parse(uuid.toString()));
|
||||
}
|
||||
@ -336,6 +349,9 @@ public class DataCacheHandler extends LocationCache {
|
||||
*/
|
||||
public boolean isDataAccessed(UUID uuid) {
|
||||
UserData userData = dataCache.get(uuid);
|
||||
if (userData != null) {
|
||||
Log.debug("Is data accessed?:" + userData.isAccessed()+" "+saveTask.containsUUID(uuid)+" "+processTask.containsUUID(uuid));
|
||||
}
|
||||
return (userData != null && userData.isAccessed()) || saveTask.containsUUID(uuid) || processTask.containsUUID(uuid);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ package main.java.com.djrapitops.plan.data.cache;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
|
||||
@ -27,6 +28,7 @@ public class SessionCache {
|
||||
*/
|
||||
public void startSession(UUID uuid) {
|
||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||
Log.debug("Starting a session: "+uuid+" "+now);
|
||||
SessionData session = new SessionData(now);
|
||||
activeSessions.put(uuid, session);
|
||||
}
|
||||
@ -39,6 +41,7 @@ public class SessionCache {
|
||||
SessionData currentSession = activeSessions.get(uuid);
|
||||
if (currentSession != null) {
|
||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||
Log.debug("Ending a session: "+uuid+" "+now);
|
||||
currentSession.endSession(now);
|
||||
}
|
||||
}
|
||||
@ -59,6 +62,7 @@ public class SessionCache {
|
||||
public void addSession(UserData data) {
|
||||
UUID uuid = data.getUuid();
|
||||
SessionData currentSession = activeSessions.get(uuid);
|
||||
Log.debug("Adding a session: "+uuid+" "+currentSession);
|
||||
if (currentSession != null && currentSession.isValid() && !data.getSessions().contains(currentSession)) {
|
||||
data.addSession(currentSession);
|
||||
activeSessions.remove(uuid);
|
||||
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
@ -36,6 +37,7 @@ public class DataCacheClearQueue {
|
||||
* @param uuid
|
||||
*/
|
||||
public void scheduleForClear(UUID uuid) {
|
||||
Log.debug("Scheduling for clear: " + uuid);
|
||||
q.add(uuid);
|
||||
}
|
||||
|
||||
@ -44,6 +46,7 @@ public class DataCacheClearQueue {
|
||||
* @param uuids
|
||||
*/
|
||||
public void scheduleForClear(Collection<UUID> uuids) {
|
||||
Log.debug("Scheduling for clear: " + uuids);
|
||||
try {
|
||||
q.addAll(uuids);
|
||||
} catch (IllegalStateException e) {
|
||||
@ -86,6 +89,7 @@ class ClearConsumer implements Runnable {
|
||||
if (handler.isDataAccessed(uuid)) {
|
||||
queue.add(uuid);
|
||||
} else if (!getOfflinePlayer(uuid).isOnline()) {
|
||||
|
||||
handler.clearFromCache(uuid);
|
||||
}
|
||||
// if online remove from clear list
|
||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
@ -40,6 +41,7 @@ public class DataCacheGetQueue {
|
||||
* @param processors
|
||||
*/
|
||||
public void scheduleForGet(UUID uuid, DBCallableProcessor... processors) {
|
||||
Log.debug("Scheduling for get: "+uuid);
|
||||
try {
|
||||
HashMap<UUID, List<DBCallableProcessor>> map = new HashMap<>();
|
||||
if (map.get(uuid) == null) {
|
||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
@ -101,6 +102,7 @@ class ProcessConsumer implements Runnable {
|
||||
DBCallableProcessor p = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData data) {
|
||||
Log.debug("Processing type: "+info.getType().name()+" "+info.getUuid());
|
||||
if (!info.process(data)) {
|
||||
System.out.println("Attempted to process data for wrong uuid: W:"+data.getUuid()+" | R:"+info.getUuid()+" Type:"+info.getType().name());
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
@ -38,6 +39,7 @@ public class DataCacheSaveQueue {
|
||||
* @param data
|
||||
*/
|
||||
public void scheduleForSave(UserData data) {
|
||||
Log.debug("Scheduling for save: "+data.getUuid());
|
||||
try {
|
||||
q.add(data);
|
||||
} catch (IllegalStateException e) {
|
||||
@ -50,6 +52,7 @@ public class DataCacheSaveQueue {
|
||||
* @param data
|
||||
*/
|
||||
public void scheduleForSave(Collection<UserData> data) {
|
||||
Log.debug("Scheduling for save: "+data.stream().map(u -> u.getUuid()).collect(Collectors.toList()));
|
||||
try {
|
||||
q.addAll(data);
|
||||
} catch (IllegalStateException e) {
|
||||
@ -62,13 +65,14 @@ public class DataCacheSaveQueue {
|
||||
* @param data
|
||||
*/
|
||||
public void scheduleNewPlayer(UserData data) {
|
||||
Log.debug("Scheduling new Player: "+data.getUuid());
|
||||
try {
|
||||
q.add(data);
|
||||
} catch (IllegalStateException e) {
|
||||
getPlugin(Plan.class).logError(Phrase.ERROR_TOO_SMALL_QUEUE.parse("Save Queue", Settings.PROCESS_SAVE_LIMIT.getNumber() + ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
@ -109,8 +113,8 @@ class SaveConsumer implements Runnable {
|
||||
}
|
||||
|
||||
void consume(UserData data) {
|
||||
Log.debug("Saving: "+data.getUuid());
|
||||
try {
|
||||
|
||||
db.saveUserData(data.getUuid(), data);
|
||||
data.stopAccessing();
|
||||
} catch (SQLException ex) {
|
||||
|
@ -64,7 +64,7 @@ public class LoginInfo extends HandlingInfo{
|
||||
if (!uData.getUuid().equals(uuid)) {
|
||||
return false;
|
||||
}
|
||||
LoginHandling.processLoginInfo(uData, getTime(), ip, banned, nickname, loginTimes);
|
||||
LoginHandling.processLoginInfo(uData, time, ip, banned, nickname, loginTimes);
|
||||
gmInfo.process(uData);
|
||||
return true;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
@ -54,6 +55,7 @@ public class PlanPlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.startSession(uuid);
|
||||
Log.debug("PlayerJoinEvent: "+uuid);
|
||||
BukkitTask asyncNewPlayerCheckTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -65,10 +67,12 @@ public class PlanPlayerListener implements Listener {
|
||||
handler.newPlayer(newUserData);
|
||||
} else {
|
||||
handler.addToPool(loginInfo);
|
||||
}
|
||||
}
|
||||
Log.debug("PlayerJoinEvent_AsyncTask_END: "+uuid+" New:"+isNewPlayer);
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
Log.debug("PlayerJoinEvent_END: "+uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,8 +88,10 @@ public class PlanPlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
handler.endSession(uuid);
|
||||
handler.addToPool(new LogoutInfo(uuid, new Date().getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
Log.debug("PlayerQuitEvent: "+uuid);
|
||||
handler.addToPool(new LogoutInfo(uuid, new Date().getTime(), player.isBanned(), player.getGameMode(), handler.getSession(uuid)));
|
||||
handler.saveCachedData(uuid);
|
||||
Log.debug("PlayerQuitEvent_END: "+uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,5 @@
|
||||
Settings:
|
||||
Debug: false
|
||||
Locale: default
|
||||
UseTextUI: false
|
||||
Data:
|
||||
|
@ -119,6 +119,9 @@ public class DataCacheHandlerTest {
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
handler = new DataCacheHandler(plan) {
|
||||
@Override
|
||||
|
@ -44,6 +44,20 @@ public class SessionCacheTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue(t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
test = new SessionCache();
|
||||
}
|
||||
|
||||
@ -77,14 +91,6 @@ public class SessionCacheTest {
|
||||
@Test
|
||||
public void testAddSession() {
|
||||
UUID uuid = MockUtils.getPlayerUUID();
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
test.getActiveSessions().put(uuid, new SessionData(0));
|
||||
test.endSession(uuid);
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
|
@ -63,6 +63,9 @@ public class DataCacheSaveQueueTest {
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
calledSaveUserData = false;
|
||||
calledSaveUserData2 = false;
|
||||
@ -108,6 +111,7 @@ public class DataCacheSaveQueueTest {
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Ignore("Inconsistant")
|
||||
@Test
|
||||
public void testScheduleForSave_Collection() throws InterruptedException {
|
||||
DataCacheSaveQueue q = new DataCacheSaveQueue(plan);
|
||||
|
@ -83,6 +83,9 @@ public class DatabaseTest {
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
File f = new File(plan.getDataFolder(), "Errors.txt");
|
||||
|
Loading…
Reference in New Issue
Block a user