Skip to content

Commit

Permalink
Fix extension name parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHua269 committed Dec 15, 2024
1 parent 9edeb2a commit 6055cc7
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ index 16f07007a0f73ec0c6f421c9b082518e87e8cc7b..fc69834e18e0860750d878e1361722fc
}
// Paper end - rewrite chunk system
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe28b6027c2 100644
index e40665cead218502b44dd49051a53326ed94f061..69ad8d832a8d5650e99fe04a654e2c137b74f910 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -23,7 +23,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
Expand All @@ -1042,7 +1042,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
private final RegionStorageInfo info;
private final Path folder;
private final boolean sync;
@@ -33,8 +33,33 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -33,8 +33,28 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
private static final int MAX_NON_EXISTING_CACHE = 1024 * 4;
private final it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet nonExistingRegionFiles = new it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet();
private static String getRegionFileName(final int chunkX, final int chunkZ) {
Expand All @@ -1053,18 +1053,13 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
+ public static abomination.IRegionFile createNew(RegionStorageInfo info, Path filePath, Path folder, boolean sync) throws IOException{
+ final me.earthme.luminol.utils.EnumRegionFormat regionFormat = me.earthme.luminol.config.modules.misc.RegionFormatConfig.regionFormat;
+ final String fullFileName = filePath.getFileName().toString();
+ final String argument;
+ final String[] fullNameSplit = fullFileName.split("\\.");
+ final String extensionName = fullNameSplit[fullNameSplit.length - 1];
+ final String expectedExtensionName = "." + regionFormat.getArgument();
+
+ int lastDotIndex = fullFileName.lastIndexOf(".");
+ if (lastDotIndex != -1 && lastDotIndex < fullFileName.length() - 1) {
+ argument = fullFileName.substring(lastDotIndex + 1);
+ }else {
+ throw new IOException("Invalid region file name: " + fullFileName);
+ }
+
+ if (!regionFormat.getArgument().equalsIgnoreCase(argument)) {
+ net.minecraft.server.MinecraftServer.setFatalException(new RuntimeException("Invalid region file format: " + argument + " expected " + regionFormat.getArgument()));
+ throw new IOException("Invalid region file format: ." + argument + " expected " + regionFormat.getArgument());
+ if (!expectedExtensionName.equalsIgnoreCase(extensionName)) {
+ net.minecraft.server.MinecraftServer.setFatalException(new RuntimeException("Invalid region file format: " + extensionName + " expected " + regionFormat.getArgument()));
+ throw new IOException("Invalid region file format: " + extensionName + " expected " + regionFormat.getArgument());
+ }
+
+ return regionFormat.getCreator().create(new me.earthme.luminol.utils.RegionCreatorInfo(info, filePath, folder, sync));
Expand All @@ -1077,7 +1072,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2

private boolean doesRegionFilePossiblyExist(final long position) {
synchronized (this.nonExistingRegionFiles) {
@@ -68,15 +93,15 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -68,15 +88,15 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}

@Override
Expand All @@ -1096,7 +1091,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
if (ret != null) {
return ret;
}
@@ -100,7 +125,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -100,7 +120,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise

FileUtil.createDirectoriesSafe(this.folder);

Expand All @@ -1105,7 +1100,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2

this.regionCache.putAndMoveToFirst(key, ret);

@@ -119,7 +144,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -119,7 +139,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}

final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
Expand All @@ -1114,7 +1109,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2

// note: not required to keep regionfile loaded after this call, as the write param takes a regionfile as input
// (and, the regionfile parameter is unused for writing until the write call)
@@ -153,7 +178,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -153,7 +173,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
) throws IOException {
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
if (writeData.result() == ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData.WriteResult.DELETE) {
Expand All @@ -1123,7 +1118,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
if (regionFile != null) {
regionFile.clear(pos);
} // else: didn't exist
@@ -168,7 +193,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -168,7 +188,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData moonrise$readData(
final int chunkX, final int chunkZ
) throws IOException {
Expand All @@ -1132,7 +1127,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2

final DataInputStream input = regionFile == null ? null : regionFile.getChunkDataInputStream(new ChunkPos(chunkX, chunkZ));

@@ -221,7 +246,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -221,7 +241,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@Nullable
public static ChunkPos getRegionFileCoordinates(Path file) {
String fileName = file.getFileName().toString();
Expand All @@ -1141,7 +1136,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
return null;
}

@@ -250,12 +275,12 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -250,12 +270,12 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}

// Paper start - rewrite chunk system
Expand All @@ -1156,7 +1151,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
// Paper start - rewrite chunk system
if (existingOnly) {
return this.moonrise$getRegionFileIfExists(chunkcoordintpair.x, chunkcoordintpair.z);
@@ -263,7 +288,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -263,7 +283,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
synchronized (this) {
final long key = ChunkPos.asLong(chunkcoordintpair.x >> REGION_SHIFT, chunkcoordintpair.z >> REGION_SHIFT);

Expand All @@ -1165,7 +1160,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
if (ret != null) {
return ret;
}
@@ -278,7 +303,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -278,7 +298,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise

FileUtil.createDirectoriesSafe(this.folder);

Expand All @@ -1174,7 +1169,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2

this.regionCache.putAndMoveToFirst(key, ret);

@@ -292,7 +317,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -292,7 +312,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
org.apache.logging.log4j.LogManager.getLogger().fatal(msg + " (" + file.toString().replaceAll(".+[\\\\/]", "") + " - " + x + "," + z + ") Go clean it up to remove this message. /minecraft:tp " + (x<<4)+" 128 "+(z<<4) + " - DO NOT REPORT THIS TO PAPER - You may ask for help on Discord, but do not file an issue. These error messages can not be removed.");
}

Expand All @@ -1183,7 +1178,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
synchronized (regionfile) {
try (DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkCoordinate)) {
CompoundTag oversizedData = regionfile.getOversizedData(chunkCoordinate.x, chunkCoordinate.z);
@@ -327,7 +352,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -327,7 +347,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@Nullable
public CompoundTag read(ChunkPos pos) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
Expand All @@ -1192,7 +1187,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
if (regionfile == null) {
return null;
}
@@ -391,7 +416,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -391,7 +411,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise

public void scanChunk(ChunkPos chunkPos, StreamTagVisitor scanner) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
Expand All @@ -1201,7 +1196,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
if (regionfile == null) {
return;
}
@@ -421,7 +446,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -421,7 +441,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}

public void write(ChunkPos pos, @Nullable CompoundTag nbt) throws IOException { // Paper - rewrite chunk system - public
Expand All @@ -1210,7 +1205,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
// Paper start - rewrite chunk system
if (regionfile == null) {
// if the RegionFile doesn't exist, no point in deleting from it
@@ -465,7 +490,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -465,7 +485,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
// Paper start - rewrite chunk system
synchronized (this) {
final ExceptionCollector<IOException> exceptionCollector = new ExceptionCollector<>();
Expand All @@ -1219,7 +1214,7 @@ index e40665cead218502b44dd49051a53326ed94f061..d16d0c0ec4cd32688b436bc73d152fe2
try {
regionFile.close();
} catch (final IOException ex) {
@@ -482,7 +507,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -482,7 +502,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
// Paper start - rewrite chunk system
synchronized (this) {
final ExceptionCollector<IOException> exceptionCollector = new ExceptionCollector<>();
Expand Down

0 comments on commit 6055cc7

Please sign in to comment.