Last active
May 17, 2017 17:26
-
-
Save HelixOW/c594396048496d93b0d3901710fca87d to your computer and use it in GitHub Desktop.
Shows how the Storage system in AlphaLibary can be used!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//init your yml file storage here | |
private static YamlStorage yamlStorage = new YamlStorage("plugins/AlphaLibary", "config.yml"); | |
//init your json file storage here | |
private static JsonStorage jsonStorage = new JsonStorage("plugins/AlphaLibary", "example.json"); | |
//init your mysql storage here | |
private static MySQLStorage mySQLStorage = new MySQLStorage(new MySQLDatabase("Your table", "Your database")); | |
//adding some values | |
public static void setDefaultYAML() { | |
yamlStorage.setValue( | |
new StorageKey("prefix"), //is used to identify where to get the value from | |
new StorageItem("&7[&6AL&7] ") //is the value for 'prefix' | |
); //this will store a new entry | |
yamlStorage.setValue( | |
new StorageKey("you can also save instances of classes here"), | |
new StorageItem(new Example("Hello!", false)) //simply put in your instances here :) | |
); | |
} | |
//getting some values from the file | |
public static Example getExampleYAML() { | |
return yamlStorage.getValue( | |
new StorageKey("you can also save instances of classes here"), //Must be the same as declared inside the setValue method | |
null, //only needed for MySQL | |
Example.class //the class of the value | |
); | |
} | |
public static void setDefaultJSON() { | |
jsonStorage.setValue( | |
new StorageKey("prefix"), //is used to identify where to get the value from | |
new StorageItem("&7[&6AL&7] ") //is the value for 'prefix' | |
); //this will store a new entry | |
jsonStorage.setValue( | |
new StorageKey("you can also save instances of classes here"), | |
new StorageItem(new Example("Hello!", false)) //simply put in your instances here :) | |
); | |
} | |
//getting some values from the file | |
public static Example getExampleJSON() { | |
return jsonStorage.getValue( | |
new StorageKey("you can also save instances of classes here"), //Must be the same as declared inside the setValue method | |
null, //only needed for MySQL | |
Example.class //the class of the value | |
); | |
} | |
public static void setDefaultMySQL() { | |
//used if you wanna insert into the table | |
mySQLStorage.registerEntry(new StorageItem("Your column", new Example("1", true))); | |
//used if you wanna update stuff | |
mySQLStorage.setValue( | |
new StorageKey("prefix"), //is used to identify where to get the value from | |
new StorageItem("pref column", "&7[&6AL&7] ") //is the value for 'prefix' | |
); //this will store a new entry | |
mySQLStorage.setValue( | |
new StorageKey("you can also save instances of classes here"), | |
new StorageItem("Your column", new Example("Hello!", false)) //simply put in your instances here :) | |
); | |
} | |
//getting some values from the file | |
public static Example getExampleMySQL() { | |
return jsonStorage.getValue( | |
new StorageKey("you can also save instances of classes here"), //Must be the same as declared inside the setValue method | |
"Your column", //put the column of the value here | |
Example.class //the class of the value | |
); | |
} | |
private static class Example implements Serializable { | |
private String seeMe; | |
private boolean acceptMe; | |
Example(String seeMe, boolean acceptMe) { | |
this.seeMe = seeMe; | |
this.acceptMe = acceptMe; | |
} | |
public String getSeeMe() { | |
return seeMe; | |
} | |
public boolean isAcceptMe() { | |
return acceptMe; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment