From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jedediah Smith Date: Sat, 4 Apr 2015 23:17:52 -0400 Subject: [PATCH] Complete resource pack API diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java index 56f6f65ceb1271e9273b1ee6658773eb3445beed..a26db4bd859ef52dadf03f1b62155bcc54b7a740 100644 --- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java @@ -156,7 +156,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), packet.id()); this.disconnect(Component.translatable("multiplayer.requiredTexturePrompt.disconnect")); } - this.cserver.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getCraftPlayer(), packet.id(), PlayerResourcePackStatusEvent.Status.values()[packet.action().ordinal()])); // CraftBukkit + // Paper start + PlayerResourcePackStatusEvent.Status packStatus = PlayerResourcePackStatusEvent.Status.values()[packet.action().ordinal()]; + player.getBukkitEntity().setResourcePackStatus(packStatus); + this.cserver.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getCraftPlayer(), packet.id(), packStatus)); // CraftBukkit + // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index a58b0d10d73310587a05e40e072029ee258063e1..6da1b2f54317ddc84a1fbff037560e402b02f771 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -44,6 +44,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.PlayerChatMessage; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket; import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; @@ -192,6 +193,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player { private double healthScale = 20; private CraftWorldBorder clientWorldBorder = null; private BorderChangeListener clientWorldBorderListener = this.createWorldBorderListener(); + // Paper start + private org.bukkit.event.player.PlayerResourcePackStatusEvent.Status resourcePackStatus; + private String resourcePackHash; + // Paper end public CraftPlayer(CraftServer server, ServerPlayer entity) { super(server, entity); @@ -2387,6 +2392,46 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public boolean getAffectsSpawning() { return this.getHandle().affectsSpawning; } + + @Override + public void setResourcePack(@NotNull String url, @NotNull String hash) { + this.setResourcePack(url, hash, false, null); + } + + @Override + public void setResourcePack(@NotNull String url, @NotNull String hash, boolean required) { + this.setResourcePack(url, hash, required, null); + } + + @Override + public void setResourcePack(@NotNull String url, @NotNull String hash, boolean required, net.kyori.adventure.text.Component resourcePackPrompt) { + Preconditions.checkArgument(url != null, "Resource pack URL cannot be null"); + Preconditions.checkArgument(hash != null, "Hash cannot be null"); + net.minecraft.network.chat.Component promptComponent = resourcePackPrompt != null ? + io.papermc.paper.adventure.PaperAdventure.asVanilla(resourcePackPrompt) : + null; + this.getHandle().connection.send(new ClientboundResourcePackPopPacket(Optional.empty())); + this.getHandle().connection.send(new ClientboundResourcePackPushPacket(UUID.randomUUID(), url, hash, required, promptComponent)); + } + + @Override + public org.bukkit.event.player.PlayerResourcePackStatusEvent.Status getResourcePackStatus() { + return this.resourcePackStatus; + } + + @Override + public String getResourcePackHash() { + return this.resourcePackHash; + } + + @Override + public boolean hasResourcePack() { + return this.resourcePackStatus == org.bukkit.event.player.PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED; + } + + public void setResourcePackStatus(org.bukkit.event.player.PlayerResourcePackStatusEvent.Status status) { + this.resourcePackStatus = status; + } // Paper end @Override