diff --git a/src/com/projectkorra/projectkorra/BendingPlayer.java b/src/com/projectkorra/projectkorra/BendingPlayer.java index a82fe782..101f67c3 100644 --- a/src/com/projectkorra/projectkorra/BendingPlayer.java +++ b/src/com/projectkorra/projectkorra/BendingPlayer.java @@ -1,22 +1,5 @@ package com.projectkorra.projectkorra; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; - import com.projectkorra.projectkorra.Element.SubElement; import com.projectkorra.projectkorra.ability.Ability; import com.projectkorra.projectkorra.ability.AvatarAbility; @@ -33,6 +16,18 @@ import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.util.Cooldown; import com.projectkorra.projectkorra.util.DBCooldownManager; import com.projectkorra.projectkorra.waterbending.blood.Bloodbending; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; /** * Class that presents a player and stores all bending information about the @@ -152,17 +147,18 @@ public class BendingPlayer { public Map loadCooldowns() { final Map cooldowns = new ConcurrentHashMap<>(); - try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_cooldowns WHERE uuid = '" + this.uuid.toString() + "'")) { - while (rs.next()) { - final int cooldownId = rs.getInt("cooldown_id"); - final long value = rs.getLong("value"); - final String name = cooldownManager.getCooldownName(cooldownId); - cooldowns.put(name, new Cooldown(value, true)); + if (ProjectKorra.isDatabaseCooldownsEnabled()) { + try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_cooldowns WHERE uuid = '" + this.uuid.toString() + "'")) { + while (rs.next()) { + final int cooldownId = rs.getInt("cooldown_id"); + final long value = rs.getLong("value"); + final String name = cooldownManager.getCooldownName(cooldownId); + cooldowns.put(name, new Cooldown(value, true)); + } + } catch (final SQLException e) { + e.printStackTrace(); } } - catch (final SQLException e) { - e.printStackTrace(); - } return cooldowns; } diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 1ebd9f4b..5cfb1f2e 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -1153,7 +1153,9 @@ public class PKListener implements Listener { Manager.getManager(StatisticsManager.class).store(player.getUniqueId()); } if (bPlayer != null) { - bPlayer.saveCooldowns(); + if (ProjectKorra.isDatabaseCooldownsEnabled()) { + bPlayer.saveCooldowns(); + } if (TOGGLED_OUT.contains(player.getUniqueId()) && bPlayer.isToggled()) { TOGGLED_OUT.remove(player.getUniqueId()); diff --git a/src/com/projectkorra/projectkorra/ProjectKorra.java b/src/com/projectkorra/projectkorra/ProjectKorra.java index 0009da96..dacaffb1 100644 --- a/src/com/projectkorra/projectkorra/ProjectKorra.java +++ b/src/com/projectkorra/projectkorra/ProjectKorra.java @@ -1,21 +1,8 @@ package com.projectkorra.projectkorra; -import java.util.HashMap; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Statistic; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import com.bekvon.bukkit.residence.protection.FlagPermissions; import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.ability.util.CollisionInitializer; -import com.projectkorra.projectkorra.ability.util.CollisionManager; -import com.projectkorra.projectkorra.ability.util.ComboManager; -import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; -import com.projectkorra.projectkorra.ability.util.PassiveManager; +import com.projectkorra.projectkorra.ability.util.*; import com.projectkorra.projectkorra.airbending.util.AirbendingManager; import com.projectkorra.projectkorra.chiblocking.util.ChiblockingManager; import com.projectkorra.projectkorra.command.Commands; @@ -24,12 +11,16 @@ import com.projectkorra.projectkorra.earthbending.util.EarthbendingManager; import com.projectkorra.projectkorra.firebending.util.FirebendingManager; import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.storage.DBConnection; -import com.projectkorra.projectkorra.util.Metrics; -import com.projectkorra.projectkorra.util.RevertChecker; -import com.projectkorra.projectkorra.util.StatisticsManager; -import com.projectkorra.projectkorra.util.TempBlock; -import com.projectkorra.projectkorra.util.Updater; +import com.projectkorra.projectkorra.util.*; import com.projectkorra.projectkorra.waterbending.util.WaterbendingManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Statistic; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; +import java.util.logging.Logger; public class ProjectKorra extends JavaPlugin { @@ -152,7 +143,7 @@ public class ProjectKorra extends JavaPlugin { Manager.getManager(StatisticsManager.class).save(player.getUniqueId(), false); } final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer != null) { + if (bPlayer != null && isDatabaseCooldownsEnabled()) { bPlayer.saveCooldowns(); } } @@ -181,5 +172,8 @@ public class ProjectKorra extends JavaPlugin { public static boolean isStatisticsEnabled() { return ConfigManager.getConfig().getBoolean("Properties.Statistics"); } + public static boolean isDatabaseCooldownsEnabled() { + return ConfigManager.getConfig().getBoolean("Properties.DatabaseCooldowns"); + } } diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index 1f809d69..a9d3d803 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -541,6 +541,7 @@ public class ConfigManager { config.addDefault("Properties.UpdateChecker", true); config.addDefault("Properties.Statistics", true); + config.addDefault("Properties.DatabaseCooldowns", true); config.addDefault("Properties.BendingPreview", true); config.addDefault("Properties.BendingAffectFallingSand.Normal", true); config.addDefault("Properties.BendingAffectFallingSand.NormalStrengthMultiplier", 1.0); diff --git a/src/com/projectkorra/projectkorra/storage/DBConnection.java b/src/com/projectkorra/projectkorra/storage/DBConnection.java index 73cd5c15..19a4cea2 100644 --- a/src/com/projectkorra/projectkorra/storage/DBConnection.java +++ b/src/com/projectkorra/projectkorra/storage/DBConnection.java @@ -1,12 +1,12 @@ package com.projectkorra.projectkorra.storage; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; - import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.configuration.ConfigManager; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + public class DBConnection { public static Database sql; @@ -66,7 +66,7 @@ public class DBConnection { } if (!sql.tableExists("pk_cooldowns")) { ProjectKorra.log.info("Creating pk_cooldowns table"); - final String query = "CREATE TABLE `pk_cooldowns` (uuid VARCHAR(36) PRIMARY KEY, cooldown_id INTEGER NOT NULL, value BIGINT);"; + final String query = "CREATE TABLE `pk_cooldowns` (uuid VARCHAR(36) NOT NULL, cooldown_id INTEGER NOT NULL, value BIGINT);"; sql.modifyQuery(query, false); } } else {