Skip to content

Commit 2979cbd

Browse files
authored
Merge pull request #299 from KosmX/login_emote_sync
Login emote sync + another forge API crash fix
2 parents 3d9cea0 + b37a07d commit 2979cbd

File tree

12 files changed

+66
-7
lines changed

12 files changed

+66
-7
lines changed

16/archCommon/src/main/java/io/github/kosmx/emotes/arch/executor/types/GettersImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class GettersImpl implements IGetters {
1010
@Override
1111
public IEmotePlayerEntity getPlayerFromUUID(UUID uuid) {
12+
if (Minecraft.getInstance().level == null) return null;
1213
return (IEmotePlayerEntity) Minecraft.getInstance().level.getPlayerByUUID(uuid);
1314
}
1415
}

16/fabric/src/main/java/io/github/kosmx/emotes/fabric/mixin/ServerPlayNetworkInstance.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import io.github.kosmx.emotes.server.network.EmotePlayTracker;
88
import io.github.kosmx.emotes.server.network.IServerNetworkInstance;
99
import io.netty.buffer.Unpooled;
10+
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
1011
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
1112
import net.minecraft.network.FriendlyByteBuf;
1213
import net.minecraft.network.protocol.Packet;
14+
import net.minecraft.server.level.ServerPlayer;
1315
import net.minecraft.server.network.ServerGamePacketListenerImpl;
1416
import org.jetbrains.annotations.Nullable;
1517
import org.spongepowered.asm.mixin.Mixin;
@@ -24,6 +26,7 @@ public abstract class ServerPlayNetworkInstance implements IServerNetworkInstanc
2426
private final EmotePlayTracker emoteTracker = new EmotePlayTracker();
2527
@Shadow public abstract void send(Packet<?> packet);
2628

29+
@Shadow public ServerPlayer player;
2730
HashMap<Byte, Byte> versions = new HashMap<>();
2831
@Override
2932
public HashMap<Byte, Byte> getRemoteVersions() {
@@ -65,6 +68,14 @@ public void sendConfigCallback() {
6568
}
6669
}
6770

71+
@Override
72+
public void presenceResponse() {
73+
IServerNetworkInstance.super.presenceResponse();
74+
for (ServerPlayer player : PlayerLookup.tracking(this.player)) {
75+
ServerNetwork.getInstance().playerStartTracking(player, this.player);
76+
}
77+
}
78+
6879
@Override
6980
public boolean isActive() {
7081
return false;

16/forge/src/main/java/io/github/kosmx/emotes/forge/mixin/ServerPlayNetworkInstance.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public void sendConfigCallback() {
6262
}
6363
}
6464

65+
@Override
66+
public void presenceResponse() {
67+
IServerNetworkInstance.super.presenceResponse();
68+
ServerNetwork.sendConsumer(this.player, otherPlayer -> ServerNetwork.getInstance().playerStartTracking(otherPlayer, ServerPlayNetworkInstance.this.player));
69+
}
70+
6571
@Override
6672
public boolean isActive() {
6773
return false;

16/forge/src/main/java/io/github/kosmx/emotes/forge/network/ServerNetwork.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ protected void sendForPlayer(NetData data, Player player, UUID target) {
174174
try {
175175
PacketDistributor.PLAYER.with(() -> (ServerPlayer) player.getCommandSenderWorld().getPlayerByUUID(target)).send(newS2CEmotesPacket(data, (ServerPlayer) player));
176176
}
177-
catch (IOException e){
177+
catch (IOException|RuntimeException e){
178178
e.printStackTrace();
179179
}
180180
}
181181

182-
private void sendConsumer(Player player, Consumer<ServerPlayer> consumer){
182+
public static void sendConsumer(Player player, Consumer<ServerPlayer> consumer){
183183
TrackedEntityAccessor tracker = ((ChunkMapAccessor)((ServerChunkCache)player.getCommandSenderWorld().getChunkSource()).chunkMap).getTrackedEntity().get(player.getId());
184-
tracker.getPlayersTracking().stream().forEach(consumer);
184+
tracker.getPlayersTracking().forEach(consumer);
185185
}
186186
}

18/archCommon/src/main/java/io/github/kosmx/emotes/arch/executor/types/GettersImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class GettersImpl implements IGetters {
1010
@Override
1111
public IEmotePlayerEntity getPlayerFromUUID(UUID uuid) {
12+
if (Minecraft.getInstance().level == null) return null;
1213
return (IEmotePlayerEntity) Minecraft.getInstance().level.getPlayerByUUID(uuid);
1314
}
1415
}

18/fabric/src/main/java/io/github/kosmx/emotes/fabric/mixin/ServerPlayNetworkInstance.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import io.github.kosmx.emotes.server.network.EmotePlayTracker;
88
import io.github.kosmx.emotes.server.network.IServerNetworkInstance;
99
import io.netty.buffer.Unpooled;
10+
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
1011
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
1112
import net.minecraft.network.FriendlyByteBuf;
1213
import net.minecraft.network.protocol.Packet;
14+
import net.minecraft.server.level.ServerPlayer;
1315
import net.minecraft.server.network.ServerGamePacketListenerImpl;
1416
import org.jetbrains.annotations.Nullable;
1517
import org.spongepowered.asm.mixin.Mixin;
@@ -25,6 +27,8 @@ public abstract class ServerPlayNetworkInstance implements IServerNetworkInstanc
2527
private final EmotePlayTracker emoteTracker = new EmotePlayTracker();
2628
@Shadow public abstract void send(Packet<?> packet);
2729

30+
@Shadow public abstract ServerPlayer getPlayer();
31+
2832
HashMap<Byte, Byte> versions = new HashMap<>();
2933
@Override
3034
public HashMap<Byte, Byte> getRemoteVersions() {
@@ -66,6 +70,14 @@ public void sendConfigCallback() {
6670
}
6771
}
6872

73+
@Override
74+
public void presenceResponse() {
75+
IServerNetworkInstance.super.presenceResponse();
76+
for (ServerPlayer player : PlayerLookup.tracking(this.getPlayer())) {
77+
ServerNetwork.getInstance().playerStartTracking(player, this.getPlayer());
78+
}
79+
}
80+
6981
@Override
7082
public boolean isActive() {
7183
return true;

18/forge/src/main/java/io/github/kosmx/emotes/forge/mixin/ServerPlayNetworkInstance.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public void sendConfigCallback() {
6767
}
6868
}
6969

70+
@Override
71+
public void presenceResponse() {
72+
IServerNetworkInstance.super.presenceResponse();
73+
ServerNetwork.sendConsumer(this.player, otherPlayer -> ServerNetwork.getInstance().playerStartTracking(otherPlayer, ServerPlayNetworkInstance.this.player));
74+
}
75+
7076
@Override
7177
public boolean isActive() {
7278
return false;

18/forge/src/main/java/io/github/kosmx/emotes/forge/network/ServerNetwork.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ protected void sendForPlayer(NetData data, Player player, UUID target) {
174174
try {
175175
PacketDistributor.PLAYER.with(() -> (ServerPlayer) player.getCommandSenderWorld().getPlayerByUUID(target)).send(newS2CEmotesPacket(data, (ServerPlayer) player));
176176
}
177-
catch (IOException e){
177+
catch (IOException|RuntimeException e){
178178
e.printStackTrace();
179179
}
180180
}
181181

182-
private void sendConsumer(Player player, Consumer<ServerPlayer> consumer){
182+
public static void sendConsumer(Player player, Consumer<ServerPlayer> consumer){
183183
TrackedEntityAccessor tracker = ((ChunkMapAccessor)((ServerChunkCache)player.getCommandSenderWorld().getChunkSource()).chunkMap).getTrackedEntity().get(player.getId());
184184
tracker.getPlayersTracking().forEach(serverPlayerConnection -> consumer.accept(serverPlayerConnection.getPlayer()));
185185
}

19/archCommon/src/main/java/io/github/kosmx/emotes/arch/executor/types/GettersImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class GettersImpl implements IGetters {
1010
@Override
1111
public IEmotePlayerEntity getPlayerFromUUID(UUID uuid) {
12+
if (Minecraft.getInstance().level == null) return null;
1213
return (IEmotePlayerEntity) Minecraft.getInstance().level.getPlayerByUUID(uuid);
1314
}
1415
}

19/fabric/src/main/java/io/github/kosmx/emotes/fabric/mixin/ServerPlayNetworkInstance.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import io.github.kosmx.emotes.server.network.EmotePlayTracker;
88
import io.github.kosmx.emotes.server.network.IServerNetworkInstance;
99
import io.netty.buffer.Unpooled;
10+
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
1011
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
1112
import net.minecraft.network.FriendlyByteBuf;
1213
import net.minecraft.network.protocol.Packet;
14+
import net.minecraft.server.level.ServerPlayer;
1315
import net.minecraft.server.network.ServerGamePacketListenerImpl;
1416
import org.jetbrains.annotations.Nullable;
1517
import org.spongepowered.asm.mixin.Mixin;
@@ -25,6 +27,8 @@ public abstract class ServerPlayNetworkInstance implements IServerNetworkInstanc
2527
private final EmotePlayTracker emoteTracker = new EmotePlayTracker();
2628
@Shadow public abstract void send(Packet<?> packet);
2729

30+
@Shadow public abstract ServerPlayer getPlayer();
31+
2832
HashMap<Byte, Byte> versions = new HashMap<>();
2933
@Override
3034
public HashMap<Byte, Byte> getRemoteVersions() {
@@ -66,6 +70,14 @@ public void sendConfigCallback() {
6670
}
6771
}
6872

73+
@Override
74+
public void presenceResponse() {
75+
IServerNetworkInstance.super.presenceResponse();
76+
for (ServerPlayer player : PlayerLookup.tracking(this.getPlayer())) {
77+
ServerNetwork.getInstance().playerStartTracking(player, this.getPlayer());
78+
}
79+
}
80+
6981
@Override
7082
public boolean isActive() {
7183
return true;

0 commit comments

Comments
 (0)