Added the option for multiple triggers on the same effect.

This commit is contained in:
GB6 2019-03-26 16:12:16 +01:00
parent af685677c6
commit 6f34341b57
22 changed files with 126 additions and 84 deletions

View File

@ -13,6 +13,7 @@ import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import static com.songoda.epicenchants.effect.EffectExecutor.Who.OPPONENT; import static com.songoda.epicenchants.effect.EffectExecutor.Who.OPPONENT;
@ -20,21 +21,21 @@ import static com.songoda.epicenchants.effect.EffectExecutor.Who.USER;
public abstract class EffectExecutor { public abstract class EffectExecutor {
@Getter private final ConfigurationSection section; @Getter private final ConfigurationSection section;
@Getter private final TriggerType triggerType; @Getter private final Set<TriggerType> triggerTypes;
private final Condition condition; private final Condition condition;
public EffectExecutor(ConfigurationSection section) { public EffectExecutor(ConfigurationSection section) {
this.section = section; this.section = section;
this.triggerType = TriggerType.valueOf(section.getString("trigger")); this.triggerTypes = GeneralUtils.parseTrigger(section.getString("trigger"));
this.condition = Condition.of(section.getString("condition")); this.condition = Condition.of(section.getString("condition"));
} }
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType) { public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType) {
if (type != triggerType) { if (triggerTypes.contains(type)) {
return; return;
} }
if (section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(section.getString("chance")).get(level, 100))) { if (section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(section.getString("chance")).get(level, 100, user, opponent))) {
return; return;
} }
@ -65,7 +66,7 @@ public abstract class EffectExecutor {
} }
public void consume(Consumer<LivingEntity> playerConsumer, Player user, @Nullable LivingEntity opponent) { public void consume(Consumer<LivingEntity> playerConsumer, Player user, @Nullable LivingEntity opponent) {
if (triggerType == TriggerType.HELD_ITEM || triggerType == TriggerType.STATIC_EFFECT) { if (triggerTypes.contains(TriggerType.HELD_ITEM) || triggerTypes.contains(TriggerType.STATIC_EFFECT)) {
playerConsumer.accept(user); playerConsumer.accept(user);
return; return;
} }

View File

@ -16,6 +16,6 @@ public class Burn extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
consume(entity -> entity.setFireTicks((int) LeveledModifier.of(getSection().getString("time")).get(level, 20)), user, opponent); consume(entity -> entity.setFireTicks((int) LeveledModifier.of(getSection().getString("time")).get(level, 20, user, opponent)), user, opponent);
} }
} }

View File

@ -2,6 +2,7 @@ package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor; import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.managers.HookManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -15,9 +16,7 @@ public class ConsoleCommand extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getSection().getString("command") Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
.replace("{level}", "" + level) HookManager.setPAPIPlaceholders(getSection().getString("command"), user, opponent, level));
.replace("{user}", user.getName())
.replace("{opponent}", opponent == null ? "" : opponent.getName()));
} }
} }

View File

@ -2,6 +2,7 @@ package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor; import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.managers.HookManager;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,9 +18,6 @@ public class Message extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
if (eventType == EventType.ON || eventType == EventType.NONE) if (eventType == EventType.ON || eventType == EventType.NONE)
consume(entity -> entity.sendMessage(color(getSection().getString("message")) consume(entity -> entity.sendMessage(color(HookManager.setPAPIPlaceholders(getSection().getString("message"), user, opponent, level))), user, opponent);
.replace("{level}", "" + level)
.replace("{user}", user.getName())
.replace("{opponent}", opponent == null ? "" : opponent.getName())), user, opponent);
} }
} }

View File

@ -20,6 +20,6 @@ public class ModifyDamage extends EffectEventExecutor {
return; return;
} }
((EntityDamageEvent) event).setDamage(LeveledModifier.of(getSection().getString("modifier")).get(level, 1)); ((EntityDamageEvent) event).setDamage(LeveledModifier.of(getSection().getString("modifier")).get(level, 1, user, opponent));
} }
} }

View File

@ -21,9 +21,9 @@ public class ModifyExp extends EffectExecutor {
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player) entity; Player player = (Player) entity;
if (getSection().getString("amount").endsWith("L")) { if (getSection().getString("amount").endsWith("L")) {
player.setLevel((int) (player.getLevel() + LeveledModifier.of(getSection().getString("amount").replace("L", "")).get(level, 0))); player.setLevel((int) (player.getLevel() + LeveledModifier.of(getSection().getString("amount").replace("L", "")).get(level, 0, user, opponent)));
} else { } else {
Experience.changeExp(player, (int) getAmount().get(level, 0)); Experience.changeExp(player, (int) getAmount().get(level, 0, user, opponent));
} }
} }
}, user, opponent); }, user, opponent);

View File

@ -17,7 +17,7 @@ public class ModifyFood extends EffectExecutor {
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
consume(entity -> { consume(entity -> {
if (entity instanceof Player) { if (entity instanceof Player) {
((Player) entity).setFoodLevel((int) (((Player) entity).getFoodLevel() + getAmount().get(level, 0))); ((Player) entity).setFoodLevel((int) (((Player) entity).getFoodLevel() + getAmount().get(level, 0, user, opponent)));
} }
}, user, opponent); }, user, opponent);
} }

View File

@ -16,7 +16,7 @@ public class ModifyHealth extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
consume(entity -> { consume(entity -> {
double amount = getAmount().get(level, 0); double amount = getAmount().get(level, 0, user, opponent);
if (entity.getHealth() + amount > entity.getMaxHealth()) { if (entity.getHealth() + amount > entity.getMaxHealth()) {
entity.setHealth(entity.getMaxHealth()); entity.setHealth(entity.getMaxHealth());
} else if (entity.getHealth() + amount < 0) { } else if (entity.getHealth() + amount < 0) {

View File

@ -0,0 +1,28 @@
package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectEventExecutor;
import com.songoda.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
public class ModifyOxygen extends EffectEventExecutor {
public ModifyOxygen(ConfigurationSection section) {
super(section);
}
@Override
public void execute(Player user, LivingEntity opponent, int level, Event event, EventType eventType) {
consume(entity -> {
double amount = getAmount().get(level, 0, user, opponent);
if (entity.getRemainingAir() + amount > entity.getMaximumAir()) {
entity.setRemainingAir(entity.getMaximumAir());
} else if (entity.getRemainingAir() + amount < 0) {
entity.setRemainingAir(0);
} else {
entity.setRemainingAir(entity.getRemainingAir() + (int) amount);
}
}, user, opponent);
}
}

View File

@ -19,7 +19,7 @@ public class MoreDrops extends EffectEventExecutor {
} }
@Override @Override
public void execute(Player player, LivingEntity opponent, int level, Event event, EventType type) { public void execute(Player user, LivingEntity opponent, int level, Event event, EventType type) {
if (!(event instanceof EntityDeathEvent)) { if (!(event instanceof EntityDeathEvent)) {
return; return;
} }
@ -27,7 +27,7 @@ public class MoreDrops extends EffectEventExecutor {
EntityDeathEvent deathEvent = (EntityDeathEvent) event; EntityDeathEvent deathEvent = (EntityDeathEvent) event;
LeveledModifier modifier = getAmount(); LeveledModifier modifier = getAmount();
List<ItemStack> newDrops = deathEvent.getDrops().stream() List<ItemStack> newDrops = deathEvent.getDrops().stream()
.peek(itemStack -> itemStack.setAmount(((int) (itemStack.getAmount() * modifier.get(level, 1))))) .peek(itemStack -> itemStack.setAmount(((int) (itemStack.getAmount() * modifier.get(level, 1, user, opponent)))))
.collect(Collectors.toList()); .collect(Collectors.toList());
deathEvent.getDrops().clear(); deathEvent.getDrops().clear();

View File

@ -2,6 +2,7 @@ package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor; import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.managers.HookManager;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,16 +19,15 @@ public class PlayerCommand extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
if (eventType == ON || eventType == NONE) { if (eventType != ON && eventType != NONE) {
return;
}
if (who() == OPPONENT && !(opponent instanceof Player)) { if (who() == OPPONENT && !(opponent instanceof Player)) {
return; return;
} }
consume(entity -> ((Player) entity).performCommand(getSection().getString("command") consume(entity -> ((Player) entity).performCommand(HookManager.setPAPIPlaceholders(getSection().getString("command"), user, opponent, level)), user, opponent);
.replace("{level}", "" + level)
.replace("{user}", user.getName())
.replace("{opponent}", opponent.getName())), user, opponent);
}
} }
} }

View File

@ -29,9 +29,9 @@ public class Potion extends EffectExecutor {
return; return;
} }
if (this.getTriggerType() == TriggerType.STATIC_EFFECT || this.getTriggerType() == TriggerType.HELD_ITEM) { if (this.getTriggerTypes() == TriggerType.STATIC_EFFECT || this.getTriggerTypes() == TriggerType.HELD_ITEM) {
if (eventType == EventType.ON) { if (eventType == EventType.ON) {
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, ((int) amplifier.get(level, 0)), consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, (int) amplifier.get(level - 1, 0, user, opponent),
false, false)), user, opponent); false, false)), user, opponent);
} else if (eventType == EventType.OFF) { } else if (eventType == EventType.OFF) {
consume(entity -> entity.removePotionEffect(effectType), user, opponent); consume(entity -> entity.removePotionEffect(effectType), user, opponent);
@ -41,8 +41,8 @@ public class Potion extends EffectExecutor {
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration")); LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, ((int) duration.get(level, 60)), consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, ((int) duration.get(level, 60, user, opponent)),
((int) amplifier.get(level, 0)), false, false)), user, opponent); ((int) amplifier.get(level - 1, 0, user, opponent)), false, false)), user, opponent);
} }
} }

View File

@ -17,20 +17,20 @@ public class StealExp extends EffectExecutor {
} }
@Override @Override
public void execute(@NotNull Player user, @Nullable LivingEntity entity, int level, EventType eventType) { public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
double amount = getAmount().get(level, 0); double amount = getAmount().get(level, 0, user, opponent);
if (!(entity instanceof Player)) { if (!(opponent instanceof Player)) {
return; return;
} }
Player opponent = (Player) entity; Player player = (Player) opponent;
if (getExp(opponent) - amount <= 0) { if (getExp(player) - amount <= 0) {
changeExp(opponent, 0); changeExp(player, 0);
} else { } else {
changeExp(opponent, (int) -amount); changeExp(player, (int) -amount);
} }
if (getExp(user) + amount <= 0) { if (getExp(user) + amount <= 0) {

View File

@ -14,7 +14,7 @@ public class StealHealth extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
double amount = getAmount().get(level, 0); double amount = getAmount().get(level, 0, user, opponent);
if (opponent == null) { if (opponent == null) {
return; return;

View File

@ -27,7 +27,7 @@ public class Throw extends EffectExecutor {
} }
Vector vector; Vector vector;
double magnitude = LeveledModifier.of(getSection().getString("magnitude")).get(level, 0.1); double magnitude = LeveledModifier.of(getSection().getString("magnitude")).get(level, 0.1, user, opponent);
LivingEntity livingEntity = who() == USER ? user : opponent; LivingEntity livingEntity = who() == USER ? user : opponent;
LivingEntity relative = getSection().getString("relative-to").equalsIgnoreCase("opponent") ? opponent : user; LivingEntity relative = getSection().getString("relative-to").equalsIgnoreCase("opponent") ? opponent : user;

View File

@ -18,9 +18,9 @@ public class Tnt extends EffectExecutor {
@Override @Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
consume(player -> { consume(player -> {
for (int i = 0; i < LeveledModifier.of(getSection().getString("amount")).get(level, 1); i++) { for (int i = 0; i < LeveledModifier.of(getSection().getString("amount")).get(level, 1, user, opponent); i++) {
TNTPrimed tntPrimed = (TNTPrimed) player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT); TNTPrimed tntPrimed = (TNTPrimed) player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT);
tntPrimed.setFuseTicks((int) LeveledModifier.of(getSection().getString("fuse")).get(level, 60)); tntPrimed.setFuseTicks((int) LeveledModifier.of(getSection().getString("fuse")).get(level, 60, user, opponent));
} }
}, user, opponent); }, user, opponent);
} }

View File

@ -1,9 +1,14 @@
package com.songoda.epicenchants.managers; package com.songoda.epicenchants.managers;
import com.songoda.epicenchants.objects.Placeholder;
import com.songoda.ultimatebottles.UltimateBottles; import com.songoda.ultimatebottles.UltimateBottles;
import lombok.Getter; import lombok.Getter;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@Getter @Getter
@ -17,4 +22,32 @@ public class HookManager {
public Optional<UltimateBottles> getUltimateBottles() { public Optional<UltimateBottles> getUltimateBottles() {
return Optional.ofNullable(ultimateBottles); return Optional.ofNullable(ultimateBottles);
} }
public static String setPAPIPlaceholders(String input, Player user, LivingEntity opponent, int level) {
for (Placeholder pair : Arrays.asList(
Placeholder.of("level", level),
Placeholder.of("user_health", user.getHealth()),
Placeholder.of("attacker_health", opponent == null ? -1 : opponent.getHealth()),
Placeholder.of("user_food", user.getFoodLevel()),
Placeholder.of("attacker_food", opponent instanceof Player ? ((Player) opponent).getFoodLevel() : 0),
Placeholder.of("user_is_sneaking", user.isSneaking()),
Placeholder.of("attacker_is_sneaking", opponent instanceof Player && ((Player) opponent).isSneaking()),
Placeholder.of("world", user.getWorld().getName()),
Placeholder.of("players_near", user.getNearbyEntities(4, 4, 4).size()),
Placeholder.of("user_on_fire", user.getFireTicks() != 0),
Placeholder.of("attacker_on_fire", opponent != null && opponent.getFireTicks() != 0)
)) {
input = input.replace(pair.getPlaceholder(), pair.getToReplace().toString());
}
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
input = PlaceholderAPI.setPlaceholders(user, input);
if (opponent instanceof Player) {
input = PlaceholderAPI.setRelationalPlaceholders(user, (Player) opponent, input);
}
}
return input;
}
} }

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.objects; package com.songoda.epicenchants.objects;
import me.clip.placeholderapi.PlaceholderAPI; import com.songoda.epicenchants.managers.HookManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import java.util.Arrays;
public class Condition { public class Condition {
private final String string; private final String string;
@ -29,33 +28,7 @@ public class Condition {
} }
ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript"); ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
String toValidate = string; String toValidate = ChatColor.stripColor(HookManager.setPAPIPlaceholders(string, user, attacker, level));
for (Placeholder pair : Arrays.asList(
Placeholder.of("level", level),
Placeholder.of("user_health", user.getHealth()),
Placeholder.of("attacker_health", attacker == null ? -1 : attacker.getHealth()),
Placeholder.of("user_food", user.getFoodLevel()),
Placeholder.of("attacker_food", attacker instanceof Player ? ((Player) attacker).getFoodLevel() : 0),
Placeholder.of("user_is_sneaking", user.isSneaking()),
Placeholder.of("attacker_is_sneaking", attacker instanceof Player && ((Player) attacker).isSneaking()),
Placeholder.of("world", user.getWorld().getName()),
Placeholder.of("players_near", user.getNearbyEntities(4, 4, 4).size()),
Placeholder.of("user_on_fire", user.getFireTicks() != 0),
Placeholder.of("attacker_on_fire", attacker != null && attacker.getFireTicks() != 0)
)) {
toValidate = toValidate.replace(pair.getPlaceholder(), pair.getToReplace().toString());
}
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
toValidate = PlaceholderAPI.setPlaceholders(user, toValidate);
if (attacker instanceof Player) {
toValidate = PlaceholderAPI.setRelationalPlaceholders(user, (Player) attacker, toValidate);
}
}
toValidate = ChatColor.stripColor(toValidate);
try { try {
return Boolean.parseBoolean(scriptEngine.eval(toValidate).toString()); return Boolean.parseBoolean(scriptEngine.eval(toValidate).toString());

View File

@ -1,6 +1,9 @@
package com.songoda.epicenchants.objects; package com.songoda.epicenchants.objects;
import com.songoda.epicenchants.managers.HookManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
@ -17,7 +20,7 @@ public class LeveledModifier {
return new LeveledModifier(string); return new LeveledModifier(string);
} }
public double get(int level, double def) { public double get(int level, double def, Player user, LivingEntity opponent) {
if (string == null || string.isEmpty()) { if (string == null || string.isEmpty()) {
return def; return def;
} }
@ -27,8 +30,7 @@ public class LeveledModifier {
} }
ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript"); ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
String toTest = HookManager.setPAPIPlaceholders(string, user, opponent, level);
String toTest = string.replace("{level}", "" + level);
try { try {
return Double.parseDouble(scriptEngine.eval(toTest).toString()); return Double.parseDouble(scriptEngine.eval(toTest).toString());

View File

@ -1,6 +1,7 @@
package com.songoda.epicenchants.utils.single; package com.songoda.epicenchants.utils.single;
import com.songoda.epicenchants.enums.EnchantResult; import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.enums.TriggerType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -49,4 +50,8 @@ public class GeneralUtils {
public static List<Integer> getSlotsList(String string) { public static List<Integer> getSlotsList(String string) {
return Arrays.stream(string.split(",")).filter(StringUtils::isNumeric).mapToInt(Integer::parseInt).boxed().collect(Collectors.toList()); return Arrays.stream(string.split(",")).filter(StringUtils::isNumeric).mapToInt(Integer::parseInt).boxed().collect(Collectors.toList());
} }
public static Set<TriggerType> parseTrigger(String triggers) {
return Arrays.stream(triggers.replaceAll("\\s+", "").split(",")).map(TriggerType::valueOf).collect(Collectors.toSet());
}
} }

View File

@ -10,7 +10,7 @@ public class EnchantmentWrapper {
private Enchantment enchantment; private Enchantment enchantment;
public int getAmplifier(int level) { public int getAmplifier(int level) {
return (int) amplifier.get(level, 0); return (int) amplifier.get(level, 0, user, opponent);
} }
public Enchantment getEnchantment() { public Enchantment getEnchantment() {

View File

@ -4,7 +4,10 @@ import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.LeveledModifier; import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.utils.objects.ItemBuilder; import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.single.GeneralUtils; import com.songoda.epicenchants.utils.single.GeneralUtils;
import de.tr7zw.itemnbtapi.*; import de.tr7zw.itemnbtapi.NBTEntity;
import de.tr7zw.itemnbtapi.NBTList;
import de.tr7zw.itemnbtapi.NBTListCompound;
import de.tr7zw.itemnbtapi.NBTType;
import lombok.Builder; import lombok.Builder;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.*; import org.bukkit.entity.*;
@ -31,13 +34,13 @@ public class MobWrapper {
return; return;
} }
if (!GeneralUtils.chance(spawnPercentage.get(level, 100))) { if (!GeneralUtils.chance(spawnPercentage.get(level, 100, user, opponent))) {
return; return;
} }
Location location = player.getLocation(); Location location = player.getLocation();
for (int i = 0; i < current().nextInt((int) (maxAmount.get(level, 1) + 1)); i++) { for (int i = 0; i < current().nextInt((int) (maxAmount.get(level, 1, user, opponent) + 1)); i++) {
Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3)); Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3));
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY(); int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
@ -52,7 +55,7 @@ public class MobWrapper {
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity; LivingEntity livingEntity = (LivingEntity) entity;
int dropChance = (int) equipmentDropChance.get(level, 0); int dropChance = (int) equipmentDropChance.get(level, 0, user, opponent);
if (helmet != null) livingEntity.getEquipment().setHelmet(helmet.buildWithWrappers(level)); if (helmet != null) livingEntity.getEquipment().setHelmet(helmet.buildWithWrappers(level));
if (chestPlate != null) livingEntity.getEquipment().setChestplate(chestPlate.buildWithWrappers(level)); if (chestPlate != null) livingEntity.getEquipment().setChestplate(chestPlate.buildWithWrappers(level));
@ -80,12 +83,12 @@ public class MobWrapper {
for (int j = 0; j < list.size(); j++) { for (int j = 0; j < list.size(); j++) {
NBTListCompound lc = list.getCompound(j); NBTListCompound lc = list.getCompound(j);
if (lc.getString("Name").equals("generic.attackDamage")) { if (lc.getString("Name").equals("generic.attackDamage")) {
lc.setDouble("Base", attackDamage.get(level, (int) lc.getDouble("Base"))); lc.setDouble("Base", attackDamage.get(level, (int) lc.getDouble("Base"), user, opponent));
continue; continue;
} }
if (lc.getString("Name").equals("generic.maxHealth")) { if (lc.getString("Name").equals("generic.maxHealth")) {
lc.setDouble("Base", health.get(level, (int) lc.getDouble("Base"))); lc.setDouble("Base", health.get(level, (int) lc.getDouble("Base"), user, opponent));
} }
} }
} }