Posted January 30, 20169 yr Hey guys! So i've written a server tick counter and I'm sure its all correct, but it doesn't seem to be running on the server. Can anyone help me as to figure out why? Here is how I register my code: @EventHandler public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new ServerEvents()); } And here is my code: import java.util.List; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent; public class ServerEvents { int intervalGold = 30; int intervalCounter = 0; //*20 for ticks, *60 for minutes int finalDuration = 1 * 20 * 60; @SubscribeEvent public void onServerTick(ServerTickEvent event) { if(event.phase == Phase.END) { //20 ticks = 1 second - check the counter is finished. if(intervalCounter % finalDuration == 0) { intervalCounter = 1; //Reset counter List<EntityPlayerMP> playerList = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for(EntityPlayerMP player : playerList) { player.addChatMessage(new ChatComponentText("Hello")); } } else { intervalCounter++; } } } }
January 30, 20169 yr did you try some basic debugging? add sysos and check if ur code is getting called etc
January 30, 20169 yr As mentioned, do some basic debugging: put 'System.out.println("Server tick called")' as the first line in your event listener to see if it is actually running, print out the tick counter to see what values it has, etc. Also, if you are going to reset the counter each time it reaches the final duration, use '>=' instead of the modulo '%' operator. There is no point in doing division if the counter simply loops from 1-max over and over again. http://i.imgur.com/NdrFdld.png[/img]
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.