From 9e3eeaa6e99a0afe009e948306369a99e946fd25 Mon Sep 17 00:00:00 2001 From: jayoevans Date: Thu, 24 Oct 2019 11:47:10 +1000 Subject: [PATCH] Bodge fix for exceptions --- src/com/projectkorra/projectkorra/ProjectKorra.java | 13 +++++++------ .../projectkorra/ability/CoreAbility.java | 9 ++++----- .../projectkorra/configuration/ConfigManager.java | 4 ---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/com/projectkorra/projectkorra/ProjectKorra.java b/src/com/projectkorra/projectkorra/ProjectKorra.java index 67fc14f0..007ef55f 100644 --- a/src/com/projectkorra/projectkorra/ProjectKorra.java +++ b/src/com/projectkorra/projectkorra/ProjectKorra.java @@ -42,9 +42,9 @@ import co.aikar.timings.lib.TimingManager; public class ProjectKorra extends JavaPlugin { - private static final GeneralPropertiesConfig GENERAL_PROPERTIES = ConfigManager.getConfig(GeneralPropertiesConfig.class); public static ProjectKorra plugin; public static Logger log; + private static GeneralPropertiesConfig generalPropertiesConfig; public static CollisionManager collisionManager; public static CollisionInitializer collisionInitializer; public static long time_step = 1; @@ -66,11 +66,12 @@ public class ProjectKorra extends JavaPlugin { plugin = this; ProjectKorra.log = this.getLogger(); + generalPropertiesConfig = ConfigManager.getConfig(GeneralPropertiesConfig.class); timingManager = TimingManager.of(this); new GeneralMethods(this); - final boolean checkUpdateOnStartup = GENERAL_PROPERTIES.UpdateChecker; + final boolean checkUpdateOnStartup = generalPropertiesConfig.UpdateChecker; this.updater = new Updater(this, "https://projectkorra.com/forum/resources/projectkorra-core.1/", checkUpdateOnStartup); new Commands(this); new MultiAbilityManager(); @@ -141,11 +142,11 @@ public class ProjectKorra extends JavaPlugin { }); if (Bukkit.getPluginManager().getPlugin("Residence") != null) { - FlagPermissions.addFlag(GENERAL_PROPERTIES.RegionProtection.ResidenceFlag); + FlagPermissions.addFlag(generalPropertiesConfig.RegionProtection.ResidenceFlag); } GeneralMethods.deserializeFile(); - GeneralMethods.startCacheCleaner(GENERAL_PROPERTIES.RegionProtection.CacheBlockTime); + GeneralMethods.startCacheCleaner(generalPropertiesConfig.RegionProtection.CacheBlockTime); if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new PlaceholderAPIHook(this).register(); @@ -195,11 +196,11 @@ public class ProjectKorra extends JavaPlugin { } public static boolean isStatisticsEnabled() { - return GENERAL_PROPERTIES.Statistics; + return generalPropertiesConfig.Statistics; } public static boolean isDatabaseCooldownsEnabled() { - return GENERAL_PROPERTIES.DatabaseCooldowns; + return generalPropertiesConfig.DatabaseCooldowns; } public static MCTiming timing(final String name) { diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index 226a6193..1f05bff4 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; @@ -20,6 +21,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.jar.JarFile; +import com.projectkorra.projectkorra.configuration.ConfigManager; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -87,8 +89,8 @@ public abstract class CoreAbility implements Ability { private static final Map, Map> ATTRIBUTE_FIELDS = new HashMap<>(); private static int idCounter; - - protected final C config; + + protected final C config = ConfigManager.getConfig(((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0])); protected Player player; protected BendingPlayer bPlayer; protected FlightHandler flightHandler; @@ -119,7 +121,6 @@ public abstract class CoreAbility implements Ability { * @see #getAbility(String) */ public CoreAbility() { - this.config = null; for (final Field field : this.getClass().getDeclaredFields()) { if (field.isAnnotationPresent(Attribute.class)) { final Attribute attribute = field.getAnnotation(Attribute.class); @@ -139,11 +140,9 @@ public abstract class CoreAbility implements Ability { */ public CoreAbility(final C config, final Player player) { if (player == null || !this.isEnabled()) { - this.config = config; return; } - this.config = config; this.player = player; this.bPlayer = BendingPlayer.getBendingPlayer(player); this.flightHandler = Manager.getManager(FlightHandler.class); diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index dd9d00ce..ea812970 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -21,10 +21,6 @@ public class ConfigManager { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final Map, Config> CONFIG_CACHE = Collections.synchronizedMap(new HashMap<>()); - static { - JavaPlugin.getProvidingPlugin(ConfigManager.class).getDataFolder().mkdir(); - } - private static C loadConfig(File file, Class clazz) throws IOException { try (BufferedReader reader = Files.newReader(file, Charset.defaultCharset())) { return GSON.fromJson(reader, clazz);