// 5 seconds.
SingletonRepository.getTurnNotifier().notifyInSeconds(5, new TurnListener() {
public void onTurnReached(final int currentTurn) {
final String name = player.getName();
final ArrestWarrant arrestWarrant = arrestWarrants.getByName(name);
if (arrestWarrant == null) {
return;
}
if (removeVeryOldWarrants(arrestWarrant)) {
return;
}
final long timestamp = arrestWarrant.getTimestamp();
player.sendPrivateText("You have been jailed "
+ " for " + arrestWarrant.getMinutes()
+ " minutes on " + String.format("%tF", timestamp)
+ ". Reason: " + arrestWarrant.getReason() + ".");
handleEscapeMessages(arrestWarrant);
imprison(player, player, arrestWarrant.getMinutes());
}
public boolean removeVeryOldWarrants(final ArrestWarrant arrestWarrant) {
final long timestamp = arrestWarrant.getTimestamp();
if (timestamp + 30 * MathHelper.MILLISECONDS_IN_ONE_DAY < System.currentTimeMillis()) {
arrestWarrants.removeByName(arrestWarrant.getCriminal());
return true;
}
return false;
}
public void handleEscapeMessages(final ArrestWarrant arrestWarrant) {
if (arrestWarrant.isStarted()) {
// Notify player that his sentences is starting again because he tried to escape by logging out
player.sendPrivateText("Although you already spent some "
+ "time in jail, your sentence has been restarted "
+ "because of your failed escape attempt.");
} else {
// Jail player who was offline at the time /jail was issued.
arrestWarrant.setStarted();
}
}
});
}