Skip to content

Commit

Permalink
Optimizing config handling
Browse files Browse the repository at this point in the history
Optimizing type inferences, remove unnecessary casts, etc.
  • Loading branch information
CoolLord22 committed Mar 30, 2023
1 parent dcab4c9 commit 8a875f3
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,38 @@ public OATConfig(OtherAnimalTeleport plugin) {
}

public void load(CommandSender sender) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
try {
firstRun();
loadConfig();
} catch (FileNotFoundException e) {
if (verbosity.exceeds(Verbosity.HIGH)) e.printStackTrace();
result.add("Config file not found!");
result.add("The error was:\n" + e.toString());
result.add("The error was:\n" + e);
result.add("You can fix the error and reload with /orr.");
sendMessage(sender, result);
} catch (IOException e) {
if (verbosity.exceeds(Verbosity.HIGH)) e.printStackTrace();
result.add("There was an IO error which has forced OtherDrops to abort loading!");
result.add("The error was:\n" + e.toString());
result.add("The error was:\n" + e);
result.add("You can fix the error and reload with /orr.");
sendMessage(sender, result);
} catch (InvalidConfigurationException e) {
if (verbosity.exceeds(Verbosity.HIGH)) e.printStackTrace();
result.add("Config is invalid!");
result.add("The error was:\n" + e.toString());
result.add("The error was:\n" + e);
result.add("You can fix the error and reload with /orr.");
sendMessage(sender, result);
} catch (NullPointerException e) {
result.add("Config load failed!");
result.add("The error was:\n" + e.toString());
result.add("The error was:\n" + e);
if (verbosity.exceeds(Verbosity.NORMAL)) e.printStackTrace();
result.add("Please try the latest version & report this issue to the developer if the problem remains.");
sendMessage(sender, result);
} catch (Exception e) {
if (verbosity.exceeds(Verbosity.HIGH)) e.printStackTrace();
result.add("Config load failed! Something went wrong.");
result.add("The error was:\n" + e.toString());
result.add("The error was:\n" + e);
result.add("If you can fix the error, reload with /orr.");
sendMessage(sender, result);
}
Expand All @@ -93,8 +93,8 @@ private void sendMessage(CommandSender sender, List<String> result) {
plugin.log.logInfo(result);
}

private void firstRun() throws Exception {
List<String> files = new ArrayList<String>();
private void firstRun() {
List<String> files = new ArrayList<>();
files.add("config.yml");

for (String filename : files) {
Expand All @@ -107,7 +107,7 @@ private void firstRun() throws Exception {
}

@SuppressWarnings("unchecked")
public void loadConfig() throws FileNotFoundException, IOException, InvalidConfigurationException {
public void loadConfig() throws IOException, InvalidConfigurationException {
String filename = "config.yml";
File global = new File(plugin.getDataFolder(), filename);
YamlConfiguration globalConfig = YamlConfiguration.loadConfiguration(global);
Expand All @@ -118,9 +118,7 @@ public void loadConfig() throws FileNotFoundException, IOException, InvalidConfi
global.createNewFile();
plugin.log.logInfo("Created a config file " + plugin.getDataFolder() + "\\" + filename + ", please edit it!");
globalConfig.save(global);
} catch (IOException ex) {
plugin.log.logWarning(plugin.getDescription().getName() + ": could not generate " + filename + ". Are the file permissions OK?");
} catch (Exception e) {
} catch (Exception ex) {
plugin.log.logWarning(plugin.getDescription().getName() + ": could not generate " + filename + ". Are the file permissions OK?");
}
}
Expand Down Expand Up @@ -178,7 +176,7 @@ public void loadConfig() throws FileNotFoundException, IOException, InvalidConfi

if(globalConfig.contains("world_groups")) {
for(Object input : globalConfig.getList("world_groups")) {
Set<World> worldList = new HashSet<World>();
Set<World> worldList = new HashSet<>();
for(String inputWorld : (ArrayList<String>)input) {
boolean foundMatch = false;
for(World knownWorld : Bukkit.getWorlds()) {
Expand Down

0 comments on commit 8a875f3

Please sign in to comment.