mirror of
https://github.com/songoda/EpicEnchants.git
synced 2024-11-15 23:26:01 +01:00
Added the option for multiple triggers on the same effect.
This commit is contained in:
parent
af685677c6
commit
6f34341b57
@ -13,6 +13,7 @@ import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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 {
|
||||
@Getter private final ConfigurationSection section;
|
||||
@Getter private final TriggerType triggerType;
|
||||
@Getter private final Set<TriggerType> triggerTypes;
|
||||
private final Condition condition;
|
||||
|
||||
public EffectExecutor(ConfigurationSection 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"));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ public abstract class EffectExecutor {
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ public class Burn extends EffectExecutor {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicenchants.effect.effects;
|
||||
|
||||
import com.songoda.epicenchants.effect.EffectExecutor;
|
||||
import com.songoda.epicenchants.enums.EventType;
|
||||
import com.songoda.epicenchants.managers.HookManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -15,9 +16,7 @@ public class ConsoleCommand extends EffectExecutor {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getSection().getString("command")
|
||||
.replace("{level}", "" + level)
|
||||
.replace("{user}", user.getName())
|
||||
.replace("{opponent}", opponent == null ? "" : opponent.getName()));
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
||||
HookManager.setPAPIPlaceholders(getSection().getString("command"), user, opponent, level));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicenchants.effect.effects;
|
||||
|
||||
import com.songoda.epicenchants.effect.EffectExecutor;
|
||||
import com.songoda.epicenchants.enums.EventType;
|
||||
import com.songoda.epicenchants.managers.HookManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,9 +18,6 @@ public class Message extends EffectExecutor {
|
||||
@Override
|
||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||
if (eventType == EventType.ON || eventType == EventType.NONE)
|
||||
consume(entity -> entity.sendMessage(color(getSection().getString("message"))
|
||||
.replace("{level}", "" + level)
|
||||
.replace("{user}", user.getName())
|
||||
.replace("{opponent}", opponent == null ? "" : opponent.getName())), user, opponent);
|
||||
consume(entity -> entity.sendMessage(color(HookManager.setPAPIPlaceholders(getSection().getString("message"), user, opponent, level))), user, opponent);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ public class ModifyDamage extends EffectEventExecutor {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ public class ModifyExp extends EffectExecutor {
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
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 {
|
||||
Experience.changeExp(player, (int) getAmount().get(level, 0));
|
||||
Experience.changeExp(player, (int) getAmount().get(level, 0, user, opponent));
|
||||
}
|
||||
}
|
||||
}, user, opponent);
|
||||
|
@ -17,7 +17,7 @@ public class ModifyFood extends EffectExecutor {
|
||||
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
|
||||
consume(entity -> {
|
||||
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);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class ModifyHealth extends EffectExecutor {
|
||||
@Override
|
||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||
consume(entity -> {
|
||||
double amount = getAmount().get(level, 0);
|
||||
double amount = getAmount().get(level, 0, user, opponent);
|
||||
if (entity.getHealth() + amount > entity.getMaxHealth()) {
|
||||
entity.setHealth(entity.getMaxHealth());
|
||||
} else if (entity.getHealth() + amount < 0) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ public class MoreDrops extends EffectEventExecutor {
|
||||
}
|
||||
|
||||
@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)) {
|
||||
return;
|
||||
}
|
||||
@ -27,7 +27,7 @@ public class MoreDrops extends EffectEventExecutor {
|
||||
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
|
||||
LeveledModifier modifier = getAmount();
|
||||
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());
|
||||
|
||||
deathEvent.getDrops().clear();
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicenchants.effect.effects;
|
||||
|
||||
import com.songoda.epicenchants.effect.EffectExecutor;
|
||||
import com.songoda.epicenchants.enums.EventType;
|
||||
import com.songoda.epicenchants.managers.HookManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -18,16 +19,15 @@ public class PlayerCommand extends EffectExecutor {
|
||||
|
||||
@Override
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
consume(entity -> ((Player) entity).performCommand(getSection().getString("command")
|
||||
.replace("{level}", "" + level)
|
||||
.replace("{user}", user.getName())
|
||||
.replace("{opponent}", opponent.getName())), user, opponent);
|
||||
}
|
||||
consume(entity -> ((Player) entity).performCommand(HookManager.setPAPIPlaceholders(getSection().getString("command"), user, opponent, level)), user, opponent);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ public class Potion extends EffectExecutor {
|
||||
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) {
|
||||
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);
|
||||
} else if (eventType == EventType.OFF) {
|
||||
consume(entity -> entity.removePotionEffect(effectType), user, opponent);
|
||||
@ -41,8 +41,8 @@ public class Potion extends EffectExecutor {
|
||||
|
||||
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
|
||||
|
||||
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, ((int) duration.get(level, 60)),
|
||||
((int) amplifier.get(level, 0)), false, false)), user, opponent);
|
||||
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, ((int) duration.get(level, 60, user, opponent)),
|
||||
((int) amplifier.get(level - 1, 0, user, opponent)), false, false)), user, opponent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,20 +17,20 @@ public class StealExp extends EffectExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull Player user, @Nullable LivingEntity entity, int level, EventType eventType) {
|
||||
double amount = getAmount().get(level, 0);
|
||||
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
|
||||
double amount = getAmount().get(level, 0, user, opponent);
|
||||
|
||||
if (!(entity instanceof Player)) {
|
||||
if (!(opponent instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player opponent = (Player) entity;
|
||||
Player player = (Player) opponent;
|
||||
|
||||
|
||||
if (getExp(opponent) - amount <= 0) {
|
||||
changeExp(opponent, 0);
|
||||
if (getExp(player) - amount <= 0) {
|
||||
changeExp(player, 0);
|
||||
} else {
|
||||
changeExp(opponent, (int) -amount);
|
||||
changeExp(player, (int) -amount);
|
||||
}
|
||||
|
||||
if (getExp(user) + amount <= 0) {
|
||||
|
@ -14,7 +14,7 @@ public class StealHealth extends EffectExecutor {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
return;
|
||||
|
@ -27,7 +27,7 @@ public class Throw extends EffectExecutor {
|
||||
}
|
||||
|
||||
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 relative = getSection().getString("relative-to").equalsIgnoreCase("opponent") ? opponent : user;
|
||||
|
||||
|
@ -18,9 +18,9 @@ public class Tnt extends EffectExecutor {
|
||||
@Override
|
||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||
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.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);
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
package com.songoda.epicenchants.managers;
|
||||
|
||||
import com.songoda.epicenchants.objects.Placeholder;
|
||||
import com.songoda.ultimatebottles.UltimateBottles;
|
||||
import lombok.Getter;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
@ -17,4 +22,32 @@ public class HookManager {
|
||||
public Optional<UltimateBottles> getUltimateBottles() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicenchants.objects;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import com.songoda.epicenchants.managers.HookManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Condition {
|
||||
private final String string;
|
||||
@ -29,33 +28,7 @@ public class Condition {
|
||||
}
|
||||
|
||||
ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
String toValidate = string;
|
||||
|
||||
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);
|
||||
String toValidate = ChatColor.stripColor(HookManager.setPAPIPlaceholders(string, user, attacker, level));
|
||||
|
||||
try {
|
||||
return Boolean.parseBoolean(scriptEngine.eval(toValidate).toString());
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.songoda.epicenchants.objects;
|
||||
|
||||
import com.songoda.epicenchants.managers.HookManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
@ -17,7 +20,7 @@ public class LeveledModifier {
|
||||
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()) {
|
||||
return def;
|
||||
}
|
||||
@ -27,8 +30,7 @@ public class LeveledModifier {
|
||||
}
|
||||
|
||||
ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
|
||||
String toTest = string.replace("{level}", "" + level);
|
||||
String toTest = HookManager.setPAPIPlaceholders(string, user, opponent, level);
|
||||
|
||||
try {
|
||||
return Double.parseDouble(scriptEngine.eval(toTest).toString());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicenchants.utils.single;
|
||||
|
||||
import com.songoda.epicenchants.enums.EnchantResult;
|
||||
import com.songoda.epicenchants.enums.TriggerType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@ -49,4 +50,8 @@ public class GeneralUtils {
|
||||
public static List<Integer> getSlotsList(String string) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class EnchantmentWrapper {
|
||||
private Enchantment enchantment;
|
||||
|
||||
public int getAmplifier(int level) {
|
||||
return (int) amplifier.get(level, 0);
|
||||
return (int) amplifier.get(level, 0, user, opponent);
|
||||
}
|
||||
|
||||
public Enchantment getEnchantment() {
|
||||
|
@ -4,7 +4,10 @@ import com.songoda.epicenchants.enums.TriggerType;
|
||||
import com.songoda.epicenchants.objects.LeveledModifier;
|
||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.entity.*;
|
||||
@ -31,13 +34,13 @@ public class MobWrapper {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GeneralUtils.chance(spawnPercentage.get(level, 100))) {
|
||||
if (!GeneralUtils.chance(spawnPercentage.get(level, 100, user, opponent))) {
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
|
||||
|
||||
@ -52,7 +55,7 @@ public class MobWrapper {
|
||||
|
||||
if (entity instanceof LivingEntity) {
|
||||
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 (chestPlate != null) livingEntity.getEquipment().setChestplate(chestPlate.buildWithWrappers(level));
|
||||
@ -80,12 +83,12 @@ public class MobWrapper {
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
NBTListCompound lc = list.getCompound(j);
|
||||
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;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user