You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @param pluginDataFolder The plugin's data directory, accessible with JavaPlugin#getDataFolder();
21
+
* @param fileName The name of the config file excluding file extensions.
22
+
*
23
+
* Please notice that the constructor does not yet create the YAML-configuration file. To create the file on the disk, use {@link ConfigFile#createConfig()}.
* @param javaPlugin A JavaPlugin instance of the plugin using this config
35
+
* @param fileName The name of the config file excluding file extensions.
36
+
*
37
+
* Please notice that the constructor does not yet create the YAML-configuration file. To create the file on the disk, use {@link ConfigFile#createConfig()}.
* This creates the configuration file. If the data folder is invalid, it will be created along with the config file.
49
+
*/
50
+
publicvoidcreateConfig() {
51
+
if (! configFile.exists()) {
52
+
if (! this.pluginDataFolder.exists()) {
53
+
this.pluginDataFolder.mkdir();
54
+
}
55
+
try {
56
+
configFile.createNewFile();
57
+
} catch (IOExceptione) {
58
+
e.printStackTrace();
59
+
}
60
+
}
61
+
}
62
+
63
+
/**
64
+
* @since 1.0.0
65
+
* @return The configuration file's directory. To get its name, use {@link ConfigFile#getName()} instead.
66
+
*/
67
+
publicFilegetDirectory() {
68
+
returnpluginDataFolder;
69
+
}
70
+
71
+
/**
72
+
* @since 1.0.0
73
+
* @return The name of the configuration file, including file extensions.
74
+
* This returns the name of the configuration file with the .yml extension. To get the file's directory, use {@link ConfigFile#getDirectory()}.
75
+
*/
76
+
publicStringgetName() {
77
+
returnfileName;
78
+
}
79
+
80
+
/**
81
+
* @since 1.0.0
82
+
* @return The config file.
83
+
* This returns the actual File object of the config file.
84
+
*/
85
+
publicFilegetFile() {
86
+
returnconfigFile;
87
+
}
88
+
89
+
/**
90
+
* @since 1.0.0
91
+
* @return The FileConfiguration object.
92
+
* This returns the actual FileConfiguration object of the config file.
93
+
*/
94
+
publicFileConfigurationgetConfig() {
95
+
returnconfig;
96
+
}
97
+
98
+
/**
99
+
* @since 1.0.0
100
+
* @param key The config key, including the path.
101
+
* @param value the config value.
102
+
* Set a default configuration value: if the entered key already exists (and it holds another value), it will do nothing. If it doesn't, it will create the key with the wanted value.
103
+
*/
104
+
publicvoidaddDefault(Stringkey, Stringvalue) {
105
+
if (config.getString(key) == null) {
106
+
config.set(key, value);
107
+
try {
108
+
config.save(configFile);
109
+
} catch (IOExceptione) {
110
+
e.printStackTrace();
111
+
}
112
+
113
+
}
114
+
}
115
+
116
+
/**
117
+
* @since 1.0.0
118
+
* @param defaults A map containing the default configuration keys and values.
119
+
* This sets the default configuration values as the ones contained in the map.
* @return true if and only if the file or directory is
148
+
* successfully deleted; otherwise
149
+
* This deletes the config file.
150
+
*/
151
+
publicbooleandeleteFile() {
152
+
returnconfigFile.delete();
153
+
}
154
+
155
+
/**
156
+
* @since 1.0.0
157
+
* This deletes the config file's directory and all it's contents.
158
+
*/
159
+
publicbooleandeleteDir() {
160
+
returngetDirectory().delete();
161
+
}
162
+
163
+
/**
164
+
* @since 1.0.0
165
+
* This deletes and recreates the file, wiping all its contents.
166
+
*/
167
+
publicvoidreset() {
168
+
this.deleteFile();
169
+
try {
170
+
configFile.createNewFile();
171
+
} catch (IOExceptione) {
172
+
e.printStackTrace();
173
+
}
174
+
}
175
+
176
+
/**
177
+
* @since 1.0.0
178
+
* Wipe the config file's directory, including the file itself.
179
+
*/
180
+
publicvoidwipeDirectory() {
181
+
this.getDirectory().delete();
182
+
this.pluginDataFolder.mkdir();
183
+
}
184
+
185
+
/**
186
+
* @since 1.0.0
187
+
* @param name The sub directory's name.
188
+
* @return true if and only if the file or directory is
189
+
* successfully deleted; otherwise
190
+
* @throws IOException If the entered string has a file extension or already exists.
191
+
* This will create a sub-directory in the plugin's data folder, which can be accessed with {@link ConfigFile#getDirectory()}.
192
+
* If the entered name is not a valid name for a directory or the sub-directory already exists or the data folder does not exist, an IOException will be thrown.
0 commit comments