Why is my player changing to a offline player?

Discussion in 'Plugin Development' started by shohouku, Oct 4, 2014.

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

    shohouku

    So when I serialize my inventory to my config then restart the server my player turns into an offline player?

    Heres my error:
    Code:java
    1. Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.CraftOff
    2. linePlayer cannot be cast to org.bukkit.inventory.InventoryHolder



    Heres my codes:

    Code:java
    1. if (event.getName().equals("Accessory")) {
    2. Inventory accessory1 = Bukkit.createInventory(p, 54, "Accessory");
    3.  
    4.  
    5. if(getInventory(inventory, "Accessory") != null){
    6. p.openInventory(getInventory(inventory, "Accessory"));
    7.  
    8. } else {
    9. p.openInventory(accessory1);
    10.  
    11. }
    12.  
    13. }
    14.  


    Code:java
    1. if(e.getInventory().getTitle().equals("Accessory")) {
    2. saveInventory(e.getInventory(), inventory, "Accessory");
    3. System.out.println("Successfully Saved " + e.getInventory().getTitle() + ", holder: " + e.getInventory().getHolder() + ", UUID: " + e.getPlayer().getUniqueId());
    4. }


    Code:java
    1. public void saveInventory(Inventory inventory, FileConfiguration file, String path){
    2. int i = 0;
    3. for(ItemStack im : inventory.getContents()){
    4. file.set(path + ".contents." + i, im);
    5. i++;
    6. }
    7. file.set(path + ".maxstacksize", inventory.getMaxStackSize());
    8. file.set(path + ".inventorytitle", inventory.getTitle());
    9. file.set(path + ".inventorysize", inventory.getSize());
    10. file.set(path + ".inventoryholder", inventory.getHolder());
    11. }
    12. public Inventory getInventory(FileConfiguration file, String path){
    13. if(file.contains(path)){
    14.  
    15. Inventory inv = Bukkit.createInventory((InventoryHolder) file.get(path + ".inventoryholder"), file.getInt(path + ".inventorysize"), file.getString(path + ".inventorytitle"));
    16. inv.setMaxStackSize(file.getInt(path + ".maxstacksize"));
    17. for(int i=0; i<inv.getSize(); i++){
    18. if(file.contains(path + ".contents." + i)){
    19. inv.setItem(i, file.getItemStack(path + ".contents." + i));
    20. }
    21. }
    22. return inv;
    23. }
    24.  
    25. return null;
    26. }


    This is what my CONFIG looks like:

    Code:
    Accessory:
      contents: {}
      maxstacksize: 64
      inventorytitle: Accessory
      inventorysize: 54
      inventoryholder:
        ==: Player
        UUID: 1fa86bee-968c-3a7f-9463-ff65416f62da
    My UUID is wrong and it should be different....

    Any ideas?
     
  2. Offline

    xepisolonxx

    shohouku
    Its probally also counting the chars in between the ":"and the "1".
    Code:
    UUID: 1fa86bee-968c-3a7f-9463-ff65416f62da
     
  3. Offline

    turt2live

    Without the full error, not much help can be given beyond "don't do that". As for the wrong UUID, you are running on an offline mode server and therefore your UUID is a hash of your username. Use an online mode server to get the correct UUID.
     
  4. Offline

    shohouku


    My server is on online mode, I still don't know why though.
     
  5. Offline

    turt2live

    If your server was in online mode, then you'd see a '4' instead of a '3' at the start of the third section in the UUID.
     
  6. Offline

    shohouku


    online-mode=true

    Thats what it says on my server properties... I'v also debugged my player UUID and its different to the one in the config.

    What I'm starting to notice is that when I shut down my server and restart it, my UUID changes.

    First it looks like this:

    Code:
    Accessory:
      contents: {}
      maxstacksize: 64
      inventorytitle: Accessory
      inventorysize: 54
      inventoryholder:
        ==: Player
        Name: shohouku
    then after server restart it looks like this:

    Code:
    Accessory:
      contents: {}
      maxstacksize: 64
      inventorytitle: Accessory
      inventorysize: 54
      inventoryholder:
        ==: Player
        UUID: 1fa86bee-968c-3a7f-9463-ff65416f62da
    My UUID should look like this:
    Code:
    f7731274-3a20-406a-bf65-2a32f5569e2b
     
Thread Status:
Not open for further replies.

Share This Page