Paper/patches/server/0064-Complete-resource-pack-API.patch
2023-09-21 20:17:35 -07:00

85 lines
4.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
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 b9062fe651de34d5b3f9d5f146ae0b4fe29cbfee..e8b12a8ae009023afa2818ecbf398a1440b9926e 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());
this.disconnect(Component.translatable("multiplayer.requiredTexturePrompt.disconnect"));
}
- this.cserver.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getCraftPlayer(), PlayerResourcePackStatusEvent.Status.values()[packet.getAction().ordinal()])); // CraftBukkit
+ // Paper start
+ PlayerResourcePackStatusEvent.Status packStatus = PlayerResourcePackStatusEvent.Status.values()[packet.getAction().ordinal()];
+ player.getBukkitEntity().setResourcePackStatus(packStatus);
+ this.cserver.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getCraftPlayer(), 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 c30d2987f4afce8737c5c67b193d9ee3b6e230be..de5d17be3d7dcd9ae1f10918c3d6a3caffe7ef23 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -191,6 +191,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);
@@ -2326,6 +2330,45 @@ 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 ClientboundResourcePackPacket(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