Skip to content

Commit

Permalink
Sync knowledge providers for other TPE team members as well
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jun 23, 2024
1 parent effd635 commit a4472e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
26 changes: 7 additions & 19 deletions src/main/java/gripe/_90/appliede/me/service/KnowledgeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.server.ServerLifecycleHooks;

import appeng.api.crafting.IPatternDetails;
import appeng.api.features.IPlayerRegistry;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridService;
Expand Down Expand Up @@ -110,34 +108,24 @@ public void onServerStartTick() {
}

if (needsSync && ticksSinceLastSync == TICKS_PER_SYNC) {
var server = ServerLifecycleHooks.getCurrentServer();

if (server != null) {
providers.forEach((uuid, provider) -> {
var id = IPlayerRegistry.getMapping(server).getPlayerId(uuid);
var player = IPlayerRegistry.getConnected(server, id);

if (player != null) {
provider.get().syncEmc(player);
}

tpeHandler.syncTeamProviders(uuid);
});
}

tpeHandler.syncTeamProviders(providers);
needsSync = false;
ticksSinceLastSync = 0;
}
}

private void addProvider(UUID playerUUID) {
providers.putIfAbsent(playerUUID, () -> {
providers.putIfAbsent(playerUUID, retrieveProvider(playerUUID));
}

static Supplier<IKnowledgeProvider> retrieveProvider(UUID playerUUID) {
return () -> {
try {
return ITransmutationProxy.INSTANCE.getKnowledgeProviderFor(playerUUID);
} catch (Throwable e) {
return TransmutationOfflineAccessor.invokeForPlayer(playerUUID);
}
});
};
}

List<IKnowledgeProvider> getProviders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package gripe._90.appliede.me.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.server.ServerLifecycleHooks;

import appeng.api.features.IPlayerRegistry;

import gripe._90.appliede.integration.Addons;

Expand Down Expand Up @@ -50,11 +54,22 @@ private Supplier<IKnowledgeProvider> getProviderFor(UUID uuid) {
return null;
}

private void syncTeamProviders(UUID uuid) {
for (var team : providersPerTeam.keySet()) {
if (team.getMembers().contains(uuid)) {
team.sync();
break;
private void syncTeamProviders() {
var server = ServerLifecycleHooks.getCurrentServer();

if (server != null) {
for (var team : providersPerTeam.keySet()) {
var members = new ArrayList<>(team.getMembers());
members.add(team.getOwner());

for (var member : members) {
var id = IPlayerRegistry.getMapping(server).getPlayerId(member);
var player = IPlayerRegistry.getConnected(server, id);

if (player != null) {
KnowledgeService.retrieveProvider(member).get().syncEmc(player);
}
}
}
}
}
Expand All @@ -78,9 +93,22 @@ Supplier<IKnowledgeProvider> getProviderFor(UUID uuid) {
return handler != null ? ((TeamProjectEHandler) handler).getProviderFor(uuid) : null;
}

void syncTeamProviders(UUID uuid) {
void syncTeamProviders(Map<UUID, Supplier<IKnowledgeProvider>> fallbackProviders) {
if (handler != null) {
((TeamProjectEHandler) handler).syncTeamProviders(uuid);
((TeamProjectEHandler) handler).syncTeamProviders();
} else {
var server = ServerLifecycleHooks.getCurrentServer();

if (server != null) {
fallbackProviders.forEach((uuid, provider) -> {
var id = IPlayerRegistry.getMapping(server).getPlayerId(uuid);
var player = IPlayerRegistry.getConnected(server, id);

if (player != null) {
provider.get().syncEmc(player);
}
});
}
}
}

Expand Down

0 comments on commit a4472e0

Please sign in to comment.