From 007f75d229bd1cccca002fd5db0d5308251c96ac Mon Sep 17 00:00:00 2001 From: GB6 Date: Mon, 8 Apr 2019 14:49:08 +0200 Subject: [PATCH] Moved mobs to the effects section. --- .../java/com/songoda/epicenchants/Action.java | 2 +- .../effects/SpawnMob.java} | 43 +++++++++++-------- .../listeners/item/BlackScrollListener.java | 11 ++++- .../songoda/epicenchants/objects/Enchant.java | 3 -- .../utils/single/ConfigParser.java | 37 ++++------------ core/src/main/resources/actions.yml | 8 ++++ 6 files changed, 52 insertions(+), 52 deletions(-) rename core/src/main/java/com/songoda/epicenchants/{wrappers/MobWrapper.java => effect/effects/SpawnMob.java} (65%) diff --git a/core/src/main/java/com/songoda/epicenchants/Action.java b/core/src/main/java/com/songoda/epicenchants/Action.java index 7bc4f65..75fccd8 100644 --- a/core/src/main/java/com/songoda/epicenchants/Action.java +++ b/core/src/main/java/com/songoda/epicenchants/Action.java @@ -50,7 +50,7 @@ public class Action { } public List getMessage(String node, Placeholder... placeholders) { - List output = config.isList(node) ? config.getStringList(node) : Collections.singletonList(config.getString(node)); + List output = config.isList(node) ? config.getStringList(node) : config.getString(node).isEmpty() ? Collections.emptyList() : Collections.singletonList(config.getString(node)); return output.stream().map(s -> { for (Placeholder placeholder : placeholders) { diff --git a/core/src/main/java/com/songoda/epicenchants/wrappers/MobWrapper.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java similarity index 65% rename from core/src/main/java/com/songoda/epicenchants/wrappers/MobWrapper.java rename to core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java index deef2f3..b4203d4 100644 --- a/core/src/main/java/com/songoda/epicenchants/wrappers/MobWrapper.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java @@ -1,43 +1,52 @@ -package com.songoda.epicenchants.wrappers; +package com.songoda.epicenchants.effect.effects; -import com.songoda.epicenchants.enums.TriggerType; +import com.songoda.epicenchants.effect.EffectExecutor; +import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.objects.LeveledModifier; import com.songoda.epicenchants.utils.objects.ItemBuilder; -import com.songoda.epicenchants.utils.single.GeneralUtils; 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.configuration.ConfigurationSection; import org.bukkit.entity.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static com.songoda.epicenchants.objects.LeveledModifier.of; +import static com.songoda.epicenchants.utils.single.GeneralUtils.color; import static java.util.concurrent.ThreadLocalRandom.current; -@Builder -public class MobWrapper { +public class SpawnMob extends EffectExecutor { + private LeveledModifier attackDamage; private String displayName; private EntityType entityType; - private LeveledModifier attackDamage; - private TriggerType triggerType; private LeveledModifier equipmentDropChance; - private LeveledModifier spawnPercentage; private LeveledModifier health; private ItemBuilder helmet, chestPlate, leggings, boots, handItem; private boolean hostile; private LeveledModifier maxAmount; - public void trySpawn(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType triggerType) { - if (this.triggerType != triggerType) { - return; - } + public SpawnMob(ConfigurationSection section) { + super(section); - if (!GeneralUtils.chance(spawnPercentage.get(level, 100, user, opponent))) { - return; - } + entityType = EntityType.valueOf(section.getName()); + maxAmount = of(section.getString("max-amount")); + health = of(section.getString("health")); + attackDamage = of(section.getString("attack-damage")); + equipmentDropChance = LeveledModifier.of(section.getString("equipment-drop-chance")); + hostile = section.getBoolean("hostile", false); + displayName = section.isString("display-name") ? color(section.getString("display-name")) : ""; + helmet = section.isConfigurationSection("equipment.helmet") ? new ItemBuilder(section.getConfigurationSection("equipment.helmet")) : null; + chestPlate = section.isConfigurationSection("equipment.chestplate") ? new ItemBuilder(section.getConfigurationSection("equipment.chestplate")) : null; + leggings = section.isConfigurationSection("equipment.leggings") ? new ItemBuilder(section.getConfigurationSection("equipment.leggings")) : null; + boots = section.isConfigurationSection("equipment.boots") ? new ItemBuilder(section.getConfigurationSection("equipment.boots")) : null; + handItem = section.isConfigurationSection("equipment.hand-item") ? new ItemBuilder(section.getConfigurationSection("equipment.hand-item")) : null; + } + @Override + public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) { Location location = user.getLocation(); for (int i = 0; i < current().nextInt((int) (maxAmount.get(level, 1, user, opponent) + 1)); i++) { @@ -74,7 +83,7 @@ public class MobWrapper { livingEntity.getEquipment().setItemInHandDropChance(dropChance); } - if (entity instanceof Monster && opponent != null) { + if (hostile && entity instanceof Monster && opponent != null) { ((Monster) entity).setTarget(opponent); } diff --git a/core/src/main/java/com/songoda/epicenchants/listeners/item/BlackScrollListener.java b/core/src/main/java/com/songoda/epicenchants/listeners/item/BlackScrollListener.java index 671dcce..6d7f9d1 100644 --- a/core/src/main/java/com/songoda/epicenchants/listeners/item/BlackScrollListener.java +++ b/core/src/main/java/com/songoda/epicenchants/listeners/item/BlackScrollListener.java @@ -2,11 +2,13 @@ package com.songoda.epicenchants.listeners.item; import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.objects.Enchant; +import com.songoda.epicenchants.utils.single.RomanNumber; import de.tr7zw.itemnbtapi.NBTCompound; import de.tr7zw.itemnbtapi.NBTItem; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import static com.songoda.epicenchants.objects.Placeholder.of; import static com.songoda.epicenchants.utils.single.GeneralUtils.getRandomElement; public class BlackScrollListener extends ItemListener { @@ -24,7 +26,7 @@ public class BlackScrollListener extends ItemListener { NBTCompound compound = current.getCompound("enchants"); if (compound == null || compound.getKeys().isEmpty()) { - instance.getAction().perform(event.getWhoClicked(), "blackscroll.noenchants"); + instance.getAction().perform(event.getWhoClicked(), "black-scroll.no-enchants"); return; } @@ -36,7 +38,12 @@ public class BlackScrollListener extends ItemListener { event.getWhoClicked().getInventory().addItem(enchant.getBook().get(enchant, level, cursor.getInteger("success-rate"), 100)); event.setCurrentItem(toSet); - instance.getAction().perform(event.getWhoClicked(), "blackscroll.success"); + instance.getAction().perform(event.getWhoClicked(), "black-scroll.success", + of("enchant", enchant.getIdentifier()), + of("group_color", enchant.getGroup().getColor()), + of("group_name", enchant.getGroup().getName()), + of("level", RomanNumber.toRoman(level))); + useItem(event); } } diff --git a/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java b/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java index 9b17dc1..d7638df 100644 --- a/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java +++ b/core/src/main/java/com/songoda/epicenchants/objects/Enchant.java @@ -4,7 +4,6 @@ import com.songoda.epicenchants.effect.EffectExecutor; import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.enums.TriggerType; import com.songoda.epicenchants.utils.single.RomanNumber; -import com.songoda.epicenchants.wrappers.MobWrapper; import lombok.Builder; import lombok.Getter; import org.bukkit.Material; @@ -28,14 +27,12 @@ public class Enchant { private Set conflict; private Set itemWhitelist; private Set effectExecutors; - private Set mobs; private List description; private String format; @Nullable private BookItem bookItem; public void onAction(@NotNull Player user, @Nullable LivingEntity opponent, Event event, int level, TriggerType triggerType, EventType eventType) { effectExecutors.forEach(effect -> effect.testAndRun(user, opponent, level, triggerType, event, eventType)); - mobs.forEach(mobWrapper -> mobWrapper.trySpawn(user, opponent, level, triggerType)); } public BookItem getBook() { diff --git a/core/src/main/java/com/songoda/epicenchants/utils/single/ConfigParser.java b/core/src/main/java/com/songoda/epicenchants/utils/single/ConfigParser.java index aa8231c..ac2ee98 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/single/ConfigParser.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/single/ConfigParser.java @@ -2,18 +2,20 @@ package com.songoda.epicenchants.utils.single; import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.effect.EffectManager; -import com.songoda.epicenchants.enums.TriggerType; -import com.songoda.epicenchants.objects.*; -import com.songoda.epicenchants.utils.objects.ItemBuilder; +import com.songoda.epicenchants.objects.BookItem; +import com.songoda.epicenchants.objects.Enchant; +import com.songoda.epicenchants.objects.Group; +import com.songoda.epicenchants.objects.LeveledModifier; import com.songoda.epicenchants.wrappers.EnchantmentWrapper; -import com.songoda.epicenchants.wrappers.MobWrapper; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Optional; import java.util.stream.Collectors; import static com.songoda.epicenchants.utils.single.GeneralUtils.color; @@ -28,10 +30,6 @@ public class ConfigParser { .bookItem(parseBookItem(instance, config.getConfigurationSection("book-item"))) .itemWhitelist((config.isList("item-whitelist") ? config.getStringList("item-whitelist").stream().map(instance.getItemGroup()::get).flatMap(Collection::stream).collect(Collectors.toSet()) : Collections.emptySet())) .conflict(config.isList("conflicting-enchants") ? new HashSet<>(config.getStringList("conflicting-enchants")) : Collections.emptySet()) - .mobs(config.isConfigurationSection("mobs") ? config.getConfigurationSection("mobs").getKeys(false).stream() - .map(s -> "mobs." + s) - .map(config::getConfigurationSection) - .map(ConfigParser::parseMobWrapper).collect(Collectors.toSet()) : Collections.emptySet()) .effectExecutors(config.isConfigurationSection("effects") ? config.getConfigurationSection("effects").getKeys(false).stream() .map(s -> "effects." + s) .map(config::getConfigurationSection) @@ -43,25 +41,6 @@ public class ConfigParser { .build(); } - public static MobWrapper parseMobWrapper(ConfigurationSection section) { - return section != null ? MobWrapper.builder() - .triggerType(TriggerType.valueOf(section.getString("trigger"))) - .entityType(EntityType.valueOf(section.getName())) - .maxAmount(LeveledModifier.of(section.getString("max-amount"))) - .spawnPercentage(LeveledModifier.of(section.getString("spawn-percentage"))) - .health(LeveledModifier.of(section.getString("health"))) - .attackDamage(LeveledModifier.of(section.getString("attack-damage"))) - .equipmentDropChance(LeveledModifier.of(section.getString("equipment-drop-chance"))) - .hostile(section.getBoolean("hostile")) - .displayName(color(section.getString("display-name"))) - .helmet(section.isConfigurationSection("equipment.helmet") ? new ItemBuilder(section.getConfigurationSection("equipment.helmet")) : null) - .chestPlate(section.isConfigurationSection("equipment.chestplate") ? new ItemBuilder(section.getConfigurationSection("equipment.chestplate")) : null) - .leggings(section.isConfigurationSection("equipment.leggings") ? new ItemBuilder(section.getConfigurationSection("equipment.leggings")) : null) - .boots(section.isConfigurationSection("equipment.boots") ? new ItemBuilder(section.getConfigurationSection("equipment.boots")) : null) - .handItem(section.isConfigurationSection("equipment.hand-item") ? new ItemBuilder(section.getConfigurationSection("equipment.hand-item")) : null) - .build() : null; - } - public static EnchantmentWrapper parseEnchantmentWrapper(String key) { return EnchantmentWrapper.builder() .amplifier(LeveledModifier.of(key.contains(":") ? key.split(":")[1] : "")) diff --git a/core/src/main/resources/actions.yml b/core/src/main/resources/actions.yml index 7a968b9..5af110b 100644 --- a/core/src/main/resources/actions.yml +++ b/core/src/main/resources/actions.yml @@ -13,6 +13,14 @@ command: reload: "&6Configuration files reload" +black-scroll: + success: "&aSuccessfully blackscrolled: {group_color}{enchant} {level}&a." + no-enchants: "&cNo enchants to blackscroll." + +white-scroll: + already-applied: "&cThis item is already protected!" + applied: "&aThis item is now protected!" + enchanter: cannot-afford: "&c&l(!) &r&cYou cannot afford this purchase." success: "&7Purchased {group_color}{group_name} &7book for &f{exp_cost} EXP&7."