Notify players when score buckets change

This commit is contained in:
2026-09-26 18:20:54 -07:00
parent e4bebd3908
commit b165d67118
4 changed files with 31 additions and 4 deletions

View File

@@ -13,6 +13,8 @@
* `/score-bucket create <id> <singular> <plural> <initialValue> [admin|global|player|none]` - Creates a bucket (operators). * `/score-bucket create <id> <singular> <plural> <initialValue> [admin|global|player|none]` - Creates a bucket (operators).
* `/score-bucket <playerName|all> <bucketId>` - Switches a player or the server default (operators). * `/score-bucket <playerName|all> <bucketId>` - Switches a player or the server default (operators).
When a player's active bucket changes, they are told the bucket name and their current score with its singular or plural unit.
NOTES: NOTES:
* All commands will use the executing player in place of [playerName] if it is omitted. * All commands will use the executing player in place of [playerName] if it is omitted.
* Permissions support is coming AFTER I get archive to work. * Permissions support is coming AFTER I get archive to work.

View File

@@ -23,6 +23,6 @@
| SK-01 | Done | Save scores between server launches. | | SK-01 | Done | Save scores between server launches. |
| SK-02 | Done | Allow tracking scores by bucket. An admin or other plugin should be able to create types of scores with named other than points. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0 } Each player's score will be tracked in a bucket by id. Players may be all switched to a bucket or individually switched. |\ | SK-02 | Done | Allow tracking scores by bucket. An admin or other plugin should be able to create types of scores with named other than points. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0 } Each player's score will be tracked in a bucket by id. Players may be all switched to a bucket or individually switched. |\
| SK-03 | Done | Add optional score reporting to buckets with these four values. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0, reporting:"admin|global|player|none" } admin means ops/admin only, global means everyone on the server, player means only tell the player, and none means don't report changes. | SK-03 | Done | Add optional score reporting to buckets with these four values. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0, reporting:"admin|global|player|none" } admin means ops/admin only, global means everyone on the server, player means only tell the player, and none means don't report changes.
| SK-04 | Ready | Tell a player when their bucket changes. Something like "You are now tracking ${id}. You have ${score} ${plural or singular depending in score}." | | SK-04 | Done | Tell a player when their bucket changes. Something like "You are now tracking ${id}. You have ${score} ${plural or singular depending in score}." |
| SK-05 | Ready | Enable high score runs for a bucket. Admins or pugins should be able to start a run on a certain kind of score. The top n (configurable) players will have their scores reported globally for this bucket and the individual player will have their score reported to them when it changes. Scores will be optionally reset to their initialValue with the old score for this bucket saved. High score runs will have a lifetime of a target high score, a time like 4 hours or 1 week, or until-disabled. When the high score run is finished all players will be messaged a table with the top n places and their scores along with the individual user's place and score. The scores will be reset to their previous values if they were reset to their initialValue at the beginning otherwise they will be left alone. | | SK-05 | Ready | Enable high score runs for a bucket. Admins or pugins should be able to start a run on a certain kind of score. The top n (configurable) players will have their scores reported globally for this bucket and the individual player will have their score reported to them when it changes. Scores will be optionally reset to their initialValue with the old score for this bucket saved. High score runs will have a lifetime of a target high score, a time like 4 hours or 1 week, or until-disabled. When the high score run is finished all players will be messaged a table with the top n places and their scores along with the individual user's place and score. The scores will be reset to their previous values if they were reset to their initialValue at the beginning otherwise they will be left alone. |
| SK-06 | Ready | Score archiving. Scores either all or within a given bucket should be able to be archived and reset to their initial value. The archived scores should be able to be listed via a command. | | SK-06 | Ready | Score archiving. Scores either all or within a given bucket should be able to be archived and reset to their initial value. The archived scores should be able to be listed via a command. |

View File

@@ -174,19 +174,33 @@ public class ScoreKeeperPlugin extends JavaPlugin {
} }
public void switchPlayerBucket(Player player, String bucketId) { public void switchPlayerBucket(Player player, String bucketId) {
requireBucket(bucketId); ScoreBucket bucket = requireBucket(bucketId);
UUID playerId = player.getUniqueId(); UUID playerId = player.getUniqueId();
String previousBucketId = getPlayerBucket(player);
if (bucketId.equals(_defaultBucketId)) { if (bucketId.equals(_defaultBucketId)) {
_playerBuckets.remove(playerId); _playerBuckets.remove(playerId);
} else { } else {
_playerBuckets.put(playerId, bucketId); _playerBuckets.put(playerId, bucketId);
} }
if (!previousBucketId.equals(bucketId)) {
sendBucketChangeMessage(player, bucket);
}
} }
public void switchAllPlayers(String bucketId) { public void switchAllPlayers(String bucketId) {
requireBucket(bucketId); requireBucket(bucketId);
Map<UUID, String> previousBuckets = new LinkedHashMap<>();
for (Player player : getServer().getOnlinePlayers()) {
previousBuckets.put(player.getUniqueId(), getPlayerBucket(player));
}
_defaultBucketId = bucketId; _defaultBucketId = bucketId;
_playerBuckets.clear(); _playerBuckets.clear();
ScoreBucket bucket = requireBucket(bucketId);
for (Player player : getServer().getOnlinePlayers()) {
if (!bucketId.equals(previousBuckets.get(player.getUniqueId()))) {
sendBucketChangeMessage(player, bucket);
}
}
} }
// endregion // endregion
@@ -204,6 +218,15 @@ public class ScoreKeeperPlugin extends JavaPlugin {
return bucket; return bucket;
} }
private void sendBucketChangeMessage(Player player, ScoreBucket bucket) {
int score = getScore(player, bucket.getId());
String unit = score == 1 ? bucket.getSingular() : bucket.getPlural();
sendMessage(
player,
Component.text(
"You are now tracking " + bucket.getId() + ". You have " + score + " " + unit + "."));
}
private void loadScores() { private void loadScores() {
File scoreFile = new File(getDataFolder(), "scores.yml"); File scoreFile = new File(getDataFolder(), "scores.yml");
if (!scoreFile.isFile()) { if (!scoreFile.isFile()) {

View File

@@ -103,8 +103,10 @@ public class ScoreBucketCommand implements CommandExecutor {
private void switchPlayerBucket(CommandSender sender, Player target, String bucketId) { private void switchPlayerBucket(CommandSender sender, Player target, String bucketId) {
try { try {
_plugin.switchPlayerBucket(target, bucketId); _plugin.switchPlayerBucket(target, bucketId);
if (sender != target) {
_plugin.sendMessage( _plugin.sendMessage(
sender, Component.text(target.getName() + " is now tracking " + bucketId + ".")); sender, Component.text(target.getName() + " is now tracking " + bucketId + "."));
}
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
sendError(sender, ex.getMessage()); sendError(sender, ex.getMessage());
} }