Solved Player skin head GUI

Discussion in 'Plugin Development' started by phadol2013, Dec 19, 2018.

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

    phadol2013

    Hello,
    Thank you for reading this thread

    its been a while since i tried to make a player head with the current player skin on it
    i did try .setOwner(args[0]) but its always turned .setOwner(args[0]) and tell me to SuspendWaring("deprecation")
    i did what eclipse said, but after continue with the command it got error in the console

    Code:
    [06:16:59] [Server thread/INFO]: phadol2013 issued server command: /info
    [06:16:59] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'info' in plugin ADMINTOOLS v0.1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:628) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1340) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1200) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:696) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:371) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:651) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:555) [craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at admintool.commands.Info.onCommand(Info.java:41) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.12.2.jar:git-Bukkit-e60fc34]
        ... 15 more
    
    i did my research on this and found only .setOwner as in SkullMeta for the best, this is my code

    Code:
    package admintool.commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.SkullMeta;
    
    import admintool.Main;
    import admintool.objects.Menu;
    import admintool.objects.Menu.Row;
    import admintool.objects.Menu.onClick;
    
    public class Info implements CommandExecutor{
       
    
       
        @SuppressWarnings("unused")
        private Main plugin;
        public Menu menu;
       
        public Info(Main plugin)
        {
            this.plugin = plugin;
            plugin.getCommand("Info").setExecutor(this);
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if(sender instanceof Player)
            {
                Player p = (Player) sender;
               
               args[0] = p.getName();
    
                ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                SkullMeta meta = (SkullMeta) head.getItemMeta();
                meta.setOwner(args[0]);
                head.setItemMeta(meta);
               
               
                Menu menu = new Menu(ChatColor.BLUE + "[INFO]", 3, new onClick() {
    
                    @Override
                    public boolean click(Player p, Menu menu, Row row, int slot, ItemStack item) {
                       
                        return false;
                    }
                   
                });
               
               
               
                menu.addButton(menu.getRow(1), 2, head, ChatColor.GOLD + p.getName(),ChatColor.AQUA + "This is info about " + ChatColor.GOLD + p.getName());
               
                menu.open(p);
               
            }
            else
            {
                sender.sendMessage(ChatColor.RED + "[ADMINTOOLS] Only player can execute this command!");
            }
           
            return false;
        }
       
    
    }
    
    but when i dont use the meta thing

    Code:
    menu.addButton(menu.getRow(1), 2, new ItemStack(Material.SKULL_ITEM, 1, (short) 3), ChatColor.GOLD + p.getName(),ChatColor.AQUA + "This is info about " + ChatColor.GOLD + p.getName());
    it worked perfectly but just the head is just steve

    I still dont get it on how to do it
    im still new to this plugin thing

    Sorry if its too obviouse and im just too stoopid
     
  2. Offline

    timtower Administrator Administrator Moderator

    @phadol2013 You are getting args[0] before you check if it is there.
     
  3. Offline

    phadol2013

    @timtower i tried to make so if the command execute without a name it will open as the sender profile

    i did
    \
    Code:
    args[0] = p.getName();
    
    does it need an if statement for checking is there an argument or not ?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @phadol2013 It is an array, the size of the array is 0.
    Make your own variable instead.
     
  5. Offline

    phadol2013

    Lol, it work
    Thank you
     
Thread Status:
Not open for further replies.

Share This Page