mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-18 16:35:25 +01:00
Fixed Tool objects being shared by all players
This commit is contained in:
parent
12b548bf46
commit
e80f60ccee
@ -13,6 +13,8 @@ import com.gmail.nossr50.config.Config;
|
|||||||
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
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.datatypes.spout.huds.McMMOHud;
|
||||||
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
|
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
@ -77,6 +79,19 @@ public class McMMOPlayer {
|
|||||||
profile = new PlayerProfile(playerName, true);
|
profile = new PlayerProfile(playerName, true);
|
||||||
party = PartyManager.getPlayerParty(playerName);
|
party = PartyManager.getPlayerParty(playerName);
|
||||||
|
|
||||||
|
Map<ToolType, Tool> tools = new HashMap<ToolType, Tool>();
|
||||||
|
|
||||||
|
// 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),
|
* 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.
|
* 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
|
// TODO: The null check is needed only because currently some SkillType doesn't have a valid skillManagerClass
|
||||||
if (skillManagerClass != null) {
|
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));
|
skillManagers.put(skillType, skillManagerClass.getConstructor(McMMOPlayer.class).newInstance(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,11 @@
|
|||||||
package com.gmail.nossr50.datatypes.skills;
|
package com.gmail.nossr50.datatypes.skills;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
|
||||||
public class Tool {
|
public class Tool {
|
||||||
private static Map<ToolType, Tool> tools = new HashMap<ToolType, Tool>();
|
|
||||||
private boolean preparationMode = true;
|
private boolean preparationMode = true;
|
||||||
private long preparationATS;
|
private long preparationATS;
|
||||||
|
|
||||||
private Tool(ToolType toolType) {
|
|
||||||
tools.put(toolType, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getPreparationMode() {
|
public boolean getPreparationMode() {
|
||||||
return preparationMode;
|
return preparationMode;
|
||||||
}
|
}
|
||||||
@ -31,14 +23,4 @@ public class Tool {
|
|||||||
|
|
||||||
preparationATS = startTime;
|
preparationATS = startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tool getTool(ToolType toolType) {
|
|
||||||
Tool tool = tools.get(toolType);
|
|
||||||
|
|
||||||
if (tool == null) {
|
|
||||||
tool = new Tool(toolType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tool;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ public abstract class SkillManager {
|
|||||||
this.mcMMOPlayer = mcMMOPlayer;
|
this.mcMMOPlayer = mcMMOPlayer;
|
||||||
this.activationChance = PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), skill);
|
this.activationChance = PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), skill);
|
||||||
this.skill = skill;
|
this.skill = skill;
|
||||||
this.tool = Tool.getTool(skill.getToolType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public McMMOPlayer getMcMMOPlayer() {
|
public McMMOPlayer getMcMMOPlayer() {
|
||||||
@ -66,4 +65,8 @@ public abstract class SkillManager {
|
|||||||
public Tool getTool() {
|
public Tool getTool() {
|
||||||
return tool;
|
return tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTool(Tool tool) {
|
||||||
|
this.tool = tool;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user