Fahrenheit451 Posted September 17, 2015 Share Posted September 17, 2015 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() { @Override 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) { e.printStackTrace(); } for(Player i : Bukkit.getServer().getOnlinePlayers()){ pw.println(i.getName()+ ":" + i.getLocation().getX() + ":" + i.getLocation().getY() + ":" + i.getLocation().getZ()); } pw.close(); } }, 0L, 200L); Any information appreciated. Quote Link to comment Share on other sites More sharing options...
delpi Posted September 17, 2015 Share Posted September 17, 2015 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. Quote Long time Bukkit & Forge Programmer Happy to try and help Link to comment Share on other sites More sharing options...
Fahrenheit451 Posted September 20, 2015 Author Share Posted September 20, 2015 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: @EventHandler 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: @SubscribeEvent public void onServerTick(TickEvent.ServerTickEvent event) { tickcount++; if (tickcount == 200 ) { task.run(metafile); tickcount = 0; } } Pretty straightforward, and thanks again. F451 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.