Bug fixes

This commit is contained in:
GB6 2019-03-21 15:35:12 +01:00
parent 926b572c8c
commit 79ed22a755
27 changed files with 163 additions and 86 deletions

View File

@ -47,11 +47,9 @@ public class EpicEnchants extends JavaPlugin {
getConsoleSender().sendMessage(color("&7" + getDescription().getName() + " " + getDescription().getVersion() + " by &5Songoda <3&7!")); getConsoleSender().sendMessage(color("&7" + getDescription().getName() + " " + getDescription().getVersion() + " by &5Songoda <3&7!"));
getConsoleSender().sendMessage(color("&7Action: &aEnabling&7...")); getConsoleSender().sendMessage(color("&7Action: &aEnabling&7..."));
FastInv.init(this); preload();
this.version = Integer.parseInt(Bukkit.getServer().getBukkitVersion().split("\\.")[1]);
this.action = new Action(); this.action = new Action();
this.fileManager = new FileManager(this);
this.groupManager = new GroupManager(this); this.groupManager = new GroupManager(this);
this.enchantManager = new EnchantManager(this); this.enchantManager = new EnchantManager(this);
this.enchantUtils = new EnchantUtils(this); this.enchantUtils = new EnchantUtils(this);
@ -62,7 +60,6 @@ public class EpicEnchants extends JavaPlugin {
this.hookManager = new HookManager(); this.hookManager = new HookManager();
this.itemGroup = new ItemGroup(this); this.itemGroup = new ItemGroup(this);
fileManager.loadFiles();
groupManager.loadGroups(); groupManager.loadGroups();
enchantManager.loadEnchants(); enchantManager.loadEnchants();
infoManager.loadMenus(); infoManager.loadMenus();
@ -78,6 +75,13 @@ public class EpicEnchants extends JavaPlugin {
getConsoleSender().sendMessage(color("&a=============================")); getConsoleSender().sendMessage(color("&a============================="));
} }
private void preload() {
FastInv.init(this);
this.version = Integer.parseInt(Bukkit.getServer().getBukkitVersion().split("\\.")[1]);
this.fileManager = new FileManager(this);
fileManager.loadFiles();
}
@Override @Override
public void onDisable() { public void onDisable() {
getConsoleSender().sendMessage(color("&a=============================")); getConsoleSender().sendMessage(color("&a============================="));
@ -101,10 +105,19 @@ public class EpicEnchants extends JavaPlugin {
public void reload() { public void reload() {
reloadConfig(); reloadConfig();
fileManager.clear();
fileManager.loadFiles(); fileManager.loadFiles();
enchantManager.loadEnchants();
groupManager.clear();
groupManager.loadGroups(); groupManager.loadGroups();
enchantManager.clear();
enchantManager.loadEnchants();
infoManager.clear();
infoManager.loadMenus(); infoManager.loadMenus();
action.load(fileManager.getConfiguration("actions")); action.load(fileManager.getConfiguration("actions"));
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantCommand extends BaseCommand {
@CommandCompletion("@players @groups @dustTypes @nothing") @CommandCompletion("@players @groups @dustTypes @nothing")
@CommandPermission("epicenchants.give.item.dust") @CommandPermission("epicenchants.give.item.dust")
public void onGiveDust(CommandSender sender, @Flags("other") Player target, Group group, @Optional String dustType, @Optional Integer percentage) { public void onGiveDust(CommandSender sender, @Flags("other") Player target, Group group, @Optional String dustType, @Optional Integer percentage) {
target.getInventory().addItem(instance.getSpecialItems().getDust(group, dustType, percentage)); target.getInventory().addItem(instance.getSpecialItems().getDust(group, dustType, percentage, true));
instance.getAction().perform(target, "command.dust.received", of("group", group.getIdentifier())); instance.getAction().perform(target, "command.dust.received", of("group", group.getIdentifier()));
instance.getAction().perform(sender, "command.dust.gave", of("player", target.getName()), of("group", group.getIdentifier())); instance.getAction().perform(sender, "command.dust.gave", of("player", target.getName()), of("group", group.getIdentifier()));
} }

View File

@ -7,8 +7,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Optional; import java.util.Optional;
import static com.google.common.base.CaseFormat.UPPER_CAMEL; import static com.google.common.base.CaseFormat.*;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
public class EffectManager { public class EffectManager {

View File

@ -78,6 +78,7 @@ public class BookListener extends ItemListener {
} }
Group group = instance.getGroupManager().getValueUnsafe(clicked.getString("group")); Group group = instance.getGroupManager().getValueUnsafe(clicked.getString("group"));
Optional<Enchant> enchant = instance.getEnchantManager().getRandomEnchant(group); Optional<Enchant> enchant = instance.getEnchantManager().getRandomEnchant(group);
if (!enchant.isPresent()) { if (!enchant.isPresent()) {

View File

@ -60,6 +60,6 @@ public class DustListener extends ItemListener {
int rate = ThreadLocalRandom.current().nextInt(clicked.getInteger("min-rate"), clicked.getInteger("max-rate")); int rate = ThreadLocalRandom.current().nextInt(clicked.getInteger("min-rate"), clicked.getInteger("max-rate"));
useItem(event); useItem(event);
event.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, null, rate)); event.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, null, rate, false));
} }
} }

View File

@ -52,15 +52,15 @@ public class CommandManager extends BukkitCommandManager {
.findFirst() .findFirst()
.orElseThrow(() -> new InvalidCommandArgument("No item by that type.", false))); .orElseThrow(() -> new InvalidCommandArgument("No item by that type.", false)));
getCommandContexts().registerContext(Group.class, c -> instance.getGroupManager().getValue(c.popFirstArg()).orElseThrow(() -> getCommandContexts().registerContext(Group.class, c -> instance.getGroupManager().getValue(c.popFirstArg().toUpperCase()).orElseThrow(() ->
new InvalidCommandArgument("No group exists by that name", false))); new InvalidCommandArgument("No group exists by that name", false)));
// REPLACEMENTS // REPLACEMENTS
getCommandReplacements().addReplacements( getCommandReplacements().addReplacements(
"enchanter", instance.getConfig().getString("commands.enchanter"), "enchanter", instance.getFileManager().getConfiguration("config").getString("commands.enchanter"),
"alchemist", instance.getConfig().getString("commands.alchemist"), "alchemist", instance.getFileManager().getConfiguration("config").getString("commands.alchemist"),
"tinkerer", instance.getConfig().getString("commands.tinkerer") "tinkerer", instance.getFileManager().getConfiguration("config").getString("commands.tinkerer")
); );
// API // API

View File

@ -20,6 +20,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
private final String directory; private final String directory;
private final LinkedHashSet<Pair<String, Boolean>> files = new LinkedHashSet<>(asList( private final LinkedHashSet<Pair<String, Boolean>> files = new LinkedHashSet<>(asList(
of("config.yml", true),
of("menus/main-info-menu.yml", true), of("menus/main-info-menu.yml", true),
of("menus/enchanter-menu.yml", true), of("menus/enchanter-menu.yml", true),
of("menus/tinkerer-menu.yml", true), of("menus/tinkerer-menu.yml", true),
@ -29,7 +30,6 @@ public class FileManager extends Manager<String, FileConfiguration> {
of("menus/groups/ultimate-menu.yml", false), of("menus/groups/ultimate-menu.yml", false),
of("menus/groups/legendary-menu.yml", false), of("menus/groups/legendary-menu.yml", false),
of("enchants/example-enchant.yml", false), of("enchants/example-enchant.yml", false),
of("config.yml", true),
of("groups.yml", true), of("groups.yml", true),
of("actions.yml", true), of("actions.yml", true),
of("items/special-items.yml", true), of("items/special-items.yml", true),
@ -45,15 +45,13 @@ public class FileManager extends Manager<String, FileConfiguration> {
} }
public void loadFiles() { public void loadFiles() {
Set<String> recentDirs = new HashSet<>();
files.forEach(pair -> { files.forEach(pair -> {
File file = new File(instance.getDataFolder() + separator + pair.getLeft()); File file = new File(instance.getDataFolder() + separator + pair.getLeft());
if (!file.exists() && (pair.getRight() || (!file.getParent().equals(instance.getDataFolder().getPath()) if (!file.exists() && (pair.getRight() || getConfiguration("config").getBoolean("first-load"))) {
&& (!file.getParentFile().exists() || recentDirs.contains(file.getParent()))))) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
recentDirs.add(file.getParent());
Bukkit.getConsoleSender().sendMessage("Creating file: " + pair.getLeft()); Bukkit.getConsoleSender().sendMessage("Creating file: " + pair.getLeft());
try { try {
FileUtils.copyInputStreamToFile(instance.getResource(directory + "/" + pair.getLeft()), file); FileUtils.copyInputStreamToFile(instance.getResource(directory + "/" + pair.getLeft()), file);
} catch (IOException e) { } catch (IOException e) {
@ -71,6 +69,13 @@ public class FileManager extends Manager<String, FileConfiguration> {
add(pair.getLeft().replace(".yml", ""), configuration); add(pair.getLeft().replace(".yml", ""), configuration);
} }
}); });
getConfiguration("config").set("first-load", false);
try {
getConfiguration("config").save(new File(instance.getDataFolder() + separator + "config.yml"));
} catch (IOException e) {
e.printStackTrace();
}
} }
public FileConfiguration getConfiguration(String key) { public FileConfiguration getConfiguration(String key) {
@ -94,6 +99,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
.filter(File::isDirectory) .filter(File::isDirectory)
.filter(s -> !s.getName().equalsIgnoreCase("old")) .filter(s -> !s.getName().equalsIgnoreCase("old"))
.forEach(f -> output.addAll(getYmlFiles(directory + separator + f.getName()))); .forEach(f -> output.addAll(getYmlFiles(directory + separator + f.getName())));
return output; return output;
} }
} }

View File

@ -13,8 +13,8 @@ public class GroupManager extends Manager<String, Group> {
public void loadGroups() { public void loadGroups() {
ConfigurationSection config = instance.getFileManager().getConfiguration("groups").getConfigurationSection("groups"); ConfigurationSection config = instance.getFileManager().getConfiguration("groups").getConfigurationSection("groups");
config.getKeys(false).forEach(key -> { config.getKeys(false).forEach(key -> {
Group group = ConfigParser.parseGroup(config.getConfigurationSection(key)); Group group = ConfigParser.parseGroup(instance, config.getConfigurationSection(key));
add(group.getIdentifier(), group); add(group.getIdentifier().toUpperCase(), group);
}); });
} }
} }

View File

@ -8,22 +8,19 @@ import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class InfoManager { public class InfoManager extends Manager<Group, InfoMenu> {
private final Map<Group, InfoMenu> infoMenus;
private final EpicEnchants instance; private final EpicEnchants instance;
@Getter private MainInfoMenu mainInfoMenu; @Getter private MainInfoMenu mainInfoMenu;
public InfoManager(EpicEnchants instance) { public InfoManager(EpicEnchants instance) {
super(instance);
this.instance = instance; this.instance = instance;
this.infoMenus = new HashMap<>();
} }
public Optional<InfoMenu> getMenu(Group group) { public Optional<InfoMenu> getMenu(Group group) {
return Optional.ofNullable(infoMenus.get(group)); return getValue(group);
} }
public void loadMenus() { public void loadMenus() {
@ -31,7 +28,7 @@ public class InfoManager {
instance.getFileManager().getYmlFiles("menus/groups").forEach(file -> { instance.getFileManager().getYmlFiles("menus/groups").forEach(file -> {
try { try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file); YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
infoMenus.put(instance.getGroupManager().getValue(config.getString("group")) add(instance.getGroupManager().getValue(config.getString("group"))
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))), new InfoMenu(instance, config)); .orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))), new InfoMenu(instance, config));
} catch (Exception e) { } catch (Exception e) {
Bukkit.getConsoleSender().sendMessage("Something went wrong loading the menu from file " + file.getName()); Bukkit.getConsoleSender().sendMessage("Something went wrong loading the menu from file " + file.getName());

View File

@ -30,4 +30,8 @@ public abstract class Manager<K, V> {
return Collections.unmodifiableCollection(map.values()); return Collections.unmodifiableCollection(map.values());
} }
public void clear() {
map.clear();
}
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -35,6 +36,8 @@ public class TinkererMenu extends FastInv {
this.instance = instance; this.instance = instance;
this.config = config; this.config = config;
AtomicBoolean accepted = new AtomicBoolean(false);
if (config.isConfigurationSection("fill")) { if (config.isConfigurationSection("fill")) {
fill(new ItemBuilder(config.getConfigurationSection("fill")).build()); fill(new ItemBuilder(config.getConfigurationSection("fill")).build());
} }
@ -50,6 +53,7 @@ public class TinkererMenu extends FastInv {
slotMap.keySet().forEach(slot -> getInventory().clear(slot)); slotMap.keySet().forEach(slot -> getInventory().clear(slot));
event.getPlayer().closeInventory(); event.getPlayer().closeInventory();
instance.getAction().perform(event.getPlayer(), "tinkerer.accepted"); instance.getAction().perform(event.getPlayer(), "tinkerer.accepted");
accepted.set(true);
return; return;
} }
@ -141,12 +145,15 @@ public class TinkererMenu extends FastInv {
} }
}); });
// Player closed inventory
onClose(event -> { onClose(event -> {
slotMap.keySet().stream().filter(s -> getInventory().getItem(s) != null).forEach(s -> { slotMap.keySet().stream().filter(s -> getInventory().getItem(s) != null).forEach(s -> {
event.getPlayer().getInventory().addItem(getInventory().getItem(s)); event.getPlayer().getInventory().addItem(getInventory().getItem(s));
}); });
instance.getAction().perform(event.getPlayer(), "tinkerer.cancelled"); if (!accepted.get())
instance.getAction().perform(event.getPlayer(), "tinkerer.cancelled");
}); });
} }

View File

@ -1,7 +1,11 @@
package com.songoda.epicenchants.objects; package com.songoda.epicenchants.objects;
import co.aikar.commands.annotation.Optional; import co.aikar.commands.annotation.Optional;
import com.songoda.epicenchants.EpicEnchants;
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.ItemGroup;
import com.songoda.epicenchants.utils.single.RomanNumber;
import de.tr7zw.itemnbtapi.NBTItem; import de.tr7zw.itemnbtapi.NBTItem;
import lombok.Builder; import lombok.Builder;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,10 +14,12 @@ import org.bukkit.inventory.ItemStack;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static java.util.concurrent.ThreadLocalRandom.current; import static java.util.concurrent.ThreadLocalRandom.current;
@Builder @Builder
public class BookItem { public class BookItem {
private EpicEnchants instance;
private Material material; private Material material;
private String displayName; private String displayName;
private List<String> lore; private List<String> lore;
@ -35,14 +41,34 @@ public class BookItem {
int finalSuccessRate = successRate; int finalSuccessRate = successRate;
int finalDestroyRate = destroyRate; int finalDestroyRate = destroyRate;
int finalLevel = level;
List<String> toSet = lore;
for (int i = lore.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()));
continue;
}
string = string
.replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A"))
.replace("{success_rate}", "" + finalSuccessRate)
.replace("{destroy_rate}", "" + finalDestroyRate);
lore.set(i, string);
}
ItemBuilder itemBuilder = new ItemBuilder(material) ItemBuilder itemBuilder = new ItemBuilder(material)
.name(displayName.replace("{level}", "" + level)) .name(color(displayName
.lore(lore.stream() .replace("{level}", "" + (instance.getFileManager().getConfiguration("config").getBoolean("roman-numbers") ? RomanNumber.toRoman(level) : level))
.map(s -> s.replace("{level}", "" + finalLevel) .replace("{enchant}", "" + enchant.getIdentifier())
.replace("{success_rate}", "" + finalSuccessRate) .replace("{group_color}", enchant.getGroup().getColor())
.replace("{destroy_rate}", "" + finalDestroyRate)) .replace("{group_name}", enchant.getGroup().getName())
.collect(Collectors.toList())); ))
.lore(toSet);
NBTItem nbtItem = itemBuilder.nbt(); NBTItem nbtItem = itemBuilder.nbt();
nbtItem.setBoolean("book-item", true); nbtItem.setBoolean("book-item", true);

View File

@ -3,6 +3,7 @@ package com.songoda.epicenchants.objects;
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.enums.TriggerType; import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.utils.single.RomanNumber;
import com.songoda.epicenchants.wrappers.MobWrapper; import com.songoda.epicenchants.wrappers.MobWrapper;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
@ -13,8 +14,11 @@ 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.List;
import java.util.Set; import java.util.Set;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
@Builder @Builder
@Getter @Getter
public class Enchant { public class Enchant {
@ -25,8 +29,8 @@ public class Enchant {
private Set<Material> itemWhitelist; private Set<Material> itemWhitelist;
private Set<EffectExecutor> effectExecutors; private Set<EffectExecutor> effectExecutors;
private Set<MobWrapper> mobs; private Set<MobWrapper> mobs;
private Set<String> description; private List<String> description;
@Nullable private String format; private String format;
@Nullable private BookItem bookItem; @Nullable private BookItem bookItem;
private Condition condition; private Condition condition;
@ -43,7 +47,14 @@ public class Enchant {
return bookItem != null ? bookItem : group.getBookItem(); return bookItem != null ? bookItem : group.getBookItem();
} }
public String getFormat() { public String getFormat(int level, boolean roman) {
return format != null ? format : group.getFormat(); String output = format.isEmpty() ? group.getFormat() : format;
output = output
.replace("{level}", "" + (roman ? RomanNumber.toRoman(level) : level))
.replace("{enchant}", "" + identifier)
.replace("{group_color}", "" + group.getColor());
return color(output);
} }
} }

View File

@ -7,7 +7,6 @@ import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.Enchant; import com.songoda.epicenchants.objects.Enchant;
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 com.songoda.epicenchants.utils.single.RomanNumber;
import de.tr7zw.itemnbtapi.NBTCompound; import de.tr7zw.itemnbtapi.NBTCompound;
import de.tr7zw.itemnbtapi.NBTItem; import de.tr7zw.itemnbtapi.NBTItem;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -72,7 +71,7 @@ public class EnchantUtils {
} }
itemBuilder.removeLore(enchant.getFormat().replace("{level}", "").trim()); itemBuilder.removeLore(enchant.getFormat().replace("{level}", "").trim());
itemBuilder.addLore(enchant.getFormat().replace("{level}", "" + (instance.getConfig().getBoolean("roman-numbers") ? RomanNumber.toRoman(level) : level))); itemBuilder.addLore(enchant.getFormat(level, instance.getFileManager().getConfiguration("config").getBoolean("roman-numbers")));
if (hasProtection) { if (hasProtection) {
itemBuilder.addLore(instance.getSpecialItems().getWhiteScrollLore()); itemBuilder.addLore(instance.getSpecialItems().getWhiteScrollLore());

View File

@ -34,7 +34,7 @@ public class SpecialItems {
} }
public ItemStack getBlackScroll(Integer amount, Integer chance) { public ItemStack getBlackScroll(Integer amount, Integer chance) {
int successRate = chance == null ? ThreadLocalRandom.current().nextInt(instance.getConfig().getInt("rates.black-scroll-min"), instance.getConfig().getInt("rates.black-scroll-max") + 1) : chance; int successRate = chance == null ? ThreadLocalRandom.current().nextInt(instance.getFileManager().getConfiguration("config").getInt("rates.black-scroll-min"), instance.getFileManager().getConfiguration("config").getInt("rates.black-scroll-max") + 1) : chance;
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt(); NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
nbtItem.setBoolean("black-scroll", true); nbtItem.setBoolean("black-scroll", true);
@ -74,12 +74,12 @@ public class SpecialItems {
nbtItem.setBoolean("secret-dust", true); nbtItem.setBoolean("secret-dust", true);
nbtItem.setString("group", group.getIdentifier()); nbtItem.setString("group", group.getIdentifier());
nbtItem.setInteger("max-rate", max); nbtItem.setInteger("max-rate", max + 1);
nbtItem.setInteger("min-rate", 1); nbtItem.setInteger("min-rate", 1);
return nbtItem.getItem(); return nbtItem.getItem();
} }
public ItemStack getDust(Group group, @Nullable String type, @Nullable Integer percentage) { public ItemStack getDust(Group group, @Nullable String type, @Nullable Integer percentage, boolean command) {
FileConfiguration dustConfig = instance.getFileManager().getConfiguration("items/dusts"); FileConfiguration dustConfig = instance.getFileManager().getConfiguration("items/dusts");
int random = ThreadLocalRandom.current().nextInt(101); int random = ThreadLocalRandom.current().nextInt(101);
int counter = 0; int counter = 0;
@ -94,9 +94,11 @@ public class SpecialItems {
} }
} }
ConfigurationSection config = dustConfig.getConfigurationSection("dusts." + (type == null ? "mystery" : type)); type = type == null ? "mystery" : type;
if (config.isInt("min-rate") && config.isInt("max-rate") && percentage == null) { ConfigurationSection config = dustConfig.getConfigurationSection("dusts." + type);
if (!command && config.isInt("min-rate") && config.isInt("max-rate")) {
int minRate = config.getInt("min-rate"); int minRate = config.getInt("min-rate");
int maxRate = config.getInt("max-rate"); int maxRate = config.getInt("max-rate");
percentage = ThreadLocalRandom.current().nextInt(minRate, maxRate + 1); percentage = ThreadLocalRandom.current().nextInt(minRate, maxRate + 1);
@ -109,7 +111,7 @@ public class SpecialItems {
of("group-name", group.getName()), of("group-name", group.getName()),
of("percentage", percentage)).nbt(); of("percentage", percentage)).nbt();
if (type != null && type.equalsIgnoreCase("mystery")) { if (type.equalsIgnoreCase("mystery")) {
return nbtItem.getItem(); return nbtItem.getItem();
} }

View File

@ -19,13 +19,13 @@ import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color; import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
public class ConfigParser { public class ConfigParser {
public static Enchant parseEnchant(EpicEnchants instance, FileConfiguration config) { public static Enchant parseEnchant(EpicEnchants instance, FileConfiguration config) throws Exception {
return Enchant.builder() return Enchant.builder()
.identifier(config.getString("identifier")) .identifier(config.getString("identifier"))
.group(instance.getGroupManager().getValue(config.getString("group").toUpperCase()).orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group")))) .group(instance.getGroupManager().getValue(config.getString("group").toUpperCase()).orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))))
.maxLevel(config.getInt("max-level")) .maxLevel(config.getInt("max-level"))
.format(color(config.getString("applied-format"))) .format(config.isSet("appliead-format") ? color(config.getString("applied-format")) : "")
.bookItem(parseBookItem(config.getConfigurationSection("book-item"))) .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())) .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()) .conflict(config.isList("conflicting-enchants") ? new HashSet<>(config.getStringList("conflicting-enchants")) : Collections.emptySet())
.condition(Condition.of(config.getString("condition"))) .condition(Condition.of(config.getString("condition")))
@ -37,10 +37,10 @@ public class ConfigParser {
.map(s -> "effects." + s) .map(s -> "effects." + s)
.map(config::getConfigurationSection) .map(config::getConfigurationSection)
.map(EffectManager::getEffect) .map(EffectManager::getEffect)
.map(o -> o.orElse(null)) .filter(Optional::isPresent)
.filter(Objects::nonNull) .map(Optional::get)
.collect(Collectors.toSet()) : Collections.emptySet()) .collect(Collectors.toSet()) : Collections.emptySet())
.description(config.isList("description") ? new HashSet<>(config.getStringList("description")) : Collections.emptySet()) .description(config.isList("description") ? config.getStringList("description") : Collections.emptyList())
.build(); .build();
} }
@ -70,21 +70,22 @@ public class ConfigParser {
.build(); .build();
} }
private static BookItem parseBookItem(ConfigurationSection section) { private static BookItem parseBookItem(EpicEnchants instance, ConfigurationSection section) {
return section != null ? BookItem.builder() return section != null ? BookItem.builder()
.instance(instance)
.material(Material.valueOf(section.getString("material"))) .material(Material.valueOf(section.getString("material")))
.displayName(color(section.getString("display-name"))) .displayName(color(section.getString("display-name")))
.lore(section.getStringList("lore").stream().map(GeneralUtils::color).collect(Collectors.toList())) .lore(section.getStringList("lore").stream().map(GeneralUtils::color).collect(Collectors.toList()))
.build() : null; .build() : null;
} }
public static Group parseGroup(ConfigurationSection section) { public static Group parseGroup(EpicEnchants instance, ConfigurationSection section) {
return section != null ? Group.builder() return section != null ? Group.builder()
.identifier(section.getName()) .identifier(section.getName())
.name(color(section.getString("group-name"))) .name(color(section.getString("group-name")))
.format(section.getString("group-lore-format")) .format(section.getString("group-lore-format"))
.color(section.getString("group-color")) .color(section.getString("group-color"))
.bookItem(parseBookItem(section.getConfigurationSection("book-item"))) .bookItem(parseBookItem(instance, section.getConfigurationSection("book-item")))
.slotsUsed(section.getInt("slots-used")) .slotsUsed(section.getInt("slots-used"))
.tinkererExp(section.getInt("tinkerer-exp-per-level")) .tinkererExp(section.getInt("tinkerer-exp-per-level"))
.destroyRateMin(section.getInt("rates.destroy-min")) .destroyRateMin(section.getInt("rates.destroy-min"))

View File

@ -28,7 +28,7 @@ public class GeneralUtils {
} }
public static String getMessageFromResult(EnchantResult result) { public static String getMessageFromResult(EnchantResult result) {
return "enchant." + result.toString().toLowerCase().replace("_", ""); return "enchants." + result.toString().toLowerCase().replace("_", "-");
} }
public static <X> X getRandomElement(Set<X> set) { public static <X> X getRandomElement(Set<X> set) {

View File

@ -1,5 +1,6 @@
package com.songoda.epicenchants.utils.single; package com.songoda.epicenchants.utils.single;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import lombok.Getter; import lombok.Getter;
@ -17,7 +18,8 @@ public class ItemGroup {
private Multimap<Group, Material> groupMap; private Multimap<Group, Material> groupMap;
public ItemGroup(EpicEnchants instance) { public ItemGroup(EpicEnchants instance) {
if (instance.getVersion() > 1.12) setupMaster(); groupMap = HashMultimap.create();
if (instance.getVersion() > 12) setupMaster();
else setupLegacy(); else setupLegacy();
} }
@ -73,6 +75,10 @@ public class ItemGroup {
return output; return output;
} }
public Optional<Group> getGroup(Set<Material> materials) {
return groupMap.asMap().entrySet().stream().filter(s -> s.getValue().equals(materials)).map(Map.Entry::getKey).findFirst();
}
public enum Group { public enum Group {
AXES, AXES,

View File

@ -1,5 +1,7 @@
#LEGACY CONFIG #LEGACY CONFIG
first-load: true
language: "en_US" language: "en_US"
roman-numbers: true roman-numbers: true
@ -8,7 +10,6 @@ rates:
black-scroll-min: 20 black-scroll-min: 20
black-scroll-max: 100 black-scroll-max: 100
commands: commands:
enchanter: "enchanter" enchanter: "enchanter"
alchemist: "alchemist" alchemist: "alchemist"

View File

@ -22,9 +22,7 @@ applied-format: "&cExampleEnchant {level}"
# What items this enchant can be applied too. # What items this enchant can be applied too.
item-whitelist: item-whitelist:
- "DIAMOND_HELMET" - "HELMETS"
- "IRON_HELMET"
- "LEATHER_HELMET"
# This enchantment can not be applied if then enchantment below is already on the item. # This enchantment can not be applied if then enchantment below is already on the item.
conflicting-enchants: conflicting-enchants:

View File

@ -2,7 +2,7 @@ groups:
SIMPLE: SIMPLE:
group-color: "&f" group-color: "&f"
group-name: "Simple" group-name: "Simple"
group-lore-format: "{group_color} {enchant} {level}" group-lore-format: "{group_color}{enchant} {level}"
rates: rates:
destroy-min: 10 destroy-min: 10
destroy-max: 100 destroy-max: 100
@ -15,6 +15,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
UNIQUE: UNIQUE:
group-color: "&a" group-color: "&a"
@ -32,6 +33,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
ELITE: ELITE:
group-color: "&b" group-color: "&b"
@ -49,6 +51,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
ULTIMATE: ULTIMATE:
group-color: "&e" group-color: "&e"
@ -66,6 +69,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
LEGENDARY: LEGENDARY:
group-color: "&6" group-color: "&6"
@ -83,4 +87,5 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."

View File

@ -8,7 +8,8 @@ rows: 1
contents: contents:
1: 1:
material: "WHITE_STAINED_GLASS_PANE" material: "STAINED_GLASS_PANE"
data: 0
display-name: "&f&lSimple Enchantment &7(Right Click)" display-name: "&f&lSimple Enchantment &7(Right Click)"
lore: lore:
- "&7Examine to receive a random" - "&7Examine to receive a random"
@ -23,7 +24,8 @@ contents:
eco-cost: 0 eco-cost: 0
slot: 2 slot: 2
2: 2:
material: "LIME_STAINED_GLASS_PANE" material: "STAINED_GLASS_PANE"
data: 5
display-name: "&a&lUnique Enchantment &7(Right Click)" display-name: "&a&lUnique Enchantment &7(Right Click)"
lore: lore:
- "&7Examine to receive a random" - "&7Examine to receive a random"
@ -38,7 +40,8 @@ contents:
eco-cost: 0 eco-cost: 0
slot: 3 slot: 3
3: 3:
material: "CYAN_STAINED_GLASS_PANE" material: "STAINED_GLASS_PANE"
data: 9
display-name: "&b&lElite Enchantment &7(Right Click)" display-name: "&b&lElite Enchantment &7(Right Click)"
lore: lore:
- "&7Examine to receive a random" - "&7Examine to receive a random"
@ -53,7 +56,8 @@ contents:
eco-cost: 0 eco-cost: 0
slot: 4 slot: 4
4: 4:
material: "YELLOW_STAINED_GLASS_PANE" material: "STAINED_GLASS_PANE"
data: 4
display-name: "&e&lUltimate Enchantment &7(Right Click)" display-name: "&e&lUltimate Enchantment &7(Right Click)"
lore: lore:
- "&7Examine to receive a random" - "&7Examine to receive a random"
@ -68,7 +72,8 @@ contents:
eco-cost: 0 eco-cost: 0
slot: 5 slot: 5
5: 5:
material: "ORANGE_STAINED_GLASS_PANE" material: "STAINED_GLASS_PANE"
data: 1
display-name: "&6&lLegendary Enchantment &7(Right Click)" display-name: "&6&lLegendary Enchantment &7(Right Click)"
lore: lore:
- "&7Examine to receive a random" - "&7Examine to receive a random"

View File

@ -1,8 +0,0 @@
name: EpicEnchants
version: ${project.version}
main: com.songoda.epicenchants.EpicEnchants
authors: [GB6]
website: https://songoda.com/
depend: [Vault]
softdepend: [UltimateBottles]
api-version: 1.13

View File

@ -1,5 +1,7 @@
#MASTER CONFIG #MASTER CONFIG
first-load: true
language: "en_US" language: "en_US"
roman-numbers: true roman-numbers: true

View File

@ -2,7 +2,7 @@ groups:
SIMPLE: SIMPLE:
group-color: "&f" group-color: "&f"
group-name: "Simple" group-name: "Simple"
group-lore-format: "{group_color} {enchant} {level}" group-lore-format: "{group_color}{enchant} {level}"
rates: rates:
destroy-min: 10 destroy-min: 10
destroy-max: 100 destroy-max: 100
@ -15,6 +15,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
UNIQUE: UNIQUE:
group-color: "&a" group-color: "&a"
@ -32,6 +33,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
ELITE: ELITE:
group-color: "&b" group-color: "&b"
@ -49,6 +51,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
ULTIMATE: ULTIMATE:
group-color: "&e" group-color: "&e"
@ -66,6 +69,7 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."
LEGENDARY: LEGENDARY:
group-color: "&6" group-color: "&6"
@ -83,4 +87,5 @@ groups:
- "&a{success_rate}% Success Rate" - "&a{success_rate}% Success Rate"
- "&c{destroy_rate}% Destroy Rate" - "&c{destroy_rate}% Destroy Rate"
- "{description}" - "{description}"
- "&7{item_group} Enchantment"
- "&7Drag and drop to enchant." - "&7Drag and drop to enchant."

View File

@ -1,5 +1,5 @@
secret-dust: secret-dust:
material: FIREBALL material: FIRE_CHARGE
display-name: "{group-color}{group-name} Secret Dust &7(Right click)" display-name: "{group-color}{group-name} Secret Dust &7(Right click)"
lore: lore:
- "&aSuccess: +{min-rate}-{max-rate}%" - "&aSuccess: +{min-rate}-{max-rate}%"
@ -9,7 +9,7 @@ secret-dust:
dusts: dusts:
mystery: mystery:
chance: 50 chance: 50
material: SULPHUR material: GUNPOWDER
display-name: "&fMystery Dust" display-name: "&fMystery Dust"
lore: lore:
- "&7The failed bi-product of" - "&7The failed bi-product of"

View File

@ -14,22 +14,19 @@ slots: "(1,5) (2,6) (3,7) (9,14)
contents: contents:
1: 1:
material: "STAINED_GLASS_PANE" material: "WHITE_STAINED_GLASS_PANE"
display-name: " " display-name: " "
slot: "4,13,22,31,40" slot: "4,13,22,31,40"
accept-left: accept-left:
material: "STAINED_GLASS_PANE" material: "LIME_STAINED_GLASS_PANE"
data: 4
display-name: "&eClick to accept trade" display-name: "&eClick to accept trade"
slot: 0 slot: 0
accept-right: accept-right:
material: "STAINED_GLASS_PANE" material: "LIME_STAINED_GLASS_PANE"
data: 4
display-name: "&eClick to accept trade" display-name: "&eClick to accept trade"
slot: 8 slot: 8
deposit-all: deposit-all:
material: "STAINED_GLASS_PANE" material: "LIME_STAINED_GLASS_PANE"
data: 4
display-name: "&l&eDeposit All" display-name: "&l&eDeposit All"
lore: lore:
- "&7Click to deposit all tinkerable items." - "&7Click to deposit all tinkerable items."