mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-21 07:59:16 +00:00
Added warp chance effect
This commit is contained in:
@@ -14,6 +14,7 @@ import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier;
|
|||||||
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
|
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
|
||||||
import com.willfp.ecoarmor.effects.effects.SpeedMutiplier;
|
import com.willfp.ecoarmor.effects.effects.SpeedMutiplier;
|
||||||
import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier;
|
import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier;
|
||||||
|
import com.willfp.ecoarmor.effects.effects.WarpChance;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ public class Effects {
|
|||||||
public static final Effect SPEED_MULTIPLIER = new SpeedMutiplier();
|
public static final Effect SPEED_MULTIPLIER = new SpeedMutiplier();
|
||||||
public static final Effect EXPERIENCE_MULTIPLIER = new ExperienceMultiplier();
|
public static final Effect EXPERIENCE_MULTIPLIER = new ExperienceMultiplier();
|
||||||
public static final Effect REGENERATION_MULTIPLIER = new RegenerationMultiplier();
|
public static final Effect REGENERATION_MULTIPLIER = new RegenerationMultiplier();
|
||||||
|
public static final Effect WARP_CHANCE = new WarpChance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get effect matching name.
|
* Get effect matching name.
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user