mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2026-01-06 15:51:50 +00:00
checkpoint - 2
This commit is contained in:
@@ -2,9 +2,15 @@ package net.momirealms.customfishing.common.config;
|
||||
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
|
||||
public interface ConfigManager {
|
||||
import java.io.File;
|
||||
|
||||
public interface ConfigLoader {
|
||||
|
||||
YamlDocument loadConfig(String filePath);
|
||||
|
||||
YamlDocument loadConfig(String filePath, char routeSeparator);
|
||||
|
||||
YamlDocument loadData(File file);
|
||||
|
||||
YamlDocument loadData(File file, char routeSeparator);
|
||||
}
|
||||
@@ -32,4 +32,9 @@ public class Node<T> {
|
||||
public Node<T> getChild(String node) {
|
||||
return childTree.get(node);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Node<T> removeChild(String node) {
|
||||
return childTree.remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class AdventureHelper {
|
||||
private final MiniMessage miniMessage;
|
||||
private final MiniMessage miniMessageStrict;
|
||||
private final GsonComponentSerializer gsonComponentSerializer;
|
||||
private final Cache<String, String> miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES)
|
||||
private final Cache<String, String> miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
|
||||
|
||||
private AdventureHelper() {
|
||||
this.miniMessage = MiniMessage.builder().build();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.customfishing.common.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface Item<I> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.customfishing.common.plugin;
|
||||
|
||||
import net.momirealms.customfishing.common.config.ConfigManager;
|
||||
import net.momirealms.customfishing.common.config.ConfigLoader;
|
||||
import net.momirealms.customfishing.common.dependency.DependencyManager;
|
||||
import net.momirealms.customfishing.common.locale.TranslationManager;
|
||||
import net.momirealms.customfishing.common.plugin.classpath.ClassPathAppender;
|
||||
@@ -30,7 +30,7 @@ public interface CustomFishingPlugin {
|
||||
|
||||
TranslationManager getTranslationManager();
|
||||
|
||||
ConfigManager getConfigManager();
|
||||
ConfigLoader getConfigManager();
|
||||
|
||||
String getServerVersion();
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.momirealms.customfishing.common.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RandomUtils {
|
||||
|
||||
private final Random random;
|
||||
|
||||
private RandomUtils() {
|
||||
random = ThreadLocalRandom.current();
|
||||
}
|
||||
|
||||
private static class SingletonHolder {
|
||||
private static final RandomUtils INSTANCE = new RandomUtils();
|
||||
}
|
||||
|
||||
private static RandomUtils getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public static int generateRandomInt(int min, int max) {
|
||||
return getInstance().random.nextInt(max - min + 1) + min;
|
||||
}
|
||||
|
||||
public static double generateRandomDouble(double min, double max) {
|
||||
return min + (max - min) * getInstance().random.nextDouble();
|
||||
}
|
||||
|
||||
public static boolean generateRandomBoolean() {
|
||||
return getInstance().random.nextBoolean();
|
||||
}
|
||||
|
||||
public static <T> T getRandomElementFromArray(T[] array) {
|
||||
int index = getInstance().random.nextInt(array.length);
|
||||
return array[index];
|
||||
}
|
||||
|
||||
public static <T> T[] getRandomElementsFromArray(T[] array, int count) {
|
||||
if (count > array.length) {
|
||||
throw new IllegalArgumentException("Count cannot be greater than array length");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T[] result = (T[]) new Object[count];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int index = getInstance().random.nextInt(array.length - i);
|
||||
result[i] = array[index];
|
||||
array[index] = array[array.length - i - 1];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user