use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class EnchantingAbilities method luckyTable.
@EventHandler(priority = EventPriority.HIGHEST)
public void luckyTable(EnchantItemEvent event) {
if (event.isCancelled())
return;
if (blockDisabled(Ability.LUCKY_TABLE))
return;
Player player = event.getEnchanter();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.LUCKY_TABLE) > 0) {
for (Map.Entry<Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
if (entry.getKey().getMaxLevel() > entry.getValue()) {
if (random.nextDouble() < getValue(Ability.LUCKY_TABLE, playerData) / 100) {
entry.setValue(entry.getValue() + 1);
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class EnduranceAbilities method mealSteal.
@EventHandler(priority = EventPriority.HIGH)
public void mealSteal(EntityDamageByEntityEvent event) {
if (blockDisabled(Ability.MEAL_STEAL))
return;
if (!event.isCancelled()) {
// Checks if entity and damager are players
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player player = (Player) event.getDamager();
Player enemy = (Player) event.getEntity();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
// Calculates chance
double chance = getValue(Ability.MEAL_STEAL, playerData) / 100;
if (r.nextDouble() < chance) {
// Removes food from enemy
if (enemy.getFoodLevel() >= 1) {
enemy.setFoodLevel(enemy.getFoodLevel() - 1);
}
// Adds food level to player
if (player.getFoodLevel() < 20) {
player.setFoodLevel(player.getFoodLevel() + 1);
} else // Adds saturation if food is full
if (player.getSaturation() < 20f) {
player.setSaturation(player.getSaturation() + 1f);
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ExcavationAbilities method biggerScoop.
@SuppressWarnings("deprecation")
public void biggerScoop(ExcavationSource source, Block block, Player player) {
if (!plugin.getAbilityManager().isEnabled(Ability.BIGGER_SCOOP))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (player.getGameMode() != GameMode.SURVIVAL)
return;
if (r.nextDouble() < (getValue(Ability.BIGGER_SCOOP, playerData) / 100)) {
ItemStack tool = player.getInventory().getItemInMainHand();
Material mat = block.getType();
for (ItemStack item : block.getDrops(tool)) {
// If silk touch
if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
PlayerLootDropEvent event;
Location loc = block.getLocation().add(0.5, 0.5, 0.5);
if (source.getLegacyData() == -1) {
event = new PlayerLootDropEvent(player, new ItemStack(mat, 2), loc, LootDropCause.BIGGER_SCOOP);
} else {
if (VersionUtils.isAtLeastVersion(13)) {
event = new PlayerLootDropEvent(player, new ItemStack(mat, 2), loc, LootDropCause.BIGGER_SCOOP);
} else {
event = new PlayerLootDropEvent(player, new ItemStack(mat, 2, source.getLegacyData()), loc, LootDropCause.BIGGER_SCOOP);
}
}
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.getItemStack());
}
} else // Drop regular item if not silk touch
{
ItemStack drop = item.clone();
drop.setAmount(2);
PlayerLootDropEvent event = new PlayerLootDropEvent(player, drop, block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.BIGGER_SCOOP);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.getItemStack());
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class AgilityAbilities method sugarRushSplash.
// For potion splashes
@EventHandler(priority = EventPriority.HIGH)
public void sugarRushSplash(PotionSplashEvent event) {
if (!event.isCancelled()) {
if (blockDisabled(Ability.SUGAR_RUSH))
return;
for (PotionEffect effect : event.getPotion().getEffects()) {
if (effect.getType().equals(PotionEffectType.SPEED) || effect.getType().equals(PotionEffectType.JUMP)) {
for (LivingEntity entity : event.getAffectedEntities()) {
if (entity instanceof Player) {
Player player = (Player) entity;
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.SUGAR_RUSH) > 0) {
double intensity = event.getIntensity(player);
double multiplier = 1 + (getValue(Ability.SUGAR_RUSH, playerData) / 100);
PotionUtil.applyEffect(player, new PotionEffect(effect.getType(), (int) (effect.getDuration() * multiplier * intensity), effect.getAmplifier()));
}
}
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class AgilityAbilities method sugarRushDrink.
// For potion drinking
@EventHandler(priority = EventPriority.HIGH)
public void sugarRushDrink(PlayerItemConsumeEvent event) {
if (!event.isCancelled()) {
if (blockDisabled(Ability.SUGAR_RUSH))
return;
Player player = event.getPlayer();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.SUGAR_RUSH) > 0) {
ItemStack item = event.getItem();
if (item.getType() == Material.POTION) {
if (item.getItemMeta() instanceof PotionMeta) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
PotionData potion = meta.getBasePotionData();
double multiplier = 1 + (getValue(Ability.SUGAR_RUSH, playerData) / 100);
if (potion.getType() == PotionType.SPEED || potion.getType() == PotionType.JUMP) {
int amplifier = 0;
if (potion.isUpgraded()) {
amplifier = 1;
}
PotionEffectType potionEffectType;
if (potion.getType() == PotionType.SPEED) {
potionEffectType = PotionEffectType.SPEED;
} else {
potionEffectType = PotionEffectType.JUMP;
}
int duration;
if (potion.isExtended()) {
duration = 480;
} else if (potion.isUpgraded()) {
duration = 90;
} else {
duration = 180;
}
duration = (int) (multiplier * duration);
PotionUtil.applyEffect(player, new PotionEffect(potionEffectType, duration * 20, amplifier));
}
// Apply custom effects
if (meta.hasCustomEffects()) {
for (PotionEffect effect : meta.getCustomEffects()) {
if (effect.getType().equals(PotionEffectType.SPEED) || effect.getType().equals(PotionEffectType.JUMP)) {
PotionUtil.applyEffect(player, new PotionEffect(effect.getType(), (int) (effect.getDuration() * multiplier), effect.getAmplifier()));
}
}
}
}
}
}
}
}
Aggregations