Skip to content

Commit 91371ad

Browse files
committed
chore: small code cleanup in ClientTeamManagerImpl
1 parent dc641f0 commit 91371ad

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

common/src/main/java/dev/ftb/mods/ftbteams/client/FTBTeamsClient.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,23 @@ public static void openMyTeamGui(TeamPropertyCollection properties, PlayerPermis
5959
}
6060

6161
public static void updateSettings(UUID id, TeamPropertyCollection properties) {
62-
if (ClientTeamManagerImpl.getInstance() == null) {
63-
return;
64-
}
65-
66-
ClientTeamManagerImpl.getInstance().getTeam(id)
67-
.ifPresent(team -> team.updateProperties(properties));
62+
ClientTeamManagerImpl.ifPresent(mgr -> mgr.getTeam(id).ifPresent(team -> team.updateProperties(properties)));
6863
}
6964

7065
public static void sendMessage(UUID from, Component text) {
71-
if (ClientTeamManagerImpl.getInstance() == null) {
72-
return;
73-
}
74-
75-
TeamMessage msg = FTBTeamsAPI.api().createMessage(from, text);
76-
ClientTeamManagerImpl.getInstance().selfTeam().addMessage(msg);
66+
ClientTeamManagerImpl.ifPresent(mgr -> {
67+
TeamMessage msg = FTBTeamsAPI.api().createMessage(from, text);
68+
mgr.selfTeam().addMessage(msg);
7769

78-
MyTeamScreen screen = ClientUtils.getCurrentGuiAs(MyTeamScreen.class);
79-
if (screen != null) {
80-
screen.refreshChat();
81-
}
70+
MyTeamScreen screen = ClientUtils.getCurrentGuiAs(MyTeamScreen.class);
71+
if (screen != null) {
72+
screen.refreshChat();
73+
}
74+
});
8275
}
8376

8477
public static void updatePresence(KnownClientPlayer update) {
85-
if (ClientTeamManagerImpl.getInstance() != null) {
86-
ClientTeamManagerImpl.getInstance().updatePresence(update);
87-
}
78+
ClientTeamManagerImpl.ifPresent(mgr -> mgr.updatePresence(update));
8879
}
8980

9081
public static void setChatRedirected(boolean chatRedirected) {

common/src/main/java/dev/ftb/mods/ftbteams/data/ClientTeamManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.jetbrains.annotations.Nullable;
1818

1919
import java.util.*;
20+
import java.util.function.Consumer;
2021

2122
/**
2223
* Represents the teams and known players that the client knows about; one global instance exists on the client.
@@ -47,6 +48,10 @@ public static ClientTeamManagerImpl getInstance() {
4748
return INSTANCE;
4849
}
4950

51+
public static void ifPresent(Consumer<ClientTeamManagerImpl> mgr) {
52+
if (INSTANCE != null) mgr.accept(INSTANCE);
53+
}
54+
5055
private ClientTeamManagerImpl(UUID managerId) {
5156
this(managerId, new HashMap<>(), new HashMap<>());
5257
}

0 commit comments

Comments
 (0)