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:
@ -1,6 +1,7 @@
|
|||||||
package com.micle.loginprotection;
|
package com.micle.loginprotection;
|
||||||
|
|
||||||
import com.micle.loginprotection.data.ProtectedPlayers;
|
import com.micle.loginprotection.data.ProtectedPlayers;
|
||||||
|
import com.micle.loginprotection.setup.Config;
|
||||||
import com.micle.loginprotection.setup.Registration;
|
import com.micle.loginprotection.setup.Registration;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
@ -24,6 +25,7 @@ public class LoginProtection {
|
|||||||
|
|
||||||
public LoginProtection() {
|
public LoginProtection() {
|
||||||
Registration.register();
|
Registration.register();
|
||||||
|
Config.init();
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package com.micle.loginprotection.data;
|
package com.micle.loginprotection.data;
|
||||||
|
|
||||||
|
import com.micle.loginprotection.setup.Config;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ProtectedPlayer {
|
public class ProtectedPlayer {
|
||||||
@ -9,7 +11,7 @@ public class ProtectedPlayer {
|
|||||||
|
|
||||||
public ProtectedPlayer(UUID player_uuid) {
|
public ProtectedPlayer(UUID player_uuid) {
|
||||||
this.player_uuid = player_uuid;
|
this.player_uuid = player_uuid;
|
||||||
this.grace_period = 400;
|
this.grace_period = (Config.GRACE_LENGTH.get() * 40);
|
||||||
this.is_loading = true;
|
this.is_loading = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.micle.loginprotection.data;
|
package com.micle.loginprotection.data;
|
||||||
|
|
||||||
|
import com.micle.loginprotection.setup.Config;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
|
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
|
||||||
@ -38,7 +39,7 @@ public class ProtectedPlayers {
|
|||||||
protected_players.remove(protected_player);
|
protected_players.remove(protected_player);
|
||||||
|
|
||||||
ServerPlayer player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(player_uuid);
|
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);
|
player.sendMessage(new TextComponent("Grace Period over!"), player_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.micle.loginprotection.network;
|
package com.micle.loginprotection.network;
|
||||||
|
|
||||||
import com.micle.loginprotection.LoginProtection;
|
import com.micle.loginprotection.LoginProtection;
|
||||||
|
import com.micle.loginprotection.setup.Config;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
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()) == null) { return; }
|
||||||
if (!LoginProtection.protected_players.getPlayer(sender.getUUID()).isLoading()) { return; }
|
if (!LoginProtection.protected_players.getPlayer(sender.getUUID()).isLoading()) { return; }
|
||||||
|
|
||||||
|
if (!Config.GRACE_ENABLED.get()) {
|
||||||
|
LoginProtection.protected_players.removePlayer(sender.getUUID());
|
||||||
|
} else {
|
||||||
LoginProtection.protected_players.getPlayer(sender.getUUID()).setLoading(false);
|
LoginProtection.protected_players.getPlayer(sender.getUUID()).setLoading(false);
|
||||||
sender.sendMessage(new TextComponent("Grace Period started!"), sender.getUUID());
|
sender.sendMessage(new TextComponent("Grace Period started!"), sender.getUUID());
|
||||||
if (sender.isInWater()) {
|
}
|
||||||
|
if (sender.isInWater() && Config.KEY_REFILL_AIR.get()) {
|
||||||
sender.setAirSupply(sender.getMaxAirSupply());
|
sender.setAirSupply(sender.getMaxAirSupply());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
41
src/main/java/com/micle/loginprotection/setup/Config.java
Normal file
41
src/main/java/com/micle/loginprotection/setup/Config.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user