setResourcePack Help

Discussion in 'Plugin Development' started by GRocksMc, Mar 13, 2017.

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

    GRocksMc

    I'm trying to set a player's resource pack once they join the server without using the server.properties.
    Code:java
    1. package com.GRocks.TexturePackPlugin;
    2. import org.bukkit.entity.Player;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.plugin.PluginManager;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. public class Main extends JavaPlugin implements Listener{
    9. public void onEnable(){
    10. PluginManager pm = getServer().getPluginManager();
    11. pm.registerEvents(this, this);
    12. }
    13. @EventHandler
    14. public void onPlayerJoin(PlayerJoinEvent event){
    15. Player player = event.getPlayer();
    16. player.sendMessage("hi");
    17. player.setResourcePack("[URL]http://download1492.mediafire.com/106c6g9yg5lg/3wczd2zlhrbytv3/GamerVerse.zip[/URL]");
    18. }
    19. }


    When I join, it says hi to me but does not set my Resource Pack. I have my Server Resource Pack set to enabled.

    Thanks much for your help in advance! Zombie_Striker

    The problem isn't the URL because I've tested about 5 different ones (all direct links).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 14, 2017
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    Zombie_Striker

    @GRocksMc
    PlayerJoinEvents is triggered before a player joins. Use schedulers to wait one tick before setting the RP.
     
  4. Offline

    GRocksMc

    timtower http://pastebin.com/Q7unRNCq

    Zombie_Striker Schedulers aren't something that I'm very familiar with, could you give an example?

    Would this do the trick?
    Code:java
    1.  
    2. package com.GRocks.TexturePackPlugin;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerJoinEvent;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin implements Listener{
    13.  
    14. public void onEnable(){
    15. PluginManager pm = getServer().getPluginManager();
    16. pm.registerEvents(this, this);
    17. }
    18.  
    19. @EventHandler
    20. public void onPlayerJoin(PlayerJoinEvent event){
    21. Player player = event.getPlayer();
    22. player.sendMessage("hi");
    23. delayTask(player);
    24. }
    25.  
    26. private void delayTask(final Player p){
    27. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    28. public void run(){
    29. p.setResourcePack("dl.dropbox.com/s/l75ixovk1q7vp25/GamerVerse.zip");
    30. }
    31.  
    32. }, 20);
    33. }
    34.  
    35. }
    36.  
     
    Last edited: Mar 14, 2017
  5. Offline

    PhantomUnicorns

    I would not make another method for it, change 20 --> 1 because you should just wait 1 tick. If you want (Not required I think) put the @Override on public void run()
     
  6. Offline

    GRocksMc

    PhantomUnicorns
    Code:java
    1.  
    2. private void delayTask(final Player p){
    3. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    4. @Override
    5. public void run(){
    6. p.setResourcePack("dl.dropbox.com/s/l75ixovk1q7vp25/GamerVerse.zip");
    7. }
    8.  
    9. }, 1);
    10. }
    11.  

    I had it set to wait 1 second just to ease my soul that I'm doing something right. Putting @Override and changing 20 -> 1 didn't do anything, my texture pack still isn't changing.
     
  7. Online

    timtower Administrator Administrator Moderator

    @GRocksMc Does your client log say anything about it?
     
  8. Offline

    GRocksMc

    timtower It does not say anything about it. :(

    Btw, the resource pack only changes glowstone to look like polished andesite.
     
  9. Offline

    SeniorCluckers

    @GRocksMc

    You should try creating a command to set the player resource pack and if your command succeeds. Then try and run the command on join.
     
  10. Offline

    PhantomUnicorns

    You sure the link is correct and the others tested? I'm not sure how resource packs go, but you are attempting to use a .zip is that correct?

    EDIT: Looking and decompiling your resource pack, it only has 1 block and you have it saved as a photoshop file for one... The other is a png, which as you stated looks as intended (From looking at it) It's also named glowstone.png, you sure it is not by another name? Or if it has caps i.e. GlowStone.png or Glowstone.png. Also your photoshop file (Not sure if it matters) has the glowstone texture still on a different layer XD
     
  11. Offline

    GRocksMc

    SeniorCluckers I will try that right now.

    EDIT:
    Code:java
    1.  
    2. package com.GRocks.TexturePackPlugin;
    3.  
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandExecutor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin implements CommandExecutor{
    11.  
    12. public void onEnable(){
    13. getCommand("pvp").setExecutor(this);
    14. }
    15.  
    16. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    17.  
    18. if(cmd.getName().equalsIgnoreCase("tp")){
    19. Player player = (Player) sender;
    20. player.sendMessage("hi");
    21. player.setResourcePack("[URL]https://dl.dropbox.com/s/l75ixovk1q7vp25/GamerVerse.zip[/URL]");
    22. }
    23.  
    24. return false;
    25.  
    26. }
    27.  
    28. }
    29.  

    I thought I would try just the command first, but that doesn't work either. It says hi to me but when I click "yes" for it to download the texture pack, it does nothing. There aren't any errors either.

    PhantomUnicorns Yes, I have the glowstone layer on it so that I can change it back if needed. Also, yes, it is supposed to be called glowstone.png.
     
    Last edited: Mar 14, 2017
  12. Online

    timtower Administrator Administrator Moderator

    @GRocksMc Try it with a texturepack wgere you are sure that it works and is visible right awsy.
     
  13. Offline

    GRocksMc

  14. Offline

    SeniorCluckers

    @GRocksMc

    So here's why. I figured this out when a plugin that would set a resource pack was not working. Your resource pack is not compatible with the minecraft version you're using or is setup incorrectly. I did tests on this before and found this out. Go ahead and make sure to use a resource pack that is made/compatible for (THE VERSION YOUR USING) so you can see that. Also, to test what I'm saying do not use your texture pack use a different one.
     
  15. Offline

    GRocksMc

    @SeniorCluckers How exactly would I get the right version? Does it have to do with the pack.mcmeta? How do I make it work for 1.11+?
     
  16. Offline

    SeniorCluckers

  17. Offline

    GRocksMc

    @SeniorCluckers

    Your resource pack that you sent me worked, but I can't seem to use it again. It prompts me and does nothing when I click "yes".

    Now we know that the problem is within my 3 file texture pack. -_-

    How would I fix that

    Code:
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    3.  
    4. if(cmd.getName().equalsIgnoreCase("tpack")){
    5. Player player = (Player) sender;
    6. player.sendMessage("It's doing something");
    7. player.setResourcePack("[URL]https://dl.dropbox.com/s/l75ixovk1q7vp25/GamerVerse.zip[/URL]");
    8. player.sendMessage("It's done");
    9. }
    10.  
    11. return false;
    12.  
    13. }
    14.  
    15. }
    16.  
     
    Last edited: Mar 15, 2017
  18. Offline

    SeniorCluckers

    @GRocksMc

    Okay so just to make sure you're not putting in [ URL ] for the url in you're actual code right?

    EDIT

    Are we talking about fixing your resourcepack or the resourcepack i gave you not working anymore?
     
  19. Offline

    GRocksMc

    @SeniorCluckers

    Bukkit.org puts in that part.

    Neither of the packs are working right now. (Yours worked once)
     
  20. Offline

    SeniorCluckers

    @GRocksMc

    Did you have the pack I gave you already set when you clicked yes? And I'm going to try it now and Ill get back to you.
     
  21. Offline

    GRocksMc

  22. Offline

    SeniorCluckers

    @GRocksMc

    Alright so after testing. I have came to the conclusion that yes it should work even after you clicked yes. I tried it using a command multiple times and worked flawlessly. Now I believe there's another issue for it not working for you and that is because of dropbox. I uploaded to a different provider as the first one I was using was not working. I used this website http://rgho.st and it worked.

    EDIT ***
    @GRocksMc
    I have fixed your resource pack also and here the download link, http://rgho.st/8Tb9SXr5R.
    Here it is working in action :
    [​IMG]

    Lastly, DO NOT put you resourcepack FILES in a folder, just select the files and create a zip. You'll see when you unzip the resourcepack about what I mean.
     
    Last edited: Mar 15, 2017
  23. Offline

    GRocksMc

    @SeniorCluckers This is really frustrating me. I'm probably, very stupidly, doing something wrong.

    I went to the link you sent. Right clicked download. Copied link address. Pasted that in as the url for the texture pack plugin. I still doesn't work.

    I tried to download from your link, but chrome (and internet explorer) blocked me from downloading it because it's "unsafe." I uploaded mine to that website and it still blocked it.

    EDIT: Nevermind, I exported it as the wrong plugin, *facepalm*, it works amazingly. Thank you so much for your help!
     
    Last edited: Mar 16, 2017
  24. Offline

    SeniorCluckers

    @GRocksMc

    Glad I could help ;).

    I should just say that the host I gave you deletes your files after a certain amount of days so look around if that is not ideal for you.

    Mark this as solved :)
     
  25. Offline

    GRocksMc

    @SeniorCluckers

    Now that I got that out of the way, I'm trying to make it so if a player teleports to a world. It'll check if that world has a URL in the config, then set the player's resource pack to that.

    Listener(main class):
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerTeleport(PlayerTeleportEvent event){
    4. Player player = event.getPlayer();
    5. String toWorld = event.getTo().getWorld().getName();
    6. System.out.println(toWorld);
    7. if(this.getConfig().getString("Resource_Pack_Worlds." + toWorld) != null){
    8. String URL = (String) this.getConfig().get("Resource_Pack_Worlds." + toWorld);
    9. System.out.println(URL);
    10. if(event.getTo().getWorld() != event.getFrom().getWorld()){
    11. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    12. public void run(){
    13. player.setResourcePack(URL);
    14. }
    15. }, 20);
    16. }
    17. }
    18. }
    19.  


    Command:
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    3.  
    4. if(cmd.getName().equalsIgnoreCase("rpack")){
    5. if(args.length == 0){
    6. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8Syntax: &7/&3tpack &7<&3World&7> <&3Resource Pack URL&7>"));
    7. }
    8. else if(args.length == 1){
    9. sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8Syntax: &7/&3tpack &7<&3World&7> <&3Resource Pack URL&7>"));
    10. }
    11. else if(args.length > 1){
    12. String worldString = args[0].replaceAll("'", "");
    13. String URL = args[1].toString();
    14. if(Bukkit.getWorld(worldString) == null){
    15. sender.sendMessage(ChatColor.DARK_AQUA + worldString + ChatColor.GRAY + " is not a world");
    16. }
    17. else{
    18. main.getConfig().set("Resource_Pack_Worlds." + worldString, URL);
    19. main.saveConfig();
    20. sender.sendMessage(ChatColor.GRAY + "The Resource Pack has been saved for world " + ChatColor.DARK_AQUA + worldString);
    21. }
    22. }
    23. }
    24.  
    25. return false;
    26.  
    27. }
    28.  


    The command works perfectly, but when I teleport to a world, it can't get the URL from the config.
     
    Last edited: Mar 17, 2017
  26. Offline

    GRocksMc

  27. Online

    timtower Administrator Administrator Moderator

    @GRocksMc Is it printing the correct world?
     
  28. Offline

    GRocksMc

    @timtower

    Into the config.yml? Yes, perfectly.

    Out of the config? I do not believe so. It must not be finding the path '"Resource_Pack_Worlds" + toWorld' because it isn't printing out URL.

    There are no errors in the console.
     
  29. Online

    timtower Administrator Administrator Moderator

    @GRocksMc You are printing the world to the console.
    Is that world in the config?
     
  30. Offline

    GRocksMc

    @timtower

    Yes, if I put that world in the config with the rpack command, it is the exact same.
     
Thread Status:
Not open for further replies.

Share This Page