use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ArmorModifierListener method onJoin.
@EventHandler(priority = EventPriority.LOWEST)
public void onJoin(PlayerDataLoadEvent event) {
Player player = event.getPlayerData().getPlayer();
PlayerData playerData = event.getPlayerData();
for (ItemStack armor : player.getInventory().getArmorContents()) {
if (armor != null) {
if (OptionL.getBoolean(Option.MODIFIER_ARMOR_TIMER_ENABLED)) {
storedArmor.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>()).put(ArmorType.matchType(armor), armor.clone());
}
if (!armor.getType().equals(Material.AIR)) {
if (requirements.meetsRequirements(ModifierType.ARMOR, armor, player)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, armor)) {
playerData.addStatModifier(modifier, false);
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, armor)) {
playerData.addMultiplier(multiplier);
}
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ArmorModifierListener method onEquip.
@EventHandler
public void onEquip(ArmorEquipEvent event) {
// Don't use if timer is enabled
if (OptionL.getBoolean(Option.MODIFIER_ARMOR_TIMER_ENABLED))
return;
Player player = event.getPlayer();
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
// Equip
if (event.getNewArmorPiece() != null && event.getNewArmorPiece().getType() != Material.AIR) {
ItemStack item = event.getNewArmorPiece();
if (requirements.meetsRequirements(ModifierType.ARMOR, item, player)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, item)) {
playerData.addStatModifier(modifier);
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, item)) {
playerData.addMultiplier(multiplier);
}
}
}
// Un-equip
if (event.getOldArmorPiece() != null && event.getOldArmorPiece().getType() != Material.AIR) {
ItemStack item = event.getOldArmorPiece();
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, item)) {
playerData.removeStatModifier(modifier.getName());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, item)) {
playerData.removeMultiplier(multiplier.getName());
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ItemListener method onJoin.
@EventHandler(priority = EventPriority.LOW)
public void onJoin(PlayerDataLoadEvent event) {
Player player = event.getPlayerData().getPlayer();
ItemStack held = player.getInventory().getItemInMainHand();
heldItems.put(player.getUniqueId(), held);
PlayerData playerData = event.getPlayerData();
if (!held.getType().equals(Material.AIR)) {
if (OptionL.getBoolean(Option.MODIFIER_AUTO_CONVERT_FROM_LEGACY)) {
held = requirements.convertFromLegacy(modifiers.convertFromLegacy(held));
if (!held.equals(player.getInventory().getItemInMainHand())) {
player.getInventory().setItemInMainHand(held);
}
}
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, held)) {
playerData.addStatModifier(modifier, false);
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, held)) {
playerData.addMultiplier(multiplier);
}
}
if (OptionL.getBoolean(Option.MODIFIER_ITEM_ENABLE_OFF_HAND)) {
ItemStack offHandItem = player.getInventory().getItemInOffHand();
offHandItems.put(player.getUniqueId(), offHandItem);
if (!offHandItem.getType().equals(Material.AIR)) {
if (OptionL.getBoolean(Option.MODIFIER_AUTO_CONVERT_FROM_LEGACY)) {
offHandItem = requirements.convertFromLegacy(modifiers.convertFromLegacy(offHandItem));
if (!offHandItem.equals(player.getInventory().getItemInOffHand())) {
player.getInventory().setItemInOffHand(offHandItem);
}
}
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, offHandItem)) {
StatModifier offHandModifier = new StatModifier(modifier.getName() + ".Offhand", modifier.getStat(), modifier.getValue());
playerData.addStatModifier(offHandModifier);
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, offHandItem)) {
Multiplier offHandMultiplier = new Multiplier(multiplier.getName() + ".Offhand", multiplier.getSkill(), multiplier.getValue());
playerData.addMultiplier(offHandMultiplier);
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ItemListener method onSwap.
@EventHandler(priority = EventPriority.MONITOR)
public void onSwap(PlayerSwapHandItemsEvent event) {
if (!event.isCancelled()) {
// Make sure event is not cancelled
if (OptionL.getBoolean(Option.MODIFIER_ITEM_ENABLE_OFF_HAND)) {
// Check off hand support is enabled
Player player = event.getPlayer();
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
// Get items switched
ItemStack itemOffHand = event.getOffHandItem();
ItemStack itemMainHand = event.getMainHandItem();
// Update items
offHandItems.put(player.getUniqueId(), itemOffHand);
heldItems.put(player.getUniqueId(), itemMainHand);
// Things to prevent double reloads
Set<String> offHandModifiers = new HashSet<>();
Set<Stat> statsToReload = new HashSet<>();
Set<String> offHandMultipliers = new HashSet<>();
// Check off hand item
if (itemOffHand != null) {
if (itemOffHand.getType() != Material.AIR) {
// Get whether player meets requirements
boolean meetsRequirements = requirements.meetsRequirements(ModifierType.ITEM, itemOffHand, player);
// For each modifier on the item
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemOffHand)) {
// Removes the old modifier from main hand
StatModifier offHandModifier = new StatModifier(modifier.getName() + ".Offhand", modifier.getStat(), modifier.getValue());
playerData.removeStatModifier(modifier.getName(), false);
// Add new one if meets requirements
if (meetsRequirements) {
playerData.addStatModifier(offHandModifier, false);
}
// Reload check stuff
offHandModifiers.add(offHandModifier.getName());
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemOffHand)) {
Multiplier offHandMultiplier = new Multiplier(multiplier.getName() + ".Offhand", multiplier.getSkill(), multiplier.getValue());
playerData.removeMultiplier(multiplier.getName());
if (meetsRequirements) {
playerData.addMultiplier(offHandMultiplier);
}
offHandMultipliers.add(offHandMultiplier.getName());
}
}
}
// Check main hand item
if (itemMainHand != null) {
if (itemMainHand.getType() != Material.AIR) {
// Get whether player meets requirements
boolean meetsRequirements = requirements.meetsRequirements(ModifierType.ITEM, itemMainHand, player);
// For each modifier on the item
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemMainHand)) {
// Removes the offhand modifier if wasn't already added
if (!offHandModifiers.contains(modifier.getName() + ".Offhand")) {
playerData.removeStatModifier(modifier.getName() + ".Offhand", false);
}
// Add if meets requirements
if (meetsRequirements) {
playerData.addStatModifier(modifier, false);
}
// Reload check stuff
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemMainHand)) {
if (!offHandMultipliers.contains(multiplier.getName() + ".Offhand")) {
playerData.removeMultiplier(multiplier.getName() + ".Offhand");
}
if (meetsRequirements) {
playerData.addMultiplier(multiplier);
}
}
}
}
// Reload stats
for (Stat stat : statsToReload) {
statLeveler.reloadStat(player, stat);
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ModifierManager method reloadPlayer.
public void reloadPlayer(Player player) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
Requirements requirements = new Requirements(plugin);
Modifiers modifiers = new Modifiers(plugin);
Multipliers multipliers = new Multipliers(plugin);
if (playerData != null) {
Set<Stat> statsToReload = new HashSet<>();
ItemStack item = player.getInventory().getItemInMainHand();
if (!(item.getType() == Material.AIR)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, item)) {
playerData.removeStatModifier(modifier.getName());
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, item)) {
playerData.removeMultiplier(multiplier.getName());
}
if (requirements.meetsRequirements(ModifierType.ITEM, item, player)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, item)) {
playerData.addStatModifier(modifier, false);
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, item)) {
playerData.addMultiplier(multiplier);
}
}
}
ItemStack itemOffHand = player.getInventory().getItemInOffHand();
if (!(itemOffHand.getType() == Material.AIR)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemOffHand)) {
playerData.removeStatModifier(modifier.getName() + ".Offhand");
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemOffHand)) {
playerData.removeMultiplier(multiplier.getName() + ".Offhand");
}
if (requirements.meetsRequirements(ModifierType.ITEM, itemOffHand, player)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemOffHand)) {
StatModifier offHandModifier = new StatModifier(modifier.getName() + ".Offhand", modifier.getStat(), modifier.getValue());
playerData.addStatModifier(offHandModifier, false);
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemOffHand)) {
Multiplier offHandMultiplier = new Multiplier(multiplier.getName() + ".Offhand", multiplier.getSkill(), multiplier.getValue());
playerData.addMultiplier(offHandMultiplier);
}
}
}
EntityEquipment equipment = player.getEquipment();
if (equipment != null) {
for (ItemStack armor : equipment.getArmorContents()) {
if (armor != null) {
if (!(armor.getType() == Material.AIR)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, armor)) {
playerData.removeStatModifier(modifier.getName());
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, armor)) {
playerData.removeMultiplier(multiplier.getName());
}
if (requirements.meetsRequirements(ModifierType.ARMOR, armor, player)) {
for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, armor)) {
playerData.addStatModifier(modifier, false);
statsToReload.add(modifier.getStat());
}
for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, armor)) {
playerData.addMultiplier(multiplier);
}
}
}
}
}
}
for (Stat stat : statsToReload) {
statLeveler.reloadStat(player, stat);
}
}
}
Aggregations