mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 20:21:45 +01:00
Kill Processing
This commit is contained in:
parent
96ff3b3fbf
commit
8002864c73
@ -12,7 +12,6 @@ import java.util.UUID;
|
|||||||
public class KillData {
|
public class KillData {
|
||||||
|
|
||||||
private final UUID victim;
|
private final UUID victim;
|
||||||
private int victimUserID;
|
|
||||||
private final long date;
|
private final long date;
|
||||||
private final String weapon;
|
private final String weapon;
|
||||||
|
|
||||||
@ -20,14 +19,12 @@ public class KillData {
|
|||||||
* Creates a KillData object with given parameters.
|
* Creates a KillData object with given parameters.
|
||||||
*
|
*
|
||||||
* @param victim UUID of the victim.
|
* @param victim UUID of the victim.
|
||||||
* @param victimID ID of the victim, get from the database.
|
|
||||||
* @param weapon Weapon used.
|
* @param weapon Weapon used.
|
||||||
* @param date Epoch millisecond at which the kill occurred.
|
* @param date Epoch millisecond at which the kill occurred.
|
||||||
*/
|
*/
|
||||||
public KillData(UUID victim, int victimID, String weapon, long date) {
|
public KillData(UUID victim, String weapon, long date) {
|
||||||
this.victim = victim;
|
this.victim = victim;
|
||||||
this.weapon = weapon;
|
this.weapon = weapon;
|
||||||
victimUserID = victimID;
|
|
||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,18 +55,10 @@ public class KillData {
|
|||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the UserID of the victim, found from the database.
|
|
||||||
*
|
|
||||||
* @return For example: 6
|
|
||||||
*/
|
|
||||||
public int getVictimUserID() {
|
|
||||||
return victimUserID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "{victim:" + victim + "|victimUserID:" + victimUserID + "|date:" + date + "|weapon:" + weapon + '}';
|
return "{victim:" + victim + "|date:" + date + "|weapon:" + weapon + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,8 +86,4 @@ public class KillData {
|
|||||||
hash = 89 * hash + Objects.hashCode(this.weapon);
|
hash = 89 * hash + Objects.hashCode(this.weapon);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVictimUserID(int victimUserID) {
|
|
||||||
this.victimUserID = victimUserID;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import main.java.com.djrapitops.plan.data.Session;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,9 +60,12 @@ public class SessionCache {
|
|||||||
* @param uuid UUID of the player.
|
* @param uuid UUID of the player.
|
||||||
* @return Session or null if not cached.
|
* @return Session or null if not cached.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public Optional<Session> getSession(UUID uuid) {
|
||||||
public Session getSession(UUID uuid) {
|
Session session = activeSessions.get(uuid);
|
||||||
return activeSessions.get(uuid);
|
if (session != null) {
|
||||||
|
return Optional.of(session);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,7 @@ package main.java.com.djrapitops.plan.data.handling.info;
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public enum InfoType {
|
public enum InfoType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package main.java.com.djrapitops.plan.data.handling.info;
|
|
||||||
|
|
||||||
import main.java.com.djrapitops.plan.data.UserData;
|
|
||||||
import main.java.com.djrapitops.plan.data.handling.KillHandling;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HandlingInfo Class for DeathEvent information when the dead entity is a
|
|
||||||
* player.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
* @since 3.0.0
|
|
||||||
*/
|
|
||||||
public class KillInfo extends HandlingInfo {
|
|
||||||
|
|
||||||
private final LivingEntity dead;
|
|
||||||
private final String weaponName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param uuid UUID of the killer.
|
|
||||||
* @param time Epoch ms the event occurred.
|
|
||||||
* @param dead Dead entity (Mob or Player)
|
|
||||||
* @param weaponName Weapon used.
|
|
||||||
*/
|
|
||||||
public KillInfo(UUID uuid, long time, LivingEntity dead, String weaponName) {
|
|
||||||
super(uuid, InfoType.KILL, time);
|
|
||||||
this.dead = dead;
|
|
||||||
this.weaponName = weaponName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void process(UserData uData) {
|
|
||||||
if (!uData.getUuid().equals(uuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
KillHandling.processKillInfo(uData, time, dead, weaponName);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,59 @@
|
|||||||
|
package main.java.com.djrapitops.plan.data.handling.player;
|
||||||
|
|
||||||
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
|
import main.java.com.djrapitops.plan.data.KillData;
|
||||||
|
import main.java.com.djrapitops.plan.data.Session;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processor Class for KillEvent information when the killer is a
|
||||||
|
* player.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
public class KillProcessor extends PlayerProcessor {
|
||||||
|
|
||||||
|
private final LivingEntity dead;
|
||||||
|
private final String weaponName;
|
||||||
|
private final long time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param uuid UUID of the killer.
|
||||||
|
* @param time Epoch ms the event occurred.
|
||||||
|
* @param dead Dead entity (Mob or Player)
|
||||||
|
* @param weaponName Weapon used.
|
||||||
|
*/
|
||||||
|
public KillProcessor(UUID uuid, long time, LivingEntity dead, String weaponName) {
|
||||||
|
super(uuid);
|
||||||
|
this.time = time;
|
||||||
|
this.dead = dead;
|
||||||
|
this.weaponName = weaponName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
UUID uuid = getUUID();
|
||||||
|
|
||||||
|
Plan plugin = Plan.getInstance();
|
||||||
|
|
||||||
|
Optional<Session> cachedSession = plugin.getDataCache().getSession(uuid);
|
||||||
|
if (!cachedSession.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Session session = cachedSession.get();
|
||||||
|
|
||||||
|
if (dead instanceof Player) {
|
||||||
|
Player deadPlayer = (Player) dead;
|
||||||
|
session.playerKilled(new KillData(deadPlayer.getUniqueId(), weaponName, time));
|
||||||
|
} else {
|
||||||
|
session.mobKilled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,8 @@ package main.java.com.djrapitops.plan.data.listeners;
|
|||||||
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
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.data.handling.player.DeathProcessor;
|
||||||
|
import main.java.com.djrapitops.plan.data.handling.player.KillProcessor;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import org.apache.commons.lang3.text.WordUtils;
|
import org.apache.commons.lang3.text.WordUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -100,8 +100,7 @@ public class PlanDeathEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Verify.notNull(killerUUID, weapon)) {
|
if (Verify.notNull(killerUUID, weapon)) {
|
||||||
|
plugin.addToProcessQueue(new KillProcessor(killerUUID, time, dead, weapon));
|
||||||
plugin.addToProcessQueue(new KillInfo(killerUUID, time, dead, weapon));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ public class KillsTable extends Table {
|
|||||||
private final String columnServerID; //TODO
|
private final String columnServerID; //TODO
|
||||||
private final String columnSessionID; //TODO
|
private final String columnSessionID; //TODO
|
||||||
|
|
||||||
|
// TODO Automatic UserID Retrieval from UsersTable.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param db
|
* @param db
|
||||||
* @param usingMySQL
|
* @param usingMySQL
|
||||||
@ -97,9 +99,8 @@ public class KillsTable extends Table {
|
|||||||
set = statement.executeQuery();
|
set = statement.executeQuery();
|
||||||
List<KillData> killData = new ArrayList<>();
|
List<KillData> killData = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int victimID = set.getInt(columnVictimUserID);
|
UUID victimUUID = null; // TODO Victim UUID Retrieval
|
||||||
UUID victimUUID = usersTable.getUserUUID(String.valueOf(victimID));
|
killData.add(new KillData(victimUUID, set.getString(columnWeapon), set.getLong(columnDate)));
|
||||||
killData.add(new KillData(victimUUID, victimID, set.getString(columnWeapon), set.getLong(columnDate)));
|
|
||||||
}
|
}
|
||||||
return killData;
|
return killData;
|
||||||
} finally {
|
} finally {
|
||||||
@ -128,24 +129,12 @@ public class KillsTable extends Table {
|
|||||||
+ columnDate
|
+ columnDate
|
||||||
+ ") VALUES (?, ?, ?, ?)");
|
+ ") VALUES (?, ?, ?, ?)");
|
||||||
boolean commitRequired = false;
|
boolean commitRequired = false;
|
||||||
kills.stream().filter(Objects::nonNull).forEach(killData -> {
|
|
||||||
int victimUserID = killData.getVictimUserID();
|
|
||||||
if (victimUserID == -1) {
|
|
||||||
try {
|
|
||||||
int newVictimID = db.getUsersTable().getUserId(killData.getVictim());
|
|
||||||
killData.setVictimUserID(newVictimID);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Log.toLog(this.getClass().getName(), e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (KillData kill : kills) {
|
for (KillData kill : kills) {
|
||||||
if (kill == null || kill.getVictimUserID() == -1) {
|
if (kill == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
statement.setInt(1, userId);
|
statement.setInt(1, userId);
|
||||||
statement.setInt(2, kill.getVictimUserID());
|
statement.setInt(2, -1); // TODO Victim ID Retrieval
|
||||||
statement.setString(3, kill.getWeapon());
|
statement.setString(3, kill.getWeapon());
|
||||||
statement.setLong(4, kill.getDate());
|
statement.setLong(4, kill.getDate());
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
@ -183,12 +172,11 @@ public class KillsTable extends Table {
|
|||||||
}
|
}
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
int killerID = set.getInt(columnKillerUserID);
|
int killerID = set.getInt(columnKillerUserID);
|
||||||
int victimID = set.getInt(columnVictimUserID);
|
|
||||||
if (!ids.contains(killerID)) {
|
if (!ids.contains(killerID)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UUID victimUUID = uuids.get(victimID);
|
UUID victimUUID = null; // TODO Victim UUID Retrieval
|
||||||
kills.get(killerID).add(new KillData(victimUUID, victimID, set.getString(columnWeapon), set.getLong(columnDate)));
|
kills.get(killerID).add(new KillData(victimUUID, set.getString(columnWeapon), set.getLong(columnDate)));
|
||||||
}
|
}
|
||||||
return kills;
|
return kills;
|
||||||
} finally {
|
} finally {
|
||||||
@ -230,14 +218,9 @@ public class KillsTable extends Table {
|
|||||||
playerKills.removeAll(s);
|
playerKills.removeAll(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
findMissingIDs(playerKills);
|
|
||||||
|
|
||||||
for (KillData kill : playerKills) {
|
for (KillData kill : playerKills) {
|
||||||
if (kill.getVictimUserID() == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, id);
|
||||||
statement.setInt(2, kill.getVictimUserID());
|
statement.setInt(2, -1); // TODO Victim ID Retrieval
|
||||||
statement.setString(3, kill.getWeapon());
|
statement.setString(3, kill.getWeapon());
|
||||||
statement.setLong(4, kill.getDate());
|
statement.setLong(4, kill.getDate());
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
@ -253,14 +236,4 @@ public class KillsTable extends Table {
|
|||||||
Benchmark.stop("Database", "Save Kills multiple");
|
Benchmark.stop("Database", "Save Kills multiple");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findMissingIDs(List<KillData> playerKills) throws SQLException {
|
|
||||||
for (KillData killData : playerKills) {
|
|
||||||
int victimUserID = killData.getVictimUserID();
|
|
||||||
if (victimUserID == -1) {
|
|
||||||
int newVictimID = db.getUsersTable().getUserId(killData.getVictim());
|
|
||||||
killData.setVictimUserID(newVictimID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user