classpublicPriority 3
PrefabLoader
com.hypixel.hytale.builtin.hytalegenerator.assets.props.prefabprop.PrefabLoader
3
Methods
3
Public Methods
0
Fields
1
Constructors
Constructors
public
PrefabLoader()Methods
Public Methods (3)
publicstatic
boolean hasJsonExtension(Path path)publicstatic
void loadAllPrefabBuffersUnder(Path dirPath, List<PrefabBuffer> pathPrefabs)@Nonnull
publicstatic
PrefabBuffer loadPrefabBufferAt(Path filePath)@Nullable
Related Classes
Source Code
package com.hypixel.hytale.builtin.hytalegenerator.assets.props.prefabprop;
import com.hypixel.hytale.builtin.hytalegenerator.LoggerUtil;
import com.hypixel.hytale.common.util.ExceptionUtil;
import com.hypixel.hytale.server.core.prefab.selection.buffer.BsonPrefabBufferDeserializer;
import com.hypixel.hytale.server.core.prefab.selection.buffer.impl.PrefabBuffer;
import com.hypixel.hytale.server.core.util.BsonUtil;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bson.BsonDocument;
public class PrefabLoader {
public PrefabLoader() {
}
@Nonnull
public static void loadAllPrefabBuffersUnder(@Nonnull Path dirPath, List<PrefabBuffer> pathPrefabs) {
if (!Files.isDirectory(dirPath)) {
PrefabBuffer prefab = loadPrefabBufferAt(dirPath);
if (prefab != null) {
pathPrefabs.add(prefab);
}
} else {
try {
Files.walkFileTree(dirPath, new PrefabFileVisitor(pathPrefabs));
} catch (IOException var4) {
String msg = "Exception thrown by HytaleGenerator while loading a Prefab:\n";
msg = msg + ExceptionUtil.toStringWithStack(var4);
LoggerUtil.getLogger().severe(msg);
}
}
}
@Nullable
public static PrefabBuffer loadPrefabBufferAt(@Nonnull Path filePath) {
if (!hasJsonExtension(filePath)) {
return null;
} else {
try {
BsonDocument prefabAsBson = BsonUtil.readDocumentNow(filePath);
return prefabAsBson == null ? null : BsonPrefabBufferDeserializer.INSTANCE.deserialize(filePath, prefabAsBson);
} catch (Exception var3) {
String msg = "Exception thrown by HytaleGenerator while loading a PrefabBuffer for " + filePath + ":\n";
msg = msg + ExceptionUtil.toStringWithStack(var3);
LoggerUtil.getLogger().severe(msg);
return null;
}
}
}
public static boolean hasJsonExtension(@Nonnull Path path) {
String pathString = path.toString();
return pathString.toLowerCase().endsWith(".json");
}
}