Added storm bow

This commit is contained in:
Auxilor
2021-07-22 16:55:52 +01:00
parent 86ffbc4445
commit ee6a6be7e4
4 changed files with 54 additions and 25 deletions

View File

@@ -49,6 +49,23 @@ public abstract class Effect {
// Override when needed.
}
/**
* Handle {@link TriggerType#PROJECTILE_HIT_ENTITY}.
*
* @param player The player.
* @param victim The victim.
* @param projectile The projectile.
* @param event The event.
* @param args The effect args.
*/
public void handleProjectileHitEntity(@NotNull final Player player,
@NotNull final LivingEntity victim,
@NotNull final Projectile projectile,
@NotNull final ProjectileHitEvent event,
@NotNull final Object args) {
// Override when needed.
}
/**
* Handle {@link TriggerType#PROJECTILE_HIT}.
*

View File

@@ -1,6 +1,5 @@
package com.willfp.ecoweapons.effects.effects;
import com.willfp.eco.util.LightningUtils;
import com.willfp.ecoweapons.effects.Effect;
import org.bukkit.World;
import org.bukkit.entity.LivingEntity;
@@ -23,10 +22,14 @@ public class EffectStrikeLightning extends Effect {
@NotNull final LivingEntity victim,
@NotNull final EntityDamageByEntityEvent event,
@NotNull final Object args) {
Map<String, Integer> argMap = (Map<String, Integer>) args;
Map<String, Double> argMap = (Map<String, Double>) args;
World world = victim.getLocation().getWorld();
assert world != null;
for (int i = 0; i < argMap.get("amount"); i++) {
LightningUtils.strike(victim, argMap.get("damage"));
this.getPlugin().getScheduler().runLater(() -> {
world.strikeLightning(victim.getLocation());
}, i);
}
}
@@ -35,12 +38,14 @@ public class EffectStrikeLightning extends Effect {
@NotNull final Projectile projectile,
@NotNull final ProjectileHitEvent event,
@NotNull final Object args) {
Map<String, Integer> argMap = (Map<String, Integer>) args;
Map<String, Double> argMap = (Map<String, Double>) args;
World world = projectile.getLocation().getWorld();
assert world != null;
for (int i = 0; i < argMap.get("amount"); i++) {
World world = projectile.getLocation().getWorld();
assert world != null;
world.strikeLightning(projectile.getLocation());
this.getPlugin().getScheduler().runLater(() -> {
world.strikeLightning(projectile.getLocation());
}, i);
}
}
}

View File

@@ -5,7 +5,6 @@ import com.willfp.ecoweapons.effects.Effect;
import com.willfp.ecoweapons.effects.TriggerType;
import com.willfp.ecoweapons.weapons.Weapon;
import com.willfp.ecoweapons.weapons.util.WeaponUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@@ -50,7 +49,7 @@ public class EffectListener implements Listener {
}
/**
* Handle {@link TriggerType#MELEE_ATTACK}.
* Handle {@link TriggerType#PROJECTILE_HIT} and {@link TriggerType#PROJECTILE_HIT_ENTITY}.
*
* @param event The event.
*/
@@ -58,8 +57,6 @@ public class EffectListener implements Listener {
ignoreCancelled = true
)
public void projectileHitListener(@NotNull final ProjectileHitEvent event) {
Bukkit.getLogger().info("Here?");
if (!(event.getEntity() instanceof Trident || event.getEntity() instanceof Arrow)) {
return;
}
@@ -72,35 +69,33 @@ public class EffectListener implements Listener {
item = ArrowUtils.getBow((Arrow) event.getEntity());
}
Bukkit.getLogger().info("2");
if (item == null) {
return;
}
Bukkit.getLogger().info("3");
if (!(event.getEntity().getShooter() instanceof Player player)) {
return;
}
Bukkit.getLogger().info("hoo");
Weapon weapon = WeaponUtils.getWeaponFromItem(item);
if (weapon == null) {
return;
}
Bukkit.getLogger().info("nayan");
if (!WeaponUtils.areConditionsMet(player, weapon)) {
return;
}
Bukkit.getLogger().info("here!");
for (Effect effect : weapon.getEffects(TriggerType.PROJECTILE_HIT)) {
effect.handleProjectileHit(player, event.getEntity(), event, weapon.getEffectStrength(effect, TriggerType.PROJECTILE_HIT));
if (event.getHitEntity() == null) {
for (Effect effect : weapon.getEffects(TriggerType.PROJECTILE_HIT)) {
effect.handleProjectileHit(player, event.getEntity(), event, weapon.getEffectStrength(effect, TriggerType.PROJECTILE_HIT));
}
} else {
if (event.getHitEntity() instanceof LivingEntity victim) {
for (Effect effect : weapon.getEffects(TriggerType.PROJECTILE_HIT)) {
effect.handleProjectileHitEntity(player, victim, event.getEntity(), event, weapon.getEffectStrength(effect, TriggerType.PROJECTILE_HIT));
}
}
}
}
}

View File

@@ -7,7 +7,6 @@
{
"id": "strike-lightning",
"args": {
"damage": 4,
"amount": 5
},
"trigger": "projectile_hit"
@@ -32,7 +31,20 @@
"level": 5
}
],
"craftable": false
"craftable": false,
"recipe": [
"redstone_block",
"glowstone_block",
"redstone_block",
"redstone_block",
"bow",
"redstone_block",
"redstone_block",
"glowstone_block",
"redstone_block"
]
}
}
]