mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-07 03:10:56 +01:00
Fixed Customized resource lookup
The method was not looking at the right directory Affects issues: - Fixed #1379
This commit is contained in:
parent
74bec0c25f
commit
8203e85f77
@ -20,12 +20,13 @@ import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.SubSystem;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -62,9 +63,13 @@ public class PlanFiles implements SubSystem {
|
||||
}
|
||||
|
||||
public File getLogsFolder() {
|
||||
File folder = getFileFromPluginFolder("logs");
|
||||
folder.mkdirs();
|
||||
return folder;
|
||||
try {
|
||||
File folder = getFileFromPluginFolder("logs");
|
||||
Files.createDirectories(folder.toPath());
|
||||
return folder;
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
@ -118,24 +123,6 @@ public class PlanFiles implements SubSystem {
|
||||
return new FileResource(resourceName, getFileFromPluginFolder(resourceName));
|
||||
}
|
||||
|
||||
private Optional<File> attemptToFind(String resourceName) {
|
||||
if (dataFolder.exists() && dataFolder.isDirectory()) {
|
||||
|
||||
String[] path = StringUtils.split(resourceName, '/');
|
||||
|
||||
Path toFile = dataFolder.getAbsoluteFile().toPath().toAbsolutePath();
|
||||
for (String next : path) {
|
||||
toFile = toFile.resolve(next);
|
||||
}
|
||||
|
||||
File found = toFile.toFile();
|
||||
if (found.exists()) {
|
||||
return Optional.of(found);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Resource> getCustomizableResource(String resourceName) {
|
||||
return Optional.ofNullable(ResourceCache.getOrCache(resourceName,
|
||||
() -> attemptToFind(resourceName)
|
||||
@ -143,4 +130,16 @@ public class PlanFiles implements SubSystem {
|
||||
.orElse(null)
|
||||
));
|
||||
}
|
||||
|
||||
private Optional<File> attemptToFind(String resourceName) {
|
||||
Path dir = getCustomizationDirectory();
|
||||
if (dir.toFile().exists() && dir.toFile().isDirectory()) {
|
||||
Path asPath = dir.resolve(resourceName);
|
||||
File found = asPath.toFile();
|
||||
if (found.exists()) {
|
||||
return Optional.of(found);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user