Error while registering Listeners

JackboyPlay

Пользователь
[BCOLOR=rgb(255, 255, 255)]Hello folks, [/BCOLOR]
[BCOLOR=rgb(255, 255, 255)]I've a problem![/BCOLOR]
[BCOLOR=rgb(255, 255, 255)]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![/BCOLOR]
[BCOLOR=rgb(255, 255, 255)]Any one know why?[/BCOLOR]
 

JackboyPlay

Пользователь
I'm not sure that I understand you right:(

Can you provide more details?
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
 

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 :)
 

Tee7even

Nukkit Coders Team
@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 :)
Hm, could you show us the listeners themselves? And there is no need to create a separate class for every event type.
 

JackboyPlay

Пользователь
Hm, could you show us the listeners themselves? And there is no need to create a separate class for every event type.
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{
	
	@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();
			}
		}
	}
}
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{

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