use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class EnduranceAbilities method antiHunger.
@EventHandler(priority = EventPriority.HIGH)
public void antiHunger(FoodLevelChangeEvent event) {
if (blockDisabled(Ability.ANTI_HUNGER))
return;
if (!event.isCancelled()) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (blockAbility(player))
return;
// Checks if food level would be decreased
if (player.getFoodLevel() > event.getFoodLevel()) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
double chance = getValue(Ability.ANTI_HUNGER, playerData) / 100;
if (r.nextDouble() < chance) {
event.setFoodLevel(player.getFoodLevel());
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class Luck method onBlockBreak.
@EventHandler(priority = EventPriority.HIGHEST)
@SuppressWarnings("deprecation")
public void onBlockBreak(BlockBreakEvent event) {
if (OptionL.getBoolean(Option.LUCK_DOUBLE_DROP_ENABLED) && !event.isCancelled()) {
Player player = event.getPlayer();
Block block = event.getBlock();
// Checks if in blocked or disabled world
if (plugin.getWorldManager().isInBlockedWorld(block.getLocation())) {
return;
}
// Checks if in blocked region
if (plugin.isWorldGuardEnabled()) {
if (plugin.getWorldGuardSupport().isInBlockedRegion(block.getLocation())) {
return;
} else // Check if blocked by flags
if (plugin.getWorldGuardSupport().blockedByFlag(block.getLocation(), player, WorldGuardFlags.FlagKey.XP_GAIN)) {
return;
}
}
if (!event.isDropItems()) {
return;
}
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
if (plugin.getRegionManager().isPlacedBlock(block))
return;
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
Material mat = block.getType();
if (mat.equals(Material.STONE) || mat.equals(Material.COBBLESTONE) || mat.equals(Material.SAND) || mat.equals(Material.GRAVEL) || mat.equals(Material.DIRT) || mat.equals(XMaterial.GRASS_BLOCK.parseMaterial()) || mat.equals(XMaterial.ANDESITE.parseMaterial()) || mat.equals(XMaterial.DIORITE.parseMaterial()) || mat.equals(XMaterial.GRANITE.parseMaterial())) {
// Calculate chance
double chance = playerData.getStatLevel(Stats.LUCK) * OptionL.getDouble(Option.LUCK_DOUBLE_DROP_MODIFIER);
if (chance * 100 > OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX)) {
chance = OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX);
}
if (r.nextDouble() < chance) {
ItemStack tool = player.getInventory().getItemInMainHand();
for (ItemStack item : block.getDrops(tool)) {
// If silk touch
if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
if (mat.equals(Material.STONE)) {
if (!XMaterial.isNewVersion()) {
if (block.getData() == 0) {
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(Material.STONE), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
}
}
} else {
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(Material.STONE), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
}
}
} else if (mat.equals(XMaterial.GRASS_BLOCK.parseMaterial())) {
Material grassBlock = XMaterial.GRASS_BLOCK.parseMaterial();
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(grassBlock), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
}
}
} else // Drop regular item if not silk touch
{
PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
Bukkit.getPluginManager().callEvent(dropEvent);
if (!event.isCancelled()) {
block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
}
}
}
}
}
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class Luck method setLuck.
private void setLuck(Player player) {
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_LUCK);
if (attribute != null) {
boolean hasModifier = false;
// Removes existing modifiers of the same name
for (AttributeModifier am : attribute.getModifiers()) {
if (am.getName().equals("AureliumSkills-Luck")) {
attribute.removeModifier(am);
hasModifier = true;
}
}
if (!hasModifier) {
attribute.setBaseValue(0.0);
}
if (plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
return;
}
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
double luck = playerData.getStatLevel(Stats.LUCK) * OptionL.getDouble(Option.LUCK_MODIFIER);
attribute.addModifier(new AttributeModifier("AureliumSkills-Luck", luck, AttributeModifier.Operation.ADD_NUMBER));
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class Regeneration method startSaturationRegen.
public void startSaturationRegen() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
if (OptionL.getBoolean(Option.REGENERATION_CUSTOM_REGEN_MECHANICS)) {
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
// Check for disabled world
if (!plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
if (!player.isDead()) {
if (player.getSaturation() > 0 && player.getFoodLevel() >= 20) {
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attribute != null) {
double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_SATURATED_MODIFIER), attribute.getValue() - player.getHealth());
CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.SATURATED);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
player.setHealth(player.getHealth() + amountGained);
}
}
}
}
}
}
}
}
}, 0L, OptionL.getInt(Option.REGENERATION_SATURATED_DELAY));
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class FarmingAbilities method bountifulHarvest.
public void bountifulHarvest(Player player, Block block) {
if (OptionL.isEnabled(Skills.FARMING)) {
if (plugin.getAbilityManager().isEnabled(Ability.BOUNTIFUL_HARVEST)) {
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
if (playerData.getAbilityLevel(Ability.BOUNTIFUL_HARVEST) > 0) {
if (r.nextDouble() < (getValue(Ability.BOUNTIFUL_HARVEST, playerData)) / 100) {
for (ItemStack item : block.getDrops()) {
checkMelonSilkTouch(player, block, item);
PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.BOUNTIFUL_HARVEST);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
block.getWorld().dropItem(event.getLocation(), event.getItemStack());
}
}
}
}
}
}
}
}
Aggregations