Skip to content

Commit

Permalink
Added an overload to stopAFK to allow silent stops
Browse files Browse the repository at this point in the history
  • Loading branch information
Dart2112 committed Sep 24, 2024
1 parent a32c6bc commit 8cf9341
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/modules/benja.IdeaProjects.AFKPlus.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions src/main/java/net/lapismc/afkplus/playerdata/AFKPlusPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,20 @@ public void forceStartAFK() {
}

/**
* Stops AFK for this player with a broadcast, Use {@link #forceStopAFK()} for a silent stop
* Stops AFK for this player with a broadcast, Use {@link #forceStopAFK()} or {@link #stopAFK(boolean)} for a silent stop
* This can be cancelled with {@link AFKStopEvent}
*/
public void stopAFK() {
stopAFK(false);
}

/**
* Stops AFK for this player with a broadcast, Use {@link #forceStopAFK()} for a silent stop
* This can be cancelled with {@link AFKStopEvent}
*
* @param silent Skips broadcasting when true, used to cleanly exit afk when a player disconnects
*/
public void stopAFK(boolean silent) {
if (Bukkit.getPlayer(getUUID()) == null) {
//Player isn't online, stop here
return;
Expand All @@ -227,8 +237,10 @@ public void stopAFK() {
//This will replace the {TIME} variable, if present
String afkTime = plugin.prettyTime.formatDuration(plugin.reduceDurationList
(plugin.prettyTime.calculatePreciseDuration(new Date(afkStart))));
broadcastOthers(event.getBroadcastMessage().replace("{PLAYER}", getName()).replace("{TIME}", afkTime));
selfMessage(event.getSelfMessage().replace("{PLAYER}", getName()).replace("{TIME}", afkTime));
if (!silent) {
broadcastOthers(event.getBroadcastMessage().replace("{PLAYER}", getName()).replace("{TIME}", afkTime));
selfMessage(event.getSelfMessage().replace("{PLAYER}", getName()).replace("{TIME}", afkTime));
}
//Stop the AFK status
forceStopAFK();
}
Expand Down

0 comments on commit 8cf9341

Please sign in to comment.