Skip to content
Merged
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
Expand Up @@ -42,7 +42,7 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.IntConsumer;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -209,13 +209,13 @@ public static ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit
/**
* Initiates the countdown for the next reconnect attempt, if any.
*/
public static void startCountdown(final IntConsumer callback) {
int delay = Config.get().getDelayForAttempt(reconnectStrategy.nextAttempt());
if (delay >= 0) {
countdown(delay, callback);
public static void startCountdown(final Consumer<Float> callback) {
float delay = Config.get().getDelayForAttempt(reconnectStrategy.nextAttempt());
if (delay >= 0F) {
countdown(Math.round(delay * 1000D), callback);
} else {
// No more attempts configured
callback.accept(-1);
callback.accept(-1F);
}
}

Expand All @@ -233,19 +233,20 @@ private static void cancelCountdown() {
/**
* Simulated reconnect countdown timer using delayed recursion.
*/
private static void countdown(int seconds, final IntConsumer callback) {
private static void countdown(long remainingMillis, final Consumer<Float> callback) {
if (reconnectStrategy == null)
return; // Should not happen
if (seconds == 0) {
if (remainingMillis <= 0L) {
// Execute on main thread
Minecraft.getInstance().execute(AutoReconnect::reconnect);
} else {
callback.accept(seconds);
callback.accept(remainingMillis / 1000F);
long stepMillis = Math.min(100L, remainingMillis);
synchronized (countdown) { // Just to be sure
countdown.set(schedule(
() -> countdown(seconds - 1, callback),
1,
TimeUnit.SECONDS
() -> countdown(remainingMillis - stepMillis, callback),
stepMillis,
TimeUnit.MILLISECONDS
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public static Options options() {

public static class Options {

public static final Supplier<List<Integer>> delaysDefault = () -> new ArrayList<>(List.of(
3,
10,
30,
60
public static final Supplier<List<Float>> delaysDefault = () -> new ArrayList<>(List.of(
3F,
10F,
30F,
60F
));
public List<Integer> delays = delaysDefault.get();
public List<Float> delays = delaysDefault.get();

public static final boolean initialDefault = false;
public boolean initial = initialDefault;
Expand Down Expand Up @@ -126,12 +126,12 @@ public Iterator<String> getMessages() {

// Utils

public int getDelayForAttempt(int attempt) {
public float getDelayForAttempt(int attempt) {
if (attempt < options.delays.size())
return options.delays.get(attempt);
if (options.infinite)
return options.delays.getLast(); // repeat last
return -1; // no more attempts configured
return -1F; // no more attempts configured
}

public boolean hasAttempts() {
Expand Down Expand Up @@ -196,7 +196,7 @@ private void validate() {
if (options.delays == null) {
options.delays = Options.delaysDefault.get();
} else if (!options.delays.isEmpty()) {
options.delays = options.delays.stream().filter(i -> i > 0).toList();
options.delays = options.delays.stream().filter(i -> i > 0F).toList();
}
if (options.autoMessages == null) {
options.autoMessages = Options.autoMessagesDefault.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ static Screen getConfigScreen(Screen parent) {
ConfigCategory.Builder attemptsCat =
ConfigCategory.createBuilder().name(localized("option", "attempts"));

attemptsCat.group(ListOption.<Integer>createBuilder()
attemptsCat.group(ListOption.<Float>createBuilder()
.name(localized("option", "attempts.delays"))
.description(OptionDescription.of(localized("option", "attempts.delays.tooltip")))
.binding(
Config.Options.delaysDefault.get(),
() -> options.delays,
val -> options.delays = val
)
.controller(option -> IntegerFieldControllerBuilder.create(option).min(1)
.controller(option -> FloatFieldControllerBuilder.create(option).min(0.001F)
.formatValue((val) -> localized("option", "attempts.delays.value", val)))
.initial(0)
.initial(0F)
.insertEntriesAtEnd(true)
.minimumNumberOfEntries(1)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ else if (button.getMessage().getContents() instanceof TranslatableContents tc)
*/
public static void startCountdown(Button reconnectButton) {
AutoReconnect.startCountdown((seconds) -> {
if (seconds < 0) {
if (seconds < 0F) {
// Out of attempts; deactivate button
reconnectButton.setMessage(localized("message", "reconnectFailed")
.withStyle(s -> s.withColor(ChatFormatting.RED)));
reconnectButton.active = false;
} else {
// Attempts ongoing; update time on button
reconnectButton.setMessage(localized("message", "reconnectIn", seconds)
String secondsStr = seconds >= 10
? String.valueOf(seconds.intValue()) // %d (down)
: String.valueOf((int) (seconds * 10) / 10F); // %.1f effective (down)
reconnectButton.setMessage(localized("message", "reconnectIn", secondsStr)
.withStyle(s -> s.withColor(ChatFormatting.GREEN)));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"message.autoreconnectrf.configScreenDisabled": "Config screen is not available on this version.",

"message.autoreconnectrf.reconnect": "Reconnect",
"message.autoreconnectrf.reconnectIn": "Reconnecting in %d...",
"message.autoreconnectrf.reconnectIn": "Reconnecting in %s...",
"message.autoreconnectrf.reconnectFailed": "Could not reconnect!",

"message.autoreconnectrf.debug.disconnected": "Disconnected by debug command!",
Expand Down Expand Up @@ -34,7 +34,7 @@

"option.autoreconnectrf.messages": "AutoMessages",
"option.autoreconnectrf.messages.tooltip": "Messages to send after a successful automatic reconnect.",
"option.autoreconnectrf.messages.instance": "AutoMessage %d",
"option.autoreconnectrf.messages.instance": "AutoMessage %s",
"option.autoreconnectrf.messages.instance.tooltip": "A single AutoMessage object for a specific server, realm or world.",
"option.autoreconnectrf.messages.instance.id": "Connection ID",
"option.autoreconnectrf.messages.instance.id.tooltip": "The server IP, realm name, or world name on which this AutoMessage should be used.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"message.autoreconnectrf.configScreenDisabled": "Экран конфигурации недоступен в этой версии.",

"message.autoreconnectrf.reconnect": "Переподключиться",
"message.autoreconnectrf.reconnectIn": "Переподключение через %d...",
"message.autoreconnectrf.reconnectIn": "Переподключение через %s...",
"message.autoreconnectrf.reconnectFailed": "Не удалось переподключиться!",

"message.autoreconnectrf.debug.disconnected": "Отключено отладочной командой!",
Expand Down Expand Up @@ -38,7 +38,7 @@

"option.autoreconnectrf.messages": "Автосообщения",
"option.autoreconnectrf.messages.tooltip": "Сообщения для отправки после успешного автоматического переподключения.",
"option.autoreconnectrf.messages.instance": "Автосообщение %d",
"option.autoreconnectrf.messages.instance": "Автосообщение %s",
"option.autoreconnectrf.messages.instance.tooltip": "Одиночный объект автосообщений для конкретного сервера, реалма или мира.",
"option.autoreconnectrf.messages.instance.id": "Идентификатор подключения",
"option.autoreconnectrf.messages.instance.id.tooltip": "IP-адрес сервера, название реалма или название мира, для которого применяется это автосообщение.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"message.autoreconnectrf.configScreenDisabled": "Config screen is not available on this version.",

"message.autoreconnectrf.reconnect": "Перепід'єднатися",
"message.autoreconnectrf.reconnectIn": "Перепід'єднання через %d...",
"message.autoreconnectrf.reconnectIn": "Перепід'єднання через %s...",
"message.autoreconnectrf.reconnectFailed": "Не вдалося перепід'єднатися!",

"message.autoreconnectrf.debug.disconnected": "Disconnected by debug command!",
Expand Down Expand Up @@ -34,7 +34,7 @@

"option.autoreconnectrf.messages": "АвтоПовідомлення",
"option.autoreconnectrf.messages.tooltip": "Повідомлення для надсилання після успішного автоматичного перепід'єднання.",
"option.autoreconnectrf.messages.instance": "Об'єкт АвтоПовідомлень %d",
"option.autoreconnectrf.messages.instance": "Об'єкт АвтоПовідомлень %s",
"option.autoreconnectrf.messages.instance.tooltip": "Окремий об'єкт АвтоПовідомлень для конкретного світу, сервера чи реалму.",
"option.autoreconnectrf.messages.instance.id": "Connection ID",
"option.autoreconnectrf.messages.instance.id.tooltip": "The server IP, realm name, or world name on which this AutoMessage should be used.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"message.autoreconnectrf.configScreenDisabled": "Config screen is not available on this version.",

"message.autoreconnectrf.reconnect": "重新连接",
"message.autoreconnectrf.reconnectIn": "在 %d 秒后重新连接...",
"message.autoreconnectrf.reconnectIn": "在 %s 秒后重新连接...",
"message.autoreconnectrf.reconnectFailed": "无法重新连接!",

"message.autoreconnectrf.debug.disconnected": "Disconnected by debug command!",
Expand Down Expand Up @@ -34,7 +34,7 @@

"option.autoreconnectrf.messages": "自动消息规则",
"option.autoreconnectrf.messages.tooltip": "自动重新连接服务器成功后发送的聊天消息。",
"option.autoreconnectrf.messages.instance": "实例 %d",
"option.autoreconnectrf.messages.instance": "实例 %s",
"option.autoreconnectrf.messages.instance.tooltip": "单独针对一个特定世界,服务器或 Realms 的自动消息对象。",
"option.autoreconnectrf.messages.instance.id": "Connection ID",
"option.autoreconnectrf.messages.instance.id.tooltip": "The server IP, realm name, or world name on which this AutoMessage should be used.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"message.autoreconnectrf.configScreenDisabled": "此版本無法使用設定畫面。",

"message.autoreconnectrf.reconnect": "重新連線",
"message.autoreconnectrf.reconnectIn": "將在 %d 秒後重新連線...",
"message.autoreconnectrf.reconnectIn": "將在 %s 秒後重新連線...",
"message.autoreconnectrf.reconnectFailed": "無法重新連線!",

"message.autoreconnectrf.debug.disconnected": "因偵錯指令而斷線!",
Expand Down Expand Up @@ -37,7 +37,7 @@

"option.autoreconnectrf.messages": "自動訊息",
"option.autoreconnectrf.messages.tooltip": "成功自動重新連線後要傳送的訊息。",
"option.autoreconnectrf.messages.instance": "自動訊息 %d",
"option.autoreconnectrf.messages.instance": "自動訊息 %s",
"option.autoreconnectrf.messages.instance.tooltip": "適用於特定伺服器、Realm 或世界的單一自動訊息設定。",
"option.autoreconnectrf.messages.instance.id": "連線 ID",
"option.autoreconnectrf.messages.instance.id.tooltip": "應使用此自動訊息的伺服器 IP、Realm 名稱或世界名稱。",
Expand Down