-
-
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?
Changes from all commits
4a1734c
ad0b8c2
656b7be
5bf5d52
526e344
67c0735
ef0a5cb
c3bb59a
d640f4c
e09ca18
6c38f6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.eternalcode.core.feature.home.event; | ||
|
||
import java.util.UUID; | ||
|
||
import com.eternalcode.commons.bukkit.position.Position; | ||
import org.bukkit.Location; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
private boolean cancelled; | ||
|
||
public HomeCreateEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Location location) { | ||
public HomeCreateEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Position position) { | ||
super(false); | ||
|
||
this.playerUniqueId = playerUniqueId; | ||
this.homeName = homeName; | ||
this.homeUniqueId = homeUniqueId; | ||
this.location = location; | ||
this.position = position; | ||
} | ||
|
||
public UUID getHomeUniqueId() { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
return this.position; | ||
} | ||
|
||
public void setLocation(Location location) { | ||
this.location = location; | ||
public void setPosition(Position position) { | ||
this.position = position; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.eternalcode.core.feature.home.event; | ||
|
||
import com.eternalcode.core.feature.home.Home; | ||
import com.eternalcode.commons.bukkit.position.Position; | ||
|
||
import java.util.UUID; | ||
import org.bukkit.Location; | ||
import org.bukkit.event.Cancellable; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
private boolean cancelled; | ||
|
||
public HomeOverrideEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Location location) { | ||
public HomeOverrideEvent(UUID playerUniqueId, String homeName, UUID homeUniqueId, Position position) { | ||
super(false); | ||
|
||
this.playerUniqueId = playerUniqueId; | ||
this.homeName = homeName; | ||
this.homeUniqueId = homeUniqueId; | ||
this.location = location; | ||
this.position = position; | ||
} | ||
|
||
public String getHomeName() { | ||
|
@@ -45,12 +46,12 @@ public UUID getPlayerUniqueId() { | |
return this.playerUniqueId; | ||
} | ||
|
||
public void setLocation(Location location) { | ||
this.location = location; | ||
public void setPosition(Position position) { | ||
this.position = position; | ||
} | ||
|
||
public Location getLocation() { | ||
return this.location; | ||
public Position getPosition() { | ||
return this.position; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.eternalcode.core.feature.home.event; | ||
|
||
import com.eternalcode.commons.bukkit.position.Position; | ||
import com.eternalcode.core.feature.home.Home; | ||
import java.util.UUID; | ||
import org.bukkit.Location; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
private boolean cancelled; | ||
|
||
public PreHomeTeleportEvent(UUID playerUniqueId, Home home) { | ||
super(false); | ||
|
||
this.playerUniqueId = playerUniqueId; | ||
this.home = home; | ||
this.location = home.getLocation(); | ||
this.position = home.getPosition(); | ||
} | ||
|
||
public Home getHome() { | ||
return this.home; | ||
} | ||
|
||
public Location getLocation() { | ||
return this.location; | ||
public Position getPosition() { | ||
return this.position; | ||
} | ||
|
||
public void setLocation(Location location) { | ||
this.location = location; | ||
public void setPosition(Position position) { | ||
this.position = position; | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.eternalcode.core.feature.jail; | ||
|
||
import com.eternalcode.commons.bukkit.position.Position; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
@@ -10,12 +12,14 @@ public class JailedPlayer { | |
private final Instant detainedAt; | ||
private final Duration prisonTime; | ||
private final String detainedBy; | ||
private final Position lastPosition; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. zmieniasz JailedPlayer na interface i robisz jakąś impl np. |
||
this.player = player; | ||
this.detainedAt = detainedAt; | ||
this.prisonTime = prisonTime; | ||
this.detainedBy = lockedUpBy; | ||
this.detainedBy = detainedBy; | ||
this.lastPosition = lastPosition; | ||
} | ||
|
||
public UUID getPlayerUniqueId() { | ||
|
@@ -34,6 +38,10 @@ public Duration getPrisonTime() { | |
return this.prisonTime; | ||
} | ||
|
||
public Position getLastPosition() { | ||
return this.lastPosition; | ||
} | ||
|
||
public boolean isPrisonExpired() { | ||
return this.detainedAt.plus(this.prisonTime).isBefore(Instant.now()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.eternalcode.core.configuration.migrations; | ||
|
||
import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move; | ||
import eu.okaeri.configs.migrate.builtin.NamedMigration; | ||
|
||
class Migration_0009_Rename_allowed_to_restricted_jail_commands extends NamedMigration { | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. a jak to działa skoro mamy |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.eternalcode.core.configuration.migrations; | ||
|
||
import static eu.okaeri.configs.migrate.ConfigMigrationDsl.move; | ||
|
||
import eu.okaeri.configs.migrate.builtin.NamedMigration; | ||
|
||
public class Migration_0010_Rename_jail_section extends NamedMigration { | ||
|
||
Migration_0010_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") | ||
); | ||
} | ||
} |
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] | ||
); | ||
Comment on lines
+45
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
public static PositionPersister getSingleton() { | ||
return instance; | ||
} | ||
} |
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