Development Assistance Error with "registerEvents"

Discussion in 'Plugin Help/Development/Requests' started by Azen0xCore, Jun 26, 2015.

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

    Azen0xCore

    Hi,
    I would create a plugin with an event (a very litle plugin ;) )
    Sources:
    package fr.azenox.test_2_events;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin implements Listener{

    PEListener listener = new PEListener(this);

    public void onEnable()
    {
    getConfig().options().copyDefaults(true);
    saveConfig();
    PluginManager pluginManager = getServer().getPluginManager();
    pluginManager.registerEvents(listener, this);
    }
    public void onDisable() {

    }

    public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {

    Player player = (Player) sender;

    if(Label.equalsIgnoreCase("java")){
    player.sendMessage("Just Another Vague Acronym");
    }

    return false;
    }


    public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    player.sendMessage("Hello " + player + " !");
    }

    }

    There, the problem is "registerEvents", it is underlined in red. The fix is "Add cast to 'pluginManager'".


    And the PEListener.java :


    package fr.azenox.test_2_events;

    import org.bukkit.event.Listener;

    public class PEListener implements Listener {

    public PEListener(Main plugin){
    this.plugin = plugin;
    }
    }

    And here I have a problem too. this.'plugin' is underlined (in red) and I have 1 fix : "Create field 'plugin' in type 'PEListener'"


    I use bukkit-1.8.1-R4-20111031.021102-1 (And Eclipse).

    Can you help me ?
     
  2. Offline

    Xerox262

    Before this
    public PEListener(Main plugin){
    this.plugin = plugin;
    }

    you must have this
    public Main plugin;
     
  3. Offline

    Azen0xCore

    Ok, I apply it (And I Create getter and setter for 'plugin', because i had a warning):

    package fr.azenox.test_2_events;

    import org.bukkit.event.Listener;

    public class PEListener implements Listener {

    private Main plugin;

    public PEListener(Main plugin){
    this.setPlugin(plugin);
    }

    public Main getPlugin() {
    return plugin;
    }

    public void setPlugin(Main plugin) {
    this.plugin = plugin;
    }
    }

    But "registerEvents" is still underlined in the Main class...
     
  4. Offline

    Xerox262

    Try removing this
    PluginManager pluginManager = getServer().getPluginManager();
    pluginManager.registerEvents(listener, this);

    and putting this
    getServer().getPluginManager().registerEvents(listener, this);
     
  5. Offline

    Azen0xCore

    I have the same error:
    The method registerEvents(PEListener, Main) is undefined for the type PluginManager
     
  6. Offline

    Xerox262

    Replace
    PEListener listener = new PEListener(this);
    With
    Listener listener = new PEListener(this);
    #Polymorph
     
  7. Offline

    Boomer

    The failure to use @EventHandler before your event handler code is also a contributing factor to the remaining not-working-right issues once the other issues are resolved ;)
     
  8. Offline

    Azen0xCore

    Hum, ok...
    I try with another Bukkit version (I was with 1.8.1, now I use 1.8.7 version)
    1) "registerEvents" works at the moment :)
    2) But I have an error here : "package fr.azenox.MsgOnJoin" (My first line :'( ) :
    "The type com.avaje.ebean.EbeanServer cannot be resolved. It is indirectly referenced from required .class files"
     
  9. Offline

    Boomer

    It would be most likely that you are using the wrong jar in your build path... are you using craftbukkit.jar in your build? (or have you added it to your build) OR, have you simply added the different bukkit version to the path, having two different versions of the bukkit jars?

    In the past it was opposite - the ebeans was missing from bukkit, and the craftbukkit had to be included in order to access it. And at one point, particular builds were broken and missing.

    So you'll have to assess your situation and determine what you do have and what you do need in the buildpath first
     
  10. Offline

    Azen0xCore

    That's ok !

    I had just import Bukkit but not craftbukkit (I had import bukkit and craftbukkit and that's work).

    I have a last question, when I type a commands on my server (for example /java):

    public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {

    Player player = (Player) sender;

    if(Label.equalsIgnoreCase("java")){
    player.sendMessage("ยง6Just Another Vague Acronym");
    }

    return false;
    }

    I have this on my server:
    (I type /java)
    {In gold}Just Another Vague Acronym
    {In white}/java


    Why I have the "/java" after the result ?
     
  11. Offline

    Boomer

    return false will cause the server to spit out the /java or whatever else you have in the plugin command usage line if defined.
    return true will tell the server "its okay, i've handled the output i want to send the user, you dont need to add anything else"
     
  12. Offline

    Azen0xCore

    Thanks !
     
Thread Status:
Not open for further replies.

Share This Page