Added common configuration file with the following exposed values: graceEnabled, graceLength and keyRefillAir. This has not been tested in LAN.

This commit is contained in:
2021-09-28 15:38:47 +01:00
parent 3977a22337
commit ec5b203e5a
5 changed files with 56 additions and 5 deletions

View File

@ -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.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
@ -24,6 +25,7 @@ public class LoginProtection {
public LoginProtection() {
Registration.register();
Config.init();
MinecraftForge.EVENT_BUS.register(this);
}

View File

@ -1,5 +1,7 @@
package com.micle.loginprotection.data;
import com.micle.loginprotection.setup.Config;
import java.util.UUID;
public class ProtectedPlayer {
@ -9,7 +11,7 @@ public class ProtectedPlayer {
public ProtectedPlayer(UUID player_uuid) {
this.player_uuid = player_uuid;
this.grace_period = 400;
this.grace_period = (Config.GRACE_LENGTH.get() * 40);
this.is_loading = true;
}

View File

@ -1,5 +1,6 @@
package com.micle.loginprotection.data;
import com.micle.loginprotection.setup.Config;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
@ -38,7 +39,7 @@ public class ProtectedPlayers {
protected_players.remove(protected_player);
ServerPlayer player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(player_uuid);
if (player == null) { return; }
if (player == null || !Config.GRACE_ENABLED.get()) { return; }
player.sendMessage(new TextComponent("Grace Period over!"), player_uuid);
}

View File

@ -1,6 +1,7 @@
package com.micle.loginprotection.network;
import com.micle.loginprotection.LoginProtection;
import com.micle.loginprotection.setup.Config;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
@ -25,9 +26,13 @@ public class C2SKeyPress {
if (LoginProtection.protected_players.getPlayer(sender.getUUID()) == null) { return; }
if (!LoginProtection.protected_players.getPlayer(sender.getUUID()).isLoading()) { return; }
LoginProtection.protected_players.getPlayer(sender.getUUID()).setLoading(false);
sender.sendMessage(new TextComponent("Grace Period started!"), sender.getUUID());
if (sender.isInWater()) {
if (!Config.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());
}
});

View File

@ -0,0 +1,41 @@
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 COMMON_CONFIG;
public static ForgeConfigSpec.BooleanValue GRACE_ENABLED;
public static ForgeConfigSpec.IntValue GRACE_LENGTH;
public static ForgeConfigSpec.BooleanValue KEY_REFILL_AIR;
public static void init() {
initCommon();
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, COMMON_CONFIG);
}
private static void initCommon() {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
builder.comment("Grace period settings").push("grace");
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);
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();
}
}