-
-
Notifications
You must be signed in to change notification settings - Fork 21
GH-971 Migrate jail feature from Position to Location with LocationPersister. Rename config section. #1141
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
igoyek
wants to merge
18
commits into
master
Choose a base branch
from
jail-system-refactor
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
GH-971 Migrate jail feature from Position to Location with LocationPersister. Rename config section. #1141
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4a1734c
Add jail command restriction type and refactor config
igoyek ad0b8c2
The prison system has been improved
igoyek 656b7be
Refactor jail release logic and update config comments
igoyek 5bf5d52
Need tests
igoyek 526e344
detainPrivate -> detained
Jakubk15 67c0735
Refactor jail feature to use Bukkit Location
igoyek ef0a5cb
Location -> Position refactor
igoyek c3bb59a
Remove PositionArgument and related messages
igoyek d640f4c
Ensure home location uses sender's world and orientation
igoyek e09ca18
Refactor jail section migration and improve Position handling
igoyek 6c38f6f
Remove unused import
igoyek c2768cc
Follow instructions
igoyek 5a76360
Merge branch 'master' into jail-system-refactor
igoyek 9015129
Merge branch 'master' into jail-system-refactor
vLuckyyy b88917d
Merge.
vLuckyyy 5da106e
Remove useless migration.
vLuckyyy feb4c9e
Revert not-related to issue changes.
vLuckyyy e31948e
Review.
vLuckyyy 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
92 changes: 51 additions & 41 deletions
92
eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/JailedPlayer.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 |
|---|---|---|
| @@ -1,48 +1,58 @@ | ||
| package com.eternalcode.core.feature.jail; | ||
|
|
||
| import org.bukkit.Location; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| public class JailedPlayer { | ||
|
|
||
| private final UUID player; | ||
| private final Instant detainedAt; | ||
| private final Duration prisonTime; | ||
| private final String detainedBy; | ||
|
|
||
| public JailedPlayer(UUID player, Instant detainedAt, Duration prisonTime, String lockedUpBy) { | ||
| this.player = player; | ||
| this.detainedAt = detainedAt; | ||
| this.prisonTime = prisonTime; | ||
| this.detainedBy = lockedUpBy; | ||
| } | ||
|
|
||
| public UUID getPlayerUniqueId() { | ||
| return this.player; | ||
| } | ||
|
|
||
| public Instant getDetainedAt() { | ||
| return this.detainedAt; | ||
| } | ||
|
|
||
| public String getDetainedBy() { | ||
| return this.detainedBy; | ||
| } | ||
|
|
||
| public Duration getPrisonTime() { | ||
| return this.prisonTime; | ||
| } | ||
|
|
||
| public boolean isPrisonExpired() { | ||
| return this.detainedAt.plus(this.prisonTime).isBefore(Instant.now()); | ||
| } | ||
|
|
||
| public Instant getReleaseTime() { | ||
| return Instant.now().plus(this.prisonTime); | ||
| } | ||
|
|
||
| public Duration getRemainingTime() { | ||
| return Duration.between(Instant.now(), this.detainedAt.plus(this.prisonTime)); | ||
| } | ||
| public interface JailedPlayer { | ||
|
|
||
| /** | ||
| * Gets the player's UUID. | ||
| * @return player's UUID. | ||
| */ | ||
| UUID playerUniqueId(); | ||
|
|
||
| /** | ||
| * Gets the time when the player was detained. | ||
| * @return time when the player was detained. | ||
| */ | ||
| Instant detainedAt(); | ||
|
|
||
| /** | ||
| * Gets the name of the player who detained the player. | ||
| * @return name of player. | ||
| */ | ||
| String detainedBy(); | ||
|
|
||
| /** | ||
| * Gets the time the player is jailed. | ||
| * @return time the player is jailed. | ||
| */ | ||
| Duration prisonTime(); | ||
|
|
||
| /** | ||
| * Gets the jail position where the player is teleported when detained. | ||
| * @return last location of player. | ||
| */ | ||
| Location lastLocation(); | ||
|
|
||
| /** | ||
| * Checks if the jail has expired. | ||
| * @return true if the jail has expired, false otherwise. | ||
| */ | ||
| boolean isPrisonExpired(); | ||
|
|
||
| /** | ||
| * Gets the time when the player was released. | ||
| * @return time when the player was released. | ||
| */ | ||
| Instant releaseTime(); | ||
|
|
||
| /** | ||
| * Gets the remaining time of the jail. | ||
| * @return remaining time of the jail. | ||
| */ | ||
| Duration remainingTime(); | ||
| } |
38 changes: 38 additions & 0 deletions
38
...ava/com/eternalcode/core/configuration/migrations/Migration_0033_Rename_jail_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,38 @@ | ||
| package com.eternalcode.core.configuration.migrations; | ||
|
|
||
| import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move; | ||
|
|
||
| import eu.okaeri.configs.migrate.builtin.NamedMigration; | ||
|
|
||
| public class Migration_0033_Rename_jail_section extends NamedMigration { | ||
|
|
||
| Migration_0033_Rename_jail_section() { | ||
| super( | ||
| "Rename jail section", | ||
|
|
||
| move("jailSection.jailLocationSet", "jail.locationSet"), | ||
| move("jailSection.jailLocationRemove", "jail.locationRemove"), | ||
| move("jailSection.jailLocationNotSet", "jail.locationNotSet"), | ||
| move("jailSection.jailLocationOverride", "jail.locationOverride"), | ||
|
|
||
| move("jailSection.jailDetainBroadcast", "jail.detainBroadcast"), | ||
| move("jailSection.jailDetainPrivate", "jail.detained"), | ||
| move("jailSection.jailDetainCountdown", "jail.detainCountdown"), | ||
| move("jailSection.jailDetainOverride", "jail.detainOverride"), | ||
| move("jailSection.jailDetainAdmin", "jail.detainAdmin"), | ||
|
|
||
| move("jailSection.jailReleaseBroadcast", "jail.releaseBroadcast"), | ||
| move("jailSection.jailReleasePrivate", "jail.released"), | ||
| move("jailSection.jailReleaseAll", "jail.releaseAll"), | ||
| move("jailSection.jailReleaseNoPlayers", "jail.releaseNoPlayers"), | ||
| move("jailSection.jailIsNotPrisoner", "jail.isNotPrisoner"), | ||
|
|
||
| move("jailSection.jailListHeader", "jail.listHeader"), | ||
| move("jailSection.jailListEmpty", "jail.listEmpty"), | ||
| move("jailSection.jailListPlayerEntry", "jail.listPlayerEntry"), | ||
|
|
||
| move("jailSection.jailCannotUseCommand", "jail.cannotUseCommand"), | ||
| move("jailSection.allowedCommands", "jail.restrictedCommands") | ||
| ); | ||
| } | ||
| } |
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
70 changes: 70 additions & 0 deletions
70
...nalcore-core/src/main/java/com/eternalcode/core/database/persister/PositionPersister.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,70 @@ | ||
| package com.eternalcode.core.database.persister; | ||
|
|
||
| import com.eternalcode.commons.bukkit.position.Position; | ||
| import com.eternalcode.commons.bukkit.position.PositionAdapter; | ||
| import com.j256.ormlite.field.FieldType; | ||
| import com.j256.ormlite.field.SqlType; | ||
| import com.j256.ormlite.field.types.BaseDataType; | ||
| import com.j256.ormlite.support.DatabaseResults; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
| public class PositionPersister extends BaseDataType { | ||
|
|
||
| private static final PositionPersister instance = new PositionPersister(); | ||
|
|
||
| private PositionPersister() { | ||
| super(SqlType.LONG_STRING, new Class<?>[] {Position.class}); | ||
| } | ||
|
|
||
| @Override | ||
| public Object javaToSqlArg(FieldType fieldType, Object javaObject) { | ||
| if (javaObject == null) { | ||
| return null; | ||
| } | ||
|
|
||
| if (!(javaObject instanceof Position position)) { | ||
| throw new IllegalArgumentException("Invalid object type: " + javaObject.getClass().getName()); | ||
| } | ||
|
|
||
| return position.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException { | ||
| return results.getString(columnPos); | ||
| } | ||
|
|
||
| @Override | ||
| public Object parseDefaultString(FieldType fieldType, String defaultStr) { | ||
| return String.valueOf(defaultStr); | ||
| } | ||
|
|
||
| @Override | ||
| public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) { | ||
| String s = (String) sqlArg; | ||
|
|
||
| if (s == null) { | ||
| return null; | ||
| } | ||
|
|
||
| String[] params = s.split("/"); | ||
|
|
||
| if (params.length != 6) { | ||
| throw new IllegalArgumentException("Invalid position format: " + s); | ||
| } | ||
|
|
||
| return new Position( | ||
| Double.parseDouble(params[1]), | ||
| Double.parseDouble(params[2]), | ||
| Double.parseDouble(params[3]), | ||
| Float.parseFloat(params[4]), | ||
| Float.parseFloat(params[5]), | ||
| params[0] | ||
| ); | ||
| } | ||
|
|
||
| public static PositionPersister getSingleton() { | ||
| return instance; | ||
| } | ||
| } | ||
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
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.