Setting Resource Pack

Discussion in 'Plugin Development' started by Agentleader1, Aug 5, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Agentleader1

    I've searched a lot of Google and was unable to find a solution to setting a player's resource pack and enforcing it. I saw a plugin do a Custom Payload packet but it uses packet data serializer. PDS requires a ByteBuf and that makes me feel unsafe. When I took a look at the implemented methods of ByteBuf, I was hecka screwed. How do I set a player's resource pack in 1.8+ (I'm using 1.8 Spigot Build Tools)?

    Also noticed it's possible to tell if someone has the resource pack on or not, I need to utilize that feature. How must I check for that as well?

    EDIT: Don't jump to the conclusion that this is all easy. It's really not for your reference. As well, I'm suspecting that you can track a response by plugin message listeners. Am I correct? If so, tell me, and as well what should I do in there?

    It appears I can not accomplish this action without the help of a protocol injector. Anyway I can create a protcol injector along with this?

    Thanks all.
     
    Last edited: Aug 5, 2015
  2. Offline

    meguy26

    @Agentleader1
    why not just use the default bukkit method? There is something in the player class for it.
     
  3. Offline

    Agentleader1

    @meguy26 I think I got the first part solved, as well; when I tried the default method (bukkit players), my friend didn't receive it. But that problem is pto ably now solved. As I need help making a protocol injector
     
  4. Offline

    meguy26

    @Agentleader1
    Couple things:
    1. The default method requires a direct download link
    2. The default method does not work if the player has disabled server resource packs
     
  5. Offline

    Agentleader1

    Those
    Those conditions are followed.
     
  6. Offline

    Agentleader1

    Bump, and I found you need a Protocol Injector. Resorting to using ProtocolLib, any code on that please?
     
  7. Offline

    GamingShades

    just wondering
    why in the world do you need a specific resourcepack
     
  8. Offline

    Agentleader1

    @GamingShades To enforce gameplay, I don't want players to be playing on the game with like gold hoes shooting snowballs at each other.
     
  9. Offline

    Slideroller

    Not sure if you can "enforce it" but you can do it without enforcement by
    p.setResourcePack("<link here>");
    Keep in mind they'd have to click yes or no, most of the times if they click yes then when they load or something in they wont need to click yes or no again.
     
  10. Offline

    teej107

    @Agentleader1 Setting the resource pack is client side. They can reject your request. If the client already has the texture pack (and said yes?) then the resource pack will be automatically switched.
     
  11. Offline

    I Al Istannen

    @Agentleader1 @Slideroller
    In Version 1.8 you can say at least if they accepted the resource pack or not. Packet. You can easily intercept that with ProtocolLib.
    I would suggest using the PacketWrapper because that makes it really easy to get the result. You can also get the Status by using "packet.getResourcePackStatus().read(0)".
    There are 4 different possibilities:
    • ACCEPTED (user clicked on Yes or Enabled Server Resourcepacks)
    • FAILED_DOWNLOAD
    • SUCCESSFULLY_LOADED (Client loaded the resourcepack and now uses it)
    • DECLINED (User clicked No or has Resourcepacks disabled)
    You can just force it indirectly with this, as you can only kick players but not force the resource pack. However it is better than nothing.
     
  12. Offline

    Agentleader1

    @I Al Istannen That is exactly what I mean. However, how do I start with packet wrapper? Thanks for the help though.
     
  13. Offline

    I Al Istannen

    @Agentleader1 You will need ProtocolLib first. The packet Wrappers are found there too (under useful links).
    A short tutorial on packet Listeners is found here. However for just this you could go with "<packet>.getResourcePackStatus().read(0)" instead of the PacketWrapper.
     
  14. Offline

    Agentleader1

    @I Al Istannen thanks for the help, but in the future I will need to remove of ProtocolLib so I can learn to make my own ProtocolInjector because I am needed of this knowledge. Any starter tutorials on creating a Protocol Injector?
     
  15. Offline

    Agentleader1

    Looking at my code, I have tried player.setResourcePack() and PacketPlayOutResourcePackSend and looks like none of those work with my test subjects' (including me) server resource pack enabled. Does world changing affect this? And this is a bump.
     
  16. Offline

    I Al Istannen

    @Agentleader1 What do you mean with "do not work"? And sadly, I have no experience with Packet Injectors whatsoever.

    I did some tests with the most basic code I could imagine. So i have this as the listener
    Code:
    ProtocolManager man = ProtocolLibrary.getProtocolManager();
    man.addPacketListener(new PacketAdapter(this, PacketType.Play.Client.RESOURCE_PACK_STATUS) {
      @Override
      public void onPacketReceiving(PacketEvent e) {
        e.getPlayer().sendMessage(e.getPacket().getResourcePackStatus().read(0) + "");
        System.out.println(e.getPacket().getResourcePackStatus().read(0));
      }
    });
    
    And the line to set the resourcepack.
    Code:
    player.setResourcePack(<Url to your ResourcePack, must be a direct download one>);
    
    Remember, the resourcepack link MUST BE a DIRECT DOWNLOAD. So when you enter it in your browser, it will automatically download it, you don't have to click anywhere. if you use dropbox for testing, change "dl=0" at the end of the url to "dl=1".

    I tried it, worked just as expected.
     
  17. Offline

    Agentleader1

    @I Al Istannen I am aware it should be a direct download link, but it just still never works.
     
  18. Offline

    I Al Istannen

    @Agentleader1 Does the statement even get executed? I send you the link to a faithful resource pack on my dropbox via PM, i don't know if you are allowed to distribute it here.
     
Thread Status:
Not open for further replies.

Share This Page