Skip to content

Commit a30a41a

Browse files
authored
Merge pull request #78 from FTBTeam/1.21.1/dev
1.21.1/dev
2 parents 611a0a3 + c712186 commit a30a41a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+870
-182
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2101.1.8]
8+
9+
### Added
10+
* Expanded the team properties system somewhat
11+
* New team property types: Big Integer, String set, and String to int/bool/string map
12+
* Added API to make it easier to register more custom property types if needed
13+
* Added new builtin "Team Stage" team property, a team-based game stages system
14+
715
## [2101.1.7]
816

917
### Added

common/src/main/java/dev/ftb/mods/ftbteams/FTBTeams.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import dev.architectury.utils.EnvExecutor;
1111
import dev.ftb.mods.ftblibrary.nbtedit.NBTEditResponseHandlers;
1212
import dev.ftb.mods.ftbteams.api.FTBTeamsAPI;
13-
import dev.ftb.mods.ftbteams.api.Team;
1413
import dev.ftb.mods.ftbteams.api.event.TeamCollectPropertiesEvent;
1514
import dev.ftb.mods.ftbteams.api.event.TeamEvent;
1615
import dev.ftb.mods.ftbteams.api.event.TeamManagerEvent;
@@ -19,12 +18,10 @@
1918
import dev.ftb.mods.ftbteams.data.AbstractTeam;
2019
import dev.ftb.mods.ftbteams.data.FTBTeamsCommands;
2120
import dev.ftb.mods.ftbteams.data.TeamManagerImpl;
22-
import dev.ftb.mods.ftbteams.data.TeamType;
2321
import dev.ftb.mods.ftbteams.net.FTBTeamsNet;
2422
import net.minecraft.commands.CommandBuildContext;
2523
import net.minecraft.commands.CommandSourceStack;
2624
import net.minecraft.commands.Commands;
27-
import net.minecraft.nbt.CompoundTag;
2825
import net.minecraft.network.chat.Component;
2926
import net.minecraft.server.MinecraftServer;
3027
import net.minecraft.server.level.ServerLevel;
@@ -92,6 +89,7 @@ private void teamConfig(TeamCollectPropertiesEvent event) {
9289
event.add(TeamProperties.COLOR);
9390
event.add(TeamProperties.FREE_TO_JOIN);
9491
event.add(TeamProperties.MAX_MSG_HISTORY_SIZE);
92+
event.add(TeamProperties.TEAM_STAGES);
9593
}
9694

9795
private void playerLoggedIn(ServerPlayer player) {

common/src/main/java/dev/ftb/mods/ftbteams/api/FTBTeamsAPI.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
import java.util.UUID;
1111

12-
/**
13-
* @author LatvianModder
14-
*/
1512
public class FTBTeamsAPI {
1613
public static final String MOD_ID = "ftbteams";
1714
public static final String MOD_NAME = "FTB Teams";

common/src/main/java/dev/ftb/mods/ftbteams/api/Team.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.ftb.mods.ftbteams.api.property.TeamPropertyCollection;
77
import net.minecraft.nbt.CompoundTag;
88
import net.minecraft.network.chat.Component;
9+
import net.minecraft.server.MinecraftServer;
910
import net.minecraft.server.level.ServerPlayer;
1011
import org.jetbrains.annotations.Nullable;
1112

@@ -236,4 +237,25 @@ default boolean isClientTeam() {
236237
* @return the newly-created party team
237238
*/
238239
Team createParty(String description, @Nullable Color4I color);
240+
241+
/**
242+
* Synchronise the value of one team property for this team to all players on the server. This method does nothing
243+
* if the property was not declared syncable (via {@link TeamProperty#syncToAll()}), or if called on the client.
244+
*
245+
* @param server the server
246+
* @param property the property to sync
247+
* @param value the value to sync
248+
* @param <T> the property type
249+
*/
250+
<T> void syncOnePropertyToAll(MinecraftServer server, TeamProperty<T> property, T value);
251+
252+
/**
253+
* Synchronise the value of one team property for this team to all online players on this team. This method does nothing
254+
* if called on the client.
255+
*
256+
* @param property the property to sync
257+
* @param value the value to sync
258+
* @param <T> the property type
259+
*/
260+
<T> void syncOnePropertyToTeam(TeamProperty<T> property, T value);
239261
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package dev.ftb.mods.ftbteams.api;
2+
3+
import dev.ftb.mods.ftbteams.api.event.TeamEvent;
4+
import dev.ftb.mods.ftbteams.api.event.TeamPropertiesChangedEvent;
5+
import dev.ftb.mods.ftbteams.api.property.TeamProperties;
6+
import dev.ftb.mods.ftbteams.api.property.TeamPropertyCollection;
7+
8+
import java.util.Collection;
9+
import java.util.Collections;
10+
import java.util.List;
11+
import java.util.Set;
12+
13+
/**
14+
* Utility class providing some convenience methods for querying and adjust the team stages for a team. These methods
15+
* all handle client sync and team data serialization internally.
16+
* <p>
17+
* Modifying a team's stages also causes a {@link TeamPropertiesChangedEvent} event to be fired.
18+
*/
19+
public class TeamStagesHelper {
20+
/**
21+
* Add one team stage to a team.
22+
*
23+
* @param team the team
24+
* @param stage the stage to add
25+
* @return true if the stage was added, false if the team already had the stage
26+
*/
27+
public static boolean addTeamStage(Team team, String stage) {
28+
return addTeamStages(team, List.of(stage)) == 1;
29+
}
30+
31+
/**
32+
* Add multiple team stages to a team. It is much more efficient to use this method rather than repeated calls to
33+
* {@link #addTeamStage(Team, String)} when adding multiple stages.
34+
*
35+
* @param team the team
36+
* @param stages the stages to add
37+
* @return the number of stages actually added
38+
*/
39+
public static int addTeamStages(Team team, Collection<String> stages) {
40+
return updateStages(team, stages, true);
41+
}
42+
43+
/**
44+
* Remove one team stage from a team.
45+
*
46+
* @param team the team
47+
* @param stage the stage to add
48+
* @return true if the stage was remove, false if the team did not have the stage
49+
*/
50+
public static boolean removeTeamStage(Team team, String stage) {
51+
return removeTeamStages(team, List.of(stage)) == 1;
52+
}
53+
54+
/**
55+
* Removing multiple team stages from a team. It is much more efficient to use this method rather than repeated calls to
56+
* {@link #removeTeamStage(Team, String)} when removing multiple stages.
57+
*
58+
* @param team the team
59+
* @param stages the stages to add
60+
* @return the number of stages actually removed
61+
*/
62+
public static int removeTeamStages(Team team, Collection<String> stages) {
63+
return updateStages(team, stages, false);
64+
}
65+
66+
/**
67+
* Check if a team has a particular stage.
68+
*
69+
* @param team the team
70+
* @param stage the stage to check
71+
* @return true if the team has the stage, false otherwise
72+
*/
73+
public static boolean hasTeamStage(Team team, String stage) {
74+
return team.getProperty(TeamProperties.TEAM_STAGES).contains(stage);
75+
}
76+
77+
/**
78+
* Get all the stages for a team.
79+
*
80+
* @param team the team
81+
* @return an unmodifiable collection of the team's stages
82+
*/
83+
public static Collection<String> getStages(Team team) {
84+
return Collections.unmodifiableSet(team.getProperty(TeamProperties.TEAM_STAGES));
85+
}
86+
87+
private static int updateStages(Team team, Collection<String> stages, boolean adding) {
88+
Set<String> stageSet = team.getProperty(TeamProperties.TEAM_STAGES);
89+
int changed = (int) stages.stream().filter(stage -> adding && stageSet.add(stage) || !adding && stageSet.remove(stage)).count();
90+
if (changed > 0) {
91+
team.setProperty(TeamProperties.TEAM_STAGES, stageSet);
92+
93+
TeamPropertyCollection old = team.getProperties().copy();
94+
TeamEvent.PROPERTIES_CHANGED.invoker().accept(new TeamPropertiesChangedEvent(team, old));
95+
team.syncOnePropertyToTeam(TeamProperties.TEAM_STAGES, stageSet);
96+
}
97+
98+
return changed;
99+
}
100+
}

common/src/main/java/dev/ftb/mods/ftbteams/api/client/ClientTeamManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.UUID;
1111

1212
/**
13-
* Used to track known teams and player on each client in the game. You can retrieve an instance of this via
13+
* Used to track known teams and players on each client in the game. You can retrieve an instance of this via
1414
* {@link FTBTeamsAPI.API#getClientManager()}.
1515
*/
1616
public interface ClientTeamManager {

common/src/main/java/dev/ftb/mods/ftbteams/api/event/ClientTeamPropertiesChangedEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import dev.ftb.mods.ftbteams.api.Team;
44
import dev.ftb.mods.ftbteams.api.property.TeamPropertyCollection;
55

6-
/**
7-
* @author LatvianModder
8-
*/
96
public class ClientTeamPropertiesChangedEvent {
107
private final Team team;
118
private final TeamPropertyCollection old;

common/src/main/java/dev/ftb/mods/ftbteams/api/event/PlayerChangedTeamEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import java.util.Optional;
88
import java.util.UUID;
99

10-
/**
11-
* @author LatvianModder
12-
*/
1310
public class PlayerChangedTeamEvent extends TeamEvent {
1411
private final Team previousTeam;
1512
private final UUID playerId;

common/src/main/java/dev/ftb/mods/ftbteams/api/event/PlayerJoinedPartyTeamEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import net.minecraft.server.level.ServerPlayer;
55
import org.jetbrains.annotations.NotNull;
66

7-
/**
8-
* @author LatvianModder
9-
*/
107
public class PlayerJoinedPartyTeamEvent extends TeamEvent {
118
private final Team previousTeam;
129
private final ServerPlayer player;

common/src/main/java/dev/ftb/mods/ftbteams/api/event/PlayerLeftPartyTeamEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
import java.util.UUID;
88

9-
/**
10-
* @author LatvianModder
11-
*/
129
public class PlayerLeftPartyTeamEvent extends TeamEvent {
1310
private final Team playerTeam;
1411
private final UUID playerId;

0 commit comments

Comments
 (0)