Skip to content

Commit e640f40

Browse files
committed
Make some ConfigFile methods boolean and remove MF-GUI to reduce file size
1 parent 06b5767 commit e640f40

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ plugins {
44
}
55

66
shadowJar {
7-
relocate 'me.mattstudios.mfgui', 'me.dkim19375.dkim19375core.mfgui'
87
}
98

109
group 'me.dkim19375'
11-
version '2.1.1'
10+
version '2.2.0'
1211

1312
repositories {
1413
mavenCentral()
@@ -24,5 +23,4 @@ dependencies {
2423
compileOnly 'me.clip:placeholderapi:2.10.9'
2524
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4'
2625
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
27-
implementation 'me.mattstudios.utils:matt-framework-gui:2.0.2'
2826
}

src/main/java/me/dkim19375/dkim19375core/ConfigFile.java

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.logging.Level;
1212
import java.util.logging.Logger;
1313

14+
@SuppressWarnings("unused")
1415
public class ConfigFile {
1516

1617
private final File configFile;
@@ -25,7 +26,9 @@ public class ConfigFile {
2526
*
2627
* Please notice that the constructor does not yet create the YAML-configuration file. To create the file on the disk, use {@link ConfigFile#createConfig()}.
2728
*/
29+
@SuppressWarnings("unused")
2830
public ConfigFile(CoreJavaPlugin plugin, String fileName) {
31+
fileName = fileName.replace('\\', '/');
2932
this.fileName = fileName;
3033
configFile = new File(plugin.getDataFolder(), fileName);
3134
this.pluginDataFolder = plugin.getDataFolder();
@@ -35,18 +38,27 @@ public ConfigFile(CoreJavaPlugin plugin, String fileName) {
3538

3639
/**
3740
* This creates the configuration file. If the data folder is invalid, it will be created along with the config file.
41+
*
42+
* @return true if the file was successfully created
3843
*/
39-
public void createConfig() {
44+
public boolean createConfig() {
45+
boolean success = false;
4046
if (! configFile.exists()) {
4147
if (! this.pluginDataFolder.exists()) {
42-
this.pluginDataFolder.mkdir();
48+
if (this.pluginDataFolder.mkdir()) {
49+
success = true;
50+
}
4351
}
4452
try {
45-
configFile.createNewFile();
53+
if (configFile.createNewFile()) {
54+
success = true;
55+
}
4656
} catch (IOException e) {
4757
e.printStackTrace();
58+
success = false;
4859
}
4960
}
61+
return success;
5062
}
5163

5264
/**
@@ -151,24 +163,35 @@ public boolean deleteDir() {
151163

152164
/**
153165
* @since 1.0.0
166+
* @return true if the file was successfully reset
154167
* This deletes and recreates the file, wiping all its contents.
155168
*/
156-
public void reset() {
169+
public boolean reset() {
157170
this.deleteFile();
171+
boolean success;
158172
try {
159-
configFile.createNewFile();
173+
success = configFile.createNewFile();
160174
} catch (IOException e) {
161175
e.printStackTrace();
176+
success = false;
162177
}
178+
return success;
163179
}
164180

165181
/**
166182
* @since 1.0.0
183+
* @return true if the directory was successfully wiped
167184
* Wipe the config file's directory, including the file itself.
168185
*/
169-
public void wipeDirectory() {
170-
this.getDirectory().delete();
171-
this.pluginDataFolder.mkdir();
186+
public boolean wipeDirectory() {
187+
boolean success = true;
188+
if (!getDirectory().delete()) {
189+
success = false;
190+
}
191+
if (!pluginDataFolder.mkdir()) {
192+
success = false;
193+
}
194+
return success;
172195
}
173196

174197
/**
@@ -230,24 +253,22 @@ public InputStream getResource(String filename) {
230253

231254
public void saveDefaultConfig() {
232255
if (!configFile.exists()) {
233-
saveResource(fileName, false);
256+
saveResource();
234257
}
235258
}
236259

237-
protected void saveResource(String resourcePath, boolean replace) {
238-
if (resourcePath == null || resourcePath.equals("")) {
260+
protected void saveResource() {
261+
if (fileName == null || fileName.equals("")) {
239262
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
240263
}
241-
242-
resourcePath = resourcePath.replace('\\', '/');
243-
InputStream in = getResource(resourcePath);
264+
InputStream in = getResource(fileName);
244265
if (in == null) {
245-
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + fileName);
266+
throw new IllegalArgumentException("The embedded resource '" + fileName + "' cannot be found in " + fileName);
246267
}
247268

248-
File outFile = new File(pluginDataFolder, resourcePath);
249-
int lastIndex = resourcePath.lastIndexOf('/');
250-
File outDir = new File(pluginDataFolder, resourcePath.substring(0, Math.max(lastIndex, 0)));
269+
File outFile = new File(pluginDataFolder, fileName);
270+
int lastIndex = fileName.lastIndexOf('/');
271+
File outDir = new File(pluginDataFolder, fileName.substring(0, Math.max(lastIndex, 0)));
251272

252273
if (!outDir.exists()) {
253274
//noinspection ResultOfMethodCallIgnored
@@ -256,7 +277,7 @@ protected void saveResource(String resourcePath, boolean replace) {
256277
Logger logger = Bukkit.getLogger();
257278

258279
try {
259-
if (!outFile.exists() || replace) {
280+
if (!outFile.exists()) {
260281
OutputStream out = new FileOutputStream(outFile);
261282
byte[] buf = new byte[1024];
262283
int len;

0 commit comments

Comments
 (0)