First Session Message Counting

This commit is contained in:
Rsl1122 2017-08-25 09:13:54 +03:00
parent caece02f63
commit d9a9c653da
4 changed files with 27 additions and 9 deletions

View File

@ -5,7 +5,10 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import java.sql.SQLException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* This Class contains the Cache.
@ -25,7 +28,7 @@ public class DataCache extends SessionCache {
private final Map<UUID, String> playerNames;
private final Map<UUID, String> displayNames;
private final Set<UUID> playersWithFirstSession;
private final Map<UUID, Integer> firstSessionInformation;
/**
* Class Constructor.
@ -41,7 +44,7 @@ public class DataCache extends SessionCache {
playerNames = new HashMap<>();
displayNames = new HashMap<>();
playersWithFirstSession = new HashSet<>();
firstSessionInformation = new HashMap<>();
}
public void updateNames(UUID uuid, String playerName, String displayName) {
@ -70,14 +73,24 @@ public class DataCache extends SessionCache {
}
public void addFirstLeaveCheck(UUID uuid) {
playersWithFirstSession.add(uuid);
firstSessionInformation.put(uuid, 0);
}
public boolean isFirstSession(UUID uuid) {
return playersWithFirstSession.contains(uuid);
return firstSessionInformation.containsKey(uuid);
}
public void clearFromFirstLeaveCheck(UUID uuid) {
playersWithFirstSession.remove(uuid);
public void endFirstSessionActionTracking(UUID uuid) {
firstSessionInformation.remove(uuid);
}
public void firstSessionMessageSent(UUID uuid) {
Integer msgCount = firstSessionInformation.getOrDefault(uuid, 0);
msgCount++;
firstSessionInformation.put(uuid, msgCount);
}
public int getFirstSessionMsgCount(UUID uuid) {
return firstSessionInformation.getOrDefault(uuid, 0);
}
}

View File

@ -47,6 +47,11 @@ public class PlanChatListener implements Listener {
String name = p.getName();
String displayName = p.getDisplayName();
DataCache dataCache = plugin.getDataCache();
if (dataCache.isFirstSession(uuid)) {
dataCache.firstSessionMessageSent(uuid);
}
plugin.addToProcessQueue(new NameProcessor(uuid, name, displayName));
}
}

View File

@ -122,7 +122,7 @@ public class PlanPlayerListener implements Listener {
new EndSessionProcessor(uuid, time)
);
int messagesSent = 0; // TODO messages Sent on first session
int messagesSent = plugin.getDataCache().getFirstSessionMsgCount(uuid);
if (cache.isFirstSession(uuid)) {
plugin.addToProcessQueue(new FirstLeaveProcessor(uuid, time, messagesSent));

View File

@ -36,7 +36,7 @@ public class FirstLeaveProcessor extends PlayerProcessor {
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
} finally {
plugin.getDataCache().clearFromFirstLeaveCheck(uuid);
plugin.getDataCache().endFirstSessionActionTracking(uuid);
}
}
}