Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store in transit resourcepack for firing the ResourcePackStatusEvent #3759

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public interface ServerGamePacketListenerImplBridge {

@Nullable ResourcePack bridge$popAcceptedResourcePack();

void bridge$resendLatestResourcePackRequest();

void bridge$captureCurrentPlayerPosition();

void bridge$setLastMoveLocation(ServerLocation location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.spongepowered.common.event.tracking.phase.packet.player;

import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.entity.living.player.ResourcePackStatusEvent;
Expand All @@ -46,7 +47,7 @@ public void unwind(BasicPacketContext phaseContext) {
final ServerGamePacketListenerImplBridge mixinHandler = (ServerGamePacketListenerImplBridge) connection;
final ServerboundResourcePackPacketAccessor resource = phaseContext.getPacket();
final ResourcePackStatusEvent.ResourcePackStatus status;
ResourcePack pack;
@Nullable ResourcePack pack;
switch (resource.accessor$action()) {
case ACCEPTED:
pack = mixinHandler.bridge$popReceivedResourcePack(true);
Expand All @@ -67,11 +68,17 @@ public void unwind(BasicPacketContext phaseContext) {
default:
throw new AssertionError();
}

if (pack == null) {
return;
}
SpongeCommon.post(
SpongeEventFactory.createResourcePackStatusEvent(PhaseTracker.getCauseStackManager().currentCause(), pack, (ServerPlayer) player, status));

SpongeCommon.post(SpongeEventFactory.createResourcePackStatusEvent(
PhaseTracker.getCauseStackManager().currentCause(),
pack,
(ServerPlayer) player,
status
));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketUtils;
import net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket;
import net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket;
import net.minecraft.network.protocol.game.ClientboundMoveVehiclePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
import net.minecraft.network.protocol.game.ClientboundResourcePackPacket;
import net.minecraft.network.protocol.game.ServerGamePacketListener;
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.network.protocol.game.ServerboundResourcePackPacket;
import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket;
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -88,6 +92,7 @@
import org.spongepowered.api.event.entity.living.AnimateHandEvent;
import org.spongepowered.api.event.message.PlayerChatEvent;
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
import org.spongepowered.api.resourcepack.ResourcePack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -103,6 +108,7 @@
import org.spongepowered.common.accessor.server.level.ServerPlayerGameModeAccessor;
import org.spongepowered.common.adventure.SpongeAdventure;
import org.spongepowered.common.bridge.network.ConnectionHolderBridge;
import org.spongepowered.common.bridge.network.protocol.game.ClientboundResourcePackPacketBridge;
import org.spongepowered.common.bridge.server.level.ServerPlayerBridge;
import org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge;
import org.spongepowered.common.command.manager.SpongeCommandManager;
Expand Down Expand Up @@ -152,6 +158,8 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerGamePac

private int impl$ignorePackets;

@Nullable private ResourcePack impl$lastReceivedPack, impl$lastAcceptedPack;

@Override
public Connection bridge$getConnection() {
return this.connection;
Expand All @@ -164,6 +172,9 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerGamePac
private void impl$onClientboundPacketSend(final Packet<?> packet, final GenericFutureListener<? extends Future<? super Void>> listener, final CallbackInfo ci) {
if (packet instanceof ClientboundPlayerInfoPacket) {
((SpongeTabList) ((ServerPlayer) this.player).tabList()).updateEntriesOnSend((ClientboundPlayerInfoPacket) packet);
} else if (packet instanceof ClientboundResourcePackPacket) {
final ResourcePack pack = ((ClientboundResourcePackPacketBridge) packet).bridge$getSpongePack();
this.impl$lastReceivedPack = pack;
}
}

Expand Down Expand Up @@ -580,5 +591,25 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerGamePac
}
}

@Inject(method = "handleResourcePackResponse", at = @At("HEAD"))
public void impl$handleResourcePackResponse(final ServerboundResourcePackPacket packet, final CallbackInfo callbackInfo) {
PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListener) this, this.player.getLevel());
}

@Override
public @Nullable ResourcePack bridge$popReceivedResourcePack(final boolean markAccepted) {
final ResourcePack pack = this.impl$lastReceivedPack;
this.impl$lastReceivedPack = null;
if (markAccepted) {
this.impl$lastAcceptedPack = pack;
}
return pack;
}

@Override
public @Nullable ResourcePack bridge$popAcceptedResourcePack() {
final ResourcePack pack = this.impl$lastAcceptedPack;
this.impl$lastAcceptedPack = null;
return pack;
}
}