Remote files are satistaskory/remote/<name-and-motd>.dat. Not IP, not world seed. Singleplayer is still the world folder.
This commit is contained in:
+9
-7
@@ -22,7 +22,8 @@ import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
/**
|
||||
* Client-owned files. The server does not need this mod.
|
||||
* Singleplayer: {@code <world>/satistaskory.dat}. Remote: {@code satistaskory/remote/<address>.dat}.
|
||||
* Singleplayer: {@code <world>/satistaskory.dat}.
|
||||
* Remote: {@code satistaskory/remote/<name-and-motd>.dat}.
|
||||
*/
|
||||
public final class ClientGoalPersistence {
|
||||
private ClientGoalPersistence() {}
|
||||
@@ -81,12 +82,13 @@ public final class ClientGoalPersistence {
|
||||
return integrated.getWorldPath(LevelResource.ROOT).resolve("satistaskory.dat");
|
||||
}
|
||||
ServerData server = minecraft.getCurrentServer();
|
||||
if (server != null && server.ip != null && !server.ip.isBlank()) {
|
||||
return minecraft.gameDirectory.toPath()
|
||||
.resolve("satistaskory")
|
||||
.resolve("remote")
|
||||
.resolve(ClientSaveKeys.remoteFileName(server.ip));
|
||||
if (server == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
String description = server.motd == null ? "" : server.motd.getString();
|
||||
return minecraft.gameDirectory.toPath()
|
||||
.resolve("satistaskory")
|
||||
.resolve("remote")
|
||||
.resolve(ClientSaveKeys.remoteFileName(server.name, description));
|
||||
}
|
||||
}
|
||||
|
||||
+16
-3
@@ -3,13 +3,14 @@ package com.sufficient.satistaskory.infrastructure.persistence;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* File names for remote-server plans on this client. Not a domain type.
|
||||
* File names for remote-server plans on this client. Keyed by list name and MOTD, not IP.
|
||||
*/
|
||||
public final class ClientSaveKeys {
|
||||
private ClientSaveKeys() {}
|
||||
|
||||
public static String remoteFileName(String address) {
|
||||
String cleaned = address.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9._-]+", "_");
|
||||
public static String remoteFileName(String name, String description) {
|
||||
String combined = join(name, description);
|
||||
String cleaned = combined.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9._-]+", "_");
|
||||
cleaned = cleaned.replaceAll("^_+|_+$", "");
|
||||
if (cleaned.isEmpty()) {
|
||||
cleaned = "unknown";
|
||||
@@ -19,4 +20,16 @@ public final class ClientSaveKeys {
|
||||
}
|
||||
return cleaned + ".dat";
|
||||
}
|
||||
|
||||
private static String join(String name, String description) {
|
||||
String n = name == null ? "" : name.trim();
|
||||
String d = description == null ? "" : description.trim();
|
||||
if (n.isEmpty()) {
|
||||
return d;
|
||||
}
|
||||
if (d.isEmpty() || d.equalsIgnoreCase(n)) {
|
||||
return n;
|
||||
}
|
||||
return n + " " + d;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-5
@@ -6,17 +6,28 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
class ClientSaveKeysTest {
|
||||
@Test
|
||||
void sanitizesHostAndPort() {
|
||||
assertEquals("127.0.0.1_25565.dat", ClientSaveKeys.remoteFileName("127.0.0.1:25565"));
|
||||
void usesNameAndDescription() {
|
||||
assertEquals("hypixel_a_minecraft_server.dat",
|
||||
ClientSaveKeys.remoteFileName("Hypixel", "A Minecraft Server"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsHostnameDots() {
|
||||
assertEquals("play.hypixel.net.dat", ClientSaveKeys.remoteFileName("play.hypixel.net"));
|
||||
void nameAloneWhenDescriptionEmpty() {
|
||||
assertEquals("my_smp.dat", ClientSaveKeys.remoteFileName("My SMP", " "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void descriptionAloneWhenNameEmpty() {
|
||||
assertEquals("creative_world.dat", ClientSaveKeys.remoteFileName("", "Creative World"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotRepeatIdenticalDescription() {
|
||||
assertEquals("hypixel.dat", ClientSaveKeys.remoteFileName("Hypixel", "Hypixel"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyBecomesUnknown() {
|
||||
assertEquals("unknown.dat", ClientSaveKeys.remoteFileName(" "));
|
||||
assertEquals("unknown.dat", ClientSaveKeys.remoteFileName(" ", null));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user