mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-28 03:19:12 +00:00
2.2.2
This commit is contained in:
@@ -21,10 +21,13 @@ import com.saicone.rtag.RtagItem;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
|
||||
import dev.dejvokep.boostedyaml.libs.org.snakeyaml.engine.v2.common.ScalarStyle;
|
||||
import dev.dejvokep.boostedyaml.libs.org.snakeyaml.engine.v2.nodes.Tag;
|
||||
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.MechanicType;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
@@ -113,7 +116,15 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
.builder()
|
||||
.setAutoUpdate(true)
|
||||
.build(),
|
||||
DumperSettings.DEFAULT,
|
||||
DumperSettings.builder()
|
||||
.setScalarFormatter((tag, value, role, def) -> {
|
||||
if (role == NodeRole.KEY) {
|
||||
return ScalarStyle.PLAIN;
|
||||
} else {
|
||||
return tag == Tag.STR ? ScalarStyle.DOUBLE_QUOTED : ScalarStyle.PLAIN;
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
UpdaterSettings
|
||||
.builder()
|
||||
.setVersioning(new BasicVersioning("config-version"))
|
||||
@@ -138,6 +149,20 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
}
|
||||
this.loadSettings();
|
||||
this.loadConfigs();
|
||||
this.loadGlobalEffects();
|
||||
}
|
||||
|
||||
private void loadGlobalEffects() {
|
||||
YamlDocument config = getMainConfig();
|
||||
globalEffects = new ArrayList<>();
|
||||
Section globalEffectSection = config.getSection("mechanics.global-effects");
|
||||
if (globalEffectSection != null) {
|
||||
for (Map.Entry<String, Object> entry : globalEffectSection.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section innerSection) {
|
||||
globalEffects.add(parseEffect(innerSection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
@@ -206,16 +231,6 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
|
||||
OffsetUtils.load(config.getSection("other-settings.offset-characters"));
|
||||
|
||||
globalEffects = new ArrayList<>();
|
||||
Section globalEffectSection = config.getSection("mechanics.global-effects");
|
||||
if (globalEffectSection != null) {
|
||||
for (Map.Entry<String, Object> entry : globalEffectSection.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section innerSection) {
|
||||
globalEffects.add(parseEffect(innerSection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventManager.GLOBAL_ACTIONS.clear();
|
||||
EventManager.GLOBAL_TIMES_ACTION.clear();
|
||||
Section globalEvents = config.getSection("mechanics.global-events");
|
||||
|
||||
@@ -140,9 +140,10 @@ public class BukkitLootManager implements LootManager {
|
||||
modifyWeightMap(lootWeightMap, context, conditionalElement);
|
||||
}
|
||||
for (Pair<String, BiFunction<Context<Player>, Double, Double>> pair : effect.weightOperations()) {
|
||||
double previous = lootWeightMap.getOrDefault(pair.left(), 0d);
|
||||
if (previous > 0)
|
||||
Double previous = lootWeightMap.get(pair.left());
|
||||
if (previous != null) {
|
||||
lootWeightMap.put(pair.left(), pair.right().apply(context, previous));
|
||||
}
|
||||
}
|
||||
for (Pair<String, BiFunction<Context<Player>, Double, Double>> pair : effect.weightOperationsIgnored()) {
|
||||
double previous = lootWeightMap.getOrDefault(pair.left(), 0d);
|
||||
@@ -159,8 +160,8 @@ public class BukkitLootManager implements LootManager {
|
||||
modifyWeightMap(lootWeightMap, context, conditionalElement);
|
||||
}
|
||||
for (Pair<String, BiFunction<Context<Player>, Double, Double>> pair : effect.weightOperations()) {
|
||||
double previous = lootWeightMap.getOrDefault(pair.left(), 0d);
|
||||
if (previous > 0) {
|
||||
Double previous = lootWeightMap.get(pair.left());
|
||||
if (previous != null) {
|
||||
lootWeightMap.put(pair.left(), pair.right().apply(context, previous));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -77,6 +79,11 @@ public class BukkitStorageManager implements StorageManager, Listener {
|
||||
@Override
|
||||
public void reload() {
|
||||
YamlDocument config = plugin.getConfigManager().loadConfig("database.yml");
|
||||
try {
|
||||
config.save(new File(plugin.getBoostrap().getDataFolder(), "database.yml"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.serverID = config.getString("unique-server-id", "default");
|
||||
|
||||
// Check if storage type has changed and reinitialize if necessary
|
||||
|
||||
Reference in New Issue
Block a user