diff --git a/src/main/java/me/gallowsdove/foxymachines/FoxyMachines.java b/src/main/java/me/gallowsdove/foxymachines/FoxyMachines.java index d99effa..51d1a98 100644 --- a/src/main/java/me/gallowsdove/foxymachines/FoxyMachines.java +++ b/src/main/java/me/gallowsdove/foxymachines/FoxyMachines.java @@ -11,6 +11,7 @@ import me.gallowsdove.foxymachines.commands.QuestCommand; import me.gallowsdove.foxymachines.commands.SacrificialAltarCommand; import me.gallowsdove.foxymachines.commands.SummonCommand; +import me.gallowsdove.foxymachines.implementation.consumables.UnbreakableRune; import me.gallowsdove.foxymachines.implementation.machines.ForcefieldDome; import me.gallowsdove.foxymachines.implementation.tools.BerryBushTrimmer; import me.gallowsdove.foxymachines.listeners.*; @@ -51,6 +52,7 @@ public void enable() { QuestUtils.init(); AbstractWand.init(); + UnbreakableRune.init(); ItemSetup.INSTANCE.init(); ResearchSetup.INSTANCE.init(); diff --git a/src/main/java/me/gallowsdove/foxymachines/implementation/consumables/UnbreakableRune.java b/src/main/java/me/gallowsdove/foxymachines/implementation/consumables/UnbreakableRune.java index 1130aeb..0c8b496 100644 --- a/src/main/java/me/gallowsdove/foxymachines/implementation/consumables/UnbreakableRune.java +++ b/src/main/java/me/gallowsdove/foxymachines/implementation/consumables/UnbreakableRune.java @@ -1,16 +1,20 @@ package me.gallowsdove.foxymachines.implementation.consumables; import io.github.mooy1.infinitylib.common.Scheduler; +import io.github.mooy1.infinitylib.core.AddonConfig; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import me.gallowsdove.foxymachines.FoxyMachines; import me.gallowsdove.foxymachines.Items; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; @@ -20,12 +24,34 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.logging.Level; public class UnbreakableRune extends SimpleSlimefunItem { + private static final Map> BLACKLIST = new HashMap<>(); private static final double RANGE = 1.5; + public static void init() { + if (!BLACKLIST.isEmpty()) { + FoxyMachines.log(Level.WARNING, "Attempted to initialize UnbreakableRune after already initialized!"); + return; + } + + AddonConfig config = FoxyMachines.getInstance().getConfig(); + ConfigurationSection blacklist = config.getConfigurationSection("unbreakable-rune-blacklist"); + if (blacklist == null) { + return; + } + + for (String addon : blacklist.getKeys(false)) { + BLACKLIST.put(addon, new HashSet<>(blacklist.getStringList(addon))); + } + } public UnbreakableRune() { super(Items.TOOLS_ITEM_GROUP, Items.UNBREAKABLE_RUNE, RecipeType.ANCIENT_ALTAR, new ItemStack[] { @@ -59,7 +85,7 @@ private void activate(@Nonnull Player p, @Nonnull Item rune) { } Location l = rune.getLocation(); - Collection entities = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem); + Collection entities = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, entity -> findCompatibleItem(p, entity)); Optional optional = entities.stream().findFirst(); if (optional.isPresent()) { @@ -92,9 +118,10 @@ private void activate(@Nonnull Player p, @Nonnull Item rune) { } } - private boolean findCompatibleItem(Entity entity) { + private boolean findCompatibleItem(Player player, Entity entity) { if (entity instanceof Item item) { - return !isUnbreakable(item.getItemStack()) && !isItem(item.getItemStack()); + ItemStack itemStack = item.getItemStack(); + return !isUnbreakable(itemStack) && !isItem(itemStack) && !isDisallowed(player, itemStack); } return false; @@ -103,7 +130,7 @@ private boolean findCompatibleItem(Entity entity) { public static void setUnbreakable(@Nullable ItemStack item) { if (item != null && item.getType() != Material.AIR) { - if (!isUnbreakable(item)) { + if (!isUnbreakable(item) && item.hasItemMeta()) { ItemMeta meta = item.getItemMeta(); meta.setUnbreakable(true); @@ -123,4 +150,19 @@ public static boolean isUnbreakable(@Nullable ItemStack item) { return false; } } + + public static boolean isDisallowed(Player player, ItemStack itemStack) { + final SlimefunItem slimefunItem = SlimefunItem.getByItem(itemStack); + if (slimefunItem == null) { + return false; + } + + final String id = slimefunItem.getId(); + final String addon = slimefunItem.getAddon().getName(); + if (BLACKLIST.containsKey(addon) && BLACKLIST.get(addon).contains(id)) { + player.sendMessage(ChatColor.LIGHT_PURPLE + "You can't make this item unbreakable!"); + return true; + } + return false; + } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cf0eb65..cbc497b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -32,6 +32,10 @@ # # quest-mobs # All mob types that can be required for a quest, for a full list of them go to: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html +# +# unbreakable-rune-blacklist +# Any items from addons to blacklist from being usable with the unbreakable rune +# for ex, by default the strainers from InfinityExpansion are disabled as they do not respect the unbreakable setting auto-update: true max-chunk-loaders: 8 @@ -101,4 +105,9 @@ quest-mobs: - ZOGLIN - ZOMBIE - ZOMBIFIED_PIGLIN - - FOX \ No newline at end of file + - FOX +unbreakable-rune-blacklist: + InfinityExpansion: + - BASIC_STRAINER + - ADVANCED_STRAINER + - REINFORCED_STRAINER \ No newline at end of file