Skip to content

Commit

Permalink
remove useless method
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Nov 5, 2024
1 parent fcec699 commit ce96c1b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -118,14 +116,6 @@ public void onEnable() {
prefixedLogger.info("Detected Folia server.");
}

try {
createDirectory(getDataFolder());
} catch (IOException e) {
prefixedLogger.error("Unable to create plugin folder!", e);
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger.info("Loading Config");
reloadConfiguration();

Expand Down Expand Up @@ -205,22 +195,13 @@ public static LanguageCache getLang(String lang) {
return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase()));
}

public void createDirectory(File dir) throws IOException {
try {
Files.createDirectories(dir.toPath());
} catch (FileAlreadyExistsException e) { // Thrown if dir exists but is not a directory
if (dir.delete()) createDirectory(dir);
}
}

public void reloadPlugin() {
reloadConfiguration();
reloadLang();
}

private void reloadConfiguration() {
try {
createDirectory(getDataFolder());
config = new Config();
if (tickReporter != null) tickReporter.disable();
tickReporter = TickReporter.create(this, config.tickData_cache_duration);
Expand Down Expand Up @@ -267,7 +248,7 @@ public void reloadLang() {

private @NotNull List<String> getAvailableTranslations() {
try (final JarFile pluginJar = new JarFile(getFile())) {
createDirectory(new File(getDataFolder(), "/lang"));
Files.createDirectories(new File(getDataFolder(), "/lang").toPath());
final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
final File[] langDirFiles = new File(getDataFolder() + "/lang").listFiles();
return Stream.concat(pluginJar.stream().map(ZipEntry::getName), Arrays.stream(langDirFiles).map(File::getName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Sound;

import java.io.File;
import java.nio.file.Files;
import java.time.Duration;
import java.util.List;
import java.util.Locale;
Expand All @@ -30,8 +31,10 @@ public class Config {

public Config() throws Exception {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
Files.createDirectories(plugin.getDataFolder().toPath());
// Load config.yml with ConfigMaster
this.config = ConfigFile.loadConfig(new File(plugin.getDataFolder(), "config.yml"));

config.set("plugin-version", plugin.getPluginMeta().getVersion());
config.set("server-version", plugin.getServer().getVersion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -124,13 +122,6 @@ public void onEnable() {
prefixedLogger.warn("Its highly recommended to use the Folia jar for your server.");
}

try {
createDirectory(getDataFolder());
} catch (IOException e) {
prefixedLogger.error("Unable to create plugin folder!", e);
getServer().getPluginManager().disablePlugin(this);
}

prefixedLogger.info("Loading Datastore");
datastore = new Datastore();

Expand Down Expand Up @@ -221,22 +212,13 @@ public static LanguageCache getLang(String lang) {
return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase()));
}

public void createDirectory(File dir) throws IOException {
try {
Files.createDirectories(dir.toPath());
} catch (FileAlreadyExistsException e) { // Thrown if dir exists but is not a directory
if (dir.delete()) createDirectory(dir);
}
}

public void reloadPlugin() {
reloadConfiguration();
reloadLang();
}

private void reloadConfiguration() {
try {
createDirectory(getDataFolder());
config = new Config();
if (tickReporter != null) tickReporter.disable();
tickReporter = TickReporter.create(this, config.tps_cache_duration);
Expand Down Expand Up @@ -283,7 +265,7 @@ public void reloadLang() {

private @NotNull List<String> getAvailableTranslations() {
try (final JarFile pluginJar = new JarFile(getFile())) {
createDirectory(new File(getDataFolder(), "/lang"));
Files.createDirectories(new File(getDataFolder(), "/lang").toPath());
final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
final File[] langDirFiles = new File(getDataFolder() + "/lang").listFiles();
return Stream.concat(pluginJar.stream().map(ZipEntry::getName), Arrays.stream(langDirFiles).map(File::getName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.Sound;

import java.io.File;
import java.nio.file.Files;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -35,8 +36,10 @@ public class Config {

public Config() throws Exception {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
Files.createDirectories(plugin.getDataFolder().toPath());
// Load config.yml with ConfigMaster
this.config = ConfigFile.loadConfig(new File(plugin.getDataFolder(), "config.yml"));

config.set("plugin-version", plugin.getDescription().getVersion());
config.set("server-version", plugin.getServer().getVersion());

Expand Down

0 comments on commit ce96c1b

Please sign in to comment.