mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-03-01 15:51:03 +01:00
MMOPlayerData refactor
Please use this version of MMOLib https://github.com/mmopluginteam/mmolib/releases/tag/1.2.5
This commit is contained in:
parent
a864b94aa8
commit
f3443a49bd
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
2
pom.xml
2
pom.xml
@ -16,7 +16,7 @@
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>Lumine Releases</name>
|
||||
<url>http://mvn.lumine.io/repository/maven-releases/</url>
|
||||
|
@ -76,6 +76,7 @@ import net.Indyuce.mmoitems.manager.recipe.RecipeManager;
|
||||
import net.Indyuce.mmoitems.manager.recipe.RecipeManagerDefault;
|
||||
import net.Indyuce.mmoitems.manager.recipe.RecipeManagerLegacy;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
||||
import net.mmogroup.mmolib.version.SpigotPlugin;
|
||||
|
||||
public class MMOItems extends JavaPlugin {
|
||||
@ -255,7 +256,7 @@ public class MMOItems extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
|
||||
// save player data
|
||||
PlayerData.getLoaded().forEach(data -> data.save());
|
||||
MMOPlayerData.getLoaded().stream().filter(data -> data.getMMOItems() != null).forEach(data -> data.getMMOItems().save());
|
||||
|
||||
// save item updater data
|
||||
ConfigFile updater = new ConfigFile("/dynamic", "updater");
|
||||
|
@ -79,6 +79,10 @@ public class ItemTier {
|
||||
public List<ItemStack> generateDeconstructedItem() {
|
||||
return hasDropTable() ? deconstruct.read(false) : new ArrayList<>();
|
||||
}
|
||||
|
||||
// public RolledTier roll() {
|
||||
// return new RolledTier(info, itemLevel)
|
||||
// }
|
||||
|
||||
public class UnidentificationInfo {
|
||||
private final String name, prefix;
|
||||
|
@ -45,16 +45,11 @@ import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.DamageType;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
/*
|
||||
* refreshes the player instance if the player has gone offline since or
|
||||
* else just return it. the offline player does not have to be refreshed, it
|
||||
* is just cached at the beginning
|
||||
*/
|
||||
private Player player;
|
||||
private final UUID uuid;
|
||||
private final MMOPlayerData mmoData;
|
||||
|
||||
/*
|
||||
* reloaded everytime the player reconnects in case of major change.
|
||||
@ -83,18 +78,16 @@ public class PlayerData {
|
||||
private Set<ParticleRunnable> itemParticles = new HashSet<>();
|
||||
private ParticleRunnable overridingItemParticles = null;
|
||||
private Set<AbilityData> itemAbilities = new HashSet<>();
|
||||
|
||||
private boolean fullHands = false;
|
||||
private SetBonuses setBonuses = null;
|
||||
private final PlayerStats stats;
|
||||
|
||||
private boolean fullHands = false;
|
||||
private PlayerData(MMOPlayerData mmoData) {
|
||||
mmoData.setMMOItems(this);
|
||||
|
||||
private static Map<UUID, PlayerData> playerDatas = new HashMap<>();
|
||||
|
||||
private PlayerData(Player player) {
|
||||
this.uuid = player.getUniqueId();
|
||||
setPlayer(player);
|
||||
stats = new PlayerStats(this);
|
||||
this.mmoData = mmoData;
|
||||
this.rpgPlayer = MMOItems.plugin.getRPG().getInfo(this);
|
||||
this.stats = new PlayerStats(this);
|
||||
|
||||
load(new ConfigFile("/userdata", getUniqueId().toString()).getConfig());
|
||||
updateInventory();
|
||||
@ -112,22 +105,18 @@ public class PlayerData {
|
||||
config.getConfig().createSection("crafting-queue");
|
||||
craftingStatus.save(config.getConfig().getConfigurationSection("crafting-queue"));
|
||||
config.save();
|
||||
|
||||
// memory leaks
|
||||
player = null;
|
||||
}
|
||||
|
||||
private void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
this.rpgPlayer = MMOItems.plugin.getRPG().getInfo(this);
|
||||
public MMOPlayerData getMMOPlayerData() {
|
||||
return mmoData;
|
||||
}
|
||||
|
||||
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
return mmoData.getUniqueId();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
return mmoData.getPlayer();
|
||||
}
|
||||
|
||||
public RPGPlayer getRPG() {
|
||||
@ -144,7 +133,7 @@ public class PlayerData {
|
||||
}
|
||||
|
||||
public void checkForInventoryUpdate() {
|
||||
PlayerInventory inv = player.getInventory();
|
||||
PlayerInventory inv = getPlayer().getInventory();
|
||||
if (!equals(helmet, inv.getHelmet()) || !equals(chestplate, inv.getChestplate()) || !equals(leggings, inv.getLeggings())
|
||||
|| !equals(boots, inv.getBoots()) || !equals(hand, inv.getItemInMainHand()) || !equals(offhand, inv.getItemInOffHand()))
|
||||
updateInventory();
|
||||
@ -169,8 +158,8 @@ public class PlayerData {
|
||||
* one two handed item and one other item at the same time. this will
|
||||
*/
|
||||
public boolean areHandsFull() {
|
||||
NBTItem main = MMOLib.plugin.getNMS().getNBTItem(player.getInventory().getItemInMainHand());
|
||||
NBTItem off = MMOLib.plugin.getNMS().getNBTItem(player.getInventory().getItemInOffHand());
|
||||
NBTItem main = MMOLib.plugin.getNMS().getNBTItem(getPlayer().getInventory().getItemInMainHand());
|
||||
NBTItem off = MMOLib.plugin.getNMS().getNBTItem(getPlayer().getInventory().getItemInOffHand());
|
||||
return (main.getBoolean("MMOITEMS_TWO_HANDED") && (off.getItem() != null && off.getItem().getType() != Material.AIR))
|
||||
|| (off.getBoolean("MMOITEMS_TWO_HANDED") && (main.getItem() != null && main.getItem().getType() != Material.AIR));
|
||||
}
|
||||
@ -195,7 +184,7 @@ public class PlayerData {
|
||||
fullHands = areHandsFull();
|
||||
|
||||
// find all the items the player can actually use.
|
||||
for (EquippedItem item : MMOItems.plugin.getInventory().getInventory(player)) {
|
||||
for (EquippedItem item : MMOItems.plugin.getInventory().getInventory(getPlayer())) {
|
||||
NBTItem nbtItem = item.newNBTItem();
|
||||
|
||||
Type type = nbtItem.getType();
|
||||
@ -247,7 +236,7 @@ public class PlayerData {
|
||||
// if the item with the abilities is in the players offhand AND
|
||||
// its disabled in the config then just move on, else add the
|
||||
// ability
|
||||
if (item.getNBT().getItem().equals(player.getInventory().getItemInOffHand())
|
||||
if (item.getNBT().getItem().equals(getPlayer().getInventory().getItemInOffHand())
|
||||
&& MMOItems.plugin.getConfig().getBoolean("disable-abilities-in-offhand")) {
|
||||
continue;
|
||||
} else
|
||||
@ -300,26 +289,26 @@ public class PlayerData {
|
||||
* actually update the player inventory so the task doesn't infinitely
|
||||
* loop on updating
|
||||
*/
|
||||
helmet = player.getInventory().getHelmet();
|
||||
chestplate = player.getInventory().getChestplate();
|
||||
leggings = player.getInventory().getLeggings();
|
||||
boots = player.getInventory().getBoots();
|
||||
hand = player.getInventory().getItemInMainHand();
|
||||
offhand = player.getInventory().getItemInOffHand();
|
||||
helmet = getPlayer().getInventory().getHelmet();
|
||||
chestplate = getPlayer().getInventory().getChestplate();
|
||||
leggings = getPlayer().getInventory().getLeggings();
|
||||
boots = getPlayer().getInventory().getBoots();
|
||||
hand = getPlayer().getInventory().getItemInMainHand();
|
||||
offhand = getPlayer().getInventory().getItemInOffHand();
|
||||
}
|
||||
|
||||
public void updateEffects() {
|
||||
|
||||
// perm effects
|
||||
permanentEffects.keySet().forEach(effect -> {
|
||||
player.removePotionEffect(effect);
|
||||
player.addPotionEffect(permanentEffects.get(effect));
|
||||
getPlayer().removePotionEffect(effect);
|
||||
getPlayer().addPotionEffect(permanentEffects.get(effect));
|
||||
});
|
||||
|
||||
// two handed
|
||||
if (fullHands) {
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 1, true, false));
|
||||
getPlayer().removePotionEffect(PotionEffectType.SLOW);
|
||||
getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 1, true, false));
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,17 +363,16 @@ public class PlayerData {
|
||||
return castAbilities(getStats().newTemporary(), target, result, castMode);
|
||||
}
|
||||
|
||||
public ItemAttackResult castAbilities(CachedStats stats, LivingEntity target, ItemAttackResult result,
|
||||
CastingMode castMode) {
|
||||
public ItemAttackResult castAbilities(CachedStats stats, LivingEntity target, ItemAttackResult result, CastingMode castMode) {
|
||||
|
||||
/*
|
||||
* if ability has target, check for ability flag at location of target and make
|
||||
* sure player can attack target. if ability has no target, check for WG flag at
|
||||
* the caster location
|
||||
* if ability has target, check for ability flag at location of target
|
||||
* and make sure player can attack target. if ability has no target,
|
||||
* check for WG flag at the caster location
|
||||
*/
|
||||
if (target == null ? !MMOItems.plugin.getFlags().isFlagAllowed(player, CustomFlag.MI_ABILITIES)
|
||||
if (target == null ? !MMOItems.plugin.getFlags().isFlagAllowed(getPlayer(), CustomFlag.MI_ABILITIES)
|
||||
: !MMOItems.plugin.getFlags().isFlagAllowed(target.getLocation(), CustomFlag.MI_ABILITIES)
|
||||
|| !MMOUtils.canDamage(player, target))
|
||||
|| !MMOUtils.canDamage(getPlayer(), target))
|
||||
return result.setSuccessful(false);
|
||||
|
||||
for (AbilityData ability : itemAbilities)
|
||||
@ -503,27 +491,29 @@ public class PlayerData {
|
||||
}
|
||||
|
||||
public static PlayerData get(UUID uuid) {
|
||||
return playerDatas.get(uuid);
|
||||
return MMOPlayerData.get(uuid).getMMOItems();
|
||||
}
|
||||
|
||||
/*
|
||||
* method called when the corresponding MMOPlayerData has already been
|
||||
* initialized
|
||||
*/
|
||||
public static void load(Player player) {
|
||||
|
||||
/*
|
||||
* if the player data is not loaded yet, load it.
|
||||
*/
|
||||
if (!playerDatas.containsKey(player.getUniqueId()))
|
||||
playerDatas.put(player.getUniqueId(), new PlayerData(player));
|
||||
MMOPlayerData mmoData = MMOPlayerData.get(player.getUniqueId());
|
||||
|
||||
/*
|
||||
* otherwise it is already loaded and the player variable must be
|
||||
* refreshed since the player logged out and in again.
|
||||
* if no mmoitems data could be found, it must be initialized
|
||||
*/
|
||||
if (mmoData.getMMOItems() == null)
|
||||
mmoData.setMMOItems(new PlayerData(mmoData));
|
||||
|
||||
/*
|
||||
* otherwise just update the cached RPGPlayer in case of any major
|
||||
* change in the player data of other rpg plugins
|
||||
*/
|
||||
else
|
||||
get(player).setPlayer(player);
|
||||
}
|
||||
|
||||
public static Collection<PlayerData> getLoaded() {
|
||||
return playerDatas.values();
|
||||
mmoData.getMMOItems().rpgPlayer = MMOItems.plugin.getRPG().getInfo(mmoData.getMMOItems());
|
||||
}
|
||||
|
||||
public enum CooldownType {
|
||||
|
@ -9,18 +9,14 @@ import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.item.VolatileMMOItem;
|
||||
import net.Indyuce.mmoitems.stat.type.AttributeStat;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.api.player.MMOData;
|
||||
import net.mmogroup.mmolib.api.stat.StatInstance;
|
||||
import net.mmogroup.mmolib.api.stat.StatMap;
|
||||
|
||||
public class PlayerStats {
|
||||
private final PlayerData playerData;
|
||||
private final StatMap map;
|
||||
|
||||
public PlayerStats(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
|
||||
map = MMOData.get(playerData.getPlayer()).setMMOItems(playerData).getStatMap();
|
||||
}
|
||||
|
||||
public PlayerData getData() {
|
||||
@ -28,7 +24,7 @@ public class PlayerStats {
|
||||
}
|
||||
|
||||
public StatMap getMap() {
|
||||
return map;
|
||||
return playerData.getMMOPlayerData().getStatMap();
|
||||
}
|
||||
|
||||
public double getStat(ItemStat stat) {
|
||||
@ -36,7 +32,7 @@ public class PlayerStats {
|
||||
}
|
||||
|
||||
public StatInstance getInstance(ItemStat stat) {
|
||||
return map.getInstance(stat.getId());
|
||||
return getMap().getInstance(stat.getId());
|
||||
}
|
||||
|
||||
public CachedStats newTemporary() {
|
||||
@ -44,7 +40,7 @@ public class PlayerStats {
|
||||
}
|
||||
|
||||
public void updateStats() {
|
||||
map.getInstances().forEach(ins -> {
|
||||
getMap().getInstances().forEach(ins -> {
|
||||
ins.remove("item");
|
||||
ins.remove("fullSetBonus");
|
||||
});
|
||||
@ -76,7 +72,7 @@ public class PlayerStats {
|
||||
|
||||
public CachedStats() {
|
||||
player = playerData.getPlayer();
|
||||
for (StatInstance ins : map.getInstances())
|
||||
for (StatInstance ins : getMap().getInstances())
|
||||
this.stats.put(ins.getStat(), ins.getTotal());
|
||||
}
|
||||
|
||||
|
@ -18,19 +18,21 @@ import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.block.CustomBlock;
|
||||
import net.Indyuce.mmoitems.api.crafting.ConditionalDisplay;
|
||||
import net.mmogroup.mmolib.api.util.AltChar;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.crafting.ExperienceCraftingTrigger;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.crafting.ProfessionCondition;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.GetMMOItemObjective;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.ItemTemplateDropItem;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemDropItem;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemTrigger;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MMOItemsBlockType;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.MineMIBlockExperienceSource;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.RandomItemDropItem;
|
||||
import net.Indyuce.mmoitems.comp.mmocore.load.SmeltMMOItemExperienceSource;
|
||||
import net.Indyuce.mmoitems.stat.type.DoubleStat;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.api.util.AltChar;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
|
||||
public class MMOCoreMMOLoader extends MMOLoader {
|
||||
|
||||
@ -90,6 +92,12 @@ public class MMOCoreMMOLoader extends MMOLoader {
|
||||
if (config.getKey().equals("mmoitem"))
|
||||
return new MMOItemDropItem(config);
|
||||
|
||||
if (config.getKey().equals("mitemplate"))
|
||||
return new ItemTemplateDropItem(config);
|
||||
|
||||
if (config.getKey().equals("mirandomitem") || config.getKey().equals("miri"))
|
||||
return new RandomItemDropItem(config);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user