Plugin cannot be null! Please help :)

Discussion in 'Plugin Development' started by FirecatHD, Feb 24, 2014.

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

    FirecatHD

    So everything works perfectly, just that the console get spammed every time the event fires.
    Here is my Main class:
    Code:java
    1. private static Plugin plugin;
    2.  
    3. public static Plugin getMainClass() {
    4. return plugin;
    5. }
    ]

    And then the listener:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(final PlayerToggleSneakEvent e){
    3.  
    4. ItemStack limeDye = new ItemStack(Material.INK_SACK, 1, (short) 14);
    5. ItemMeta meta = limeDye.getItemMeta();
    6. meta.setDisplayName(ChatColor.RED + "Healing Fire Gel");
    7. ArrayList<String> lore = new ArrayList<String>();
    8. lore.add(ChatColor.DARK_GRAY + "Heals 3,5 " + ChatColor.RED + "Hearts" + ChatColor.DARK_GRAY + ", press shift to refill!");
    9. meta.setLore(lore);
    10. limeDye.setItemMeta(meta);
    11.  
    12. final Player p = e.getPlayer();
    13.  
    14. if (Kits.getFirePvP().contains(p.getName())) {
    15.  
    16. if (e.getPlayer().getInventory().contains(limeDye)) return;
    17.  
    18. if (Kits.getHealingCooldown().contains(p.getName())) {
    19.  
    20. p.sendMessage(ChatColor.RED +(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Fire" + ChatColor.YELLOW + "PvP" + ChatColor.DARK_GRAY + "] " + ChatColor.RED + "You can only restock every 15 seconds!")); return; }
    21.  
    22. p.getInventory().setItem(2, limeDye);
    23. p.getInventory().setItem(3, limeDye);
    24. p.getInventory().setItem(4, limeDye);
    25. p.getInventory().setItem(5, limeDye);
    26. p.getInventory().setItem(6, limeDye);
    27. p.getInventory().setItem(7, limeDye);
    28. p.getInventory().setItem(8, limeDye);
    29.  
    30. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 10, 1);
    31.  
    32. p.sendMessage((ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Fire" + ChatColor.YELLOW + "PvP" + ChatColor.DARK_GRAY + "] " + ChatColor.GREEN + "Your " + ChatColor.RED + "Healing Fire Gel " + ChatColor.GREEN + "have been restocked!"));
    33.  
    34. Kits.getHealingCooldown().add(p.getName());
    35.  
    36. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Kits.getMainClass(), new Runnable() {
    37. public void run() {
    38.  
    39. Kits.getHealingCooldown().remove(p.getName());
    40. }
    41. },300 );
    42. }
    43. }
    44. }


    And yes i have registrered events and everything :)
    -Firecat

    Nevermind, i just tested and it wont work :( Anyone know what i can do?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    sgavster

    PHP:
    private final MainClass plugin;
    public 
    YourClass(MainClass plugin) {
    this.plugin plugin;
    }
     
    NathanWolf likes this.
  3. Offline

    FirecatHD

    sgavster

    So this would fix all my problems?
     
  4. Offline

    sgavster

    It should
     
  5. Offline

    FirecatHD

    sgavster

    I did so, but it doesn let me call the method in the listener class :( What should i do?

    Code:java
    1. private final Kits plugin;
    2. public Kits(Kits plugin) {
    3. this.plugin = plugin;
    4. }
    5.  
    6. public Kits getPlugin() {
    7. return plugin;
    8. }


    Thanks.
     
  6. Offline

    Alshain01

    You took away the static modifiers. You have to create an instance that way... or put the static modifiers back.
     
  7. Offline

    Lolmewn Retired Staff

    FirecatHD That is for your listener class. Rename Kits to whatever your listener class is called and, when creating your listener, add 'this' as parameter to the constructor.
     
  8. Offline

    FirecatHD

    Lolmewn

    Im sorry that i am a noob, but the plugin wont load now and here is the stacktrace:

    [20:12:39 INFO]: [Essentials] Disabling Essentials v2.12.1
    [20:12:40 ERROR]: Could not load 'plugins\FirePvP.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: Abnormal plugin type
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:56) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:133) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:313) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:236) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:350) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:77
    1) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.Bukkit.reload(Bukkit.java:279) [craftbukkit.jar:git-Bukkit
    -1.7.2-R0.3-b3020jnks]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:683) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchServerCommand(Craf
    tServer.java:670) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.aw(DedicatedServer.java:
    286) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    51) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.InstantiationException: me.FirecatHD.FirePvP.Kits
    at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_45]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:52) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    ... 15 more
    [20:12:40 INFO]: [Essentials] Loading Essentials v2.12.1
    [20:12:40 INFO]: [Essentials] Enabling Essentials v2.12.1
    [20:12:40 INFO]: Essentials: Using config file enhanced permissions.
    [20:12:40 INFO]: Permissions listed in as player-commands will be given to all u
    sers.
    [20:12:40 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:12:40 INFO]: CONSOLE: Reload complete.

    So yeah, im pretty sure i did what you told me, but i have clearly done something wrong :(

    This is in the Listener class:

    Code:java
    1. private final Kits plugin;
    2. public TrollOpListener(Kits plugin) {
    3. this.plugin = plugin;
    4. }
    5.  
    6. public Kits getPlugin() {
    7. return plugin;
    8. }


    And in main class when i registrer the event:

    Code:java
    1. Bukkit.getServer().getPluginManager()
    2. .registerEvents(new TrollOpListener(this), this);


    Again i apologise for not understanding :)
     
  9. Offline

    Lolmewn Retired Staff

    FirecatHD Should be good, what is your plugin.yml?
     
  10. Offline

    FirecatHD

    Lolmewn

    name: FirePvP
    author: FirecatHD
    version: 1,0
    main: me.FirecatHD.FirePvP.Kits
    description: FirecatHD's own KitPvP plugin, custom coded by FirecatHD.

    commands:

    kit:
    usage: /<command>
    aliases: [k]
    description: Use kits!

    trollOP:
    usage: /<command>
    description: Turn on blood!
    permission: trollop.use
    default: op
     
  11. Offline

    Lolmewn Retired Staff

    FirecatHD Could you throw your whole main class on pastebin and link it here?
     
  12. Offline

    FirecatHD

  13. Offline

    Lolmewn Retired Staff

    FirecatHD Looks good, don't know what the error is. :S
     
  14. Offline

    sgavster

    Do this, in your main class:

    PHP:
    private static Kits kits;
     
     
     
    //ON ENABLE:
     
    kits this;
     
     
     
    //ON DISABLE:
     
    kits null;
     
    //ANYWHERE
     
     
     
    public static final Kits getKits() {
     
    return 
    this.kits;
     
     
  15. Offline

    Lolmewn Retired Staff

  16. Offline

    sgavster

    Lolmewn I know, but thats what he did with my code so I fixed it.
     
  17. Offline

    FirecatHD

    sgavster Lolmewn

    Now it gives me and error on "Kits getKits"
    perhaps you could try editing my code, i will understand what you mean easier, plus i will learn it :)

    Also does any1 know how i can have commands in different classes?
     
  18. Offline

    sgavster

    change return this.kits; to return kits;.
     
  19. Offline

    Lolmewn Retired Staff

  20. Offline

    FirecatHD

    sgavster - Syntax error on token "Kits", @ expected Still says this ;_;
    Lolmewn - I figured it out already but thx anyways :)

    sgavster Lolmewn

    Ok i have one more small question; i have a command with one argument in another class, how am i supposed to registrer that? I cant just registrer the first cmd because i have the same thing in main class sp the one in the separate class will overwrite the one in the main class ;_; What can i do?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  21. Offline

    Lolmewn Retired Staff

    FirecatHD Wat. I have no clue what you're trying to say.
     
  22. Offline

    MordorKing78

    If this is fixed plz help me :D
     
  23. Offline

    FirecatHD

    Lolmewn - I am trying to say that i have the same command in two classes but with different arguments.
    So now i cant do the command that is made in the main class, due to the very similar cmd in the separate class overwrites it. Is that understandable? :3
     
  24. Offline

    Lolmewn Retired Staff

    FirecatHD Yup. Just execute the command in one class, check the variables in that class.
     
  25. Offline

    FirecatHD

    Lolmewn

    This is how i thought to, but idk how exactly im gonna do that, thats why i asked :3

    Lolmewn sgavster

    I acually managed to figure out how to get the mainclass instance by myself :3
    But i really need help with the command argument thing .-.

    Anyone? Just show me a little code >:3

    Bump?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page