mirror of
https://github.com/Auxilor/Reforges.git
synced 2025-12-24 17:39:32 +00:00
Added reward_kill effect
This commit is contained in:
@@ -5,6 +5,7 @@ import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.reforges.effects.effects.EffectCritMultiplier;
|
||||
import com.willfp.reforges.effects.effects.EffectDamageMultiplier;
|
||||
import com.willfp.reforges.effects.effects.EffectRewardKill;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -21,6 +22,7 @@ public class Effects {
|
||||
|
||||
public static final Effect DAMAGE_MULTIPLIER = new EffectDamageMultiplier();
|
||||
public static final Effect CRIT_MULTIPLIER = new EffectCritMultiplier();
|
||||
public static final Effect REWARD_KILL = new EffectRewardKill();
|
||||
|
||||
/**
|
||||
* Get effect matching name.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.willfp.reforges.effects.effects;
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.events.EntityDeathByEntityEvent;
|
||||
import com.willfp.reforges.effects.Effect;
|
||||
import com.willfp.reforges.vault.EconomyHandler;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EffectRewardKill extends Effect {
|
||||
/**
|
||||
* Create a new effect.
|
||||
*/
|
||||
public EffectRewardKill() {
|
||||
super("reward_kill");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKill(@NotNull final LivingEntity killer,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final EntityDeathByEntityEvent event,
|
||||
@NotNull final JSONConfig config) {
|
||||
if (!(killer instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EconomyHandler.getInstance().depositPlayer(player, config.getDouble("amount"));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.willfp.reforges.reforges.util;
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.events.EntityDeathByEntityEvent;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@@ -167,6 +168,21 @@ public interface Watcher {
|
||||
// Empty default as effects only override required watchers.
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity kills another entity.
|
||||
*
|
||||
* @param killer The killer.
|
||||
* @param victim The victim.
|
||||
* @param event The event.
|
||||
* @param config The effect config.
|
||||
*/
|
||||
default void onKill(@NotNull final LivingEntity killer,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final EntityDeathByEntityEvent event,
|
||||
@NotNull final JSONConfig config) {
|
||||
// Empty default as effects only override required watchers.
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a trident hits a block or entity.
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.willfp.reforges.reforges.util;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.events.EntityDeathByEntityEvent;
|
||||
import com.willfp.eco.core.events.PlayerJumpEvent;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||
@@ -13,6 +14,7 @@ import com.willfp.reforges.reforges.Reforge;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -270,6 +272,57 @@ public class WatcherTriggers extends PluginDependent<EcoPlugin> implements Liste
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity kills another entity.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onKill(@NotNull final EntityDeathByEntityEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity killer = null;
|
||||
Entity uncast = event.getKiller();
|
||||
if (uncast instanceof LivingEntity) {
|
||||
killer = (LivingEntity) uncast;
|
||||
} else if (uncast instanceof Projectile projectile) {
|
||||
if (projectile.getShooter() instanceof LivingEntity) {
|
||||
killer = (Player) projectile.getShooter();
|
||||
}
|
||||
}
|
||||
|
||||
if (killer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = event.getVictim();
|
||||
|
||||
if (killer instanceof Player && !AntigriefManager.canInjure((Player) killer, victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityEquipment entityEquipment = killer.getEquipment();
|
||||
|
||||
if (entityEquipment == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reforge reforge = ReforgeUtils.getReforge(entityEquipment.getItemInMainHand());
|
||||
|
||||
if (reforge == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<Effect, JSONConfig> entry : reforge.getEffects().entrySet()) {
|
||||
if (NumberUtils.randFloat(0, 100) > (entry.getValue().has("chance") ? entry.getValue().getDouble("chance") : 100)) {
|
||||
continue;
|
||||
}
|
||||
entry.getKey().onKill(killer, victim, event, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity shoots a bow.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user