9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 03:19:14 +00:00

添加注释

This commit is contained in:
XiaoMoMi
2025-09-14 21:58:04 +08:00
parent fa3c7eb9ae
commit 3aa5bbe3a8
3 changed files with 41 additions and 5 deletions

View File

@@ -5,6 +5,22 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* This event is triggered when a user executes the "/ce reload pack" command.
* <p>
* The event initiates a process that caches all resource content into a virtual file system
* to ensure optimal build performance. To add your resource pack through this event,
* you must use the {@link #registerExternalResourcePack(Path)} method every time this event is called.
* </p>
* <p>
* Important: The caching system will not update your resource pack if its file size or
* last modification time remains unchanged between reloads. Ensure these attributes change
* if you need the cache to recognize updates.
* </p>
*/
public class AsyncResourcePackCacheEvent extends Event {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final PackCacheData cacheData;
@@ -16,7 +32,7 @@ public class AsyncResourcePackCacheEvent extends Event {
@NotNull
public PackCacheData cacheData() {
return cacheData;
return this.cacheData;
}
@NotNull
@@ -28,4 +44,24 @@ public class AsyncResourcePackCacheEvent extends Event {
public HandlerList getHandlers() {
return getHandlerList();
}
/**
* Adds an external resource pack to the cache.
* <p>
* This method accepts either a .zip file or a directory path representing a resource pack.
* The resource pack will be added to the appropriate cache collection based on its type.
* </p>
*
* @param path the file system path to the resource pack. Must be either a .zip file or a directory.
* @throws IllegalArgumentException if the provided path is neither a .zip file nor a directory.
*/
public void registerExternalResourcePack(@NotNull final Path path) {
if (Files.isRegularFile(path) && path.getFileName().endsWith(".zip")) {
this.cacheData.externalZips().add(path);
} else if (Files.isDirectory(path)) {
this.cacheData.externalFolders().add(path);
} else {
throw new IllegalArgumentException("Illegal resource pack path: " + path);
}
}
}

View File

@@ -273,7 +273,7 @@ public abstract class AbstractPackManager implements PackManager {
@Override
public void initCachedAssets() {
try {
PackCacheData cacheData = new PackCacheData(plugin);
PackCacheData cacheData = new PackCacheData(this.plugin);
this.cacheEventDispatcher.accept(cacheData);
this.updateCachedAssets(cacheData, null);
} catch (Exception e) {

View File

@@ -1,6 +1,5 @@
package net.momirealms.craftengine.core.pack;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import org.jetbrains.annotations.NotNull;
@@ -8,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.stream.Collectors;
public class PackCacheData {
private final Set<Path> externalZips;
@@ -17,13 +17,13 @@ public class PackCacheData {
this.externalFolders = Config.foldersToMerge().stream()
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
.filter(Files::exists)
.collect(ObjectOpenHashSet.toSet());
.collect(Collectors.toSet());
this.externalZips = Config.zipsToMerge().stream()
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
.filter(Files::exists)
.filter(Files::isRegularFile)
.filter(file -> file.getFileName().toString().endsWith(".zip"))
.collect(ObjectOpenHashSet.toSet());
.collect(Collectors.toSet());
}
@NotNull