error help

Discussion in 'Plugin Development' started by 15987632, Sep 5, 2014.

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

    15987632

    my error
    Code:
    [19:57:58 ERROR]: Could not load 'plugins\NewFood.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Fi
    le cannot be null
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:182) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:308) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:231) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:255) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:23
    3) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    a:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.IllegalArgumentException: File cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbu
    kkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Yam
    lConfiguration.java:171) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:118) ~
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:112) ~[cr
    aftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at me.trevor.bukkit.NewFood.<init>(NewFood.java:21) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ~[?:1.8.0_20]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    ~[?:1.8.0_20]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce) ~[?:1.8.0_20]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_2
    0]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:178) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            ... 9 more
    my class
    Code:java
    1. package me.trevor.bukkit;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. import java.util.HashMap;
    13. import java.util.Map;
    14.  
    15. public class NewFood extends JavaPlugin implements Listener {
    16.  
    17. private Map<String, Long> lastUsageYellow = new HashMap<String, Long>();
    18. private Map<String, Long> lastUsageOrange = new HashMap<String, Long>();
    19. private Map<String, Long> lastUsageBone = new HashMap<String, Long>();
    20. private Map<String, Long> lastUsageLapis = new HashMap<String, Long>();
    21. private final int cdyellow = getConfig().getInt("cool-down-yellow");
    22. private final int cdorange = getConfig().getInt("cool-down-orange");
    23. private final int cdbone = getConfig().getInt("cool-down-bone-meal");
    24. private final int cdlapis = getConfig().getInt("cool-down-lapis");
    25.  
    26.  
    27. public void onEnable() {
    28. Bukkit.getPluginManager().registerEvents(this, this);
    29. saveDefaultConfig();
    30. }
    31.  
    32. @SuppressWarnings("deprecation")
    33. @EventHandler
    34. public void onClick(PlayerInteractEvent e) {
    35. if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
    36. if (e.getClickedBlock().getType() == Material.INK_SACK) {
    37. Player p = e.getPlayer();
    38.  
    39. if (p.getHealth() != p.getMaxHealth()) {
    40. if (e.getClickedBlock().getData() == 4) {
    41. //lapis
    42. long lastUsed = 0;
    43.  
    44. if (lastUsageLapis.containsKey(p.getName())) {
    45.  
    46. lastUsed = lastUsageLapis.get(p.getName());
    47.  
    48.  
    49. }
    50.  
    51. int cdmillis10 = cdlapis * 1000;
    52.  
    53. if (System.currentTimeMillis() - lastUsed >= cdmillis10) {
    54.  
    55. // it works
    56.  
    57.  
    58. double pHealth = p.getHealth();
    59. double pMaxHealth = p.getMaxHealth();
    60. int pHeal = getConfig().getInt("heal-lapis");
    61.  
    62.  
    63. if (pHealth + pHeal > pMaxHealth) {
    64. p.setHealth(pMaxHealth);
    65. } else {
    66. p.setFoodLevel(pHeal + (int) pHealth);
    67. }
    68.  
    69. if (p.getItemInHand().getAmount() > 1) {
    70. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    71. } else {
    72. p.setItemInHand(null);
    73. }
    74.  
    75. } else {
    76.  
    77. int timeLeft = (int) (cdlapis - ((System.currentTimeMillis() - lastUsed) / 1000));
    78.  
    79. //player.sendMessage("This ability is on cooldown for you for another " + timeLeft + " seconds.");
    80. }
    81. }
    82. if (e.getClickedBlock().getData() == 11) {
    83. //yellow
    84.  
    85. long lastUsed = 0;
    86.  
    87. if (lastUsageYellow.containsKey(p.getName())) {
    88.  
    89. lastUsed = lastUsageYellow.get(p.getName());
    90.  
    91.  
    92. }
    93.  
    94. int cdmillis10 = cdyellow * 1000;
    95.  
    96. if (System.currentTimeMillis() - lastUsed >= cdmillis10) {
    97.  
    98. // it works
    99.  
    100. double pHealth = p.getHealth();
    101. double pMaxHealth = p.getMaxHealth();
    102. int pHeal = getConfig().getInt("heal-yellow");
    103.  
    104.  
    105. if (pHealth + pHeal > pMaxHealth) {
    106. p.setHealth(pMaxHealth);
    107. } else {
    108. p.setFoodLevel(pHeal + (int) pHealth);
    109. }
    110.  
    111. if (p.getItemInHand().getAmount() > 1) {
    112. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    113. } else {
    114. p.setItemInHand(null);
    115. }
    116.  
    117. } else {
    118.  
    119. int timeLeft = (int) (cdyellow - ((System.currentTimeMillis() - lastUsed) / 1000));
    120.  
    121. //player.sendMessage("This ability is on cooldown for you for another " + timeLeft + " seconds.");
    122. }
    123.  
    124. }
    125. if (e.getClickedBlock().getData() == 14) {
    126. //orange
    127.  
    128. long lastUsed = 0;
    129.  
    130. if (lastUsageOrange.containsKey(p.getName())) {
    131.  
    132. lastUsed = lastUsageOrange.get(p.getName());
    133.  
    134.  
    135. }
    136.  
    137. int cdmillis10 = cdorange * 1000;
    138.  
    139. if (System.currentTimeMillis() - lastUsed >= cdmillis10) {
    140.  
    141. // it works
    142.  
    143. double pHealth = p.getHealth();
    144. double pMaxHealth = p.getMaxHealth();
    145. int pHeal = getConfig().getInt("heal-orange");
    146.  
    147.  
    148. if (pHealth + pHeal > pMaxHealth) {
    149. p.setHealth(pMaxHealth);
    150. } else {
    151. p.setFoodLevel(pHeal + (int) pHealth);
    152. }
    153.  
    154. if (p.getItemInHand().getAmount() > 1) {
    155. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    156. } else {
    157. p.setItemInHand(null);
    158. }
    159.  
    160.  
    161. } else {
    162.  
    163. int timeLeft = (int) (cdorange - ((System.currentTimeMillis() - lastUsed) / 1000));
    164.  
    165. //player.sendMessage("This ability is on cooldown for you for another " + timeLeft + " seconds.");
    166. }
    167. }
    168. if (e.getClickedBlock().getData() == 15) {
    169. //bone meal
    170.  
    171.  
    172. long lastUsed = 0;
    173.  
    174. if (lastUsageBone.containsKey(p.getName())) {
    175.  
    176. lastUsed = lastUsageBone.get(p.getName());
    177.  
    178.  
    179. }
    180.  
    181. int cdmillis10 = cdbone * 1000;
    182.  
    183. if (System.currentTimeMillis() - lastUsed >= cdmillis10) {
    184.  
    185. // it works
    186.  
    187.  
    188. double pHealth = p.getHealth();
    189. double pMaxHealth = p.getMaxHealth();
    190. int pHeal = getConfig().getInt("heal-bone-meal");
    191.  
    192.  
    193. if (pHealth + pHeal > pMaxHealth) {
    194. p.setHealth(pMaxHealth);
    195. } else {
    196. p.setFoodLevel(pHeal + (int) pHealth);
    197. }
    198.  
    199. if (p.getItemInHand().getAmount() > 1) {
    200. p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
    201. } else {
    202. p.setItemInHand(null);
    203. }
    204.  
    205.  
    206. } else {
    207.  
    208. int timeLeft = (int) (cdbone - ((System.currentTimeMillis() - lastUsed) / 1000));
    209.  
    210. //player.sendMessage("This ability is on cooldown for you for another " + timeLeft + " seconds.");
    211. }
    212. }
    213.  
    214. }
    215. }
    216. }
    217. }
    218. }
    219.  
    220.  



    my config

    Code:
    cool-down-yellow: 5
    heal-yellow: 5
    cool-down-orange: 5
    heal-orange: 5
    cool-down-bone-meal: 5
    heal-bone-meal: 5
    cool-down-lapis: 5
    heal-lapis: 5
    my plugin.yml

    Code:
    name: NewFood
    version: 1.0.0
    main: me.trevor.bukkit.NewFood
    author: 15987632
    description: Adds new foods to minecraft with cooldowns
     
  2. Offline

    dchaosknight

    15987632
    I believe what's happening here is that you're calling getConfig() before Bukkit creates the config.yml file. Try defining your ints in the onEnable() method and see if that fixes it.
     
  3. Offline

    15987632

    dchaosknight this was one of my many errors thanks. I fixed all of them btw :p
     
  4. Offline

    ChipDev

    Read.. the.. freaking.. sticky.. threads...
     
Thread Status:
Not open for further replies.

Share This Page