diff --git a/Changelog.txt b/Changelog.txt index 6563da290..c98b39629 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -9,11 +9,14 @@ Key: Version 1.3.13-dev + Added Craftbukkit 1.4.6 compatibility + + Added a configurable durability cap for ArmorImpact to advanced.yml = Fixed issue with missing default cases from several switch/case statements = Fixed issue with Mining using actual skill level rather than max skill level = Fixed some issues with static access = Fixed ItemStack deprecation issues = Fixed Async deprecation issues + = Fixed some issues with mySQL databases (non-alphanumeric characters preventing MySQL) + = Fixed skill commands displaying .x% instead of 0.x% ! GJ stopped being a lazy slacker and got stuff done - Removed dead code relating to null profiles - Removed unused imports diff --git a/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java index 0270ce771..51c61cb8c 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/AcrobaticsCommand.java @@ -33,7 +33,7 @@ public class AcrobaticsCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); // DODGE if(skillValue >= dodgeMaxBonusLevel) dodgeChance = df.format(dodgeChanceMax); else dodgeChance = df.format(((double) dodgeChanceMax / (double) dodgeMaxBonusLevel) * skillValue); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java index 5a163086e..cd1e7e5da 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/ArcheryCommand.java @@ -37,7 +37,7 @@ public class ArcheryCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); // SkillShot double bonus = (int)((double) skillValue / (double) skillShotIncreaseLevel) * skillShotIncreasePercentage; if (bonus > skillShotBonusMax) skillShotBonus = percent.format(skillShotBonusMax); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java index 23cc17bf2..f422f39bd 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/AxesCommand.java @@ -39,7 +39,7 @@ public class AxesCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); int skillCheck = Misc.skillCheck((int)skillValue, critMaxBonusLevel); impactDamage = String.valueOf(1 + ((double) skillValue / (double) greaterImpactIncreaseLevel)); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java index 61bae0d28..7f8a657ab 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java @@ -42,18 +42,18 @@ public class HerbalismCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); greenTerraLength = String.valueOf(2 + (int) ((double) skillValue / (double) abilityLengthIncreaseLevel)); //FARMERS DIET if(skillValue >= farmersDietMaxLevel) farmersDietRank = "5"; - else farmersDietRank = String.valueOf((double) skillValue / (double) farmersDietRankChange); + else farmersDietRank = String.valueOf((int) ((double) skillValue / (double) farmersDietRankChange)); //GREEN THUMB if(skillValue >= greenThumbStageMaxLevel) greenThumbStage = "4"; - else greenThumbStage = String.valueOf((double) skillValue / (double) greenThumbStageChange); + else greenThumbStage = String.valueOf((int) ((double) skillValue / (double) greenThumbStageChange)); if(skillValue >= greenThumbMaxLevel) greenThumbChance = String.valueOf(greenThumbMaxBonus); - else greenThumbChance = String.valueOf((greenThumbMaxBonus / greenThumbMaxLevel) * skillValue); + else greenThumbChance = df.format((greenThumbMaxBonus / greenThumbMaxLevel) * skillValue); //DOUBLE DROPS if(skillValue >= doubleDropsMaxLevel) doubleDropChance = df.format(doubleDropsMaxBonus); else doubleDropChance = df.format((doubleDropsMaxBonus / doubleDropsMaxLevel) * skillValue); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java index d76888497..66d1d12f7 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/MiningCommand.java @@ -45,7 +45,7 @@ public class MiningCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); superBreakerLength = String.valueOf(2 + (int) ((double) skillValue / (double) abilityLengthIncreaseLevel)); if(skillValue >= doubleDropsMaxLevel) doubleDropChance = df.format(doubleDropsMaxBonus); else doubleDropChance = df.format((doubleDropsMaxBonus / doubleDropsMaxLevel) * skillValue); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java index d6250a282..94d9a00b7 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java @@ -49,7 +49,7 @@ public class RepairCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); // We're using pickaxes here, not the best but it works Repairable diamondRepairable = mcMMO.repairManager.getRepairable(278); Repairable goldRepairable = mcMMO.repairManager.getRepairable(285); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java index 6bfb0a2b5..3a5649071 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SwordsCommand.java @@ -36,7 +36,7 @@ public class SwordsCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); serratedStrikesLength = String.valueOf(2 + (int) ((double) skillValue / (double) abilityLengthIncreaseLevel)); if (skillValue >= bleedMaxLevel) bleedLength = String.valueOf(bleedMaxTicks); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java index 892a64c4c..03f915b34 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/TamingCommand.java @@ -38,7 +38,7 @@ public class TamingCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); if(skillValue >= goreMaxLevel) goreChance = df.format(goreChanceMax); else goreChance = df.format(((double) goreChanceMax / (double) goreMaxLevel) * skillValue); } diff --git a/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java index 888e64139..2cb86b9fa 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/UnarmedCommand.java @@ -35,7 +35,7 @@ public class UnarmedCommand extends SkillCommand { @Override protected void dataCalculations() { - DecimalFormat df = new DecimalFormat("#.0"); + DecimalFormat df = new DecimalFormat("0.0"); berserkLength = String.valueOf(2 + (int) ((double) skillValue / (double) abilityLengthIncreaseLevel)); if(skillValue >= disarmMaxLevel) disarmChance = df.format(disarmChanceMax); diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 85632cb4e..f9a32ce3d 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -61,6 +61,7 @@ public class AdvancedConfig extends ConfigLoader { public int getGreaterImpactBonusDamage() { return config.getInt("Skills.Axes.GreaterImpact_BonusDamage", 2); } public int getArmorImpactIncreaseLevel() { return config.getInt("Skills.Axes.ArmorImpact_IncreaseLevel", 50); } + public int getArmorImpactMaxDurabilityDamage() { return config.getInt("Skills.Axes.ArmorImpact_MaxPercentageDurabilityDamage", 20); } /* EXCAVATION */ //Nothing to configure, everything is already configurable in config.yml diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 5be89feed..bc05cc572 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -40,20 +40,29 @@ public class Config extends ConfigLoader { /* mySQL */ public boolean getUseMySQL() { return config.getBoolean("MySQL.Enabled", false); } public String getMySQLTablePrefix() { return config.getString("MySQL.Database.TablePrefix", "mcmmo_"); } - public String getMySQLDatabaseName() { return config.getString("MySQL.Database.Name", "DatabaseName"); } - public String getMySQLUserName() { return config.getString("MySQL.Database.User_Name", "UserName"); } //Really should be labeled under MySQL.User_Name instead... + public String getMySQLDatabaseName() { return getStringIncludingInts(config, "MySQL.Database.Name"); } + public String getMySQLUserName() { return getStringIncludingInts(config, "MySQL.Database.User_Name"); } public int getMySQLServerPort() { return config.getInt("MySQL.Server.Port", 3306); } public String getMySQLServerName() { return config.getString("MySQL.Server.Address", "localhost"); } public String getMySQLUserPassword() { - if (config.getString("MySQL.Database.User_Password", null) != null) { - return config.getString("MySQL.Database.User_Password", null); + if (getStringIncludingInts(config, "MySQL.Database.User_Password") != null) { + return getStringIncludingInts(config, "MySQL.Database.User_Password"); } else { return ""; } } + private static String getStringIncludingInts(ConfigurationSection cfg, String key) { + String str = cfg.getString(key); + if (str == null) + str = String.valueOf(cfg.getInt(key)); + if (str == null) + str = "No value set for '" + key + "'"; + return str; + } + /* Hardcore Mode */ public boolean getHardcoreEnabled() { return config.getBoolean("Hardcore.Enabled", false); } public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss_Penalty_Percentage", 75); } diff --git a/src/main/java/com/gmail/nossr50/skills/combat/Axes.java b/src/main/java/com/gmail/nossr50/skills/combat/Axes.java index b7e4c9dbc..c09dc19b1 100644 --- a/src/main/java/com/gmail/nossr50/skills/combat/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/combat/Axes.java @@ -16,6 +16,7 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.PartyManager; +import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -130,6 +131,8 @@ public class Axes { /* Every 30 Skill Levels you gain 1 durability damage */ int impactIncreaseLevel = advancedConfig.getArmorImpactIncreaseLevel(); + float impactMaxDamage = (float) advancedConfig.getArmorImpactMaxDurabilityDamage() / 100F; + short maxDurability; durabilityDamage += (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) impactIncreaseLevel); if (!hasArmor(targetPlayer)) { @@ -137,8 +140,11 @@ public class Axes { } else { for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) { - if(Math.random() * 100 > 75) + if(Math.random() * 100 > 75) { + maxDurability = (short) (ItemChecks.getMaxDurabilityArmor(armor) * impactMaxDamage); + if (durabilityDamage > maxDurability) durabilityDamage = (short) maxDurability; armor.setDurability((short) (armor.getDurability() + durabilityDamage)); //Damage armor piece + } } targetPlayer.updateInventory(); } diff --git a/src/main/java/com/gmail/nossr50/util/Database.java b/src/main/java/com/gmail/nossr50/util/Database.java index 203732d91..16a60f5fe 100644 --- a/src/main/java/com/gmail/nossr50/util/Database.java +++ b/src/main/java/com/gmail/nossr50/util/Database.java @@ -17,20 +17,20 @@ import com.gmail.nossr50.runnables.SQLReconnect; public class Database { private static Config configInstance = Config.getInstance(); + private static String connectionString; - private static String connectionString = "jdbc:mysql://" + configInstance.getMySQLServerName() + ":" + configInstance.getMySQLServerPort() + "/" + configInstance.getMySQLDatabaseName() + "?user=" + configInstance.getMySQLUserName() + "&password=" + configInstance.getMySQLUserPassword(); private static String tablePrefix = configInstance.getMySQLTablePrefix(); private static Connection connection = null; private static mcMMO plugin = null; // Scale waiting time by this much per failed attempt - private static final double SCALING_FACTOR = 5; + private static final double SCALING_FACTOR = 10; // Minimum wait in nanoseconds (default 500ms) - private static final long MIN_WAIT = 500*100000L; + private static final long MIN_WAIT = 500L*1000000L; // Maximum time to wait between reconnects (default 5 minutes) - private static final long MAX_WAIT = 5*60000000000L; + private static final long MAX_WAIT = 5L * 60L * 1000L * 1000000L; // How long to wait when checking if connection is valid (default 3 seconds) private static final int VALID_TIMEOUT = 3; @@ -50,28 +50,27 @@ public class Database { * Attempt to connect to the mySQL database. */ public static void connect() { - try { - System.out.println("[mcMMO] Attempting connection to MySQL..."); + connectionString = "jdbc:mysql://" + configInstance.getMySQLServerName() + ":" + configInstance.getMySQLServerPort() + "/" + configInstance.getMySQLDatabaseName(); + try { + mcMMO.p.getLogger().info("Attempting connection to MySQL..."); - // Force driver to load if not yet loaded - Class.forName("com.mysql.jdbc.Driver"); - Properties connectionProperties = new Properties(); - connectionProperties.put("autoReconnect", "false"); - connectionProperties.put("maxReconnects", "0"); - connection = DriverManager.getConnection(connectionString, connectionProperties); + // Force driver to load if not yet loaded + Class.forName("com.mysql.jdbc.Driver"); + Properties connectionProperties = new Properties(); + connectionProperties.put("user", configInstance.getMySQLUserName()); + connectionProperties.put("password", configInstance.getMySQLUserPassword()); + connectionProperties.put("autoReconnect", "false"); + connectionProperties.put("maxReconnects", "0"); + connection = DriverManager.getConnection(connectionString, connectionProperties); - System.out.println("[mcMMO] Connection to MySQL was a success!"); - } - catch (SQLException ex) { - connection = null; - System.out.println("[mcMMO] Connection to MySQL failed!"); - ex.printStackTrace(); - printErrors(ex); - } catch (ClassNotFoundException ex) { - connection = null; - System.out.println("[mcMMO] MySQL database driver not found!"); - ex.printStackTrace(); - } + mcMMO.p.getLogger().info("Connection to MySQL was a success!"); + } catch (SQLException ex) { + connection = null; + if(reconnectAttempt == 0 || reconnectAttempt >= 11) mcMMO.p.getLogger().info("Connection to MySQL failed!"); + } catch (ClassNotFoundException ex) { + connection = null; + if(reconnectAttempt == 0 || reconnectAttempt >= 11) mcMMO.p.getLogger().info("MySQL database driver not found!"); + } } /** @@ -156,6 +155,7 @@ public class Database { PreparedStatement statement = null; try { + if(!checkConnected()) return; statement = connection.prepareStatement(sql); resultSet = statement.executeQuery(); @@ -172,12 +172,12 @@ public class Database { catch (SQLException ex) { switch (update) { case BLAST_MINING: - System.out.println("Updating mcMMO MySQL tables for Blast Mining..."); + mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Blast Mining..."); write("ALTER TABLE `"+tablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;"); break; case FISHING: - System.out.println("Updating mcMMO MySQL tables for Fishing..."); + mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Fishing..."); write("ALTER TABLE `"+tablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;"); write("ALTER TABLE `"+tablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;"); break; diff --git a/src/main/java/com/gmail/nossr50/util/ItemChecks.java b/src/main/java/com/gmail/nossr50/util/ItemChecks.java index 098a42a9e..41c987f98 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ItemChecks.java @@ -474,4 +474,39 @@ public class ItemChecks { public static boolean isEnchantable(ItemStack is) { return isArmor(is) || isSword(is) || isAxe(is) || isShovel(is) || isPickaxe(is) || (is.getType() == Material.BOW); } + + /** + * Get the maximum durability of an armor type. + * + * @param is Item to check + * @return maximum durability value. + */ + public static int getMaxDurabilityArmor(ItemStack is) { + int durability = 0; + if (isDiamondArmor(is)) { + if (isHelmet(is)) durability = 364; + else if (isChestplate(is)) durability = 529; + else if (isPants(is)) durability = 496; + else if (isBoots(is)) durability = 430; + } + else if (isIronArmor(is)) { + if (isHelmet(is)) durability = 166; + else if (isChestplate(is)) durability = 242; + else if (isPants(is)) durability = 226; + else if (isBoots(is)) durability = 196; + } + else if (isGoldArmor(is)) { + if (isHelmet(is)) durability = 78; + else if (isChestplate(is)) durability = 114; + else if (isPants(is)) durability = 106; + else if (isBoots(is)) durability = 92; + } + else if (isLeatherArmor(is)) { + if (isHelmet(is)) durability = 56; + else if (isChestplate(is)) durability = 82; + else if (isPants(is)) durability = 76; + else if (isBoots(is)) durability = 66; + } + return durability; + } } diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index 939e69e55..1191f3f79 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -45,6 +45,7 @@ Skills: GreaterImpact_KnockbackModifier: 1.5 GreaterImpact_BonusDamage: 2 ArmorImpact_IncreaseLevel: 50 + ArmorImpact_MaxPercentageDurabilityDamage: 20 Fishing: Shake_UnlockLevel: 150 Enchantment_Chance: 10