Updated configuration file layout. Added new post-protection features (configurable): water protection, lava protection and fire protection. Changed default configuration values.
This commit is contained in:
@ -11,7 +11,7 @@ public class ProtectedPlayer {
|
||||
|
||||
public ProtectedPlayer(UUID player_uuid) {
|
||||
this.player_uuid = player_uuid;
|
||||
this.grace_period = (Config.GRACE_LENGTH.get() * 40);
|
||||
this.grace_period = (Config.POST_GRACE_DURATION.get() * 40);
|
||||
this.is_loading = true;
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ public class ProtectedPlayers {
|
||||
protected_players.remove(protected_player);
|
||||
|
||||
ServerPlayer player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(player_uuid);
|
||||
if (player == null || !Config.GRACE_ENABLED.get()) { return; }
|
||||
if (player == null || !Config.POST_GRACE_ENABLED.get()) { return; }
|
||||
player.sendMessage(new TextComponent("Grace Period over!"), player_uuid);
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,9 @@ import com.micle.loginprotection.setup.Config;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@ -26,14 +29,25 @@ public class C2SKeyPress {
|
||||
if (LoginProtection.protected_players.getPlayer(sender.getUUID()) == null) { return; }
|
||||
if (!LoginProtection.protected_players.getPlayer(sender.getUUID()).isLoading()) { return; }
|
||||
|
||||
if (!Config.GRACE_ENABLED.get()) {
|
||||
if (!Config.POST_GRACE_ENABLED.get()) {
|
||||
LoginProtection.protected_players.removePlayer(sender.getUUID());
|
||||
} else {
|
||||
LoginProtection.protected_players.getPlayer(sender.getUUID()).setLoading(false);
|
||||
sender.sendMessage(new TextComponent("Grace Period started!"), sender.getUUID());
|
||||
}
|
||||
if (sender.isInWater() && Config.KEY_REFILL_AIR.get()) {
|
||||
sender.setAirSupply(sender.getMaxAirSupply());
|
||||
if (sender.isInWater()) {
|
||||
if (Config.POST_DROWN_ENABLED.get()) {
|
||||
sender.setAirSupply(sender.getMaxAirSupply());
|
||||
}
|
||||
if (Config.POST_WATER_ENABLED.get()) {
|
||||
sender.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, Config.POST_WATER_DURATION.get()*20, 0));
|
||||
}
|
||||
}
|
||||
if (sender.isInLava() && Config.POST_LAVA_ENABLED.get()) {
|
||||
sender.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, Config.POST_LAVA_DURATION.get()*20, 0));
|
||||
}
|
||||
if (sender.isOnFire() && Config.POST_FIRE_ENABLED.get()) {
|
||||
sender.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, Config.POST_FIRE_DURATION.get()*20, 0));
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
|
||||
@ -5,37 +5,65 @@ import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
|
||||
public class Config {
|
||||
public static ForgeConfigSpec COMMON_CONFIG;
|
||||
public static ForgeConfigSpec SERVER_CONFIG;
|
||||
|
||||
public static ForgeConfigSpec.BooleanValue GRACE_ENABLED;
|
||||
public static ForgeConfigSpec.IntValue GRACE_LENGTH;
|
||||
|
||||
public static ForgeConfigSpec.BooleanValue KEY_REFILL_AIR;
|
||||
public static ForgeConfigSpec.BooleanValue POST_GRACE_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 void init() {
|
||||
initCommon();
|
||||
initServer();
|
||||
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, COMMON_CONFIG);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG);
|
||||
}
|
||||
|
||||
private static void initCommon() {
|
||||
private static void initServer() {
|
||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
||||
|
||||
builder.comment("Grace period settings").push("grace");
|
||||
GRACE_ENABLED = builder
|
||||
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", true);
|
||||
GRACE_LENGTH = builder
|
||||
.comment("How long the grace period lasts for a player in seconds.")
|
||||
.defineInRange("graceLength", 10, 1, Integer.MAX_VALUE/40);
|
||||
.define("graceEnabled", false);
|
||||
POST_GRACE_DURATION = builder
|
||||
.comment("Grace period duration in seconds.")
|
||||
.defineInRange("graceDuration", 10, 1, Integer.MAX_VALUE/40);
|
||||
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();
|
||||
|
||||
builder.comment("Key settings").push("key");
|
||||
KEY_REFILL_AIR = builder
|
||||
.comment("Whether a player's air supply gets refilled upon becoming active.")
|
||||
.define("keyRefillAir", true);
|
||||
builder.pop();
|
||||
|
||||
COMMON_CONFIG = builder.build();
|
||||
SERVER_CONFIG = builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user