[HELP] FirstPlugin

Discussion in 'Plugin Development' started by rob1998@, Apr 30, 2012.

Thread Status:
Not open for further replies.
  1. I have made a plugin with a tutorial but when I add it to my plugins I get this code:

    09:38:58 [SEVERE] Could not load 'plugins/FirstPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.Error: Unresolved compilation problems:
    The type java.io.InputStream cannot be resolved. It is indirectly referenced from required .class files
    The type java.io.File cannot be resolved. It is indirectly referenced from required .class files
    The import java.util.logging.Logger cannot be resolved
    The hierarchy of the type FirstPlugin is inconsistent
    Logger cannot be resolved to a type
    Logger cannot be resolved

    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:148)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183)
    at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:53)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:422)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.Error: Unresolved compilation problems:
    The type java.io.InputStream cannot be resolved. It is indirectly referenced from required .class files
    The type java.io.File cannot be resolved. It is indirectly referenced from required .class files
    The import java.util.logging.Logger cannot be resolved
    The hierarchy of the type FirstPlugin is inconsistent
    Logger cannot be resolved to a type
    Logger cannot be resolved

    at com.gmail.grob1998.FirstPlugin.FirstPlugin.<init>(FirstPlugin.java:1)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:144)
    ... 8 more
     
  2. Unresolved compilation problems <- means you see the problem in your IDE (and it will provide you with hints how to fix it). Also we don't know your code, so we can't know.
     
  3. Offline

    DeadlyScone

    Looks like there is something messed up with initializing, importing or declaring the logger. Post your FirstPlugin.class and when i say "post" post every last bit of the class.
     
  4. FirstPlugin.java:


    package com.gmail.grob1998.FirstPlugin;

    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.logging.Logger;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.event.Event;

    public class FirstPlugin extends JavaPlugin
    {
    public static final Logger log = Logger.getLogger("Minecraft");
    private final FirstPluginBlockListener blockListener = new FirstPluginBlockListener(this);

    public void onEnable()
    {
    getServer().getPluginManager().registerEvents(blockListener,this);
    }

    public void onDisable()
    {

    }
    }


    FirstPluginBlockListener:


    package com.gmail.grob1998.FirstPlugin;

    import org.bukkit.event.Listener;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.Material;

    public class FirstPluginBlockListener implements Listener
    {
    public static FirstPlugin plugin;

    public FirstPluginBlockListener(FirstPlugin plugin)
    {
    this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.NORMAL)
    public void onBlockPlace(BlockPlaceEvent event)
    {
    if (event.getBlockPlaced().getType().equals(Material.DIRT))
    {
    FirstPlugin.log.info(event.getPlayer().getName()+" placed a dirt block!");
    }
    }
    }


    plugin.yml:


    name: FirstPlugin
    main: com.gmail.grob1998.FirstPlugin.FirstPlugin
    version: 1.0
    authors:
    - rob1998
     
  5. Use [ code] [/code] or [ syntax=java] [/syntax] tags (without spaces)

    And some stuff I noticed:
    - Don't asign logger when you create the global variable, asign it inside onEnable() and you can use getLogger() instead
    - blockListener is kinda pointless, just use the new class() inside the registerEvents().... but for such a small plugin you could use the events in the main class.
    - getType() can be used with == on Material. because it's a enum and basically you're comparing numbers.

    But, apart from the unused PluginManager include, I can't see what your editor has a problem with that code... but anyway, here's the shorter version:
    Code:
    package com.gmail.grob1998.FirstPlugin;
    
    import org.bukkit.Material;
    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.logging.Logger;
    import org.bukkit.event.*;
    import org.bukkit.event.block.BlockPlaceEvent;
    
    public class FirstPlugin extends JavaPlugin implements Listener
    {
    	public Logger log;
    	
    	public void onEnable()
    	{
    		log = getLogger();
    		
    		getServer().getPluginManager().registerEvents(this, this);
    	}
    	
    	@EventHandler()
    	public void onBlockPlace(BlockPlaceEvent event)
    	{
    		if(event.getBlockPlaced().getType() == Material.DIRT)
    		{
    			log.info(event.getPlayer().getName()+" placed a dirt block!");
    		}
    	}
    }
     
Thread Status:
Not open for further replies.

Share This Page