Minor fixes suggested by idea.
This commit is contained in:
parent
cd67e94787
commit
aca7dba943
5 changed files with 14 additions and 75 deletions
|
@ -122,7 +122,7 @@ private static String getVersion(String baseVersion, URL url) {
|
|||
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(connection.getInputStream())
|
||||
NodeList versionNodes = doc.getElementsByTagName("version")
|
||||
|
||||
String latestVersion = null;
|
||||
String latestVersion = null
|
||||
for (int i = 0; i < versionNodes.getLength(); i++) {
|
||||
String version = versionNodes.item(i).getTextContent()
|
||||
if (version.startsWith(baseVersion)) {
|
||||
|
|
|
@ -14,7 +14,7 @@ loader_version_range=[4,)
|
|||
modid=extbackup
|
||||
mod_name=ExtBackup
|
||||
group=net.sweevo
|
||||
mod_version=2.0.0
|
||||
mod_version=2.0.1
|
||||
## Upload Properties
|
||||
upload_versions=1.21, 1.21.1
|
||||
upload_release=release
|
||||
|
|
|
@ -20,29 +20,17 @@ import javax.annotation.Nullable;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.SignStyle;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BackupThread extends Thread {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(BackupThread.class);
|
||||
private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder()
|
||||
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD).appendLiteral('-')
|
||||
.appendValue(ChronoField.MONTH_OF_YEAR, 2).appendLiteral('-')
|
||||
.appendValue(ChronoField.DAY_OF_MONTH, 2).appendLiteral('_')
|
||||
.appendValue(ChronoField.HOUR_OF_DAY, 2).appendLiteral('-')
|
||||
.appendValue(ChronoField.MINUTE_OF_HOUR, 2).appendLiteral('-')
|
||||
.appendValue(ChronoField.SECOND_OF_MINUTE, 2)
|
||||
.toFormatter();
|
||||
private final MinecraftServer server;
|
||||
private final boolean quiet;
|
||||
private final File script;
|
||||
|
||||
private BackupThread(@Nonnull MinecraftServer server, boolean quiet, BackupData backupData) {
|
||||
private BackupThread(@Nonnull MinecraftServer server, boolean quiet) {
|
||||
this.server = server;
|
||||
this.quiet = quiet;
|
||||
this.setName("ExtBackup");
|
||||
|
@ -53,7 +41,7 @@ public class BackupThread extends Thread {
|
|||
public static boolean tryCreateBackup(MinecraftServer server) {
|
||||
BackupData backupData = BackupData.get(server);
|
||||
if (BackupThread.shouldRunBackup(server)) {
|
||||
BackupThread thread = new BackupThread(server, false, backupData);
|
||||
BackupThread thread = new BackupThread(server, false);
|
||||
thread.start();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
backupData.updateSaveTime(currentTime);
|
||||
|
@ -74,7 +62,7 @@ public class BackupThread extends Thread {
|
|||
}
|
||||
|
||||
public static void createBackup(MinecraftServer server, boolean quiet) {
|
||||
BackupThread thread = new BackupThread(server, quiet, null);
|
||||
BackupThread thread = new BackupThread(server, quiet);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
@ -106,28 +94,28 @@ public class BackupThread extends Thread {
|
|||
|
||||
private void broadcast(String message, Style style, Object... parameters) {
|
||||
if (CommonConfig.sendMessages() && !this.quiet) {
|
||||
this.server.execute(() -> {
|
||||
this.server.getPlayerList().getPlayers().forEach(player -> {
|
||||
this.server.execute(() -> this.server.getPlayerList().getPlayers().forEach(player -> {
|
||||
if (ServerConfig.messagesForEveryone() || player.hasPermissions(2)) {
|
||||
player.sendSystemMessage(BackupThread.component(player, message, parameters).withStyle(style));
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// vanilla copy with modifications
|
||||
private void makeWorldBackup() throws IOException {
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
private void makeWorldBackup() {
|
||||
if (!script.exists() || !script.canExecute()) {
|
||||
ExtBackup.LOGGER.error("Cannot access or execute backup script. Bailing out!");
|
||||
}
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(script.getAbsolutePath());
|
||||
int returnValue = -1;
|
||||
int returnValue;
|
||||
pb.redirectErrorStream(true);
|
||||
try {
|
||||
Process backup = pb.start();
|
||||
returnValue = backup.waitFor();
|
||||
if (returnValue != 0) { throw new IOException("Backup process returned non-zero result!");}
|
||||
} catch (Exception ex) {
|
||||
ExtBackup.LOGGER.error("Something went wrong with the Backup script!");
|
||||
ExtBackup.LOGGER.error("Check your Backups.");
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package net.sweevo.jinks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum StorageSize {
|
||||
B(0),
|
||||
KB(1),
|
||||
MB(2),
|
||||
GB(3),
|
||||
TB(4);
|
||||
|
||||
private final long sizeInBytes;
|
||||
private final String postfix;
|
||||
|
||||
StorageSize(int factor) {
|
||||
this.sizeInBytes = (long) Math.pow(1024, factor);
|
||||
this.postfix = this.name().toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static StorageSize getSizeFor(double bytes) {
|
||||
for (StorageSize value : StorageSize.values()) {
|
||||
if (bytes < value.sizeInBytes) {
|
||||
return value.getLower();
|
||||
} else if (value == TB) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return B;
|
||||
}
|
||||
|
||||
public static long getBytes(String s) {
|
||||
String[] splits = s.split(" ");
|
||||
int amount = Integer.parseInt(splits[0]);
|
||||
StorageSize size = StorageSize.valueOf(splits[1].toUpperCase(Locale.ROOT));
|
||||
return amount * size.sizeInBytes;
|
||||
}
|
||||
|
||||
public static String getFormattedSize(double bytes) {
|
||||
StorageSize size = StorageSize.getSizeFor(bytes);
|
||||
double small = bytes / size.sizeInBytes;
|
||||
return String.format("%.1f %s", small, size.postfix);
|
||||
}
|
||||
|
||||
public StorageSize getLower() {
|
||||
return this.ordinal() == 0 ? this : StorageSize.values()[this.ordinal() - 1];
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ public class ClientEventHandler {
|
|||
isPaused = paused;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@SubscribeEvent
|
||||
public void onRenderText(CustomizeGuiOverlayEvent.DebugText event) {
|
||||
if (!isPaused) {
|
||||
|
|
Loading…
Reference in a new issue