Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyDynamic committed Apr 20, 2024
1 parent 11d3bcf commit 533b44d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -149,11 +150,11 @@ private static void executeRestore(ServerCommandSource commandSource) {
Timer timer = (Timer) QbDataHashMap.get("QBM").get("Timer");
ScheduledExecutorService countdown = (ScheduledExecutorService) QbDataHashMap.get("QBM").get("Countdown");
AtomicInteger countDown = new AtomicInteger(11);
final List<ServerPlayerEntity> playerList = server.getPlayerManager().getPlayerList();
List<ServerPlayerEntity> finalPlayerList = new ArrayList<>(server.getPlayerManager().getPlayerList());
countdown.scheduleAtFixedRate(() -> {
int remaining = countDown.decrementAndGet();
if (remaining >= 1) {
for (ServerPlayerEntity player : playerList) {
for (ServerPlayerEntity player : finalPlayerList) {
//#if MC>11900
MutableText content = Messenger.literal(tr("quickbackupmulti.restore.countdown.text", remaining, slot))
//#else
Expand All @@ -174,7 +175,7 @@ private static void executeRestore(ServerCommandSource commandSource) {
} catch (IOException var4) {
LOGGER.error("Failed to unlock level {}", server.session.getDirectoryName(), var4);
}
timer.schedule(new RestoreTask(env, playerList, slot), 10000);
timer.schedule(new RestoreTask(env, finalPlayerList, slot), 10000);
} else {
Messenger.sendMessage(commandSource, Text.of(tr("quickbackupmulti.confirm_restore.nothing_to_confirm")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import org.quartz.JobExecutionContext;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;

import static dev.skydynamic.quickbackupmulti.i18n.Translate.tr;
import static dev.skydynamic.quickbackupmulti.utils.QbmManager.scheduleMake;
Expand All @@ -24,14 +25,14 @@ public void execute(JobExecutionContext context) {
if (Config.TEMP_CONFIG.server != null) {
MinecraftServer server = Config.TEMP_CONFIG.server;
if (scheduleMake(server.getCommandSource(), generateName())) {
final Collection<ServerPlayerEntity> playerList = server.getPlayerManager().getPlayerList();
List<ServerPlayerEntity> finalPlayerList = new ArrayList<>(server.getPlayerManager().getPlayerList());
Config.TEMP_CONFIG.setLatestScheduleExecuteTime(System.currentTimeMillis());
String nextExecuteTime = "";
switch (Config.INSTANCE.getScheduleMode()) {
case "interval" -> nextExecuteTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis() + Config.INSTANCE.getScheduleInrerval() * 1000L);
case "cron" -> nextExecuteTime = getNextExecutionTime(Config.INSTANCE.getScheduleCron(), true);
}
for (ServerPlayerEntity player : playerList) {
for (ServerPlayerEntity player : finalPlayerList) {
player.sendMessage(Messenger.literal(tr("quickbackupmulti.schedule.execute.finish", nextExecuteTime)), false);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.skydynamic.quickbackupmulti.utils.storage;

import java.util.List;
import java.util.Objects;

public class SlotInfoStorage {
String desc;
long timestamp;
List<String> indexFiles;

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

public List<String> getIndexFiles() {
return indexFiles;
}

public void setIndexFiles(List<String> indexFiles) {
this.indexFiles = indexFiles;
}

@Override
public int hashCode() {
return Objects.hash(getDesc(), getTimestamp());
}
}

0 comments on commit 533b44d

Please sign in to comment.