[Solved] Problems with (plugin), please help me!!!!

Discussion in 'Plugin Development' started by Luloak2, Feb 22, 2012.

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

    Luloak2

    PHP:
    public NPCManager m = new NPCManager(plugin);
    Eclipse underlines "(plugin)" , I don't know what is wrong....


    Here is my server.log:


    Code:
    2012-02-22 08:58:05 [INFO] This server is running CraftBukkit version git-Bukkit-1.1-R4-b1938jnks (MC: 1.1) (Implementing API version 1.1-R4)
    2012-02-22 08:58:05 [SEVERE] Could not load 'plugins\PvP_Area.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:136)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:286)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:201)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:164)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:140)
    at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:148)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.Error: Unresolved compilation problem:
    plugin cannot be resolved to a variable
    at me.Luloak2.PvP_Area.PvP_Area.<init>(PvP_Area.java:22)
    ... 13 more
    I tried this, too:

    PHP:
    private JavaPlugin plugin;
    public 
    NPCManager m = new NPCManager(plugin);
    And get this errors....

    Code:
    2012-02-22 09:40:14 [INFO] This server is running CraftBukkit version git-Bukkit-1.1-R4-b1938jnks (MC: 1.1) (Implementing API version 1.1-R4)
    2012-02-22 09:40:14 [SEVERE] Could not load 'plugins\PvP_Area.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:136)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:286)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:201)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:164)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:140)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:148)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:200)
        at com.topcat.npclib.NPCManager.<init>(NPCManager.java:52)
        at me.Luloak2.PvP_Area.PvP_Area.<init>(PvP_Area.java:25)
        ... 13 more
     
  2. Offline

    CRAZYxMUNK3Y

    It is caused by the Class PvP_Arena on line 25.

    Can you post the line (a few before and after it too) on here, or use pastebin?

    Also, for future reference, use this guide to troubleshoot errors.
     
  3. Offline

    SirTyler

    Only need to look at the caused by line. says "plugin is null", meaning you did not intialize your plugin variable.
    Code:java
    1.  
    2. private JavaPlugin plugin
    3. public NPCManager m = new NPCManager(plugin);
    4.  

    that is the same as
    Code:java
    1.  
    2. private JavaPlugin plugin = null;
    3. public NPCManager m = new NPCManager(null);
    4.  
     
  4. Offline

    Luloak2

    SirTyler
    But how can I initialize my Plugin variable?

    CRAZYxMUNK3Y
    Here is the piece of code:

    PHP:
    package me.Luloak2.PvP_Area;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.topcat.npclib.NPCManager;
     
     
    public class 
    PvP_Area extends JavaPlugin
    {
     
     
        private 
    JavaPlugin plugin;
        public 
    NPCManager m = new NPCManager(plugin);
     
        protected 
    FileConfiguration config;
     
        
    //Definition aller Variablen
        
    int Xoperate_Point1;
        
    int Zoperate_Point1;
        
    int Xoperate_Point2;
        
    int Zoperate_Point2;
        
    int damage_of_player;
        
    int health_of_damaged_player;
        
    String damaged_player_name;
        
    Player damaged_player;
        
    int damaged_player_location_X;
        
    int damaged_player_location_Z;
        
    int damage_to_attacker;
        
    String message_to_attacker;
     
     
        public 
    void onEnable()
        {
     
        }
     
  5. Offline

    SirTyler

    Since its in your main class do this:
    Code:java
    1.  
    2. public NPCManager m = new NPCManager(this);
    3.  
     
  6. Offline

    CRAZYxMUNK3Y

    Scrap that, Tyler beat me to it :p
     
  7. Offline

    Luloak2

    No, it is not in my main class, I am using the NPCLib, and it is in "com.topcat.npclip ". I asked in the thread for an example:

    But Eclipse is underlining " (plugin)"....
     
  8. Offline

    SirTyler

    because like we said you are using a variable that is null, so if it not in the main class (which doesn't really make sense why you don't have it there...) then make plugin = the main class.

    Edit: if you don't know what null is and how to fix it then you really should learn java first...
     
  9. Offline

    dillyg10

    if it is in a seperate class, use somthing like this..
    Code:
    private YourMainClass plugin;
    public static void YourMethod(YourMainClass instance) {
    plugin = instance;
    }
    //then in your onEnable call
    YourClass.YourMethod(this);
     
  10. Offline

    Luloak2

    Maybe I am too stupid...
    I will explain everything again, maybe I found not the right words...

    I want to spawn an human NPC with the NPCLib.
    Here is the interesting part of the "NPCManager.java" in "com.topcat.npclib":

    PHP:
    package com.topcat.npclib;
     
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Map;
    import java.util.logging.Level;
     
    import net.minecraft.server.Entity;
    import net.minecraft.server.ItemInWorldManager;
    import net.minecraft.server.WorldServer;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.entity.CraftEntity;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.server.PluginDisableEvent;
    import org.bukkit.event.world.ChunkLoadEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.topcat.npclib.entity.HumanNPC;
    import com.topcat.npclib.entity.NPC;
    import com.topcat.npclib.nms.BServer;
    import com.topcat.npclib.nms.BWorld;
    import com.topcat.npclib.nms.NPCEntity;
    import com.topcat.npclib.nms.NPCNetworkManager;
     
     
    public class 
    NPCManager {
     
        private 
    HashMap<StringNPCnpcs = new HashMap<StringNPC>();
        private 
    BServer server;
        private 
    int taskid;
        private 
    Map<WorldBWorldbworlds = new HashMap<WorldBWorld>();
        private 
    NPCNetworkManager npcNetworkManager;
        public static 
    JavaPlugin plugin;
     
        public 
    NPCManager(JavaPlugin plugin) {
            
    server BServer.getInstance();
     
            
    npcNetworkManager = new NPCNetworkManager();
            
    NPCManager.plugin plugin;
            
    taskid Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                @
    Override
                
    public void run() {
                    
    HashSet<StringtoRemove = new HashSet<String>();
                    for (
    String i npcs.keySet()) {
                        
    Entity j npcs.get(i).getEntity();
                        
    j.am();
                        if (
    j.dead) {
                            
    toRemove.add(i);
                        }
                    }
                    for (
    String n toRemove) {
                        
    npcs.remove(n);
                    }
                }
            }, 
    1L1L);
            
    Bukkit.getServer().getPluginManager().registerEvents(new SL(), plugin);
            
    Bukkit.getServer().getPluginManager().registerEvents(new WL(), plugin);
        }
    My plugin is in the package "me.Luloak2.PvP_Area", and the classwhich I want to spawn an HumanNPC from is "PvP_Area.java"

    Here is my PvP_Area.java:

    PHP:
    package me.Luloak2.PvP_Area;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.topcat.npclib.NPCManager;
     
     
    public class 
    PvP_Area extends JavaPlugin
    {   
        protected 
    FileConfiguration config;
     
       [
    B] public NPCManager m = new NPCManager(plugin);[/B]
       
        public 
    void onEnable()
        {                
                        
    //Player Listener
                        
    getServer().getPluginManager().registerEvents(new MKclass(), this);
        }
       
        public 
    void onDisable()
        {
     
        }
       
        
    //************Beginn innere Klasse********************
            
    public class MKclass implements Listener
            
    {   
                @
    EventHandler(priority EventPriority.HIGHEST)
                public 
    void onEnityDamage (EntityDamageEvent event)
                {
                      
    m.spawnHumanNPC("Example NPC"example_location);      
                }
             }
         
    //************Ende innere Klasse**********************
            
    public final MKclass pl = new MKclass();
     
    }
    (I shortened the class a bit, then you can understand it better I think)

    I asked in the NPCLib thread for an example, here it is:

    PHP:
        public NPCManager m = new NPCManager(plugin);
     
        public 
    void create(){
        
    m.spawnHumanNPC("name of npc"location);
        }
     
    But Eclipse is getting an error and underlines "(plugin)".
    The error message is: "plugin cannot be resolved to a variable".
    I know that the "(plugin)" is null, but could anyone give me an example, how I can fix that....
     
  11. Offline

    SirTyler

    A
    Again I say... define either the NPCManager at main and do new NPCManager(this); or do JavaPlugin plugin = this; on the Main class, then call to that from another class. If you really can not get this working (have no idea why you cant its simple definition and calling) then try Bukkit.getPluginManager().getPlugin("plugin name here"); that should work as a last resort.
     
  12. Offline

    Luloak2

    PHP:
    JavaPlugin plugin this;
        public 
    NPCManager m = new NPCManager(plugin);
       
        public 
    void onEnable()
        {
         }
    I have done this, but there are these errors:

    2012-02-22 15:11:43 [INFO] This server is running CraftBukkit version git-Bukkit-1.1-R4-b1938jnks (MC: 1.1) (Implementing API version 1.1-R4)
    2012-02-22 15:11:43 [SEVERE] Could not load 'plugins\PvP_Area.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:136)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:286)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:201)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:164)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:140)
    at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:148)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register com.topcat.npclib.NPCManager$SL@106ee1f while not enabled
    at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginManager.java:536)
    at com.topcat.npclib.NPCManager.<init>(NPCManager.java:68)
    at me.Luloak2.PvP_Area.PvP_Area.<init>(PvP_Area.java:102)
    ... 13 more
     
  13. Offline

    SirTyler

    I guess this is my fault for saying to do that exact line, do this.
    Code:java
    1.  
    2. public JavaPlugin plugin;
    3. public NPCManager m;
    4. public void onEnable() {
    5. plugin = this;
    6. m = new NPCManager(plugin);
    7. }
    8.  

    I do not see why you can not simply do new NPCManager(this);
    because you are running this code in your main class and would work.
     
    Luloak2 likes this.
  14. Offline

    Luloak2

    Yeah, thank you so much :) Now it is working :) Great!
     
Thread Status:
Not open for further replies.

Share This Page