Skip to content

Commit 6a9e517

Browse files
committed
Improve checking spenttime target user.
1 parent af67b24 commit 6a9e517

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

  • spenttime-plugin/src/main/java/com/github/imdmk/spenttime/litecommands/implementation

spenttime-plugin/src/main/java/com/github/imdmk/spenttime/litecommands/implementation/SpentTimeCommand.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import com.github.imdmk.spenttime.user.User;
99
import com.github.imdmk.spenttime.util.DurationUtil;
1010
import dev.rollczi.litecommands.annotations.argument.Arg;
11+
import dev.rollczi.litecommands.annotations.async.Async;
1112
import dev.rollczi.litecommands.annotations.command.Command;
1213
import dev.rollczi.litecommands.annotations.context.Context;
1314
import dev.rollczi.litecommands.annotations.execute.Execute;
1415
import dev.rollczi.litecommands.annotations.permission.Permission;
1516
import org.bukkit.command.CommandSender;
1617
import org.bukkit.entity.Player;
1718

19+
import java.time.Duration;
20+
1821
@Command(name = "spenttime")
1922
public 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

Comments
 (0)