package net.minecraft.src; import java.util.*; import java.util.regex.*; import java.io.*; /** * Class for managing my custom client's properties * * @author oxguy3 */ public abstract class OxProps { public static boolean configloaded = false; private static Properties props = new Properties(); private static String[] usernames; public static void loadConfig() { System.out.println("loadConfig() called"); if (!configloaded) { System.out.println("loading config for the first time"); File cfile = new File("oxconfig.properties"); boolean configisnew; if (!cfile.exists()) { System.out.println("cfile failed exists(), creating blank file"); try { configisnew = cfile.createNewFile(); } catch (IOException e) { e.printStackTrace(); configisnew=true; } } else { System.out.println("cfile passed exists(), proceding"); configisnew=false; } FileInputStream cin = null; FileOutputStream cout = null; try { cin = new FileInputStream(cfile); cout = new FileOutputStream(cfile); } catch (FileNotFoundException e) { e.printStackTrace(); } if (!configisnew) { //if the config already existed System.out.println("config already existed"); try { props.load(cin); } catch (IOException e) { e.printStackTrace(); } } else { //if it doesn't exist, and therefore needs to be created System.out.println("creating new config"); props.setProperty("names", "oxguy3, Player"); props.setProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png"); try { props.store(cout, "OXGUY3'S CUSTOM CLIENT\n\ncloak_url is the URL to get custom cloaks from\nnames are the usernames to give cloaks to\n"); cout.flush(); } catch (IOException e) { e.printStackTrace(); } } String names = props.getProperty("names"); System.out.println("names: "+names); try { usernames = Pattern.compile(", ").split(names); } catch (NullPointerException npe) { npe.printStackTrace(); } System.out.println("usernames: "+Arrays.toString(usernames)); configloaded=true; } } public static boolean checkUsername(String username) { loadConfig(); System.out.println("Checking username..."); for (int i=0; i