Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-903 Add seen command feature #918

Merged
merged 9 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.eternalcode.core.feature.seen;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.user.User;
import com.eternalcode.core.util.DurationUtil;
import com.eternalcode.core.viewer.Viewer;
import dev.rollczi.litecommands.annotations.argument.Arg;
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.OfflinePlayer;
import org.bukkit.Server;

import java.time.Duration;
import java.time.Instant;

@Command(name = "seen", aliases = { "lastonline" })
@Permission("eternalcore.seen")
class SeenCommand {

public static final int NEVER_JOINED_BEFORE = 0;
private final Server server;
private final NoticeService noticeService;

@Inject
public SeenCommand(Server server, NoticeService noticeService) {
this.server = server;
this.noticeService = noticeService;
}

@Execute
@DescriptionDocs(description = "Shows when the player was last seen on the server")
void execute(@Context Viewer sender, @Arg User target) {
OfflinePlayer targetPlayer = this.server.getOfflinePlayer(target.getUniqueId());

if (targetPlayer.isOnline()) {
this.noticeService.create()
.viewer(sender)
.notice(translation -> translation.seen().nowOnline())
.placeholder("{PLAYER}", target.getName())
.send();

return;
}

long lastPlayed = targetPlayer.getLastPlayed();

if (lastPlayed == NEVER_JOINED_BEFORE) {
this.noticeService.create()
.viewer(sender)
.notice(translation -> translation.seen().neverPlayedBefore())
.placeholder("{PLAYER}", target.getName())
.send();

return;
}

Duration lastPlayedBetween = Duration.between(Instant.ofEpochMilli(lastPlayed), Instant.now());
String lastPlayedFormatted = DurationUtil.format(lastPlayedBetween, true);

this.noticeService.create()
.viewer(sender)
.notice(translation -> translation.seen().lastSeen())
.placeholder("{PLAYER}", target.getName())
.placeholder("{SEEN}", lastPlayedFormatted)
.send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eternalcode.core.feature.seen.messages;

import com.eternalcode.multification.notice.Notice;
import lombok.Getter;
import lombok.experimental.Accessors;
import net.dzikoysk.cdn.entity.Contextual;
import net.dzikoysk.cdn.entity.Description;

@Getter
@Accessors(fluent = true)
@Contextual
public class ENSeenMessages implements SeenMessages {

@Description("# {PLAYER} - The player who is never played before on the server")
public Notice neverPlayedBefore = Notice.chat("<green>{PLAYER} has not played before on this server.");

@Description("# {PLAYER} - The player who was last seen on the server, {SEEN} - Time since last login")
public Notice lastSeen = Notice.chat("<green>{PLAYER} was last seen {SEEN} ago.");

@Description("# {PLAYER} - The player who is now online")
public Notice nowOnline = Notice.chat("<green>{PLAYER} is now online!");

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eternalcode.core.feature.seen.messages;

import com.eternalcode.multification.notice.Notice;
import lombok.Getter;
import lombok.experimental.Accessors;
import net.dzikoysk.cdn.entity.Contextual;
import net.dzikoysk.cdn.entity.Description;

@Getter
@Accessors(fluent = true)
@Contextual
public class PLSeenMessages implements SeenMessages {

@Description("# {PLAYER} - Gracz który nigdy nie grał na serwerze")
public Notice neverPlayedBefore = Notice.chat("<green>{PLAYER} nie grał nigdy na tym serwerze.");

@Description("# {PLAYER} - Gracz który ostatnio był widziany na serwerze, {SEEN} - Czas od ostatniego logowania")
public Notice lastSeen = Notice.chat("<green>{PLAYER} był ostatnio widziany {SEEN} temu.");

@Description("# {PLAYER} - Gracz który jest aktualnie online")
public Notice nowOnline = Notice.chat("<green>{PLAYER} jest aktualnie online!");

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.eternalcode.core.feature.seen.messages;

import com.eternalcode.multification.notice.Notice;

public interface SeenMessages {

Notice neverPlayedBefore();
Notice lastSeen();
Notice nowOnline();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.privatechat.messages.PrivateChatMessages;
import com.eternalcode.core.feature.randomteleport.messages.RandomTeleportMessages;
import com.eternalcode.core.feature.seen.messages.SeenMessages;
import com.eternalcode.core.feature.setslot.messages.SetSlotMessages;
import com.eternalcode.core.feature.spawn.messages.SpawnMessages;
import com.eternalcode.core.feature.sudo.messages.SudoMessages;
Expand Down Expand Up @@ -219,6 +220,8 @@ interface ContainerSection {
InventorySection inventory();
// player section
PlayerSection player();
//Seen section
SeenMessages seen();
// spawn section
SpawnMessages spawn();
// set slot section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.eternalcode.core.feature.home.messages.ENHomeMessages;
import com.eternalcode.core.feature.jail.messages.ENJailMessages;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.seen.messages.ENSeenMessages;
import com.eternalcode.core.feature.setslot.messages.ENSetSlotMessages;
import com.eternalcode.core.feature.privatechat.messages.ENPrivateMessages;
import com.eternalcode.core.feature.randomteleport.messages.ENRandomTeleportMessages;
Expand Down Expand Up @@ -131,6 +132,12 @@ public static class ENFormatSection implements Format {
})
public ENHelpOpMessages helpOp = new ENHelpOpMessages();

@Description({
" ",
"# This section is responsible for the messages of the /seen command"
})
public ENSeenMessages seen = new ENSeenMessages();

@Description({
" ",
"# This section is responsible for the communication between administration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.eternalcode.core.feature.home.messages.PLHomeMessages;
import com.eternalcode.core.feature.jail.messages.PLJailMessages;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.seen.messages.PLSeenMessages;
import com.eternalcode.core.feature.setslot.messages.PLSetSlotMessages;
import com.eternalcode.core.feature.privatechat.messages.PLPrivateChatMessages;
import com.eternalcode.core.feature.randomteleport.messages.PLRandomTeleportMessages;
Expand Down Expand Up @@ -140,6 +141,12 @@ public static class PLFormatSection implements Format {
})
public PLSudoMessages sudo = new PLSudoMessages();

@Description({
" ",
"# Ta sekcja odpowiada za wiadomości komendy /seen"
})
public PLSeenMessages seen = new PLSeenMessages();

@Description({
" ",
"# Ta sekcja odpowiada za komunikaty związane z teleportacją",
Expand Down