Advertisement
captainawesome7

Config.class

May 29th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. package me.captain.SimpleGive; //Package
  2. //Imports
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileWriter;
  6. import java.io.PrintWriter;
  7. import java.util.Properties;
  8.  
  9. public class Config {
  10.    
  11.     /* Here I will explain the basic purpose of this file and the getItem(String item) method.
  12.      * When the command sends the argument to this method, it will look like this:
  13.      * "argument" the argument, as a string, is then put into the getProperty(item). item is what the specified property is
  14.      * for the method, so the argument in the command that the main class sends is changed to item. Based on command context,
  15.      * item can be a name, like stone, or an item id, like 35. This method basically tests to see if it is in the property file,
  16.      * And if it is, it returns the string on the other end of the equals sign. Using this method allows you to let the user to
  17.      * create his own strings and map them to IDs, so he can make stone=1 smoothstone=1 and it will work in game.
  18.      * If that was confusing, don't worry, read the below and you should understand :)
  19.      */
  20.     public static Boolean getMsg(String msg)  // New method, with an argument. You need to specify the argument to use this method
  21.     {
  22.         Properties prop = new Properties(); //Creates The Properties file
  23.         try {
  24.             if (!new File("plugins/SimpleGive/Config.txt").exists()) //Try to see if it exists
  25.             {
  26.                 new File("plugins/SimpleGive").mkdir();// If the directory doesn't exist, make one
  27.                 new File("plugins/SimpleGive/Config.txt").createNewFile(); // if it doesn't, create a new one
  28.                 PrintWriter out = new PrintWriter(new FileWriter("plugins/SimpleGive/Config.txt")); //Specify the path of the new file
  29.                 out.println("# This file is the file for confirm messages");
  30.                 out.println("# To turn off the in game confirm message just change the value to false:");
  31.                 out.println("ItemConfirmMessage=true ");
  32.                 out.println("GiveConfirmMessage=true ");
  33.                 out.close();// Close the output stream
  34.             }  
  35.            
  36.            
  37.             FileInputStream in = new FileInputStream("plugins/SimpleGive/Config.txt");  // Open an input stream
  38.             prop.load(in); // Loads the properties from the input stream
  39.            
  40.            
  41.             String iv = prop.getProperty(msg); // Make the argument (item) a string
  42.             Boolean ii = Boolean.parseBoolean(iv);
  43.             if(iv==null) { // If the property of item is null, return item (this is most likely because it is an item ID,
  44.                 in.close();  // In which case, you want it to return item
  45.                 return false;
  46.             } else {
  47.                 in.close();  // If the property of item isn't null (it exists in the file), then return it
  48.                 return ii;
  49.             }
  50.                
  51.             } catch (Exception e) {
  52.                 System.out.println("[SimpleGive] Error while reading Config.txt!"); // Catch some errors!
  53.                 e.printStackTrace();
  54.             }
  55.         return false;
  56.        
  57.     }
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement