From f5fc9419166c6feef2bc1995b04fca68d73f7b6c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 1 Mar 2012 13:01:41 -0800 Subject: [PATCH] Cooldowns for Blast Mining are now fully functional (BUILD IS SAFE AGAIN) --- src/main/java/com/gmail/nossr50/Database.java | 8 +++++--- .../gmail/nossr50/datatypes/AbilityType.java | 7 ++++++- .../nossr50/datatypes/PlayerProfile.java | 2 +- .../nossr50/listeners/mcPlayerListener.java | 20 ++++++++++++++++++- .../com/gmail/nossr50/runnables/mcTimer.java | 16 ++++++++------- .../java/com/gmail/nossr50/skills/Skills.java | 4 +--- .../resources/locale/locale_en_us.properties | 4 +++- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/Database.java b/src/main/java/com/gmail/nossr50/Database.java index 05f9f3dfb..b9ede47f2 100644 --- a/src/main/java/com/gmail/nossr50/Database.java +++ b/src/main/java/com/gmail/nossr50/Database.java @@ -96,6 +96,7 @@ public class Database { + "`swords` int(32) unsigned NOT NULL DEFAULT '0'," + "`axes` int(32) unsigned NOT NULL DEFAULT '0'," + "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0'," + + "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0'," + "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); Write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "skills` (`user_id` int(10) unsigned NOT NULL," + "`taming` int(10) unsigned NOT NULL DEFAULT '0'," @@ -129,6 +130,7 @@ public class Database { Write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"spawn`"); checkDatabaseStructure(); + checkDatabaseStructureForBlastMining(); } public void checkDatabaseStructure() @@ -151,7 +153,7 @@ public class Database { } } } catch (SQLException ex) { - System.out.println("Updating mcMMO MySQL tables..."); + System.out.println("Updating mcMMO MySQL tables for Fishing..."); Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;"); Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;"); } @@ -177,8 +179,8 @@ public class Database { } } } catch (SQLException ex) { - System.out.println("Updating mcMMO MySQL tables..."); - Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "cooldowns` ADD `blast_mining` int(10) NOT NULL DEFAULT '0' ;"); + System.out.println("Updating mcMMO MySQL tables for Blast Mining..."); + Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;"); } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/AbilityType.java b/src/main/java/com/gmail/nossr50/datatypes/AbilityType.java index a7e4f2ef3..55caa5d1a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/AbilityType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/AbilityType.java @@ -15,7 +15,7 @@ public enum AbilityType SKULL_SPLIITER(LoadProperties.skullSplitterCooldown, mcLocale.getString("Skills.SkullSplitterOn"), mcLocale.getString("Skills.SkullSplitterOff"), "Skills.SkullSplitterPlayer", mcLocale.getString("Skills.YourSkullSplitter"), "Skills.SkullSplitterPlayerOff"), TREE_FELLER(LoadProperties.treeFellerCooldown, mcLocale.getString("Skills.TreeFellerOn"), mcLocale.getString("Skills.TreeFellerOff"), "Skills.TreeFellerPlayer", mcLocale.getString("Skills.YourTreeFeller"), "Skills.TreeFellerPlayerOff"), SERRATED_STRIKES(LoadProperties.skullSplitterCooldown, mcLocale.getString("Skills.SerratedStrikesOn"), mcLocale.getString("Skills.SerratedStrikesOff"), "Skills.SerratedStrikesPlayer", mcLocale.getString("Skills.YourSerratedStrikes"), "Skills.SerratedStrikesPlayerOff"), - BLAST_MINING(LoadProperties.blastMiningCooldown, mcLocale.getString("Skills.BlastMiningOn"), mcLocale.getString("Skills.BlastMiningOff"), "Skills.BlastMiningPlayer", mcLocale.getString("Skills.YourBlastMining"), "Skills.BlastMiningPlayerOff"); + BLAST_MINING(LoadProperties.blastMiningCooldown, "NOT NEEDED FOR BLAST MINING", "NOT NEEDED FOR BLAST MINING", "Skills.BlastMiningPlayer", mcLocale.getString("Skills.YourBlastMining"), "NOT NEEDED FOR BLAST MINING"); private int cooldown; private String abilityOn; @@ -118,6 +118,8 @@ public enum AbilityType { switch(this) { + case BLAST_MINING: + return PP.getBlastMiningInformed(); case BERSERK: return PP.getBerserkInformed(); case SUPER_BREAKER: @@ -140,6 +142,9 @@ public enum AbilityType { switch(this) { + case BLAST_MINING: + PP.setBlastMiningInformed(bool); + break; case BERSERK: PP.setBerserkInformed(bool); break; diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 5a0cde0f4..b3b9759ef 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -171,7 +171,7 @@ public class PlayerProfile HashMap> users = mcMMO.database.Read("SELECT lastlogin, party FROM "+LoadProperties.MySQLtablePrefix+"users WHERE id = " + id); //lastlogin = Integer.parseInt(users.get(1).get(0)); party = users.get(1).get(1); - HashMap> cooldowns = mcMMO.database.Read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes FROM "+LoadProperties.MySQLtablePrefix+"cooldowns WHERE user_id = " + id); + HashMap> cooldowns = mcMMO.database.Read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM "+LoadProperties.MySQLtablePrefix+"cooldowns WHERE user_id = " + id); /* * I'm still learning MySQL, this is a fix for adding a new table * its not pretty but it works diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index ad3613ac8..8408eb94a 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -56,6 +56,7 @@ import com.gmail.nossr50.commands.general.XprateCommand; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.runnables.RemoveProfileFromMemoryTask; import com.gmail.nossr50.spout.SpoutStuff; +import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; @@ -282,14 +283,31 @@ public class mcPlayerListener implements Listener } } - if(action == Action.RIGHT_CLICK_AIR && is.getTypeId() == LoadProperties.detonatorID) + //BLAST MINING + if((action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) && is.getTypeId() == LoadProperties.detonatorID) { Block b = player.getTargetBlock(null, 100); if(b.getType().equals(Material.TNT)) { + AbilityType ability = AbilityType.BLAST_MINING; + //Check cooldown + if(!Skills.cooldownOver(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown())) + { + player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown()) + "s)"); + return; + } + //Send message to nearby players + for(Player y : player.getWorld().getPlayers()) + { + if(y != player && m.isNear(player.getLocation(), y.getLocation(), 10)) + y.sendMessage(ability.getAbilityPlayer(player)); + } + TNTPrimed tnt = player.getWorld().spawn(b.getLocation(), TNTPrimed.class); b.setType(Material.AIR); tnt.setFuseTicks(0); + PP.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining + PP.setBlastMiningInformed(false); } } } diff --git a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java index bc9fb4829..4047916d2 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java @@ -20,6 +20,7 @@ import org.bukkit.entity.*; import com.gmail.nossr50.Combat; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; @@ -63,13 +64,14 @@ public class mcTimer implements Runnable /* * COOLDOWN MONITORING */ - Skills.watchCooldown(player, PP, curTime, SkillType.AXES); - Skills.watchCooldown(player, PP, curTime, SkillType.EXCAVATION); - Skills.watchCooldown(player, PP, curTime, SkillType.HERBALISM); - Skills.watchCooldown(player, PP, curTime, SkillType.MINING); - Skills.watchCooldown(player, PP, curTime, SkillType.SWORDS); - Skills.watchCooldown(player, PP, curTime, SkillType.UNARMED); - Skills.watchCooldown(player, PP, curTime, SkillType.WOODCUTTING); + Skills.watchCooldown(player, PP, curTime, AbilityType.SKULL_SPLIITER); + Skills.watchCooldown(player, PP, curTime, AbilityType.GIGA_DRILL_BREAKER); + Skills.watchCooldown(player, PP, curTime, AbilityType.GREEN_TERRA); + Skills.watchCooldown(player, PP, curTime, AbilityType.SUPER_BREAKER); + Skills.watchCooldown(player, PP, curTime, AbilityType.SERRATED_STRIKES); + Skills.watchCooldown(player, PP, curTime, AbilityType.BERSERK); + Skills.watchCooldown(player, PP, curTime, AbilityType.TREE_FELLER); + Skills.watchCooldown(player, PP, curTime, AbilityType.BLAST_MINING); /* * PLAYER BLEED MONITORING diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index e0b5123f5..a24aa36ba 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -55,10 +55,8 @@ public class Skills return (int) (((deactivatedTimeStamp + (cooldown * 1000)) - System.currentTimeMillis())/1000); } - public static void watchCooldown(Player player, PlayerProfile PP, long curTime, SkillType skill) + public static void watchCooldown(Player player, PlayerProfile PP, long curTime, AbilityType ability) { - AbilityType ability = skill.getAbility(); - if(!ability.getInformed(PP) && curTime - (PP.getSkillDATS(ability) * 1000) >= (ability.getCooldown() * 1000)) { ability.setInformed(PP, true); diff --git a/src/main/resources/locale/locale_en_us.properties b/src/main/resources/locale/locale_en_us.properties index e30f7dbf9..2d19b2fba 100644 --- a/src/main/resources/locale/locale_en_us.properties +++ b/src/main/resources/locale/locale_en_us.properties @@ -412,4 +412,6 @@ Skills.TreeFellerPlayerOff=[[RED]]Tree Feller[[GREEN]] has worn off for [[YELLOW Skills.SuperBreakerPlayerOff=[[RED]]Super Breaker[[GREEN]] has worn off for [[YELLOW]]{0} Skills.SkullSplitterPlayerOff=[[RED]]Skull Splitter[[GREEN]] has worn off for [[YELLOW]]{0} Skills.GigaDrillBreakerPlayerOff=[[RED]]Giga Drill Breaker[[GREEN]] has worn off for [[YELLOW]]{0} -Skills.SerratedStrikesPlayerOff=[[RED]]Serrated Strikes[[GREEN]] has worn off for [[YELLOW]]{0} \ No newline at end of file +Skills.SerratedStrikesPlayerOff=[[RED]]Serrated Strikes[[GREEN]] has worn off for [[YELLOW]]{0} +Skills.BlastMiningPlayer=[[GREEN]]{0}[[DARK_GREEN]] has used [[RED]]Blast Mining! +Skills.YourBlastMining=[[GREEN]]Your [[YELLOW]]Blast Mining [[GREEN]]ability is refreshed! \ No newline at end of file