Skip to content

Commit

Permalink
Add team support for FTB Teams and Argonauts
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiahwinsley committed Aug 14, 2023
1 parent c37ae5b commit 9c1e97e
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 12 deletions.
28 changes: 25 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand All @@ -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")

}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions src/main/java/net/permutated/pylons/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -28,6 +29,9 @@ private ConfigManager() {
}

public static class ServerConfig {
// CATEGORY_GENERAL
public final ForgeConfigSpec.BooleanValue teamSupportEnabled;

// CATEGORY_EXPULSION
public final ForgeConfigSpec.ConfigValue<List<? extends String>> expulsionAllowedDimensions;
public final ForgeConfigSpec.IntValue expulsionWorldSpawnRadius;
Expand All @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/permutated/pylons/Pylons.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
21 changes: 21 additions & 0 deletions src/main/java/net/permutated/pylons/compat/teams/TeamCompat.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.permutated.pylons.compat.teams;

import java.util.UUID;

public interface TeamSupport {
boolean arePlayersInSameTeam(UUID player1, UUID player2);
}
3 changes: 2 additions & 1 deletion src/main/java/net/permutated/pylons/data/DataGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +82,6 @@ public void setRemoved() {
}

protected UUID owner = null;
protected String ownerName = null;

@Nullable
public UUID getOwner() {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/permutated/pylons/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9c1e97e

Please sign in to comment.