use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class FishingAbilities method luckyCatch.
@EventHandler
public void luckyCatch(PlayerFishEvent event) {
if (blockDisabled(Ability.LUCKY_CATCH))
return;
Player player = event.getPlayer();
if (blockAbility(player))
return;
if (event.getCaught() instanceof Item) {
if (event.getExpToDrop() > 0) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
if (r.nextDouble() < (getValue(Ability.LUCKY_CATCH, playerData) / 100)) {
Item item = (Item) event.getCaught();
ItemStack drop = item.getItemStack();
if (drop.getMaxStackSize() > 1) {
drop.setAmount(drop.getAmount() * 2);
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, drop, item.getLocation(), LootDropCause.LUCKY_CATCH);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
item.setItemStack(dropEvent.getItemStack());
}
}
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class FishingLootHandler method onFish.
@EventHandler(priority = EventPriority.HIGH)
public void onFish(PlayerFishEvent event) {
if (!OptionL.isEnabled(Skills.FISHING))
return;
Player player = event.getPlayer();
if (blockAbility(player))
return;
if (plugin.getWorldManager().isInBlockedWorld(player.getLocation())) {
return;
}
if (plugin.isWorldGuardEnabled()) {
if (plugin.getWorldGuardSupport().isInBlockedRegion(player.getLocation())) {
return;
} else // Check if blocked by flags
if (plugin.getWorldGuardSupport().blockedByFlag(player.getLocation(), player, WorldGuardFlags.FlagKey.XP_GAIN)) {
return;
}
}
if (!(event.getCaught() instanceof Item))
return;
if (!event.getState().equals(PlayerFishEvent.State.CAUGHT_FISH))
return;
if (event.getExpToDrop() == 0)
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
ItemStack originalItem = ((Item) event.getCaught()).getItemStack();
FishingSource originalSource = FishingSource.valueOf(originalItem);
LootTable table = plugin.getLootTableManager().getLootTable(Skills.FISHING);
if (table == null)
return;
for (LootPool pool : table.getPools()) {
// Calculate chance for pool
Source source;
double chance = getCommonChance(pool, playerData);
LootDropCause cause = LootDropCause.FISHING_OTHER_LOOT;
if (pool.getName().equals("rare") && plugin.getAbilityManager().isEnabled(Ability.TREASURE_HUNTER)) {
chance += (getValue(Ability.TREASURE_HUNTER, playerData) / 100);
source = FishingSource.RARE;
cause = LootDropCause.TREASURE_HUNTER;
} else if (pool.getName().equals("epic") && plugin.getAbilityManager().isEnabled(Ability.EPIC_CATCH)) {
chance += (getValue(Ability.EPIC_CATCH, playerData) / 100);
source = FishingSource.EPIC;
cause = LootDropCause.EPIC_CATCH;
} else {
source = originalSource;
}
if (random.nextDouble() < chance) {
// Pool is selected
Loot selectedLoot = selectLoot(pool, originalSource);
// Give loot
if (selectedLoot != null) {
if (selectedLoot instanceof ItemLoot) {
ItemLoot itemLoot = (ItemLoot) selectedLoot;
giveFishingItemLoot(player, itemLoot, event, source, cause);
} else if (selectedLoot instanceof CommandLoot) {
CommandLoot commandLoot = (CommandLoot) selectedLoot;
giveCommandLoot(player, commandLoot, source);
}
break;
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class EnchantingAbilities method xpConvert.
@EventHandler(priority = EventPriority.MONITOR)
public void xpConvert(XpGainEvent event) {
if (event.isCancelled())
return;
if (blockDisabled(Ability.XP_CONVERT))
return;
Player player = event.getPlayer();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
if (playerData.getAbilityLevel(Ability.XP_CONVERT) > 0 && event.getAmount() > 0) {
double totalXp = playerData.getAbilityData(Ability.XP_CONVERT).getDouble("xp") + event.getAmount();
double value = getValue(Ability.XP_CONVERT, playerData);
if (value > 0) {
int added = (int) (totalXp / value);
double remainder = totalXp - added * value;
player.giveExp(added);
playerData.getAbilityData(Ability.XP_CONVERT).setData("xp", remainder);
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class EnduranceAbilities method goldenHealAndRecovery.
@EventHandler(priority = EventPriority.HIGH)
public void goldenHealAndRecovery(EntityRegainHealthEvent event) {
if (OptionL.isEnabled(Skills.ENDURANCE)) {
if (!event.isCancelled()) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (blockAbility(player))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
// Golden Heal
if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.MAGIC_REGEN)) {
if (isEnabled(Ability.GOLDEN_HEAL)) {
// Applies modifier
double modifier = getValue(Ability.GOLDEN_HEAL, playerData) / 100;
event.setAmount(event.getAmount() * (1 + modifier));
}
} else // Recovery
if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.SATIATED)) {
if (isEnabled(Ability.RECOVERY)) {
// Gets health
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attribute != null) {
double currentHealth = player.getHealth();
double maxHealth = attribute.getValue();
// Checks if health is less than half of max
if (currentHealth < (maxHealth / 2)) {
// Applies modifier
double modifier = getValue(Ability.RECOVERY, playerData) / 100;
event.setAmount(event.getAmount() * (1 + modifier));
}
}
}
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class EnduranceAbilities method recoveryCustom.
@EventHandler(priority = EventPriority.LOWEST)
public void recoveryCustom(CustomRegenEvent event) {
if (!event.isCancelled()) {
if (isEnabled(Ability.RECOVERY)) {
Player player = event.getPlayer();
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
// Gets health
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attribute != null) {
double currentHealth = player.getHealth();
double maxHealth = attribute.getValue();
// Checks if health is less than half of max
if (currentHealth < (maxHealth / 2)) {
// Applies modifier
double modifier = getValue(Ability.RECOVERY, playerData) / 100;
event.setAmount(event.getAmount() * (1 + modifier));
}
}
}
}
}
Aggregations