0

I've two classes under the same package Class names are "TestPlugin" and "Pokemon". The error I get is in the class TestPlugin at line 7 where there's written "New Pokemon". The error is "Cannot be resolved to a variable". I want the TestPlugin to acces the code in Pokemon so it can be used. What should I do to fix this problem? New to bukkit plugin creation so don't make the answer too advanced please. "I don't own this code/plugin. I've it for educational purposes only!". If you wonder what bukkit libary I'm using, it's the recommended build "craftbukkit-1.6.4-R2.0".

TestPlugin's code:

package com.hotmail.marrunsilkeborg.plugins.testplugin;

import org.bukkit.plugin.java.JavaPlugin;   

public class TestPlugin extends JavaPlugin{
    public void onEnable(){
        getServer().getPluginManager().registerEvents(new Pokemon, this);

    }
}

Pokemon's code:

package com.hotmail.marrunsilkeborg.plugins.testplugin;

import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;

public class Pokemon implements Listener{

    @EventHandler
    public void onBlockPlace(BlockPlaceEvent event){
        Player p = event.getPlayer();
        Block bp = event.getBlockPlaced();


        p.sendMessage("You've placed a " + bp.getType().toString());        
    }
}

2 Answers 2

2

Change line 7 to this.getServer().getPluginManager().registerEvents(new Pokemon(this), this); also think about adding a on disable

Sign up to request clarification or add additional context in comments.

Comments

0

You wanted to call Pokemon's constructor, so use new Pokemon() with the parentheses.

As @Welsar55 mentioned, use new Pokemon(this) if you are referencing your plugin in the Pokemon constructor (common-practice for Java plugins), i.e. where your Pokemon constructor is:

public Pokemon(TestPlugin myPlugin) {
    this.plugin = myPlugin;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.