Merge remote-tracking branch 'origin/master'

# Conflicts:
#	MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java
This commit is contained in:
Jules 2023-04-23 21:42:10 +02:00
commit 41617f722c
16 changed files with 205 additions and 19 deletions

View File

@ -196,6 +196,20 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.civious</groupId>
<artifactId>OBTeam</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.playavalon</groupId>
<artifactId>DungeonParties</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alessiodp</groupId>
<artifactId>Parties</artifactId>

View File

@ -21,6 +21,7 @@ import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.player.profess.Subclass;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.skill.binding.BoundSkillInfo;
import net.Indyuce.mmocore.api.player.social.FriendRequest;
import net.Indyuce.mmocore.api.player.stats.PlayerStats;
@ -151,14 +152,15 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
* /mmocore reload
*/
public void reload() {
try {
profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId());
getStats().updateStats();
} catch (NullPointerException exception) {
MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
}
//We remove all the stats and buffs associated to triggers.
getMMOPlayerData().getStatMap().getInstances().forEach(statInstance -> statInstance.removeIf(key ->key.startsWith(Trigger.TRIGGER_PREFIX)));
getMMOPlayerData().getSkillModifierMap().getInstances().forEach(skillModifierInstance -> skillModifierInstance.removeIf(key ->key.startsWith(Trigger.TRIGGER_PREFIX)));
final Iterator<Map.Entry<Integer, BoundSkillInfo>> ite = boundSkills.entrySet().iterator();
while (ite.hasNext())
try {
@ -167,10 +169,9 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
final String skillId = entry.getValue().getClassSkill().getSkill().getHandler().getId();
final @Nullable ClassSkill classSkill = getProfess().getSkill(skillId);
Validate.notNull(skillSlot, "Could not find skill slot n" + entry.getKey());
Validate.notNull(skillSlot, "Could not find skill with ID '" + skillId + "'");
entry.getValue().close();
boundSkills.put(entry.getKey(), new BoundSkillInfo(skillSlot, classSkill, this));
Validate.notNull(classSkill, "Could not find skill with ID '" + skillId + "'");
unbindSkill(entry.getKey());
bindSkill(entry.getKey(), classSkill);
} catch (Exception exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not reload data of '" + getPlayer().getName() + "': " + exception.getMessage());
}

View File

@ -165,6 +165,10 @@ public class PlayerAttributes {
return (int) d;
}
public int getSpent() {
return spent;
}
public AttributeModifier getModifier(String key) {
return map.get(key);
}

View File

@ -37,11 +37,6 @@ public class StatTrigger extends Trigger implements Removable {
prevModifier.add(amount).register(player.getMMOPlayerData());
}
/**
* Removes the effect of the trigger to the player by registering the
* opposite amount. (Little corrective term for the relative to have the inverse.
* Not a problem to store twice the stat modifiers are there only remain in the RAM.
*/
@Override
public void remove(PlayerData playerData) {
playerData.getMMOPlayerData().getStatMap().getInstance(stat).remove(modifierKey);

View File

@ -7,6 +7,7 @@ import io.lumine.mythic.lib.manager.StatManager;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
@ -16,10 +17,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@ -71,7 +72,15 @@ public class RPGPlaceholders extends PlaceholderExpansion {
String id = identifier.substring(12);
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(id), "Could not find skill with ID '" + id + "'");
return String.valueOf(playerData.getSkillLevel(skill));
} else if (identifier.equals("level_percent")) {
}
else if(identifier.startsWith("mmocore_attribute_points_spent_")){
String attributeId=identifier.substring(31);
PlayerAttributes.AttributeInstance attributeInstance=Objects.requireNonNull(playerData.getAttributes().getInstance(attributeId),"Could not find attribute with ID '"+attributeId+"'");
return String.valueOf(attributeInstance.getSpent());
}
else if (identifier.equals("level_percent")) {
double current = playerData.getExperience(), next = playerData.getLevelUpExperience();
return MythicLib.plugin.getMMOConfig().decimal.format(current / next * 100);
} else if (identifier.equals("health"))

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import me.ulrich.clans.manager.I;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -88,6 +89,8 @@ public class SkillList extends EditableInventory {
}
};
}
if(function.equals("selected"))
return new SelectedItem(config);
return new SimplePlaceholderItem(config);
}
@ -96,6 +99,31 @@ public class SkillList extends EditableInventory {
return new SkillViewerInventory(data, this);
}
public class SelectedItem extends InventoryItem<SkillViewerInventory> {
public SelectedItem(ConfigurationSection config) {
//We must use this constructor to show that there are not specified material
super(Material.BARRIER,config);
}
@Override
public ItemStack display(SkillViewerInventory inv, int n) {
ItemStack item =super.display(inv, n);
if(inv.selected== null)
return new ItemStack(Material.AIR);
if (inv.selected != null) {
item.setType(inv.selected.getSkill().getIcon().getType());
}
return item;
}
@Override
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
Placeholders holders= new Placeholders();
holders.register("selected", inv.selected.getSkill().getName());
return holders;
}
}
public class LevelItem extends InventoryItem<SkillViewerInventory> {
private final int offset;

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.skilltree.NodeStatus;
@ -120,6 +121,8 @@ public class SkillTreeViewer extends EditableInventory {
lore.add(holders.apply(inv.getPlayer(), string));
});
meta.setLore(lore);
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(skillTree.getCustomModelData());
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(new NamespacedKey(MMOCore.plugin, "skill-tree-id"), PersistentDataType.STRING, skillTree.getId());
item.setItemMeta(meta);

View File

@ -4,6 +4,7 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
@ -112,13 +113,18 @@ public class SubclassSelect extends EditableInventory {
if (item.getFunction().startsWith("sub-class")) {
String classId = item.getFunction().substring(10);
PlayerClass profess = MMOCore.plugin.classManager.get(classId);
if (playerData.getClassPoints() < 1) {
player.closeInventory();
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(getPlayer());
new ConfigMessage("cant-choose-new-class").send(player);
return;
}
if (profess.hasOption(ClassOption.NEEDS_PERMISSION) && !player.hasPermission("mmocore.class." + profess.getId().toLowerCase())) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
new ConfigMessage("no-permission-for-class").send(player);
return;
}
InventoryManager.CLASS_CONFIRM.get(classId).newInventory(playerData, this, true).open();
}

View File

@ -12,6 +12,8 @@ public enum PartyModuleType {
MCMMO("mcMMO", McMMOPartyModule::new),
MMOCORE("MMOCore", MMOCorePartyModule::new),
PARTIES("Parties", PartiesPartyModule::new),
MYTHICDUNGEONS("MythicDungeons", DungeonPartiesPartyModule::new),
OBTEAM("OBTeam", OBTeamPartyModule::new),
PARTY_AND_FRIENDS("PartyAndFriends", PAFPartyModule::new),
PARTY_AND_FRIENDS_BUNGEECORD_VELOCITY("Spigot-Party-API-PAF", PAFProxyPartyModule::new),
;

View File

@ -0,0 +1,57 @@
package net.Indyuce.mmocore.party.compat;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.party.PartyModule;
import net.playavalon.avnparty.AvNParty;
import net.playavalon.avnparty.party.Party;
import net.playavalon.avnparty.player.AvalonPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class DungeonPartiesPartyModule implements PartyModule, Listener {
@Nullable
@Override
public AbstractParty getParty(PlayerData playerData) {
final @Nullable Party party = AvNParty.plugin.players.get(playerData.getPlayer()).getParty();
return party == null ? null : new CustomParty(party);
}
class CustomParty implements AbstractParty {
private final Party party;
public CustomParty(Party party) {
this.party = party;
}
@Override
public boolean hasMember(Player player) {
for (AvalonPlayer member : party.getPlayers())
if (member.getPlayer().getUniqueId().equals(player.getUniqueId())) return true;
return false;
}
@Override
public List<PlayerData> getOnlineMembers() {
final List<PlayerData> list = new ArrayList<>();
for (AvalonPlayer member : party.getPlayers())
try {
list.add(PlayerData.get(member.getPlayer().getUniqueId()));
} catch (Exception ignored) {
}
return list;
}
@Override
public int countMembers() {
return party.getPlayers().size();
}
}
}

View File

@ -68,7 +68,7 @@ public class DungeonsXLPartyModule implements PartyModule, Listener {
MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData()));
}
class CustomParty implements AbstractParty, Listener {
class CustomParty implements AbstractParty {
private final PlayerGroup group;
public CustomParty(PlayerGroup group) {

View File

@ -74,12 +74,11 @@ public class McMMOPartyModule implements PartyModule, Listener {
MMOCore.plugin.partyManager.getBonuses().forEach(buff -> buff.unregister(player.getMMOPlayerData()));
}
class CustomParty implements AbstractParty, Listener {
class CustomParty implements AbstractParty {
private final Party party;
public CustomParty(Party party) {
this.party = party;
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin);
}
@Override

View File

@ -0,0 +1,59 @@
package net.Indyuce.mmocore.party.compat;
import com.civious.obteam.mechanics.Team;
import com.civious.obteam.mechanics.TeamManager;
import com.civious.obteam.mechanics.TeamMember;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.party.PartyModule;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class OBTeamPartyModule implements PartyModule, Listener {
@Nullable
@Override
public AbstractParty getParty(PlayerData playerData) {
final @Nullable Team team = TeamManager.getInstance().getTeam(playerData.getPlayer());
return team == null ? null : new CustomParty(team);
}
class CustomParty implements AbstractParty {
private final Team team;
public CustomParty(Team team) {
this.team = team;
}
@Override
public boolean hasMember(Player player) {
for (TeamMember member : team.getMembers())
if (member.getOfflinePlayer().getUniqueId().equals(player.getUniqueId())) return true;
return false;
}
@Override
public List<PlayerData> getOnlineMembers() {
final List<PlayerData> list = new ArrayList<>();
for (TeamMember member : team.getMembersAndOwner())
try {
list.add(PlayerData.get(member.getOfflinePlayer().getUniqueId()));
} catch (Exception ignored) {
}
return list;
}
@Override
public int countMembers() {
return team.getMembersAndOwner().size();
}
}
}

View File

@ -39,6 +39,8 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
private final String id, name;
private final List<String> lore = new ArrayList<>();
private final Material item;
private final int customModelData;
//2 different maps to get the nodes
//Represents all the coordinates that will be displayed as a path (between 2 nodes of the tree)
@ -59,6 +61,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
this.name = MythicLib.plugin.parseColors(Objects.requireNonNull(config.getString("name"), "Could not find skill tree name"));
Objects.requireNonNull(config.getStringList("lore"), "Could not find skill tree lore").forEach(str -> lore.add(MythicLib.plugin.parseColors(str)));
this.item = Material.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("item"))));
this.customModelData = config.getInt("custom-model-data", 0);
Validate.isTrue(config.isConfigurationSection("nodes"), "Could not find any nodes in the tree");
this.maxPointSpent = config.getInt("max-point-spent", Integer.MAX_VALUE);
for (String key : config.getConfigurationSection("nodes").getKeys(false)) {
@ -148,6 +151,10 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje
return maxPointSpent;
}
public int getCustomModelData() {
return customModelData;
}
public static SkillTree loadSkillTree(ConfigurationSection config) {
SkillTree skillTree = null;

View File

@ -61,6 +61,8 @@ protect-custom-mine: false
# - party_and_friends (Use this one if you are using Party and Friends Extended for Spigot)
# - party_and_friends_bungeecord_velocity (Use this one if you are using Party and Friends For Bungeecord, Party and Friends For Velocity or Party and Friends Extended Edition for Bungeecord/Velocity. This one requires https://www.spigotmc.org/resources/spigot-party-api-for-party-and-friends.39751/ to be installed)
# - mcmmo
# - obteam (addon for DungeonMMO)
# - mythicdungeons (only when using default party handler)
party-plugin: mmocore
# Edit the plugin handling guilds here.

View File

@ -3,9 +3,9 @@ version: ${project.version}
main: net.Indyuce.mmocore.MMOCore
author: Indyuce
description: ${project.description}
loadbefore: [ MMOItems ]
loadbefore: [ MMOItems,MythicDungeons ]
depend: [ MythicLib ]
softdepend: [ Vault,MythicMobs,PlaceholderAPI,Residence,Citizens,ProtocolLib ]
softdepend: [ Vault,MythicMobs,PlaceholderAPI,Residence,Citizens,ProtocolLib,OBTeam ]
api-version: 1.13
commands:
mmocore: