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-577 Add TpaCommand to support ignored players #577

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,39 +1,41 @@
package com.eternalcode.core.feature.teleport.request;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.feature.ignore.IgnoreService;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import dev.rollczi.litecommands.argument.Arg;
import dev.rollczi.litecommands.command.execute.Execute;
import dev.rollczi.litecommands.command.permission.Permission;
import dev.rollczi.litecommands.command.route.Route;
import org.bukkit.entity.Player;
import panda.std.reactive.Completable;

@Route(name = "tpa")
@Permission("eternalcore.tpa")
class TpaCommand {

private final TeleportRequestService requestService;
private final IgnoreService ignoreService;
private final NoticeService noticeService;

@Inject
TpaCommand(TeleportRequestService requestService, NoticeService noticeService) {
TpaCommand(TeleportRequestService requestService, IgnoreService ignoreService, NoticeService noticeService) {
this.requestService = requestService;
this.ignoreService = ignoreService;
this.noticeService = noticeService;
}

@Execute(required = 1)
@DescriptionDocs(description = "Send teleport request to player", arguments = "<player>")
void execute(Player player, @Arg Player target) {
if (player.equals(target)) {

this.noticeService.player(player.getUniqueId(), translation -> translation.tpa().tpaSelfMessage());

return;
}

if (this.requestService.hasRequest(player.getUniqueId(), target.getUniqueId())) {

this.noticeService.player(player.getUniqueId(), translation -> translation.tpa().tpaAlreadySentMessage());

return;
Expand All @@ -46,14 +48,29 @@ void execute(Player player, @Arg Player target) {
.placeholder("{PLAYER}", target.getName())
.send();

this.noticeService
.create()
.player(target.getUniqueId())
.notice(translation -> translation.tpa().tpaReceivedMessage())
.placeholder("{PLAYER}", player.getName())
.send();
this.isIgnoring(target, player).then((isIgnoring) -> {
if (isIgnoring) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.tpa().tpaTargetIgnoresYou())
.placeholder("{PLAYER}", target.getName())
.send();

return;
}

this.noticeService.create()
.player(target.getUniqueId())
.notice(translation -> translation.tpa().tpaReceivedMessage())
.placeholder("{PLAYER}", player.getName())
.send();

this.requestService.createRequest(player.getUniqueId(), target.getUniqueId());
});
}

this.requestService.createRequest(player.getUniqueId(), target.getUniqueId());
Completable<Boolean> isIgnoring(Player target, Player sender) {
return this.ignoreService.isIgnored(target.getUniqueId(), sender.getUniqueId());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.Material;
import org.bukkit.event.entity.EntityDamageEvent;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -186,6 +185,7 @@ interface TpaSection {
Notice tpaAlreadySentMessage();
Notice tpaSentMessage();
Notice tpaReceivedMessage();
Notice tpaTargetIgnoresYou();

Notice tpaDenyNoRequestMessage();
Notice tpaDenyDoneMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ public static class ENTpaSection implements TpaSection {

@Description(" ")
public Notice tpaAcceptAllAccepted = Notice.chat("<green>► <white>All players have accepted your teleport request!");

@Description(" ")
public Notice tpaTargetIgnoresYou = Notice.chat("<green>► <red>{PLAYER} <white>is ignoring you!");
}

@Description({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ public static class PLTpaSection implements TpaSection {

@Description(" ")
public Notice tpaAcceptAllAccepted = Notice.chat("<green>► <white>Zaakceptowano wszystkie prośby o teleportację!");

@Description(" ")
public Notice tpaTargetIgnoresYou = Notice.chat("<green>► <red>{PLAYER} <white>ignoruje Cię!");
}

@Description({
Expand Down