diff --git a/build.gradle b/build.gradle index 7dde86f..6d7bf45 100644 --- a/build.gradle +++ b/build.gradle @@ -113,9 +113,27 @@ minecraft { sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { - maven { - url "https://www.cursemaven.com" - content { + exclusiveContent { + forRepositories(fg.repository) + forRepository { + maven { + name "Modrinth" + url "https://api.modrinth.com/maven" + } + } + filter { + includeGroup "maven.modrinth" + } + } + exclusiveContent { + forRepositories(fg.repository) + forRepository { + maven { + name "CurseMaven" + url "https://www.cursemaven.com" + } + } + filter { includeGroup "curse.maven" } } @@ -128,6 +146,10 @@ dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" runtimeOnly fg.deobf("curse.maven:jei-238222:4574528") + compileOnly fg.deobf("curse.maven:ftb-teams-forge-404468:4623116") + + compileOnly fg.deobf("maven.modrinth:argonauts:1.0.2") + compileOnly fg.deobf("maven.modrinth:resourceful-lib:2.0.8") } diff --git a/gradle.properties b/gradle.properties index a7f15a2..da63a2f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=1.20 -forge_version=46.0.12 +minecraft_version=1.20.1 +forge_version=47.1.0 group=net.permutated mod_id=pylons -version=4.0.0 +version=4.1.0 diff --git a/src/main/java/net/permutated/pylons/ConfigManager.java b/src/main/java/net/permutated/pylons/ConfigManager.java index 11bdf8a..99b4daa 100644 --- a/src/main/java/net/permutated/pylons/ConfigManager.java +++ b/src/main/java/net/permutated/pylons/ConfigManager.java @@ -13,6 +13,7 @@ private ConfigManager() { // nothing to do } + public static final String CATEGORY_GENERAL = "general"; public static final String CATEGORY_EXPULSION = "expulsion_pylon"; public static final String CATEGORY_INFUSION = "infusion_pylon"; public static final String CATEGORY_HARVESTER = "harvester_pylon"; @@ -28,6 +29,9 @@ private ConfigManager() { } public static class ServerConfig { + // CATEGORY_GENERAL + public final ForgeConfigSpec.BooleanValue teamSupportEnabled; + // CATEGORY_EXPULSION public final ForgeConfigSpec.ConfigValue> expulsionAllowedDimensions; public final ForgeConfigSpec.IntValue expulsionWorldSpawnRadius; @@ -49,6 +53,15 @@ public static class ServerConfig { ServerConfig(ForgeConfigSpec.Builder builder) { + // CATEGORY_GENERAL + builder.push(CATEGORY_GENERAL); + + teamSupportEnabled = builder + .comment("Whether team support is enabled if a compatible mod (FTB Teams, Argonauts) is installed") + .define("teamSupportEnabled", true); + + builder.pop(); + // CATEGORY_EXPULSION builder.push(CATEGORY_EXPULSION); diff --git a/src/main/java/net/permutated/pylons/Pylons.java b/src/main/java/net/permutated/pylons/Pylons.java index b704e9c..43e9f10 100644 --- a/src/main/java/net/permutated/pylons/Pylons.java +++ b/src/main/java/net/permutated/pylons/Pylons.java @@ -10,9 +10,10 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.permutated.pylons.machines.base.AbstractPylonBlock; +import net.permutated.pylons.compat.teams.TeamCompat; import net.permutated.pylons.item.MobFilterCard; import net.permutated.pylons.item.PlayerFilterCard; +import net.permutated.pylons.machines.base.AbstractPylonBlock; import net.permutated.pylons.network.NetworkDispatcher; import net.permutated.pylons.util.ChunkManager; import org.apache.logging.log4j.LogManager; @@ -32,6 +33,7 @@ public Pylons() { ModRegistry.register(); NetworkDispatcher.register(); + TeamCompat.init(); ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ConfigManager.SERVER_SPEC); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetupEvent); diff --git a/src/main/java/net/permutated/pylons/compat/teams/ArgonautTeamSupport.java b/src/main/java/net/permutated/pylons/compat/teams/ArgonautTeamSupport.java new file mode 100644 index 0000000..ba250da --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/teams/ArgonautTeamSupport.java @@ -0,0 +1,19 @@ +package net.permutated.pylons.compat.teams; + +import earth.terrarium.argonauts.api.guild.Guild; +import earth.terrarium.argonauts.api.guild.GuildApi; +import net.minecraftforge.server.ServerLifecycleHooks; + +import java.util.UUID; + +public class ArgonautTeamSupport implements TeamSupport { + @Override + public boolean arePlayersInSameTeam(UUID player1, UUID player2) { + Guild guild = GuildApi.API.getPlayerGuild(ServerLifecycleHooks.getCurrentServer(), player1); + + if (guild != null) { + return guild.members().isMember(player2); + } + return false; + } +} diff --git a/src/main/java/net/permutated/pylons/compat/teams/FTBTeamSupport.java b/src/main/java/net/permutated/pylons/compat/teams/FTBTeamSupport.java new file mode 100644 index 0000000..69afb5f --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/teams/FTBTeamSupport.java @@ -0,0 +1,12 @@ +package net.permutated.pylons.compat.teams; + +import dev.ftb.mods.ftbteams.api.FTBTeamsAPI; + +import java.util.UUID; + +public class FTBTeamSupport implements TeamSupport { + @Override + public boolean arePlayersInSameTeam(UUID player1, UUID player2) { + return FTBTeamsAPI.api().getManager().arePlayersInSameTeam(player1, player2); + } +} diff --git a/src/main/java/net/permutated/pylons/compat/teams/NoTeamSupport.java b/src/main/java/net/permutated/pylons/compat/teams/NoTeamSupport.java new file mode 100644 index 0000000..ab2e7fc --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/teams/NoTeamSupport.java @@ -0,0 +1,10 @@ +package net.permutated.pylons.compat.teams; + +import java.util.UUID; + +public class NoTeamSupport implements TeamSupport { + @Override + public boolean arePlayersInSameTeam(UUID player1, UUID player2) { + return false; + } +} diff --git a/src/main/java/net/permutated/pylons/compat/teams/TeamCompat.java b/src/main/java/net/permutated/pylons/compat/teams/TeamCompat.java new file mode 100644 index 0000000..4a1f6b9 --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/teams/TeamCompat.java @@ -0,0 +1,21 @@ +package net.permutated.pylons.compat.teams; + +import net.minecraftforge.fml.ModList; + +public class TeamCompat { + private TeamCompat() { + // nothing to do + } + private static TeamSupport instance = new NoTeamSupport(); + public static TeamSupport getInstance() { + return instance; + } + + public static void init() { + if (ModList.get().isLoaded("ftbteams")) { + instance = new FTBTeamSupport(); + } else if (ModList.get().isLoaded("argonauts")) { + instance = new ArgonautTeamSupport(); + } + } +} diff --git a/src/main/java/net/permutated/pylons/compat/teams/TeamSupport.java b/src/main/java/net/permutated/pylons/compat/teams/TeamSupport.java new file mode 100644 index 0000000..860a2da --- /dev/null +++ b/src/main/java/net/permutated/pylons/compat/teams/TeamSupport.java @@ -0,0 +1,7 @@ +package net.permutated.pylons.compat.teams; + +import java.util.UUID; + +public interface TeamSupport { + boolean arePlayersInSameTeam(UUID player1, UUID player2); +} diff --git a/src/main/java/net/permutated/pylons/data/DataGenerators.java b/src/main/java/net/permutated/pylons/data/DataGenerators.java index d2ab9ed..c8370b0 100644 --- a/src/main/java/net/permutated/pylons/data/DataGenerators.java +++ b/src/main/java/net/permutated/pylons/data/DataGenerators.java @@ -8,6 +8,7 @@ import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.permutated.pylons.Pylons; import net.permutated.pylons.data.client.BlockStates; import net.permutated.pylons.data.client.ItemModels; import net.permutated.pylons.data.client.Languages; @@ -18,7 +19,7 @@ import java.util.Collections; import java.util.List; -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Pylons.MODID) public final class DataGenerators { private DataGenerators() {} diff --git a/src/main/java/net/permutated/pylons/machines/base/AbstractPylonTile.java b/src/main/java/net/permutated/pylons/machines/base/AbstractPylonTile.java index fbbcdf2..643c9c5 100644 --- a/src/main/java/net/permutated/pylons/machines/base/AbstractPylonTile.java +++ b/src/main/java/net/permutated/pylons/machines/base/AbstractPylonTile.java @@ -20,6 +20,8 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; +import net.permutated.pylons.ConfigManager; +import net.permutated.pylons.compat.teams.TeamCompat; import net.permutated.pylons.util.ChunkManager; import net.permutated.pylons.util.Constants; import net.permutated.pylons.util.Range; @@ -80,7 +82,6 @@ public void setRemoved() { } protected UUID owner = null; - protected String ownerName = null; @Nullable public UUID getOwner() { @@ -92,8 +93,13 @@ public void setOwner(UUID owner) { this.setChanged(); } + public boolean hasTeamAccess(Player player) { + return Boolean.TRUE.equals(ConfigManager.SERVER.teamSupportEnabled.get()) + && TeamCompat.getInstance().arePlayersInSameTeam(owner, player.getUUID()); + } + public boolean canAccess(Player player) { - return Objects.equals(player.getUUID(), owner) || owner == null || player.hasPermissions(2); + return Objects.equals(player.getUUID(), owner) || owner == null || player.hasPermissions(2) || hasTeamAccess(player); } private long lastTicked = 0L; diff --git a/src/main/java/net/permutated/pylons/util/Constants.java b/src/main/java/net/permutated/pylons/util/Constants.java index 30b175d..d52a329 100644 --- a/src/main/java/net/permutated/pylons/util/Constants.java +++ b/src/main/java/net/permutated/pylons/util/Constants.java @@ -20,6 +20,7 @@ private NBT() { public static final String REGISTRY = "registry"; public static final String ENERGY = "energy"; public static final String OWNER = "owner"; + public static final String TEAM = "team"; public static final String NAME = "name"; public static final String UUID = "uuid"; public static final String INV = "inv"; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index c262f13..1846c18 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -6,7 +6,7 @@ # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml modLoader="javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="[46,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion="[47,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. license="MIT" @@ -35,7 +35,7 @@ Utility Pylons # Does this dependency have to exist - if not, ordering below must be specified mandatory=true #mandatory # The version range of the dependency - versionRange="[46,)" #mandatory + versionRange="[47,)" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER