mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-04 06:21:43 +01:00
Logout & Kick Processing
Renaming handler to dataCache
This commit is contained in:
parent
b9c9f4d950
commit
5a7aa662e5
@ -192,9 +192,10 @@ public class Plan extends BukkitPlugin<Plan> {
|
|||||||
Log.error("WebServer was not successfully initialized.");
|
Log.error("WebServer was not successfully initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark.start("ServerInfo Registration");
|
//TODO Re-Enable after DB ServerTable has been initialized properly.
|
||||||
serverInfoManager = new ServerInfoManager(this);
|
// Benchmark.start("ServerInfo Registration");
|
||||||
Benchmark.stop("Enable", "ServerInfo Registration");
|
// serverInfoManager = new ServerInfoManager(this);
|
||||||
|
// Benchmark.stop("Enable", "ServerInfo Registration");
|
||||||
|
|
||||||
setupFilter(); // TODO Move to RegisterCommand Constructor
|
setupFilter(); // TODO Move to RegisterCommand Constructor
|
||||||
|
|
||||||
@ -398,7 +399,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
|||||||
*
|
*
|
||||||
* @return Current instance of the DataCache
|
* @return Current instance of the DataCache
|
||||||
*/
|
*/
|
||||||
public DataCache getHandler() {
|
public DataCache getDataCache() {
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class ManageRestoreCommand extends SubCommand {
|
|||||||
|
|
||||||
if (ManageUtils.clearAndCopy(database, backupDB)) {
|
if (ManageUtils.clearAndCopy(database, backupDB)) {
|
||||||
if (database.getConfigName().equals(plugin.getDB().getConfigName())) {
|
if (database.getConfigName().equals(plugin.getDB().getConfigName())) {
|
||||||
plugin.getHandler().getCommandUseFromDb();
|
plugin.getDataCache().getCommandUseFromDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||||
|
@ -33,7 +33,7 @@ public class InspectCacheHandler {
|
|||||||
* @param plugin Current instance of Plan.class
|
* @param plugin Current instance of Plan.class
|
||||||
*/
|
*/
|
||||||
public InspectCacheHandler(Plan plugin) {
|
public InspectCacheHandler(Plan plugin) {
|
||||||
this.handler = plugin.getHandler();
|
this.handler = plugin.getDataCache();
|
||||||
this.cache = new HashMap<>();
|
this.cache = new HashMap<>();
|
||||||
cacheTimes = new HashMap<>();
|
cacheTimes = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,11 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class BanProcessor extends PlayerProcessor {
|
public class BanProcessor extends PlayerProcessor {
|
||||||
|
|
||||||
public BanProcessor(UUID uuid) {
|
private final boolean banned;
|
||||||
|
|
||||||
|
public BanProcessor(UUID uuid, boolean banned) {
|
||||||
super(uuid);
|
super(uuid);
|
||||||
|
this.banned = banned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Licence is provided in the jar as license.yml also here:
|
||||||
|
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||||
|
*/
|
||||||
|
package main.java.com.djrapitops.plan.data.handling.player;
|
||||||
|
|
||||||
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* //TODO Class Javadoc Comment
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class EndSessionProcessor extends PlayerProcessor {
|
||||||
|
|
||||||
|
private final long time;
|
||||||
|
|
||||||
|
public EndSessionProcessor(UUID uuid, long time) {
|
||||||
|
super(uuid);
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
UUID uuid = getUUID();
|
||||||
|
Plan.getInstance().getDataCache().endSession(uuid, time);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Licence is provided in the jar as license.yml also here:
|
||||||
|
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||||
|
*/
|
||||||
|
package main.java.com.djrapitops.plan.data.handling.player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* //TODO Class Javadoc Comment
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class KickProcessor extends PlayerProcessor {
|
||||||
|
public KickProcessor(UUID uuid) {
|
||||||
|
super(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
UUID uuid = getUUID();
|
||||||
|
// TODO Update DB Kick +1
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ public class PlanCommandPreprocessListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
public PlanCommandPreprocessListener(Plan plugin) {
|
public PlanCommandPreprocessListener(Plan plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
handler = plugin.getHandler();
|
handler = plugin.getDataCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,23 +1,12 @@
|
|||||||
package main.java.com.djrapitops.plan.data.listeners;
|
package main.java.com.djrapitops.plan.data.listeners;
|
||||||
|
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
|
||||||
import com.djrapitops.plugin.utilities.player.Fetch;
|
import com.djrapitops.plugin.utilities.player.Fetch;
|
||||||
import com.djrapitops.plugin.utilities.player.Gamemode;
|
|
||||||
import com.djrapitops.plugin.utilities.player.IPlayer;
|
|
||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
import main.java.com.djrapitops.plan.data.Session;
|
import main.java.com.djrapitops.plan.data.Session;
|
||||||
import main.java.com.djrapitops.plan.data.UserData;
|
|
||||||
import main.java.com.djrapitops.plan.data.cache.DataCache;
|
import main.java.com.djrapitops.plan.data.cache.DataCache;
|
||||||
import main.java.com.djrapitops.plan.data.handling.DBCommitProcessor;
|
import main.java.com.djrapitops.plan.data.handling.DBCommitProcessor;
|
||||||
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
|
import main.java.com.djrapitops.plan.data.handling.player.*;
|
||||||
import main.java.com.djrapitops.plan.data.handling.info.LoginInfo;
|
|
||||||
import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo;
|
|
||||||
import main.java.com.djrapitops.plan.data.handling.player.BanProcessor;
|
|
||||||
import main.java.com.djrapitops.plan.data.handling.player.IPUpdateProcessor;
|
|
||||||
import main.java.com.djrapitops.plan.data.handling.player.NameProcessor;
|
|
||||||
import main.java.com.djrapitops.plan.data.handling.player.RegisterProcessor;
|
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -27,7 +16,6 @@ import org.bukkit.event.player.PlayerKickEvent;
|
|||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +38,7 @@ public class PlanPlayerListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
public PlanPlayerListener(Plan plugin) {
|
public PlanPlayerListener(Plan plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
cache = plugin.getHandler();
|
cache = plugin.getDataCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
@ -58,25 +46,23 @@ public class PlanPlayerListener implements Listener {
|
|||||||
PlayerLoginEvent.Result result = event.getResult();
|
PlayerLoginEvent.Result result = event.getResult();
|
||||||
UUID uuid = event.getPlayer().getUniqueId();
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
if (result == PlayerLoginEvent.Result.KICK_BANNED) {
|
if (result == PlayerLoginEvent.Result.KICK_BANNED) {
|
||||||
plugin.addToProcessQueue(new BanProcessor(uuid));
|
plugin.addToProcessQueue(new BanProcessor(uuid, true));
|
||||||
|
} else {
|
||||||
|
plugin.addToProcessQueue(new BanProcessor(uuid, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerJoinEvent Listener.
|
* PlayerJoinEvent Listener.
|
||||||
* <p>
|
* <p>
|
||||||
* If player is a new player, creates new data for the player.
|
* Adds processing information to the Queue.
|
||||||
* <p>
|
|
||||||
* Adds a LoginInfo to the processingQueue if the user is not new.
|
|
||||||
*
|
*
|
||||||
* @param event The Fired event.
|
* @param event The Fired event.
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
plugin.getNotificationCenter().checkNotifications(Fetch.wrapBukkit(player));
|
||||||
IPlayer iPlayer = Fetch.wrapBukkit(player);
|
|
||||||
plugin.getNotificationCenter().checkNotifications(iPlayer);
|
|
||||||
|
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
long time = MiscUtils.getTime();
|
long time = MiscUtils.getTime();
|
||||||
@ -99,31 +85,6 @@ public class PlanPlayerListener implements Listener {
|
|||||||
new NameProcessor(uuid, playerName, displayName),
|
new NameProcessor(uuid, playerName, displayName),
|
||||||
new DBCommitProcessor(plugin.getDB())
|
new DBCommitProcessor(plugin.getDB())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
plugin.getRunnableFactory().createNew(new AbsRunnable("NewPlayerCheckTask") {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
long time = MiscUtils.getTime();
|
|
||||||
InetAddress ip = player.getAddress().getAddress();
|
|
||||||
boolean banned = player.isBanned();
|
|
||||||
String displayName = player.getDisplayName();
|
|
||||||
String gm = player.getGameMode().name();
|
|
||||||
String worldName = player.getWorld().getName();
|
|
||||||
|
|
||||||
LoginInfo loginInfo = new LoginInfo(uuid, time, ip, banned, displayName, gm, 1, worldName);
|
|
||||||
boolean isNewPlayer = !plugin.getDB().wasSeenBefore(uuid);
|
|
||||||
|
|
||||||
if (isNewPlayer) {
|
|
||||||
UserData newUserData = NewPlayerCreator.createNewPlayer(iPlayer);
|
|
||||||
loginInfo.process(newUserData);
|
|
||||||
// TODO Rewrite Register & Login system cache.newPlayer(newUserData);
|
|
||||||
} else {
|
|
||||||
// cache.addToPool(loginInfo);
|
|
||||||
}
|
|
||||||
this.cancel();
|
|
||||||
}
|
|
||||||
}).runTaskAsynchronously();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,23 +96,21 @@ public class PlanPlayerListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
// TODO Rewrite Logout system
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
cache.endSession(uuid);
|
|
||||||
|
|
||||||
long time = MiscUtils.getTime();
|
long time = MiscUtils.getTime();
|
||||||
boolean banned = player.isBanned();
|
Player player = event.getPlayer();
|
||||||
Gamemode gm = Gamemode.wrap(player.getGameMode());
|
UUID uuid = player.getUniqueId();
|
||||||
String worldName = player.getWorld().getName();
|
|
||||||
|
|
||||||
plugin.addToProcessQueue(new LogoutInfo(uuid, time, banned, gm.name(), worldName));
|
plugin.addToProcessQueue(
|
||||||
|
new BanProcessor(uuid, player.isBanned()),
|
||||||
|
new EndSessionProcessor(uuid, time)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerKickEvent Listener.
|
* PlayerKickEvent Listener.
|
||||||
* <p>
|
* <p>
|
||||||
* Adds a KickInfo & LogoutInfo to the processing Queue.
|
* After KickEvent, the QuitEvent is automatically called.
|
||||||
*
|
*
|
||||||
* @param event Fired event
|
* @param event Fired event
|
||||||
*/
|
*/
|
||||||
@ -160,18 +119,7 @@ public class PlanPlayerListener implements Listener {
|
|||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
Player player = event.getPlayer();
|
plugin.addToProcessQueue(new KickProcessor(uuid));
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
|
|
||||||
cache.endSession(uuid);
|
|
||||||
|
|
||||||
long time = MiscUtils.getTime();
|
|
||||||
boolean banned = player.isBanned();
|
|
||||||
Gamemode gm = Gamemode.wrap(player.getGameMode());
|
|
||||||
String worldName = player.getWorld().getName();
|
|
||||||
//TODO String geoLocation = GeolocationCacheHandler.getCountry(ip.getHostAddress());
|
|
||||||
plugin.addToProcessQueue(new LogoutInfo(uuid, time, banned, gm.name(), worldName));
|
|
||||||
plugin.addToProcessQueue(new KickInfo(uuid));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class TPSCountTimer extends AbsRunnable {
|
|||||||
public TPSCountTimer(Plan plugin) {
|
public TPSCountTimer(Plan plugin) {
|
||||||
super("TPSCountTimer");
|
super("TPSCountTimer");
|
||||||
lastCheckNano = -1;
|
lastCheckNano = -1;
|
||||||
this.handler = plugin.getHandler();
|
this.handler = plugin.getDataCache();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
history = new ArrayList<>();
|
history = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
|||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
@Deprecated // TODO Remove once sure that this is unnecessary.
|
||||||
public class NewPlayerCreator {
|
public class NewPlayerCreator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +46,6 @@ public class NewPlayerCreator {
|
|||||||
* @return a new UserData object
|
* @return a new UserData object
|
||||||
*/
|
*/
|
||||||
public static UserData createNewPlayer(IOfflinePlayer player, Gamemode gm) {
|
public static UserData createNewPlayer(IOfflinePlayer player, Gamemode gm) {
|
||||||
// TODO Rewrite
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public class Analysis {
|
|||||||
rawData.sort(new UserDataLastPlayedComparator());
|
rawData.sort(new UserDataLastPlayedComparator());
|
||||||
List<UUID> uuids = rawData.stream().map(UserData::getUuid).collect(Collectors.toList());
|
List<UUID> uuids = rawData.stream().map(UserData::getUuid).collect(Collectors.toList());
|
||||||
Benchmark.start("Create Empty dataset");
|
Benchmark.start("Create Empty dataset");
|
||||||
DataCache handler = plugin.getHandler();
|
DataCache handler = plugin.getDataCache();
|
||||||
Map<String, Integer> commandUse = handler.getCommandUse();
|
Map<String, Integer> commandUse = handler.getCommandUse();
|
||||||
|
|
||||||
AnalysisData analysisData = new AnalysisData(commandUse, tpsData);
|
AnalysisData analysisData = new AnalysisData(commandUse, tpsData);
|
||||||
|
@ -56,7 +56,7 @@ public class QueueTest {
|
|||||||
public void startAsyncPeriodicSaveTask() {
|
public void startAsyncPeriodicSaveTask() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
when(plan.getHandler()).thenReturn(handler);
|
when(plan.getDataCache()).thenReturn(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
Loading…
Reference in New Issue
Block a user