mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
!MMOLib stat system refactor
This commit is contained in:
parent
f829d7c1be
commit
c1e3b6942c
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
@ -91,9 +91,6 @@ import net.Indyuce.mmocore.manager.profession.SmithingManager;
|
||||
import net.Indyuce.mmocore.manager.social.BoosterManager;
|
||||
import net.Indyuce.mmocore.manager.social.PartyManager;
|
||||
import net.Indyuce.mmocore.manager.social.RequestManager;
|
||||
import net.mmogroup.mmolib.api.stat.StatMap;
|
||||
import net.mmogroup.mmolib.api.stat.instance.MMOCoreStatInstance;
|
||||
import net.mmogroup.mmolib.api.stat.instance.SimpleStatInstance;
|
||||
import net.mmogroup.mmolib.comp.Metrics;
|
||||
import net.mmogroup.mmolib.version.SpigotPlugin;
|
||||
|
||||
@ -159,20 +156,6 @@ public class MMOCore extends JavaPlugin {
|
||||
new SpigotPlugin(70575, this).checkForUpdate();
|
||||
new Metrics(this);
|
||||
|
||||
/*
|
||||
* mmocore stats are functions of the stat base value. the function
|
||||
* applies all the different stat modifiers saved in the stat map. using
|
||||
* specific stat instances let MMOLib calculate stats with set base
|
||||
* value
|
||||
*/
|
||||
StatMap.setInstanceGenerator((map, stat) -> {
|
||||
try {
|
||||
return new MMOCoreStatInstance(map, StatType.valueOf(stat));
|
||||
} catch (IllegalArgumentException notMMOCoreStat) {
|
||||
return new SimpleStatInstance(map, stat);
|
||||
}
|
||||
});
|
||||
|
||||
if (getConfig().contains("mysql") && getConfig().getBoolean("mysql.enabled"))
|
||||
dataProvider = new MySQLDataProvider();
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
package net.Indyuce.mmocore.api;
|
||||
|
||||
public class AltChar {
|
||||
public static final String gemSymbol = "۞";
|
||||
public static final String square = "█";
|
||||
public static final String star = "✦";
|
||||
public static final String rightArrow = "⇨";
|
||||
public static final String fourEdgedClub = "✤";
|
||||
public static final String manaStar = "⭐";
|
||||
|
||||
public static final String club = "♣";
|
||||
public static final String diamond = "◆";
|
||||
public static final String spade = "♤";
|
||||
public static final String heart = "♥";
|
||||
|
||||
public static final String note1 = "♩";
|
||||
public static final String note2 = "♪";
|
||||
public static final String doubleNote1 = "♫";
|
||||
public static final String doubleNote2 = "♬";
|
||||
|
||||
public static final String listDash = "►";
|
||||
public static final String smallListDash = "▸";
|
||||
|
||||
public static final String listSquare = "■";
|
||||
|
||||
public static final String ok = "✔";
|
||||
public static final String no = "✖";
|
||||
}
|
@ -23,7 +23,7 @@ public class PlayerActionBar extends BukkitRunnable {
|
||||
ticks = config.getInt("ticks-to-update");
|
||||
format = config.getString("format");
|
||||
|
||||
runTaskTimerAsynchronously(MMOCore.plugin, 0, ticks);
|
||||
runTaskTimer(MMOCore.plugin, 0, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,25 +10,26 @@ public class PlayerLevelUpEvent extends PlayerDataEvent {
|
||||
|
||||
// if null, this is main level
|
||||
private final Profession profession;
|
||||
private final int level;
|
||||
private final int oldLevel, newLevel;
|
||||
|
||||
public PlayerLevelUpEvent(PlayerData player, int level) {
|
||||
this(player, null, level);
|
||||
public PlayerLevelUpEvent(PlayerData player, int oldLevel, int newLevel) {
|
||||
this(player, null, oldLevel, newLevel);
|
||||
}
|
||||
|
||||
public PlayerLevelUpEvent(PlayerData player, Profession profession, int level) {
|
||||
public PlayerLevelUpEvent(PlayerData player, Profession profession, int oldLevel, int newLevel) {
|
||||
super(player);
|
||||
|
||||
this.profession = profession;
|
||||
this.level = level;
|
||||
this.oldLevel = oldLevel;
|
||||
this.newLevel = newLevel;
|
||||
}
|
||||
|
||||
public int getNewLevel() {
|
||||
return level;
|
||||
return newLevel;
|
||||
}
|
||||
|
||||
public int getGained() {
|
||||
return level - getData().getLevel();
|
||||
public int getOldLevel() {
|
||||
return oldLevel;
|
||||
}
|
||||
|
||||
public boolean hasProfession() {
|
||||
|
@ -118,27 +118,28 @@ public class PlayerProfessions {
|
||||
exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + value : value);
|
||||
|
||||
// display hologram
|
||||
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms")) {
|
||||
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms"))
|
||||
if (loc != null && MMOCore.plugin.hologramSupport != null)
|
||||
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
|
||||
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());
|
||||
}
|
||||
|
||||
int needed, exp, level;
|
||||
int needed, exp, level, oldLevel = getLevel(profession);
|
||||
boolean check = false;
|
||||
while ((exp = this.exp.get(profession.getId())) >= (needed = profession.getExpCurve().getExperience((level = getLevel(profession)) + 1))) {
|
||||
this.exp.put(profession.getId(), exp - needed);
|
||||
this.level.put(profession.getId(), level + 1);
|
||||
check = true;
|
||||
playerData.giveExperience((int) profession.getExperience().calculate(level), null);
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(playerData, profession, level + 1));
|
||||
}
|
||||
|
||||
if (check) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(playerData, profession, oldLevel, level));
|
||||
new SmallParticleEffect(playerData.getPlayer(), Particle.SPELL_INSTANT);
|
||||
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + (level + 1), "profession", profession.getName())
|
||||
.send(playerData.getPlayer());
|
||||
playerData.getPlayer().playSound(playerData.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
playerData.getStats().updateStats();
|
||||
}
|
||||
if (check)
|
||||
new SmallParticleEffect(playerData.getPlayer(), Particle.SPELL_INSTANT);
|
||||
|
||||
String bar = "" + ChatColor.BOLD;
|
||||
int chars = (int) ((double) exp / needed * 20);
|
||||
|
@ -139,10 +139,9 @@ public class PlayerData extends OfflinePlayerData {
|
||||
return MMOCore.plugin.dataProvider.getDataManager().getLoaded();
|
||||
}
|
||||
|
||||
public PlayerData setPlayer(Player player) {
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
this.lastLogin = System.currentTimeMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<UUID> getFriends() {
|
||||
@ -228,7 +227,7 @@ public class PlayerData extends OfflinePlayerData {
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = Math.max(1, level);
|
||||
getStats().getMap().updateAll();
|
||||
getStats().updateStats();
|
||||
}
|
||||
|
||||
public void giveLevels(int value) {
|
||||
@ -427,7 +426,7 @@ public class PlayerData extends OfflinePlayerData {
|
||||
|
||||
experience += event.getExperience();
|
||||
|
||||
int needed;
|
||||
int level = getLevel(), oldLevel = level, needed;
|
||||
boolean check = false;
|
||||
while (experience >= (needed = getLevelUpExperience())) {
|
||||
|
||||
@ -439,14 +438,14 @@ public class PlayerData extends OfflinePlayerData {
|
||||
experience -= needed;
|
||||
level = getLevel() + 1;
|
||||
check = true;
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(this, null, level + 1));
|
||||
}
|
||||
|
||||
if (check) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(this, null, oldLevel, level));
|
||||
new ConfigMessage("level-up").addPlaceholders("level", "" + level).send(player);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
|
||||
new SmallParticleEffect(player, Particle.SPELL_INSTANT);
|
||||
getStats().getMap().updateAll();
|
||||
getStats().updateStats();
|
||||
}
|
||||
|
||||
refreshVanillaExp();
|
||||
@ -631,7 +630,7 @@ public class PlayerData extends OfflinePlayerData {
|
||||
// if (!getProfess().hasSkill(iterator.next().getSkill()))
|
||||
// iterator.remove();
|
||||
|
||||
getStats().getMap().updateAll();
|
||||
getStats().updateStats();
|
||||
}
|
||||
|
||||
public boolean hasSkillBound(int slot) {
|
||||
|
@ -16,6 +16,8 @@ import com.google.gson.JsonObject;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.mmogroup.mmolib.api.stat.modifier.Closable;
|
||||
import net.mmogroup.mmolib.api.stat.modifier.ModifierType;
|
||||
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
|
||||
|
||||
public class PlayerAttributes {
|
||||
@ -136,12 +138,12 @@ public class PlayerAttributes {
|
||||
public double getTotal(double d) {
|
||||
|
||||
for (StatModifier attr : map.values())
|
||||
if (attr.isRelative())
|
||||
d = attr.apply(d);
|
||||
if (attr.getType() == ModifierType.FLAT)
|
||||
d += attr.getValue();
|
||||
|
||||
for (StatModifier attr : map.values())
|
||||
if (!attr.isRelative())
|
||||
d = attr.apply(d);
|
||||
if (attr.getType() == ModifierType.RELATIVE)
|
||||
d *= attr.getValue();
|
||||
|
||||
return d;
|
||||
}
|
||||
@ -175,8 +177,9 @@ public class PlayerAttributes {
|
||||
* otherwise the runnable will try to remove the key from the map
|
||||
* even though the attribute was cancelled before hand
|
||||
*/
|
||||
if (map.containsKey(key)) {
|
||||
map.get(key).close();
|
||||
StatModifier mod;
|
||||
if (map.containsKey(key) && (mod = map.get(key)) instanceof Closable) {
|
||||
((Closable) mod).close();
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
@ -186,7 +189,8 @@ public class PlayerAttributes {
|
||||
public void update() {
|
||||
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
|
||||
int total = getTotal();
|
||||
attribute.getBuffs().forEach(buff -> data.getStats().getInstance(buff.getKey()).addModifier("attribute." + attribute.getId(), buff.getValue().multiply(total)));
|
||||
attribute.getBuffs().forEach(buff -> data.getStats().getInstance(buff.getKey()).addModifier("attribute." + attribute.getId(),
|
||||
buff.getValue().multiply(total)));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@ -196,7 +200,7 @@ public class PlayerAttributes {
|
||||
|
||||
public void setBaseAttribute(String id, int value) {
|
||||
getAttributeInstances().forEach(ins -> {
|
||||
if(ins.getId().equals(id))
|
||||
if (ins.getId().equals(id))
|
||||
ins.setBase(value);
|
||||
});
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.AltChar;
|
||||
import net.mmogroup.mmolib.api.util.AltChar;
|
||||
|
||||
public class ManaDisplayOptions {
|
||||
private final ChatColor full, half, empty;
|
||||
@ -12,7 +12,7 @@ public class ManaDisplayOptions {
|
||||
private final char barCharacter;
|
||||
|
||||
public static final ManaDisplayOptions DEFAULT = new ManaDisplayOptions(ChatColor.AQUA, ChatColor.BLUE, ChatColor.WHITE, "Mana",
|
||||
AltChar.listSquare.charAt(0), ChatColor.BLUE + AltChar.manaStar);
|
||||
AltChar.listSquare.charAt(0), ChatColor.BLUE + AltChar.star2);
|
||||
|
||||
public ManaDisplayOptions(ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load mana display options");
|
||||
|
@ -4,6 +4,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.mmogroup.mmolib.api.player.MMOData;
|
||||
import net.mmogroup.mmolib.api.stat.StatInstance;
|
||||
import net.mmogroup.mmolib.api.stat.StatMap;
|
||||
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
|
||||
|
||||
public class PlayerStats {
|
||||
private final PlayerData data;
|
||||
@ -42,13 +43,27 @@ public class PlayerStats {
|
||||
}
|
||||
|
||||
public double getBase(StatType stat) {
|
||||
return getInstance(stat).getBase();
|
||||
return data.getProfess().calculateStat(stat,
|
||||
stat.hasProfession() ? data.getCollectionSkills().getLevel(stat.getProfession()) : data.getLevel());
|
||||
}
|
||||
|
||||
/*
|
||||
* applies relative attributes on the extra stat value only
|
||||
* used to update MMOCore stat modifiers due to class and send them over to
|
||||
* MMOLib. must be ran everytime the player levels up or changes class.
|
||||
*/
|
||||
public double getExtraStat(StatType stat) {
|
||||
return getInstance(stat).getTotal(0);
|
||||
public void updateStats() {
|
||||
map.getInstances().forEach(ins -> ins.removeIf(key -> key.equals("mmocoreClass")));
|
||||
|
||||
for (StatType stat : StatType.values()) {
|
||||
double base = getBase(stat);
|
||||
if (base == 0)
|
||||
continue;
|
||||
|
||||
StatInstance instance = map.getInstance(stat.name());
|
||||
if ((base -= instance.getVanilla()) != 0)
|
||||
instance.addModifier("mmocoreClass", new StatModifier(base));
|
||||
}
|
||||
|
||||
map.updateAll();
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class DebugCommandMap extends CommandMap {
|
||||
super(parent, "debug");
|
||||
|
||||
addFloor(new StatValueCommandMap(this));
|
||||
addFloor(new StatModifiersCommandMap(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,53 @@
|
||||
package net.Indyuce.mmocore.command.rpg.debug;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.command.api.CommandEnd;
|
||||
import net.Indyuce.mmocore.command.api.CommandMap;
|
||||
import net.Indyuce.mmocore.command.api.Parameter;
|
||||
import net.mmogroup.mmolib.api.stat.StatInstance;
|
||||
import net.mmogroup.mmolib.api.stat.modifier.StatModifier;
|
||||
|
||||
public class StatModifiersCommandMap extends CommandEnd {
|
||||
public StatModifiersCommandMap(CommandMap parent) {
|
||||
super(parent, "statmods");
|
||||
|
||||
addParameter(new Parameter("<stat>", list -> {
|
||||
for (StatType stat : StatType.values())
|
||||
list.add(stat.name());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
if (args.length < 3)
|
||||
return CommandResult.THROW_USAGE;
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by a player.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
PlayerData data = PlayerData.get((Player) sender);
|
||||
|
||||
StatType stat;
|
||||
try {
|
||||
stat = StatType.valueOf(args[2].toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
sender.sendMessage(ChatColor.RED + "Could not find stat: " + args[2] + ".");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
StatInstance instance = data.getStats().getInstance(stat);
|
||||
sender.sendMessage("Stat Modifiers (" + instance.getKeys().size() + "):");
|
||||
for (String key : instance.getKeys()) {
|
||||
StatModifier mod = instance.getByKey(key);
|
||||
sender.sendMessage("- " + key + ": " + mod.getValue() + " " + mod.getType().name());
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ public class LootColor extends BukkitRunnable {
|
||||
this.item = item;
|
||||
this.color = color;
|
||||
|
||||
runTaskTimerAsynchronously(MMOCore.plugin, 0, 1);
|
||||
runTaskTimer(MMOCore.plugin, 0, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +69,7 @@ public class Lootsplosion implements Listener {
|
||||
item.setVelocity(randomVector());
|
||||
|
||||
if (colored)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> {
|
||||
NBTItem nbt = MMOLib.plugin.getNMS().getNBTItem(item.getItemStack());
|
||||
if (nbt.hasTag("MMOITEMS_TIER")) {
|
||||
ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER"));
|
||||
|
@ -7,12 +7,12 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.AltChar;
|
||||
import net.Indyuce.mmocore.api.experience.PlayerProfessions;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.quest.PlayerQuests;
|
||||
import net.mmogroup.mmolib.api.util.AltChar;
|
||||
|
||||
public class RPGPlaceholders
|
||||
extends PlaceholderExpansion /** implements Relational */
|
||||
|
@ -114,8 +114,8 @@ public class PlayerStats extends EditableInventory {
|
||||
Placeholders holders = new Placeholders();
|
||||
|
||||
for (StatType stat : StatType.values()) {
|
||||
double base = stats.getBase(stat), total = stats.getInstance(stat).getTotal(base), extra = total - base;
|
||||
holders.register(stat.name().toLowerCase(), stat.format(extra + base));
|
||||
double base = stats.getBase(stat), total = stats.getStat(stat), extra = total - base;
|
||||
holders.register(stat.name().toLowerCase(), stat.format(total));
|
||||
holders.register(stat.name().toLowerCase() + "_base", stat.format(base));
|
||||
holders.register(stat.name().toLowerCase() + "_extra", stat.format(extra));
|
||||
}
|
||||
|
@ -88,14 +88,12 @@ public class EditableFriendList extends EditableInventory {
|
||||
ItemStack disp = super.display(inv, n);
|
||||
ItemMeta meta = disp.getItemMeta();
|
||||
|
||||
|
||||
if (meta instanceof SkullMeta) {
|
||||
if (meta instanceof SkullMeta)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
((SkullMeta) meta).setOwningPlayer(friend);
|
||||
disp.setItemMeta(meta);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return NBTItem.get(disp).addTag(new ItemTag("uuid", friend.getUniqueId().toString())).toItem();
|
||||
}
|
||||
}
|
||||
@ -125,13 +123,11 @@ public class EditableFriendList extends EditableInventory {
|
||||
ItemStack disp = super.display(inv, n);
|
||||
ItemMeta meta = disp.getItemMeta();
|
||||
|
||||
/*
|
||||
* run async to save performance
|
||||
*/
|
||||
if (meta instanceof SkullMeta) {
|
||||
((SkullMeta) meta).setOwningPlayer(friend);
|
||||
disp.setItemMeta(meta);
|
||||
}
|
||||
if (meta instanceof SkullMeta)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
((SkullMeta) meta).setOwningPlayer(friend);
|
||||
disp.setItemMeta(meta);
|
||||
});
|
||||
|
||||
return NBTItem.get(disp).addTag(new ItemTag("uuid", friend.getUniqueId().toString())).toItem();
|
||||
}
|
||||
@ -153,7 +149,8 @@ public class EditableFriendList extends EditableInventory {
|
||||
|
||||
@Override
|
||||
public ItemStack display(GeneratedInventory inv, int n) {
|
||||
return inv.getPlayerData().getFriends().size() <= n ? super.display(inv, n) : Bukkit.getOfflinePlayer(inv.getPlayerData().getFriends().get(n)).isOnline() ? online.display(inv, n) : offline.display(inv, n);
|
||||
return inv.getPlayerData().getFriends().size() <= n ? super.display(inv, n)
|
||||
: Bukkit.getOfflinePlayer(inv.getPlayerData().getFriends().get(n)).isOnline() ? online.display(inv, n) : offline.display(inv, n);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -197,7 +194,8 @@ public class EditableFriendList extends EditableInventory {
|
||||
|
||||
long remaining = playerData.getLastFriendRequest() + 60 * 2 * 1000 - System.currentTimeMillis();
|
||||
if (remaining > 0) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("friend-request-cooldown", "cooldown", new DelayFormat().format(remaining)).send(player);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("friend-request-cooldown", "cooldown", new DelayFormat().format(remaining))
|
||||
.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -232,7 +230,8 @@ public class EditableFriendList extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("friend") && event.getAction() == InventoryAction.PICKUP_HALF)
|
||||
InventoryManager.FRIEND_REMOVAL.newInventory(playerData, Bukkit.getOfflinePlayer(UUID.fromString(NBTItem.get(event.getCurrentItem()).getString("uuid"))), this).open();
|
||||
InventoryManager.FRIEND_REMOVAL.newInventory(playerData,
|
||||
Bukkit.getOfflinePlayer(UUID.fromString(NBTItem.get(event.getCurrentItem()).getString("uuid"))), this).open();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,13 +62,11 @@ public class EditableGuildAdmin extends EditableInventory {
|
||||
ItemStack disp = super.display(inv, n);
|
||||
ItemMeta meta = disp.getItemMeta();
|
||||
|
||||
/*
|
||||
* run async to save performance
|
||||
*/
|
||||
if (meta instanceof SkullMeta) {
|
||||
((SkullMeta) meta).setOwningPlayer(member.getPlayer());
|
||||
disp.setItemMeta(meta);
|
||||
}
|
||||
if (meta instanceof SkullMeta)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
((SkullMeta) meta).setOwningPlayer(member.getPlayer());
|
||||
disp.setItemMeta(meta);
|
||||
});
|
||||
|
||||
return NBTItem.get(disp).addTag(new ItemTag("uuid", member.getUniqueId().toString())).toItem();
|
||||
}
|
||||
@ -151,7 +149,8 @@ public class EditableGuildAdmin extends EditableInventory {
|
||||
|
||||
long remaining = playerData.getGuild().getLastInvite(target) + 60 * 2 * 1000 - System.currentTimeMillis();
|
||||
if (remaining > 0) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("guild-invite-cooldown", "player", target.getName(), "cooldown", new DelayFormat().format(remaining)).send(player);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("guild-invite-cooldown", "player", target.getName(), "cooldown",
|
||||
new DelayFormat().format(remaining)).send(player);
|
||||
open();
|
||||
return;
|
||||
}
|
||||
|
@ -69,13 +69,11 @@ public class EditableGuildView extends EditableInventory {
|
||||
ItemStack disp = super.display(inv, n);
|
||||
ItemMeta meta = disp.getItemMeta();
|
||||
|
||||
/*
|
||||
* run async to save performance
|
||||
*/
|
||||
if (meta instanceof SkullMeta) {
|
||||
((SkullMeta) meta).setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
disp.setItemMeta(meta);
|
||||
}
|
||||
if (meta instanceof SkullMeta)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
((SkullMeta) meta).setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
disp.setItemMeta(meta);
|
||||
});
|
||||
|
||||
return NBTItem.get(disp).addTag(new ItemTag("uuid", uuid.toString())).toItem();
|
||||
}
|
||||
|
@ -28,8 +28,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void a(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
MMOCore.plugin.dataProvider.getDataManager().setup(player).getStats().getMap().updateAll();
|
||||
MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -39,6 +39,7 @@ public abstract class GuildDataManager {
|
||||
delete(guild);
|
||||
}
|
||||
|
||||
// TODO has nothing to do here
|
||||
public Guild stillInGuild(UUID uuid, String id) {
|
||||
Guild guild = getGuild(id);
|
||||
if (guild != null && guild.getMembers().has(uuid))
|
||||
@ -64,10 +65,12 @@ public abstract class GuildDataManager {
|
||||
|
||||
public abstract void save(Guild guild);
|
||||
|
||||
// TODO move to constructor, useless to handle vie abstract method
|
||||
public abstract void load();
|
||||
|
||||
public abstract void delete(Guild guild);
|
||||
|
||||
// TODO fix this
|
||||
// Shitty code for loading config values for guilds.
|
||||
private GuildConfiguration config;
|
||||
|
||||
|
@ -5,9 +5,11 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
|
||||
@ -24,7 +26,7 @@ public abstract class PlayerDataManager {
|
||||
|
||||
public abstract OfflinePlayerData getOffline(UUID uuid);
|
||||
|
||||
public PlayerData setup(Player player) {
|
||||
public void setup(Player player) {
|
||||
|
||||
/*
|
||||
* setup playerData based on loadData method to support both MySQL and
|
||||
@ -32,11 +34,18 @@ public abstract class PlayerDataManager {
|
||||
*/
|
||||
if (!map.containsKey(player.getUniqueId())) {
|
||||
PlayerData generated = new PlayerData(player);
|
||||
loadData(generated);
|
||||
map.put(player.getUniqueId(), generated);
|
||||
|
||||
/*
|
||||
* loads player data and ONLY THEN refresh the player statistics
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
loadData(generated);
|
||||
generated.getStats().updateStats();
|
||||
});
|
||||
}
|
||||
|
||||
return get(player).setPlayer(player);
|
||||
get(player).setPlayer(player);
|
||||
}
|
||||
|
||||
public boolean isLoaded(UUID uuid) {
|
||||
|
@ -35,12 +35,17 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
@Override
|
||||
public void loadData(PlayerData data) {
|
||||
ResultSet result = provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';");
|
||||
if (result == null)
|
||||
MMOCore.log(Level.SEVERE, "Failed to load playerdata from MySQL!");
|
||||
if (result == null) {
|
||||
MMOCore.log(Level.SEVERE, "Failed to load playerdata of '" + data.getPlayer().getName() + "' from MySQL server");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!result.next()) {
|
||||
|
||||
// player data not initialized yet
|
||||
if (!result.next())
|
||||
return;
|
||||
}
|
||||
|
||||
Gson parser = new Gson();
|
||||
|
||||
data.setClassPoints(result.getInt("class_points"));
|
||||
@ -186,7 +191,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
while (result.next()) {
|
||||
level = result.getInt("level");
|
||||
lastLogin = result.getLong("last_login");
|
||||
profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
|
||||
profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass()
|
||||
: MMOCore.plugin.classManager.get(result.getString("class"));
|
||||
if (!result.getString("friends").equalsIgnoreCase("null"))
|
||||
getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
|
||||
else
|
||||
@ -201,7 +207,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
@Override
|
||||
public void removeFriend(UUID uuid) {
|
||||
friends.remove(uuid);
|
||||
new MySQLTableEditor(Table.PLAYERDATA, uuid).updateData("friends", friends.stream().map(friend -> friend.toString()).collect(Collectors.toList()));
|
||||
new MySQLTableEditor(Table.PLAYERDATA, uuid).updateData("friends",
|
||||
friends.stream().map(friend -> friend.toString()).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -223,6 +230,5 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
public long getLastLogin() {
|
||||
return lastLogin;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,24 +5,19 @@ import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
|
||||
public class RequestManager {
|
||||
private Set<Request> requests = new HashSet<>();
|
||||
private final Set<Request> requests = new HashSet<>();
|
||||
|
||||
/*
|
||||
* flush friend requests async not to consume performance every 5 minutes so
|
||||
* there is no memory overleak.
|
||||
* flush friend requests every 5 minutes so there is no memory overleak
|
||||
*/
|
||||
public RequestManager() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
flushRequests();
|
||||
}
|
||||
}.runTaskTimerAsynchronously(MMOCore.plugin, 60 * 20, 60 * 20 * 5);
|
||||
Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, () -> flushRequests(), 60 * 20, 60 * 20 * 5);
|
||||
}
|
||||
|
||||
public Request getRequest(UUID uuid) {
|
||||
|
Loading…
Reference in New Issue
Block a user