Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.captain.SimpleGive; //Package
- //Imports
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.PrintWriter;
- import java.util.Properties;
- public class Config {
- /* Here I will explain the basic purpose of this file and the getItem(String item) method.
- * When the command sends the argument to this method, it will look like this:
- * "argument" the argument, as a string, is then put into the getProperty(item). item is what the specified property is
- * for the method, so the argument in the command that the main class sends is changed to item. Based on command context,
- * 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,
- * 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
- * create his own strings and map them to IDs, so he can make stone=1 smoothstone=1 and it will work in game.
- * If that was confusing, don't worry, read the below and you should understand :)
- */
- public static Boolean getMsg(String msg) // New method, with an argument. You need to specify the argument to use this method
- {
- Properties prop = new Properties(); //Creates The Properties file
- try {
- if (!new File("plugins/SimpleGive/Config.txt").exists()) //Try to see if it exists
- {
- new File("plugins/SimpleGive").mkdir();// If the directory doesn't exist, make one
- new File("plugins/SimpleGive/Config.txt").createNewFile(); // if it doesn't, create a new one
- PrintWriter out = new PrintWriter(new FileWriter("plugins/SimpleGive/Config.txt")); //Specify the path of the new file
- out.println("# This file is the file for confirm messages");
- out.println("# To turn off the in game confirm message just change the value to false:");
- out.println("ItemConfirmMessage=true ");
- out.println("GiveConfirmMessage=true ");
- out.close();// Close the output stream
- }
- FileInputStream in = new FileInputStream("plugins/SimpleGive/Config.txt"); // Open an input stream
- prop.load(in); // Loads the properties from the input stream
- String iv = prop.getProperty(msg); // Make the argument (item) a string
- Boolean ii = Boolean.parseBoolean(iv);
- if(iv==null) { // If the property of item is null, return item (this is most likely because it is an item ID,
- in.close(); // In which case, you want it to return item
- return false;
- } else {
- in.close(); // If the property of item isn't null (it exists in the file), then return it
- return ii;
- }
- } catch (Exception e) {
- System.out.println("[SimpleGive] Error while reading Config.txt!"); // Catch some errors!
- e.printStackTrace();
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement