88import com .github .imdmk .spenttime .user .User ;
99import com .github .imdmk .spenttime .util .DurationUtil ;
1010import dev .rollczi .litecommands .annotations .argument .Arg ;
11+ import dev .rollczi .litecommands .annotations .async .Async ;
1112import dev .rollczi .litecommands .annotations .command .Command ;
1213import dev .rollczi .litecommands .annotations .context .Context ;
1314import dev .rollczi .litecommands .annotations .execute .Execute ;
1415import dev .rollczi .litecommands .annotations .permission .Permission ;
1516import org .bukkit .command .CommandSender ;
1617import org .bukkit .entity .Player ;
1718
19+ import java .time .Duration ;
20+
1821@ Command (name = "spenttime" )
1922public class SpentTimeCommand {
2023
@@ -41,17 +44,30 @@ void showSpentTime(@Context Player player) {
4144 this .notificationSender .send (player , notification );
4245 }
4346
47+ @ Async
4448 @ Execute
4549 @ Permission ("command.spenttime.target" )
4650 void showTarget (@ Context CommandSender sender , @ Arg User target ) {
47- String userSpentTime = DurationUtil .toHumanReadable (target .getSpentTimeDuration ());
51+ String targetName = target .getName ();
52+ String targetSpentTime = DurationUtil .toHumanReadable (this .updateSpentTime (target ));
4853
4954 Notification notification = new NotificationFormatter ()
5055 .notification (this .notificationSettings .targetSpentTime )
51- .placeholder ("{PLAYER}" , target . getName () )
52- .placeholder ("{TIME}" , userSpentTime )
56+ .placeholder ("{PLAYER}" , targetName )
57+ .placeholder ("{TIME}" , targetSpentTime )
5358 .build ();
5459
5560 this .notificationSender .send (sender , notification );
5661 }
62+
63+ private Duration updateSpentTime (User target ) {
64+ Duration playerSpentTime = this .bukkitPlayerSpentTimeService .getSpentTime (target .getUuid ());
65+ Duration userSpentTime = target .getSpentTimeDuration ();
66+
67+ if (!playerSpentTime .equals (userSpentTime )) {
68+ target .setSpentTime (playerSpentTime );
69+ }
70+
71+ return playerSpentTime ;
72+ }
5773}
0 commit comments