Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db): add datetime column to sc_kills #432

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void saveKill(Kill kill, Kill.Type type) {
ClanPlayer killer = kill.getKiller();
ClanPlayer victim = kill.getVictim();
killer.addKill(type);
plugin.getStorageManager().insertKill(killer, victim, type.getShortname());
plugin.getStorageManager().insertKill(killer, victim, type.getShortname(), kill.getTime());
}

private double calculateReward(@NotNull ClanPlayer attacker, @NotNull ClanPlayer victim) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.logging.Level;

Expand Down Expand Up @@ -151,6 +152,7 @@ public void initiateDB() {
+ " `victim` varchar(16) NOT NULL,"
+ " `victim_tag` varchar(16) NOT NULL,"
+ " `kill_type` varchar(1) NOT NULL,"
+ " `created_at` datetime NULL,"
+ " PRIMARY KEY (`kill_id`));";
core.execute(query);
}
Expand Down Expand Up @@ -228,6 +230,7 @@ public void initiateDB() {
+ " `victim` varchar(16) NOT NULL,"
+ " `victim_tag` varchar(16) NOT NULL,"
+ " `kill_type` varchar(1) NOT NULL,"
+ " `created_at` datetime NULL,"
+ " PRIMARY KEY (`kill_id`));";
core.execute(query);
}
Expand Down Expand Up @@ -931,11 +934,11 @@ public void insertKill(Player attacker, String attackerTag, Player victim, Strin
* @param victim the victim
* @param type the kill type
*/
public void insertKill(@NotNull ClanPlayer attacker, @NotNull ClanPlayer victim, @NotNull String type) {
String query = "INSERT INTO `" + getPrefixedTable("kills") + "` ( `attacker_uuid`, `attacker`, `attacker_tag`, `victim_uuid`, " +
"`victim`, `victim_tag`, `kill_type`) ";
public void insertKill(@NotNull ClanPlayer attacker, @NotNull ClanPlayer victim, @NotNull String type, @NotNull LocalDateTime time) {
String query = "INSERT INTO `sc_kills` ( `attacker_uuid`, `attacker`, `attacker_tag`, `victim_uuid`, " +
"`victim`, `victim_tag`, `kill_type`, `created_at`) ";
String values = "VALUES ( '" + attacker.getUniqueId() + "','" + attacker.getName() + "','" + attacker.getTag()
+ "','" + victim.getUniqueId() + "','" + victim.getName() + "','" + victim.getTag() + "','" + type + "');";
+ "','" + victim.getUniqueId() + "','" + victim.getName() + "','" + victim.getTag() + "','" + type + "','" + time + "');";
core.executeUpdate(query + values);
}

Expand Down Expand Up @@ -1174,6 +1177,12 @@ private void updateDatabase() {
query = "CREATE UNIQUE INDEX IF NOT EXISTS `uq_player_uuid` ON `" + getPrefixedTable("players") + "` (`uuid`);";
core.execute(query);
}

// From 2.19.3 to 2.20.0
if (!core.existsColumn("sc_kills", "created_at")) {
query = "ALTER TABLE sc_kills ADD `created_at` datetime NULL;";
core.execute(query);
}
}

/**
Expand Down
Loading