Moved mobs to the effects section.

This commit is contained in:
GB6 2019-04-08 14:49:08 +02:00
parent a40b001ed0
commit 007f75d229
6 changed files with 52 additions and 52 deletions

View File

@ -50,7 +50,7 @@ public class Action {
}
public List<String> getMessage(String node, Placeholder... placeholders) {
List<String> output = config.isList(node) ? config.getStringList(node) : Collections.singletonList(config.getString(node));
List<String> 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) {

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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<String> conflict;
private Set<Material> itemWhitelist;
private Set<EffectExecutor> effectExecutors;
private Set<MobWrapper> mobs;
private List<String> 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() {

View File

@ -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] : ""))

View File

@ -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."