Skip to content

Commit

Permalink
Improve checking spenttime target user.
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK committed Dec 27, 2024
1 parent af67b24 commit 6a9e517
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import com.github.imdmk.spenttime.user.User;
import com.github.imdmk.spenttime.util.DurationUtil;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.async.Async;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.time.Duration;

@Command(name = "spenttime")
public class SpentTimeCommand {

Expand All @@ -41,17 +44,30 @@ void showSpentTime(@Context Player player) {
this.notificationSender.send(player, notification);
}

@Async
@Execute
@Permission("command.spenttime.target")
void showTarget(@Context CommandSender sender, @Arg User target) {
String userSpentTime = DurationUtil.toHumanReadable(target.getSpentTimeDuration());
String targetName = target.getName();
String targetSpentTime = DurationUtil.toHumanReadable(this.updateSpentTime(target));

Notification notification = new NotificationFormatter()
.notification(this.notificationSettings.targetSpentTime)
.placeholder("{PLAYER}", target.getName())
.placeholder("{TIME}", userSpentTime)
.placeholder("{PLAYER}", targetName)
.placeholder("{TIME}", targetSpentTime)
.build();

this.notificationSender.send(sender, notification);
}

private Duration updateSpentTime(User target) {
Duration playerSpentTime = this.bukkitPlayerSpentTimeService.getSpentTime(target.getUuid());
Duration userSpentTime = target.getSpentTimeDuration();

if (!playerSpentTime.equals(userSpentTime)) {
target.setSpentTime(playerSpentTime);
}

return playerSpentTime;
}
}

0 comments on commit 6a9e517

Please sign in to comment.