From f5ddf1bc0e74a2198d6efe77860631ecb91f5a39 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 17 Apr 2012 16:22:57 -0400 Subject: [PATCH] Fixed bug with only getting one level when there was enough XP for multiple levels. Fixes MCCORE-191 --- Changelog.txt | 6 +++-- .../nossr50/datatypes/PlayerProfile.java | 25 +++++++++++++++++++ .../java/com/gmail/nossr50/skills/Repair.java | 1 + .../java/com/gmail/nossr50/skills/Skills.java | 16 ++++++------ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index e3958d94c..36cf00037 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -15,14 +15,16 @@ Version 1.3.06-dev = Fixed mmoupdate not being useable from console = Fixed bug with repairing wooden tools = Fixed bug with Nether Wart not awarding XP - = Fixed bug with fishing treasures when treasures list is empty + = Fixed bug with fishing treasures when treasures list is empty + = Fixed bug with only getting one level when there was enough XP for multiple levels. ! Changed mcremove to no longer kick players when they are removed from database ! Changed mcremove to work on offline users for FlatFile ! Changed PlayerProfile constructor to always take a boolean ! Changed getPlayerProfile function to work for online & offline users ! Changed Archery's Daze to deal 4 DMG on proc (2 Hearts) ! Changed /addlevel command to work for offline users - ! Changed party & admin chat handling to be nicer to developers + ! Changed party & admin chat handling to be nicer to developers + ! Changed UpdateXPBar function to hopefully avoid errors Version 1.3.05 + Added Skill Shot to Archery which increases damage dealt by 10% every 50 skill levels (caps at 200%) diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 17d14d8ed..01daf227a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -964,6 +964,10 @@ public class PlayerProfile { return skillsXp.get(skillType); } + public void skillUp(SkillType skillType, int newValue) { + skills.put(skillType, skills.get(skillType) + newValue); + } + /** * Adds XP to the player, doesn't calculate for XP Rate * @@ -1038,6 +1042,27 @@ public class PlayerProfile { lastgained = skillType; } + /** + * Remove XP from a skill. + * + * @param skillType Type of skill to modify + * @param xp Amount of xp to remove + */ + public void removeXP(SkillType skillType, int xp) { + if (skillType.equals(SkillType.ALL)) { + for (SkillType skill : SkillType.values()) { + if (skill.equals(SkillType.ALL)) { + continue; + } + + skillsXp.put(skill, skillsXp.get(skill) - xp); + } + } + else { + skillsXp.put(skillType, skillsXp.get(skillType) - xp); + } + } + /** * Modify a skill level. * diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index 95187e73b..8a37dd84f 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -11,6 +11,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; + import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.player.SpoutPlayer; diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index 68909aace..b918469c8 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -189,14 +189,13 @@ public class Skills { while (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) { if ((skillType.getMaxLevel() >= PP.getSkillLevel(skillType) + 1) && (m.getPowerLevelCap() >= PP.getPowerLevel() + 1)) { skillups++; - PP.addLevels(skillType, 1); + PP.skillUp(skillType, 1); McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType); Bukkit.getPluginManager().callEvent(eventToFire); } - else { - PP.addLevels(skillType, 0); - } + + PP.removeXP(skillType, PP.getXpToLevel(skillType)); } if (!LoadProperties.useMySQL) { @@ -212,15 +211,14 @@ public class Skills { if (sPlayer.isSpoutCraftEnabled()) { if (LoadProperties.xpbar) { - SpoutStuff.updateXpBar(sPlayer); + SpoutStuff.updateXpBar(player); } SpoutStuff.levelUpNotification(skillType, sPlayer); - + /* Update custom titles */ if(LoadProperties.showPowerLevel) { - sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" - + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(PP.getPowerLevel())); + sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE + "." + ChatColor.GREEN + String.valueOf(PP.getPowerLevel())); } } else { @@ -237,7 +235,7 @@ public class Skills { SpoutPlayer sPlayer = (SpoutPlayer) player; if (sPlayer.isSpoutCraftEnabled()) { if (LoadProperties.xpbar) { - SpoutStuff.updateXpBar(sPlayer); + SpoutStuff.updateXpBar(player); } } }