9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-19 15:09:26 +00:00

Added warp chance effect

This commit is contained in:
Auxilor
2021-01-15 10:26:06 +00:00
parent 64ac868b15
commit 0fdbfc5dd4
2 changed files with 60 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
import com.willfp.ecoarmor.effects.effects.SpeedMutiplier;
import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier;
import com.willfp.ecoarmor.effects.effects.WarpChance;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
@@ -37,6 +38,7 @@ public class Effects {
public static final Effect SPEED_MULTIPLIER = new SpeedMutiplier();
public static final Effect EXPERIENCE_MULTIPLIER = new ExperienceMultiplier();
public static final Effect REGENERATION_MULTIPLIER = new RegenerationMultiplier();
public static final Effect WARP_CHANCE = new WarpChance();
/**
* Get effect matching name.

View File

@@ -0,0 +1,58 @@
package com.willfp.ecoarmor.effects.effects;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
public class WarpChance extends Effect {
public WarpChance() {
super("warp-chance");
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
if (event.isCancelled()) {
return;
}
if (!(event.getDamager() instanceof Player)) {
return;
}
if (!(event.getEntity() instanceof LivingEntity)) {
return;
}
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
double chance = ArmorUtils.getEffectStrength(player, this);
if (NumberUtils.randFloat(0, 100) > chance) {
return;
}
Vector between = victim.getLocation().subtract(player.getLocation()).toVector();
Location behind = victim.getLocation().add(between);
behind.setYaw(player.getLocation().getYaw() + 180);
Block head = behind.add(0, 1.4, 0).getBlock();
if (!head.getType().isAir()) {
return;
}
player.getLocation().setYaw(player.getLocation().getYaw() + 180);
player.teleport(behind);
}
}