Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

My listener for subscribe events is don't work.

Featured Replies

Posted

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

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.