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.");
|
||||
}
|
||||
|
||||
Benchmark.start("ServerInfo Registration");
|
||||
serverInfoManager = new ServerInfoManager(this);
|
||||
Benchmark.stop("Enable", "ServerInfo Registration");
|
||||
//TODO Re-Enable after DB ServerTable has been initialized properly.
|
||||
// Benchmark.start("ServerInfo Registration");
|
||||
// serverInfoManager = new ServerInfoManager(this);
|
||||
// Benchmark.stop("Enable", "ServerInfo Registration");
|
||||
|
||||
setupFilter(); // TODO Move to RegisterCommand Constructor
|
||||
|
||||
@ -398,7 +399,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
*
|
||||
* @return Current instance of the DataCache
|
||||
*/
|
||||
public DataCache getHandler() {
|
||||
public DataCache getDataCache() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class ManageRestoreCommand extends SubCommand {
|
||||
|
||||
if (ManageUtils.clearAndCopy(database, backupDB)) {
|
||||
if (database.getConfigName().equals(plugin.getDB().getConfigName())) {
|
||||
plugin.getHandler().getCommandUseFromDb();
|
||||
plugin.getDataCache().getCommandUseFromDb();
|
||||
}
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||
|
@ -33,7 +33,7 @@ public class InspectCacheHandler {
|
||||
* @param plugin Current instance of Plan.class
|
||||
*/
|
||||
public InspectCacheHandler(Plan plugin) {
|
||||
this.handler = plugin.getHandler();
|
||||
this.handler = plugin.getDataCache();
|
||||
this.cache = new HashMap<>();
|
||||
cacheTimes = new HashMap<>();
|
||||
}
|
||||
|
@ -13,8 +13,11 @@ import java.util.UUID;
|
||||
*/
|
||||
public class BanProcessor extends PlayerProcessor {
|
||||
|
||||
public BanProcessor(UUID uuid) {
|
||||
private final boolean banned;
|
||||
|
||||
public BanProcessor(UUID uuid, boolean banned) {
|
||||
super(uuid);
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
@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) {
|
||||
this.plugin = plugin;
|
||||
handler = plugin.getHandler();
|
||||
handler = plugin.getDataCache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,23 +1,12 @@
|
||||
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.Gamemode;
|
||||
import com.djrapitops.plugin.utilities.player.IPlayer;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
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.handling.DBCommitProcessor;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
|
||||
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.data.handling.player.*;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
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.PlayerQuitEvent;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -50,7 +38,7 @@ public class PlanPlayerListener implements Listener {
|
||||
*/
|
||||
public PlanPlayerListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
cache = plugin.getHandler();
|
||||
cache = plugin.getDataCache();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -58,25 +46,23 @@ public class PlanPlayerListener implements Listener {
|
||||
PlayerLoginEvent.Result result = event.getResult();
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
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.
|
||||
* <p>
|
||||
* If player is a new player, creates new data for the player.
|
||||
* <p>
|
||||
* Adds a LoginInfo to the processingQueue if the user is not new.
|
||||
* Adds processing information to the Queue.
|
||||
*
|
||||
* @param event The Fired event.
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
IPlayer iPlayer = Fetch.wrapBukkit(player);
|
||||
plugin.getNotificationCenter().checkNotifications(iPlayer);
|
||||
plugin.getNotificationCenter().checkNotifications(Fetch.wrapBukkit(player));
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
@ -99,31 +85,6 @@ public class PlanPlayerListener implements Listener {
|
||||
new NameProcessor(uuid, playerName, displayName),
|
||||
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)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
// TODO Rewrite Logout system
|
||||
Player player = event.getPlayer();
|
||||
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();
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
plugin.addToProcessQueue(new LogoutInfo(uuid, time, banned, gm.name(), worldName));
|
||||
plugin.addToProcessQueue(
|
||||
new BanProcessor(uuid, player.isBanned()),
|
||||
new EndSessionProcessor(uuid, time)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerKickEvent Listener.
|
||||
* <p>
|
||||
* Adds a KickInfo & LogoutInfo to the processing Queue.
|
||||
* After KickEvent, the QuitEvent is automatically called.
|
||||
*
|
||||
* @param event Fired event
|
||||
*/
|
||||
@ -160,18 +119,7 @@ public class PlanPlayerListener implements Listener {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
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));
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
plugin.addToProcessQueue(new KickProcessor(uuid));
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class TPSCountTimer extends AbsRunnable {
|
||||
public TPSCountTimer(Plan plugin) {
|
||||
super("TPSCountTimer");
|
||||
lastCheckNano = -1;
|
||||
this.handler = plugin.getHandler();
|
||||
this.handler = plugin.getDataCache();
|
||||
this.plugin = plugin;
|
||||
history = new ArrayList<>();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated // TODO Remove once sure that this is unnecessary.
|
||||
public class NewPlayerCreator {
|
||||
|
||||
/**
|
||||
@ -45,7 +46,6 @@ public class NewPlayerCreator {
|
||||
* @return a new UserData object
|
||||
*/
|
||||
public static UserData createNewPlayer(IOfflinePlayer player, Gamemode gm) {
|
||||
// TODO Rewrite
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class Analysis {
|
||||
rawData.sort(new UserDataLastPlayedComparator());
|
||||
List<UUID> uuids = rawData.stream().map(UserData::getUuid).collect(Collectors.toList());
|
||||
Benchmark.start("Create Empty dataset");
|
||||
DataCache handler = plugin.getHandler();
|
||||
DataCache handler = plugin.getDataCache();
|
||||
Map<String, Integer> commandUse = handler.getCommandUse();
|
||||
|
||||
AnalysisData analysisData = new AnalysisData(commandUse, tpsData);
|
||||
|
@ -56,7 +56,7 @@ public class QueueTest {
|
||||
public void startAsyncPeriodicSaveTask() {
|
||||
}
|
||||
};
|
||||
when(plan.getHandler()).thenReturn(handler);
|
||||
when(plan.getDataCache()).thenReturn(handler);
|
||||
}
|
||||
|
||||
@After
|
||||
|
Loading…
Reference in New Issue
Block a user