forked from Upstream/mmocore
Transfer of Unlockable to MythicLib
This commit is contained in:
parent
77d4f8e4e4
commit
fbe4314649
@ -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();
|
||||
|
@ -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<SkillTreeNode, Integer> nodeLevels = new HashMap<>();
|
||||
private final Map<String, Integer> 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<String> 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<String> getUnlockedItems() {
|
||||
return new HashSet<>(unlockedItems);
|
||||
public Set<String> 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<String> unlockedItems) {
|
||||
this.unlockedItems.clear();
|
||||
this.unlockedItems.addAll(unlockedItems);
|
||||
Set<String> 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) {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -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);
|
||||
|
@ -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"));
|
||||
|
@ -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<String, Integer> getNodeTimesClaimed();
|
||||
|
||||
Set<String> getUnlockedItems();
|
||||
Set<String> getMMOUnlockedItems();
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class DefaultPlayerData implements ClassDataContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getUnlockedItems() {
|
||||
public Set<String> getMMOUnlockedItems() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user