Debug and enhancements for the reset method.

This commit is contained in:
Ka0rX 2022-11-05 21:02:27 +01:00
parent 06985321d6
commit 9e821c79db
3 changed files with 222 additions and 186 deletions

View File

@ -173,10 +173,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
j++; j++;
} }
for(SkillTree skillTree:profess.getSkillTrees()) { for (SkillTree skillTree : profess.getSkillTrees()) {
for(SkillTreeNode node: skillTree.getNodes()) { for (SkillTreeNode node : skillTree.getNodes()) {
if(!nodeLevels.containsKey(node)) if (!nodeLevels.containsKey(node))
nodeLevels.put(node,0); nodeLevels.put(node, 0);
} }
} }
@ -196,7 +196,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
node.getExperienceTable().claimStatTriggers(this, node); node.getExperienceTable().claimStatTriggers(this, node);
} }
} }
statLoaded=true; statLoaded = true;
} }
@ -233,6 +233,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return new HashMap(skillTreePoints); return new HashMap(skillTreePoints);
} }
public void clearSkillTreePoints() { public void clearSkillTreePoints() {
skillTreePoints.clear(); skillTreePoints.clear();
} }
@ -371,21 +373,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return result; return result;
} }
public void resetNodeTimesClaimed() { public void resetTimesClaimed() {
Map<String, Integer> newTableItemClaims = new HashMap<>();
tableItemClaims.forEach((str, val) -> {
if (!str.startsWith(SkillTreeNode.getPrefix()))
newTableItemClaims.put(str, val);
});
tableItemClaims.clear(); tableItemClaims.clear();
tableItemClaims.putAll(newTableItemClaims);
} }
public void addNodeLevel(SkillTreeNode node) {
nodeLevels.put(node, nodeLevels.get(node) + 1);
}
@Override @Override
public void close() { public void close() {
@ -804,7 +796,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
* If it's null, no hologram will be displayed * If it's null, no hologram will be displayed
* @param splitExp Should the exp be split among party members * @param splitExp Should the exp be split among party members
*/ */
public void giveExperience(double value, EXPSource source, @Nullable Location hologramLocation, boolean splitExp) { public void giveExperience(double value, EXPSource source, @Nullable Location hologramLocation,
boolean splitExp) {
if (value <= 0) if (value <= 0)
return; return;

View File

@ -4,6 +4,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes; import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.tree.skilltree.SkillTree;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -14,210 +15,250 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter; import io.lumine.mythic.lib.command.api.Parameter;
public class ResetCommandTreeNode extends CommandTreeNode { public class ResetCommandTreeNode extends CommandTreeNode {
public ResetCommandTreeNode(CommandTreeNode parent) { public ResetCommandTreeNode(CommandTreeNode parent) {
super(parent, "reset"); super(parent, "reset");
addChild(new ResetLevelsCommandTreeNode(this)); addChild(new ResetLevelsCommandTreeNode(this));
addChild(new ResetSkillsCommandTreeNode(this)); addChild(new ResetSkillsCommandTreeNode(this));
addChild(new ResetAllCommandTreeNode(this)); addChild(new ResetAllCommandTreeNode(this));
addChild(new ResetAttributesCommandTreeNode(this)); addChild(new ResetAttributesCommandTreeNode(this));
addChild(new ResetWaypointsCommandTreeNode(this)); addChild(new ResetWaypointsCommandTreeNode(this));
} addChild(new ResetSkillTreesCommandTreeNode(this));
}
@Override @Override
public CommandResult execute(CommandSender sender, String[] args) { public CommandResult execute(CommandSender sender, String[] args) {
return CommandResult.THROW_USAGE; return CommandResult.THROW_USAGE;
} }
public static class ResetAllCommandTreeNode extends CommandTreeNode { public static class ResetAllCommandTreeNode extends CommandTreeNode {
public ResetAllCommandTreeNode(CommandTreeNode parent) { public ResetAllCommandTreeNode(CommandTreeNode parent) {
super(parent, "all"); super(parent, "all");
addParameter(Parameter.PLAYER); addParameter(Parameter.PLAYER);
} }
@Override @Override
public CommandResult execute(CommandSender sender, String[] args) { public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 4) if (args.length < 4)
return CommandResult.THROW_USAGE; return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]); Player player = Bukkit.getPlayer(args[3]);
if (player == null) { if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
PlayerData data = PlayerData.get(player); PlayerData data = PlayerData.get(player);
MMOCore.plugin.dataProvider.getDataManager().getDefaultData().apply(data); MMOCore.plugin.dataProvider.getDataManager().getDefaultData().apply(data);
data.setExperience(0); data.setExperience(0);
for (Profession profession : MMOCore.plugin.professionManager.getAll()) { for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
data.getCollectionSkills().setExperience(profession, 0); data.getCollectionSkills().setExperience(profession, 0);
data.getCollectionSkills().setLevel(profession, 0); data.getCollectionSkills().setLevel(profession, 0);
} }
MMOCore.plugin.classManager.getAll().forEach(data::unloadClassInfo); MMOCore.plugin.classManager.getAll().forEach(data::unloadClassInfo);
data.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); data.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
data.mapSkillLevels().forEach((skill, level) -> data.resetSkillLevel(skill)); data.mapSkillLevels().forEach((skill, level) -> data.resetSkillLevel(skill));
while (data.hasSkillBound(0)) data.setSkillTreePoints("global", 0);
data.unbindSkill(0); for (SkillTree skillTree : data.getProfess().getSkillTrees()) {
data.getQuestData().resetFinishedQuests(); data.resetSkillTree(skillTree);
data.getQuestData().start(null); data.setSkillTreePoints(skillTree.getId(), 0);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, }
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s data was succesfully reset.");
return CommandResult.SUCCESS;
}
}
public static class ResetWaypointsCommandTreeNode extends CommandTreeNode { data.resetTimesClaimed();
public ResetWaypointsCommandTreeNode(CommandTreeNode parent) { while (data.hasSkillBound(0))
super(parent, "waypoints"); data.unbindSkill(0);
while (data.hasPassiveSkillBound(0))
data.unbindPassiveSkill(0);
data.getQuestData().resetFinishedQuests();
data.getQuestData().start(null);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s data was succesfully reset.");
return CommandResult.SUCCESS;
}
}
addParameter(Parameter.PLAYER); public static class ResetWaypointsCommandTreeNode extends CommandTreeNode {
} public ResetWaypointsCommandTreeNode(CommandTreeNode parent) {
super(parent, "waypoints");
@Override addParameter(Parameter.PLAYER);
public CommandResult execute(CommandSender sender, String[] args) { }
if (args.length < 4)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]); @Override
if (player == null) { public CommandResult execute(CommandSender sender, String[] args) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); if (args.length < 4)
return CommandResult.FAILURE; return CommandResult.THROW_USAGE;
}
PlayerData data = PlayerData.get(player); Player player = Bukkit.getPlayer(args[3]);
data.getWaypoints().clear(); if (player == null) {
return CommandResult.SUCCESS; sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
} return CommandResult.FAILURE;
} }
public static class ResetQuestsCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player);
public ResetQuestsCommandTreeNode(CommandTreeNode parent) { data.getWaypoints().clear();
super(parent, "quests"); return CommandResult.SUCCESS;
}
}
addParameter(Parameter.PLAYER); public static class ResetQuestsCommandTreeNode extends CommandTreeNode {
} public ResetQuestsCommandTreeNode(CommandTreeNode parent) {
super(parent, "quests");
@Override addParameter(Parameter.PLAYER);
public CommandResult execute(CommandSender sender, String[] args) { }
if (args.length < 4)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]); @Override
if (player == null) { public CommandResult execute(CommandSender sender, String[] args) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); if (args.length < 4)
return CommandResult.FAILURE; return CommandResult.THROW_USAGE;
}
PlayerData data = PlayerData.get(player); Player player = Bukkit.getPlayer(args[3]);
data.getQuestData().resetFinishedQuests(); if (player == null) {
data.getQuestData().start(null); sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.SUCCESS; return CommandResult.FAILURE;
} }
}
public static class ResetSkillsCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player);
public ResetSkillsCommandTreeNode(CommandTreeNode parent) { data.getQuestData().resetFinishedQuests();
super(parent, "skills"); data.getQuestData().start(null);
return CommandResult.SUCCESS;
}
}
addParameter(Parameter.PLAYER); public static class ResetSkillsCommandTreeNode extends CommandTreeNode {
} public ResetSkillsCommandTreeNode(CommandTreeNode parent) {
super(parent, "skills");
@Override addParameter(Parameter.PLAYER);
public CommandResult execute(CommandSender sender, String[] args) { }
if (args.length < 4)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]); @Override
if (player == null) { public CommandResult execute(CommandSender sender, String[] args) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); if (args.length < 4)
return CommandResult.FAILURE; return CommandResult.THROW_USAGE;
}
PlayerData data = PlayerData.get(player); Player player = Bukkit.getPlayer(args[3]);
data.mapSkillLevels().forEach((skill, level) -> data.resetSkillLevel(skill)); if (player == null) {
while (data.hasSkillBound(0)) sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
data.unbindSkill(0); return CommandResult.FAILURE;
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, }
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s skill data was succesfully reset.");
return CommandResult.SUCCESS;
}
}
public class ResetAttributesCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player);
public ResetAttributesCommandTreeNode(CommandTreeNode parent) { data.mapSkillLevels().forEach((skill, level) -> data.resetSkillLevel(skill));
super(parent, "attributes"); while (data.hasSkillBound(0))
data.unbindSkill(0);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s skill data was succesfully reset.");
return CommandResult.SUCCESS;
}
}
addParameter(Parameter.PLAYER);
addParameter(new Parameter("(-reallocate)", (explore, list) -> list.add("-reallocate")));
}
@Override public static class ResetSkillTreesCommandTreeNode extends CommandTreeNode {
public CommandResult execute(CommandSender sender, String[] args) { public ResetSkillTreesCommandTreeNode(CommandTreeNode parent) {
if (args.length < 4) super(parent, "skill-trees");
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]); addParameter(Parameter.PLAYER);
if (player == null) { }
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.FAILURE;
}
PlayerData data = PlayerData.get(player); @Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 4)
return CommandResult.THROW_USAGE;
/* Player player = Bukkit.getPlayer(args[3]);
* force reallocating of player attribute points if (player == null) {
*/ sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
if (args.length > 4 && args[4].equalsIgnoreCase("-reallocate")) { return CommandResult.FAILURE;
}
int points = 0; PlayerData data = PlayerData.get(player);
for (PlayerAttributes.AttributeInstance ins : data.getAttributes().getInstances()) { for (SkillTree skillTree : data.getProfess().getSkillTrees())
points += ins.getBase(); data.resetSkillTree(skillTree);
ins.setBase(0); CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
} ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s skill-tree data was succesfully reset.");
return CommandResult.SUCCESS;
}
}
data.giveAttributePoints(points); public class ResetAttributesCommandTreeNode extends CommandTreeNode {
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, public ResetAttributesCommandTreeNode(CommandTreeNode parent) {
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attribute points spendings were successfully reset."); super(parent, "attributes");
return CommandResult.SUCCESS;
}
data.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); addParameter(Parameter.PLAYER);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, addParameter(new Parameter("(-reallocate)", (explore, list) -> list.add("-reallocate")));
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attributes were succesfully reset."); }
return CommandResult.SUCCESS;
}
}
public static class ResetLevelsCommandTreeNode extends CommandTreeNode { @Override
public ResetLevelsCommandTreeNode(CommandTreeNode parent) { public CommandResult execute(CommandSender sender, String[] args) {
super(parent, "levels"); if (args.length < 4)
return CommandResult.THROW_USAGE;
addParameter(Parameter.PLAYER); Player player = Bukkit.getPlayer(args[3]);
} if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.FAILURE;
}
@Override PlayerData data = PlayerData.get(player);
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 4)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]); /*
if (player == null) { * force reallocating of player attribute points
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); */
return CommandResult.FAILURE; if (args.length > 4 && args[4].equalsIgnoreCase("-reallocate")) {
}
PlayerData data = PlayerData.get(player); int points = 0;
data.setLevel(MMOCore.plugin.dataProvider.getDataManager().getDefaultData().getLevel()); for (PlayerAttributes.AttributeInstance ins : data.getAttributes().getInstances()) {
data.setExperience(0); points += ins.getBase();
for (Profession profession : MMOCore.plugin.professionManager.getAll()) { ins.setBase(0);
data.getCollectionSkills().setExperience(profession, 0); }
data.getCollectionSkills().setLevel(profession, 0);
}
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s levels were succesfully reset.");
return CommandResult.SUCCESS; data.giveAttributePoints(points);
} CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
} ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attribute points spendings were successfully reset.");
return CommandResult.SUCCESS;
}
data.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attributes were succesfully reset.");
return CommandResult.SUCCESS;
}
}
public static class ResetLevelsCommandTreeNode extends CommandTreeNode {
public ResetLevelsCommandTreeNode(CommandTreeNode parent) {
super(parent, "levels");
addParameter(Parameter.PLAYER);
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 4)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[3]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
return CommandResult.FAILURE;
}
PlayerData data = PlayerData.get(player);
data.setLevel(MMOCore.plugin.dataProvider.getDataManager().getDefaultData().getLevel());
data.setExperience(0);
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
data.getCollectionSkills().setExperience(profession, 0);
data.getCollectionSkills().setLevel(profession, 0);
profession.getExperienceTable().reset(data, profession);
}
CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET,
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s levels were succesfully reset.");
return CommandResult.SUCCESS;
}
}
} }

View File

@ -184,6 +184,8 @@ public abstract class PlayerDataManager {
player.setSkillPoints(skillPoints); player.setSkillPoints(skillPoints);
player.setAttributePoints(attributePoints); player.setAttributePoints(attributePoints);
player.setAttributeReallocationPoints(attrReallocPoints); player.setAttributeReallocationPoints(attrReallocPoints);
player.setSkillTreeReallocationPoints(skillTreeReallocPoints);
player.setSkillReallocationPoints(skillReallocPoints);
} }
} }
} }