Skip to content

Commit

Permalink
Add config option to change default per-player build mode enabled state
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Oct 31, 2023
1 parent 991c8c4 commit 7903605
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/com/lovetropics/gamemodebuild/GBConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.config.ModConfig;

@EventBusSubscriber (modid = GamemodeBuild.MODID, bus = Bus.MOD)
public class GBConfigs {
Expand Down Expand Up @@ -58,6 +57,7 @@ public static class Server {

final BooleanValue enabled;
final BooleanValue removeBreakSpeedDebuff;
final BooleanValue playerDefaultEnabled;

final Map<String, ItemFilter> filters = new HashMap<>();;

Expand All @@ -77,6 +77,7 @@ public static class Server {

enabled = builder.comment("Enable SurvivalPlus for all players").define("enabled", true);
removeBreakSpeedDebuff = builder.comment("If true, players will break blocks in build mode as fast as if they were not flying").define("removeBreakSpeedDebuff", true);
playerDefaultEnabled = builder.comment("Enable for all players by default. If false, you will need to use /build enable @s to enable for a player.").define("playerDefaultEnabled", true);
}

void loadLists() {
Expand Down Expand Up @@ -182,6 +183,10 @@ public boolean enabled() {
return enabled.get();
}

public boolean playerDefaultEnabled() {
return playerDefaultEnabled.get();
}

public boolean removeBreakSpeedDebuff() {
return removeBreakSpeedDebuff.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lovetropics.gamemodebuild.state;

import com.lovetropics.gamemodebuild.GBConfigs;
import com.lovetropics.gamemodebuild.GamemodeBuild;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand All @@ -25,6 +26,9 @@ public static void setEnabled(Player player, boolean enabled) {

public static boolean isEnabled(Player player) {
CompoundTag survivalPlus = getOrCreatePersistent(player, GamemodeBuild.MODID);
if (!survivalPlus.contains(KEY_ENABLED)) {
return GBConfigs.SERVER.playerDefaultEnabled();
}
return !survivalPlus.contains(KEY_ENABLED) || survivalPlus.getBoolean(KEY_ENABLED);
}

Expand Down

0 comments on commit 7903605

Please sign in to comment.