Make me a fully functional Minecraft plugin for Paper 1.21.11 that adds a complete team and alliance system with custom double-chest GUIs. Make sure every feature works properly and that all team data saves after server restarts.
**Team Creation**
- Allow any player to use `/team create` to create their own team.
- When a player uses `/team create`, open a custom GUI that allows them to enter a team name. They must enter a valid name before the team can be created.
- Do not allow players to create a team without a name or join multiple teams at once.
- Automatically make the player who creates the team its owner.
- Give every team a unique name and prevent duplicate team names.
- After creating a team, automatically open its custom double-chest GUI.
**Team GUI**
Create a custom 54-slot double-chest GUI for each team. Make it look clean and organized, with clickable items representing different options.
The GUI should include:
- Team information and team name.
- Team members displayed using their Minecraft player heads.
- An option to invite players.
- An option to view pending invitations.
- An option to manage team members.
- An option to view allied teams.
- An option to send alliance requests.
- An option to leave the team.
- An option to disband the team (team owner only).
Make every option functional. Players must not be able to take items from the GUI, place items inside it, or exploit it using shift-clicking, number keys, or inventory dragging.
**Team Commands and Invitations**
- `/team` — Open the team GUI and view team information.
- `/team create` — Start the team creation process.
- `/team invite ` — Invite a player to the team.
- `/team accept ` — Accept a team invitation.
- `/team deny ` — Decline a team invitation.
- `/team leave` — Leave the current team.
- `/team kick ` — Kick a member (owner or authorized staff only).
- `/team info ` — View team information.
- `/team transfer ` — Transfer team ownership.
- `/team disband` — Disband the team (owner only).
Players should receive clear messages when they are invited, accept or decline an invitation, leave a team, or get kicked. Prevent expired, duplicate, and invalid invitations.
**Team Names Next to Player Names**
- Display each player's team name next to their username in the Minecraft tab list.
- Display the team name next to their username above their head during normal gameplay.
- Use a clean format such as `[TeamName] PlayerName`.
- Update the formatting automatically whenever someone joins a team, leaves a team, changes their name display, or gets kicked.
- Players who are not in a team should keep their normal username display.
- Make sure this works for both online and offline team members when their data is loaded.
**Alliance System**
Add a complete alliance system that lets separate teams become allies.
- Add an alliance option to the team GUI.
- Add `/ally request ` to request an alliance with the team of the specified player.
- If the target player is not in a team, display an appropriate error message.
- Send alliance requests to the target team's owner or authorized members.
- Allow the receiving team to accept or decline alliance requests.
- Add `/ally accept `, `/ally deny `, `/ally list`, and `/ally remove `.
- Display allied teams in the team GUI, including their team names.
- Allow authorized members to manage alliances through the GUI.
- Prevent teams from allying with themselves, sending duplicate requests, or creating duplicate alliances.
- If a team is disbanded, clean up its alliance relationships and pending requests.
**Team and Ally PvP Protection**
This is one of the most important parts of the plugin.
- Team members cannot damage or kill other members of their own team.
- Allied teams cannot damage or kill each other's members.
- Protection must work in both directions.
- Block melee attacks, swords, axes, bows, crossbows, tridents, projectiles, and other player-caused damage.
- Correctly identify the original shooter of arrows and other projectiles so players cannot bypass protection using ranged attacks.
- Make sure explosions or other indirect player-caused attacks cannot bypass the protection when the responsible attacker can be identified.
- Cancel the damage completely so protected players do not lose health.
- Do not interfere with normal PvP between players who are not teammates or allies.
- Ensure that team and alliance protection works consistently after reconnecting or restarting the server.
**Permissions and Restrictions**
- Any player can create and manage their own team, subject to team ownership rules.
- Only team owners or authorized members can invite players, kick members, disband teams, transfer ownership, or manage alliances.
- Prevent unauthorized players from using team management commands.
- Validate all player names and team names.
- Prevent players from joining another team while already in a team.
- Handle team ownership correctly if the owner leaves or transfers ownership.
- Display helpful error messages whenever a command cannot be completed.
**Data Saving and Configuration**
- Save team names, owners, members, invitations, alliances, and pending alliance requests.
- Store the data in persistent files so it survives server restarts and reloads.
- Add a configuration file for settings such as team size limits, invitation expiration, team name length, and name formatting.
- Ensure all data is loaded safely when the plugin starts.
- Avoid data loss when players disconnect, teams change, or the server shuts down.
**Technical Requirements**
- Build the plugin specifically for Paper 1.21.11.
- Use reliable Bukkit/Paper APIs and proper event listeners.
- Include a valid `plugin.yml` or equivalent supported plugin metadata, all required source files, and a working build configuration.
- Register every command and tab completion correctly.
- Avoid deprecated or incompatible methods where possible.
- Make sure the plugin compiles without errors and does not produce console errors during normal operation.
- Do not leave any commands, GUI buttons, or features unfinished.
Before finishing, test the team creation process, invitations, GUI interactions, team name displays, alliance requests, ownership permissions, data persistence, and all friendly-fire protection scenarios.
The final result must be a working `.jar` plugin that I can put directly into my server's `plugins` folder, along with the source code and any setup instructions needed to use it.