[Change] Separated all World-Load related code to a new namespace
This commit is contained in:
parent
67d09676c4
commit
25fa53541f
79 changed files with 1924 additions and 814 deletions
|
@ -1,100 +1,62 @@
|
|||
package org.betterx.bclib.util;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class PathUtil {
|
||||
public final static Path GAME_FOLDER = FabricLoader.getInstance()
|
||||
.getGameDir()
|
||||
.normalize();
|
||||
|
||||
public final static Path MOD_FOLDER = FabricLoader.getInstance()
|
||||
.getGameDir()
|
||||
.resolve("mods")
|
||||
.normalize();
|
||||
|
||||
public final static Path MOD_BAK_FOLDER = MOD_FOLDER.resolve("_bclib_deactivated")
|
||||
.normalize();
|
||||
/**
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#GAME_FOLDER}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public final static Path GAME_FOLDER = org.betterx.worlds.together.util.PathUtil.GAME_FOLDER;
|
||||
|
||||
/**
|
||||
* Tests if a path is a child-path.
|
||||
* <p>
|
||||
* A path is a child of another if it is located in the parent or any of the parents subdirectories
|
||||
*
|
||||
* @param parent The folder we search for the {@code child}
|
||||
* @param child The folder you want to test
|
||||
* @return {@code true} if {@code child} is in {@code parent} or any of its sub directories
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#MOD_FOLDER}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public final static Path MOD_FOLDER = org.betterx.worlds.together.util.PathUtil.MOD_FOLDER;
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#MOD_BAK_FOLDER}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public final static Path MOD_BAK_FOLDER = org.betterx.worlds.together.util.PathUtil.MOD_BAK_FOLDER;
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#isChildOf(Path, Path)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static boolean isChildOf(Path parent, Path child) {
|
||||
if (child == null || parent == null) return false;
|
||||
parent = parent.toAbsolutePath().normalize();
|
||||
child = child.toAbsolutePath().normalize();
|
||||
|
||||
final int pCount = parent.getNameCount();
|
||||
final int cCount = child.getNameCount();
|
||||
|
||||
if (cCount > pCount) return isChildOf(parent, child.getParent());
|
||||
if (cCount < pCount) return false;
|
||||
|
||||
return child.equals(parent);
|
||||
return org.betterx.worlds.together.util.PathUtil.isChildOf(parent, child);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple directory walker that ignores dot-files
|
||||
*
|
||||
* @param path The path where you want to start
|
||||
* @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
|
||||
* for each visited file
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#fileWalker(File, Consumer)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void fileWalker(File path, Consumer<Path> pathConsumer) {
|
||||
fileWalker(path, true, pathConsumer);
|
||||
org.betterx.worlds.together.util.PathUtil.fileWalker(path, pathConsumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple directory walker that ignores dot-files
|
||||
*
|
||||
* @param path The path where you want to start
|
||||
* @param recursive if {@code false}, only the {@code path} is traversed
|
||||
* @param pathConsumer The consumer called for each valid file. The consumer will get an absolute {@link Path}-Object
|
||||
* for each visited file
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#fileWalker(File, boolean, Consumer)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void fileWalker(File path, boolean recursive, Consumer<Path> pathConsumer) {
|
||||
if (!path.exists()) return;
|
||||
for (final File f : path.listFiles()) {
|
||||
if (f.getName()
|
||||
.startsWith(".")) continue;
|
||||
if (f.isDirectory()) {
|
||||
if (recursive) fileWalker(f, pathConsumer);
|
||||
} else if (f.isFile()) {
|
||||
pathConsumer.accept(f.toPath());
|
||||
}
|
||||
}
|
||||
org.betterx.worlds.together.util.PathUtil.fileWalker(path, recursive, pathConsumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a human readable File-Size
|
||||
*
|
||||
* @param size Filesize in bytes
|
||||
* @return A Human readable String
|
||||
* @deprecated replaced by {@link org.betterx.worlds.together.util.PathUtil#humanReadableFileSize(long)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static String humanReadableFileSize(long size) {
|
||||
final int threshold = 2;
|
||||
final int factor = 1024;
|
||||
if (size < 0) return "? Byte";
|
||||
if (size < factor * threshold) {
|
||||
return size + " Byte";
|
||||
}
|
||||
char[] units = {'K', 'M', 'G', 'T', 'P'};
|
||||
int unitIndex = 0;
|
||||
double fSize = size;
|
||||
do {
|
||||
unitIndex++;
|
||||
fSize /= 1024;
|
||||
} while (fSize > factor * threshold && unitIndex < units.length);
|
||||
|
||||
return String.format("%.1f %ciB", fSize, units[unitIndex - 1]);
|
||||
return org.betterx.worlds.together.util.PathUtil.humanReadableFileSize(size);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue