Tutorial [1.8,1.9,1.10] Checking if a player accepted a resourcepack.

Discussion in 'Resources' started by Zombie_Striker, Jan 26, 2016.

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

    Zombie_Striker

    While looking through the 1.8 docs, I came across an event and enum that I have never seen before. There is a event called PlayerResourcePackStatusEvent, which gets called after the player either accepts or denies the resourcepack. The reason why I am creating this thread is because there does not seem to be any other thread of the forums that even discusses this event, and because there have been many other members looking for a way to force players to download their resourcepack.

    Since this event is the same as any other event, the structure of the event looks like the following:
    Code:
    @EventHandler
    public void onResourcepackStatusEvent(PlayerResourcePackStatusEvent event){
    
    }
    Now, to get the status, you use the .getStatus method which returns a Status object, which contains the following values, ACCEPT, DECLINED, FAILED_DOWNLOAD, and SUCCESSFULLY_DOWNLOADED. The first two cases are triggered when the player first clicks what they wish to do. The last two cases are triggered after the player accepts and determines if the download was successful. Because of this, note that the event may trigger twice for an individual request.

    Since most people want this event because they would wish to kick the player if the player denies the request, this is how you would go about kicking the player if the player does not accept the request.
    Code:
    if(event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED)
      event.getPlayer().kickPlayer(" You did not accept the resourcepack request.");
    
    
    Since this apart of the Spigot 1.8 docs, this will not work on versions 1.7 or lower.
     
    Last edited: Sep 2, 2016
  2. Offline

    ski23

    This is helpful! I was going to be looking into forcing a resource pack onto players for certain games and now I know how! Bookmarked for future reference.
     
  3. Offline

    sethrem

    Wow the spoonfeeding is strong within this. Yes tell the lazy people about an event that exists because they're too lazy to find it themselves. +1 bro
     
    Madszinader and Zombie_Striker like this.
  4. Offline

    Zombie_Striker

    @sethrem
    True, I probably should edit it so no one would copy and paste (+1 for thinking about that). As for "To lazy for people to find it themselves" I did not even know about it until I just stumbled upon it in the docs. I had no clue that it even existed, like a lot of the other members of the forums, and that is why I even created this page; To inform people about this event.
     
  5. Offline

    teej107

    I haven't tested it but I'm sure it won't work. The event is not documented in the 1.7 docs so I'll just assume it doesn't exist in 1.7.

    I think of it as awareness. I had no idea it existed. However I still use the 1.7 API for most of my projects.
     
  6. Offline

    MisterErwin

    @Zombie_Striker I don't see a reason why to mention it. It is visible via the javadocs via wiki.vg

    And towards your "example": According to the javadocs its DECLINED, and what would you do if the download failed?
     
  7. Offline

    Zombie_Striker

    As I said before, the only reason why I created this threads was because I did not know it exist (like a bunch of other users). It's great that you already know about it, but I have been looking for something like this for the past year, and there have been multiple PD threads created looking for this as well that are still unanswered. I simply wanted to post this for people like me who are/were looking for this.

    BTW: You posted the packet, which most users may want to avoid. This event is easier for new Devs and is more "User friendly".

    Thanks for this. Did not even notice. Fixed in the main post.

    You would use if the status is equal to Status.FAILED_DOWNLOAD.
     
    MisterErwin likes this.
  8. Offline

    0566

    This is going to help so much people, and I'm going to get kicked from so much servers
     
  9. Offline

    Zombie_Striker

    @0566
    Not necessarily. The player would need to allow the server to send ResourcePackRequest when they add the server in order for the prompts to open, and as such for this even to be triggered. All you need to do to get around this is to set so the server can't send you resourcepacks when you first add the server to your client.
     
  10. Offline

    Xerox262

    Which can be fixed if you kick them if you don't receive an accepted followed by a successfully loaded
     
  11. Offline

    mcdorli

    @Zombie_Striker Nice, I thought this is only possible, by listening to the PacketPlayInClientCommand packet.

    Btw.: if this is how your average event look like
    Code:
    public void onResourcepackStatusEvent(PlayerResourcePackStatusEvent event){
    
    Then I seriosuly don't want to look at some of ypur more complex codes.

    It's not allowed to kick players for this. I can't find the thread bit there was a discussion about this problem a long time ago.
     
    Last edited by a moderator: Feb 4, 2016
  12. Offline

    Xerox262

    @mcdorli can you lock them in a room and tell them the server is much more enjoyable with the resource pack? Without forcing them to accept it or forcing them to leave the server.
     
  13. Offline

    mcdorli

    Possibly only if the owner allows it. There's no server owner, who wants to kick players just because they didn't downloaded a resource pack.

    I had an idea, of instead of kicking them, if they didn't downloaded the resource pack, try to force them to click on it, like with a packetPlayInClientCommand packet. You can force them out of the respawn screen, so, I think it shpuld be possible
     
  14. Offline

    Xerox262

    But you can't do that for the same reason that you can't kick them, you cannot force the client to download a file to their machine to play on your server, the file could be malicious, even though I don't know of a way for resource packs to be as such, but yea.
     
  15. Offline

    Zombie_Striker

    Bump
     
    sgavster likes this.
  16. Offline

    sgavster

    Thank you!
     
  17. Offline

    Zarlen

    PlayerResourcePackStatusEvent cannot be resolved to a type

    sigh im using spigot 1.8 r2 ;-;
     
  18. While it might be lazy, I don't think this is a bad thread. After all, if we didn't need to help anyone because everyone read all the javadocs, were would this forum be?
     
    Zombie_Striker likes this.
  19. Offline

    Tecno_Wizard

    @TheEnderCrafter9, can confirm- There are so many events in bukkit even I don't know them all.
     
Thread Status:
Not open for further replies.

Share This Page