diff --git a/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java b/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java index daea3f273..ce5132102 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/analysis/KillPart.java @@ -1,9 +1,12 @@ package main.java.com.djrapitops.plan.data.analysis; +import main.java.com.djrapitops.plan.data.PlayerKill; import main.java.com.djrapitops.plan.data.Session; import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.UUID; /** * Part responsible for all Death related analysis. @@ -57,4 +60,8 @@ public class KillPart extends RawData { public long getDeaths() { return deaths; } + + public void addKills(Map> playerKills) { + this.playerKills += playerKills.values().stream().mapToLong(Collection::size).sum(); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java index c6af8e2f6..407966b12 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java @@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.tables; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException; import main.java.com.djrapitops.plan.data.PlayerKill; import main.java.com.djrapitops.plan.data.Session; @@ -12,9 +13,7 @@ import main.java.com.djrapitops.plan.database.sql.TableSqlParser; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * @author Rsl1122 @@ -148,4 +147,43 @@ public class KillsTable extends UserIDTable { close(set, statement); } } + + public Map> getPlayerKills() throws SQLException { + return getPlayerKills(Plan.getServerUUID()); + } + + public Map> getPlayerKills(UUID serverUUID) throws SQLException { + PreparedStatement statement = null; + ResultSet set = null; + try { + String usersIDColumn = usersTable + "." + usersTable.getColumnID(); + String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as victim_uuid"; + String usersUUIDColumn2 = usersTable + "." + usersTable.getColumnUUID() + " as killer_uuid"; + statement = prepareStatement("SELECT " + + columnDate + ", " + + columnWeapon + ", " + + usersUUIDColumn + ", " + + usersUUIDColumn2 + + " FROM " + tableName + + " JOIN " + usersTable + " on " + usersIDColumn + "=" + columnVictimUserID + + " JOIN " + usersTable + " on " + usersIDColumn + "=" + columnKillerUserID); + + statement.setFetchSize(10000); + set = statement.executeQuery(); + + Map> allKills = new HashMap<>(); + while (set.next()) { + UUID killer = UUID.fromString(set.getString("killer_uuid")); + UUID victim = UUID.fromString(set.getString("victim_uuid")); + long date = set.getLong(columnDate); + String weapon = set.getString(columnWeapon); + List kills = allKills.getOrDefault(killer, new ArrayList<>()); + kills.add(new PlayerKill(victim, weapon, date)); + allKills.put(killer, kills); + } + return allKills; + } finally { + close(set, statement); + } + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 1d9f4897d..d3e6d4c59 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -5,10 +5,7 @@ import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.data.AnalysisData; -import main.java.com.djrapitops.plan.data.Session; -import main.java.com.djrapitops.plan.data.TPS; -import main.java.com.djrapitops.plan.data.UserInfo; +import main.java.com.djrapitops.plan.data.*; import main.java.com.djrapitops.plan.data.additional.AnalysisType; import main.java.com.djrapitops.plan.data.additional.HookHandler; import main.java.com.djrapitops.plan.data.additional.PluginData; @@ -240,6 +237,7 @@ public class Analysis { CommandUsagePart commandUsagePart = analysisData.getCommandUsagePart(); GeolocationPart geolocPart = analysisData.getGeolocationPart(); JoinInfoPart joinInfo = analysisData.getJoinInfoPart(); + KillPart killPart = analysisData.getKillPart(); PlayerCountPart playerCount = analysisData.getPlayerCountPart(); PlaytimePart playtime = analysisData.getPlaytimePart(); TPSPart tpsPart = analysisData.getTpsPart(); @@ -290,6 +288,9 @@ public class Analysis { joinInfo.addActiveSessions(activeSessions); joinInfo.addSessions(sessions); + Map> playerKills = db.getKillsTable().getPlayerKills(); + killPart.addKills(playerKills); + Map> geolocations = db.getIpsTable().getAllGeolocations(); geolocPart.addGeoLocations(geolocations);