Skip to content

Commit

Permalink
Improvements to config validation
Browse files Browse the repository at this point in the history
Small improvements
  • Loading branch information
A5H73Y committed Oct 3, 2018
1 parent 96fc9ab commit 0205b7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

if (args.length == 0) {
Utils.log("v" + Static.getVersion() + " installed. Plugin created by A5H73Y.");
Utils.log("Enter 'pa cmds' to display all console commands.");
Utils.log("Enter 'pac cmds' to display all console commands.");
return true;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Backup.backupNow(true);

} else {
Utils.log("Unknown Command. Enter 'pa cmds' to display all console commands.");
Utils.log("Unknown Command. Enter 'pac cmds' to display all console commands.");
}
return true;
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/me/A5H73Y/Parkour/Other/Configurations.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.A5H73Y.Parkour.Utilities.Static;
import me.A5H73Y.Parkour.Utilities.Utils;

import org.bukkit.Particle;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

Expand Down Expand Up @@ -143,6 +144,8 @@ public void reload() {
kitData = YamlConfiguration.loadConfiguration(kitFile);
if (Static.getEconomy())
econData = YamlConfiguration.loadConfiguration(econFile);

validateConfigProperties();
}

public FileConfiguration getCheckData() {
Expand Down Expand Up @@ -532,5 +535,24 @@ public void setupConfig() {
config.addDefault("Lobby.EnforceWorld", false);
config.options().copyDefaults(true);
Parkour.getPlugin().saveConfig();

validateConfigProperties();
}

private void validateConfigProperties() {
FileConfiguration config = Parkour.getPlugin().getConfig();
// First check if the Trail is valid
if (config.getBoolean("OnCourse.Trails.Enabled")) {
String trail = config.getString("OnCourse.Trails.Particle").toUpperCase();

try {
Particle particle = Particle.valueOf(trail);
Parkour.getPlugin().getServer().getWorlds().get(0).spawnParticle(particle, 0, 0, 0, 1);
} catch (IllegalArgumentException | NullPointerException ex) {
Utils.log("Particle: " + trail + " is invalid. Disabling Trails.", 2);
config.set("OnCourse.Trails.Enabled", false);
Parkour.getPlugin().saveConfig();
}
}
}
}
20 changes: 1 addition & 19 deletions src/main/java/me/A5H73Y/Parkour/Other/StartPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ public class StartPlugin {
public static void run() {
checkConvertToLatest();
Parkour.getParkourConfig().setupConfig();
validateConfigProperties();
Static.initiate();
initiateSQL();
setupExternalPlugins();
populatePlayers();
Utils.log("Enabled Parkour v" + Static.getVersion() + "!");
Utils.log("Enabled Parkour v" + Static.getVersion());
}

private static void setupExternalPlugins() {
Expand Down Expand Up @@ -206,23 +205,6 @@ private static void checkConvertToLatest() {
Parkour.getPlugin().saveConfig();
}

private static void validateConfigProperties() {
FileConfiguration config = Parkour.getPlugin().getConfig();
// First check if the Trail is valid
if (config.getBoolean("OnCourse.Trails.Enabled")) {
String trail = config.getString("OnCourse.Trails.Particle").toUpperCase();

try {
Particle particle = Particle.valueOf(trail);
Parkour.getPlugin().getServer().getWorlds().get(0).spawnParticle(particle, 0, 0, 0, 1);
} catch (IllegalArgumentException | NullPointerException ex) {
Utils.log("Particle: " + trail + " is invalid. Disabling Trails.", 2);
config.set("OnCourse.Trails.Enabled", false);
Parkour.getPlugin().saveConfig();
}
}
}

private static void fixParkourBlocks(HashMap<String, ParkourSession> players) {
for (String playerName : players.keySet()) {
ParkourSession session = players.get(playerName);
Expand Down

0 comments on commit 0205b7f

Please sign in to comment.