refactor: reorganize PlayerInfo without static variables

This commit is contained in:
bobby29831 2022-05-14 08:36:25 -05:00
parent 99c1ea8eb3
commit e45099a5f4
5 changed files with 81 additions and 44 deletions

View file

@ -54,7 +54,7 @@ public class Top implements ICommand {
return; return;
} }
for(PlayerInfo info : infos) { for(PlayerInfo info : infos) {
String name = Main.getInstance().getServer().getOfflinePlayer(info.uuid).getName(); String name = Main.getInstance().getServer().getOfflinePlayer(info.getUniqueId()).getName();
ChatColor color; ChatColor color;
switch (i) { switch (i) {
case 1: color = ChatColor.YELLOW; break; case 1: color = ChatColor.YELLOW; break;
@ -63,7 +63,7 @@ public class Top implements ICommand {
default: color = ChatColor.WHITE; break; default: color = ChatColor.WHITE; break;
} }
message.append(String.format("%s%s. %s%s %s%s\n", message.append(String.format("%s%s. %s%s %s%s\n",
color, i, ChatColor.RED, info.seeker_wins+info.hider_wins, ChatColor.WHITE, name)); color, i, ChatColor.RED, info.getSeekerWins() +info.getHiderWins(), ChatColor.WHITE, name));
i++; i++;
} }
sender.sendMessage(message.toString()); sender.sendMessage(message.toString());

View file

@ -64,8 +64,8 @@ public class Wins implements ICommand {
message = message + message("INFORMATION_FOR").addPlayer(name) + "\n"; message = message + message("INFORMATION_FOR").addPlayer(name) + "\n";
message = message + "==============================\n"; message = message + "==============================\n";
message = message + String.format("%sTOTAL WINS: %s%s\n%sHIDER WINS: %s%s\n%sSEEKER WINS: %s%s\n%sGAMES PLAYED: %s", message = message + String.format("%sTOTAL WINS: %s%s\n%sHIDER WINS: %s%s\n%sSEEKER WINS: %s%s\n%sGAMES PLAYED: %s",
ChatColor.YELLOW, ChatColor.WHITE, info.seeker_wins+info.hider_wins, ChatColor.GOLD, ChatColor.WHITE, info.hider_wins, ChatColor.YELLOW, ChatColor.WHITE, info.getSeekerWins() +info.getHiderWins(), ChatColor.GOLD, ChatColor.WHITE, info.getHiderWins(),
ChatColor.RED, ChatColor.WHITE, info.seeker_wins, ChatColor.WHITE, info.seeker_games+info.hider_games); ChatColor.RED, ChatColor.WHITE, info.getSeekerWins(), ChatColor.WHITE, info.getSeekerGames() +info.getHiderGames());
message = message + ChatColor.WHITE + "" + ChatColor.BOLD + "\n=============================="; message = message + ChatColor.WHITE + "" + ChatColor.BOLD + "\n==============================";
sender.sendMessage(message); sender.sendMessage(message);

View file

@ -23,25 +23,62 @@ import java.util.UUID;
public class PlayerInfo { public class PlayerInfo {
public final UUID uuid; private final UUID uniqueId;
public final int hider_wins; private final int hiderWins;
public final int seeker_wins; private final int seekerWins;
public final int hider_games; private final int hiderGames;
public final int seeker_games; private final int seekerGames;
public final int hider_kills; private final int hiderKills;
public final int seeker_kills; private final int seekerKills;
public final int hider_deaths; private final int hiderDeaths;
public final int seeker_deaths; private final int seekerDeaths;
public PlayerInfo(UUID uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths) { public PlayerInfo(UUID uniqueId, int hiderWins, int seekerWins, int hiderGames, int seekerGames, int hiderKills, int seekerKills, int hiderDeaths, int seekerDeaths) {
this.uuid = uuid; this.uniqueId = uniqueId;
this.hider_wins = hider_wins; this.hiderWins = hiderWins;
this.seeker_wins = seeker_wins; this.seekerWins = seekerWins;
this.hider_games = hider_games; this.hiderGames = hiderGames;
this.seeker_games = seeker_games; this.seekerGames = seekerGames;
this.hider_kills = hider_kills; this.hiderKills = hiderKills;
this.seeker_kills = seeker_kills; this.seekerKills = seekerKills;
this.hider_deaths = hider_deaths; this.hiderDeaths = hiderDeaths;
this.seeker_deaths = seeker_deaths; this.seekerDeaths = seekerDeaths;
} }
public UUID getUniqueId() {
return uniqueId;
}
public int getHiderWins() {
return hiderWins;
}
public int getSeekerWins() {
return seekerWins;
}
public int getHiderGames() {
return hiderGames;
}
public int getSeekerGames() {
return seekerGames;
}
public int getHiderKills() {
return hiderKills;
}
public int getSeekerKills() {
return seekerKills;
}
public int getHiderDeaths() {
return hiderDeaths;
}
public int getSeekerDeaths() {
return seekerDeaths;
}
} }

View file

@ -177,14 +177,14 @@ public class PlayerInfoTable {
} }
try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) { try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setBytes(1, database.encodeUUID(uuid)); statement.setBytes(1, database.encodeUUID(uuid));
statement.setInt(2, info.hider_wins + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0)); statement.setInt(2, info.getHiderWins() + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0));
statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0)); statement.setInt(3, info.getSeekerWins() + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0));
statement.setInt(4, info.hider_games + (board.isHider(uuid) || (board.isSeeker(uuid) && !board.getFirstSeeker().getUniqueId().equals(uuid)) ? 1 : 0)); statement.setInt(4, info.getHiderGames() + (board.isHider(uuid) || (board.isSeeker(uuid) && !board.getFirstSeeker().getUniqueId().equals(uuid)) ? 1 : 0));
statement.setInt(5, info.seeker_games + (board.getFirstSeeker().getUniqueId().equals(uuid) ? 1 : 0)); statement.setInt(5, info.getSeekerGames() + (board.getFirstSeeker().getUniqueId().equals(uuid) ? 1 : 0));
statement.setInt(6, info.hider_kills + hider_kills.getOrDefault(uuid.toString(), 0)); statement.setInt(6, info.getHiderKills() + hider_kills.getOrDefault(uuid.toString(), 0));
statement.setInt(7, info.seeker_kills + seeker_kills.getOrDefault(uuid.toString(), 0)); statement.setInt(7, info.getSeekerKills() + seeker_kills.getOrDefault(uuid.toString(), 0));
statement.setInt(8, info.hider_deaths + hider_deaths.getOrDefault(uuid.toString(), 0)); statement.setInt(8, info.getHiderDeaths() + hider_deaths.getOrDefault(uuid.toString(), 0));
statement.setInt(9, info.seeker_deaths + seeker_deaths.getOrDefault(uuid.toString(), 0)); statement.setInt(9, info.getSeekerDeaths() + seeker_deaths.getOrDefault(uuid.toString(), 0));
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Main.getInstance().getLogger().severe("SQL Error: " + e.getMessage()); Main.getInstance().getLogger().severe("SQL Error: " + e.getMessage());

View file

@ -57,7 +57,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
if (args[0].equals("rank-score")) { if (args[0].equals("rank-score")) {
return getValue(info, args[1]); return getValue(info, args[1]);
} else { } else {
return Main.getInstance().getServer().getOfflinePlayer(info.uuid).getName(); return Main.getInstance().getServer().getOfflinePlayer(info.getUniqueId()).getName();
} }
} else if (args[0].equals("rank-place") && args.length == 2) { } else if (args[0].equals("rank-place") && args.length == 2) {
if (getRanking(args[1]) == null) { return placeholderError; } if (getRanking(args[1]) == null) { return placeholderError; }
@ -83,29 +83,29 @@ public class PAPIExpansion extends PlaceholderExpansion {
if (query == null) return null; if (query == null) return null;
switch (query) { switch (query) {
case "total-wins": case "total-wins":
return String.valueOf(info.hider_wins + info.seeker_wins); return String.valueOf(info.getHiderWins() + info.getSeekerWins());
case "hider-wins": case "hider-wins":
return String.valueOf(info.hider_wins); return String.valueOf(info.getHiderWins());
case "seeker-wins": case "seeker-wins":
return String.valueOf(info.seeker_wins); return String.valueOf(info.getSeekerWins());
case "total-games": case "total-games":
return String.valueOf(info.hider_games + info.seeker_games); return String.valueOf(info.getHiderGames() + info.getSeekerGames());
case "hider-games": case "hider-games":
return String.valueOf(info.hider_games); return String.valueOf(info.getHiderGames());
case "seeker-games": case "seeker-games":
return String.valueOf(info.seeker_games); return String.valueOf(info.getSeekerGames());
case "total-kills": case "total-kills":
return String.valueOf(info.hider_kills + info.seeker_kills); return String.valueOf(info.getHiderKills() + info.getSeekerKills());
case "hider-kills": case "hider-kills":
return String.valueOf(info.hider_kills); return String.valueOf(info.getHiderKills());
case "seeker-kills": case "seeker-kills":
return String.valueOf(info.seeker_kills); return String.valueOf(info.getSeekerKills());
case "total-deaths": case "total-deaths":
return String.valueOf(info.hider_deaths + info.seeker_deaths); return String.valueOf(info.getHiderDeaths() + info.getSeekerDeaths());
case "hider-deaths": case "hider-deaths":
return String.valueOf(info.hider_deaths); return String.valueOf(info.getHiderDeaths());
case "seeker-deaths": case "seeker-deaths":
return String.valueOf(info.seeker_deaths); return String.valueOf(info.getSeekerDeaths());
default: default:
return null; return null;
} }