Formatted ping placeholder values

Affects issues:
- Fixed #1324
This commit is contained in:
Rsl1122 2020-02-08 19:20:19 +02:00
parent be0fab2f6b
commit 9d26591dfc
3 changed files with 20 additions and 11 deletions

View File

@ -45,6 +45,7 @@ import java.util.UUID;
public class PlayerPlaceHolder extends AbstractPlanPlaceHolder {
private final DBSystem dbSystem;
private final Formatter<Double> decimals;
private Formatter<Long> year;
private Formatter<Long> time;
@ -57,10 +58,11 @@ public class PlayerPlaceHolder extends AbstractPlanPlaceHolder {
this.dbSystem = dbSystem;
time = formatters.timeAmount();
year = formatters.yearLong();
decimals = formatters.decimals();
}
@Override
public String onPlaceholderRequest(Player p, String params) throws Exception {
public String onPlaceholderRequest(Player p, String params) {
Serializable got = get(params, p.getUniqueId());
return got != null ? got.toString() : null;
}
@ -93,12 +95,17 @@ public class PlayerPlaceHolder extends AbstractPlanPlaceHolder {
return PlayerVersusMutator.forContainer(player).toKillDeathRatio();
case "player_ping_average_day":
return PingMutator.forContainer(player).filterBy(Predicates.within(dayAgo(), now())).average();
return decimals.apply(PingMutator.forContainer(player)
.filterBy(Predicates.within(dayAgo(), now()))
.average()) + " ms";
case "player_ping_average_week":
return PingMutator.forContainer(player).filterBy(Predicates.within(weekAgo(), now())).average();
return decimals.apply(PingMutator.forContainer(player)
.filterBy(Predicates.within(weekAgo(), now()))
.average()) + " ms";
case "player_ping_average_month":
return PingMutator.forContainer(player).filterBy(Predicates.within(monthAgo(), now())).average();
return decimals.apply(PingMutator.forContainer(player)
.filterBy(Predicates.within(monthAgo(), now()))
.average()) + " ms";
case "player_lastseen":
return year.apply(player.getValue(PlayerKeys.LAST_SEEN).orElse((long) 0));

View File

@ -50,7 +50,7 @@ public class ServerPlaceHolders extends AbstractPlanPlaceHolder {
}
@Override
public String onPlaceholderRequest(Player p, String params) throws Exception {
public String onPlaceholderRequest(Player p, String params) {
Database database = dbSystem.getDatabase();
UUID serverUUID = serverUUID();
Serializable got = get(params, database, serverUUID);

View File

@ -42,6 +42,7 @@ import java.util.UUID;
public class SessionPlaceHolder extends AbstractPlanPlaceHolder {
private final DBSystem dbSystem;
private final Formatter<Double> decimals;
private Formatter<Long> timeAmount;
private int tzOffsetMs;
private Formatter<DateHolder> year;
@ -58,10 +59,11 @@ public class SessionPlaceHolder extends AbstractPlanPlaceHolder {
tzOffsetMs = config.getTimeZone().getOffset(System.currentTimeMillis());
timeAmount = formatters.timeAmount();
year = formatters.year();
decimals = formatters.decimals();
}
@Override
public String onPlaceholderRequest(Player p, String params) throws Exception {
public String onPlaceholderRequest(Player p, String params) {
Serializable got = get(params);
return got != null ? got.toString() : null;
}
@ -163,13 +165,13 @@ public class SessionPlaceHolder extends AbstractPlanPlaceHolder {
return database.query(PlayerCountQueries.newPlayerCount(monthAgo(), now(), serverUUID));
case "ping_total":
return database.query(PingQueries.averagePing(0L, now(), serverUUID));
return decimals.apply(database.query(PingQueries.averagePing(0L, now(), serverUUID))) + " ms";
case "ping_day":
return database.query(PingQueries.averagePing(dayAgo(), now(), serverUUID));
return decimals.apply(database.query(PingQueries.averagePing(dayAgo(), now(), serverUUID))) + " ms";
case "ping_week":
return database.query(PingQueries.averagePing(weekAgo(), now(), serverUUID));
return decimals.apply(database.query(PingQueries.averagePing(weekAgo(), now(), serverUUID))) + " ms";
case "ping_month":
return database.query(PingQueries.averagePing(monthAgo(), now(), serverUUID));
return decimals.apply(database.query(PingQueries.averagePing(monthAgo(), now(), serverUUID))) + " ms";
case "sessions_peak_count":
return database.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID)).map(DateObj::getValue).orElse(0);