-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework the flow of events to ensure clients verify mods AFTER the ser…
…ver has sent them! (Fabric's server JOIN event fires too late so client needs a custom event to check after it)
- Loading branch information
Showing
10 changed files
with
158 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/sollace/fabwork/impl/ModEntriesUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.sollace.fabwork.impl; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import com.sollace.fabwork.api.ModEntry; | ||
|
||
public interface ModEntriesUtil { | ||
|
||
static Set<String> compare(Stream<ModEntryImpl> provided, List<ModEntryImpl> required) { | ||
return provided | ||
.map(ModEntry::modId) | ||
.filter(id -> required.stream().filter(cc -> cc.modId().equalsIgnoreCase(id)).findAny().isEmpty()) | ||
.distinct() | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
static Set<String> ids(List<ModEntryImpl> entries) { | ||
return entries.stream().map(ModEntry::modId).distinct().collect(Collectors.toSet()); | ||
} | ||
|
||
static String stringify(List<ModEntryImpl> entries) { | ||
String[] values = entries.stream().map(ModEntry::modId).toArray(String[]::new); | ||
return " [" + String.join(", ", values) + "] (" + values.length + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/sollace/fabwork/impl/event/ClientConnectionEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sollace.fabwork.impl.event; | ||
|
||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents.Join; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
|
||
public interface ClientConnectionEvents { | ||
/** | ||
* An event for notification when a player has successfully connected to the server. | ||
* <p> | ||
* This event is triggered after JOIN once initial game data has been sent to the client. | ||
*/ | ||
Event<Join> CONNECT = EventFactory.createArrayBacked(Join.class, callbacks -> (handler, sender, server) -> { | ||
for (Join callback : callbacks) { | ||
callback.onPlayReady(handler, sender, server); | ||
} | ||
}); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/sollace/fabwork/impl/event/ServerConnectionEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sollace.fabwork.impl.event; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents.Join; | ||
|
||
public interface ServerConnectionEvents { | ||
/** | ||
* An event for notification when a player has successfully connected to the server. | ||
* <p> | ||
* This event is triggered after JOIN but before the corresponding event packet is dispatched to the client. | ||
*/ | ||
Event<Join> CONNECT = EventFactory.createArrayBacked(Join.class, callbacks -> (handler, sender, server) -> { | ||
for (Join callback : callbacks) { | ||
callback.onPlayReady(handler, sender, server); | ||
} | ||
}); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/sollace/fabwork/impl/mixin/PlayerManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sollace.fabwork.impl.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.sollace.fabwork.impl.event.ServerConnectionEvents; | ||
|
||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; | ||
import net.minecraft.network.ClientConnection; | ||
import net.minecraft.server.PlayerManager; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
@Mixin(PlayerManager.class) | ||
abstract class PlayerManagerMixin { | ||
@Inject(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/SynchronizeTagsS2CPacket;<init>(Ljava/util/Map;)V")) | ||
private void handlePlayerConnection(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { | ||
ServerConnectionEvents.CONNECT.invoker().onPlayReady(player.networkHandler, ServerPlayNetworking.getSender(player), player.getServer()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/sollace/fabwork/impl/mixin/client/ClientPlayNetworkHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.sollace.fabwork.impl.mixin.client; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.sollace.fabwork.impl.event.ClientConnectionEvents; | ||
|
||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket; | ||
|
||
@Mixin(value = ClientPlayNetworkHandler.class, priority = 999) | ||
abstract class ClientPlayNetworkHandlerMixin { | ||
@Inject(method = "onSynchronizeRecipes", at = @At("RETURN")) | ||
private void onOnSynchronizeRecipes(SynchronizeRecipesS2CPacket packet, CallbackInfo cinfo) { | ||
final MinecraftClient client = MinecraftClient.getInstance(); | ||
ClientConnectionEvents.CONNECT.invoker().onPlayReady(client.player.networkHandler, ClientPlayNetworking.getSender(), client); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters