Advertisement
oxguy3

OxProps.java

Dec 29th, 2011
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.76 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.io.*;
  6.  
  7. /**
  8.  * Class for managing my custom client's properties
  9.  *
  10.  * @author oxguy3
  11.  */
  12. public abstract class OxProps
  13. {
  14.     public static boolean configloaded = false;
  15.     private static Properties props = new Properties();
  16.     private static String[] usernames;
  17.    
  18.     public static void loadConfig() {
  19.         System.out.println("loadConfig() called");
  20.         if (!configloaded) {
  21.             System.out.println("loading config for the first time");
  22.             File cfile = new File("oxconfig.properties");
  23.             boolean configisnew;
  24.            
  25.             if (!cfile.exists()) {
  26.                 System.out.println("cfile failed exists(), creating blank file");
  27.                 try {
  28.                     configisnew = cfile.createNewFile();
  29.                 } catch (IOException e) {
  30.                         e.printStackTrace();
  31.                         configisnew=true;
  32.                 }
  33.             } else {
  34.                 System.out.println("cfile passed exists(), proceding");
  35.                 configisnew=false;
  36.             }
  37.            
  38.             FileInputStream cin = null;
  39.             FileOutputStream cout = null;
  40.             try {
  41.                 cin = new FileInputStream(cfile);
  42.                 cout = new FileOutputStream(cfile);
  43.             } catch (FileNotFoundException e) {
  44.                 e.printStackTrace();
  45.             }
  46.            
  47.             if (!configisnew) { //if the config already existed
  48.                 System.out.println("config already existed");
  49.                 try {
  50.                     props.load(cin);
  51.                 } catch (IOException e) {
  52.                     e.printStackTrace();
  53.                 }
  54.             } else { //if it doesn't exist, and therefore needs to be created
  55.                 System.out.println("creating new config");
  56.                 props.setProperty("names", "oxguy3, Player");
  57.                 props.setProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png");
  58.                 try {
  59.                     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");
  60.                     cout.flush();
  61.                 } catch (IOException e) {
  62.                     e.printStackTrace();
  63.                 }
  64.             }
  65.             String names = props.getProperty("names");
  66.             System.out.println("names: "+names);
  67.             try {
  68.                 usernames = Pattern.compile(", ").split(names);
  69.             } catch (NullPointerException npe) {
  70.                 npe.printStackTrace();
  71.             }
  72.             System.out.println("usernames: "+Arrays.toString(usernames));
  73.             configloaded=true;
  74.         }
  75.     }
  76.    
  77.     public static boolean checkUsername(String username) {
  78.         loadConfig();
  79.         System.out.println("Checking username...");
  80.         for (int i=0; i<usernames.length; i++) {
  81.             System.out.println("comparing "+username+" with config value "+usernames[i]);
  82.             if (username.startsWith(usernames[i])){
  83.                 System.out.println("we got a match!");
  84.                 return true;
  85.             }
  86.         }
  87.         System.out.println("no match found");
  88.         return false;
  89.     }
  90.    
  91.     public static String getCloakUrl() {
  92.         loadConfig();
  93.         return props.getProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png");
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement