What obvious thing am I doing wrong?

Discussion in 'Plugin Development' started by unrealdesign, Jul 8, 2014.

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

    unrealdesign

    I'm doing something wrong and I have no idea what it is.

    Console Output:
    Code:
    [00:13:04] [Server thread/INFO]: ##### Start creating INV from CONSTRUCTOR #####
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: DIAMOND_HELMET
    [00:13:04] [Server thread/INFO]: ------ End creating INV from CONSTRUCTOR ------
    [00:13:04] [Server thread/INFO]: ##### Start reading INV from CONSTRUCTOR #####
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: Armor type from MySQL: NULL
    [00:13:04] [Server thread/INFO]: ------ End reading INV from CONSTRUCTOR ------
    Pertaining code - (From UItemstack):
    Code:java
    1. /**
    2.   * Create an UInventory from a serializedInventory
    3.   *
    4.   * @param serializedInventory Serialized string of the inventory to load from
    5.   */
    6. public UInventory(String serializedInventory)
    7. {
    8. if(serializedInventory != null && !serializedInventory.equals(""))
    9. {
    10. String[] data = serializedInventory.split(":");
    11.  
    12. String[] invData = data[0].split(";");
    13. for(int i=0; i<invData.length; i++)
    14. {
    15. invContents[i] = new UItemStack(invData[i]);
    16. }
    17.  
    18. if(data.length > 1)
    19. {
    20. String[] armorData = data[1].split(";");
    21. System.out.println("Deserializing armor part of inventory in constructor.");
    22. for(int i=0; i<armorData.length; i++)
    23. {
    24. System.out.println("Armor Data: "+armorData[i]);
    25. armorContents[i] = new UItemStack(armorData[i]);
    26. System.out.println("Duplicate of previous:"+armorContents[i]);
    27. }
    28.  
    29. System.out.println("##### Start creating INV from CONSTRUCTOR #####");
    30. for(UItemStack item : getArmorContents())
    31. {
    32. ItemStack is = item.getItemStack();
    33. if(is != null)
    34. System.out.println("Armor type from MySQL: "+item.getItemStack().getType().name());
    35. else
    36. System.out.println("Armor type from MySQL: NULL");
    37. }
    38.  
    39. System.out.println("------ End creating INV from CONSTRUCTOR ------");
    40.  
    41. if(data.length > 2)
    42. {
    43. String[] potionsData = data[2].split(";");
    44. for(String potionData : potionsData)
    45. {
    46. String[] potionInfo = potionData.split(",");
    47. if(potionInfo.length > 2)
    48. {
    49. PotionEffectType type = PotionEffectType.getByName(potionInfo[0]);
    50. int dur = Integer.parseInt(potionInfo[1]);
    51. int amp = Integer.parseInt(potionInfo[2]);
    52. potionEffects.add(new PotionEffect(type, dur, amp));
    53. }
    54. }
    55. }
    56. else
    57. {
    58. for(int i=0; i<armorContents.length; i++)
    59. {
    60. armorContents[i] = new UItemStack("");
    61. }
    62. }
    63. }
    64.  
    65.  
    66. }
    67. }[/i][/i][/i][/i][/i][/i][/i]


    Pertaining code from loadInventory() method:
    Code:java
    1. /**
    2.   * Load inventory from the database
    3.   */
    4. public void loadInventory()
    5. {
    6. try
    7. {
    8. ResultSet rs = stmt.executeQuery("SELECT inventory "
    9. + "FROM "+DBSection.INFO.getTable()+" "
    10. + "WHERE ucharacter='"+name+"';");
    11. while(rs.next())
    12. {
    13. UInventory inv = new UInventory(rs.getString("inventory"));
    14. System.out.println("##### Start reading INV from CONSTRUCTOR #####");
    15. for(UItemStack item : inv.getArmorContents())
    16. {
    17. ItemStack is = item.getItemStack();
    18. if(is != null)
    19. System.out.println("Armor type from MySQL: "+item.getItemStack().getType().name());
    20. else
    21. System.out.println("Armor type from MySQL: NULL");
    22. }
    23.  
    24. System.out.println("------ End reading INV from CONSTRUCTOR ------");
    25. inv.loadIntoInventory(up.getPlayer().getInventory());
    26. }
    27. }
    28. catch(SQLException e)
    29. {
    30. e.printStackTrace();
    31. }
    32. }


    Pertaining code from getArmorContents()
    Code:java
    1. public UItemStack[] getArmorContents()
    2. {
    3. return armorContents;
    4. }


    As you can see, somewhere between the constructor and the getter for the armor contents it's doing something wrong.

    Background: I have a custom UItemStack, UInventory, and UBook wrappers for the pertaining bukkit classes. This is so I can turn itemstacks from bukkit data to string data so I can load it from MySQL. The MySQL data is being saved to and read from correctly, but somehow between the constructor and getter for the armor contents, it's turning everything inside of it null.
     
  2. Offline

    fireblast709

    unrealdesign Do you even set the armorContents array / use the same object which you loaded it to?
     
  3. Offline

    unrealdesign

    Yes I set in the instance declaration. Sorry about not posting that but I thought it was obvious since I was retrieving and adding data from it in the constructor. And I do use the exact same object as shown in the loadInventory() method
     
  4. Offline

    unrealdesign

    Any fancy ideas? I honestly have no idea what I've done wrong :/. I'll be sure to post back if I found the solution though.
     
Thread Status:
Not open for further replies.

Share This Page