Added PlayerKills that are not included with the Session objects.

This commit is contained in:
Rsl1122 2017-09-02 16:59:32 +03:00
parent ff5342ed16
commit e78dea9cd9
3 changed files with 53 additions and 7 deletions

View File

@ -1,9 +1,12 @@
package main.java.com.djrapitops.plan.data.analysis; 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 main.java.com.djrapitops.plan.data.Session;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* Part responsible for all Death related analysis. * Part responsible for all Death related analysis.
@ -57,4 +60,8 @@ public class KillPart extends RawData {
public long getDeaths() { public long getDeaths() {
return deaths; return deaths;
} }
public void addKills(Map<UUID, List<PlayerKill>> playerKills) {
this.playerKills += playerKills.values().stream().mapToLong(Collection::size).sum();
}
} }

View File

@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log; 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.api.exceptions.DBCreateTableException;
import main.java.com.djrapitops.plan.data.PlayerKill; import main.java.com.djrapitops.plan.data.PlayerKill;
import main.java.com.djrapitops.plan.data.Session; 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.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.UUID;
/** /**
* @author Rsl1122 * @author Rsl1122
@ -148,4 +147,43 @@ public class KillsTable extends UserIDTable {
close(set, statement); close(set, statement);
} }
} }
public Map<UUID, List<PlayerKill>> getPlayerKills() throws SQLException {
return getPlayerKills(Plan.getServerUUID());
}
public Map<UUID, List<PlayerKill>> 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<UUID, List<PlayerKill>> 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<PlayerKill> kills = allKills.getOrDefault(killer, new ArrayList<>());
kills.add(new PlayerKill(victim, weapon, date));
allKills.put(killer, kills);
}
return allKills;
} finally {
close(set, statement);
}
}
} }

View File

@ -5,10 +5,7 @@ import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData; import main.java.com.djrapitops.plan.data.*;
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.additional.AnalysisType; 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.HookHandler;
import main.java.com.djrapitops.plan.data.additional.PluginData; import main.java.com.djrapitops.plan.data.additional.PluginData;
@ -240,6 +237,7 @@ public class Analysis {
CommandUsagePart commandUsagePart = analysisData.getCommandUsagePart(); CommandUsagePart commandUsagePart = analysisData.getCommandUsagePart();
GeolocationPart geolocPart = analysisData.getGeolocationPart(); GeolocationPart geolocPart = analysisData.getGeolocationPart();
JoinInfoPart joinInfo = analysisData.getJoinInfoPart(); JoinInfoPart joinInfo = analysisData.getJoinInfoPart();
KillPart killPart = analysisData.getKillPart();
PlayerCountPart playerCount = analysisData.getPlayerCountPart(); PlayerCountPart playerCount = analysisData.getPlayerCountPart();
PlaytimePart playtime = analysisData.getPlaytimePart(); PlaytimePart playtime = analysisData.getPlaytimePart();
TPSPart tpsPart = analysisData.getTpsPart(); TPSPart tpsPart = analysisData.getTpsPart();
@ -290,6 +288,9 @@ public class Analysis {
joinInfo.addActiveSessions(activeSessions); joinInfo.addActiveSessions(activeSessions);
joinInfo.addSessions(sessions); joinInfo.addSessions(sessions);
Map<UUID, List<PlayerKill>> playerKills = db.getKillsTable().getPlayerKills();
killPart.addKills(playerKills);
Map<UUID, List<String>> geolocations = db.getIpsTable().getAllGeolocations(); Map<UUID, List<String>> geolocations = db.getIpsTable().getAllGeolocations();
geolocPart.addGeoLocations(geolocations); geolocPart.addGeoLocations(geolocations);