This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Complete resource pack API
- Loading branch information
Showing
3 changed files
with
279 additions
and
1 deletion.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| From dfe7295982f90c3da7a0b30a085b8de585fc6ba5 Mon Sep 17 00:00:00 2001 | ||
| From: Jedediah Smith <jedediah@silencegreys.com> | ||
| Date: Sat, 4 Apr 2015 22:59:54 -0400 | ||
| Subject: [PATCH] Complete resource pack API | ||
|
|
||
|
|
||
| diff --git a/src/main/java/org/bukkit/ResourcePackStatus.java b/src/main/java/org/bukkit/ResourcePackStatus.java | ||
| new file mode 100644 | ||
| index 0000000..8d1c420 | ||
| --- /dev/null | ||
| +++ b/src/main/java/org/bukkit/ResourcePackStatus.java | ||
| @@ -0,0 +1,18 @@ | ||
| +package org.bukkit; | ||
| + | ||
| +/** | ||
| + * These are the responses a player can send when asked to use a custom | ||
| + * resource pack. | ||
| + * | ||
| + * When the player accepts or declines a resource pack, the client will | ||
| + * immediately send the {@link #ACCEPTED} or {@link #DECLINED} status to | ||
| + * the server. If the player accepts, the client will download the resource | ||
| + * pack, install it, and then send the {@link #LOADED} status. If anything | ||
| + * fails, it will send the {@link #FAILED} status. | ||
| + * | ||
| + * If the player already has a saved decision, the same status responses | ||
| + * are sent, starting immediately when the client receives the resource pack. | ||
| + */ | ||
| +public enum ResourcePackStatus { | ||
| + ACCEPTED, DECLINED, LOADED, FAILED | ||
| +} | ||
| diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java | ||
| index e4e9efc..b105165 100644 | ||
| --- a/src/main/java/org/bukkit/entity/Player.java | ||
| +++ b/src/main/java/org/bukkit/entity/Player.java | ||
| @@ -11,6 +11,7 @@ import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.Note; | ||
| import org.bukkit.OfflinePlayer; | ||
| +import org.bukkit.ResourcePackStatus; | ||
| import org.bukkit.Skin; | ||
| import org.bukkit.Sound; | ||
| import org.bukkit.Statistic; | ||
| @@ -1129,13 +1130,36 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline | ||
| * @param url The URL from which the client will download the resource | ||
| * pack. The string must contain only US-ASCII characters and should | ||
| * be encoded as per RFC 1738. | ||
| + * @param hash A 40 character hexadecimal and lowercase SHA-1 digest of | ||
| + * the resource pack file. | ||
| * @throws IllegalArgumentException Thrown if the URL is null. | ||
| * @throws IllegalArgumentException Thrown if the URL is too long. The | ||
| * length restriction is an implementation specific arbitrary value. | ||
| */ | ||
| + public void setResourcePack(String url, String hash); | ||
| + | ||
| + @Deprecated | ||
| public void setResourcePack(String url); | ||
|
|
||
| /** | ||
| + * @return the most recent resource pack status received from the player, | ||
| + * or null if no status has ever been received from this player. | ||
| + */ | ||
| + public ResourcePackStatus getResourcePackStatus(); | ||
| + | ||
| + /** | ||
| + * @return the most recent resource pack hash received from the player, | ||
| + * or null if no hash has ever been received from this player. | ||
| + */ | ||
| + public String getResourcePackHash(); | ||
| + | ||
| + /** | ||
| + * @return true if the last resource pack status received from this player | ||
| + * was {@link ResourcePackStatus#LOADED} | ||
| + */ | ||
| + public boolean hasResourcePack(); | ||
| + | ||
| + /** | ||
| * Gets the Scoreboard displayed to this player | ||
| * | ||
| * @return The current scoreboard seen by this player | ||
| diff --git a/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java b/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java | ||
| new file mode 100644 | ||
| index 0000000..e87d824 | ||
| --- /dev/null | ||
| +++ b/src/main/java/org/bukkit/event/player/PlayerResourcePackStatusEvent.java | ||
| @@ -0,0 +1,43 @@ | ||
| +package org.bukkit.event.player; | ||
| + | ||
| +import org.bukkit.ResourcePackStatus; | ||
| +import org.bukkit.entity.Player; | ||
| +import org.bukkit.event.HandlerList; | ||
| + | ||
| +/** | ||
| + * This event is fired when a player sends their resource pack status | ||
| + * to the server, in response to the server asking them to use a custom | ||
| + * resource pack e.g. with {@link Player#setResourcePack}. | ||
| + * | ||
| + * See {@link ResourcePackStatus} for details about the process. | ||
| + */ | ||
| +public class PlayerResourcePackStatusEvent extends PlayerEvent { | ||
| + | ||
| + private final ResourcePackStatus status; | ||
| + private final String hash; | ||
| + | ||
| + public PlayerResourcePackStatusEvent(Player who, ResourcePackStatus status, String hash) { | ||
| + super(who); | ||
| + this.status = status; | ||
| + this.hash = hash; | ||
| + } | ||
| + | ||
| + public ResourcePackStatus getStatus() { | ||
| + return status; | ||
| + } | ||
| + | ||
| + public String getHash() { | ||
| + return hash; | ||
| + } | ||
| + | ||
| + private static final HandlerList handlers = new HandlerList(); | ||
| + | ||
| + @Override | ||
| + public HandlerList getHandlers() { | ||
| + return handlers; | ||
| + } | ||
| + | ||
| + public static HandlerList getHandlerList() { | ||
| + return handlers; | ||
| + } | ||
| +} | ||
| -- | ||
| 1.9.0 | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| From ca68849674c25dc62160d9a6e78fe36f98e2b36c 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/PacketPlayInResourcePackStatus.java b/src/main/java/net/minecraft/server/PacketPlayInResourcePackStatus.java | ||
| index 50f3adc..e3d1956 100644 | ||
| --- a/src/main/java/net/minecraft/server/PacketPlayInResourcePackStatus.java | ||
| +++ b/src/main/java/net/minecraft/server/PacketPlayInResourcePackStatus.java | ||
| @@ -2,8 +2,10 @@ package net.minecraft.server; | ||
|
|
||
| public class PacketPlayInResourcePackStatus implements Packet { | ||
|
|
||
| - private String a; | ||
| - private EnumResourcePackStatus b; | ||
| + // SportBukkit start - make public | ||
| + public String a; | ||
| + public EnumResourcePackStatus b; | ||
| + // SportBukkit end | ||
|
|
||
| public PacketPlayInResourcePackStatus() {} | ||
|
|
||
| diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java | ||
| index 9047814..24fa700 100644 | ||
| --- a/src/main/java/net/minecraft/server/PlayerConnection.java | ||
| +++ b/src/main/java/net/minecraft/server/PlayerConnection.java | ||
| @@ -55,6 +55,8 @@ import org.bukkit.event.player.PlayerTeleportEvent; | ||
| import org.bukkit.event.player.PlayerToggleFlightEvent; | ||
| import org.bukkit.event.player.PlayerToggleSneakEvent; | ||
| import org.bukkit.event.player.PlayerToggleSprintEvent; | ||
| +import org.bukkit.event.player.PlayerResourcePackStatusEvent; | ||
| +import org.bukkit.ResourcePackStatus; | ||
| import org.bukkit.inventory.CraftingInventory; | ||
| import org.bukkit.inventory.InventoryView; | ||
| import org.bukkit.util.NumberConversions; | ||
| @@ -842,7 +844,22 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList | ||
|
|
||
| } | ||
|
|
||
| - public void a(PacketPlayInResourcePackStatus packetplayinresourcepackstatus) {} | ||
| + // SportBukkit start | ||
| + public void a(PacketPlayInResourcePackStatus packetplayinresourcepackstatus) { | ||
| + PlayerConnectionUtils.ensureMainThread(packetplayinresourcepackstatus, this, this.player.u()); | ||
| + | ||
| + ResourcePackStatus status; | ||
| + switch(packetplayinresourcepackstatus.b) { | ||
| + case ACCEPTED: status = ResourcePackStatus.ACCEPTED; break; | ||
| + case DECLINED: status = ResourcePackStatus.DECLINED; break; | ||
| + case SUCCESSFULLY_LOADED: status = ResourcePackStatus.LOADED; break; | ||
| + default: status = ResourcePackStatus.FAILED; break; | ||
| + } | ||
| + | ||
| + this.getPlayer().setResourcePackStatus(status, packetplayinresourcepackstatus.a); | ||
| + this.server.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getPlayer(), status, packetplayinresourcepackstatus.a)); | ||
| + } | ||
| + // SportBukkit end | ||
|
|
||
| public void a(IChatBaseComponent ichatbasecomponent) { | ||
| // CraftBukkit start - Rarely it would send a disconnect line twice | ||
| diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
| index 359dd94..bf0354c 100644 | ||
| --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
| @@ -83,6 +83,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player { | ||
| private double healthScale = 20; | ||
| private Skin realSkin; | ||
| private boolean showInvisibles; | ||
| + private ResourcePackStatus resourcePackStatus; | ||
| + private String resourcePackHash; | ||
|
|
||
| private final Map<CommandSender, String> fakeNames = new WeakHashMap<CommandSender, String>(); | ||
| private final Map<CommandSender, String> fakeDisplayNames = new WeakHashMap<CommandSender, String>(); | ||
| @@ -1393,9 +1395,36 @@ public class CraftPlayer extends CraftHumanEntity implements Player { | ||
|
|
||
| @Override | ||
| public void setResourcePack(String url) { | ||
| + setResourcePack(url, "null"); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public void setResourcePack(String url, String hash) { | ||
| Validate.notNull(url, "Resource pack URL cannot be null"); | ||
| + Validate.notNull(hash, "Hash cannot be null"); | ||
| + Validate.isTrue(hash.matches("^[0-9a-f]{40}$"), "Hash must be a 40 character SHA-1 digest with lowercase letters"); | ||
| + | ||
| + getHandle().setResourcePack(url, hash); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public ResourcePackStatus getResourcePackStatus() { | ||
| + return resourcePackStatus; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public String getResourcePackHash() { | ||
| + return resourcePackHash; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public boolean hasResourcePack() { | ||
| + return this.resourcePackStatus == ResourcePackStatus.LOADED; | ||
| + } | ||
|
|
||
| - getHandle().setResourcePack(url, "null"); | ||
| + public void setResourcePackStatus(ResourcePackStatus status, String hash) { | ||
| + this.resourcePackStatus = status; | ||
| + this.resourcePackHash = hash; | ||
| } | ||
|
|
||
| public void addChannel(String channel) { | ||
| -- | ||
| 1.9.0 | ||
|
|