use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ForgingAbilities method anvilMaster.
@EventHandler(priority = EventPriority.MONITOR)
public void anvilMaster(InventoryOpenEvent event) {
if (event.isCancelled())
return;
if (blockDisabled(Ability.ANVIL_MASTER))
return;
if (!XMaterial.isNewVersion())
return;
Inventory inventory = event.getInventory();
if (inventory.getType() == InventoryType.ANVIL && inventory instanceof AnvilInventory) {
AnvilInventory anvil = (AnvilInventory) inventory;
if (event.getPlayer() instanceof Player) {
Player player = (Player) event.getPlayer();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.ANVIL_MASTER) > 0) {
int maxCost = (int) Math.round(getValue(Ability.ANVIL_MASTER, playerData));
anvil.setMaximumRepairCost(maxCost);
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ForgingAbilities method disenchanter.
@EventHandler(priority = EventPriority.MONITOR)
public void disenchanter(InventoryClickEvent event) {
if (event.isCancelled())
return;
if (blockDisabled(Ability.DISENCHANTER))
return;
// This ability requires at least 1.14
if (!VersionUtils.isAtLeastVersion(14))
return;
if (event.getWhoClicked() instanceof Player) {
Player player = (Player) event.getWhoClicked();
if (blockAbility(player))
return;
Inventory inventory = event.getClickedInventory();
if (inventory == null)
return;
ClickType click = event.getClick();
// Only allow right and left clicks if inventory full
if (click != ClickType.LEFT && click != ClickType.RIGHT && ItemUtils.isInventoryFull(player))
return;
// Make sure the click was successful
if (event.getResult() != Event.Result.ALLOW)
return;
// Make sure cursor is empty
if (player.getItemOnCursor().getType() != Material.AIR)
return;
if (event.getClickedInventory().getType() == InventoryType.GRINDSTONE) {
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.DISENCHANTER) == 0)
return;
Location location = inventory.getLocation();
if (location == null)
return;
ItemStack first = inventory.getItem(0);
ItemStack second = inventory.getItem(1);
if (first != null && second != null) {
// If two items, make sure items are the same type
if (first.getType() != second.getType()) {
return;
}
}
Set<EnchantmentValue> enchants = new HashSet<>();
// Add enchants to disenchant
checkEnchants(first, enchants);
checkEnchants(second, enchants);
if (enchants.size() == 0)
return;
// Calculate the sum
try {
int sum = 0;
for (EnchantmentValue value : enchants) {
String enchantName = value.getEnchantment().getKey().getKey().toUpperCase(Locale.ENGLISH);
if (containsEnchant(enchantName)) {
sum += GrindstoneEnchant.valueOf(enchantName).getLevel(value.getLevel());
}
}
// Get the average experience that would drop
int average = (sum + (int) Math.ceil(((double) sum) / 2)) / 2;
int added = (int) Math.round(average * (getValue(Ability.DISENCHANTER, playerData) / 100));
World world = location.getWorld();
if (world != null) {
world.spawn(location, ExperienceOrb.class).setExperience(added);
}
} catch (IllegalArgumentException ignored) {
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ForgingAbilities method skillMender.
@EventHandler(priority = EventPriority.MONITOR)
@SuppressWarnings("deprecation")
public void skillMender(XpGainEvent event) {
if (event.isCancelled())
return;
if (blockDisabled(Ability.SKILL_MENDER))
return;
Player player = event.getPlayer();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.SKILL_MENDER) == 0)
return;
if (random.nextDouble() < getValue(Ability.SKILL_MENDER, playerData) / 100) {
// Get all the items that have mending
List<ItemStack> mendingItems = new ArrayList<>();
for (ItemStack item : player.getInventory().getArmorContents()) {
if (item != null) {
if (item.containsEnchantment(Enchantment.MENDING) && hasDamage(item)) {
mendingItems.add(item);
}
}
}
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
if (mainHandItem.containsEnchantment(Enchantment.MENDING) && hasDamage(mainHandItem)) {
mendingItems.add(mainHandItem);
}
ItemStack offHandItem = player.getInventory().getItemInOffHand();
if (offHandItem.containsEnchantment(Enchantment.MENDING) && hasDamage(offHandItem)) {
mendingItems.add(offHandItem);
}
if (mendingItems.size() == 0)
return;
// Pick a random item
ItemStack mendedItem = mendingItems.get(random.nextInt(mendingItems.size()));
// One durability per 2 skill xp gained
int durabilityToRepair = (int) Math.round(event.getAmount() / 2);
// Apply durability repair
if (XMaterial.isNewVersion()) {
ItemMeta meta = mendedItem.getItemMeta();
if (meta == null)
return;
if (meta instanceof Damageable) {
Damageable damageable = (Damageable) meta;
damageable.setDamage(Math.max(damageable.getDamage() - durabilityToRepair, 0));
mendedItem.setItemMeta(damageable);
}
} else {
mendedItem.setDurability((short) Math.max(mendedItem.getDurability() - durabilityToRepair, 0));
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class HealingAbilities method goldenHeart.
@EventHandler(priority = EventPriority.HIGHEST)
public void goldenHeart(EntityDamageEvent event) {
if (blockDisabled(Ability.GOLDEN_HEART))
return;
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (getAbsorptionAmount(player) > 0 && playerData.getAbilityLevel(Ability.GOLDEN_HEART) > 0) {
double multiplier = 1 - getValue(Ability.GOLDEN_HEART, playerData) / 100;
if (multiplier < 0.01) {
// Cap at 99% reduction
multiplier = 0.01;
}
event.setDamage(event.getDamage() * multiplier);
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class HealingAbilities method revival.
@EventHandler
public void revival(PlayerRespawnEvent event) {
if (blockDisabled(Ability.REVIVAL))
return;
Player player = event.getPlayer();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.REVIVAL) > 0) {
double healthBonus = getValue(Ability.REVIVAL, playerData);
double regenerationBonus = getValue2(Ability.REVIVAL, playerData);
StatModifier healthModifier = new StatModifier("AureliumSkills.Ability.Revival.Health", Stats.HEALTH, healthBonus);
StatModifier regenerationModifier = new StatModifier("AureliumSkills.Ability.Revival.Regeneration", Stats.REGENERATION, regenerationBonus);
playerData.addStatModifier(healthModifier);
playerData.addStatModifier(regenerationModifier);
if (plugin.getAbilityManager().getOptionAsBooleanElseTrue(Ability.REVIVAL, "enable_message")) {
Locale locale = playerData.getLocale();
plugin.getAbilityManager().sendMessage(player, TextUtil.replace(Lang.getMessage(AbilityMessage.REVIVAL_MESSAGE, locale), "{value}", NumberUtil.format1(healthBonus), "{value_2}", NumberUtil.format1(regenerationBonus)));
}
new BukkitRunnable() {
@Override
public void run() {
playerData.removeStatModifier("AureliumSkills.Ability.Revival.Health");
playerData.removeStatModifier("AureliumSkills.Ability.Revival.Regeneration");
}
}.runTaskLater(plugin, 30 * 20);
}
}
Aggregations