mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Logout & Kick Processing
Renaming handler to dataCache Death Processing
This commit is contained in:
parent
5a7aa662e5
commit
96ff3b3fbf
@ -70,7 +70,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
private API api;
|
||||
|
||||
private ProcessingQueue processingQueue;
|
||||
private DataCache handler;
|
||||
private DataCache dataCache;
|
||||
private InspectCacheHandler inspectCache;
|
||||
private AnalysisCacheHandler analysisCache;
|
||||
private HookHandler hookHandler; // Manages 3rd party data sources
|
||||
@ -158,7 +158,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
Benchmark.stop("Enable", "Init Database");
|
||||
|
||||
Benchmark.start("Init DataCache");
|
||||
this.handler = new DataCache(this);
|
||||
this.dataCache = new DataCache(this);
|
||||
this.inspectCache = new InspectCacheHandler(this);
|
||||
this.analysisCache = new AnalysisCacheHandler(this);
|
||||
Benchmark.stop("Enable", "Init DataCache");
|
||||
@ -261,14 +261,14 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
if (Verify.notNull(handler, db)) {
|
||||
if (Verify.notNull(dataCache, db)) {
|
||||
Benchmark.start("Disable: DataCache Save");
|
||||
// Saves the DataCache to the database without Bukkit's Schedulers.
|
||||
Log.info(Locale.get(Msg.DISABLE_CACHE_SAVE).toString());
|
||||
|
||||
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
scheduler.execute(() -> {
|
||||
handler.saveCacheOnDisable();
|
||||
dataCache.saveCacheOnDisable();
|
||||
taskStatus().cancelAllKnownTasks();
|
||||
Benchmark.stop("Disable: DataCache Save");
|
||||
});
|
||||
@ -400,7 +400,7 @@ public class Plan extends BukkitPlugin<Plan> {
|
||||
* @return Current instance of the DataCache
|
||||
*/
|
||||
public DataCache getDataCache() {
|
||||
return handler;
|
||||
return dataCache;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +91,7 @@ public class DataCache extends SessionCache {
|
||||
* @throws IllegalStateException BukkitScheduler is in a wrong state.
|
||||
*/
|
||||
public void startAsyncPeriodicSaveTask() {
|
||||
DataCache handler = this;
|
||||
DataCache dataCache = this;
|
||||
plugin.getRunnableFactory().createNew(new AbsRunnable("PeriodicCacheSaveTask") {
|
||||
private int timesSaved = 0;
|
||||
|
||||
|
@ -23,7 +23,7 @@ import java.util.*;
|
||||
@Deprecated
|
||||
public class InspectCacheHandler {
|
||||
|
||||
private final DataCache handler;
|
||||
private final DataCache dataCache;
|
||||
private final Map<UUID, UserData> cache;
|
||||
private final Map<UUID, Long> cacheTimes;
|
||||
|
||||
@ -33,7 +33,7 @@ public class InspectCacheHandler {
|
||||
* @param plugin Current instance of Plan.class
|
||||
*/
|
||||
public InspectCacheHandler(Plan plugin) {
|
||||
this.handler = plugin.getDataCache();
|
||||
this.dataCache = plugin.getDataCache();
|
||||
this.cache = new HashMap<>();
|
||||
cacheTimes = new HashMap<>();
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package main.java.com.djrapitops.plan.data.handling;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -56,13 +54,4 @@ public class KillHandling {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a material name
|
||||
*
|
||||
* @param material The material
|
||||
* @return The normalized material name
|
||||
*/
|
||||
public static String normalizeMaterialName(Material material) {
|
||||
return WordUtils.capitalizeFully(material.name(), '_').replace('_', ' ');
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* HandlingInfo Class for DeathEvent information.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class DeathInfo extends HandlingInfo {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param uuid UUID of the dead player.
|
||||
*/
|
||||
public DeathInfo(UUID uuid) {
|
||||
super(uuid, InfoType.DEATH, 0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(UserData uData) {
|
||||
if (!uData.getUuid().equals(uuid)) {
|
||||
return;
|
||||
}
|
||||
//TODO uData.setDeaths(uData.getDeaths() + 1);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package main.java.com.djrapitops.plan.data.handling.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* // TODO Write Javadoc Class Description
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class DeathProcessor extends PlayerProcessor {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param uuid UUID of the dead player.
|
||||
*/
|
||||
public DeathProcessor(UUID uuid) {
|
||||
super(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
UUID uuid = getUUID();
|
||||
// TODO DB Update Deaths +1
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
@ -20,7 +19,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
public class PlanCommandPreprocessListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCache handler;
|
||||
private final DataCache dataCache;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -29,7 +28,7 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
*/
|
||||
public PlanCommandPreprocessListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
handler = plugin.getDataCache();
|
||||
dataCache = plugin.getDataCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,6 +41,10 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission(Permissions.IGNORE_COMMANDUSE.getPermission())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String commandName = event.getMessage().substring(1).split(" ")[0].toLowerCase();
|
||||
|
||||
@ -52,21 +55,13 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
Command command = plugin.getServer().getPluginCommand(commandName);
|
||||
if (command == null) {
|
||||
if (doNotLogUnknownCommands) {
|
||||
Log.debug("Ignored command, command is unknown");
|
||||
return;
|
||||
}
|
||||
} else if (combineCommandAliasesToMainCommand) {
|
||||
commandName = command.getName();
|
||||
}
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.hasPermission(Permissions.IGNORE_COMMANDUSE.getPermission())) {
|
||||
Log.debug("Ignored command, player had ignore permission.");
|
||||
return;
|
||||
}
|
||||
|
||||
handler.handleCommand(commandName);
|
||||
// TODO Command Usage -> DB Save Processor
|
||||
dataCache.handleCommand(commandName);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.handling.KillHandling;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.DeathInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.player.DeathProcessor;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -15,6 +16,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Event Listener for EntityDeathEvents.
|
||||
*
|
||||
@ -45,7 +48,7 @@ public class PlanDeathEventListener implements Listener {
|
||||
LivingEntity dead = event.getEntity();
|
||||
|
||||
if (dead instanceof Player) {
|
||||
plugin.addToProcessQueue(new DeathInfo(dead.getUniqueId()));
|
||||
plugin.addToProcessQueue(new DeathProcessor(dead.getUniqueId()));
|
||||
}
|
||||
|
||||
EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
|
||||
@ -56,6 +59,9 @@ public class PlanDeathEventListener implements Listener {
|
||||
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent;
|
||||
Entity killerEntity = entityDamageByEntityEvent.getDamager();
|
||||
|
||||
UUID killerUUID = null;
|
||||
String weapon = null;
|
||||
|
||||
if (killerEntity instanceof Player) {
|
||||
Player killer = (Player) killerEntity;
|
||||
Material itemInHand;
|
||||
@ -69,39 +75,44 @@ public class PlanDeathEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
plugin.addToProcessQueue(new KillInfo(killer.getUniqueId(), time, dead, KillHandling.normalizeMaterialName(itemInHand)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (killerEntity instanceof Wolf) {
|
||||
killerUUID = killer.getUniqueId();
|
||||
weapon = normalizeMaterialName(itemInHand);
|
||||
} else if (killerEntity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) killerEntity;
|
||||
|
||||
if (!wolf.isTamed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AnimalTamer owner = wolf.getOwner();
|
||||
|
||||
if (!(owner instanceof Player)) {
|
||||
return;
|
||||
if (owner instanceof Player) {
|
||||
killerUUID = owner.getUniqueId();
|
||||
weapon = "Wolf";
|
||||
}
|
||||
|
||||
plugin.addToProcessQueue(new KillInfo(owner.getUniqueId(), time, dead, "Wolf"));
|
||||
}
|
||||
|
||||
if (killerEntity instanceof Arrow) {
|
||||
} else if (killerEntity instanceof Arrow) {
|
||||
Arrow arrow = (Arrow) killerEntity;
|
||||
|
||||
ProjectileSource source = arrow.getShooter();
|
||||
|
||||
if (!(source instanceof Player)) {
|
||||
return;
|
||||
if (source instanceof Player) {
|
||||
Player player = (Player) source;
|
||||
killerUUID = player.getUniqueId();
|
||||
weapon = "Bow";
|
||||
}
|
||||
|
||||
Player player = (Player) source;
|
||||
|
||||
plugin.addToProcessQueue(new KillInfo(player.getUniqueId(), time, dead, "Bow"));
|
||||
}
|
||||
|
||||
if (Verify.notNull(killerUUID, weapon)) {
|
||||
|
||||
plugin.addToProcessQueue(new KillInfo(killerUUID, time, dead, weapon));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a material name
|
||||
*
|
||||
* @param material The material
|
||||
* @return The normalized material name
|
||||
*/
|
||||
private String normalizeMaterialName(Material material) {
|
||||
return WordUtils.capitalizeFully(material.name(), '_').replace('_', ' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,6 @@ public class PlanPlayerListener implements Listener {
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
* <p>
|
||||
* Copies the references to multiple handlers from Current instance of cache.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
@ -52,10 +50,27 @@ public class PlanPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerKickEvent Listener.
|
||||
* <p>
|
||||
* Adds processing information to the ProcessingQueue.
|
||||
* After KickEvent, the QuitEvent is automatically called.
|
||||
*
|
||||
* @param event Fired event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
plugin.addToProcessQueue(new KickProcessor(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerJoinEvent Listener.
|
||||
* <p>
|
||||
* Adds processing information to the Queue.
|
||||
* Adds processing information to the ProcessingQueue.
|
||||
*
|
||||
* @param event The Fired event.
|
||||
*/
|
||||
@ -90,7 +105,7 @@ public class PlanPlayerListener implements Listener {
|
||||
/**
|
||||
* PlayerQuitEvent Listener.
|
||||
* <p>
|
||||
* Adds a LogoutInfo to the processing Queue.
|
||||
* Adds processing information to the ProcessingQueue.
|
||||
*
|
||||
* @param event Fired event
|
||||
*/
|
||||
@ -106,20 +121,4 @@ public class PlanPlayerListener implements Listener {
|
||||
new EndSessionProcessor(uuid, time)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerKickEvent Listener.
|
||||
* <p>
|
||||
* After KickEvent, the QuitEvent is automatically called.
|
||||
*
|
||||
* @param event Fired event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
plugin.addToProcessQueue(new KickProcessor(uuid));
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||
public class TPSCountTimer extends AbsRunnable {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCache handler;
|
||||
private final DataCache dataCache;
|
||||
private final List<TPS> history;
|
||||
private long lastCheckNano;
|
||||
|
||||
@ -32,7 +32,7 @@ public class TPSCountTimer extends AbsRunnable {
|
||||
public TPSCountTimer(Plan plugin) {
|
||||
super("TPSCountTimer");
|
||||
lastCheckNano = -1;
|
||||
this.handler = plugin.getDataCache();
|
||||
this.dataCache = plugin.getDataCache();
|
||||
this.plugin = plugin;
|
||||
history = new ArrayList<>();
|
||||
}
|
||||
@ -54,7 +54,8 @@ public class TPSCountTimer extends AbsRunnable {
|
||||
history.add(tps);
|
||||
|
||||
if (history.size() >= 60) {
|
||||
handler.addTPSLastMinute(history);
|
||||
// TODO Process & Save to DB with a new Processor.
|
||||
dataCache.addTPSLastMinute(history);
|
||||
history.clear();
|
||||
}
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ 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.getDataCache();
|
||||
Map<String, Integer> commandUse = handler.getCommandUse();
|
||||
DataCache dataCache = plugin.getDataCache();
|
||||
Map<String, Integer> commandUse = dataCache.getCommandUse();
|
||||
|
||||
AnalysisData analysisData = new AnalysisData(commandUse, tpsData);
|
||||
analysisData.setPluginsTabLayout(plugin.getHookHandler().getPluginsTabLayoutForAnalysis());
|
||||
|
@ -21,7 +21,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||
public class DataCacheTest {
|
||||
|
||||
private Database db;
|
||||
private DataCache handler;
|
||||
private DataCache dataCache;
|
||||
|
||||
private int callsToSaveCommandUse;
|
||||
private int callsToSaveUserData;
|
||||
|
@ -34,7 +34,7 @@ public class QueueTest {
|
||||
|
||||
private final UUID uuid1 = MockUtils.getPlayerUUID();
|
||||
|
||||
private DataCache handler;
|
||||
private DataCache dataCache;
|
||||
private Database db;
|
||||
|
||||
public QueueTest() {
|
||||
@ -51,12 +51,12 @@ public class QueueTest {
|
||||
};
|
||||
db.init();
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
handler = new DataCache(plan) {
|
||||
dataCache = new DataCache(plan) {
|
||||
@Override
|
||||
public void startAsyncPeriodicSaveTask() {
|
||||
}
|
||||
};
|
||||
when(plan.getDataCache()).thenReturn(handler);
|
||||
when(plan.getDataCache()).thenReturn(dataCache);
|
||||
}
|
||||
|
||||
@After
|
||||
@ -68,7 +68,7 @@ public class QueueTest {
|
||||
public void testProcessQueue() {
|
||||
List<Integer> processCalls = new ArrayList<>();
|
||||
List<Integer> errors = new ArrayList<>();
|
||||
// handler.addToPool(new HandlingInfo(uuid1, InfoType.OTHER, 0) {
|
||||
// dataCache.addToPool(new HandlingInfo(uuid1, InfoType.OTHER, 0) {
|
||||
// @Override
|
||||
// public void process(UserData uData) {
|
||||
// if (uData.equals(data1)) {
|
||||
|
Loading…
Reference in New Issue
Block a user