-
-
Notifications
You must be signed in to change notification settings - Fork 21
GH-1192 Extend /back functionality to per-death and per-teleport #1192
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
21
commits into
master
Choose a base branch
from
back-on-deatch-permission-wip
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.
+408
−92
Open
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ac0a158
WIP permission for back on death.
vLuckyyy 32bce4b
Improve back logic
Jakubk15 1b130ad
Merge branch 'master' into back-on-deatch-permission-wip
Jakubk15 c733197
Update eternalcore-core/src/main/java/com/eternalcode/core/configurat…
Jakubk15 a2b33a8
Adjust to others' suggestions
Jakubk15 043f190
Document tpaTimer to also work for /back command
Jakubk15 98fc5f6
Simplify if-else statement
Jakubk15 d973b9c
Merge branch 'master' into back-on-deatch-permission-wip
Jakubk15 ad729d7
Merge branch 'master' into back-on-deatch-permission-wip
Jakubk15 ed16382
Add missing comma
Jakubk15 265a842
wip
Jakubk15 cc42f2d
Update messages
Jakubk15 75ea7fd
Adjust to others' suggestions (WIP)
Jakubk15 738ee16
Remove unused imports
Jakubk15 29b76e2
Create a default executor for /back command
Jakubk15 16362d6
Add proper permission to BackCommand
Jakubk15 8f7ffa1
Reduce nesting level
Jakubk15 282c4bd
Properly send a message to player when teleporting back
Jakubk15 b41d2d4
Fix ClassCastException
Jakubk15 ecae120
Revert accidental world name change
Jakubk15 52a5d8a
Encapsulate classes
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...rnalcode/core/configuration/migrations/Migration_0030_Move_back_to_dedicated_section.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,17 @@ | ||
| package com.eternalcode.core.configuration.migrations; | ||
|
|
||
| import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move; | ||
|
|
||
| import eu.okaeri.configs.migrate.builtin.NamedMigration; | ||
|
|
||
| public class Migration_0030_Move_back_to_dedicated_section extends NamedMigration { | ||
| Migration_0030_Move_back_to_dedicated_section() { | ||
| super( | ||
| "Improve homes config", | ||
| move("teleport.teleportedToLastLocation", "back.teleportedToLastTeleportLocation"), | ||
| move("teleport.teleportedSpecifiedPlayerLastLocation", "back.teleportedTargetPlayerToLastTeleportLocation"), | ||
| move("teleport.lastLocationNoExist", "back.lastLocationNotFound") | ||
| ); | ||
| } | ||
| } | ||
|
|
||
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
108 changes: 108 additions & 0 deletions
108
eternalcore-core/src/main/java/com/eternalcode/core/feature/back/BackCommand.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,108 @@ | ||
| package com.eternalcode.core.feature.back; | ||
|
|
||
| import com.eternalcode.annotations.scan.command.DescriptionDocs; | ||
| import com.eternalcode.commons.bukkit.position.Position; | ||
| import com.eternalcode.commons.bukkit.position.PositionAdapter; | ||
| import com.eternalcode.core.injector.annotations.Inject; | ||
| import com.eternalcode.core.notice.NoticeService; | ||
| 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.Sender; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.execute.ExecuteDefault; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import java.util.Optional; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| @Command(name = "back") | ||
| public class BackCommand { | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private final BackService backService; | ||
| private final NoticeService noticeService; | ||
|
|
||
| @Inject | ||
| public BackCommand(BackService backService, NoticeService noticeService) { | ||
| this.backService = backService; | ||
| this.noticeService = noticeService; | ||
| } | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @ExecuteDefault | ||
| @Execute(name = "teleport") | ||
| @Permission("eternalcore.back.teleport") | ||
| @DescriptionDocs(description = "Teleport to your last teleport location") | ||
| public void executeBackTeleport(@Sender Player player) { | ||
| if (this.teleportBack(player)) { | ||
| this.noticeService.player(player.getUniqueId(), translation -> translation.back().teleportedToLastTeleportLocation()); | ||
| return; | ||
| } | ||
| this.noticeService.player(player.getUniqueId(), translation -> translation.back().lastLocationNotFound()); | ||
| } | ||
|
|
||
| @Execute(name = "death") | ||
| @Permission("eternalcore.back.death") | ||
| @DescriptionDocs(description = "Teleport to your last death location") | ||
| public void executeBackDeath(@Sender Player player) { | ||
| if (this.teleportBackDeath(player)) { | ||
| this.noticeService.player(player.getUniqueId(), translation -> translation.back().teleportedToLastDeathLocation()); | ||
| return; | ||
| } | ||
| this.noticeService.player(player.getUniqueId(), translation -> translation.back().lastLocationNotFound()); | ||
| } | ||
|
|
||
| @Execute(name = "teleport") | ||
| @Permission("eternalcore.back.teleport.other") | ||
| @DescriptionDocs(description = "Teleport specified player to their last teleport location", arguments = "<player>") | ||
| public void executeBackTeleportOther(@Sender Viewer viewer, @Arg Player target) { | ||
| if (this.teleportBack(target)) { | ||
| this.noticeService.player(target.getUniqueId(), translation -> translation.back().teleportedToLastTeleportLocationByAdmin()); | ||
|
|
||
| this.noticeService.create() | ||
| .viewer(viewer) | ||
| .notice(translation -> translation.back().teleportedTargetPlayerToLastTeleportLocation()) | ||
| .placeholder("{PLAYER}", target.getName()) | ||
| .send(); | ||
| return; | ||
| } | ||
| this.noticeService.player(viewer.getUniqueId(), translation -> translation.back().lastLocationNotFound()); | ||
| } | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Execute(name = "death") | ||
| @Permission("eternalcore.back.death.other") | ||
| @DescriptionDocs(description = "Teleport specified player to their last death location", arguments = "<player>") | ||
| public void executeBackDeathOther(@Sender Viewer viewer, @Arg Player target) { | ||
| if (this.teleportBackDeath(target)) { | ||
| this.noticeService.player(target.getUniqueId(), translation -> translation.back().teleportedToLastDeathLocationByAdmin()); | ||
|
|
||
| this.noticeService.create() | ||
| .viewer(viewer) | ||
| .notice(translation -> translation.back().teleportedTargetPlayerToLastDeathLocation()) | ||
| .placeholder("{PLAYER}", target.getName()) | ||
| .send(); | ||
| return; | ||
| } | ||
| this.noticeService.player(viewer.getUniqueId(), translation -> translation.back().lastLocationNotFound()); | ||
| } | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private boolean teleportBack(Player target) { | ||
| Optional<Position> teleportLocation = this.backService.getTeleportLocation(target.getUniqueId()); | ||
|
|
||
| if (teleportLocation.isPresent()) { | ||
| this.backService.teleportBack(target, PositionAdapter.convert(teleportLocation.get())); | ||
|
|
||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean teleportBackDeath(Player target) { | ||
| Optional<Position> deathLocation = this.backService.getDeathLocation(target.getUniqueId()); | ||
|
|
||
| if (deathLocation.isPresent()) { | ||
| this.backService.teleportBack(target, PositionAdapter.convert(deathLocation.get())); | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
eternalcore-core/src/main/java/com/eternalcode/core/feature/back/BackController.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,36 @@ | ||
| package com.eternalcode.core.feature.back; | ||
|
|
||
| import com.eternalcode.commons.bukkit.position.PositionAdapter; | ||
| import com.eternalcode.core.injector.annotations.Inject; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.entity.PlayerDeathEvent; | ||
| import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
|
||
| public class BackController implements Listener { | ||
|
|
||
| private final BackService backService; | ||
|
|
||
| @Inject | ||
| public BackController(BackService backService) { | ||
| this.backService = backService; | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onPlayerDeath(PlayerDeathEvent event) { | ||
| Player entity = event.getEntity(); | ||
|
|
||
| this.backService.markDeathLocation(entity.getUniqueId(), PositionAdapter.convert(entity.getLocation())); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onPlayerTeleport(PlayerTeleportEvent event) { | ||
| if (event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) { | ||
| return; | ||
| } | ||
|
|
||
| this.backService.markTeleportLocation(event.getPlayer().getUniqueId(), PositionAdapter.convert(event.getFrom())); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
eternalcore-core/src/main/java/com/eternalcode/core/feature/back/BackService.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,76 @@ | ||
| package com.eternalcode.core.feature.back; | ||
|
|
||
| import com.eternalcode.commons.bukkit.position.Position; | ||
| import com.eternalcode.commons.bukkit.position.PositionAdapter; | ||
| import com.eternalcode.core.feature.teleport.TeleportService; | ||
| 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.injector.annotations.component.Service; | ||
| import com.github.benmanes.caffeine.cache.Cache; | ||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| @Service | ||
| public class BackService { | ||
|
|
||
| private static final String BYPASS_PERMISSION = "eternalcore.teleport.bypass"; | ||
|
|
||
| private final TeleportService teleportService; | ||
| private final TeleportTaskService teleportTaskService; | ||
| private final TeleportRequestSettings settings; | ||
|
|
||
| private final Cache<UUID, Position> deathLocations; | ||
| private final Cache<UUID, Position> teleportLocations; | ||
|
|
||
| @Inject | ||
| public BackService( | ||
| TeleportService teleportService, | ||
| TeleportTaskService teleportTaskService, | ||
| TeleportRequestSettings settings | ||
| ) { | ||
| this.teleportService = teleportService; | ||
| this.teleportTaskService = teleportTaskService; | ||
| this.settings = settings; | ||
|
|
||
| this.deathLocations = Caffeine.newBuilder() | ||
| .expireAfterWrite(2, TimeUnit.HOURS) | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .build(); | ||
| this.teleportLocations = Caffeine.newBuilder() | ||
| .expireAfterWrite(2, TimeUnit.HOURS) | ||
| .build(); | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public Optional<Position> getDeathLocation(UUID playerId) { | ||
| return Optional.ofNullable(deathLocations.getIfPresent(playerId)); | ||
| } | ||
|
|
||
| public Optional<Position> getTeleportLocation(UUID playerId) { | ||
| return Optional.ofNullable(teleportLocations.getIfPresent(playerId)); | ||
| } | ||
|
|
||
| public void markDeathLocation(UUID player, Position position) { | ||
| this.deathLocations.put(player, position); | ||
| } | ||
|
|
||
| public void markTeleportLocation(UUID player, Position position) { | ||
| this.teleportLocations.put(player, position); | ||
| } | ||
|
|
||
| public void teleportBack(Player player, Location location) { | ||
| if (player.hasPermission(BYPASS_PERMISSION)) { | ||
| teleportService.teleport(player, location); | ||
| return; | ||
| } | ||
| teleportTaskService.createTeleport( | ||
| player.getUniqueId(), | ||
| PositionAdapter.convert(player.getLocation()), | ||
| PositionAdapter.convert(location), | ||
| settings.tpaTimer() | ||
| ); | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
eternalcore-core/src/main/java/com/eternalcode/core/feature/back/messages/BackMessages.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,19 @@ | ||
| package com.eternalcode.core.feature.back.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
|
|
||
| public interface BackMessages { | ||
|
|
||
| Notice lastLocationNotFound(); | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Teleport do ostatniej lokalizacji teleportacji | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Notice teleportedToLastTeleportLocation(); | ||
| Notice teleportedTargetPlayerToLastTeleportLocation(); | ||
| Notice teleportedToLastTeleportLocationByAdmin(); | ||
|
|
||
| // Teleport do ostatniej lokalizacji śmierci | ||
| Notice teleportedToLastDeathLocation(); | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Notice teleportedTargetPlayerToLastDeathLocation(); | ||
| Notice teleportedToLastDeathLocationByAdmin(); | ||
|
|
||
| } | ||
28 changes: 28 additions & 0 deletions
28
...nalcore-core/src/main/java/com/eternalcode/core/feature/back/messages/ENBackMessages.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,28 @@ | ||
| package com.eternalcode.core.feature.back.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
| import eu.okaeri.configs.OkaeriConfig; | ||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| @Getter | ||
| @Accessors(fluent = true) | ||
| public class ENBackMessages extends OkaeriConfig implements BackMessages { | ||
|
|
||
| public Notice lastLocationNotFound = Notice.chat( | ||
| "<red>► <white>You don't have any last location to teleport to!"); | ||
|
|
||
| public Notice teleportedToLastTeleportLocation = Notice.chat( | ||
| "<green>► <white>You have been teleported to your last location!"); | ||
| public Notice teleportedTargetPlayerToLastTeleportLocation = Notice.chat( | ||
| "<green>► <white>Player <green>{PLAYER} <white>has been teleported to their last location!"); | ||
| public Notice teleportedToLastTeleportLocationByAdmin = Notice.chat( | ||
| "<green>► <white>You have been teleported to your last location by an administrator!"); | ||
|
|
||
| public Notice teleportedToLastDeathLocation = Notice.chat( | ||
| "<green>► <white>You have been teleported to your last death location!"); | ||
| public Notice teleportedTargetPlayerToLastDeathLocation = Notice.chat( | ||
| "<green>► <white>Player <green>{PLAYER} <white>has been teleported to their last death location!"); | ||
| public Notice teleportedToLastDeathLocationByAdmin = Notice.chat( | ||
| "<green>► <white>You have been teleported to your last death location by an administrator!"); | ||
| } |
29 changes: 29 additions & 0 deletions
29
...nalcore-core/src/main/java/com/eternalcode/core/feature/back/messages/PLBackMessages.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,29 @@ | ||
| package com.eternalcode.core.feature.back.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
| import eu.okaeri.configs.OkaeriConfig; | ||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| @Getter | ||
| @Accessors(fluent = true) | ||
| public class PLBackMessages extends OkaeriConfig implements BackMessages { | ||
|
|
||
| public Notice lastLocationNotFound = Notice.chat( | ||
| "<red>► <white>Nie masz żadnej ostatniej lokalizacji, do której można się teleportować!"); | ||
|
|
||
| public Notice teleportedToLastTeleportLocation = Notice.chat( | ||
| "<green>► <white>Zostałeś przeteleportowany do ostatniej lokalizacji!"); | ||
| public Notice teleportedTargetPlayerToLastTeleportLocation = Notice.chat( | ||
| "<green>► <white>Gracz <green>{PLAYER} <white>został przeteleportowany do swojej ostatniej lokalizacji!"); | ||
| public Notice teleportedToLastTeleportLocationByAdmin = Notice.chat( | ||
| "<green>► <white>Zostałeś przeteleportowany do ostatniej lokalizacji przez administratora!"); | ||
|
|
||
| public Notice teleportedToLastDeathLocation = Notice.chat( | ||
| "<green>► <white>Zostałeś przeteleportowany do ostatniej lokalizacji śmierci!"); | ||
| public Notice teleportedTargetPlayerToLastDeathLocation = Notice.chat( | ||
| "<green>► <white>Gracz <green>{PLAYER} <white>został przeteleportowany do swojej ostatniej lokalizacji śmierci!"); | ||
| public Notice teleportedToLastDeathLocationByAdmin = Notice.chat( | ||
| "<green>► <white>Zostałeś przeteleportowany do ostatniej lokalizacji śmierci przez administratora!"); | ||
|
|
||
| } |
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.