Jump to content

My listener for subscribe events is don't work.


WizardBR

Recommended Posts

Hello everyone! I'm a begineer developer in forge, the reason i'm here is because my listener to events is don't work!

This is simple, i ever register the listener in MinecraftForge.EVENT_BUS and FMLCommonHandler in EventHandlers.

But, in game my debug not is calle

 

My forge version is 1.7.10, and I know that the doubts about this version are gone.

Code:
 

	@EventHandler
	private void onInit(FMLInitializationEvent event) {
		commonProxy.doSomething(); 
		
		GuardListener listener = new GuardListener();

		MinecraftForge.EVENT_BUS.register(listener);
		FMLCommonHandler.instance().bus().register(listener);	
	}

My listener is:

	private final CuboidRepository cuboidRepository = CuboidRepository.getInstance();
	
	@SubscribeEvent
	private void onJoin(PlayerEvent.PlayerLoggedInEvent event) {
		System.out.println(event);
	}
	
	@SubscribeEvent(priority = EventPriority.HIGHEST)
	private void onDamage(LivingAttackEvent event) {
		System.out.println(event);
		
		if(!(event.entityLiving instanceof EntityPlayer)) return;
		
		Cuboid cuboid = cuboidRepository.has(event.entityLiving.worldObj, event.entityLiving.chunkCoordX, event.entityLiving.chunkCoordY, event.entityLiving.chunkCoordZ);
		
		if(cuboid == null) return; 
		
		event.setCanceled(true); TextMessage.of().apply("The pvp is disabled in your region!").color(EnumChatFormatting.RED).build((EntityPlayer) event.entityLiving);
	}
	
	@SubscribeEvent(priority = EventPriority.HIGHEST)
	private void onDamaged(AttackEntityEvent event) {
		System.out.println(event);
		
		if(!(event.target instanceof EntityPlayer)) return;
		
		Cuboid cuboid = cuboidRepository.has(event.entityPlayer.worldObj, event.entityPlayer.playerLocation.posX, event.entityPlayer.playerLocation.posY, event.entityPlayer.playerLocation.posZ);
		
		if(cuboid == null) return;
		
		event.setCanceled(true); TextMessage.of().apply("The pvp is disabled in your region!").color(EnumChatFormatting.RED).build(event.entityPlayer);
	}

 

There will be some errors in the code or maybe even crazy, but it's simple, because I just want to see if I get messages from the events ...

EDIT: This mod is server-side!

Edited by WizardBR
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.