I have set up an inventory save method. My plugin won't enable. I am still confused.

Discussion in 'Plugin Development' started by football70500, Jun 24, 2014.

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

    football70500

    So I created an inventory. I made a method to save the inventory. I am confused as to what I am doing wrong on the onEnable method. Do I need to create defaults or what?

    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2.  
    3. private Main plugin;
    4.  
    5. public Main(Main plugin){
    6. this.plugin = plugin;
    7. }
    8.  
    9. public static Inventory enderone = Bukkit.createInventory(null, 9, "EnderChest");
    10. public static Inventory endertwo = Bukkit.createInventory(null, 18, "EnderChest");
    11. public static Inventory enderthree = Bukkit.createInventory(null, 27, "EnderChest");
    12. public static Inventory enderfour = Bukkit.createInventory(null, 36, "EnderChest");
    13. public static Inventory enderfive = Bukkit.createInventory(null, 45, "EnderChest");
    14. public static Inventory endersix = Bukkit.createInventory(null, 54, "EnderChest");
    15. public static Inventory backpackone = Bukkit.createInventory(null, 9, "Inventory");
    16.  
    17. @Override
    18. public void onEnable(){
    19. getLogger().info("JumboChest has been enabled!");
    20. Bukkit.getPluginManager().registerEvents(this, this);
    21. }
    22.  
    23. @Override
    24. public void onDisable(){
    25. getLogger().info("JumboChest has been disabled!");
    26. }
    27.  
    28.  
    29. @EventHandler
    30. public void onOpen(PlayerInteractEvent e){
    31. Player player = e.getPlayer();
    32. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    33. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    34. e.setCancelled(true);
    35. if(player.hasPermission("jc.ender.one")){
    36. player.openInventory(enderone);
    37. }
    38. if(player.hasPermission("jc.ender.two")){
    39. player.openInventory(endertwo);
    40. }
    41. if(player.hasPermission("jc.ender.three")){
    42. player.openInventory(enderthree);
    43. }
    44. if(player.hasPermission("jc.ender.four")){
    45. player.openInventory(enderfour);
    46. }
    47. if(player.hasPermission("jc.ender.five")){
    48. player.openInventory(enderfive);
    49. }
    50. if(player.hasPermission("jc.ender.six")){
    51. player.openInventory(endersix);
    52. }
    53. }
    54. }
    55. }
    56.  
    57. @EventHandler
    58. public void onClose(InventoryCloseEvent e){
    59. saveInventory(e.getPlayer().getInventory().getContents(), e.getPlayer().getInventory().getArmorContents(), e.getPlayer().getUniqueId());
    60.  
    61. }
    62.  
    63.  
    64.  
    65. public void saveInventory(ItemStack[] inventory, ItemStack[] armor, UUID uuid) {
    66. try {
    67. YamlConfiguration c = new YamlConfiguration();
    68. if (inventory != null)
    69. c.set("inventory.inventory", inventory);
    70. if (armor != null)
    71. c.set("inventory.armor", armor);
    72. c.save(new File(this.getDataFolder() + "/data/", uuid + ".yml"));
    73. saveConfig();
    74. } catch (IOException e) {
    75. Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Failed to save inventory due to error: " + e.getMessage());
    76. }
    77. }
    78.  
    79.  
    80.  
    81. }


    What did I do wrong? My plugin will not enable.
    Do I need to set the config up in the onEnable method?
     
  2. Offline

    Rocoty

    Your plugin won't enable because you don't have a no-arg constructor. As a general rule of thumb you should not define your own constructor in the main class, let alone a constructor that takes arguments, because there would simply be no use for one.
     
  3. Offline

    football70500

    Okay, so I deleted it, The custom inventory still doesn't save. The plugin enables now tho
     
Thread Status:
Not open for further replies.

Share This Page