Jump to content

JensenX

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by JensenX

  1. 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]
×
×
  • Create New...

Important Information

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