Skip to content

Commit

Permalink
feat: added optional gamestage requirement
Browse files Browse the repository at this point in the history
"require_game_stage" server config setting, defaults to false
If true, players need the "ftbchunks_mapping" game stage to be able
to open the map or see the minimap

KubeJS and/or Gamestages are required to support this

FTBTeam/FTB-Mods-Issues#580
  • Loading branch information
desht committed Dec 14, 2022
1 parent 9d8ca61 commit dcb97c9
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.ftb.mods.ftbchunks;

import dev.ftb.mods.ftbchunks.data.*;
import dev.ftb.mods.ftbchunks.integration.stages.StageHelper;
import dev.ftb.mods.ftblibrary.config.NameMap;
import dev.ftb.mods.ftblibrary.snbt.config.*;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

import java.util.Collections;
Expand Down Expand Up @@ -33,6 +35,7 @@ public interface FTBChunksWorldConfig {
IntValue HARD_TEAM_CLAIM_LIMIT = CONFIG.getInt("hard_team_claim_limit", 0, 0, Integer.MAX_VALUE).comment("Hard limit for the number of chunks a team can claim, regardless of how many members. Default of 0 means no hard limit.");
IntValue HARD_TEAM_FORCE_LIMIT = CONFIG.getInt("hard_team_force_limit", 0, 0, Integer.MAX_VALUE).comment("Hard limit for the number of chunks a team can force-load, regardless of how many members. Default of 0 means no hard limit.");
EnumValue<PartyLimitMode> PARTY_LIMIT_MODE = CONFIG.getEnum("party_limit_mode", PartyLimitMode.NAME_MAP).comment("Method by which party claim & force-load limits are calculated.","LARGEST: use the limits of the member with the largest limits","SUM: add up all the members' limits","OWNER: use the party owner's limits only","AVERAGE: use the average of all members' limits.");
BooleanValue REQUIRE_GAME_STAGE = CONFIG.getBoolean("require_game_stage", false).comment("If true, the player must have the 'ftbchunks_mapping' Game stage to be able to use the map and minimap.\nRequires KubeJS and/or Gamestages to be installed.");

Set<ResourceKey<Level>> CLAIM_DIMENSION_BLACKLIST_SET = new HashSet<>();

Expand Down Expand Up @@ -64,4 +67,12 @@ static boolean noWilderness(ServerPlayer player) {

return NO_WILDERNESS.get();
}

static boolean playerHasMapStage(Player player) {
return !REQUIRE_GAME_STAGE.get() || StageHelper.INSTANCE.get().has(player, "ftbchunks_mapping");
}

static boolean shouldShowMinimap(Player player) {
return !FORCE_DISABLE_MINIMAP.get() && playerHasMapStage(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public EventResult customClick(CustomClickEvent event) {
}

public EventResult keyPressed(Minecraft client, int keyCode, int scanCode, int action, int modifiers) {
if (action != GLFW.GLFW_PRESS || client.screen != null) {
if (action != GLFW.GLFW_PRESS || client.screen != null || !FTBChunksWorldConfig.playerHasMapStage(client.player)) {
return EventResult.pass();
}
if (openMapKey.matches(keyCode, scanCode)) {
Expand Down Expand Up @@ -564,7 +564,7 @@ public void renderHud(PoseStack matrixStack, float tickDelta) {
currentPlayerChunkZ = cz;
}

if (mc.options.renderDebug || !FTBChunksClientConfig.MINIMAP_ENABLED.get() || FTBChunksClientConfig.MINIMAP_VISIBILITY.get() == 0 || FTBChunksWorldConfig.FORCE_DISABLE_MINIMAP.get()) {
if (mc.options.renderDebug || !FTBChunksClientConfig.MINIMAP_ENABLED.get() || FTBChunksClientConfig.MINIMAP_VISIBILITY.get() == 0 || !FTBChunksWorldConfig.shouldShowMinimap(mc.player)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.ftb.mods.ftbchunks.integration.stages;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;

public class EntityTagStageHelper extends StageHelper {
@Override
public boolean has(Player player, String stage) {
return player.getTags().contains(stage);
}

@Override
public void add(ServerPlayer player, String stage) {
player.addTag(stage);
}

@Override
public void remove(ServerPlayer player, String stage) {
player.removeTag(stage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.ftb.mods.ftbchunks.integration.stages;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;

public class GameStagesStageHelper extends StageHelper {
@Override
public boolean has(Player player, String stage) {
return hasStage(player, stage);
}

@Override
public void add(ServerPlayer player, String stage) {
addStage(player, stage);
}

@Override
public void remove(ServerPlayer player, String stage) {
removeStage(player, stage);
}

@ExpectPlatform
public static boolean hasStage(Player player, String stage) {
throw new AssertionError();
}

@ExpectPlatform
public static void addStage(Player player, String stage) {
throw new AssertionError();
}

@ExpectPlatform
public static void removeStage(Player player, String stage) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.ftb.mods.ftbchunks.integration.stages;

import dev.latvian.mods.kubejs.stages.Stages;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;

public class KubeJSStageHelper extends StageHelper {
@Override
public boolean has(Player player, String stage) {
return Stages.get(player).has(stage);
}

@Override
public void add(ServerPlayer player, String stage) {
Stages.get(player).add(stage);
}

@Override
public void remove(ServerPlayer player, String stage) {
Stages.get(player).remove(stage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.ftb.mods.ftbchunks.integration.stages;

import com.google.common.base.Suppliers;
import dev.architectury.platform.Platform;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;

import java.util.function.Supplier;

public abstract class StageHelper {
public static final Supplier<StageHelper> INSTANCE = Suppliers.memoize(() -> {
if (Platform.isModLoaded("kubejs")) {
return new KubeJSStageHelper();
} else if (Platform.isModLoaded("gamestages")) {
return new GameStagesStageHelper();
} else {
return new EntityTagStageHelper();
}
}
);

public abstract boolean has(Player player, String stage);

public abstract void add(ServerPlayer player, String stage);

public abstract void remove(ServerPlayer player, String stage);
}
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/ftbchunks/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,7 @@
"ftbchunks.hard_team_force_limit": "Hard Max Team Forceload Limit",
"ftbchunks.hard_team_force_limit.tooltip": "Hard force-load limit for party teams,\n regardless of member count or Party Limit Calculation mode.\nDefault of 0 means no hard limit.",
"ftbchunks.party_limit_mode": "Party Limit Calculation Mode",
"ftbchunks.party_limit_mode.tooltip": "Method by which party claim & force-load limits are calculated.\nLARGEST: use the limits of the member with the largest limits\nSUM: add up all the members' limits\nOWNER: use the party owner's limits only\nAVERAGE: use the average of all members' limits."
"ftbchunks.party_limit_mode.tooltip": "Method by which party claim & force-load limits are calculated.\nLARGEST: use the limits of the member with the largest limits\nSUM: add up all the members' limits\nOWNER: use the party owner's limits only\nAVERAGE: use the average of all members' limits.",
"ftbchunks.require_game_stage": "Require Game Stage for Mapping",
"ftbchunks.require_game_stage.tooltip": "If true, players must have the 'ftbchunks_mapping' game stage (KubeJS and/or Gamestages required) to be able to open the map or see the minimap"
}
4 changes: 2 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ dependencies {
modImplementation("dev.ftb.mods:ftb-library-fabric:${rootProject.ftb_library_version}") { transitive = false }
modImplementation("dev.ftb.mods:ftb-teams-fabric:${rootProject.ftb_teams_version}") { transitive = false }
modImplementation("dev.ftb.mods:ftb-ranks-fabric:${rootProject.ftb_ranks_version}") { transitive = false }
// modImplementation("dev.latvian.mods:rhino-fabric:${rootProject.rhino_version}") { transitive = false }
// modImplementation("dev.latvian.mods:kubejs-fabric:${rootProject.kubejs_version}") { transitive = false }
modImplementation("dev.latvian.mods:rhino-fabric:${rootProject.rhino_version}")
modImplementation("dev.latvian.mods:kubejs-fabric:${rootProject.kubejs_version}")

// modImplementation("curse.maven:auth-me-356643:3725468")
modImplementation("curse.maven:cloth-config-348521:3972420")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.ftb.mods.ftbchunks.integration.stages.fabric;

import net.minecraft.world.entity.player.Player;

/**
* Dummy no-op implementation since there's no Gamestages on Fabric.
* This shouldn't ever get loaded, but just in case...
*/
public class GameStagesStageHelperImpl {
public static boolean hasStage(Player player, String stage) {
return false;
}

public static void addStage(Player player, String stage) {
}

public static void removeStage(Player player, String stage) {
}
}
8 changes: 8 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ repositories {
includeGroup "mezz.jei"
}
}
maven {
url "https://maven.blamejared.com"
content {
includeGroup "net.darkhax.gamestages"
}
}
}

dependencies {
Expand All @@ -59,6 +65,8 @@ dependencies {
modImplementation("curse.maven:balm-531761:${balm_forge_version}")
modImplementation("curse.maven:waystones-245755:${waystones_forge_version}")

modCompileOnlyApi "net.darkhax.gamestages:GameStages-Forge-${rootProject.minecraft_version}:${rootProject.gamestages_version}"

common(project(path: ":common", configuration: "dev")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive false }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.ftb.mods.ftbchunks.integration.stages.forge;

import net.darkhax.gamestages.GameStageHelper;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;

public class GameStagesStageHelperImpl {
public static boolean hasStage(Player player, String stage) {
return GameStageHelper.hasStage(player, stage);
}

public static void addStage(Player player, String stage) {
if (player instanceof ServerPlayer sp) GameStageHelper.addStage(sp, stage);
}

public static void removeStage(Player player, String stage) {
if (player instanceof ServerPlayer sp) GameStageHelper.removeStage(sp, stage);
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ waystones_forge_version=3901921
waystones_fabric_version=3901920
balm_forge_version=3914527
balm_fabric_version=3913965

0 comments on commit dcb97c9

Please sign in to comment.