diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index bc7de14bc..f4522eafa 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -13,6 +13,8 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.datatypes.skills.Tool; +import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.datatypes.spout.huds.McMMOHud; import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent; import com.gmail.nossr50.party.PartyManager; @@ -77,6 +79,19 @@ public class McMMOPlayer { profile = new PlayerProfile(playerName, true); party = PartyManager.getPlayerParty(playerName); + Map tools = new HashMap(); + + // Build Tool objects for the current player, a tool can be used by multiple skills + for (SkillType skillType : SkillType.values()) { + ToolType toolType = skillType.getToolType(); + + if (tools.containsKey(toolType)) { + continue; + } + + tools.put(toolType, new Tool()); + } + /* * I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually), * but I actually have no idea about the performance impact, if there is any. @@ -88,6 +103,9 @@ public class McMMOPlayer { // TODO: The null check is needed only because currently some SkillType doesn't have a valid skillManagerClass if (skillManagerClass != null) { + SkillManager skillManager = skillManagerClass.getConstructor(McMMOPlayer.class).newInstance(this); + + skillManager.setTool(tools.get(skillType)); skillManagers.put(skillType, skillManagerClass.getConstructor(McMMOPlayer.class).newInstance(this)); } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java b/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java index 2a0ab605c..b3ff772eb 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java @@ -1,19 +1,11 @@ package com.gmail.nossr50.datatypes.skills; -import java.util.HashMap; -import java.util.Map; - import com.gmail.nossr50.util.Misc; public class Tool { - private static Map tools = new HashMap(); private boolean preparationMode = true; private long preparationATS; - private Tool(ToolType toolType) { - tools.put(toolType, this); - } - public boolean getPreparationMode() { return preparationMode; } @@ -31,14 +23,4 @@ public class Tool { preparationATS = startTime; } - - public static Tool getTool(ToolType toolType) { - Tool tool = tools.get(toolType); - - if (tool == null) { - tool = new Tool(toolType); - } - - return tool; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java index 1853ef507..b3d943447 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManager.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -20,7 +20,6 @@ public abstract class SkillManager { this.mcMMOPlayer = mcMMOPlayer; this.activationChance = PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), skill); this.skill = skill; - this.tool = Tool.getTool(skill.getToolType()); } public McMMOPlayer getMcMMOPlayer() { @@ -66,4 +65,8 @@ public abstract class SkillManager { public Tool getTool() { return tool; } + + public void setTool(Tool tool) { + this.tool = tool; + } }