From 12e75d6560c60ac393b35244e4ab678f3fd946c4 Mon Sep 17 00:00:00 2001 From: char3210 <45241413+char3210@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:24:21 -0600 Subject: [PATCH] multiblockcraft criterion, some optimizations --- README.md | 33 +++++---- pom.xml | 2 +- .../sfadvancements/SFAdvancements.java | 18 ++++- .../api/criteria/CriteriaTypes.java | 1 + .../criteria/MultiBlockCraftCriterion.java | 56 +++++++++++++++ .../core/AdvancementsItemGroup.java | 2 +- .../core/command/DumpItemCommand.java | 2 +- .../BlockBreakCriterionCompleter.java | 4 ++ .../completer/ConsumeCriterionCompleter.java | 8 +-- .../criteria/completer/DefaultCompleters.java | 6 ++ .../completer/InteractCriterionCompleter.java | 8 +-- .../InventoryCriterionCompleter.java | 8 +-- .../completer/MobKillCriterionCompleter.java | 5 +- .../MultiBlockCraftCriterionCompleter.java | 69 +++++++++++++++++++ .../MultiBlockCriterionCompleter.java | 8 +-- .../completer/PlaceCriterionCompleter.java | 7 +- .../completer/ResearchCriterionCompleter.java | 7 +- .../completer/SearchCriterionCompleter.java | 4 +- .../sfadvancements/core/gui/MenuItems.java | 4 +- .../sfadvancements/core/gui/OpenGUI.java | 2 +- 20 files changed, 204 insertions(+), 50 deletions(-) create mode 100644 src/main/java/me/char321/sfadvancements/api/criteria/MultiBlockCraftCriterion.java create mode 100644 src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCraftCriterionCompleter.java diff --git a/README.md b/README.md index fae9d3b..517ab61 100644 --- a/README.md +++ b/README.md @@ -107,40 +107,43 @@ The name is what appears in the gui for progress. (Supports color codes with `&` The type is the type of criterion. By default, these are the default criterion types: - `consume` - for eating items - - has an item parameter `item`, which is the item to consume - note that this only works for vanilla consumption, NOT exotic garden fruits for example, use `interact` for that + - has an item parameter `item`, item to consume - has an integer parameter `amount`, the number of items to consume - `interact` - for right-clicking items - - has an item parameter `item`, which is the item to be right-clicked + - has an item parameter `item`, the item to be right-clicked - has an integer parameter `amount`, the number of times to interact - `inventory` - for having an item in an inventory - has an item parameter `item`, the item to have in the inventory - - has an integer parameter `amount`, which is the number of items you need to complete the criterion + - has an integer parameter `amount`, the number of items you need to complete the criterion - `multiblock` - for interacting with a slimefun multiblock - - has a string parameter `multiblock`, which is the slimefun item id of the multiblock + - has a string parameter `multiblock`, the slimefun item id of the multiblock - `place` - for placing blocks - - has an item parameter `item`, which is the item to place down - - has an integer parameter `amount`, which is the number of items to place - - note that there is no protection against players repeatedly breaking and replacing the block, so for most items setting the `amount` to 1 would be appropriate + - has an item parameter `item`, the item to place down + - has an integer parameter `amount`, the number of items to place + - note that there is no protection against players repeatedly breaking and replacing the same block, so for most items setting the `amount` to 1 would be appropriate - `break` - like `place` but for breaking blocks, same parameters - `research` - for completing a research - - has a string parameter `research`, which is the namespaced key of the research - - namespaced keys have the format "plugin:key", so for slimefun researches, it is "slimefun:research" - - ex: "slimefun:ender_talismans" + - has a string parameter `research`, the namespaced key of the research + - namespaced keys have the format "plugin:key", so for slimefun researches, it is "slimefun:research", e.g. "slimefun:ender_talismans" - `mobkill` - for killing a type of mob - - int parameter 'amount', the number of mobs to kill - - has a string parameter `entity` which is the mob to kill - - entity types are generally lowercase, separated by underscores (ex. `stray`, `cave_spider`, `glow_squid`, etc.) + - has an integer parameter `amount`, the number of mobs to kill + - has a string parameter `entity`, the mob to kill + - entity types are generally lowercase, separated by underscores (ex. `stray`, `cave_spider`, `glow_squid`, etc.) - `search` - for searching for a string in the slimefun guide - - string parameter `search` which is the exact string to search for + - string parameter `search`, the exact string to search for in the guide +- `multiblockcraft` + - for crafting an item in a multiblock + - has an item parameter `item`, the item to craft + - has an integer parameter `amount`, the number of times to craft it (not how many items are to be crafted) #### rewards @@ -164,7 +167,7 @@ see [api.md](https://github.com/qwertyuioplkjhgfd/SlimefunAdvancements/blob/main ## TODO: - ~~criteria system~~ - ~~inventory criteria~~ - - craft criteria (soon, see [Slimefun/Slimefun4#3439](https://github.com/Slimefun/Slimefun4/pull/3439)) + - ~~craft criteria (soon, see [Slimefun/Slimefun4#3439](https://github.com/Slimefun/Slimefun4/pull/3439))~~ - ~~interact criteria~~ - ~~place criteria~~ - ~~research criteria~~ diff --git a/pom.xml b/pom.xml index 9a7deab..4227b5a 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ com.github.Slimefun Slimefun4 - RC-30 + b646e15974 provided diff --git a/src/main/java/me/char321/sfadvancements/SFAdvancements.java b/src/main/java/me/char321/sfadvancements/SFAdvancements.java index deec1fa..f8247a0 100644 --- a/src/main/java/me/char321/sfadvancements/SFAdvancements.java +++ b/src/main/java/me/char321/sfadvancements/SFAdvancements.java @@ -1,8 +1,8 @@ package me.char321.sfadvancements; +import io.github.bakedlibs.dough.config.Config; import io.github.bakedlibs.dough.updater.BlobBuildUpdater; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; -import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import me.char321.sfadvancements.api.AdvancementBuilder; import me.char321.sfadvancements.api.AdvancementGroup; import me.char321.sfadvancements.api.criteria.CriteriaTypes; @@ -45,6 +45,7 @@ public final class SFAdvancements extends JavaPlugin implements SlimefunAddon { private YamlConfiguration groupConfig; private boolean testing = false; + private boolean multiBlockCraftEvent = false; public SFAdvancements() { @@ -61,6 +62,8 @@ public void onEnable() { config = new Config(this); + detectCapabilities(); + autoUpdate(); getCommand("sfadvancements").setExecutor(new SFACommand(this)); @@ -108,6 +111,15 @@ public void onDisable() { } } + private void detectCapabilities() { + try { + Class.forName("io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent"); + multiBlockCraftEvent = true; + } catch (ClassNotFoundException e) { + multiBlockCraftEvent = false; + } + } + private void autoUpdate() { if (config.getBoolean("auto-update") && !getDescription().getVersion().contains("MODIFIED")) { info("Checking for updates..."); @@ -207,6 +219,10 @@ public boolean isTesting() { return testing; } + public boolean isMultiBlockCraftEvent() { + return multiBlockCraftEvent; + } + public static Logger logger() { return instance.getLogger(); } diff --git a/src/main/java/me/char321/sfadvancements/api/criteria/CriteriaTypes.java b/src/main/java/me/char321/sfadvancements/api/criteria/CriteriaTypes.java index 8f227b9..e98a58a 100644 --- a/src/main/java/me/char321/sfadvancements/api/criteria/CriteriaTypes.java +++ b/src/main/java/me/char321/sfadvancements/api/criteria/CriteriaTypes.java @@ -22,6 +22,7 @@ public static void loadDefaultCriteria() { putType("none", Criterion::loadFromConfig); putType("search", SearchCriterion::loadFromConfig); putType("break", BlockBreakCriterion::loadFromConfig); + putType("multiblockcraft", MultiBlockCraftCriterion::loadFromConfig); } /** diff --git a/src/main/java/me/char321/sfadvancements/api/criteria/MultiBlockCraftCriterion.java b/src/main/java/me/char321/sfadvancements/api/criteria/MultiBlockCraftCriterion.java new file mode 100644 index 0000000..ba5a9c2 --- /dev/null +++ b/src/main/java/me/char321/sfadvancements/api/criteria/MultiBlockCraftCriterion.java @@ -0,0 +1,56 @@ +package me.char321.sfadvancements.api.criteria; + +import me.char321.sfadvancements.SFAdvancements; +import me.char321.sfadvancements.util.ConfigUtils; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.inventory.ItemStack; + +public class MultiBlockCraftCriterion extends Criterion { + private final ItemStack item; + + public static MultiBlockCraftCriterion loadFromConfig(ConfigurationSection config) { + String id = config.getName(); + + if (!SFAdvancements.instance().isMultiBlockCraftEvent()) { + SFAdvancements.warn("Multiblock craft events are not available on this version of Slimefun! for criterion " + id); + return null; + } + + int amount = config.getInt("amount"); + if (amount == 0) { + amount = 1; + } + + String name = config.getString("name"); + if(name == null) { + name = id; + } + + name = ChatColor.translateAlternateColorCodes('&', name); + + ItemStack item = ConfigUtils.getItem(config, "item"); + if (item == null) { + SFAdvancements.warn("unknown item for multiblock craft criterion " + id); + return null; + } + + return new MultiBlockCraftCriterion(id, amount, name, item); + } + + /** + * + * @param id + * @param count + * @param name + * @param item the output item of the multiblock craft + */ + public MultiBlockCraftCriterion(String id, int count, String name, ItemStack item) { + super(id, count, name); + this.item = item; + } + + public ItemStack getItem() { + return item; + } +} diff --git a/src/main/java/me/char321/sfadvancements/core/AdvancementsItemGroup.java b/src/main/java/me/char321/sfadvancements/core/AdvancementsItemGroup.java index 01921a5..b631b11 100644 --- a/src/main/java/me/char321/sfadvancements/core/AdvancementsItemGroup.java +++ b/src/main/java/me/char321/sfadvancements/core/AdvancementsItemGroup.java @@ -1,9 +1,9 @@ package me.char321.sfadvancements.core; +import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import me.char321.sfadvancements.SFAdvancements; import org.bukkit.Material; import org.bukkit.NamespacedKey; diff --git a/src/main/java/me/char321/sfadvancements/core/command/DumpItemCommand.java b/src/main/java/me/char321/sfadvancements/core/command/DumpItemCommand.java index 2e1d7e0..2276c2c 100644 --- a/src/main/java/me/char321/sfadvancements/core/command/DumpItemCommand.java +++ b/src/main/java/me/char321/sfadvancements/core/command/DumpItemCommand.java @@ -1,8 +1,8 @@ package me.char321.sfadvancements.core.command; +import io.github.bakedlibs.dough.items.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.ItemUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.char321.sfadvancements.SFAdvancements; import org.bukkit.ChatColor; diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/BlockBreakCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/BlockBreakCriterionCompleter.java index 636d1c5..15a9e1a 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/BlockBreakCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/BlockBreakCriterionCompleter.java @@ -39,6 +39,10 @@ public void onBlockBreak(BlockBreakEvent e) { @Override public void register(Criterion criterion) { + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); + } + BlockBreakCriterion criterion1 = (BlockBreakCriterion) criterion; criteria.computeIfAbsent(criterion1.getItem().getType(), k -> new ArrayList<>()).add(criterion1); } diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/ConsumeCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/ConsumeCriterionCompleter.java index 445e604..e821cc3 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/ConsumeCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/ConsumeCriterionCompleter.java @@ -41,13 +41,13 @@ public void onConsume(PlayerItemConsumeEvent e) { @Override public void register(Criterion criterion) { - if (!(criterion instanceof ConsumeCriterion)) { - throw new IllegalArgumentException("criterion must be an ConsumeCriterion"); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); } + ConsumeCriterion criterion1 = (ConsumeCriterion) criterion; Material m = criterion1.getItem().getType(); - criteria.computeIfAbsent(m, k -> new HashSet<>()); - criteria.get(m).add(criterion1); + criteria.computeIfAbsent(m, k -> new HashSet<>()).add(criterion1); } @Override diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/DefaultCompleters.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/DefaultCompleters.java index da89dec..8171a5b 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/DefaultCompleters.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/DefaultCompleters.java @@ -1,5 +1,7 @@ package me.char321.sfadvancements.core.criteria.completer; +import me.char321.sfadvancements.SFAdvancements; + public class DefaultCompleters { private DefaultCompleters() { @@ -16,5 +18,9 @@ public static void registerDefaultCompleters() { new MobKillCriterionCompleter().register(); new SearchCriterionCompleter().register(); new BlockBreakCriterionCompleter().register(); + + if (SFAdvancements.instance().isMultiBlockCraftEvent()) { + new MultiBlockCraftCriterionCompleter().register(); + } } } diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/InteractCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/InteractCriterionCompleter.java index 3c88608..9e26fa1 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/InteractCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/InteractCriterionCompleter.java @@ -41,13 +41,13 @@ public void onInteract(PlayerRightClickEvent e) { @Override public void register(Criterion criterion) { - if (!(criterion instanceof InteractCriterion)) { - throw new IllegalArgumentException("criterion must be an interactcriterion"); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); } + InteractCriterion criterion1 = (InteractCriterion) criterion; Material m = criterion1.getItem().getType(); - criteria.computeIfAbsent(m, k -> new HashSet<>()); - criteria.get(m).add(criterion1); + criteria.computeIfAbsent(m, k -> new HashSet<>()).add(criterion1); } @Override diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/InventoryCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/InventoryCriterionCompleter.java index 2664172..83d9caa 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/InventoryCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/InventoryCriterionCompleter.java @@ -68,13 +68,13 @@ public void onInventory1(Player p) { @Override public void register(Criterion criterion) { - if (!(criterion instanceof InventoryCriterion)) { - throw new IllegalArgumentException("criterion must be an interactcriterion"); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); } + InventoryCriterion criterion1 = (InventoryCriterion) criterion; Material m = criterion1.getItem().getType(); - criteria.computeIfAbsent(m, k -> new HashSet<>()); - criteria.get(m).add(criterion1); + criteria.computeIfAbsent(m, k -> new HashSet<>()).add(criterion1); } @Override diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/MobKillCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/MobKillCriterionCompleter.java index 30428aa..9b34ba3 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/MobKillCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/MobKillCriterionCompleter.java @@ -45,9 +45,10 @@ public void onDeath(EntityDeathEvent e) { @Override public void register(Criterion criterion) { - if (!(criterion instanceof MobKillCriterion)) { - throw new IllegalArgumentException("criterion must be a MobKillCriterion"); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); } + MobKillCriterion criterion1 = (MobKillCriterion) criterion; criteria.computeIfAbsent(criterion1.getEntity(), k -> new ArrayList<>()).add(criterion1); } diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCraftCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCraftCriterionCompleter.java new file mode 100644 index 0000000..246c870 --- /dev/null +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCraftCriterionCompleter.java @@ -0,0 +1,69 @@ +package me.char321.sfadvancements.core.criteria.completer; + +import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent; +import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.api.researches.Research; +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import me.char321.sfadvancements.SFAdvancements; +import me.char321.sfadvancements.api.criteria.Criterion; +import me.char321.sfadvancements.api.criteria.MultiBlockCraftCriterion; +import me.char321.sfadvancements.api.criteria.ResearchCriterion; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class MultiBlockCraftCriterionCompleter implements CriterionCompleter, Listener { + private final Map> criteria = new EnumMap<>(Material.class); + + public MultiBlockCraftCriterionCompleter() { + Bukkit.getPluginManager().registerEvents(this, SFAdvancements.instance()); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onMultiBlockCraft(MultiBlockCraftEvent e) { + performCriteria(e.getPlayer(), e.getOutput()); + } + + private void performCriteria(Player player, ItemStack output) { + Set allcriteria = criteria.get(output.getType()); + if (allcriteria == null) { + return; + } + + for (MultiBlockCraftCriterion criterion : allcriteria) { + if (SlimefunUtils.isItemSimilar(output, criterion.getItem(), false, false)) { + criterion.perform(player); + } + } + } + + @Override + public void register(Criterion criterion) { + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); + } + + MultiBlockCraftCriterion criterion1 = ((MultiBlockCraftCriterion) criterion); + Material material = criterion1.getItem().getType(); + criteria.computeIfAbsent(material, k -> new HashSet<>()).add(criterion1); + } + + @Override + public Class getCriterionClass() { + return MultiBlockCraftCriterion.class; + } + + @Override + public void reload() { + criteria.clear(); + } +} diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCriterionCompleter.java index 6f9dc34..d3641f4 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/MultiBlockCriterionCompleter.java @@ -34,13 +34,13 @@ public void onMultiBlock(MultiBlockInteractEvent e) { @Override public void register(Criterion criterion) { - if (!(criterion instanceof MultiBlockCriterion)) { - throw new IllegalArgumentException("criterion must be an multiblockcriterion"); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be a " + getCriterionClass().getName()); } + MultiBlockCriterion criterion1 = (MultiBlockCriterion) criterion; String machine = criterion1.getMachineId(); - criteria.computeIfAbsent(machine, k -> new HashSet<>()); - criteria.get(machine).add(criterion1); + criteria.computeIfAbsent(machine, k -> new HashSet<>()).add(criterion1); } @Override diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/PlaceCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/PlaceCriterionCompleter.java index 198e2ad..15076f6 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/PlaceCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/PlaceCriterionCompleter.java @@ -45,14 +45,13 @@ public Class getCriterionClass() { @Override public void register(Criterion criterion) { - if (!(criterion instanceof PlaceCriterion)) { - throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be a " + getCriterionClass().getName()); } PlaceCriterion placeCriterion = (PlaceCriterion) criterion; Material m = placeCriterion.getItem().getType(); - criteria.computeIfAbsent(m, k -> new HashSet<>()); - criteria.get(m).add(placeCriterion); + criteria.computeIfAbsent(m, k -> new HashSet<>()).add(placeCriterion); } @Override diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/ResearchCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/ResearchCriterionCompleter.java index 723b203..e1616c0 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/ResearchCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/ResearchCriterionCompleter.java @@ -54,14 +54,13 @@ private void performCriteria(Player player, Research research) { @Override public void register(Criterion criterion) { - if (!(criterion instanceof ResearchCriterion)) { - throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be a " + getCriterionClass().getName()); } ResearchCriterion criterion1 = ((ResearchCriterion) criterion); NamespacedKey research = criterion1.getResearch(); - criteria.computeIfAbsent(research, k -> new HashSet<>()); - criteria.get(research).add(criterion1); + criteria.computeIfAbsent(research, k -> new HashSet<>()).add(criterion1); } @Override diff --git a/src/main/java/me/char321/sfadvancements/core/criteria/completer/SearchCriterionCompleter.java b/src/main/java/me/char321/sfadvancements/core/criteria/completer/SearchCriterionCompleter.java index ed78ea0..495351e 100644 --- a/src/main/java/me/char321/sfadvancements/core/criteria/completer/SearchCriterionCompleter.java +++ b/src/main/java/me/char321/sfadvancements/core/criteria/completer/SearchCriterionCompleter.java @@ -64,8 +64,8 @@ private void onSearch(Player player, String str) { //TODO make not trigger multi @Override public void register(Criterion criterion) { - if (!(criterion instanceof SearchCriterion)) { - throw new IllegalArgumentException("criterion must be an " + getCriterionClass().getName()); + if (!(getCriterionClass().isInstance(criterion))) { + throw new IllegalArgumentException("criterion must be a " + getCriterionClass().getName()); } SearchCriterion criterion1 = (SearchCriterion) criterion; diff --git a/src/main/java/me/char321/sfadvancements/core/gui/MenuItems.java b/src/main/java/me/char321/sfadvancements/core/gui/MenuItems.java index 328a0dd..9d41243 100644 --- a/src/main/java/me/char321/sfadvancements/core/gui/MenuItems.java +++ b/src/main/java/me/char321/sfadvancements/core/gui/MenuItems.java @@ -1,8 +1,8 @@ package me.char321.sfadvancements.core.gui; +import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.libraries.dough.common.ChatColors; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemFlag; diff --git a/src/main/java/me/char321/sfadvancements/core/gui/OpenGUI.java b/src/main/java/me/char321/sfadvancements/core/gui/OpenGUI.java index 10651fe..2d55a0f 100644 --- a/src/main/java/me/char321/sfadvancements/core/gui/OpenGUI.java +++ b/src/main/java/me/char321/sfadvancements/core/gui/OpenGUI.java @@ -1,9 +1,9 @@ package me.char321.sfadvancements.core.gui; +import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import me.char321.sfadvancements.SFAdvancements; import me.char321.sfadvancements.api.Advancement; import me.char321.sfadvancements.api.AdvancementGroup;