Bodge fix for exceptions

This commit is contained in:
jayoevans 2019-10-24 11:47:10 +10:00
parent 7fd3186d40
commit 9e3eeaa6e9
3 changed files with 11 additions and 15 deletions

View file

@ -42,9 +42,9 @@ import co.aikar.timings.lib.TimingManager;
public class ProjectKorra extends JavaPlugin { public class ProjectKorra extends JavaPlugin {
private static final GeneralPropertiesConfig GENERAL_PROPERTIES = ConfigManager.getConfig(GeneralPropertiesConfig.class);
public static ProjectKorra plugin; public static ProjectKorra plugin;
public static Logger log; public static Logger log;
private static GeneralPropertiesConfig generalPropertiesConfig;
public static CollisionManager collisionManager; public static CollisionManager collisionManager;
public static CollisionInitializer collisionInitializer; public static CollisionInitializer collisionInitializer;
public static long time_step = 1; public static long time_step = 1;
@ -66,11 +66,12 @@ public class ProjectKorra extends JavaPlugin {
plugin = this; plugin = this;
ProjectKorra.log = this.getLogger(); ProjectKorra.log = this.getLogger();
generalPropertiesConfig = ConfigManager.getConfig(GeneralPropertiesConfig.class);
timingManager = TimingManager.of(this); timingManager = TimingManager.of(this);
new GeneralMethods(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); this.updater = new Updater(this, "https://projectkorra.com/forum/resources/projectkorra-core.1/", checkUpdateOnStartup);
new Commands(this); new Commands(this);
new MultiAbilityManager(); new MultiAbilityManager();
@ -141,11 +142,11 @@ public class ProjectKorra extends JavaPlugin {
}); });
if (Bukkit.getPluginManager().getPlugin("Residence") != null) { if (Bukkit.getPluginManager().getPlugin("Residence") != null) {
FlagPermissions.addFlag(GENERAL_PROPERTIES.RegionProtection.ResidenceFlag); FlagPermissions.addFlag(generalPropertiesConfig.RegionProtection.ResidenceFlag);
} }
GeneralMethods.deserializeFile(); GeneralMethods.deserializeFile();
GeneralMethods.startCacheCleaner(GENERAL_PROPERTIES.RegionProtection.CacheBlockTime); GeneralMethods.startCacheCleaner(generalPropertiesConfig.RegionProtection.CacheBlockTime);
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceholderAPIHook(this).register(); new PlaceholderAPIHook(this).register();
@ -195,11 +196,11 @@ public class ProjectKorra extends JavaPlugin {
} }
public static boolean isStatisticsEnabled() { public static boolean isStatisticsEnabled() {
return GENERAL_PROPERTIES.Statistics; return generalPropertiesConfig.Statistics;
} }
public static boolean isDatabaseCooldownsEnabled() { public static boolean isDatabaseCooldownsEnabled() {
return GENERAL_PROPERTIES.DatabaseCooldowns; return generalPropertiesConfig.DatabaseCooldowns;
} }
public static MCTiming timing(final String name) { public static MCTiming timing(final String name) {

View file

@ -5,6 +5,7 @@ import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -20,6 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
@ -87,8 +89,8 @@ public abstract class CoreAbility<C extends AbilityConfig> implements Ability {
private static final Map<Class<? extends CoreAbility>, Map<String, Field>> ATTRIBUTE_FIELDS = new HashMap<>(); private static final Map<Class<? extends CoreAbility>, Map<String, Field>> ATTRIBUTE_FIELDS = new HashMap<>();
private static int idCounter; private static int idCounter;
protected final C config; protected final C config = ConfigManager.getConfig(((Class<C>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
protected Player player; protected Player player;
protected BendingPlayer bPlayer; protected BendingPlayer bPlayer;
protected FlightHandler flightHandler; protected FlightHandler flightHandler;
@ -119,7 +121,6 @@ public abstract class CoreAbility<C extends AbilityConfig> implements Ability {
* @see #getAbility(String) * @see #getAbility(String)
*/ */
public CoreAbility() { public CoreAbility() {
this.config = null;
for (final Field field : this.getClass().getDeclaredFields()) { for (final Field field : this.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(Attribute.class)) { if (field.isAnnotationPresent(Attribute.class)) {
final Attribute attribute = field.getAnnotation(Attribute.class); final Attribute attribute = field.getAnnotation(Attribute.class);
@ -139,11 +140,9 @@ public abstract class CoreAbility<C extends AbilityConfig> implements Ability {
*/ */
public CoreAbility(final C config, final Player player) { public CoreAbility(final C config, final Player player) {
if (player == null || !this.isEnabled()) { if (player == null || !this.isEnabled()) {
this.config = config;
return; return;
} }
this.config = config;
this.player = player; this.player = player;
this.bPlayer = BendingPlayer.getBendingPlayer(player); this.bPlayer = BendingPlayer.getBendingPlayer(player);
this.flightHandler = Manager.getManager(FlightHandler.class); this.flightHandler = Manager.getManager(FlightHandler.class);

View file

@ -21,10 +21,6 @@ public class ConfigManager {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final Map<Class<? extends Config>, Config> CONFIG_CACHE = Collections.synchronizedMap(new HashMap<>()); private static final Map<Class<? extends Config>, Config> CONFIG_CACHE = Collections.synchronizedMap(new HashMap<>());
static {
JavaPlugin.getProvidingPlugin(ConfigManager.class).getDataFolder().mkdir();
}
private static <C extends Config> C loadConfig(File file, Class<C> clazz) throws IOException { private static <C extends Config> C loadConfig(File file, Class<C> clazz) throws IOException {
try (BufferedReader reader = Files.newReader(file, Charset.defaultCharset())) { try (BufferedReader reader = Files.newReader(file, Charset.defaultCharset())) {
return GSON.fromJson(reader, clazz); return GSON.fromJson(reader, clazz);