Fix bed entry statistic labels
This commit is contained in:
@@ -5,6 +5,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import io.papermc.paper.block.bed.BedEnterAction;
|
||||
import io.papermc.paper.block.bed.BedEnterProblem;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -436,9 +438,29 @@ final class PlayerStatsListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onBedEnter(PlayerBedEnterEvent event) {
|
||||
stats.increment(event.getPlayer(), "beds.enter_attempts");
|
||||
stats.increment(event.getPlayer(), "beds.enter_action." + event.enterAction().toString());
|
||||
stats.increment(event.getPlayer(), "beds.enter_result." + bedEnterResult(event.enterAction()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private static String bedEnterResult(BedEnterAction action) {
|
||||
BedEnterProblem problem = action.problem();
|
||||
if (problem != null) {
|
||||
if (problem == BedEnterProblem.TOO_FAR_AWAY) return "too_far_away";
|
||||
if (problem == BedEnterProblem.OBSTRUCTED) return "obstructed";
|
||||
if (problem == BedEnterProblem.NOT_SAFE) return "not_safe";
|
||||
if (problem == BedEnterProblem.EXPLOSION) return "explosion";
|
||||
return "other_problem";
|
||||
}
|
||||
|
||||
boolean canSleep = action.canSleep().success();
|
||||
boolean canSetSpawn = action.canSetSpawn().success();
|
||||
if (canSleep && canSetSpawn) return "sleep_and_spawn";
|
||||
if (canSleep) return "sleep_only";
|
||||
if (canSetSpawn) return "spawn_only";
|
||||
return "denied";
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
|
||||
@@ -78,6 +78,7 @@ final class SqlStatsStorage implements StatsStorage {
|
||||
""");
|
||||
}
|
||||
ensureStatKeyCapacity(db);
|
||||
removeMalformedBedActionStats(db);
|
||||
}
|
||||
|
||||
private void ensureStatKeyCapacity(Connection db) throws SQLException {
|
||||
@@ -104,6 +105,14 @@ final class SqlStatsStorage implements StatsStorage {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeMalformedBedActionStats(Connection db) throws SQLException {
|
||||
try (PreparedStatement statement = db.prepareStatement(
|
||||
"DELETE FROM rose_player_stats WHERE stat_key LIKE ?")) {
|
||||
statement.setString(1, "beds.enter_action.bedenteractionimpl%");
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerRecord load(UUID uuid, String currentName) throws Exception {
|
||||
Connection db = ensureConnection();
|
||||
|
||||
Reference in New Issue
Block a user