rank-place placeholder, fix null pointer in sql
This commit is contained in:
parent
1d85e99534
commit
0fdc77157f
2 changed files with 33 additions and 6 deletions
|
@ -186,6 +186,23 @@ public class PlayerInfoTable {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getRanking(String order, UUID uuid){
|
||||
String sql = "SELECT count(*) AS total FROM hs_data WHERE "+order+" < (SELECT "+order+" FROM hs_data WHERE uuid = ?);";
|
||||
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
||||
statement.setBytes(1, encodeUUID(uuid));
|
||||
ResultSet rs = statement.executeQuery();
|
||||
if(rs.next()){
|
||||
return rs.getInt("total")+1;
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e){
|
||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addWins(List<UUID> uuids, List<UUID> winners, Map<String,Integer> kills, Map<String,Integer> deaths, WinType type){
|
||||
for(UUID uuid : uuids){
|
||||
String sql = "INSERT OR REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)";
|
||||
|
@ -196,10 +213,10 @@ public class PlayerInfoTable {
|
|||
statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0));
|
||||
statement.setInt(4, info.hider_games + (Board.isHider(uuid) ? 1 : 0));
|
||||
statement.setInt(5, info.seeker_games + (Board.isSeeker(uuid) ? 1 : 0));
|
||||
statement.setInt(6, info.hider_kills + (Board.isHider(uuid) ? kills.get(uuid.toString()) : 0));
|
||||
statement.setInt(7, info.seeker_kills + (Board.isSeeker(uuid) ? kills.get(uuid.toString()) : 0));
|
||||
statement.setInt(8, info.hider_deaths + (Board.isHider(uuid) ? deaths.get(uuid.toString()) : 0));
|
||||
statement.setInt(9, info.seeker_deaths + (Board.isSeeker(uuid) ? deaths.get(uuid.toString()) : 0));
|
||||
statement.setInt(6, info.hider_kills + (Board.isHider(uuid) ? kills.getOrDefault(uuid.toString(), 0) : 0));
|
||||
statement.setInt(7, info.seeker_kills + (Board.isSeeker(uuid) ? kills.getOrDefault(uuid.toString(), 0) : 0));
|
||||
statement.setInt(8, info.hider_deaths + (Board.isHider(uuid) ? deaths.getOrDefault(uuid.toString(), 0) : 0));
|
||||
statement.setInt(9, info.seeker_deaths + (Board.isSeeker(uuid) ? deaths.getOrDefault(uuid.toString(), 0) : 0));
|
||||
statement.execute();
|
||||
} catch (SQLException e){
|
||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||
|
@ -211,6 +228,4 @@ public class PlayerInfoTable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -57,6 +57,18 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||
} else {
|
||||
return UUIDFetcher.getPlayer(info.uuid).getName();
|
||||
}
|
||||
} else if(args[0].equals("rank-place") && args.length == 2){
|
||||
if(getRanking(args[1]) == null) { return placeholderError; }
|
||||
Integer count = Database.playerInfo.getRanking(getRanking(args[1]), player.getUniqueId());
|
||||
if(count == null) { return placeholderNoData; }
|
||||
return count.toString();
|
||||
} else if(args[0].equals("rank-place") && args.length == 3){
|
||||
UUID uuid;
|
||||
try { uuid = UUIDFetcher.getUUID(args[2]); } catch (Exception e) { return placeholderError; }
|
||||
if(getRanking(args[1]) == null) { return placeholderError; }
|
||||
Integer count = Database.playerInfo.getRanking(getRanking(args[1]), uuid);
|
||||
if(count == null) { return placeholderNoData; }
|
||||
return count.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue