Solved PlayerInventory error :\

Discussion in 'Plugin Development' started by Jetsinsu, Mar 22, 2014.

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


    Hey guys! I want to update my inventory after receiving an item and I keep getting this ClassCastExeption error.

    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.inventor
    y.CraftInventoryPlayer cannot be cast to org.bukkit.entity.Player
            at me.jetsinsu.flappybirds.Flappybirds.onPlayerInteract(
    :174) ~[?:?]
    1. if (s.getLine(0).equals("§6[§l§1FB§6]")){
    2. join.add(e.getPlayer().getName());
    3. Player p = (Player) e.getPlayer();
    4. PlayerInventory pi = (PlayerInventory) p.getInventory();
    5. World w = Bukkit.getServer().getWorld(getConfig().getString(""));
    6. double x = getConfig().getDouble("spawn.x");
    7. double y = getConfig().getDouble("spawn.y");
    8. double z = getConfig().getDouble("spawn.z");
    9. e.getPlayer().teleport(new Location(w, x, y, z));
    10. pi.addItem(new ItemStack(Material.FEATHER, 1));
    11. ((Player) pi).updateInventory();
    12. return;
    13. }
  2. Offline


    Your using a PlayerInventory to update the players inventory:
    ((Player) pi).updateInventory();

    Change "pi" to "p".
    Jetsinsu likes this.
  3. Offline


    WOw! THat 1 mistake T_T Ty
  4. Offline


    Lol, everyone makes mistakes in their code once in a while. I'm just glad I could help.
    Jetsinsu likes this.
Thread Status:
Not open for further replies.

Share This Page