Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Getting EntityPlayer in a TickEvent to call another method.


Geometrically
 Share

Recommended Posts

I want to call a method that has a parameter, EntityPlayer player to a TickEvent. I did this with null, and I get a NullPointerExeption. How do I get the entity player there and put it there? My code is attached.

 

The line is 

printMessages(null);

package com.geometrically.SolarApoc.util;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;


public class WorldTickHandler {
	
	public static int ticker;
	@SubscribeEvent
	public void onWorldTick(WorldTickEvent handler){
		ticker++;
		
		//Tick Checkers
		if (ticker > SAConfiguration.dayoneStart){
			SAMethods.beginDayOne();
			System.out.println("Day One has started");
		}
		if (ticker > SAConfiguration.daytwoStart){
			SAMethods.beginDayTwo();
		}
		if (ticker > SAConfiguration.daythreeStart){
			SAMethods.beginDayThree();
		}
		if (ticker > SAConfiguration.dayfourStart){
			SAMethods.beginDayFour();
		}
		if (ticker > SAConfiguration.dayfiveStart){
			SAMethods.beginDayFive();
		}
		
		printMessages(null);
		
	}
	
	public void printMessages(EntityPlayer player){

		//Message Printers
		if (ticker == SAConfiguration.dayoneStart){
			SAMethods.beginDayOne();
			
			player.addChatComponentMessage(new TextComponentString(TextFormatting.RED + "The Solar Apocalypse has started. Day One will now upbring its wrath."));
			System.out.println("!!!!!!!!!!!!!!!!!!!!Day One has started");
		}
		if (ticker == SAConfiguration.daytwoStart){
			SAMethods.beginDayTwo();
			
			
			player.addChatComponentMessage(new TextComponentString(TextFormatting.RED + "The Solar Apocalypse's second wave has arrived. Day Two will now upbring its wrath."));
		}
		if (ticker == SAConfiguration.daythreeStart){
			SAMethods.beginDayThree();
			
			player.addChatComponentMessage(new TextComponentString(TextFormatting.RED + "The Solar Apocalypse's third wave has arrived. Day Three will now upbring its wrath."));
		}
		if (ticker == SAConfiguration.dayfourStart){
			SAMethods.beginDayFour();
			
			player.addChatComponentMessage(new TextComponentString(TextFormatting.RED + "The Solar Apocalypse's fourth wave has arrived. Day Four will now upbring its wrath."));
		}
		if (ticker == SAConfiguration.dayfiveStart){
			SAMethods.beginDayFive();
			
			player.addChatComponentMessage(new TextComponentString(TextFormatting.RED + "The Solar Apocalypse's fifth and final wave has arrived. Let's see how long you can survive. "));
			player.addChatComponentMessage(new TextComponentString(TextFormatting.GOLD + "Escape if you can."));
		}
	}
}

 

Edited by Geometrically
Link to comment
Share on other sites

The handler has a way to get a List of all the players. From the handler you can get the world and from the world you can get said list. For example

 

World worldIn = handler.world;
List<EntityPlayers> playerList = worldIn.playerEntities;

 

That returns a List<EntityPlayers>. You iterate through the list players to then pass a specific player to the printMessages method.

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.