Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
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")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class Migrations {
new Migration_0015_Move_ignore_messages_to_dedicated_section(),
new Migration_0031_Move_death_messages_to_dedicated_section(),
new Migration_0032_Move_join_quit_messages_to_dedicated_section(),
};
new Migration_0033_Rename_jail_section()
};

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ static HomeTable from(Home home) {
return new HomeTable(home.getUuid(), home.getOwner(), home.getName(), home.getLocation());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,3 @@ private String formattedListUserHomes(UUID uniqueId) {
.collect(Collectors.joining(this.pluginConfiguration.format.separator));
}
}

Loading