Jump to content

Need some help getting player online list and runnable task in forge


Recommended Posts

Hi. Anyone know how to accomlish this with the Forge API? I have been searching for a number of days and simply can not find the appropriate information on the web.


I wrote a simple bukkit plugin for our servers that writes out player positions into a file every 200 ticks, but I now need to write this for our Forge servers also. This meta data is used by scripts and programs outside of the minecraft server. Pretty Simple piece of code, but I simply haven't found suitable info to convert to Forge. I have the basic forge Mod running based on the example provided with Forge API.


BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
            public void run() {
       		// open the meta file for writing
       		File mfile = new File(metafile);
       		FileWriter writer;
       		try {
       			writer = new FileWriter(mfile, false);
       			pw = new PrintWriter(writer);
       		} catch(IOException e) {
            	for(Player i : Bukkit.getServer().getOnlinePlayers()){
            		pw.println(i.getName()+ ":" + i.getLocation().getX() + ":" + i.getLocation().getY() + ":" + i.getLocation().getZ());
}, 0L, 200L);


Any information appreciated.


Link to comment
Share on other sites

Look for tutorials on tick handler or events.  It is the method you can use for your trigger.  you will have to implement a basic timer for 200 ticks from it.


There is an equivalent getserver().getOnlinePlayers, I just don't remember the context off the top of my head. might be "MinecraftServer().getserver.....", you will have to check.  Change Player to EntityPlayer.


All your file stuff for writing should be fine.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Thanks a lot both of you. That go me on the right track and I have this working nicely.


For those interested (and for any further refinements, gotchas or improvements):


I created a new basic ticker class that I registered in the preInit eventhandler routine of the main class:


    public void preInit (FMLPreInitializationEvent event) {
      FMLCommonHandler.instance().bus().register(new OBTicker("config/"+metafile));


and in the ticker class I created a subscribe event onServerTick routine that counts 200 ticks (5 seconds) and runs the command to dump the meta data out:


 public void onServerTick(TickEvent.ServerTickEvent event) {


	 if (tickcount == 200 ) {
	    tickcount = 0;


Pretty straightforward, and thanks again.



Link to comment
Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

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