diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java index 71d465c4..e820d667 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -57,6 +57,7 @@ import java.util.logging.Level; public class MMOCore extends JavaPlugin { public static MMOCore plugin; + public final static String MMOCORE_ITEM_ID = "mmocore:"; public final WaypointManager waypointManager = new WaypointManager(); public final SoundManager soundManager = new SoundManager(); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 68eba7e4..2984400e 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -38,7 +38,6 @@ import net.Indyuce.mmocore.party.provided.MMOCorePartyModule; import net.Indyuce.mmocore.party.provided.Party; import net.Indyuce.mmocore.player.ClassDataContainer; import net.Indyuce.mmocore.player.CombatHandler; -import net.Indyuce.mmocore.player.Unlockable; import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.cast.SkillCastingHandler; @@ -66,6 +65,8 @@ import java.util.*; import java.util.logging.Level; import java.util.stream.Collectors; +import static net.Indyuce.mmocore.MMOCore.MMOCORE_ITEM_ID; + public class PlayerData extends OfflinePlayerData implements Closable, ExperienceTableClaimer, ClassDataContainer { @@ -112,15 +113,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc private final Map nodeLevels = new HashMap<>(); private final Map skillTreePoints = new HashMap<>(); - /** - * Saves all the items that have been unlocked so far by - * the player. This is used for: - * - waypoints - * - skills - * - * @see {@link Unlockable} - */ - private final Set unlockedItems = new HashSet<>(); /** * Saves the amount of times the player has claimed some @@ -374,16 +366,29 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return result; } + /** + * @return All the unlocked items that are handled by MMOCore (the ones that MMOCore saves & load by itself. + */ @Override - public Set getUnlockedItems() { - return new HashSet<>(unlockedItems); + public Set getMMOUnlockedItems() { + return mmoData.getUnlockedItems().stream().filter(key->key.startsWith(MMOCORE_ITEM_ID)).collect(Collectors.toSet()); } + + /** + * Used to change the value of the unlockedItems handled by mmocore. + * @param unlockedItems + */ public void setUnlockedItems(Set unlockedItems) { - this.unlockedItems.clear(); - this.unlockedItems.addAll(unlockedItems); + Set mythicUnlockedItems=mmoData.getUnlockedItems() + .stream() + .filter((key)->!key.startsWith(MMOCORE_ITEM_ID)) + .collect(Collectors.toSet()); + mythicUnlockedItems.addAll(unlockedItems); + mmoData.setUnlockedItems(mythicUnlockedItems); } + public void resetTimesClaimed() { tableItemClaims.clear(); } @@ -542,32 +547,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return guild != null; } - /** - * @return If the item is unlocked by the player - * This is used for skills that can be locked & unlocked. - */ - public boolean hasUnlocked(Unlockable unlockable) { - return unlockedItems.contains(unlockable.getUnlockNamespacedKey()); - } - - - /** - * Unlocks an item for the player. This is mainly used to unlock skills. - * - * @return If the item was already unlocked when calling this method - */ - public boolean unlock(Unlockable unlockable) { - return unlockedItems.add(unlockable.getUnlockNamespacedKey()); - } - - /** - * Locks an item for the player by removing it from the unlocked items map if it is present. - * This is mainly used to remove unlocked items when changing class or reallocating a skill tree. - */ - public void lock(Unlockable unlockable){ - unlockedItems.remove(unlockable.getUnlockNamespacedKey()); - } - public void setLevel(int level) { this.level = Math.max(1, level); @@ -1149,6 +1128,13 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc // Update stats if (isOnline()) getStats().updateStats(); + + Bukkit.broadcastMessage("IN"); + //Loads the classUnlockedSkills + profess.getSkills() + .stream() + .filter(ClassSkill::isUnlockedByDefault) + .forEach(skill->mmoData.unlock(skill.getSkill())); } public boolean hasSkillBound(int slot) { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index ab0bd9c9..2424f8cb 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -124,7 +124,7 @@ public class SavedClassInformation { data.getNodeLevels().forEach((node, level) -> nodeLevels.put(node.getFullId(), level)); data.getNodeTimesClaimed().forEach((key, val) -> nodeTimesClaimed.put(key, val)); data.mapBoundSkills().forEach((slot, skill) -> boundSkills.put(slot, skill)); - data.getUnlockedItems().forEach(item->unlockedItems.add(item)); + data.getMMOUnlockedItems().forEach(item->unlockedItems.add(item)); } public int getLevel() { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/UnlockSkillTrigger.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/UnlockSkillTrigger.java index 4fc77c40..e827f9b2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/UnlockSkillTrigger.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/UnlockSkillTrigger.java @@ -19,11 +19,11 @@ public class UnlockSkillTrigger extends Trigger implements Removable { @Override public void apply(PlayerData player) { - player.unlock(skill); + player.getMMOPlayerData().unlock(skill); } @Override public void remove(PlayerData playerData) { - playerData.lock(skill); + playerData.getMMOPlayerData().lock(skill); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java index 38fdd94c..21e93385 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/rpg/admin/SkillCommandTreeNode.java @@ -103,16 +103,16 @@ public class SkillCommandTreeNode extends CommandTreeNode { } PlayerData playerData = PlayerData.get(player); - RegisteredSkill skill = MMOCore.plugin.skillManager.getSkill(args[4]); + ClassSkill skill = playerData.getProfess().getSkill(args[4]); if (skill == null) { - sender.sendMessage(ChatColor.RED + "Could not find the skill called " + args[4] + "."); + sender.sendMessage(ChatColor.RED + "The player's class doesn't have a skill called " + args[4] + "."); return CommandResult.FAILURE; } if (lock) - playerData.lock(skill); + playerData.getMMOPlayerData().lock(skill.getSkill()); else - playerData.unlock(skill); - CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, "The skill " + skill.getName() + " is now " + (lock ? "locked" : "unlocked" + " for " + player.getName())); + playerData.getMMOPlayerData().unlock(skill.getSkill()); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.SKILL, "The skill " + skill.getSkill() + " is now " + (lock ? "locked" : "unlocked" + " for " + player.getName())); return CommandResult.SUCCESS; } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index 1a1bc7ed..6b7b10fc 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -322,10 +322,11 @@ public class SkillList extends EditableInventory { public SkillViewerInventory(PlayerData playerData, EditableInventory editable) { super(playerData, editable); - + Bukkit.broadcastMessage("UNLOCKED"); + playerData.getMMOPlayerData().getUnlockedItems().forEach(str->Bukkit.broadcastMessage(str)); skills = playerData.getProfess().getSkills() .stream() - .filter((classSkill)->playerData.hasUnlocked(classSkill.getSkill())) + .filter((classSkill)->playerData.getMMOPlayerData().hasUnlocked(classSkill.getSkill())) .collect(Collectors.toList()); skillSlots = getEditable().getByFunction("skill").getSlots(); Validate.notNull(getEditable().getByFunction("slot"), "Your skill GUI config file is out-of-date, please regenerate it."); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index d2c7a2e1..666b80ea 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -12,7 +12,6 @@ import net.Indyuce.mmocore.manager.data.PlayerDataManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -64,7 +63,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { updater.addData("professions", data.getCollectionSkills().toJsonString()); updater.addData("quests", data.getQuestData().toJsonString()); updater.addData("class_info", createClassInfoData(data).toString()); - updater.addJSONArray("unlocked_items", data.getUnlockedItems()); + updater.addJSONArray("unlocked_items", data.getMMOUnlockedItems()); if (logout) updater.addData("is_saved", 1); @@ -91,7 +90,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { classinfo.addProperty("stamina", info.getStamina()); classinfo.addProperty("stellium", info.getStellium()); JsonArray array = new JsonArray(); - for (String unlockedItem : playerData.getUnlockedItems()) { + for (String unlockedItem : playerData.getMMOUnlockedItems()) { array.add(unlockedItem); } classinfo.add("unlocked-items", array); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index c5d029b4..2f28b1f7 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -159,7 +159,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { data.getItemClaims().forEach((key, times) -> config.set("times-claimed." + key, times)); data.mapBoundSkills().forEach((slot, skill) -> config.set("bound-skills." + slot, skill)); - config.set("unlocked-items", data.getUnlockedItems().stream().collect(Collectors.toList())); + config.set("unlocked-items", data.getMMOUnlockedItems().stream().collect(Collectors.toList())); config.set("attribute", null); config.createSection("attribute"); data.getAttributes().save(config.getConfigurationSection("attribute")); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java index 5d6a7e1e..c30934e5 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/ClassDataContainer.java @@ -1,11 +1,8 @@ package net.Indyuce.mmocore.player; -import io.lumine.mythic.lib.player.skill.PassiveSkill; import net.Indyuce.mmocore.api.player.profess.SavedClassInformation; -import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skilltree.SkillTreeNode; -import java.util.List; import java.util.Map; import java.util.Set; @@ -50,5 +47,5 @@ public interface ClassDataContainer { Map getNodeTimesClaimed(); - Set getUnlockedItems(); + Set getMMOUnlockedItems(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java index 1a46af5e..06efa836 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/DefaultPlayerData.java @@ -120,7 +120,7 @@ public class DefaultPlayerData implements ClassDataContainer { } @Override - public Set getUnlockedItems() { + public Set getMMOUnlockedItems() { return new HashSet<>(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/Unlockable.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/Unlockable.java deleted file mode 100644 index 9349f308..00000000 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/player/Unlockable.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.Indyuce.mmocore.player; - -import net.Indyuce.mmocore.api.player.PlayerData; - -/** - * Some item that can be unlocked. All unlockables are saved in the - * same list in the player data. This useful list can be used for: - * - waypoints - * - skill tree nodes - * - skills using skill books? TODO - * - external plugins that implement other unlockable items - * - * @see {@link PlayerData#unlock(Unlockable)} and {@link PlayerData#hasUnlocked(Unlockable)} - */ -public interface Unlockable { - - /** - * Format being used is the minecraft's default namespaced - * key format, e.g "skill_tree:strength_1_5" for readability - */ - String getUnlockNamespacedKey(); -} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java index 628cf616..a1610d12 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skill/RegisteredSkill.java @@ -1,12 +1,13 @@ package net.Indyuce.mmocore.skill; import io.lumine.mythic.lib.UtilityMethods; +import io.lumine.mythic.lib.player.Unlockable; import io.lumine.mythic.lib.skill.handler.SkillHandler; import io.lumine.mythic.lib.skill.trigger.TriggerType; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; -import net.Indyuce.mmocore.player.Unlockable; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -59,7 +60,7 @@ public class RegisteredSkill implements Unlockable { @Override public String getUnlockNamespacedKey() { - return "registered_skill:" + handler.getId().toLowerCase(); + return MMOCore.MMOCORE_ITEM_ID+"skill:" + handler.getId().toLowerCase(); } public SkillHandler getHandler() { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java index b5f3d643..021261e1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java @@ -2,10 +2,10 @@ package net.Indyuce.mmocore.waypoint; import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.util.PostLoadObject; +import io.lumine.mythic.lib.player.Unlockable; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.loot.chest.condition.Condition; import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance; -import net.Indyuce.mmocore.player.Unlockable; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/MMOCore-Dist/src/main/resources/default/gui/skill-list.yml b/MMOCore-Dist/src/main/resources/default/gui/skill-list.yml index 3042f98e..0e88dd1a 100644 --- a/MMOCore-Dist/src/main/resources/default/gui/skill-list.yml +++ b/MMOCore-Dist/src/main/resources/default/gui/skill-list.yml @@ -46,7 +46,7 @@ items: - '&eCosts 1 skill reallocation point.' - '&e◆ Skill Reallocation Points: &6{points}' - skill-slot: + slot: slots: [ 8,17,26,35,44,53 ] function: slot item: BOOK