.openInventory() not working

Discussion in 'Plugin Development' started by JjPwN1, May 18, 2013.

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

    JjPwN1

    I have made a code in which a 9-slot inventory is supposed to be opened, and you click the item you want to give a player, and the player is given that item. The problem I am encountering is, when you type the command to open the inventory, it doesn't open the inventory. When I replace player.openInventory with target.openInventory it works, but that's not what I want. The "player" is in Creative mode, but I've tried setting them to Survival and then opening the inventory, and that does no good. Is there something I'm missing?
    Code:
            if(cmd.getName().equalsIgnoreCase("sponsor")){
                if(args.length == 1){
                    if(pgplayer.isOnline(Bukkit.getPlayer(args[0])) && !tributes.containsKey(player.getName()) && tributes.containsKey(Bukkit.getPlayer(args[0]).getName())){
                        Player target = Bukkit.getPlayer(args[0]);
                        sponsor.put(player.getName(), target.getName());
                        player.openInventory(inv);
                        pgplayer.sendMessage("Opening sponsor page!", player);
                    }else if(!pgplayer.isOnline(Bukkit.getPlayer(args[0]))){
                        pgplayer.sendError("That player is not online!", player);
                    }else if(tributes.containsKey(player.getName())){
                        pgplayer.sendError("You're not a spectator!", player);
                    }else if(!tributes.containsKey(Bukkit.getPlayer(args[0]).getName())){
                        pgplayer.sendError("That player is not a tribute!", player);
                    }
                }else if(args.length != 1){
                    pgplayer.sendError("Usage: /sponsor <player>", player);
                }
            }
     
  2. Offline

    MrGussio

    You need to create a inventory in the onEnable() method and a variable.
    Code:
    public static Inventory inv;
     
    @Override
    public void onEnable(){
    inv = Bukkit.createInventory(null, 9, "The inventory of " + args.[0]);
    }
    Then it's gonna work I think...
     
Thread Status:
Not open for further replies.

Share This Page