Fixed dusts and lores.

This commit is contained in:
GB6 2019-03-21 15:55:11 +01:00
parent 79ed22a755
commit 49bfa0ef90
3 changed files with 9 additions and 9 deletions

View File

@ -37,7 +37,6 @@ public class DustListener extends ItemListener {
}
successRate = successRate + cursor.getInteger("percentage") > 100 ? 100 : successRate + cursor.getInteger("percentage");
event.setCurrentItem(enchant.getBook().get(enchant, current.getInteger("level"), successRate, current.getInteger("destroy-rate")));
event.setCancelled(true);

View File

@ -1,6 +1,5 @@
package com.songoda.epicenchants.objects;
import co.aikar.commands.annotation.Optional;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.single.GeneralUtils;
@ -10,7 +9,9 @@ import de.tr7zw.itemnbtapi.NBTItem;
import lombok.Builder;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -34,7 +35,7 @@ public class BookItem {
current().nextInt(enchant.getGroup().getDestroyRateMin(), enchant.getGroup().getDestroyRateMax()));
}
public ItemStack get(Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) {
public ItemStack get(Enchant enchant, @Nullable Integer level, @Nullable Integer successRate, @Nullable Integer destroyRate) {
successRate = successRate == null ? current().nextInt(101) : successRate;
destroyRate = destroyRate == null ? current().nextInt(101) : destroyRate;
level = level == null ? current().nextInt(1, enchant.getMaxLevel() + 1) : level;
@ -42,14 +43,14 @@ public class BookItem {
int finalSuccessRate = successRate;
int finalDestroyRate = destroyRate;
List<String> toSet = lore;
List<String> toSet = new ArrayList<>(lore);
for (int i = lore.size() - 1; i >= 0; i--) {
for (int i = toSet.size() - 1; i >= 0; i--) {
String string = toSet.get(i);
if (string.contains("{description}")) {
lore.remove(i);
lore.addAll(i, enchant.getDescription().stream().map(GeneralUtils::color).collect(Collectors.toList()));
toSet.remove(i);
toSet.addAll(i, enchant.getDescription().stream().map(GeneralUtils::color).collect(Collectors.toList()));
continue;
}
@ -58,7 +59,7 @@ public class BookItem {
.replace("{success_rate}", "" + finalSuccessRate)
.replace("{destroy_rate}", "" + finalDestroyRate);
lore.set(i, string);
toSet.set(i, string);
}
ItemBuilder itemBuilder = new ItemBuilder(material)

View File

@ -24,7 +24,7 @@ public class ConfigParser {
.identifier(config.getString("identifier"))
.group(instance.getGroupManager().getValue(config.getString("group").toUpperCase()).orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))))
.maxLevel(config.getInt("max-level"))
.format(config.isSet("appliead-format") ? color(config.getString("applied-format")) : "")
.format(config.isSet("applied-format") ? color(config.getString("applied-format")) : "")
.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())