Skill Tree Points

This commit is contained in:
Ka0rX 2022-08-18 09:04:04 +02:00
parent 4e517f4053
commit 5a75156411
5 changed files with 37 additions and 15 deletions

View File

@ -236,7 +236,7 @@ public class MMOCore extends JavaPlugin {
// Load MMOCore-Bukkit module
try {
Class.forName("net.Indyuce.mmocore.MMOCoreBukkit").getConstructor(MMOCore.class).newInstance(this);
} catch(Throwable exception) {
} catch (Throwable exception) {
throw new RuntimeException("Cannot run an API build on Spigot!");
}
@ -368,7 +368,7 @@ public class MMOCore extends JavaPlugin {
classManager.initialize(clearBefore);
InventoryManager.load();
skillTreeManager.initialize(clearBefore);
questManager.initialize(clearBefore);
lootChests.initialize(clearBefore);
restrictionManager.initialize(clearBefore);

View File

@ -389,8 +389,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
@NotNull
public SkillTree getOpenedSkillTree() {
if (cachedSkillTree == null)
return MMOCore.plugin.skillTreeManager.getAll().stream().findFirst().get();
if (cachedSkillTree == null) {
Optional<SkillTree> optionnal=MMOCore.plugin.skillTreeManager.getAll().stream().findFirst();
return optionnal.isPresent()?optionnal.get():null;
}
return cachedSkillTree;
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.command;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.event.MMOCommandEvent;
import net.Indyuce.mmocore.manager.InventoryManager;
@ -17,16 +18,20 @@ public class SkillTreeCommand extends BukkitCommand {
setAliases(config.getStringList("aliases"));
setDescription("Opens the skills menu.");
}
@Override
public boolean execute(@NotNull CommandSender sender, String s, String[] args) {
if (!(sender instanceof Player))
return false;
PlayerData data = PlayerData.get((Player) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "skills");
MMOCommandEvent event = new MMOCommandEvent(data, "skilltree");
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
return true;
InventoryManager.TREE_VIEW.newInventory(data).open();
if (MMOCore.plugin.skillTreeManager.getAll().size() != 0) {
InventoryManager.TREE_VIEW.newInventory(data).open();
return false;
}
return true;
}

View File

@ -16,7 +16,7 @@ import java.util.*;
public abstract class PlayerDataManager {
private final static Map<UUID, PlayerData> data = Collections.synchronizedMap(new HashMap<>());
private DefaultPlayerData defaultData = new DefaultPlayerData(1, 0, 0, 0, 0,0);
private DefaultPlayerData defaultData = new DefaultPlayerData(1, 0, 0, 0, 0, 0,0);
public PlayerData get(OfflinePlayer player) {
return get(player.getUniqueId());
@ -134,7 +134,7 @@ public abstract class PlayerDataManager {
public abstract void saveData(PlayerData data);
public class DefaultPlayerData {
private final int level, classPoints, skillPoints, attributePoints, attrReallocPoints,skillReallocPoints;
private final int level, classPoints, skillPoints, attributePoints, attrReallocPoints, skillReallocPoints, skillTreeReallocPoints;
public DefaultPlayerData(ConfigurationSection config) {
level = config.getInt("level", 1);
@ -142,17 +142,19 @@ public abstract class PlayerDataManager {
skillPoints = config.getInt("skill-points");
attributePoints = config.getInt("attribute-points");
attrReallocPoints = config.getInt("attribute-realloc-points");
skillReallocPoints=config.getInt("skill-realloc-points",0);
skillReallocPoints = config.getInt("skill-realloc-points", 0);
skillTreeReallocPoints = config.getInt("skill-tree-realloc-points", 0);
}
public DefaultPlayerData(int level, int classPoints, int skillPoints, int attributePoints, int attrReallocPoints,int skillReallocPoints) {
public DefaultPlayerData(int level, int classPoints, int skillPoints, int attributePoints, int attrReallocPoints, int skillReallocPoints, int skillTreeReallocPoints) {
this.level = level;
this.classPoints = classPoints;
this.skillPoints = skillPoints;
this.attributePoints = attributePoints;
this.attrReallocPoints = attrReallocPoints;
this.skillReallocPoints=skillReallocPoints;
this.skillReallocPoints = skillReallocPoints;
this.skillTreeReallocPoints = skillTreeReallocPoints;
}
public int getLevel() {
@ -163,6 +165,11 @@ public abstract class PlayerDataManager {
return skillPoints;
}
public int getSkillTreeReallocPoints() {
return skillTreeReallocPoints;
}
public int getClassPoints() {
return classPoints;
}

View File

@ -30,7 +30,8 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
data.setClassPoints(config.getInt("class-points", getDefaultData().getClassPoints()));
data.setSkillPoints(config.getInt("skill-points", getDefaultData().getSkillPoints()));
data.setSkillReallocationPoints(config.getInt("skill-reallocation-points",getDefaultData().getSkillReallocPoints()));
data.setSkillReallocationPoints(config.getInt("skill-reallocation-points", getDefaultData().getSkillReallocPoints()));
data.setSkillTreeReallocationPoints(config.getInt("skill-tree-reallocation-points", getDefaultData().getSkillTreeReallocPoints()));
data.setAttributePoints(config.getInt("attribute-points", getDefaultData().getAttributePoints()));
data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points", getDefaultData().getAttrReallocPoints()));
data.setLevel(config.getInt("level", getDefaultData().getLevel()));
@ -66,6 +67,12 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
if (data.getProfess().hasSkill(id))
data.getBoundSkills().add(data.getProfess().getSkill(id));
for (String key : MMOCore.plugin.skillTreeManager.getAll().stream().map(skillTree -> skillTree.getId()).toList()) {
data.setSkillTreePoints(key, config.getInt("skill-tree-points." + key, 0));
}
data.setSkillTreePoints("global", config.getInt("skill-tree-points.global", 0));
if (config.contains("times-claimed"))
for (String key : config.getConfigurationSection("times-claimed").getKeys(true))
data.getItemClaims().put(key, config.getInt("times-claimed." + key));
@ -91,7 +98,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
config.set("class-points", data.getClassPoints());
config.set("skill-points", data.getSkillPoints());
config.set("skill-reallocation-points",data.getSkillReallocationPoints());
config.set("skill-reallocation-points", data.getSkillReallocationPoints());
config.set("attribute-points", data.getAttributePoints());
// config.set("skill-realloc-points", skillReallocationPoints);
config.set("attribute-realloc-points", data.getAttributeReallocationPoints());
@ -102,7 +109,8 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
config.set("friends", data.getFriends().stream().map(UUID::toString).collect(Collectors.toList()));
config.set("last-login", data.getLastLogin());
config.set("guild", data.hasGuild() ? data.getGuild().getId() : null);
data.getSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value));
config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints());
config.set("skill", null);
data.mapSkillLevels().forEach((key1, value) -> config.set("skill." + key1, value));
data.getItemClaims().forEach((key, times) -> config.set("times-claimed." + key, times));