Skull heads when deleting playerdata

Discussion in 'Spigot Plugin Development' started by helmwet, Apr 18, 2017.

  1. I have a server for testing plugins. I have only TWO plugins:
    - WorldEdit
    - Hub (A plugin I've made)

    There is a functionality in the Hub plugin. Every time a user joins clear their inventory and set the 8th item in their inv to their head. (Skull)

    I also run a script every time the server start which deletes:
    - ops.json
    - banned-players.json
    - world
    - et cetera.

    And then I copy a built map into the main directory and rename it to world. (The map doesn't have nothing in playerdata)

    Then when I join the server, I get the skull but with the alex skin. Only after I rejoin I see my skin.
    It happens to other players also, and this is driving me crazy.

    What should I do? Thanks for help

    Edit:
    start.bat:
    Code (Text):
    :mc
    rd world /q /s
    rd world_nether /q /s
    rd world_the_end /q /s
    rd logs /q /s
    rd crash-reports /q /s
    del whitelist.json /q
    del usercache.jon /q
    del ops.json /q
    del banned-ips.json /q
    del banned-players.json /q
    del bukkit.yml /q
    del commands.yml /q
    del permissions.yml /q
    del spigot.yml /q
    del server.properties /q
    del help.yml /q
    xcopy default\spawn_map world /h /i /q /e
    copy default\server.properties server.properties
    copy default\bukkit.yml bukkit.yml
    copy default\spigot.yml spigot.yml
    java -jar spigot.jar
    goto mc
    InventoryGUI.java:
    Code (Text):
    package org.seklyza.mynznetwork.hub.utils;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.SkullMeta;

    public class InventoryGUI {
        public static final void giveItems(Player player) {
            PlayerInventory inv = player.getInventory();
         
            inv.clear();
         
            ItemStack playerSkull = createSkull(player.getName(), "Your details");
         
            inv.setItem(7, playerSkull);
        }
        private static ItemStack nameItem(ItemStack item, String name) {
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(name);
            item.setItemMeta(meta);
            return item;
        }
        private static ItemStack nameItem(Material item, String name) {
            return nameItem(new ItemStack(item), name);
        }
        private static ItemStack createSkull(String playerName, String name) {
            ItemStack skullItem = nameItem(Material.SKULL_ITEM, name);
            SkullMeta skullMeta = (SkullMeta) skullItem.getItemMeta();
            skullMeta.setOwner(playerName);
            skullItem.setItemMeta(skullMeta);
            skullItem.setDurability((byte)3);
            return skullItem;
        }
    }
     
  2. Is your Hub plugin set to start at STARTUP instead of the default POSTWORLD in the plugin.yml?
    Code (YAML):
    load: STARTUP
    Since you're deleting the world, I assume that would have an effect.
     
  3. Just set the load key in the plugin.yml?
     
  4. Yes. I'm not saying for sure that will help, but I would think, if nothing else, it would simply be good practice to set that in a plugin where you need to load in special files like that.

    Edit: Oh, I just realized you said the copying part is in a script.
     
  5. Well, it doesn't work. I think the skin details are in the playerdata folder but not sure

    Edit: Also tried player.saveData();
     
  6. Maybe try using a scheduler to do the head thing 1 tick later? That might give it the time it needs to load in the skin data it needs to load
    Code (Java):
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        InventoryGUI.giveItems(event.getPlayer());
    }, 1L);
     
  7. Tried that before, now I did it again, and still, no success
     
  8. Ok, I switched to Spigot version 1.9.4 and it works now. Perhaps specific to 1.11.x