From 3a812612dee484dd6276e7bbdb6641b6802ecc2a Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 9 Feb 2012 15:28:05 -0800 Subject: [PATCH] Fixed a major problem where the hashmap wasn't initialized on PlayerProfile creation. However there is still a big bug with abilities instantly wearing off and refreshing. --- .../nossr50/datatypes/PlayerProfile.java | 24 +++++++++---------- .../java/com/gmail/nossr50/skills/Axes.java | 2 +- .../com/gmail/nossr50/skills/Excavation.java | 2 +- .../com/gmail/nossr50/skills/Herbalism.java | 2 +- .../java/com/gmail/nossr50/skills/Mining.java | 2 +- .../java/com/gmail/nossr50/skills/Swords.java | 2 +- .../com/gmail/nossr50/skills/Unarmed.java | 3 ++- .../com/gmail/nossr50/skills/WoodCutting.java | 2 +- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 2d78dc888..11e290272 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -69,7 +69,6 @@ public class PlayerProfile //Time to HashMap this shiz HashMap skills = new HashMap(); //Skills and XP HashMap skillsXp = new HashMap(); //Skills and XP - HashMap skillsATS = new HashMap(); //Skill ATS HashMap skillsDATS = new HashMap(); //Skill ATS String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users"; @@ -77,6 +76,12 @@ public class PlayerProfile public PlayerProfile(Player player) { hud = LoadProperties.defaulthud; + //Setup the HashMap for ability ATS & DATS + for(AbilityType abilityType : AbilityType.values()) + { + skillsDATS.put(abilityType, 0); + } + //Setup the HashMap for the skills for(SkillType skillType : SkillType.values()) { @@ -817,22 +822,17 @@ public class PlayerProfile { skills.put(skillType, 0); } - public int getSkillATS(AbilityType abilityType) - { - return skillsATS.get(abilityType); - } - public void setSkillATS(AbilityType abilityType, int ticks) - { - skillsATS.put(abilityType, (int) System.currentTimeMillis()/1000); - setSkillDATS(abilityType, ticks); - } public int getSkillDATS(AbilityType abilityType) { return skillsDATS.get(abilityType); } - private void setSkillDATS(AbilityType abilityType, int ticks) + public void setSkillDATS(AbilityType abilityType, long value) { - skillsDATS.put(abilityType, (int) (System.currentTimeMillis() + (ticks * 1000))/1000); + System.out.println("Storing to DATS: "+value); + int wearsOff = (int) (value * .001D); + System.out.println("After dividing by 1000: "+wearsOff); + skillsDATS.put(abilityType, wearsOff); + System.out.println("Should be the same as the above value: "+skillsDATS.get(abilityType)); } public void resetCooldowns() { diff --git a/src/main/java/com/gmail/nossr50/skills/Axes.java b/src/main/java/com/gmail/nossr50/skills/Axes.java index f39dad29e..01ce3cc95 100644 --- a/src/main/java/com/gmail/nossr50/skills/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/Axes.java @@ -60,7 +60,7 @@ public class Axes { if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.SkullSplitterPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.SKULL_SPLIITER, ticks); + PP.setSkillDATS(AbilityType.SKULL_SPLIITER, System.currentTimeMillis()+(ticks*1000)); PP.setSkullSplitterMode(true); } if(!PP.getSkullSplitterMode() && !Skills.cooldownOver(player, (PP.getSkillDATS(AbilityType.SKULL_SPLIITER)*1000), LoadProperties.skullSplitterCooldown)){ diff --git a/src/main/java/com/gmail/nossr50/skills/Excavation.java b/src/main/java/com/gmail/nossr50/skills/Excavation.java index fbf4e86e0..ea780c1e5 100644 --- a/src/main/java/com/gmail/nossr50/skills/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/Excavation.java @@ -69,7 +69,7 @@ public class Excavation if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.GIGA_DRILL_BREAKER, ticks); + PP.setSkillDATS(AbilityType.GIGA_DRILL_BREAKER, System.currentTimeMillis()+(ticks*1000)); PP.setGigaDrillBreakerMode(true); } diff --git a/src/main/java/com/gmail/nossr50/skills/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/Herbalism.java index 8e963f9dd..f5e4212e2 100644 --- a/src/main/java/com/gmail/nossr50/skills/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/Herbalism.java @@ -66,7 +66,7 @@ public class Herbalism if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.GreenTerraPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.GREEN_TERRA, ticks); + PP.setSkillDATS(AbilityType.GREEN_TERRA, System.currentTimeMillis()+(ticks*1000)); PP.setGreenTerraMode(true); } diff --git a/src/main/java/com/gmail/nossr50/skills/Mining.java b/src/main/java/com/gmail/nossr50/skills/Mining.java index 4cbf6cae2..1a80504df 100644 --- a/src/main/java/com/gmail/nossr50/skills/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/Mining.java @@ -70,7 +70,7 @@ public class Mining if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.SuperBreakerPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.SUPER_BREAKER, ticks); + PP.setSkillDATS(AbilityType.SUPER_BREAKER, System.currentTimeMillis()+(ticks*1000)); PP.setSuperBreakerMode(true); } diff --git a/src/main/java/com/gmail/nossr50/skills/Swords.java b/src/main/java/com/gmail/nossr50/skills/Swords.java index 47d7b7f5b..4f54dd241 100644 --- a/src/main/java/com/gmail/nossr50/skills/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/Swords.java @@ -59,7 +59,7 @@ public class Swords if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.SerratedStrikesPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.SERRATED_STRIKES, ticks); + PP.setSkillDATS(AbilityType.SERRATED_STRIKES, System.currentTimeMillis()+(ticks*1000)); PP.setSerratedStrikesMode(true); } diff --git a/src/main/java/com/gmail/nossr50/skills/Unarmed.java b/src/main/java/com/gmail/nossr50/skills/Unarmed.java index ba9c76cca..fbf1d6e6d 100644 --- a/src/main/java/com/gmail/nossr50/skills/Unarmed.java +++ b/src/main/java/com/gmail/nossr50/skills/Unarmed.java @@ -53,7 +53,8 @@ public class Unarmed { if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.BerserkPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.BERSERK, ticks); + PP.setSkillDATS(AbilityType.BERSERK, System.currentTimeMillis()+(ticks*1000)); + System.out.println("getSkillDATS(): "+PP.getSkillDATS(AbilityType.BERSERK)); PP.setBerserkMode(true); } } diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index 49e1a6b3f..0813302d6 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -90,7 +90,7 @@ public class WoodCutting if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10) y.sendMessage(mcLocale.getString("Skills.TreeFellerPlayer", new Object[] {player.getName()})); } - PP.setSkillATS(AbilityType.TREE_FELLER, ticks); + PP.setSkillDATS(AbilityType.TREE_FELLER, System.currentTimeMillis()+(ticks*1000)); PP.setTreeFellerMode(true); } if(!PP.getTreeFellerMode() && !Skills.cooldownOver(player, (PP.getSkillDATS(AbilityType.TREE_FELLER)*1000), LoadProperties.treeFellerCooldown)){