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