From db787d46d177ec3d9d4f050526faf0db6bf0f105 Mon Sep 17 00:00:00 2001 From: micle Date: Wed, 29 Sep 2021 18:39:53 +0100 Subject: [PATCH] Added configuration file. --- .../loginprotection/LoginProtection.java | 2 + .../micle/loginprotection/setup/Config.java | 81 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/main/java/com/micle/loginprotection/setup/Config.java diff --git a/src/main/java/com/micle/loginprotection/LoginProtection.java b/src/main/java/com/micle/loginprotection/LoginProtection.java index 3dc7765..0b1d6de 100755 --- a/src/main/java/com/micle/loginprotection/LoginProtection.java +++ b/src/main/java/com/micle/loginprotection/LoginProtection.java @@ -1,6 +1,7 @@ package com.micle.loginprotection; import com.micle.loginprotection.data.ProtectedPlayers; +import com.micle.loginprotection.setup.Config; import com.micle.loginprotection.setup.Registration; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; @@ -23,6 +24,7 @@ public class LoginProtection { public LoginProtection() { Registration.register(); + Config.init(); MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/com/micle/loginprotection/setup/Config.java b/src/main/java/com/micle/loginprotection/setup/Config.java new file mode 100644 index 0000000..2bf4044 --- /dev/null +++ b/src/main/java/com/micle/loginprotection/setup/Config.java @@ -0,0 +1,81 @@ +package com.micle.loginprotection.setup; + +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.config.ModConfig; + +public class Config { + public static ForgeConfigSpec SERVER_CONFIG; + + public static ForgeConfigSpec.BooleanValue POST_GRACE_ENABLED; + public static ForgeConfigSpec.BooleanValue POST_GRACE_IGNORE_PLAYER_ENABLED; + public static ForgeConfigSpec.IntValue POST_GRACE_DURATION; + public static ForgeConfigSpec.BooleanValue POST_DROWN_ENABLED; + public static ForgeConfigSpec.BooleanValue POST_WATER_ENABLED; + public static ForgeConfigSpec.IntValue POST_WATER_DURATION; + public static ForgeConfigSpec.BooleanValue POST_LAVA_ENABLED; + public static ForgeConfigSpec.IntValue POST_LAVA_DURATION; + public static ForgeConfigSpec.BooleanValue POST_FIRE_ENABLED; + public static ForgeConfigSpec.IntValue POST_FIRE_DURATION; + + public static ForgeConfigSpec.BooleanValue MAIN_IGNORE_PLAYER_ENABLED; + + public static void init() { + initServer(); + + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG); + } + + private static void initServer() { + ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + + builder.comment("Main protection settings for protecting inactive (loading) players.").push("main"); + MAIN_IGNORE_PLAYER_ENABLED = builder + .comment("Whether mobs will ignore a protected player. (They will not attack/aggro)") + .define("ignorePlayerEnabled", true); + builder.pop(); + + builder.comment("Additional protection settings that apply as soon as a player becomes active.").push("post"); + builder.push("grace_period"); + POST_GRACE_ENABLED = builder + .comment("Whether a player receives a grace period after becoming active or not.") + .define("graceEnabled", false); + POST_GRACE_DURATION = builder + .comment("Grace period duration in seconds.") + .defineInRange("graceDuration", 10, 1, Integer.MAX_VALUE/40); + POST_GRACE_IGNORE_PLAYER_ENABLED = builder + .comment("Whether mobs will ignore a player during their grace period.") + .define("graceIgnorePlayerEnabled", false); + builder.pop(); + builder.push("water_protection"); + POST_DROWN_ENABLED = builder + .comment("Whether a player's air supply gets refilled.") + .define("drownEnabled", true); + POST_WATER_ENABLED = builder + .comment("Whether a player receives water breating when in water.") + .define("waterEnabled", false); + POST_WATER_DURATION = builder + .comment("Water breathing duration in seconds.") + .defineInRange("waterDuration", 10, 1, Integer.MAX_VALUE/20); + builder.pop(); + builder.push("lava_protection"); + POST_LAVA_ENABLED = builder + .comment("Whether a player receives fire resistance when in lava.") + .define("lavaEnabled", true); + POST_LAVA_DURATION = builder + .comment("Fire resistance duration in seconds.") + .defineInRange("lavaDuration", 10, 1, Integer.MAX_VALUE/20); + builder.pop(); + builder.push("fire_protection"); + POST_FIRE_ENABLED = builder + .comment("Whether a player receives fire resistance when on fire.") + .define("fireEnabled", false); + POST_FIRE_DURATION = builder + .comment("Fire resistance duration in seconds.") + .defineInRange("fireDuration", 10, 1, Integer.MAX_VALUE/20); + builder.pop(); + builder.pop(); + + SERVER_CONFIG = builder.build(); + } +}