-
-
Notifications
You must be signed in to change notification settings - Fork 17
GH-926 Add teleport timer to TeleportBackCommand, add teleport-here functionality. #926
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
Open
Jakubk15
wants to merge
7
commits into
master
Choose a base branch
from
improve-tpa
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10ec79a
Add teleport timer to TeleportBackCommand, add self-teleport request …
Jakubk15 855beaa
Add LuckPerms to runServer task for testing purposes
Jakubk15 d73ce90
Add missing permissions, change translations to reflect Mike's sugges…
Jakubk15 bab4e63
Move permissions to constants class
Jakubk15 f4d518b
Use class instead of interface
Jakubk15 e4a955d
remove unnecessary new lines, inline fields, change access
Jakubk15 04e3fe9
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/te…
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...rc/main/java/com/eternalcode/core/feature/teleportrequest/self/SelfRequesterArgument.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.eternalcode.core.feature.teleportrequest.self; | ||
|
||
import com.eternalcode.core.bridge.litecommand.argument.AbstractViewerArgument; | ||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.lite.LiteArgument; | ||
import com.eternalcode.core.translation.Translation; | ||
import com.eternalcode.core.translation.TranslationManager; | ||
import dev.rollczi.litecommands.argument.Argument; | ||
import dev.rollczi.litecommands.argument.parser.ParseResult; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.suggestion.SuggestionContext; | ||
import dev.rollczi.litecommands.suggestion.SuggestionResult; | ||
import org.bukkit.Server; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.HumanEntity; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Objects; | ||
|
||
@LiteArgument(type = Player.class, name = SelfRequesterArgument.KEY) | ||
class SelfRequesterArgument extends AbstractViewerArgument<Player> { | ||
|
||
static final String KEY = "selfrequester"; | ||
|
||
private final TeleportHereRequestService requestService; | ||
private final Server server; | ||
|
||
@Inject | ||
SelfRequesterArgument(TeleportHereRequestService requestService, TranslationManager translationManager, Server server) { | ||
super(translationManager); | ||
this.requestService = requestService; | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public ParseResult<Player> parse(Invocation<CommandSender> invocation, String argument, Translation translation) { | ||
Player target = this.server.getPlayer(argument); | ||
|
||
if (!(invocation.sender() instanceof Player player)) { | ||
return ParseResult.failure(translation.argument().onlyPlayer()); | ||
} | ||
|
||
if (target == null || !this.requestService.hasRequest(target.getUniqueId(), player.getUniqueId())) { | ||
return ParseResult.failure(translation.tpa().tpaDenyNoRequestMessage()); | ||
} | ||
|
||
return ParseResult.success(target); | ||
} | ||
|
||
@Override | ||
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<Player> argument, SuggestionContext context) { | ||
if (!(invocation.sender() instanceof Player player)) { | ||
return SuggestionResult.empty(); | ||
} | ||
|
||
return this.requestService.findRequests(player.getUniqueId()).stream() | ||
.map(this.server::getPlayer) | ||
.filter(Objects::nonNull) | ||
.map(HumanEntity::getName) | ||
.collect(SuggestionResult.collector()); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...in/java/com/eternalcode/core/feature/teleportrequest/self/TeleportHereRequestService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.eternalcode.core.feature.teleportrequest.self; | ||
|
||
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings; | ||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.component.Service; | ||
import com.google.common.cache.Cache; | ||
import com.google.common.cache.CacheBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Service | ||
class TeleportHereRequestService { | ||
|
||
private final Cache<UUID, UUID> requests; | ||
|
||
@Inject | ||
TeleportHereRequestService(TeleportRequestSettings settings) { | ||
this.requests = CacheBuilder | ||
.newBuilder() | ||
.expireAfterWrite(settings.teleportExpire()) | ||
.build(); | ||
} | ||
|
||
void createRequest(UUID requester, UUID target) { | ||
this.requests.put(requester, target); | ||
} | ||
|
||
void removeRequest(UUID requester) { | ||
this.requests.asMap().remove(requester); | ||
} | ||
|
||
boolean hasRequest(UUID requester, UUID target) { | ||
Map<UUID, UUID> map = this.requests.asMap(); | ||
|
||
for (Map.Entry<UUID, UUID> entry : map.entrySet()) { | ||
if (entry.getKey().equals(requester) && entry.getValue().equals(target)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
List<UUID> findRequests(UUID target) { | ||
Map<UUID, UUID> map = this.requests.asMap(); | ||
|
||
List<UUID> requesters = new ArrayList<>(); | ||
|
||
for (Map.Entry<UUID, UUID> entry : map.entrySet()) { | ||
if (entry.getValue().equals(target)) { | ||
requesters.add(entry.getKey()); | ||
} | ||
} | ||
|
||
return requesters; | ||
} | ||
|
||
} |
114 changes: 114 additions & 0 deletions
114
...src/main/java/com/eternalcode/core/feature/teleportrequest/self/TpaHereActionCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.eternalcode.core.feature.teleportrequest.self; | ||
|
||
import com.eternalcode.annotations.scan.command.DescriptionDocs; | ||
import com.eternalcode.commons.bukkit.position.PositionAdapter; | ||
import com.eternalcode.core.feature.teleport.TeleportTaskService; | ||
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings; | ||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.notice.NoticeService; | ||
import dev.rollczi.litecommands.annotations.argument.Arg; | ||
import dev.rollczi.litecommands.annotations.command.RootCommand; | ||
import dev.rollczi.litecommands.annotations.context.Context; | ||
import dev.rollczi.litecommands.annotations.execute.Execute; | ||
import org.bukkit.Server; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RootCommand | ||
public class TpaHereActionCommand { | ||
|
||
private final TeleportHereRequestService requestService; | ||
private final TeleportTaskService teleportTaskService; | ||
private final TeleportRequestSettings settings; | ||
private final NoticeService noticeService; | ||
private final Server server; | ||
|
||
@Inject | ||
TpaHereActionCommand(TeleportHereRequestService requestService, TeleportTaskService teleportTaskService, TeleportRequestSettings settings, NoticeService noticeService, Server server) { | ||
this.requestService = requestService; | ||
this.teleportTaskService = teleportTaskService; | ||
this.settings = settings; | ||
this.noticeService = noticeService; | ||
this.server = server; | ||
} | ||
|
||
@Execute(name = "tpahereaccept") | ||
void accept(@Context Player player, @Arg(SelfRequesterArgument.KEY) Player target) { | ||
this.teleportTaskService.createTeleport( | ||
player.getUniqueId(), | ||
PositionAdapter.convert(player.getLocation()), | ||
PositionAdapter.convert(target.getLocation()), | ||
this.settings.teleportTime() | ||
); | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
this.requestService.removeRequest(target.getUniqueId()); | ||
|
||
this.noticeService | ||
.create() | ||
.player(player.getUniqueId()) | ||
.notice(translation -> translation.tpa().tpaAcceptMessage()) | ||
.placeholder("{PLAYER}", target.getName()) | ||
.send(); | ||
|
||
this.noticeService | ||
.create() | ||
.player(target.getUniqueId()) | ||
.notice(translation -> translation.tpa().tpaAcceptReceivedMessage()) | ||
.placeholder("{PLAYER}", player.getName()) | ||
.send(); | ||
} | ||
|
||
@Execute(name = "tpaheredeny") | ||
@DescriptionDocs(description = "Deny a teleport here request") | ||
void executeTarget(@Context Player player, @Arg(SelfRequesterArgument.KEY) Player target) { | ||
this.requestService.removeRequest(target.getUniqueId()); | ||
|
||
this.noticeService | ||
.create() | ||
.player(player.getUniqueId()) | ||
.notice(translation -> translation.tpa().tpaDenyDoneMessage()) | ||
.placeholder("{PLAYER}", target.getName()) | ||
.send(); | ||
|
||
this.noticeService | ||
.create() | ||
.player(target.getUniqueId()) | ||
.notice(translation -> translation.tpa().tpaDenyReceivedMessage()) | ||
.placeholder("{PLAYER}", player.getName()) | ||
.send(); | ||
} | ||
|
||
@Execute(name = "tpaheredeny -all") | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@DescriptionDocs(description = "Deny all teleport here requests") | ||
void executeAll(@Context Player player) { | ||
List<UUID> requests = this.requestService.findRequests(player.getUniqueId()); | ||
|
||
if (requests.isEmpty()) { | ||
|
||
this.noticeService.player(player.getUniqueId(), translation -> translation.tpa().tpaDenyNoRequestMessage()); | ||
|
||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
for (UUID uniqueId : requests) { | ||
Player requester = this.server.getPlayer(uniqueId); | ||
|
||
this.requestService.removeRequest(uniqueId); | ||
|
||
if (requester != null) { | ||
|
||
this.noticeService | ||
.create() | ||
.player(uniqueId) | ||
.notice(translation -> translation.tpa().tpaDenyReceivedMessage()) | ||
.placeholder("{PLAYER}", player.getName()) | ||
.send(); | ||
} | ||
} | ||
|
||
this.noticeService.player(player.getUniqueId(), translation -> translation.tpa().tpaDenyAllDenied()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.