Skip to content

Commit 8cf53ef

Browse files
committed
Move proxy online mode files to their own directory
1 parent f5f99d3 commit 8cf53ef

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/main/java/net/lenni0451/miniconnect/proxy/event/ProxyOnlineModeHandler.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,38 @@
22

33
import net.lenni0451.lambdaevents.EventHandler;
44
import net.lenni0451.miniconnect.Main;
5+
import net.lenni0451.miniconnect.server.model.PlayerConfig;
56
import net.lenni0451.miniconnect.utils.UUIDUtils;
67
import net.raphimc.viaproxy.ViaProxy;
78
import net.raphimc.viaproxy.plugins.events.ShouldVerifyOnlineModeEvent;
89
import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent;
10+
import net.raphimc.viaproxy.util.logging.Logger;
911

1012
import java.io.File;
1113
import java.util.UUID;
1214

1315
public class ProxyOnlineModeHandler {
1416

17+
public ProxyOnlineModeHandler() {
18+
try {
19+
File dataDir = Main.getInstance().getDataFolder();
20+
if (!dataDir.exists()) return;
21+
for (File file : dataDir.listFiles()) {
22+
if (!file.isFile()) continue;
23+
if (!file.getName().endsWith(".dat")) continue;
24+
File target = new File(PlayerConfig.baseDir(), file.getName());
25+
if (target.exists()) {
26+
Logger.LOGGER.warn("Skipping migration of {} as it already exists in the target directory", file.getName());
27+
continue;
28+
}
29+
target.getParentFile().mkdirs();
30+
file.renameTo(target);
31+
Logger.LOGGER.info("Migrated online mode settings file {} to new directory", file.getName());
32+
}
33+
} catch (Throwable ignored) {
34+
}
35+
}
36+
1537
@EventHandler
1638
public void onViaProxyLoaded(final ViaProxyLoadedEvent event) {
1739
ViaProxy.getConfig().setProxyOnlineMode(true);
@@ -24,7 +46,7 @@ public void onShouldVerifyOnlineMode(final ShouldVerifyOnlineModeEvent event) {
2446
event.setCancelled(false); //Enforce online mode verification
2547
} else {
2648
String hashedUUID = UUIDUtils.hash(uuid);
27-
File settingsFile = new File(Main.getInstance().getDataFolder(), hashedUUID + ".dat");
49+
File settingsFile = new File(PlayerConfig.baseDir(), hashedUUID + ".dat");
2850
if (!settingsFile.exists()) event.setCancelled(true);
2951
}
3052
}

src/main/java/net/lenni0451/miniconnect/server/model/PlayerConfig.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public class PlayerConfig {
2323

2424
private static final AESEncryption ENCRYPTION = new AESEncryption();
2525

26+
public static File baseDir() {
27+
return new File(Main.getInstance().getDataFolder(), "online_mode_settings");
28+
}
29+
30+
2631
public final UUID uuid;
2732
@Nullable
2833
public String serverAddress;
@@ -57,7 +62,7 @@ public ConnectionInfo toConnectionInfo() {
5762

5863
public void load() throws Exception {
5964
String hashedUUID = UUIDUtils.hash(this.uuid);
60-
File settingsFile = new File(Main.getInstance().getDataFolder(), hashedUUID + ".dat");
65+
File settingsFile = new File(PlayerConfig.baseDir(), hashedUUID + ".dat");
6166
if (!settingsFile.exists()) return;
6267
this.isSaved = true;
6368

@@ -74,7 +79,7 @@ public void load() throws Exception {
7479

7580
public void save() throws Exception {
7681
String hashedUUID = UUIDUtils.hash(this.uuid);
77-
File settingsFile = new File(Main.getInstance().getDataFolder(), hashedUUID + ".dat");
82+
File settingsFile = new File(PlayerConfig.baseDir(), hashedUUID + ".dat");
7883
settingsFile.getParentFile().mkdirs();
7984
this.isSaved = true;
8085

@@ -91,7 +96,7 @@ public void save() throws Exception {
9196

9297
public void delete() {
9398
String hashedUUID = UUIDUtils.hash(this.uuid);
94-
File settingsFile = new File(Main.getInstance().getDataFolder(), hashedUUID + ".dat");
99+
File settingsFile = new File(PlayerConfig.baseDir(), hashedUUID + ".dat");
95100
if (settingsFile.exists()) settingsFile.delete();
96101
this.isSaved = false;
97102
}

0 commit comments

Comments
 (0)