forked from Upstream/mmocore
Support for profile placeholders
This commit is contained in:
parent
c5dbf21694
commit
2bcd505bf8
@ -139,6 +139,14 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.phoenixdevt</groupId>
|
||||
<artifactId>MMOProfiles-Dist</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
|
@ -259,7 +259,7 @@ public class MMOCore extends JavaPlugin {
|
||||
* recognize what profess the player has and professes will be lost
|
||||
*/
|
||||
playerDataManager.setupAll();
|
||||
playerDataManager.registerEvents(EventPriority.NORMAL);
|
||||
playerDataManager.registerEvents(EventPriority.NORMAL, EventPriority.NORMAL);
|
||||
|
||||
// load guild data after loading player data
|
||||
dataProvider.getGuildManager().load();
|
||||
|
@ -128,6 +128,11 @@ public class PlayerAttributes {
|
||||
return spent;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getSpent() {
|
||||
return getBase();
|
||||
}
|
||||
|
||||
public void setBase(int value) {
|
||||
spent = Math.max(0, value);
|
||||
|
||||
@ -165,10 +170,6 @@ public class PlayerAttributes {
|
||||
return (int) d;
|
||||
}
|
||||
|
||||
public int getSpent() {
|
||||
return spent;
|
||||
}
|
||||
|
||||
public AttributeModifier getModifier(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class PlayerQuests implements Closable {
|
||||
bossbarNamespacedKey = new NamespacedKey(MMOCore.plugin, "mmocore_quest_progress_" + playerData.getUniqueId().toString());
|
||||
bossbar = Bukkit.createBossBar(bossbarNamespacedKey, "", BarColor.PURPLE, BarStyle.SEGMENTED_20);
|
||||
bossbar.addPlayer(playerData.getPlayer());
|
||||
bossbar.setVisible(false); // Safety
|
||||
|
||||
// Bossbar is disabled
|
||||
} else {
|
||||
|
@ -17,7 +17,6 @@ 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;
|
||||
@ -73,12 +72,12 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
||||
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.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.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.getBase());
|
||||
}
|
||||
|
||||
else if (identifier.equals("level_percent")) {
|
||||
double current = playerData.getExperience(), next = playerData.getLevelUpExperience();
|
||||
|
@ -0,0 +1,46 @@
|
||||
package net.Indyuce.mmocore.comp.profile;
|
||||
|
||||
import fr.phoenixdevt.profile.placeholder.PlaceholderRequest;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.comp.profile.ProfileDataModuleImpl;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
|
||||
public class MMOCoreProfileDataModule extends ProfileDataModuleImpl {
|
||||
public MMOCoreProfileDataModule() {
|
||||
super(MMOCore.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlaceholders() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "mmocore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPlaceholderRequest(PlaceholderRequest placeholderRequest) {
|
||||
final PlayerData fictiveData = new PlayerData(new MMOPlayerData(placeholderRequest.getProfile().getUniqueId()));
|
||||
MMOCore.plugin.playerDataManager.getDataHandler().loadData(fictiveData).thenRun(() -> {
|
||||
placeholderRequest.addPlaceholder("class", fictiveData.getProfess().getName());
|
||||
placeholderRequest.addPlaceholder("level", fictiveData.getLevel());
|
||||
|
||||
for (PlayerAttribute attribute : MMOCore.plugin.attributeManager.getAll())
|
||||
placeholderRequest.addPlaceholder("attribute_" + attribute.getId().replace("-", "_"), fictiveData.getAttributes().getInstance(attribute).getBase());
|
||||
|
||||
for (Profession profession : MMOCore.plugin.professionManager.getAll())
|
||||
placeholderRequest.addPlaceholder("profession_" + profession.getId().replace("-", "_"), fictiveData.getCollectionSkills().getLevel(profession));
|
||||
|
||||
placeholderRequest.addPlaceholder("exp", MythicLib.plugin.getMMOConfig().decimal.format(fictiveData.getExperience()));
|
||||
placeholderRequest.addPlaceholder("exp_next_level", MythicLib.plugin.getMMOConfig().decimal.format(fictiveData.getLevelUpExperience()));
|
||||
|
||||
placeholderRequest.validate();
|
||||
});
|
||||
}
|
||||
}
|
@ -26,7 +26,9 @@ public class VaultEconomy {
|
||||
|
||||
/**
|
||||
* @return If an economy plugin was found
|
||||
* @deprecated Not needed. {@link MMOCore#economy} could be null and that's all
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isValid() {
|
||||
return economy != null;
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package net.Indyuce.mmocore.manager.data;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface AbstractOfflinePlayerData {
|
||||
|
||||
|
||||
public abstract void removeFriend(UUID uuid);
|
||||
|
||||
public abstract boolean hasFriend(UUID uuid);
|
||||
|
||||
public abstract PlayerClass getProfess();
|
||||
|
||||
public abstract int getLevel();
|
||||
|
||||
public abstract long getLastLogin();
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package net.Indyuce.mmocore.manager.data;
|
||||
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.comp.profile.ProfileDataModuleImpl;
|
||||
import io.lumine.mythic.lib.data.SynchronizedDataManager;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.comp.profile.MMOCoreProfileDataModule;
|
||||
import net.Indyuce.mmocore.manager.data.yaml.YAMLPlayerDataHandler;
|
||||
import net.Indyuce.mmocore.player.DefaultPlayerData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -20,6 +22,11 @@ public class PlayerDataManager extends SynchronizedDataManager<PlayerData, Offli
|
||||
return new PlayerData(playerData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileDataModuleImpl newProfileDataModule() {
|
||||
return new MMOCoreProfileDataModule();
|
||||
}
|
||||
|
||||
public DefaultPlayerData getDefaultData() {
|
||||
return defaultData;
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @deprecated Not implemented yet
|
||||
*/
|
||||
@Deprecated
|
||||
public class PlayerDataTableUpdater {
|
||||
private final PlayerData playerData;
|
||||
private final SQLDataSource provider;
|
||||
@ -30,7 +34,7 @@ public class PlayerDataTableUpdater {
|
||||
|
||||
public void executeRequest(boolean autosave) {
|
||||
final String request = "INSERT INTO mmocore_playerdata(uuid, " + formatCollection(requestMap.keySet(), false)
|
||||
+ ") VALUES('" + playerData.getUniqueId() + "'," + formatCollection(requestMap.values(), true) + ")" +
|
||||
+ ") VALUES('" + playerData.getProfileId() + "'," + formatCollection(requestMap.values(), true) + ")" +
|
||||
" ON DUPLICATE KEY UPDATE " + formatMap() + ";";
|
||||
|
||||
try {
|
||||
@ -40,21 +44,21 @@ public class PlayerDataTableUpdater {
|
||||
try {
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getUniqueId() + ", saving through YAML instead");
|
||||
MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getProfileId() + ", saving through YAML instead");
|
||||
new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave);
|
||||
exception.printStackTrace();
|
||||
} finally {
|
||||
statement.close();
|
||||
}
|
||||
} catch (SQLException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getUniqueId() + ", saving through YAML instead");
|
||||
MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getProfileId() + ", saving through YAML instead");
|
||||
new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave);
|
||||
exception.printStackTrace();
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getUniqueId() + ", saving through YAML instead");
|
||||
MMOCore.log(Level.WARNING, "Could not save player data of " + playerData.getProfileId() + ", saving through YAML instead");
|
||||
new YAMLPlayerDataHandler(MMOCore.plugin).saveData(playerData, autosave);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
||||
|
||||
@Override
|
||||
public void saveData(PlayerData data, boolean autosave) {
|
||||
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saving data for: '" + data.getUniqueId() + "'...");
|
||||
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saving data for: '" + data.getProfileId() + "'...");
|
||||
|
||||
final PlayerDataTableUpdater updater = new PlayerDataTableUpdater(getDataSource(), data);
|
||||
updater.addData("class_points", data.getClassPoints());
|
||||
@ -128,7 +128,7 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
||||
|
||||
updater.executeRequest(autosave);
|
||||
|
||||
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saved data for: " + data.getUniqueId());
|
||||
UtilityMethods.debug(MMOCore.plugin, "SQL", "Saved data for: " + data.getProfileId());
|
||||
UtilityMethods.debug(MMOCore.plugin, "SQL", String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
|
||||
}
|
||||
|
||||
@ -190,77 +190,7 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
||||
@NotNull
|
||||
@Override
|
||||
public OfflinePlayerData getOffline(UUID uuid) {
|
||||
return new MySQLOfflinePlayerData(uuid);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public class MySQLOfflinePlayerData implements OfflinePlayerData {
|
||||
private final UUID uuid;
|
||||
private int level;
|
||||
private long lastLogin;
|
||||
private PlayerClass profess;
|
||||
private List<UUID> friends;
|
||||
|
||||
@Deprecated
|
||||
public MySQLOfflinePlayerData(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
/*
|
||||
provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';", (result) -> {
|
||||
try {
|
||||
MythicLib.debug("MMOCoreSQL", "Loading OFFLINE data for '" + uuid + "'.");
|
||||
if (!result.next()) {
|
||||
level = 0;
|
||||
lastLogin = 0;
|
||||
profess = MMOCore.plugin.classManager.getDefaultClass();
|
||||
friends = new ArrayList<>();
|
||||
MythicLib.debug("MMOCoreSQL", "Default OFFLINE data loaded.");
|
||||
} else {
|
||||
level = result.getInt("level");
|
||||
lastLogin = result.getLong("last_login");
|
||||
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
|
||||
if (!isEmpty(result.getString("friends")))
|
||||
MMOCoreUtils.jsonArrayToList(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
|
||||
else friends = new ArrayList<>();
|
||||
MythicLib.debug("MMOCoreSQL", "Saved OFFLINE data loaded.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}); */
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFriend(UUID uuid) {
|
||||
// TODO recode
|
||||
// friends.remove(uuid);
|
||||
// new PlayerDataTableUpdater(provider, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFriend(UUID uuid) {
|
||||
return friends.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerClass getProfess() {
|
||||
return profess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
return new SQLOfflinePlayerData(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,81 @@
|
||||
package net.Indyuce.mmocore.manager.data.sql;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @deprecated Not implemented yet
|
||||
*/
|
||||
@Deprecated
|
||||
public class SQLOfflinePlayerData implements OfflinePlayerData {
|
||||
private final UUID uuid;
|
||||
private int level;
|
||||
private long lastLogin;
|
||||
private PlayerClass profess;
|
||||
private List<UUID> friends;
|
||||
|
||||
@Deprecated
|
||||
public SQLOfflinePlayerData(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
/*
|
||||
provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';", (result) -> {
|
||||
try {
|
||||
MythicLib.debug("MMOCoreSQL", "Loading OFFLINE data for '" + uuid + "'.");
|
||||
if (!result.next()) {
|
||||
level = 0;
|
||||
lastLogin = 0;
|
||||
profess = MMOCore.plugin.classManager.getDefaultClass();
|
||||
friends = new ArrayList<>();
|
||||
MythicLib.debug("MMOCoreSQL", "Default OFFLINE data loaded.");
|
||||
} else {
|
||||
level = result.getInt("level");
|
||||
lastLogin = result.getLong("last_login");
|
||||
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
|
||||
if (!isEmpty(result.getString("friends")))
|
||||
MMOCoreUtils.jsonArrayToList(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
|
||||
else friends = new ArrayList<>();
|
||||
MythicLib.debug("MMOCoreSQL", "Saved OFFLINE data loaded.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}); */
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFriend(UUID uuid) {
|
||||
// TODO recode
|
||||
// friends.remove(uuid);
|
||||
// new PlayerDataTableUpdater(provider, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFriend(UUID uuid) {
|
||||
return friends.contains(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerClass getProfess() {
|
||||
return profess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
}
|
@ -9,6 +9,9 @@ import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @deprecated Not implemented yet
|
||||
*/
|
||||
@Deprecated
|
||||
public class YAMLOfflinePlayerData implements OfflinePlayerData {
|
||||
private final UUID uuid;
|
||||
|
@ -5,7 +5,7 @@ author: Indyuce
|
||||
description: ${project.description}
|
||||
loadbefore: [ MMOItems,MythicDungeons ]
|
||||
depend: [ MythicLib ]
|
||||
softdepend: [ Vault,MythicMobs,PlaceholderAPI,Residence,Citizens,ProtocolLib,OBTeam ]
|
||||
softdepend: [ Vault,MythicMobs,MMOProfiles,PlaceholderAPI,Residence,Citizens,ProtocolLib,OBTeam ]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
mmocore:
|
||||
|
Loading…
Reference in New Issue
Block a user