-
-
Notifications
You must be signed in to change notification settings - Fork 19
GH-971 Jail system refactor #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
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/JailServiceImpl.java
Outdated
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/JailConfig.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, follow gemini suggestions 🙌
@@ -10,12 +13,19 @@ public class JailedPlayer { | |||
private final Instant detainedAt; | |||
private final Duration prisonTime; | |||
private final String detainedBy; | |||
@Nullable | |||
private final Location lastLocation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok but I think I will be obliged to use another serializer for Position class in database?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
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
@@ -6,5 +6,6 @@ plugins { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Position usage in API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
||
import com.eternalcode.annotations.scan.permission.PermissionDocs; | ||
|
||
public class JailPermissionConstant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only permissions that don’t come from commands should be documented here. Command annotations generate documentation automatically. @PermissionDocs is needed only when a permission doesn’t belong to a command, for example in a listener.
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
@@ -16,15 +18,16 @@ public class HomeCreateEvent extends Event implements Cancellable { | |||
private final UUID playerUniqueId; | |||
private final UUID homeUniqueId; | |||
private String homeName; | |||
private Location location; | |||
private Position position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@@ -43,12 +46,12 @@ public UUID getPlayerUniqueId() { | |||
return this.playerUniqueId; | |||
} | |||
|
|||
public Location getLocation() { | |||
return this.location; | |||
public Position getPosition() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@@ -17,16 +18,16 @@ public class HomeOverrideEvent extends Event implements Cancellable { | |||
private final UUID playerUniqueId; | |||
private final UUID homeUniqueId; | |||
private String homeName; | |||
private Location location; | |||
private Position position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@@ -16,27 +16,27 @@ public class PreHomeTeleportEvent extends Event implements Cancellable { | |||
|
|||
private final UUID playerUniqueId; | |||
private final Home home; | |||
private Location location; | |||
private Position position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
|
||
public JailedPlayer(UUID player, Instant detainedAt, Duration prisonTime, String lockedUpBy) { | ||
public JailedPlayer(UUID player, Instant detainedAt, Duration prisonTime, String detainedBy, Position lastPosition) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zmieniasz JailedPlayer na interface i robisz jakąś impl np. JailedCorePlayer
/JailedPlayerImpl
, metody w API mają nie wystawiać Position
. (ze względu na to że to libka a nie część API)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
|
||
Migration_0009_Rename_allowed_to_restricted_jail_commands() { | ||
super("Rename allowed to restricted jail commands", | ||
move("jail.allowedCommands", "jail.restrictedCommands") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a jak to działa skoro mamy jailSection
a nie jail
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] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
szczerze zastanawia mnie czy ten kod działa, bo Position#toString zwraca format który parsuje Position.parse
a nie po /
|
||
public class HomeImpl implements Home { | ||
|
||
private final UUID uuid; | ||
private final UUID owner; | ||
private final String name; | ||
private final Location location; | ||
private final Position position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated
Map<String, Home> homes = this.userHomes.computeIfAbsent(playerUniqueId, k -> new HashMap<>()); | ||
|
||
Home home = homes.get(name); | ||
|
||
if (home != null) { | ||
HomeOverrideEvent event = this.eventCaller.callEvent(new HomeOverrideEvent(playerUniqueId, name, playerUniqueId, location)); | ||
HomeOverrideEvent event = this.eventCaller.callEvent(new HomeOverrideEvent(playerUniqueId, name, playerUniqueId, position)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated
this.eventCaller.callEvent(event); | ||
|
||
if (event.isCancelled()) { | ||
return null; | ||
} | ||
|
||
Home homeInEvent = new HomeImpl(playerUniqueId, event.getHomeName(), event.getLocation()); | ||
Home homeInEvent = new HomeImpl(playerUniqueId, event.getHomeName(), event.getPosition()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated
@@ -54,7 +55,7 @@ private void setOrOverrideHome(User user, Player player, String homeName) { | |||
UUID uniqueId = user.getUniqueId(); | |||
|
|||
if (this.homeService.hasHome(uniqueId, homeName)) { | |||
this.homeService.createHome(uniqueId, homeName, player.getLocation()); | |||
this.homeService.createHome(uniqueId, homeName, PositionAdapter.convert(player.getLocation())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated
@DatabaseField(columnName = "location", persisterClass = LocationPersister.class) | ||
private Location location; | ||
@DatabaseField(columnName = "location", persisterClass = PositionPersister.class) | ||
private Position position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated i potencjalnie rozwala kompatybilność jeśli użyjemy poprawnie zaimplmentowanego PositionPersister
@@ -122,7 +129,8 @@ void home(@Context Player player, @Arg("player home") PlayerHomeEntry playerHome | |||
return; | |||
} | |||
|
|||
PaperLib.teleportAsync(player, homeOption.get().getLocation()); | |||
Location homeLocation = PositionAdapter.convert(homeOption.get().getPosition()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated
The entire prison system has been improved and fixes from #971 have been applied.
All game changes and migrations have been tested.