mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 17:39:30 +00:00
refactor(core): 回退
This commit is contained in:
@@ -1,41 +1,29 @@
|
||||
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 net.momirealms.craftengine.core.plugin.logger.Debugger;
|
||||
import net.momirealms.craftengine.core.util.SetMonitor;
|
||||
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;
|
||||
private final Set<Path> externalFolders;
|
||||
|
||||
PackCacheData(@NotNull CraftEngine plugin) {
|
||||
this.externalFolders = new SetMonitor<>(
|
||||
Config.foldersToMerge().stream()
|
||||
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
|
||||
.filter(Files::exists)
|
||||
.collect(Collectors.toSet()),
|
||||
add -> plugin.logger().info("Adding external folder: " + add),
|
||||
remove -> plugin.logger().info("Removing external folder: " + remove),
|
||||
true
|
||||
);
|
||||
this.externalZips = new SetMonitor<>(
|
||||
Config.zipsToMerge().stream()
|
||||
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
|
||||
.filter(Files::exists)
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(file -> file.getFileName().toString().endsWith(".zip"))
|
||||
.collect(Collectors.toSet()),
|
||||
add -> plugin.logger().info("Adding external zip: " + add),
|
||||
remove -> plugin.logger().info("Removing external zip: " + remove),
|
||||
true
|
||||
);
|
||||
this.externalFolders = Config.foldersToMerge().stream()
|
||||
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
|
||||
.filter(Files::exists)
|
||||
.collect(ObjectOpenHashSet.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());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -13,16 +13,10 @@ public class ListMonitor<T> implements List<T> {
|
||||
private final List<T> list;
|
||||
private final Consumer<T> addConsumer;
|
||||
private final Consumer<Object> removeConsumer;
|
||||
|
||||
public ListMonitor(List<T> list, Consumer<T> addConsumer, Consumer<Object> removeConsumer) {
|
||||
this(list, addConsumer, removeConsumer, false);
|
||||
}
|
||||
|
||||
public ListMonitor(List<T> list, Consumer<T> addConsumer, Consumer<Object> removeConsumer, boolean skipInitialNotification) {
|
||||
this.list = list;
|
||||
this.addConsumer = addConsumer;
|
||||
this.removeConsumer = removeConsumer;
|
||||
if (skipInitialNotification) return;
|
||||
for (T key : list) {
|
||||
this.addConsumer.accept(key);
|
||||
}
|
||||
|
||||
@@ -13,14 +13,9 @@ public class SetMonitor<E> implements Set<E> {
|
||||
private final Consumer<Object> removeConsumer;
|
||||
|
||||
public SetMonitor(Set<E> set, Consumer<E> addConsumer, Consumer<Object> removeConsumer) {
|
||||
this(set, addConsumer, removeConsumer, false);
|
||||
}
|
||||
|
||||
public SetMonitor(Set<E> set, Consumer<E> addConsumer, Consumer<Object> removeConsumer, boolean skipInitialNotification) {
|
||||
this.set = set;
|
||||
this.addConsumer = addConsumer;
|
||||
this.removeConsumer = removeConsumer;
|
||||
if (skipInitialNotification) return;
|
||||
for (E element : set) {
|
||||
this.addConsumer.accept(element);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user