Error while registering Listeners

Discussion in 'Nukkit discussions and help' started by JackboyPlay, 4/12/16.

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
We welcome you on our site. This site is devoted to the Nukkit project and all that is connected with him. Here you can communicate, download plugins, also many other things get acquainted! Register the account right now :3
  1. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    Hello folks,
    I've a problem!
    If I register the Listeners without my login plugin is enabled my Core plugin works, but if the login plugin is enabled, the register process from the listeners wont work!
    Any one know why?
     
  2. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
  3. fromgate

    fromgate Administrator

    Messages:
    681
    Likes Received:
    192
    I'm not sure that I understand you right:(

    Can you provide more details?
     
  4. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    If I enable my 1st plugin called Core the plugin Listeners (JoinEvent, QuitEvent,...) works but if I enable my 2nd plugin called JClogin my Core plugin wont work anymore
     
  5. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    @fromgate are that enough informations?
     
  6. Tee7even

    Tee7even Nukkit Coders Team

    Messages:
    126
    Likes Received:
    27
     
    fromgate likes this.
  7. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    @Tee7even register listeners in JClogin:
    PHP:
    private void registerListener(){
    Server.getInstance().getPluginManager().registerEvents(new BlockBreak(), this);
    Server.getInstance().getPluginManager().registerEvents(new BlockPlace(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerChat(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerInteract(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerJoin(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerQuit(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerPreLogin(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerMove(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerCommandPreProcess(), this);
    Server.getInstance().getPluginManager().registerEvents(new EntityDamage(), this);
    }
    register listeners in Core:
    PHP:
    public void registerEvents(){
    Server.getInstance().getPluginManager().registerEvents(new BlockBreak(), this);
    Server.getInstance().getPluginManager().registerEvents(new BlockPlace(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerInteract(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerChat(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerJoin(), this);
    Server.getInstance().getPluginManager().registerEvents(new PlayerQuit(), this);
    }
    If you need more informations say it :)
     
  8. Tee7even

    Tee7even Nukkit Coders Team

    Messages:
    126
    Likes Received:
    27
    Hm, could you show us the listeners themselves? And there is no need to create a separate class for every event type.
     
  9. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    i know that I wont need a class for each listener but I like it with more classes :D
     
  10. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    A BlockBreakEvent Listener in Core:
    PHP:
    package me.JackboyPlay.Listener;

    import cn.nukkit.Player;
    import cn.nukkit.block.Block;
    import cn.nukkit.event.EventHandler;
    import cn.nukkit.event.Listener;
    import cn.nukkit.event.block.BlockBreakEvent;
    import me.JackboyPlay.JCKern.WorldEdit;

    public class 
    BlockBreak implements Listener{

    [
    pre][code]@EventHandler
    public void onBlockBreak(BlockBreakEvent e) {
        
    Player player e.getPlayer();
        
    Block block e.getBlock();
        if (
    player.getGamemode() == 1) {
            if (
    e.getItem().getId() == 271) {
                if (
    WorldEdit.pos1x.containsKey(player.getName())) {
                    
    WorldEdit.pos1x.remove(player.getName());
                }
                if (
    WorldEdit.pos1y.containsKey(player.getName())) {
                    
    WorldEdit.pos1y.remove(player.getName());
                }
                if (
    WorldEdit.pos1z.containsKey(player.getName())) {
                    
    WorldEdit.pos1z.remove(player.getName());
                }
                
    WorldEdit.pos1x.put(player.getName(), block.getFloorX());
                
    WorldEdit.pos1y.put(player.getName(), block.getFloorY());
                
    WorldEdit.pos1z.put(player.getName(), block.getFloorZ());
                
    player.sendMessage("§c[§aWE§c] §ePosition §a1§e gesetzt! §7[§c" String.valueOf(block.getFloorX()) + "§7:§c" String.valueOf(block.getFloorY()) + "§7:§c" String.valueOf(block.getFloorZ()) + "§7]");
                
    e.setCancelled();
            }
        }
    }[/
    code][/pre]
    }
    A listener in JCLogin:
    PHP:
    package me.JackboyPlay.Listener;

    import cn.nukkit.Player;
    import cn.nukkit.event.EventHandler;
    import cn.nukkit.event.EventPriority;
    import cn.nukkit.event.Listener;
    import cn.nukkit.event.block.BlockBreakEvent;
    import me.JackboyPlay.JCLogin.JCLogin;

    public class 
    BlockBreak implements Listener{

    [
    pre][code]@EventHandler(priority EventPriority.HIGHEST)
    public 
    void onBreak(BlockBreakEvent e){
        
    Player player e.getPlayer();
        if(!(
    JCLogin.isLogged(player))){
            
    e.setCancelled();
        }
    }[/
    code][/pre]
    }
    PS: Event isnt cancelled in JCLogin because I am already logged in and I can break blocks
     
  11. JackboyPlay

    JackboyPlay Пользователь

    Messages:
    19
    Likes Received:
    1
    Minecraft:
    JackboyPlay
    Fixed it ^^
     

Share This Page