Skip to content

Commit

Permalink
Go back to old tracking system for teams as it was causing auto-craft…
Browse files Browse the repository at this point in the history
…ing issues
  • Loading branch information
62832 committed May 4, 2024
1 parent e73188e commit 865ea65
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cn.leomc.teamprojecte.TeamChangeEvent;
import cn.leomc.teamprojecte.TeamKnowledgeProvider;
import moze_intel.projecte.api.capabilities.IKnowledgeProvider;
import moze_intel.projecte.api.proxy.ITransmutationProxy;

class TeamProjectEHandler {
private final Map<UUID, TPTeam> playersInSharingTeams = new HashMap<>();
Expand All @@ -32,9 +33,9 @@ private boolean notSharingEmc(Map.Entry<UUID, Supplier<IKnowledgeProvider>> prov
var uuid = provider.getKey();
var team = TPTeam.getOrCreateTeam(uuid);

if (team.isSharingEMC() && (!playersInSharingTeams.containsValue(team) || !providersToKeep.containsKey(team))) {
if (team.isSharingEMC() && (!playersInSharingTeams.containsValue(team))) {
playersInSharingTeams.put(uuid, team);
providersToKeep.put(team, provider.getValue());
providersToKeep.putIfAbsent(team, provider.getValue());
return true;
}

Expand All @@ -50,7 +51,9 @@ private void removeTeamReference(UUID member) {
}

private void onTeamChange(TeamChangeEvent event) {
providersToKeep.remove(playersInSharingTeams.remove(event.getPlayerUUID()));
var uuid = event.getPlayerUUID();
providersToKeep.remove(playersInSharingTeams.remove(uuid));

var team = event.getTeam();

if (team != null && !team.isSharingEMC()) {
Expand All @@ -59,6 +62,16 @@ private void onTeamChange(TeamChangeEvent event) {
.forEach(entry -> playersInSharingTeams.remove(entry.getKey()));
providersToKeep.remove(team);
}

var newTeam = event.getNewTeam();

if (newTeam != null && uuid != null) {
playersInSharingTeams.put(uuid, newTeam);

if (newTeam.isSharingEMC()) {
providersToKeep.putIfAbsent(newTeam, () -> ITransmutationProxy.INSTANCE.getKnowledgeProviderFor(uuid));
}
}
}

private void onServerStop(ServerStoppedEvent event) {
Expand Down

0 comments on commit 865ea65

Please sign in to comment.