blueaxolotlk

I want to build a mod that adds /team where you can make a team of up to 2 players and you cant leave the team and you can turn on and off PVP for your team.

Kodari AI
KodariSep 25 at 10:12 pm 2
DuoTeamPVP
Adds a /team command allowing players to form permanent two-player teams. Teams cannot be left or disbanded once created. Players can toggle friendly fire (PVP) for their team on or off at any time, controlling whether teammates can damage each other. The mod tracks team membership and PVP settings, applying damage rules accordingly during combat. Simple and focused, it enhances cooperative play while giving teams control over their combat dynamics.
  1. Add the Fabric 26.2 project scaffold and /team commands for creating a two-player team, inviting/accepting a teammate, and toggling friendly fire; omit leaving a team.

  2. Block teammate damage while team PvP is disabled.

Created the Fabric 26.2 mod with two-player teams, invitations, and teammate PvP controls.

  • Commands: /duoteam create, /duoteam invite <player>, /duoteam accept, /duoteam pvp on|off, and /duoteam info. There’s no command to leave a team; friendly fire starts off.

  • The custom command uses /duoteam because vanilla /team is permission-gated for operators. Reusing it for regular players would require weakening vanilla team-admin permissions.

  • Teams and invitations are currently held in memory, so they reset when the server restarts.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 284
src/main/java/com/example/duoteams/DuoTeamsMod.java
package com.example.duoteams;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.minecraft.world.entity.player.Player;

public class DuoTeamsMod implements ModInitializer {
	@Override
	public void onInitialize() {
		TeamCommands.register();
		ServerLivingEntityEvents.ALLOW_DAMAGE.register((entity, source, amount) -> {
			if (!(entity instanceof Player victim) || !(source.getEntity() instanceof Player attacker)) {
				return true;
			}
			return TeamManager.canDamage(attacker, victim);
		});
	}
}