Added Rage

This commit is contained in:
Auxilor 2020-08-29 14:24:06 +01:00
parent b85252d481
commit 8a299e54bc
4 changed files with 96 additions and 0 deletions

View File

@ -200,6 +200,7 @@ public class EcoEnchants {
public static final EcoEnchant DEFENDER = new Defender();
public static final EcoEnchant NETHERIC = new Netheric();
public static final EcoEnchant ENDERISM = new Enderism();
public static final EcoEnchant RAGE = new Rage();
/**
* Get all registered {@link EcoEnchant}s

View File

@ -0,0 +1,67 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.LocationUtils;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
public class Rage extends EcoEnchant {
public Rage() {
super(
new EcoEnchantBuilder("rage", EnchantmentType.NORMAL, Target.Applicable.BOW, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Arrow))
return;
if(!(((Arrow) event.getDamager()).getShooter() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) ((Arrow) event.getDamager()).getShooter();
LivingEntity victim = (LivingEntity) event.getEntity();
if(!AntigriefManager.canInjure(player, victim)) return;
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"))
return;
double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level");
final double distance = distancePerLevel * level;
for (Entity e : victim.getWorld().getNearbyEntities(victim.getLocation(), distance, distance, distance)) {
if(!(e instanceof Monster)) continue;
if(e instanceof PigZombie) {
((PigZombie) e).setAngry(true);
}
((Monster) e).setTarget(victim);
Vector vector = player.getLocation().toVector().clone().subtract(e.getLocation().toVector()).normalize().multiply(0.23d);
if(LocationUtils.isFinite(vector)) {
e.setVelocity(vector);
}
}
}
}

View File

@ -0,0 +1,24 @@
#
# Rage EcoEnchant
#
config-version: 4.0 # Don't edit this.
name: "Rage"
description: Chance of angering nearby monsters towards your opponent.
obtaining:
table: true
villager: true
loot: true
rarity: epic
general-config:
grindstoneable: true
conflicts: []
maximum-level: 5
config:
chance-per-level: 5
distance-per-level: 4 # Distance for mobs to check

View File

@ -219,6 +219,7 @@ permissions:
ecoenchants.fromtable.defender: true
ecoenchants.fromtable.netheric: true
ecoenchants.fromtable.enderism: true
ecoenchants.fromtable.rage: true
ecoenchants.updateannounce:
description: Informs admins of a new update
@ -748,4 +749,7 @@ permissions:
default: true
ecoenchants.fromtable.enderism:
description: Allows getting enderism from an enchanting table
default: true
ecoenchants.fromtable.rage:
description: Allows getting rage from an enchanting table
default: true