GH-971 Migrate jail feature from Position to Location with LocationPersister. Rename config section.#1141
GH-971 Migrate jail feature from Position to Location with LocationPersister. Rename config section.#1141
Conversation
Introduced JailCommandRestrictionType enum to support both whitelist and blacklist command restrictions for jailed players. Updated JailConfig and JailSettings to use 'restrictedCommands' and 'restrictionType' instead of 'allowedCommands'. Modified JailController logic to handle both restriction types. Took 12 minutes
Added a record of the player's previous location. Configuration values and messages have been migrated. Added constant permission values and used static imports for better appearance. Other cosmetic or quality improvements have been made. Took 49 minutes
There was a problem hiding this comment.
Code Review
This pull request refactors the jail system, introducing features like storing a player's last location before being jailed and a more flexible command restriction system (whitelist/blacklist). The refactoring also includes centralizing permission constants and cleaning up configuration keys and message structures. My review has identified a couple of issues: a critical bug where a new configuration migration is not registered, which could lead to data loss for users, and a logical flaw in the releaseAllPlayers method where event cancellations are not fully respected. I've also suggested a minor improvement to a configuration comment for better clarity. Overall, this is a solid refactoring with significant improvements, and addressing these points will make it even better.
eternalcore-core/src/main/java/com/eternalcode/core/configuration/migrations/Migrations.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/JailServiceImpl.java
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/JailConfig.java
Outdated
Show resolved
Hide resolved
P1otrulla
left a comment
There was a problem hiding this comment.
Good job, follow gemini suggestions 🙌
| private final Duration prisonTime; | ||
| private final String detainedBy; | ||
| @Nullable | ||
| private final Location lastLocation; |
There was a problem hiding this comment.
Location -> Position, We don't keep the location because it creates memory leaks and has a lot of world dependencies
There was a problem hiding this comment.
Ok but I think I will be obliged to use another serializer for Position class in database?
Jakubk15
left a comment
There was a problem hiding this comment.
Other than that, please apply Gemini's suggestions. It gave valuable feedback
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/messages/JailMessages.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/messages/JailMessages.java
Outdated
Show resolved
Hide resolved
Refactored JailServiceImpl.releaseAllPlayers to avoid clearing all jailed players and prisoners at once, now only releasing non-cancelled events and handling null players. Updated JailConfig comments for clarity and registered new migration for jail section in Migrations. Took 8 minutes
Took 15 minutes
releasePrivate -> released
Replaced custom Position class with Bukkit's Location for storing and handling player locations in jail-related classes. Updated constructors, field names, and database persister to reflect this change, improving compatibility and simplifying location management. Took 36 minutes
eternalcore-api/build.gradle.kts
Outdated
|
|
||
| dependencies { | ||
| compileOnly("org.spigotmc:spigot-api:${Versions.SPIGOT_API}") | ||
| compileOnly("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}") |
There was a problem hiding this comment.
Position usage in API
There was a problem hiding this comment.
trochę słabo będzie wystawiać API które jest relokowane
...eternalcode/core/configuration/migrations/Migration_0010_Move_jail_to_dedicated_section.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/JailPermissionConstant.java
Show resolved
Hide resolved
Took 58 minutes
Deleted PositionArgument class and removed references to invalidPosition messages in ArgumentMessages, ENArgumentMessages, and PLArgumentMessages. Updated HomeAdminCommand to use Location instead of Position for home setting, simplifying argument handling. Took 25 minutes
When setting a home for a user, the location now explicitly uses the sender's world, yaw, and pitch to avoid inconsistencies if a custom location is provided without these values. Took 8 minutes
Renamed migration class and references from 'Move_jail_to_dedicated_section' to 'Rename_jail_section' for clarity. Updated PositionPersister to use Position's toString method and added type safety. Minor import and formatting adjustments in JailedPlayer and PrisonerTable. Took 35 minutes
Took 2 minutes
eternalcore-api/src/main/java/com/eternalcode/core/feature/home/event/HomeCreateEvent.java
Outdated
Show resolved
Hide resolved
eternalcore-api/src/main/java/com/eternalcode/core/feature/home/event/HomeCreateEvent.java
Outdated
Show resolved
Hide resolved
eternalcore-api/src/main/java/com/eternalcode/core/feature/home/event/HomeOverrideEvent.java
Outdated
Show resolved
Hide resolved
eternalcore-api/src/main/java/com/eternalcode/core/feature/home/event/PreHomeTeleportEvent.java
Outdated
Show resolved
Hide resolved
eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/JailedPlayer.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Zmiany w home do wywalenia, migracje były testowane? I czy ten persister do DB był testowany? I czy API z jakrą było testowane? Nie mówię, że nie było albo że trzeba wszystko testować ale widzę parę miejsc które słabo rokują
szczególnie te zmiany w wystawianiu libki jako API #1141 (comment)
...core/configuration/migrations/Migration_0009_Rename_allowed_to_restricted_jail_commands.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/database/persister/PositionPersister.java
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomeImpl.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomeManager.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomeManager.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/home/command/SetHomeCommand.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/home/database/HomeTable.java
Outdated
Show resolved
Hide resolved
...nalcore-core/src/main/java/com/eternalcode/core/feature/home/homeadmin/HomeAdminCommand.java
Outdated
Show resolved
Hide resolved
# Conflicts: # eternalcore-core/src/main/java/com/eternalcode/core/configuration/migrations/Migrations.java # eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java # eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java
| * Gets the player's UUID. | ||
| * @return player's UUID. | ||
| */ | ||
| UUID playerUniqueId(); |
There was a problem hiding this comment.
raczej nie w konwencji naszej i po co rozwalać API żeby usuwać get
|
|
||
| @Override | ||
| public boolean releasePlayer(Player player) { | ||
| if (player == null) { |
There was a problem hiding this comment.
trochę przesada z tymi niektórymi nullcheckami
| JailedPlayer jailedPlayer = this.jailedPlayers.get(player.getUniqueId()); | ||
|
|
||
| this.prisonerRepository.deletePrisoner(player.getUniqueId()); | ||
| this.jailedPlayers.remove(player.getUniqueId()); |
There was a problem hiding this comment.
JailedPlayer jailedPlayer = this.jailedPlayers.remove(player.getUniqueId());
this.prisonerRepository.deletePrisoner(player.getUniqueId());:P
| if (jailedPlayer == null || jailedPlayer.isPrisonExpired()) { | ||
| return false; | ||
| if (player == null) { | ||
| throw new IllegalArgumentException("Player UUID cannot be null"); |
| @Blocking | ||
| public void setupJailArea(Location jailLocation) { | ||
| if (jailLocation == null) { | ||
| throw new IllegalArgumentException("Jail location cannot be null"); |
The entire prison system has been improved and fixes from #971 have been applied.
All game changes and migrations have been tested.