Jump to content

Recommended Posts

Posted

I'm sure this has been answered somewhere else, but I have not been able to find it. I have an issue with the PlayerLoggedOutEvent triggering on player logout. Is there an alternative to this or am I just doing something wrong.

 

RSSkills.java

package Jensen.RSSkills;


import java.nio.file.Paths;
import java.util.ArrayList;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = RSSkills.MODID, version = RSSkills.VERSION)
public class RSSkills {

public static final String MODID = "RSSkills";
public static final String VERSION = "0.1";
public static final String DIR = Paths.get("").toAbsolutePath().toString();
public static ArrayList<PlayerSkills> playerSkills = new ArrayList<PlayerSkills>();

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{	

	FMLCommonHandler.instance().bus().register(new OnPlayerLogin());
	FMLCommonHandler.instance().bus().register(new OnPlayerLogout());

}	
}

 

OnPlayerLogout.java

package Jensen.RSSkills;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;


public class OnPlayerLogout {


@SubscribeEvent
public void onLogout(PlayerEvent.PlayerLoggedOutEvent event){
	String username = event.player.getDisplayName();

	//save skills to txt file
	System.out.println("Save Skills for " + username);
	File skills = new File(RSSkills.DIR + "/" + username + ".txt");
	System.out.println(skills.getAbsolutePath());
	try(BufferedWriter writer = Files.newBufferedWriter(skills.toPath(), Charset.forName("US-ASCII")){

		for(int i = 0; i < PlayerSkills.skillNames.length; i++){
			writer.write(RSSkills.playerSkills.get(RSSkills.playerSkills.size()-1).xp[i] + "\n");
		}
		writer.close();
	} catch (IOException e) {e.printStackTrace();}

}

}

 

 

PS: Help if you're going to help, if not do not bother replying. Thanks.[/code]

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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